forked from github/server
spells that have no function in the xml file get one from an array, cleaning up and simplifying that code.
This commit is contained in:
parent
12c03644c4
commit
88acf39638
2 changed files with 17 additions and 7 deletions
|
@ -2034,7 +2034,7 @@ static void eval_race(struct opstack **stack, const void *userdata)
|
||||||
static void eval_order(struct opstack **stack, const void *userdata)
|
static void eval_order(struct opstack **stack, const void *userdata)
|
||||||
{ /* order -> string */
|
{ /* order -> string */
|
||||||
const struct order *ord = (const struct order *)opop(stack).v;
|
const struct order *ord = (const struct order *)opop(stack).v;
|
||||||
static char buf[256];
|
static char buf[512];
|
||||||
size_t len;
|
size_t len;
|
||||||
variant var;
|
variant var;
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ without prior permission by the authors of Eressea.
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
#include <util/bsdstring.h>
|
||||||
#include <util/crmessage.h>
|
#include <util/crmessage.h>
|
||||||
#include <util/functions.h>
|
#include <util/functions.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
@ -51,7 +52,6 @@ without prior permission by the authors of Eressea.
|
||||||
|
|
||||||
static boolean gamecode_enabled = false;
|
static boolean gamecode_enabled = false;
|
||||||
|
|
||||||
void (*set_spelldata_cb) (struct spell * sp) = 0;
|
|
||||||
static building_type *bt_get_or_create(const char *name)
|
static building_type *bt_get_or_create(const char *name)
|
||||||
{
|
{
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
|
@ -1481,6 +1481,8 @@ static int parse_spells(xmlDocPtr doc)
|
||||||
{
|
{
|
||||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||||
xmlXPathObjectPtr spells;
|
xmlXPathObjectPtr spells;
|
||||||
|
char zText[32];
|
||||||
|
strcpy(zText, "fumble_");
|
||||||
|
|
||||||
/* reading eressea/spells/spell */
|
/* reading eressea/spells/spell */
|
||||||
spells = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spell", xpath);
|
spells = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spell", xpath);
|
||||||
|
@ -1547,13 +1549,19 @@ static int parse_spells(xmlDocPtr doc)
|
||||||
|
|
||||||
if (gamecode_enabled) {
|
if (gamecode_enabled) {
|
||||||
/* reading eressea/spells/spell/function */
|
/* reading eressea/spells/spell/function */
|
||||||
|
pf_generic cast = 0;
|
||||||
|
pf_generic fumble = 0;
|
||||||
|
|
||||||
xpath->node = node;
|
xpath->node = node;
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
||||||
|
|
||||||
if (result->nodesetval->nodeNr == 0) {
|
if (result->nodesetval->nodeNr == 0) {
|
||||||
/* deprecated style: this spell gets its' function from a callback */
|
cast = get_function(sp->sname);
|
||||||
if (set_spelldata_cb)
|
if (!cast) {
|
||||||
set_spelldata_cb(sp);
|
log_error(("no spell cast function registered for '%s'\n", sp->sname));
|
||||||
|
}
|
||||||
|
strlcpy(zText+7, sp->sname, sizeof(zText)-7);
|
||||||
|
fumble = get_function(zText);
|
||||||
} else {
|
} else {
|
||||||
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];
|
||||||
|
@ -1568,9 +1576,9 @@ static int parse_spells(xmlDocPtr doc)
|
||||||
}
|
}
|
||||||
assert(propValue != NULL);
|
assert(propValue != NULL);
|
||||||
if (strcmp((const char *)propValue, "cast") == 0) {
|
if (strcmp((const char *)propValue, "cast") == 0) {
|
||||||
sp->cast = (spell_f) fun;
|
cast = fun;
|
||||||
} else if (strcmp((const char *)propValue, "fumble") == 0) {
|
} else if (strcmp((const char *)propValue, "fumble") == 0) {
|
||||||
sp->patzer = (fumble_f) 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));
|
||||||
|
@ -1578,6 +1586,8 @@ static int parse_spells(xmlDocPtr doc)
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sp->cast = (spell_f)cast;
|
||||||
|
sp->patzer = (fumble_f)fumble;
|
||||||
xmlXPathFreeObject(result);
|
xmlXPathFreeObject(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue