Simplified the combat code, removing battle::fighters and putting things in lists rather than vectors.

Removed the unnecessary shuffling and sorting that takes quite some time.
Fixed a few bugs in ally-selection, I think.
This commit is contained in:
Enno Rehling 2006-04-13 17:16:15 +00:00
parent 50b94b730d
commit 4d8ed2c854
5 changed files with 1567 additions and 1491 deletions

View File

@ -106,7 +106,7 @@ attack_firesword(const troop * at, const struct weapon_type * wtype, int *casual
} }
do { do {
dt = select_enemy(fi->side->battle, fi, minrow, maxrow, true); dt = select_enemy(fi, minrow, maxrow, true);
assert(dt.fighter); assert(dt.fighter);
--force; --force;
killed += terminate(dt, *at, AT_SPELL, damage, 1); killed += terminate(dt, *at, AT_SPELL, damage, 1);
@ -167,7 +167,7 @@ attack_catapult(const troop * at, const struct weapon_type * wtype, int * casual
while (--n >= 0) { while (--n >= 0) {
/* Select defender */ /* Select defender */
dt = select_enemy(b, af, minrow, maxrow, true); dt = select_enemy(af, minrow, maxrow, true);
if (!dt.fighter) if (!dt.fighter)
break; break;

File diff suppressed because it is too large Load Diff

View File

@ -19,8 +19,6 @@ extern "C" {
#define SHOW_KILLS #define SHOW_KILLS
#undef SMALL_BATTLE_MESSAGES #undef SMALL_BATTLE_MESSAGES
#undef FIXED_OPPONENTS
#undef NO_RUNNING
/** more defines **/ /** more defines **/
#define FS_ENEMY 1 #define FS_ENEMY 1
@ -29,6 +27,7 @@ extern "C" {
/***** Verteidigungslinien. /***** Verteidigungslinien.
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen * Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen
*/ */
#define NUMROWS 5 #define NUMROWS 5
#define SUM_ROW 0 #define SUM_ROW 0
#define FIGHT_ROW 1 #define FIGHT_ROW 1
@ -37,6 +36,7 @@ extern "C" {
#define FLEE_ROW 4 #define FLEE_ROW 4
#define LAST_ROW (NUMROWS-1) #define LAST_ROW (NUMROWS-1)
#define FIRST_ROW FIGHT_ROW #define FIRST_ROW FIGHT_ROW
#define MAXSIDES 256 /* if there are ever more than this, we're fucked. */
struct message; struct message;
@ -50,21 +50,24 @@ extern "C" {
boolean attacker; boolean attacker;
} bfaction; } bfaction;
typedef struct battle { typedef struct battle {
cvector leaders; cvector leaders;
struct region *region; struct region *region;
struct plane *plane; struct plane *plane;
bfaction * factions; bfaction * factions;
int nfactions; int nfactions;
cvector fighters; int nfighters;
cvector sides; #if 0
struct fighter ** fighters;
#endif
struct side * sides;
cvector meffects; cvector meffects;
int max_tactics; int max_tactics;
int turn; int turn;
boolean has_tactics_turn; boolean has_tactics_turn;
int keeploot; int keeploot;
boolean reelarrow; boolean reelarrow;
int dh;
int alive; int alive;
#ifdef SMALL_BATTLE_MESSAGES #ifdef SMALL_BATTLE_MESSAGES
boolean small; boolean small;
@ -76,17 +79,22 @@ extern "C" {
int value; int value;
} tactics; } tactics;
#define SIDE_STEALTH 1<<0
#ifdef SIMPLE_COMBAT
#define SIDE_ATTACKER 1<<1
#endif
typedef struct side { typedef struct side {
struct tactics leader; /* der beste Taktiker des Heeres */ struct side * next; /* nächstes Heer in der Schlacht */
struct side * nextF; /* nächstes Heer der gleichen Partei */ struct side * nextF; /* nächstes Heer der gleichen Partei */
struct battle * battle; struct battle * battle;
struct bfaction * bf; /* Die Partei, die hier kämpft */ struct bfaction * bf; /* Die Partei, die hier kämpft */
const struct group * group; const struct group * group;
struct tactics leader; /* der beste Taktiker des Heeres */
# define E_ENEMY 1 # define E_ENEMY 1
# define E_ATTACKING 2 # define E_ATTACKING 2
int enemy[128]; unsigned char enemy[128];
struct side * enemies[128]; struct side * enemies[128];
cvector fighters; /* vector der Einheiten dieser Fraktion */ struct fighter * fighters;
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */ int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */ int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kämpfer, z.B. Schattenritter. */ int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kämpfer, z.B. Schattenritter. */
@ -96,8 +104,7 @@ extern "C" {
int dead; int dead;
int casualties; /* those dead that were real people, not undead! */ int casualties; /* those dead that were real people, not undead! */
int healed; int healed;
boolean dh; unsigned int flags;
boolean stealth; /* Die Einheiten sind getarnt */
const struct faction *stealthfaction; const struct faction *stealthfaction;
} side; } side;
@ -117,10 +124,6 @@ extern "C" {
#define FL_STUNNED 32 /* eine Runde keinen Angriff */ #define FL_STUNNED 32 /* eine Runde keinen Angriff */
#define FL_HIT 64 /* the person at attacked */ #define FL_HIT 64 /* the person at attacked */
/*** fighter::flags ***/
#define FIG_ATTACKED 1
#define FIG_NOLOOT 2
typedef struct troop { typedef struct troop {
struct fighter *fighter; struct fighter *fighter;
int index; int index;
@ -132,7 +135,11 @@ extern "C" {
int count; int count;
} armor; } armor;
/*** fighter::flags ***/
#define FIG_ATTACKER 1<<0
#define FIG_NOLOOT 1<<1
typedef struct fighter { typedef struct fighter {
struct fighter * next;
struct side *side; struct side *side;
struct unit *unit; /* Die Einheit, die hier kämpft */ struct unit *unit; /* Die Einheit, die hier kämpft */
struct building *building; /* Gebäude, in dem die Einheit evtl. steht */ struct building *building; /* Gebäude, in dem die Einheit evtl. steht */
@ -163,18 +170,13 @@ extern "C" {
int last_action : 4; /* In welcher Runde haben wir zuletzt etwas getan */ int last_action : 4; /* In welcher Runde haben wir zuletzt etwas getan */
struct weapon * missile; /* missile weapon */ struct weapon * missile; /* missile weapon */
struct weapon * melee; /* melee weapon */ struct weapon * melee; /* melee weapon */
#ifdef FIXED_OPPONENTS
struct troop opponent; /* default opponent */
#endif
} * person; } * person;
int flags; unsigned int flags;
struct { struct {
int number; /* number of people who have flown */ int number; /* number of people who have flown */
int hp; /* accumulated hp of fleeing people */ int hp; /* accumulated hp of fleeing people */
#ifndef NO_RUNNING
struct region *region; /* destination of fleeing people */ struct region *region; /* destination of fleeing people */
struct item * items; /* items they take */ struct item * items; /* items they take */
#endif
} run; } run;
#ifndef SIMPLE_COMBAT #ifndef SIMPLE_COMBAT
int action_counter; /* number of active actions the struct unit did in the fight */ int action_counter; /* number of active actions the struct unit did in the fight */
@ -208,7 +210,7 @@ extern "C" {
extern void do_battle(void); extern void do_battle(void);
/* for combar spells and special attacks */ /* for combar spells and special attacks */
extern troop select_enemy(struct battle * b, struct fighter * af, int minrow, int maxrow, boolean advance); extern troop select_enemy(struct fighter * af, int minrow, int maxrow, boolean advance);
extern int count_enemies(struct battle * b, struct side * as, int minrow, int maxrow, boolean advance); extern int count_enemies(struct battle * b, struct side * as, int minrow, int maxrow, boolean advance);
extern boolean terminate(troop dt, troop at, int type, const char *damage, boolean missile); extern boolean terminate(troop dt, troop at, int type, const char *damage, boolean missile);
extern void battlemsg(battle * b, struct unit * u, const char * s); extern void battlemsg(battle * b, struct unit * u, const char * s);
@ -218,7 +220,7 @@ extern "C" {
extern int hits(troop at, troop dt, weapon * awp); extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg, int damage_abs); extern void damage_building(struct battle *b, struct building *bldg, int damage_abs);
extern struct cvector * fighters(struct battle *b, struct fighter *af, int minrow, int maxrow, int mask); extern struct cvector * fighters(struct battle *b, struct fighter *af, int minrow, int maxrow, int mask);
extern int countallies(struct side * as); extern int count_allies(struct side * as, int minrow, int maxrow, boolean advance);
extern int get_unitrow(const struct fighter * af); extern int get_unitrow(const struct fighter * af);
extern boolean helping(struct side * as, struct side * ds); extern boolean helping(struct side * as, struct side * ds);
extern void rmfighter(fighter *df, int i); extern void rmfighter(fighter *df, int i);
@ -228,6 +230,7 @@ extern "C" {
extern int statusrow(int status); extern int statusrow(int status);
extern void drain_exp(struct unit *u, int d); extern void drain_exp(struct unit *u, int d);
extern void rmtroop(troop dt); extern void rmtroop(troop dt);
extern boolean is_attacker(const fighter * fig);
#ifdef __cplusplus #ifdef __cplusplus
} }

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,6 @@ Code cleanup:
Larger Features: Larger Features:
- eressea (b/g)zip reports? - eressea (b/g)zip reports?
- NO_RUNNING
- ZERSTÖRE - Man sollte alle Materialien zurückkriegen können: - ZERSTÖRE - Man sollte alle Materialien zurückkriegen können:
Scripts, etc: Scripts, etc: