get_spellfromtoken needs a mage, not any unit.

This commit is contained in:
Enno Rehling 2012-05-09 13:06:16 -07:00
parent c41d185cd6
commit c10e2552ad
5 changed files with 31 additions and 32 deletions

View file

@ -461,25 +461,15 @@ static void unit_castspell(unit * u, const char *name)
for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spell *sp = (spell *) ql_get(ql, qi); spell *sp = (spell *) ql_get(ql, qi);
if (strcmp(name, sp->sname) == 0) { 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) { if (sp->sp_function == NULL) {
log_error(("spell '%s' has no function.\n", sp->sname)); log_error(("spell '%s' has no function.\n", sp->sname));
co->level = 0;
} else { } else {
castorder *co = new_castorder(u, 0, sp, u->region, sp->level, sp->level, 0, 0, 0);
sp->sp_function(co); sp->sp_function(co);
}
free(co); free(co);
} }
} }
}
} }
static int tolua_unit_castspell(lua_State * L) static int tolua_unit_castspell(lua_State * L)

View file

@ -2420,8 +2420,9 @@ static void reshow(unit * u, struct order *ord, const char *s, param_t p)
int skill, c; int skill, c;
const potion_type *ptype; const potion_type *ptype;
const item_type *itype; const item_type *itype;
const spell *sp; const spell *sp = 0;
const race *rc; const race *rc;
sc_mage * mage;
switch (p) { switch (p) {
case P_ZAUBER: 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 */ /* try for a spell */
sp = get_spellfromtoken(u, s, u->faction->locale); mage = get_mage(u);
if (sp != NULL && u_hasspell(u, sp)) { if (mage) {
sp = get_spellfromtoken(mage, s, u->faction->locale);
}
if (sp) {
attrib *a = a_find(u->faction->attribs, &at_seenspell); 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; a = a->next;
if (a != NULL) }
if (a != NULL) {
a_remove(&u->faction->attribs, a); a_remove(&u->faction->attribs, a);
}
break; break;
} }
/* last, check if it's a race. */ /* last, check if it's a race. */
@ -2615,7 +2621,8 @@ static int combatspell_cmd(unit * u, struct order *ord)
{ {
const char *s; const char *s;
int level = 0; int level = 0;
spell *spell; spell *sp = 0;
sc_mage * mage;
init_tokens(ord); init_tokens(ord);
skip_token(); skip_token();
@ -2635,9 +2642,11 @@ static int combatspell_cmd(unit * u, struct order *ord)
s = getstrtoken(); s = getstrtoken();
} }
spell = get_spellfromtoken(u, s, u->faction->locale); mage = get_mage(u);
if (mage) {
if (!spell) { sp = get_spellfromtoken(mage, s, u->faction->locale);
}
if (!sp) {
cmistake(u, ord, 173, MSG_MAGIC); cmistake(u, ord, 173, MSG_MAGIC);
return 0; return 0;
} }
@ -2647,11 +2656,11 @@ static int combatspell_cmd(unit * u, struct order *ord)
if (findparam(s, u->faction->locale) == P_NOT) { if (findparam(s, u->faction->locale) == P_NOT) {
/* KAMPFZAUBER "<Spruchname>" NICHT löscht diesen speziellen /* KAMPFZAUBER "<Spruchname>" NICHT löscht diesen speziellen
* Kampfzauber */ * Kampfzauber */
unset_combatspell(u, spell); unset_combatspell(u, sp);
return 0; return 0;
} else { } else {
/* KAMPFZAUBER "<Spruchname>" setzt diesen Kampfzauber */ /* KAMPFZAUBER "<Spruchname>" setzt diesen Kampfzauber */
set_combatspell(u, spell, ord, level); set_combatspell(u, sp, ord, level);
} }
return 0; return 0;

View file

@ -112,9 +112,10 @@ static char *get_command(const order * ord, char *sbuffer, size_t size)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (text) if (text)
*bufp++ = ' '; *bufp++ = ' ';
} else } else {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
}
if (text) { if (text) {
bytes = (int)strlcpy(bufp, (const char *)text, size); bytes = (int)strlcpy(bufp, (const char *)text, size);
if (wrptr(&bufp, &size, bytes) != 0) { if (wrptr(&bufp, &size, bytes) != 0) {

View file

@ -70,29 +70,28 @@ spell *find_spell(const char *name)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* Spruch identifizieren */ /* Spruch identifizieren */
spell *get_spellfromtoken(unit * u, const char *name, spell *get_spellfromtoken(sc_mage *mage, const char *name,
const struct locale * lang) const struct locale * lang)
{ {
variant token; variant token;
sc_mage *m = get_mage(u); struct spell_names * names = mage->spellnames;
struct spell_names * names = m->spellnames;
for (;names;names=names->next) { for (;names;names=names->next) {
if (names->lang==lang) break; if (names->lang==lang) break;
} }
if (!names) { if (!names) {
quicklist *ql = m->spells; quicklist *ql = mage->spells;
int qi; int qi;
names = (spell_names *)calloc(1, sizeof(spell_names)); names = (spell_names *)calloc(1, sizeof(spell_names));
names->next = m->spellnames; names->next = mage->spellnames;
names->lang = lang; names->lang = lang;
names->tokens = (tnode *)calloc(1, sizeof(tnode)); 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); spell *sp = (spell *) ql_get(ql, qi);
const char *n = spell_name(sp, lang); const char *n = spell_name(sp, lang);
token.v = sp; token.v = sp;
addtoken(names->tokens, n, token); addtoken(names->tokens, n, token);
} }
m->spellnames = names; mage->spellnames = names;
} }
if (findtoken(names->tokens, name, &token) != E_TOK_NOMATCH) { if (findtoken(names->tokens, name, &token) != E_TOK_NOMATCH) {

View file

@ -50,7 +50,7 @@ extern "C" {
extern void register_spell(struct spell *sp); extern void register_spell(struct spell *sp);
extern struct spell *find_spell(const char *name); extern struct spell *find_spell(const char *name);
extern struct spell *find_spellbyid(unsigned int i); 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); const struct locale *lang);
#ifdef __cplusplus #ifdef __cplusplus