fix the fix_fam_spells function (2585 WIP)

This commit is contained in:
Enno Rehling 2019-05-19 15:28:16 +02:00
parent 670aa56d4e
commit 1c01f4d083
2 changed files with 12 additions and 0 deletions

View file

@ -2268,6 +2268,10 @@ void fix_fam_spells(unit *u) {
sc_mage *dmage;
unit *du = unit_create(0);
if (!is_familiar(u)) {
return;
}
u_setrace(du, u_race(u));
dmage = create_mage(du, M_GRAY);
equip_familiar(du);

View file

@ -540,11 +540,19 @@ static void test_fix_fam_spells(CuTest *tc) {
CuAssertPtrEquals(tc, NULL, unit_get_spellbook(u));
CuAssertTrue(tc, !u_hasspell(u, sp));
callbacks.equip_unit = equip_spell;
CuAssertTrue(tc, is_familiar(u));
fix_fam_spells(u);
CuAssertTrue(tc, is_familiar(u));
CuAssertPtrNotNull(tc, unit_get_spellbook(u));
CuAssertTrue(tc, u_hasspell(u, sp));
/* u is a migrant, and does not get equipped: */
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
u_setrace(u, rc);
CuAssertTrue(tc, !is_familiar(u));
fix_fam_spells(u);
CuAssertTrue(tc, !is_familiar(u));
CuAssertPtrEquals(tc, NULL, unit_get_spellbook(u));
test_teardown();
}