From 2d274426817938dbf689e0208f0f3ef03384fe9f Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 19 Jan 2015 15:13:03 +0100 Subject: [PATCH] apply possible number of racial attacks consequently --- src/battle.c | 6 ++++-- src/kernel/race.c | 4 +++- src/kernel/race.h | 4 +++- src/kernel/xmlreader.c | 10 ++++++++-- src/laws.c | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/battle.c b/src/battle.c index 1720e222a..1484ccfa3 100644 --- a/src/battle.c +++ b/src/battle.c @@ -2294,16 +2294,18 @@ void do_attack(fighter * af) /* Wir suchen eine beliebige Feind-Einheit aus. An der können * wir feststellen, ob noch jemand da ist. */ int apr, attacks = attacks_per_round(ta); + assert(attacks <= RACE_ATTACKS); if (!count_enemies(b, af, FIGHT_ROW, LAST_ROW, SELECT_FIND)) break; for (apr = 0; apr != attacks; ++apr) { int a; - for (a = 0; a != 10 && u_race(au)->attack[a].type != AT_NONE; ++a) { + for (a = 0; a < RACE_ATTACKS && u_race(au)->attack[a].type != AT_NONE; ++a) { if (apr > 0) { /* Wenn die Waffe nachladen muss, oder es sich nicht um einen * Waffen-Angriff handelt, dann gilt der Speed nicht. */ - if (u_race(au)->attack[a].type != AT_STANDARD) + /* FIXME allow multiple AT_NATURAL attacks? */ + if (u_race(au)->attack[a].type != AT_STANDARD) continue; else { weapon *wp = preferred_weapon(ta, true); diff --git a/src/kernel/race.c b/src/kernel/race.c index f577216db..81af9d9a1 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -169,6 +169,7 @@ const race * rc_find(const char *name) { race *rc_get_or_create(const char *zName) { race *rc; + int i; assert(zName); rc = rc_find_i(zName); @@ -191,7 +192,8 @@ race *rc_get_or_create(const char *zName) rc->precombatspell = NULL; rc->attack[0].type = AT_COMBATSPELL; - rc->attack[1].type = AT_NONE; + for (i = 1; i < RACE_ATTACKS; ++i) + rc->attack[i].type = AT_NONE; rc->index = num_races++; ++cache_breaker; rc->next = races; diff --git a/src/kernel/race.h b/src/kernel/race.h index d8246a382..a81853915 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -40,6 +40,8 @@ extern "C" { #define RACESPOILCHANCE 5 /* Chance auf rassentypische Beute */ +#define RACE_ATTACKS 10 /* maximum number of attacks */ + struct param; struct spell; @@ -145,7 +147,7 @@ extern "C" { int battle_flags; int ec_flags; race_t oldfamiliars[MAXMAGIETYP]; - struct att attack[10]; + struct att attack[RACE_ATTACKS]; signed char bonus[MAXSKILLS]; const char *(*generate_name) (const struct unit *); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index cd0969311..7179238ab 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1610,7 +1610,7 @@ static int parse_races(xmlDocPtr doc) xmlChar *propValue; race *rc; xmlXPathObjectPtr result; - int k, study_speed_base; + int k, study_speed_base, attacks; struct att *attack; propValue = xmlGetProp(node, BAD_CAST "name"); @@ -1838,10 +1838,16 @@ static int parse_races(xmlDocPtr doc) xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "attack", xpath); attack = rc->attack; + attacks = 0; for (k = 0; k != result->nodesetval->nodeNr; ++k) { xmlNodePtr node = result->nodesetval->nodeTab[k]; - while (attack->type != AT_NONE) + while (attack->type != AT_NONE) { ++attack; + if (attacks++ >= RACE_ATTACKS) { + log_error("too many attacks for race '%s'\n", rc->_name); + assert(!"aborting"); + } + } propValue = xmlGetProp(node, BAD_CAST "damage"); if (propValue != NULL) { diff --git a/src/laws.c b/src/laws.c index 9a1358733..28a08dca1 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2339,7 +2339,7 @@ static bool display_race(faction * f, unit * u, const race * rc) /* b_damage : Schaden */ at_count = 0; - for (a = 0; a < 6; a++) { + for (a = 0; a < RACE_ATTACKS; a++) { if (rc->attack[a].type != AT_NONE) { at_count++; } @@ -2371,7 +2371,7 @@ static bool display_race(faction * f, unit * u, const race * rc) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - for (a = 0; a < 6; a++) { + for (a = 0; a < RACE_ATTACKS; a++) { if (rc->attack[a].type != AT_NONE) { if (a != 0) bytes = (int)strlcpy(bufp, ", ", size);