refactor handling of race.param in XML

This commit is contained in:
Enno Rehling 2017-02-03 20:16:44 +01:00
parent 250227cad2
commit 70b12ae6ca
3 changed files with 13 additions and 14 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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");
}