Merge pull request #185 from stm2/race_attacks

apply possible number of racial attacks consistently
This commit is contained in:
Enno Rehling 2015-05-08 09:30:54 -07:00
commit ac2099aa0f
5 changed files with 20 additions and 8 deletions

View File

@ -2294,16 +2294,18 @@ void do_attack(fighter * af)
/* Wir suchen eine beliebige Feind-Einheit aus. An der können /* Wir suchen eine beliebige Feind-Einheit aus. An der können
* wir feststellen, ob noch jemand da ist. */ * wir feststellen, ob noch jemand da ist. */
int apr, attacks = attacks_per_round(ta); int apr, attacks = attacks_per_round(ta);
assert(attacks <= RACE_ATTACKS);
if (!count_enemies(b, af, FIGHT_ROW, LAST_ROW, SELECT_FIND)) if (!count_enemies(b, af, FIGHT_ROW, LAST_ROW, SELECT_FIND))
break; break;
for (apr = 0; apr != attacks; ++apr) { for (apr = 0; apr != attacks; ++apr) {
int a; 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) { if (apr > 0) {
/* Wenn die Waffe nachladen muss, oder es sich nicht um einen /* Wenn die Waffe nachladen muss, oder es sich nicht um einen
* Waffen-Angriff handelt, dann gilt der Speed nicht. */ * 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; continue;
else { else {
weapon *wp = preferred_weapon(ta, true); weapon *wp = preferred_weapon(ta, true);

View File

@ -169,6 +169,7 @@ const race * rc_find(const char *name) {
race *rc_get_or_create(const char *zName) race *rc_get_or_create(const char *zName)
{ {
race *rc; race *rc;
int i;
assert(zName); assert(zName);
rc = rc_find_i(zName); rc = rc_find_i(zName);
@ -191,7 +192,8 @@ race *rc_get_or_create(const char *zName)
rc->precombatspell = NULL; rc->precombatspell = NULL;
rc->attack[0].type = AT_COMBATSPELL; 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++; rc->index = num_races++;
++cache_breaker; ++cache_breaker;
rc->next = races; rc->next = races;

View File

@ -40,6 +40,8 @@ extern "C" {
#define RACESPOILCHANCE 5 /* Chance auf rassentypische Beute */ #define RACESPOILCHANCE 5 /* Chance auf rassentypische Beute */
#define RACE_ATTACKS 10 /* maximum number of attacks */
struct param; struct param;
struct spell; struct spell;
@ -145,7 +147,7 @@ extern "C" {
int battle_flags; int battle_flags;
int ec_flags; int ec_flags;
race_t oldfamiliars[MAXMAGIETYP]; race_t oldfamiliars[MAXMAGIETYP];
struct att attack[10]; struct att attack[RACE_ATTACKS];
signed char bonus[MAXSKILLS]; signed char bonus[MAXSKILLS];
const char *(*generate_name) (const struct unit *); const char *(*generate_name) (const struct unit *);

View File

@ -1610,7 +1610,7 @@ static int parse_races(xmlDocPtr doc)
xmlChar *propValue; xmlChar *propValue;
race *rc; race *rc;
xmlXPathObjectPtr result; xmlXPathObjectPtr result;
int k, study_speed_base; int k, study_speed_base, attacks;
struct att *attack; struct att *attack;
propValue = xmlGetProp(node, BAD_CAST "name"); propValue = xmlGetProp(node, BAD_CAST "name");
@ -1838,10 +1838,16 @@ static int parse_races(xmlDocPtr doc)
xpath->node = node; xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "attack", xpath); result = xmlXPathEvalExpression(BAD_CAST "attack", xpath);
attack = rc->attack; attack = rc->attack;
attacks = 0;
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];
while (attack->type != AT_NONE) while (attack->type != AT_NONE) {
++attack; ++attack;
if (attacks++ >= RACE_ATTACKS) {
log_error("too many attacks for race '%s'\n", rc->_name);
assert(!"aborting");
}
}
propValue = xmlGetProp(node, BAD_CAST "damage"); propValue = xmlGetProp(node, BAD_CAST "damage");
if (propValue != NULL) { if (propValue != NULL) {

View File

@ -2339,7 +2339,7 @@ static bool display_race(faction * f, unit * u, const race * rc)
/* b_damage : Schaden */ /* b_damage : Schaden */
at_count = 0; at_count = 0;
for (a = 0; a < 6; a++) { for (a = 0; a < RACE_ATTACKS; a++) {
if (rc->attack[a].type != AT_NONE) { if (rc->attack[a].type != AT_NONE) {
at_count++; at_count++;
} }
@ -2371,7 +2371,7 @@ static bool display_race(faction * f, unit * u, const race * rc)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
for (a = 0; a < 6; a++) { for (a = 0; a < RACE_ATTACKS; a++) {
if (rc->attack[a].type != AT_NONE) { if (rc->attack[a].type != AT_NONE) {
if (a != 0) if (a != 0)
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)strlcpy(bufp, ", ", size);