From 67414f29ebf6af99a084e315d086bf429cd646cd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 19:26:07 +0100 Subject: [PATCH] wrap ai.scare and at_scare in rc_set_param --- src/kernel/race.c | 5 +++++ src/kernel/race.test.c | 2 ++ src/kernel/xmlreader.c | 13 ++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index 4dc347751..b7c52d169 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -311,6 +311,11 @@ void rc_set_param(struct race *rc, const char *key, const char *value) { if (strcmp(key, "recruit_multi") == 0) { rc->recruit_multi = atof(value); } + else if (strcmp(key, "ai.scare") == 0) { + attrib *a = a_new(&at_scare); + a->data.i = atoi(value); + a_add(&rc->attribs, a); + } else if (strcmp(key, "migrants.formula") == 0) { if (value[0] == '1') { rc->flags |= RCF_MIGRANTS; diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index 132457cb4..857e8696a 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -96,6 +96,8 @@ static void test_rc_set_param(CuTest *tc) { rc_set_param(rc, "migrants.formula", "1"); CuAssertIntEquals(tc, RCF_MIGRANTS, rc->flags&RCF_MIGRANTS); CuAssertIntEquals(tc, MIGRANTS_LOG10, rc_migrants_formula(rc)); + rc_set_param(rc, "ai.scare", "400"); + CuAssertIntEquals(tc, 400, rc_scare(rc)); test_cleanup(); } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index c07e19809..0864df9a6 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1575,13 +1575,12 @@ static int parse_spells(xmlDocPtr doc) static void parse_ai(race * rc, xmlNodePtr node) { - int n; - - n = xml_ivalue(node, "scare", 0); - if (n>0) { - attrib *a = a_new(&at_scare); - a->data.i = n; - a_add(&rc->attribs, a); + xmlChar *propValue; + + propValue = xmlGetProp(node, BAD_CAST "scare"); + if (propValue) { + rc_set_param(rc, "ai.scare", (const char *)propValue); + xmlFree(propValue); } rc->splitsize = xml_ivalue(node, "splitsize", 0); rc->aggression = (float)xml_fvalue(node, "aggression", 0.04);