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

View File

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

View File

@ -7784,7 +7784,6 @@ find_spellbyid(spellid_t id)
{
spell_list * slist;
assert(id!=SPL_DONOTUSE);
for (slist=spells;slist!=NULL;slist=slist->next) {
spell* sp = slist->data;
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 */
enum {
SPL_DONOTUSE,
SPL_NOSPELL,
SPL_ARTEFAKT_OF_POWER,
SPL_ARTEFAKT_OF_AURAPOWER,
SPL_ARTEFAKT_OF_REGENERATION,
@ -219,9 +219,7 @@ extern "C" {
SPL_WDWPYRAMID_BARDE,
SPL_WDWPYRAMID_CHAOS,
#endif
SPL_NOSPELL = (spellid_t) -1
};
#define NO_SPELL SPL_NOSPELL
/* Prototypen */

View File

@ -774,10 +774,10 @@ parse_races(xmlDocPtr doc)
/* reading eressea/races/race/precombatspell */
xpath->node = node;
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) {
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);