diff --git a/src/magic.c b/src/magic.c index fdd74d55e..7b15bb71d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -117,6 +117,11 @@ typedef struct sc_mage { struct spellbook *spellbook; } sc_mage; +void mage_set_spellpoints(sc_mage *m, int aura) +{ + m->spellpoints = aura; +} + int mage_get_spellpoints(const sc_mage *m) { return m ? m->spellpoints : 0; @@ -603,7 +608,7 @@ void set_spellpoints(unit * u, int sp) { sc_mage *m = get_mage(u); if (m) { - m->spellpoints = sp; + mage_set_spellpoints(m, sp); } } @@ -615,18 +620,6 @@ int change_spellpoints(unit * u, int mp) return mage_change_spellpoints(get_mage(u), mp); } -/** - * Bietet die Moeglichkeit, die maximale Anzahl der Magiepunkte mit - * Regionszaubern oder Attributen zu beinflussen - */ -static int get_spchange(const unit * u) -{ - sc_mage *m; - - m = get_mage(u); - return m ? m->spchange : 0; -} - /* ein Magier kann normalerweise maximal Stufe^2.1/1.2+1 Magiepunkte * haben. * Manche Rassen haben einen zusaetzlichen Multiplikator @@ -655,12 +648,15 @@ int max_spellpoints(const struct unit *u, const region * r) double potenz = 2.1; double divisor = 1.2; const struct resource_type *rtype; + const sc_mage *m; assert(u); if (!r) r = u->region; sk = effskill(u, SK_MAGIC, r); - msp = rc_maxaura(u_race(u)) * (pow(sk, potenz) / divisor + 1) + get_spchange(u); + msp = rc_maxaura(u_race(u)) * (pow(sk, potenz) / divisor + 1); + m = get_mage(u); + if (m) msp += m->spchange; rtype = rt_find("aurafocus"); if (rtype && i_get(u->items, rtype->itype) > 0) { @@ -1464,44 +1460,47 @@ void regenerate_aura(void) for (r = regions; r; r = r->next) { for (u = r->units; u; u = u->next) { - if (u->number && is_mage(u)) { - aura = get_spellpoints(u); - auramax = max_spellpoints_depr(r, u); - if (aura < auramax) { - struct building *b = inside_building(u); - const struct building_type *btype = building_is_active(b) ? b->type : NULL; - reg_aura = regeneration(u); + if (u->number && u->attribs) { + sc_mage *m = get_mage(u); + if (m) { + aura = mage_get_spellpoints(m); + auramax = max_spellpoints(u, r); + if (aura < auramax) { + struct building *b = inside_building(u); + const struct building_type *btype = building_is_active(b) ? b->type : NULL; + reg_aura = regeneration(u); - /* Magierturm erhoeht die Regeneration um 75% */ - /* Steinkreis erhoeht die Regeneration um 50% */ - if (btype) - reg_aura *= btype->auraregen; + /* Magierturm erhoeht die Regeneration um 75% */ + /* Steinkreis erhoeht die Regeneration um 50% */ + if (btype) + reg_aura *= btype->auraregen; - /* Bonus/Malus durch Zauber */ - mod = get_curseeffect(u->attribs, &ct_auraboost); - if (mod > 0) { - reg_aura = (reg_aura * mod) / 100.0; + /* Bonus/Malus durch Zauber */ + mod = get_curseeffect(u->attribs, &ct_auraboost); + if (mod > 0) { + reg_aura = (reg_aura * mod) / 100.0; + } + + /* Einfluss von Artefakten */ + /* TODO (noch gibs keine) */ + + /* maximal Differenz bis Maximale-Aura regenerieren + * mindestens 1 Aura pro Monat */ + regen = (int)reg_aura; + reg_aura -= regen; + if (chance(reg_aura)) { + ++regen; + } + if (regen < 1) regen = 1; + if (regen > auramax - aura) regen = auramax - aura; + + aura += regen; + ADDMSG(&u->faction->msgs, msg_message("regenaura", + "unit region amount", u, r, regen)); } - - /* Einfluss von Artefakten */ - /* TODO (noch gibs keine) */ - - /* maximal Differenz bis Maximale-Aura regenerieren - * mindestens 1 Aura pro Monat */ - regen = (int)reg_aura; - reg_aura -= regen; - if (chance(reg_aura)) { - ++regen; - } - if (regen < 1) regen = 1; - if (regen > auramax - aura) regen = auramax - aura; - - aura += regen; - ADDMSG(&u->faction->msgs, msg_message("regenaura", - "unit region amount", u, r, regen)); + if (aura > auramax) aura = auramax; + mage_set_spellpoints(m, aura); } - if (aura > auramax) aura = auramax; - set_spellpoints(u, aura); } } } diff --git a/src/magic.h b/src/magic.h index 8d2b2b534..5269e3259 100644 --- a/src/magic.h +++ b/src/magic.h @@ -210,6 +210,7 @@ extern "C" { const struct spell *mage_get_combatspell(const struct sc_mage *mage, int nr, int *level); struct spellbook * mage_get_spellbook(const struct sc_mage * mage); int mage_get_spellpoints(const struct sc_mage *m); + void mage_set_spellpoints(struct sc_mage *m, int aura); int mage_change_spellpoints(struct sc_mage *m, int delta); enum magic_t unit_get_magic(const struct unit *u); @@ -259,7 +260,7 @@ extern "C" { /* veraendert die maximalen Magiepunkte einer Einheit */ /* Zaubern */ - extern double spellpower(struct region *r, struct unit *u, const struct spell * sp, + double spellpower(struct region *r, struct unit *u, const struct spell * sp, int cast_level, struct order *ord); /* ermittelt die Staerke eines Spruchs */ bool fumble(struct region *r, struct unit *u, const struct spell * sp, @@ -315,7 +316,7 @@ extern "C" { int resist_bonus); /* gibt false zurueck, wenn der Zauber gelingt, true, wenn das Ziel * widersteht */ - extern struct spell * unit_getspell(struct unit *u, const char *s, + struct spell * unit_getspell(struct unit *u, const char *s, const struct locale *lang); const char *magic_name(magic_t mtype, const struct locale *lang); diff --git a/src/magic.test.c b/src/magic.test.c index 577e88a37..160662c15 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -108,7 +108,7 @@ void test_pay_spell(CuTest * tc) test_setup(); init_resources(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); @@ -142,7 +142,7 @@ void test_pay_spell_failure(CuTest * tc) test_setup(); init_resources(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); @@ -179,7 +179,7 @@ void test_getspell_unit(CuTest * tc) struct locale * lang; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); u = test_create_unit(f, r); create_mage(u, M_GWYRRD); @@ -207,7 +207,7 @@ void test_getspell_faction(CuTest * tc) struct locale * lang; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); @@ -238,7 +238,7 @@ void test_getspell_school(CuTest * tc) struct spellbook * book; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); @@ -268,7 +268,7 @@ void test_set_pre_combatspell(CuTest * tc) const int index = 0; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); @@ -300,7 +300,7 @@ void test_set_main_combatspell(CuTest * tc) const int index = 1; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); @@ -332,7 +332,7 @@ void test_set_post_combatspell(CuTest * tc) const int index = 2; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); @@ -363,7 +363,7 @@ void test_hasspell(CuTest * tc) struct region * r; test_setup(); - r = test_create_region(0, 0, NULL); + r = test_create_plain(0, 0); f = test_create_faction(NULL); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); @@ -405,7 +405,7 @@ void test_multi_cast(CuTest *tc) { locale_setstring(lang, mkname("spell", sp->sname), "Feuerball"); CuAssertStrEquals(tc, "Feuerball", spell_name(sp, lang)); - u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); set_level(u, SK_MAGIC, 10); unit_add_spell(u, sp, 1); CuAssertPtrEquals(tc, sp, unit_getspell(u, "Feuerball", lang)); @@ -426,7 +426,7 @@ static void test_magic_resistance(CuTest *tc) { test_setup(); rc = test_create_race("human"); - u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL)); + u = test_create_unit(test_create_faction(rc), test_create_plain(0, 0)); CuAssertTrue(tc, frac_equal(rc->magres, magic_resistance(u))); rc->magres = frac_one; CuAssert(tc, "magic resistance is capped at 0.9", frac_equal(magic_resistance(u), frac_make(9, 10))); @@ -445,23 +445,45 @@ static void test_max_spellpoints(CuTest *tc) { test_setup(); rc = test_create_race("human"); - u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL)); + u = test_create_unit(test_create_faction(rc), test_create_plain(0, 0)); CuAssertIntEquals(tc, 1, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 1, max_spellpoints(u, u->region)); + CuAssertIntEquals(tc, 1, max_spellpoints(u, NULL)); rc->maxaura = 100; - CuAssertIntEquals(tc, 1, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 1, max_spellpoints(u, u->region)); rc->maxaura = 200; - CuAssertIntEquals(tc, 2, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 2, max_spellpoints(u, u->region)); create_mage(u, M_GWYRRD); set_level(u, SK_MAGIC, 1); - CuAssertIntEquals(tc, 3, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 3, max_spellpoints(u, u->region)); set_level(u, SK_MAGIC, 2); - CuAssertIntEquals(tc, 9, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 9, max_spellpoints(u, u->region)); /* permanent aura loss: */ CuAssertIntEquals(tc, 7, change_maxspellpoints(u, -2)); - CuAssertIntEquals(tc, 7, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 7, max_spellpoints(u, u->region)); test_teardown(); } +static void test_regenerate_aura(CuTest *tc) { + unit *u; + + test_setup(); + test_teardown(); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + create_mage(u, M_GWYRRD); + CuAssertIntEquals(tc, 0, get_spellpoints(u)); + CuAssertIntEquals(tc, 1, max_spellpoints(u, NULL)); + regenerate_aura(); + CuAssertIntEquals(tc, 1, get_spellpoints(u)); + + u = test_create_unit(u->faction, u->region); + create_mage(u, M_GRAY); + CuAssertIntEquals(tc, 0, get_spellpoints(u)); + CuAssertIntEquals(tc, 1, max_spellpoints(u, NULL)); + regenerate_aura(); + CuAssertIntEquals(tc, 1, get_spellpoints(u)); +} + static void test_illusioncastle(CuTest *tc) { building *b; @@ -470,7 +492,7 @@ static void test_illusioncastle(CuTest *tc) test_setup(); btype = test_create_buildingtype("castle"); bt_icastle = test_create_buildingtype("illusioncastle"); - b = test_create_building(test_create_region(0, 0, NULL), bt_icastle); + b = test_create_building(test_create_plain(0, 0), bt_icastle); b->size = 1; make_icastle(b, btype, 10); a = a_find(b->attribs, &at_icastle); @@ -488,7 +510,7 @@ static void test_is_mage(CuTest *tc) { struct sc_mage *mage; test_setup(); - u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); CuAssertPtrEquals(tc, NULL, get_mage(u)); CuAssertTrue(tc, !is_mage(u)); set_level(u, SK_MAGIC, 1); @@ -505,7 +527,7 @@ static void test_get_mage(CuTest *tc) { struct sc_mage *mage; test_setup(); - u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); CuAssertPtrEquals(tc, NULL, get_mage(u)); CuAssertPtrNotNull(tc, mage = create_mage(u, M_CERDDOR)); CuAssertPtrEquals(tc, mage, get_mage(u)); @@ -517,8 +539,8 @@ static void test_familiar_set(CuTest *tc) { test_setup(); - mag = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); - fam = test_create_unit(mag->faction, test_create_region(0, 0, NULL)); + mag = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + fam = test_create_unit(mag->faction, test_create_plain(0, 0)); CuAssertPtrEquals(tc, NULL, get_familiar(mag)); CuAssertPtrEquals(tc, NULL, get_familiar_mage(fam)); CuAssertPtrEquals(tc, NULL, a_find(mag->attribs, &at_skillmod)); @@ -537,8 +559,8 @@ static void test_familiar_age(CuTest *tc) { test_setup(); - mag = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); - fam = test_create_unit(mag->faction, test_create_region(0, 0, NULL)); + mag = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + fam = test_create_unit(mag->faction, test_create_plain(0, 0)); set_familiar(mag, fam); CuAssertPtrEquals(tc, fam, get_familiar(mag)); CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); @@ -568,8 +590,8 @@ static void test_familiar_equip(CuTest *tc) { test_setup(); callbacks.equip_unit = equip_callback; - mag = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); - u = test_create_unit(mag->faction, test_create_region(0, 0, NULL)); + mag = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + u = test_create_unit(mag->faction, test_create_plain(0, 0)); CuAssertStrEquals(tc, "human", u->_race->_name); set_familiar(mag, u); create_newfamiliar(mag, u); @@ -612,5 +634,6 @@ CuSuite *get_magic_suite(void) SUITE_ADD_TEST(suite, test_magic_resistance); SUITE_ADD_TEST(suite, test_max_spellpoints); SUITE_ADD_TEST(suite, test_illusioncastle); + SUITE_ADD_TEST(suite, test_regenerate_aura); return suite; }