From 70b12ae6ca9fc34ed124db53d8e1b41a78736e16 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 20:16:44 +0100 Subject: [PATCH] refactor handling of race.param in XML --- src/kernel/faction.c | 2 +- src/kernel/xmlreader.c | 23 +++++++++++------------ src/upkeep.c | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b7115c62f..e3cb4508a 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -758,7 +758,7 @@ int count_migrants(const faction * f) int count_maxmigrants(const faction * f) { - int formula = get_param_int(f->race->parameters, "migrants.formula", 0); + int formula = f->race->parameters ? get_param_int(f->race->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE; if (formula == MIGRANTS_LOG10) { int nsize = count_all(f); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index d75a6583f..9b1f5532c 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1573,17 +1573,6 @@ static int parse_spells(xmlDocPtr doc) return 0; } -static void parse_param(struct param **params, xmlNodePtr node) -{ - xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - xmlChar *propValue = xmlGetProp(node, BAD_CAST "value"); - - set_param(params, (const char *)propName, (const char *)propValue); - - xmlFree(propName); - xmlFree(propValue); -} - static void parse_ai(race * rc, xmlNodePtr node) { int n; @@ -1737,12 +1726,22 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "noattack", false)) rc->battle_flags |= BF_NO_ATTACK; + rc->recruit_multi = 1.0; for (child = node->children; child; child = child->next) { if (strcmp((const char *)child->name, "ai") == 0) { parse_ai(rc, child); } else if (strcmp((const char *)child->name, "param") == 0) { - parse_param(&rc->parameters, child); + xmlChar *propName = xmlGetProp(child, BAD_CAST "name"); + xmlChar *propValue = xmlGetProp(child, BAD_CAST "value"); + if (strcmp((const char *)propName, "recruit_multi")==0) { + rc->recruit_multi = atof((const char *)propValue); + } + else { + set_param(&rc->parameters, (const char *)propName, (const char *)propValue); + } + xmlFree(propName); + xmlFree(propValue); } } rc->recruit_multi = get_param_flt(rc->parameters, "recruit_multi", 1.0); diff --git a/src/upkeep.c b/src/upkeep.c index 94cbc341d..c53c321d0 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -59,7 +59,7 @@ static void help_feed(unit * donor, unit * u, int *need_p) } static const char *hunger_damage(const race *rc) { - const char * damage = get_param(rc->parameters, "hunger.damage"); + const char * damage = rc->parameters ? get_param(rc->parameters, "hunger.damage") : NULL; if (!damage) { damage = config_get("hunger.damage"); }