forked from github/server
fix trying to add to null-spellbook.
all unit tests pass.
This commit is contained in:
parent
6417f55ec6
commit
b8d8bac9ae
|
@ -480,7 +480,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
|
|||
commonspells[spellno] = commonspells[maxspell];
|
||||
commonspells[maxspell--] = sp;
|
||||
sp = 0;
|
||||
} else if (spellbook_get(f->spellbook, sp)) {
|
||||
} else if (f->spellbook && spellbook_get(f->spellbook, sp)) {
|
||||
commonspells[spellno] = commonspells[numspells--];
|
||||
if (maxspell>numspells) {
|
||||
maxspell = numspells;
|
||||
|
@ -490,6 +490,9 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
|
|||
}
|
||||
|
||||
if (spellno<maxspell) {
|
||||
if (!f->spellbook) {
|
||||
f->spellbook = create_spellbook(0);
|
||||
}
|
||||
spellbook_add(f->spellbook, sp, f->max_spelllevel);
|
||||
commonspells[spellno] = commonspells[numspells--];
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ void test_updatespells(CuTest * tc)
|
|||
CuAssertPtrNotNull(tc, book);
|
||||
spellbook_add(book, sp, 1);
|
||||
|
||||
CuAssertIntEquals(tc, 0, ql_length(f->spellbook->spells));
|
||||
CuAssertPtrEquals(tc, 0, f->spellbook);
|
||||
pick_random_spells(f, 1, book, 1);
|
||||
CuAssertPtrNotNull(tc, f->spellbook);
|
||||
CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells));
|
||||
|
|
|
@ -57,6 +57,7 @@ spellbook_entry * spellbook_get(spellbook *sb, struct spell * sp)
|
|||
quicklist *ql;
|
||||
int qi;
|
||||
|
||||
assert(sb);
|
||||
for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) {
|
||||
spellbook_entry *sbe = (spellbook_entry *) ql_get(ql, qi);
|
||||
if (sp==sbe->sp) {
|
||||
|
|
Loading…
Reference in New Issue