avoid duplicate spells in spellbooks (it's a bit hackish)

This commit is contained in:
Enno Rehling 2012-05-26 15:15:18 -07:00
parent e4244f6282
commit 36ad727394
3 changed files with 14 additions and 5 deletions

View File

@ -3725,10 +3725,12 @@ static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel)
for (qi = 0, ql = src->spells; ql; ql_advance(&ql, &qi, 1)) {
spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi);
if (sbe->level<=maxlevel) {
if (!spellbook_get(dst, sbe->sp)) {
spellbook_add(dst, sbe->sp, sbe->level);
}
}
}
}
}
static void update_spells(void)

View File

@ -1257,13 +1257,17 @@ void read_spellbook(spellbook **bookp, struct storage *store, int (*get_level)(c
level = store->r_int(store);
}
if (sp) {
spellbook * sb = *bookp;
if (level<=0 && get_level) {
level = get_level(sp, cbdata);
}
if (!*bookp) {
if (!sb) {
*bookp = create_spellbook(0);
sb = *bookp;
}
if (store->version>=SPELLBOOK_VERSION || !spellbook_get(sb, sp)) {
spellbook_add(sb, sp, level);
}
spellbook_add(*bookp, sp, level);
}
}
}

View File

@ -18,9 +18,12 @@ spellbook * create_spellbook(const char * name)
void spellbook_add(spellbook *sb, struct spell * sp, int level)
{
spellbook_entry * sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry));
spellbook_entry * sbe;
assert(sb && level>0);
assert(sb && sp && level>0);
assert(!spellbook_get(sb, sp));
sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry));
sbe->sp = sp;
sbe->level = level;
ql_push(&sb->spells, sbe);