deal with invalid border types (wisps are getting deleted from Eressea) and disabled spells (again, wisps).

This commit is contained in:
Enno Rehling 2012-05-12 13:16:07 -07:00
parent 88acf39638
commit 08fc39cca7
2 changed files with 53 additions and 44 deletions

View file

@ -676,7 +676,8 @@ int read_borders(struct storage *store)
if (result < 0) if (result < 0)
return result; return result;
} }
if (!to || !from) { if (!type->name || !to || !from) {
log_warning(("erase invalid border '%s' between '%s' and '%s'\n", type->__name, regionname(from, 0), regionname(to, 0)));
erase_border(b); erase_border(b);
} }
} }

View file

@ -1497,6 +1497,7 @@ static int parse_spells(xmlDocPtr doc)
int k; int k;
spell_component *component; spell_component *component;
spell *sp; spell *sp;
int valid = 1;
static int modes[] = { 0, PRECOMBATSPELL, COMBATSPELL, POSTCOMBATSPELL }; static int modes[] = { 0, PRECOMBATSPELL, COMBATSPELL, POSTCOMBATSPELL };
/* spellname */ /* spellname */
@ -1559,6 +1560,7 @@ static int parse_spells(xmlDocPtr doc)
cast = get_function(sp->sname); cast = get_function(sp->sname);
if (!cast) { if (!cast) {
log_error(("no spell cast function registered for '%s'\n", sp->sname)); log_error(("no spell cast function registered for '%s'\n", sp->sname));
valid = 0;
} }
strlcpy(zText+7, sp->sname, sizeof(zText)-7); strlcpy(zText+7, sp->sname, sizeof(zText)-7);
fumble = get_function(zText); fumble = get_function(zText);
@ -1568,19 +1570,20 @@ static int parse_spells(xmlDocPtr doc)
pf_generic fun; pf_generic fun;
parse_function(node, &fun, &propValue); parse_function(node, &fun, &propValue);
if (fun == NULL) {
log_error(("unknown function name '%s' for spell '%s'\n",
(const char *)propValue, sp->sname));
xmlFree(propValue);
continue;
}
assert(propValue != NULL); assert(propValue != NULL);
if (strcmp((const char *)propValue, "cast") == 0) { if (strcmp((const char *)propValue, "cast") == 0) {
cast = fun; if (fun) {
} else if (strcmp((const char *)propValue, "fumble") == 0) { cast = fun;
valid = 1;
} else {
log_error(("unknown function name '%s' for spell '%s'\n",
(const char *)propValue, sp->sname));
valid = 0;
}
} else if (fun && strcmp((const char *)propValue, "fumble") == 0) {
fumble = fun; fumble = fun;
} else { } else {
log_error(("unknown function type '%s' for spell %s\n", log_error(("unknown function type '%s' for spell '%s'\n",
(const char *)propValue, sp->sname)); (const char *)propValue, sp->sname));
} }
xmlFree(propValue); xmlFree(propValue);
@ -1591,45 +1594,50 @@ static int parse_spells(xmlDocPtr doc)
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
} }
/* reading eressea/spells/spell/resource */ if (valid) {
xpath->node = node; /* reading eressea/spells/spell/resource */
result = xmlXPathEvalExpression(BAD_CAST "resource", xpath); xpath->node = node;
if (result->nodesetval->nodeNr) { result = xmlXPathEvalExpression(BAD_CAST "resource", xpath);
sp->components = if (result->nodesetval->nodeNr) {
(spell_component *) malloc(sizeof(spell_component) * sp->components =
(result->nodesetval->nodeNr + 1)); (spell_component *) malloc(sizeof(spell_component) *
sp->components[result->nodesetval->nodeNr].type = 0; (result->nodesetval->nodeNr + 1));
} sp->components[result->nodesetval->nodeNr].type = 0;
for (component = sp->components, k = 0; k != result->nodesetval->nodeNr;
++k) {
const resource_type *rtype;
xmlNodePtr node = result->nodesetval->nodeTab[k];
propValue = xmlGetProp(node, BAD_CAST "name");
assert(propValue);
rtype = rt_find((const char *)propValue);
if (!rtype) {
log_error(("spell %s uses unknown component %s.\n", sp->sname,
(const char *)propValue));
xmlFree(propValue);
continue;
} }
component->type = rtype; for (component = sp->components, k = 0; k != result->nodesetval->nodeNr;
xmlFree(propValue); ++k) {
component->amount = xml_ivalue(node, "amount", 1); const resource_type *rtype;
component->cost = SPC_FIX; xmlNodePtr node = result->nodesetval->nodeTab[k];
propValue = xmlGetProp(node, BAD_CAST "cost"); propValue = xmlGetProp(node, BAD_CAST "name");
if (propValue != NULL) { assert(propValue);
if (strcmp((const char *)propValue, "linear") == 0) { rtype = rt_find((const char *)propValue);
component->cost = SPC_LINEAR; if (!rtype) {
} else if (strcmp((const char *)propValue, "level") == 0) { log_error(("spell %s uses unknown component %s.\n", sp->sname,
component->cost = SPC_LEVEL; (const char *)propValue));
xmlFree(propValue);
continue;
} }
component->type = rtype;
xmlFree(propValue); xmlFree(propValue);
component->amount = xml_ivalue(node, "amount", 1);
component->cost = SPC_FIX;
propValue = xmlGetProp(node, BAD_CAST "cost");
if (propValue != NULL) {
if (strcmp((const char *)propValue, "linear") == 0) {
component->cost = SPC_LINEAR;
} else if (strcmp((const char *)propValue, "level") == 0) {
component->cost = SPC_LEVEL;
}
xmlFree(propValue);
}
component++;
} }
component++; xmlXPathFreeObject(result);
}
if (valid) {
register_spell(sp);
} }
xmlXPathFreeObject(result);
register_spell(sp);
} }
} }