forked from github/server
avoid duplicate spells in spellbooks (it's a bit hackish)
This commit is contained in:
parent
e4244f6282
commit
36ad727394
|
@ -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)) {
|
for (qi = 0, ql = src->spells; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi);
|
spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi);
|
||||||
if (sbe->level<=maxlevel) {
|
if (sbe->level<=maxlevel) {
|
||||||
spellbook_add(dst, sbe->sp, sbe->level);
|
if (!spellbook_get(dst, sbe->sp)) {
|
||||||
|
spellbook_add(dst, sbe->sp, sbe->level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1257,13 +1257,17 @@ void read_spellbook(spellbook **bookp, struct storage *store, int (*get_level)(c
|
||||||
level = store->r_int(store);
|
level = store->r_int(store);
|
||||||
}
|
}
|
||||||
if (sp) {
|
if (sp) {
|
||||||
|
spellbook * sb = *bookp;
|
||||||
if (level<=0 && get_level) {
|
if (level<=0 && get_level) {
|
||||||
level = get_level(sp, cbdata);
|
level = get_level(sp, cbdata);
|
||||||
}
|
}
|
||||||
if (!*bookp) {
|
if (!sb) {
|
||||||
*bookp = create_spellbook(0);
|
*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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,12 @@ spellbook * create_spellbook(const char * name)
|
||||||
|
|
||||||
void spellbook_add(spellbook *sb, struct spell * sp, int level)
|
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->sp = sp;
|
||||||
sbe->level = level;
|
sbe->level = level;
|
||||||
ql_push(&sb->spells, sbe);
|
ql_push(&sb->spells, sbe);
|
||||||
|
|
Loading…
Reference in New Issue