forked from github/server
get_spellfromtoken needs a mage, not any unit.
This commit is contained in:
parent
c41d185cd6
commit
c10e2552ad
5 changed files with 31 additions and 32 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 "<Spruchname>" NICHT löscht diesen speziellen
|
||||
* Kampfzauber */
|
||||
unset_combatspell(u, spell);
|
||||
unset_combatspell(u, sp);
|
||||
return 0;
|
||||
} else {
|
||||
/* KAMPFZAUBER "<Spruchname>" setzt diesen Kampfzauber */
|
||||
set_combatspell(u, spell, ord, level);
|
||||
set_combatspell(u, sp, ord, level);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue