find_spellbyid() kriegt nen magietyp für den fall wo zwei zauber gleich heissen, und nicht über ihre 'alte' id erkannt werden, sondern den hash des namens (für seenspell)

This commit is contained in:
Enno Rehling 2006-01-01 20:11:09 +00:00
parent 88ea1b27b7
commit c60502bfc8
8 changed files with 24 additions and 67 deletions

View File

@ -201,6 +201,9 @@
<File
RelativePath=".\itemtypes.c">
</File>
<File
RelativePath=".\phoenixcompass.c">
</File>
<File
RelativePath=".\seed.c">
</File>

View File

@ -211,7 +211,9 @@ read_mage(attrib * a, FILE * F)
if (global.data_version<SPELLNAME_VERSION) {
int spid;
fscanf (F, "%d %d", &spid, &mage->combatspells[i].level);
if (spid>=0) mage->combatspells[i].sp = find_spellbyid((spellid_t)spid);
if (spid>=0) {
mage->combatspells[i].sp = find_spellbyid(mage->magietyp, (spellid_t)spid);
}
} else {
fscanf (F, "%s %d", spname, &mage->combatspells[i].level);
if (strcmp("none", spname)!=0) {
@ -226,7 +228,7 @@ read_mage(attrib * a, FILE * F)
if (global.data_version<SPELLNAME_VERSION) {
fscanf (F, "%d", &i);
if (i < 0) break;
sp = find_spellbyid((spellid_t)i);
sp = find_spellbyid(mage->magietyp, (spellid_t)i);
} else {
fscanf(F, "%s", spname);
if (strcmp(spname, "end")==0) break;
@ -367,7 +369,7 @@ read_seenspell(attrib * a, FILE * f)
fscanf(f, "%s", buf);
i = atoi(buf);
if (i!=0) {
sp = find_spellbyid((spellid_t)i);
sp = find_spellbyid(M_GRAU, (spellid_t)i);
} else {
int mtype;
fscanf(f, "%d", &mtype);
@ -410,9 +412,9 @@ updatespelllist(unit * u)
boolean ismonster = u->faction->no==MONSTER_FACTION;
/* Nur Wyrm-Magier bekommen den Wyrmtransformationszauber */
sp = find_spellbyid(SPL_BECOMEWYRM);
sp = find_spellbyid(M_GRAU, SPL_BECOMEWYRM);
if (fspecial(u->faction, FS_WYRM) && !has_spell(u, sp) && sp->level<=sk) {
add_spell(mage, find_spellbyid(SPL_BECOMEWYRM));
add_spell(mage, find_spellbyid(M_GRAU, SPL_BECOMEWYRM));
}
/* Transformierte Wyrm-Magier bekommen Drachenodem */
@ -421,17 +423,17 @@ updatespelllist(unit * u)
switch (urc) {
/* keine breaks! Wyrme sollen alle drei Zauber können.*/
case RC_WYRM:
sp = find_spellbyid(SPL_WYRMODEM);
sp = find_spellbyid(M_GRAU, SPL_WYRMODEM);
if (sp!=NULL && !has_spell(u, sp) && sp->level<=sk) {
add_spell(mage, sp);
}
case RC_DRAGON:
sp = find_spellbyid(SPL_DRAGONODEM);
sp = find_spellbyid(M_GRAU, SPL_DRAGONODEM);
if (sp!=NULL && !has_spell(u, sp) && sp->level<=sk) {
add_spell(mage, sp);
}
case RC_FIREDRAGON:
sp = find_spellbyid(SPL_FIREDRAGONODEM);
sp = find_spellbyid(M_GRAU, SPL_FIREDRAGONODEM);
if (sp!=NULL && !has_spell(u, sp) && sp->level<=sk) {
add_spell(mage, sp);
}

View File

@ -270,9 +270,6 @@ boolean is_familiar(const struct unit *u);
spell *get_spellfromtoken(struct unit *u, const char *s, const struct locale * lang);
/* versucht einen Spruch über den Namen zu identifizieren, gibt
* ansonsten NULL zurück */
spell *find_spellbyid(spellid_t i);
/* versucht einen Spruch über seine Id zu identifizieren, gibt
* ansonsten NULL zurück */
int get_combatspelllevel(const struct unit *u, int nr);
/* versucht, eine eingestellte maximale Kampfzauberstufe
* zurückzugeben. 0 = Maximum, -1 u ist kein Magier. */

View File

@ -1170,12 +1170,12 @@ readunit(FILE * F)
mage->spellpoints = ri(F);
mage->spchange = ri(F);
while ((i = ri(F)) != -1) {
mage->combatspells[csp].sp = find_spellbyid((spellid_t)i);
mage->combatspells[csp].sp = find_spellbyid(mage->magietyp, (spellid_t)i);
mage->combatspells[csp].level = ri(F);
csp++;
}
while ((i = ri(F)) != -1) {
add_spell(mage, find_spellbyid((spellid_t)i));
add_spell(mage, find_spellbyid(mage->magietyp, (spellid_t)i));
}
mage->spellcount = 0;
a = a_add(&u->attribs, a_new(&at_mage));

View File

@ -165,7 +165,7 @@ get_spellfromtoken(unit *u, const char *name, const struct locale * lang)
}
spell *
find_spellbyid(spellid_t id)
find_spellbyid(magic_t mtype, spellid_t id)
{
spell_list * slist;
@ -181,8 +181,12 @@ find_spellbyid(spellid_t id)
}
for (slist=spells;slist!=NULL;slist=slist->next) {
spell* sp = slist->data;
int hashid = hashstring(sp->sname);
if (hashid == id) return sp;
unsigned int hashid = hashstring(sp->sname);
if (hashid==id) {
if (sp->magietyp==mtype || mtype==M_GRAU) {
return sp;
}
}
}
log_warning(("cannot find spell by id: %u\n", id));

View File

@ -44,6 +44,7 @@ extern "C" {
extern void init_spells(void);
extern void register_spell(struct spell * sp);
extern struct spell * find_spell(magic_t mtype, const char * name);
extern struct spell * find_spellbyid(magic_t mtype, spellid_t i);
#ifdef __cplusplus
}

View File

@ -7088,7 +7088,7 @@ sp_becomewyrm(castorder *co)
}
u->race = new_race[RC_WYRM];
add_spell(get_mage(u), find_spellbyid(SPL_WYRMODEM));
add_spell(get_mage(u), find_spellbyid(M_GRAU, SPL_WYRMODEM));
ADDMSG(&u->faction->msgs, msg_message("becomewyrm", "u", u));

View File

@ -268,55 +268,6 @@ attrib_type at_roadfix = {
ATF_UNIQUE
};
/* ************************************************************ */
/* GANZ WICHTIG! ALLE GEÄNDERTEN SPRÜCHE NEU ANZEIGEN */
/* GANZ WICHTIG! FÜGT AUCH NEUE ZAUBER IN DIE LISTE DER BEKANNTEN EIN */
/* ************************************************************ */
static void
show_newspells(void)
{
region *r;
/* Alle geänderten Zauber in das array newspellids[]. mit SPL_NOSPELL
* terminieren */
spellid_t newspellids[] = {
SPL_NOSPELL
};
/* die id's der neuen oder veränderten Sprüche werden in newspellids[]
* abgelegt */
for(r=regions; r; r=r->next) {
unit *u;
for(u=r->units;u;u=u->next) {
sc_mage *m = get_mage(u);
if (u->faction->no == MONSTER_FACTION) continue;
if (m != NULL) {
int i;
if (m->magietyp == M_GRAU) continue;
for (i = 0; newspellids[i] != SPL_NOSPELL; i++) {
spell *sp = find_spellbyid(newspellids[i]);
if (!sp) continue;
if (m->magietyp == sp->magietyp || has_spell(u, sp)) {
attrib * a = a_find(u->faction->attribs, &at_reportspell);
while (a && a->data.v != sp) a = a->nexttype;
if (!a) {
/* spell is not being shown yet. if seen before, remove to show again */
a = a_find(u->faction->attribs, &at_seenspell);
while (a && a->data.v != sp) a = a->nexttype;
if (a) a_remove(&u->faction->attribs, a);
}
}
}
}
}
}
}
extern plane * arena;
static void
@ -1086,7 +1037,6 @@ korrektur(void)
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
* Beschreibungen geändert haben */
show_newspells();
fix_age();
/* Immer ausführen! Erschafft neue Teleport-Regionen, wenn nötig */