From b506bed4d9e441f724a75cfdbd5aa4b8583bd07c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Dec 2014 12:56:36 +0100 Subject: [PATCH 1/2] fix a crash in the parser for USE orders when no item name was given. --- src/laws.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/laws.c b/src/laws.c index 6010d0e33..2d04606dd 100755 --- a/src/laws.c +++ b/src/laws.c @@ -3796,7 +3796,7 @@ int use_cmd(unit * u, struct order *ord) /* BENUTZE 42 Yanxspirit */ t = getstrtoken(); } - itype = finditemtype(t, u->faction->locale); + itype = t ? finditemtype(t, u->faction->locale) : NULL; if (itype != NULL) { err = use_item(u, itype, n, ord); From 42d75c334d80a2f48ae11931567f948973695749 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Dec 2014 12:55:36 +0100 Subject: [PATCH 2/2] WIP: Familiars check for combat spells in the magician's list of spells, too. https://bugs.eressea.de/view.php?id=1660 This does not work, because set_combatspell later uses knowsspell to make sure the spell is one the familiar has. --- src/magic.c | 74 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/src/magic.c b/src/magic.c index d59503def..8fc5072f6 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2903,40 +2903,56 @@ const char *curse_name(const curse_type * ctype, const struct locale *lang) return LOC(lang, mkname("spell", ctype->cname)); } -spell *unit_getspell(struct unit *u, const char *name, const struct locale * lang) -{ - sc_mage * mage = get_mage(u); - if (mage) { - variant token; - void * tokens = 0; - spellbook *sb = unit_get_spellbook(u); +static void select_spellbook(void **tokens, spellbook *sb, const struct locale * lang) { + quicklist * ql; + int qi; - if (sb) { - quicklist * ql; - int qi; + assert(sb); + assert(lang); - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); - spell *sp = sbe->sp; - const char *n = spell_name(sp, lang); - if (!n) { - log_error("no translation in locale %s for spell %s\n", locale_name(lang), sp->sname); - } - else { - token.v = sp; - addtoken(&tokens, n, token); - } - } + for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + spell *sp = sbe->sp; + + const char *n = spell_name(sp, lang); + if (!n) { + log_error("no translation in locale %s for spell %s\n", locale_name(lang), sp->sname); } - - if (tokens) { - if (findtoken(tokens, name, &token) != E_TOK_NOMATCH) { - freetokens(tokens); - return (spell *)token.v; - } - freetokens(tokens); + else { + variant token; + token.v = sp; + addtoken(tokens, n, token); } } +} + +spell *unit_getspell(struct unit *u, const char *name, const struct locale * lang) +{ + void * tokens = 0; + spellbook *sb; + + sb = unit_get_spellbook(u); + if (sb) { + select_spellbook(&tokens, sb, lang); + } + + u = get_familiar_mage(u); + if (u) { + sb = unit_get_spellbook(u); + if (sb) { + select_spellbook(&tokens, sb, lang); + } + } + + if (tokens) { + variant token; + if (findtoken(tokens, name, &token) != E_TOK_NOMATCH) { + freetokens(tokens); + return (spell *)token.v; + } + freetokens(tokens); + } + return 0; }