forked from github/server
fix an indexing error in pick_random_spell
This commit is contained in:
parent
6ffe9cac33
commit
c73297ba44
1 changed files with 13 additions and 12 deletions
|
@ -389,6 +389,14 @@ attrib_type at_seenspell = {
|
||||||
"seenspell", NULL, NULL, NULL, write_seenspell, read_seenspell
|
"seenspell", NULL, NULL, NULL, write_seenspell, read_seenspell
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MAXSPELLS 256
|
||||||
|
|
||||||
|
static boolean has_spell(quicklist * ql, const spell * sp)
|
||||||
|
{
|
||||||
|
int qi;
|
||||||
|
return ql_set_find(&ql, &qi, sp) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
static boolean already_seen(const faction * f, const spell * sp)
|
static boolean already_seen(const faction * f, const spell * sp)
|
||||||
{
|
{
|
||||||
attrib *a;
|
attrib *a;
|
||||||
|
@ -401,14 +409,6 @@ static boolean already_seen(const faction * f, const spell * sp)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXSPELLS 256
|
|
||||||
|
|
||||||
static boolean has_spell(quicklist * ql, const spell * sp)
|
|
||||||
{
|
|
||||||
int qi;
|
|
||||||
return ql_set_find(&ql, &qi, sp) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_spells(faction * f, sc_mage * mage, int level, const spellbook *book)
|
static void update_spells(faction * f, sc_mage * mage, int level, const spellbook *book)
|
||||||
{
|
{
|
||||||
boolean ismonster = is_monsters(f);
|
boolean ismonster = is_monsters(f);
|
||||||
|
@ -448,6 +448,7 @@ void updatespelllist(unit * u)
|
||||||
if (mage->magietyp != M_GRAY) {
|
if (mage->magietyp != M_GRAY) {
|
||||||
spellbook * book;
|
spellbook * book;
|
||||||
book = get_spellbook(magic_school[mage->magietyp]);
|
book = get_spellbook(magic_school[mage->magietyp]);
|
||||||
|
|
||||||
update_spells(u->faction, mage, sk, book);
|
update_spells(u->faction, mage, sk, book);
|
||||||
|
|
||||||
if (FactionSpells()) {
|
if (FactionSpells()) {
|
||||||
|
@ -489,11 +490,11 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
|
||||||
spellno = rng_int() % maxspell;
|
spellno = rng_int() % maxspell;
|
||||||
sp = commonspells[spellno];
|
sp = commonspells[spellno];
|
||||||
if (sp->level>f->max_spelllevel) {
|
if (sp->level>f->max_spelllevel) {
|
||||||
commonspells[spellno] = commonspells[maxspell];
|
commonspells[spellno] = commonspells[--maxspell];
|
||||||
commonspells[maxspell--] = sp;
|
commonspells[maxspell] = sp;
|
||||||
sp = 0;
|
sp = 0;
|
||||||
} else if (f->spellbook && spellbook_get(f->spellbook, sp)) {
|
} else if (f->spellbook && spellbook_get(f->spellbook, sp)) {
|
||||||
commonspells[spellno] = commonspells[numspells--];
|
commonspells[spellno] = commonspells[--numspells];
|
||||||
if (maxspell>numspells) {
|
if (maxspell>numspells) {
|
||||||
maxspell = numspells;
|
maxspell = numspells;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +507,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
|
||||||
f->spellbook = create_spellbook(0);
|
f->spellbook = create_spellbook(0);
|
||||||
}
|
}
|
||||||
spellbook_add(f->spellbook, sp, f->max_spelllevel);
|
spellbook_add(f->spellbook, sp, f->max_spelllevel);
|
||||||
commonspells[spellno] = commonspells[numspells--];
|
commonspells[spellno] = commonspells[--numspells];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue