Das durcheinander mit 0 und -1 bei den spells (SPL_NOSPELL) hoffentlich bereinigt.

This commit is contained in:
Enno Rehling 2004-04-10 22:48:19 +00:00
parent fa69b66879
commit 8d04c6a448
5 changed files with 49 additions and 51 deletions

View File

@ -198,76 +198,77 @@ init_mage(attrib * a) {
static void static void
free_mage(attrib * a) free_mage(attrib * a)
{ {
sc_mage * mage = (sc_mage*)a->data.v; sc_mage * mage = (sc_mage*)a->data.v;
freelist(mage->spellptr); freelist(mage->spellptr);
free(mage); free(mage);
} }
static int static int
read_mage(attrib * a, FILE * F) read_mage(attrib * a, FILE * F)
{ {
int i, mtype; int i, mtype;
sc_mage * mage = (sc_mage*)a->data.v; sc_mage * mage = (sc_mage*)a->data.v;
spell_ptr ** sp = &mage->spellptr; spell_ptr ** sp = &mage->spellptr;
fscanf(F, "%d %d %d", &mtype, &mage->spellpoints, &mage->spchange);
fscanf(F, "%d %d %d", &mtype, &mage->spellpoints, &mage->spchange);
mage->magietyp = (magic_t)mtype; mage->magietyp = (magic_t)mtype;
for (i=0;i!=MAXCOMBATSPELLS;++i) { for (i=0;i!=MAXCOMBATSPELLS;++i) {
int spid; int spid;
fscanf (F, "%d %d", &spid, &mage->combatspelllevel[i]); fscanf (F, "%d %d", &spid, &mage->combatspelllevel[i]);
if (spid<0) spid = SPL_NOSPELL;
mage->combatspell[i] = (spellid_t)spid; mage->combatspell[i] = (spellid_t)spid;
} }
for (;;) { for (;;) {
int spid; int spid;
fscanf (F, "%d", &spid); fscanf (F, "%d", &spid);
if (spid < 0) break; if (spid < 0) break;
*sp = calloc (sizeof(spell_ptr), 1); *sp = calloc (sizeof(spell_ptr), 1);
(*sp)->spellid = (spellid_t)spid; (*sp)->spellid = (spellid_t)spid;
sp = &(*sp)->next; sp = &(*sp)->next;
} }
return AT_READ_OK; return AT_READ_OK;
} }
static void static void
write_mage(const attrib * a, FILE * F) { write_mage(const attrib * a, FILE * F) {
int i; int i;
sc_mage *mage = (sc_mage*)a->data.v; sc_mage *mage = (sc_mage*)a->data.v;
spell_ptr *sp = mage->spellptr; spell_ptr *sp = mage->spellptr;
fprintf (F, "%d %d %d ", fprintf(F, "%d %d %d ", mage->magietyp, mage->spellpoints, mage->spchange);
mage->magietyp, mage->spellpoints, mage->spchange); for (i=0;i!=MAXCOMBATSPELLS;++i) {
for (i=0;i!=MAXCOMBATSPELLS;++i) { fprintf(F, "%d %d ", mage->combatspell[i], mage->combatspelllevel[i]);
fprintf (F, "%d %d ", mage->combatspell[i], mage->combatspelllevel[i]); }
} while (sp!=NULL) {
while (sp) { fprintf (F, "%d ", sp->spellid);
fprintf (F, "%d ", sp->spellid); sp = sp->next;
sp = sp->next; }
} fprintf (F, "-1\n");
fprintf (F, "-1\n");
} }
attrib_type at_mage = { attrib_type at_mage = {
"mage", "mage",
init_mage, init_mage,
free_mage, free_mage,
NULL, NULL,
write_mage, write_mage,
read_mage, read_mage,
ATF_UNIQUE ATF_UNIQUE
}; };
boolean boolean
is_mage(const unit * u) is_mage(const unit * u)
{ {
return i2b(get_mage(u) != NULL); return i2b(get_mage(u) != NULL);
} }
sc_mage * sc_mage *
get_mage(const unit * u) get_mage(const unit * u)
{ {
if (has_skill(u, SK_MAGIC)) { if (has_skill(u, SK_MAGIC)) {
attrib * a = a_find(u->attribs, &at_mage); attrib * a = a_find(u->attribs, &at_mage);
if (a) return a->data.v; if (a) return a->data.v;
} }
return (sc_mage *) NULL; return (sc_mage *) NULL;
} }
magic_t magic_t
@ -490,7 +491,7 @@ get_combatspell(const unit *u, int nr)
m = get_mage(u); m = get_mage(u);
if (m) { if (m) {
return find_spellbyid(m->combatspell[nr]); return find_spellbyid(m->combatspell[nr]);
} else if(u->race->precombatspell != NO_SPELL) { } else if(u->race->precombatspell != SPL_NOSPELL) {
return find_spellbyid(u->race->precombatspell); return find_spellbyid(u->race->precombatspell);
} }

View File

@ -76,7 +76,7 @@ rc_new(const char * zName)
rc->_name[2] = strdup(zBuffer); rc->_name[2] = strdup(zBuffer);
sprintf(zBuffer, "%s_x", zName); sprintf(zBuffer, "%s_x", zName);
rc->_name[3] = strdup(zBuffer); rc->_name[3] = strdup(zBuffer);
rc->precombatspell = NO_SPELL; rc->precombatspell = SPL_NOSPELL;
return rc; return rc;
} }

View File

@ -7784,7 +7784,6 @@ find_spellbyid(spellid_t id)
{ {
spell_list * slist; spell_list * slist;
assert(id!=SPL_DONOTUSE);
for (slist=spells;slist!=NULL;slist=slist->next) { for (slist=spells;slist!=NULL;slist=slist->next) {
spell* sp = slist->data; spell* sp = slist->data;
if (sp->id == id) return sp; if (sp->id == id) return sp;

View File

@ -28,7 +28,7 @@ extern "C" {
/* Sprüche. Neue NUR hinten anfügen, oder das Datenfile geht kaputt */ /* Sprüche. Neue NUR hinten anfügen, oder das Datenfile geht kaputt */
enum { enum {
SPL_DONOTUSE, SPL_NOSPELL,
SPL_ARTEFAKT_OF_POWER, SPL_ARTEFAKT_OF_POWER,
SPL_ARTEFAKT_OF_AURAPOWER, SPL_ARTEFAKT_OF_AURAPOWER,
SPL_ARTEFAKT_OF_REGENERATION, SPL_ARTEFAKT_OF_REGENERATION,
@ -219,9 +219,7 @@ extern "C" {
SPL_WDWPYRAMID_BARDE, SPL_WDWPYRAMID_BARDE,
SPL_WDWPYRAMID_CHAOS, SPL_WDWPYRAMID_CHAOS,
#endif #endif
SPL_NOSPELL = (spellid_t) -1
}; };
#define NO_SPELL SPL_NOSPELL
/* Prototypen */ /* Prototypen */

View File

@ -774,10 +774,10 @@ parse_races(xmlDocPtr doc)
/* reading eressea/races/race/precombatspell */ /* reading eressea/races/race/precombatspell */
xpath->node = node; xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "precombatspell", xpath); result = xmlXPathEvalExpression(BAD_CAST "precombatspell", xpath);
assert(rc->precombatspell==NO_SPELL || !"precombatspell is already initialized"); assert(rc->precombatspell==SPL_NOSPELL || !"precombatspell is already initialized");
for (k=0;k!=result->nodesetval->nodeNr;++k) { for (k=0;k!=result->nodesetval->nodeNr;++k) {
xmlNodePtr node = result->nodesetval->nodeTab[k]; xmlNodePtr node = result->nodesetval->nodeTab[k];
rc->precombatspell = (spellid_t)xml_ivalue(node, "spell", NO_SPELL); rc->precombatspell = (spellid_t)xml_ivalue(node, "spell", SPL_NOSPELL);
} }
xmlXPathFreeObject(result); xmlXPathFreeObject(result);