diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index f4bc53952..27f069345 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -3725,7 +3725,9 @@ 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) { - spellbook_add(dst, sbe->sp, sbe->level); + if (!spellbook_get(dst, sbe->sp)) { + spellbook_add(dst, sbe->sp, sbe->level); + } } } } diff --git a/src/kernel/save.c b/src/kernel/save.c index 4a7454a48..20f1eb39d 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -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); } } } diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index 45d2f6d50..ab73bdd09 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -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);