From 670aa56d4ec6ab94844e6ba751e591ad6c382c64 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 May 2019 15:14:01 +0200 Subject: [PATCH] fix_fam_spells happy case test (is familiar) --- src/kernel/save.c | 2 +- src/magic.c | 14 ++++++++++++-- src/magic.h | 3 ++- src/magic.test.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index f43c21f20..1d51ee433 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1659,7 +1659,7 @@ int read_game(gamedata *data) fix_familiars(fix_fam_triggers); } if (data->version < FAMILIAR_FIXSPELLBOOK_VERSION) { - fix_familiars(fix_fam_mage); + fix_familiars(fix_fam_spells); } log_debug("Done loading turn %d.", turn); diff --git a/src/magic.c b/src/magic.c index 553927ec6..8b8cf9c3d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2251,9 +2251,20 @@ static int copy_spell_cb(spellbook_entry *sbe, void *udata) { } /** + * Entferne Magie-Attribut von Migranten, die keine Vertrauten sind. + * + * Einmalige Reparatur von Vertrauten (Bug 2585). + */ +void fix_fam_migrant(unit *u) { + +} + +/** + * Einheiten, die Vertraute sind, bekommen ihre fehlenden Zauber. + * * Einmalige Reparatur von Vertrauten (Bugs 2451, 2517). */ -void fix_fam_mage(unit *u) { +void fix_fam_spells(unit *u) { sc_mage *dmage; unit *du = unit_create(0); @@ -2286,7 +2297,6 @@ void fix_fam_mage(unit *u) { void create_newfamiliar(unit * mage, unit * fam) { - create_mage(fam, M_GRAY); set_familiar(mage, fam); equip_familiar(fam); diff --git a/src/magic.h b/src/magic.h index 5269e3259..15870e90c 100644 --- a/src/magic.h +++ b/src/magic.h @@ -330,7 +330,8 @@ extern "C" { void create_newfamiliar(struct unit *mage, struct unit *familiar); void create_newclone(struct unit *mage, struct unit *familiar); - void fix_fam_mage(struct unit *u); + void fix_fam_spells(struct unit *u); + void fix_fam_migrant(struct unit *u); const char *spell_info(const struct spell *sp, const struct locale *lang); diff --git a/src/magic.test.c b/src/magic.test.c index 7923fb6d8..e70e026ca 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -473,7 +473,6 @@ 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)); @@ -487,6 +486,7 @@ static void test_regenerate_aura(CuTest *tc) { CuAssertIntEquals(tc, 1, max_spellpoints(u, NULL)); regenerate_aura(); CuAssertIntEquals(tc, 1, get_spellpoints(u)); + test_teardown(); } /** @@ -500,14 +500,53 @@ static void test_regenerate_aura_migrants(CuTest *tc) { race *rc; test_setup(); - test_teardown(); rc = test_create_race("demon"); rc->maxaura = 100; + rc->flags |= RCF_FAMILIAR; + 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)); + test_teardown(); +} + +static bool equip_spell(unit *u, const char *eqname, int mask) { + spell * sp = find_spell("test"); + unit_add_spell(u, sp, 1); + return true; +} + +static void test_fix_fam_spells(CuTest *tc) { + unit *u, *mage; + race *rc; + spell * sp; + + test_setup(); + sp = create_spell("test"); + rc = test_create_race("demon"); + rc->maxaura = 100; + rc->flags |= RCF_FAMILIAR; + + /* u is a familiar, and gets equipped: */ + mage = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + u_setrace(u, rc); + /* reproduce the bug, create a broken familiar: */ + callbacks.equip_unit = NULL; + create_newfamiliar(mage, u); + set_level(u, SK_MAGIC, 1); + CuAssertPtrEquals(tc, NULL, unit_get_spellbook(u)); + CuAssertTrue(tc, !u_hasspell(u, sp)); + callbacks.equip_unit = equip_spell; + fix_fam_spells(u); + CuAssertPtrNotNull(tc, unit_get_spellbook(u)); + CuAssertTrue(tc, u_hasspell(u, sp)); + + /* u is a migrant, and does not get equipped: */ + + test_teardown(); } static void test_illusioncastle(CuTest *tc) @@ -662,5 +701,6 @@ CuSuite *get_magic_suite(void) SUITE_ADD_TEST(suite, test_illusioncastle); SUITE_ADD_TEST(suite, test_regenerate_aura); SUITE_ADD_TEST(suite, test_regenerate_aura_migrants); + SUITE_ADD_TEST(suite, test_fix_fam_spells); return suite; }