From c10e2552ad4cb4aa2c89dba72734b3d0ff159527 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 9 May 2012 13:06:16 -0700 Subject: [PATCH] get_spellfromtoken needs a mage, not any unit. --- src/bindings/bind_unit.c | 14 ++------------ src/gamecode/laws.c | 31 ++++++++++++++++++++----------- src/kernel/order.c | 3 ++- src/kernel/spell.c | 13 ++++++------- src/kernel/spell.h | 2 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/bindings/bind_unit.c b/src/bindings/bind_unit.c index c0aec9d92..ba7b692df 100644 --- a/src/bindings/bind_unit.c +++ b/src/bindings/bind_unit.c @@ -461,23 +461,13 @@ static void unit_castspell(unit * u, const char *name) for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { spell *sp = (spell *) ql_get(ql, qi); if (strcmp(name, sp->sname) == 0) { - castorder *co = (castorder *) malloc(sizeof(castorder)); - co->distance = 0; - co->familiar = NULL; - co->force = sp->level; - co->level = sp->level; - co->magician.u = u; - co->order = NULL; - co->par = NULL; - co->rt = u->region; - co->sp = sp; if (sp->sp_function == NULL) { log_error(("spell '%s' has no function.\n", sp->sname)); - co->level = 0; } else { + castorder *co = new_castorder(u, 0, sp, u->region, sp->level, sp->level, 0, 0, 0); sp->sp_function(co); + free(co); } - free(co); } } } diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 5ef5fa739..4e6fd92be 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -2420,8 +2420,9 @@ static void reshow(unit * u, struct order *ord, const char *s, param_t p) int skill, c; const potion_type *ptype; const item_type *itype; - const spell *sp; + const spell *sp = 0; const race *rc; + sc_mage * mage; switch (p) { case P_ZAUBER: @@ -2452,13 +2453,18 @@ static void reshow(unit * u, struct order *ord, const char *s, param_t p) } } /* try for a spell */ - sp = get_spellfromtoken(u, s, u->faction->locale); - if (sp != NULL && u_hasspell(u, sp)) { + mage = get_mage(u); + if (mage) { + sp = get_spellfromtoken(mage, s, u->faction->locale); + } + if (sp) { attrib *a = a_find(u->faction->attribs, &at_seenspell); - while (a != NULL && a->type == &at_seenspell && a->data.v != sp) + while (a != NULL && a->type == &at_seenspell && a->data.v != sp) { a = a->next; - if (a != NULL) + } + if (a != NULL) { a_remove(&u->faction->attribs, a); + } break; } /* last, check if it's a race. */ @@ -2615,7 +2621,8 @@ static int combatspell_cmd(unit * u, struct order *ord) { const char *s; int level = 0; - spell *spell; + spell *sp = 0; + sc_mage * mage; init_tokens(ord); skip_token(); @@ -2635,9 +2642,11 @@ static int combatspell_cmd(unit * u, struct order *ord) s = getstrtoken(); } - spell = get_spellfromtoken(u, s, u->faction->locale); - - if (!spell) { + mage = get_mage(u); + if (mage) { + sp = get_spellfromtoken(mage, s, u->faction->locale); + } + if (!sp) { cmistake(u, ord, 173, MSG_MAGIC); return 0; } @@ -2647,11 +2656,11 @@ static int combatspell_cmd(unit * u, struct order *ord) if (findparam(s, u->faction->locale) == P_NOT) { /* KAMPFZAUBER "" NICHT löscht diesen speziellen * Kampfzauber */ - unset_combatspell(u, spell); + unset_combatspell(u, sp); return 0; } else { /* KAMPFZAUBER "" setzt diesen Kampfzauber */ - set_combatspell(u, spell, ord, level); + set_combatspell(u, sp, ord, level); } return 0; diff --git a/src/kernel/order.c b/src/kernel/order.c index 3738354b4..1ea62abf9 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -112,8 +112,9 @@ static char *get_command(const order * ord, char *sbuffer, size_t size) WARN_STATIC_BUFFER(); if (text) *bufp++ = ' '; - } else + } else { WARN_STATIC_BUFFER(); + } } if (text) { bytes = (int)strlcpy(bufp, (const char *)text, size); diff --git a/src/kernel/spell.c b/src/kernel/spell.c index cb5df21ca..4e183029f 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -70,29 +70,28 @@ spell *find_spell(const char *name) /* ------------------------------------------------------------- */ /* Spruch identifizieren */ -spell *get_spellfromtoken(unit * u, const char *name, +spell *get_spellfromtoken(sc_mage *mage, const char *name, const struct locale * lang) { variant token; - sc_mage *m = get_mage(u); - struct spell_names * names = m->spellnames; + struct spell_names * names = mage->spellnames; for (;names;names=names->next) { if (names->lang==lang) break; } if (!names) { - quicklist *ql = m->spells; + quicklist *ql = mage->spells; int qi; names = (spell_names *)calloc(1, sizeof(spell_names)); - names->next = m->spellnames; + names->next = mage->spellnames; names->lang = lang; names->tokens = (tnode *)calloc(1, sizeof(tnode)); - for (qi = 0, ql = m->spells; ql; ql_advance(&ql, &qi, 1)) { + for (qi = 0, ql = mage->spells; ql; ql_advance(&ql, &qi, 1)) { spell *sp = (spell *) ql_get(ql, qi); const char *n = spell_name(sp, lang); token.v = sp; addtoken(names->tokens, n, token); } - m->spellnames = names; + mage->spellnames = names; } if (findtoken(names->tokens, name, &token) != E_TOK_NOMATCH) { diff --git a/src/kernel/spell.h b/src/kernel/spell.h index c43aa8cc7..4e5daf1b5 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -50,7 +50,7 @@ extern "C" { extern void register_spell(struct spell *sp); extern struct spell *find_spell(const char *name); extern struct spell *find_spellbyid(unsigned int i); - extern struct spell *get_spellfromtoken(struct unit *u, const char *s, + extern struct spell *get_spellfromtoken(struct sc_mage *mage, const char *s, const struct locale *lang); #ifdef __cplusplus