diff --git a/src/magic.c b/src/magic.c index 7b15bb71d..553927ec6 100644 --- a/src/magic.c +++ b/src/magic.c @@ -651,12 +651,13 @@ int max_spellpoints(const struct unit *u, const region * r) const sc_mage *m; assert(u); + m = get_mage(u); + if (!m) return 0; if (!r) r = u->region; sk = effskill(u, SK_MAGIC, r); msp = rc_maxaura(u_race(u)) * (pow(sk, potenz) / divisor + 1); - m = get_mage(u); - if (m) msp += m->spchange; + msp += m->spchange; rtype = rt_find("aurafocus"); if (rtype && i_get(u->items, rtype->itype) > 0) { diff --git a/src/magic.test.c b/src/magic.test.c index 160662c15..83d5610f6 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -446,14 +446,14 @@ static void test_max_spellpoints(CuTest *tc) { test_setup(); rc = test_create_race("human"); 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)); + CuAssertIntEquals(tc, 0, max_spellpoints_depr(u->region, u)); + CuAssertIntEquals(tc, 0, max_spellpoints(u, u->region)); + CuAssertIntEquals(tc, 0, max_spellpoints(u, NULL)); + create_mage(u, M_GWYRRD); rc->maxaura = 100; CuAssertIntEquals(tc, 1, max_spellpoints(u, u->region)); rc->maxaura = 200; CuAssertIntEquals(tc, 2, max_spellpoints(u, u->region)); - create_mage(u, M_GWYRRD); set_level(u, SK_MAGIC, 1); CuAssertIntEquals(tc, 3, max_spellpoints(u, u->region)); set_level(u, SK_MAGIC, 2); @@ -484,6 +484,27 @@ static void test_regenerate_aura(CuTest *tc) { CuAssertIntEquals(tc, 1, get_spellpoints(u)); } +/** + * Test for Bug 2582. + * + * Migrant units that are not familiars, but whose race has a maxaura + * must not regenerate aura. + */ +static void test_regenerate_aura_migrants(CuTest *tc) { + unit *u; + race *rc; + + test_setup(); + test_teardown(); + rc = test_create_race("demon"); + rc->maxaura = 100; + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + u_setrace(u, rc); + CuAssertIntEquals(tc, 0, get_spellpoints(u)); + regenerate_aura(); + CuAssertIntEquals(tc, 0, get_spellpoints(u)); +} + static void test_illusioncastle(CuTest *tc) { building *b; @@ -635,5 +656,6 @@ CuSuite *get_magic_suite(void) SUITE_ADD_TEST(suite, test_max_spellpoints); SUITE_ADD_TEST(suite, test_illusioncastle); SUITE_ADD_TEST(suite, test_regenerate_aura); + SUITE_ADD_TEST(suite, test_regenerate_aura_migrants); return suite; } diff --git a/src/randenc.c b/src/randenc.c index 9c3fd4739..e6ebf549b 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -239,6 +239,7 @@ static void move_iceberg(region * r) "region dir", r, dir)); } + stats_count("iceberg.drift", 1); x = r->x; y = r->y; @@ -379,6 +380,7 @@ static void create_icebergs(void) continue; r->terrain = t_iceberg; + stats_count("iceberg.terraform", 1); fset(r, RF_SELECT); move_iceberg(r);