magiegebiet-fix für findspell

This commit is contained in:
Enno Rehling 2002-05-05 11:40:08 +00:00
parent c875dc341e
commit 56319bcbb3
1 changed files with 17 additions and 7 deletions

View File

@ -551,16 +551,26 @@ getspell(const unit *u, spellid_t spellid)
#include "umlaut.h" #include "umlaut.h"
static local_names * spellnames; typedef struct spell_names {
static local_names * struct spell_names * next;
init_spellnames(const struct locale * lang) const struct locale * lang;
magic_t mtype;
struct tnode names;
} spell_names;
static spell_names * spellnames;
static spell_names *
init_spellnames(const struct locale * lang, magic_t mtype)
{ {
int i; int i;
local_names * sn = calloc(sizeof(local_names), 1); spell_names * sn = calloc(sizeof(spell_names), 1);
sn->next = spellnames; sn->next = spellnames;
sn->lang = lang; sn->lang = lang;
sn->mtype = mtype;
for (i=0; spelldaten[i].id != SPL_NOSPELL; i++) { for (i=0; spelldaten[i].id != SPL_NOSPELL; i++) {
const char * n = spelldaten[i].sname; const char * n = spelldaten[i].sname;
if (spelldaten[i].magietyp!=mtype) continue;
if (spelldaten[i].info==NULL) n = locale_string(lang, mkname("spell", n)); if (spelldaten[i].info==NULL) n = locale_string(lang, mkname("spell", n));
addtoken(&sn->names, n, (void*)(spelldaten+i)); addtoken(&sn->names, n, (void*)(spelldaten+i));
} }
@ -571,17 +581,17 @@ init_spellnames(const struct locale * lang)
spell * spell *
find_spellbyname(unit *u, char *name, const struct locale * lang) find_spellbyname(unit *u, char *name, const struct locale * lang)
{ {
local_names * sn = spellnames; spell_names * sn = spellnames;
spell_ptr *spt; spell_ptr *spt;
sc_mage * m = get_mage(u); sc_mage * m = get_mage(u);
spell * sp; spell * sp;
if (!m) return NULL; if (!m) return NULL;
while (sn) { while (sn) {
if (sn->lang==lang) break; if (sn->mtype==m->magietyp && sn->lang==lang) break;
sn=sn->next; sn=sn->next;
} }
if (!sn) sn = init_spellnames(lang); if (!sn) sn = init_spellnames(lang, m->magietyp);
if (findtoken(&sn->names, name, &sp)==E_TOK_NOMATCH) return NULL; if (findtoken(&sn->names, name, &sp)==E_TOK_NOMATCH) return NULL;
for (spt = m->spellptr; spt; spt = spt->next) { for (spt = m->spellptr; spt; spt = spt->next) {