fix_familiars had a bug caused by quicklist

This commit is contained in:
Enno Rehling 2011-05-02 23:27:39 -07:00
parent 817f396467
commit a2816f1528
2 changed files with 11 additions and 13 deletions

View File

@ -142,15 +142,13 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask)
if (mask & EQUIP_SPELLS) { if (mask & EQUIP_SPELLS) {
quicklist *ql = eq->spells; quicklist *ql = eq->spells;
if (ql) { if (ql) {
int qi;
sc_mage *m = get_mage(u); sc_mage *m = get_mage(u);
if (m == NULL) {
assert(!"trying to equip spells on a non-mage!"); assert(m || !"trying to equip spells on a non-mage!");
} else { for (qi = 0; ql; ql_advance(&ql, &qi, 1)) {
int qi; spell *sp = (spell *) ql_get(ql, qi);
for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { add_spell(&m->spells, sp);
spell *sp = (spell *) ql_get(ql, qi);
add_spell(get_spelllist(m, u->faction), sp);
}
} }
} }
} }

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <errno.h> #include <errno.h>
#define QL_MAXSIZE 14 /* total struct is 64 bytes */ #define QL_MAXSIZE 14 /* total struct is 64 bytes */
#define QL_LIMIT 8 #define QL_LIMIT 7
struct quicklist { struct quicklist {
struct quicklist *next; struct quicklist *next;
@ -89,7 +89,7 @@ int ql_delete(quicklist ** qlp, int index)
if (ql->num_elements == 0) { if (ql->num_elements == 0) {
*qlp = ql->next; *qlp = ql->next;
free(ql); free(ql);
} else if (ql->next && ql->num_elements < QL_LIMIT) { } else if (ql->next && ql->num_elements <= QL_LIMIT) {
quicklist *qn = ql->next; quicklist *qn = ql->next;
if (ql->num_elements + qn->num_elements > QL_MAXSIZE) { if (ql->num_elements + qn->num_elements > QL_MAXSIZE) {
memcpy(ql->elements + ql->num_elements, qn->elements, sizeof(void *)); memcpy(ql->elements + ql->num_elements, qn->elements, sizeof(void *));
@ -124,10 +124,10 @@ int ql_insert(quicklist ** qlp, int index, void *data)
quicklist *qn = (quicklist *) malloc(sizeof(quicklist)); quicklist *qn = (quicklist *) malloc(sizeof(quicklist));
qn->next = ql->next; qn->next = ql->next;
ql->next = qn; ql->next = qn;
qn->num_elements = QL_LIMIT; qn->num_elements = ql->num_elements-QL_LIMIT;
ql->num_elements -= QL_LIMIT; ql->num_elements = QL_LIMIT;
memcpy(qn->elements, ql->elements + ql->num_elements, memcpy(qn->elements, ql->elements + ql->num_elements,
QL_LIMIT * sizeof(void *)); qn->num_elements * sizeof(void *));
if (index <= ql->num_elements) { if (index <= ql->num_elements) {
return ql_insert(qlp, index, data); return ql_insert(qlp, index, data);
} else { } else {