diff --git a/src/spells.c b/src/spells.c index be5aaa996..0490a6c71 100644 --- a/src/spells.c +++ b/src/spells.c @@ -278,24 +278,24 @@ static void magicanalyse_building(building * b, unit * mage, double force) for (a = b->attribs; a; a = a->next) { curse *c; double probability; - int mon; if (a->type != &at_curse) continue; + found = true; c = (curse *)a->data.v; /* ist der curse schwaecher als der Analysezauber, so ergibt sich * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); - mon = c->duration + (rng_int() % 10) - 5; - if (mon < 1) mon = 1; if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { - ADDMSG(&mage->faction->msgs, msg_message("analyse_building_age", + ADDMSG(&mage->faction->msgs, msg_message("analyse_building_noage", "mage building curse", mage, b, c->type)); } else { + int mon = c->duration + (rng_int() % 10) - 5; + if (mon < 1) mon = 1; ADDMSG(&mage->faction->msgs, msg_message("analyse_building_age", "mage building curse months", mage, b, c->type, mon)); } diff --git a/src/spells.test.c b/src/spells.test.c index e43233ffb..e4d989c50 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1945,6 +1946,61 @@ static void test_analysemagic_ship(CuTest *tc) test_teardown(); } +static void test_analysemagic_building(CuTest *tc) +{ + struct region *r; + struct faction *f; + unit *u; + castorder co; + spellparameter param, *args = NULL; + message *m; + curse *c, *c2; + + test_setup(); + random_source_inject_constants(0.0, 0); + mt_create_va(mt_new("analyse_building_age", NULL), "mage:unit", "building:building", "curse:curse", "months:int", MT_NEW_END); + mt_create_va(mt_new("analyse_building_noage", NULL), "mage:unit", "building:building", "curse:curse", MT_NEW_END); + r = test_create_plain(0, 0); + f = test_create_faction(); + f->magiegebiet = M_DRAIG; + u = test_create_unit(f, r); + u->building = test_create_building(r, NULL); + + param.flag = TARGET_OK; + param.typ = SPP_BUILDING; + param.data.b = u->building; + arrput(args, param); + + test_create_castorder(&co, u, 3, 4., 0, args); + CuAssertIntEquals(tc, co.level, sp_analysemagic(&co)); + CuAssertIntEquals(tc, 1, test_count_messagetype(f->msgs, "analyse_building_nospell")); + CuAssertIntEquals(tc, 0, test_count_messagetype(f->msgs, "analyse_building_age")); + test_clear_messages(f); + + c = create_curse(u, &u->building->attribs, &ct_strongwall, 5.0, 20, 1, 0); + CuAssertIntEquals(tc, co.level, sp_analysemagic(&co)); + CuAssertIntEquals(tc, 0, test_count_messagetype(f->msgs, "analyse_building_nospell")); + /* curse is too strong, analysis fails */ + CuAssertIntEquals(tc, 1, test_count_messagetype(f->msgs, "analyse_building_fail")); + test_clear_messages(f); + + c->vigour = co.force; + c2 = create_curse(u, &u->building->attribs, &ct_magicwalls, co.force, 20, 1, 0); + CuAssertIntEquals(tc, co.level, sp_analysemagic(&co)); + CuAssertIntEquals(tc, 0, test_count_messagetype(f->msgs, "analyse_building_nospell")); + CuAssertPtrNotNull(tc, m = test_find_faction_message(f, "analyse_building_age")); + CuAssertPtrEquals(tc, u, m->parameters[0].v); + CuAssertPtrEquals(tc, u->building, m->parameters[1].v); + CuAssertPtrEquals(tc, (void *)c->type, m->parameters[2].v); + CuAssertIntEquals(tc, 15, m->parameters[3].i); + CuAssertPtrNotNull(tc, m = test_find_faction_message(f, "analyse_building_noage")); + CuAssertPtrEquals(tc, u, m->parameters[0].v); + CuAssertPtrEquals(tc, u->building, m->parameters[1].v); + CuAssertPtrEquals(tc, (void *)c2->type, m->parameters[2].v); + + test_teardown(); +} + CuSuite *get_spells_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -1995,7 +2051,7 @@ CuSuite *get_spells_suite(void) SUITE_ADD_TEST(suite, test_analysemagic_unit); //SUITE_ADD_TEST(suite, test_analysemagic_temp); SUITE_ADD_TEST(suite, test_analysemagic_ship); - //SUITE_ADD_TEST(suite, test_analysemagic_building); + SUITE_ADD_TEST(suite, test_analysemagic_building); //SUITE_ADD_TEST(suite, test_analysemagic_region); return suite;