2010-08-08 10:06:34 +02:00
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2015-01-30 20:37:14 +01:00
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef H_KRNL_BATTLE
|
|
|
|
#define H_KRNL_BATTLE
|
2014-11-01 12:57:01 +01:00
|
|
|
|
|
|
|
#include <kernel/types.h>
|
2017-01-10 16:31:05 +01:00
|
|
|
#include <stdbool.h>
|
2014-11-01 12:57:01 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-26 17:41:21 +01:00
|
|
|
struct message;
|
|
|
|
struct selist;
|
2018-02-15 20:25:58 +01:00
|
|
|
union variant;
|
2017-01-26 17:41:21 +01:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/** more defines **/
|
2010-08-08 10:06:34 +02:00
|
|
|
#define FS_ENEMY 1
|
|
|
|
#define FS_HELP 2
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/***** Verteidigungslinien.
|
2016-11-20 18:09:08 +01:00
|
|
|
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthaelt Summen
|
2015-01-30 20:37:14 +01:00
|
|
|
*/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#define NUMROWS 5
|
|
|
|
#define SUM_ROW 0
|
|
|
|
#define FIGHT_ROW 1
|
|
|
|
#define BEHIND_ROW 2
|
|
|
|
#define AVOID_ROW 3
|
|
|
|
#define FLEE_ROW 4
|
|
|
|
#define FIRST_ROW FIGHT_ROW
|
2015-11-05 11:08:55 +01:00
|
|
|
#define LAST_ROW FLEE_ROW
|
2011-03-07 08:02:35 +01:00
|
|
|
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct bfaction {
|
|
|
|
struct bfaction *next;
|
|
|
|
struct side *sides;
|
|
|
|
struct faction *faction;
|
|
|
|
bool attacker;
|
|
|
|
} bfaction;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct tactics {
|
2017-01-26 17:41:21 +01:00
|
|
|
struct selist *fighters;
|
2015-01-30 20:37:14 +01:00
|
|
|
int value;
|
|
|
|
} tactics;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#define SIDE_STEALTH 1<<0
|
|
|
|
#define SIDE_HASGUARDS 1<<1
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct side {
|
|
|
|
struct side *nextF; /* next army of same faction */
|
|
|
|
struct battle *battle;
|
|
|
|
struct bfaction *bf; /* battle info that goes with the faction */
|
|
|
|
struct faction *faction; /* cache optimization for bf->faction */
|
|
|
|
const struct group *group;
|
|
|
|
struct tactics leader; /* this army's best tactician */
|
2010-08-08 10:06:34 +02:00
|
|
|
# define E_ENEMY 1
|
|
|
|
# define E_FRIEND 2
|
|
|
|
# define E_ATTACKING 4
|
2015-01-30 20:37:14 +01:00
|
|
|
unsigned char relations[MAXSIDES];
|
|
|
|
struct side *enemies[MAXSIDES];
|
|
|
|
struct fighter *fighters;
|
2016-11-23 18:56:40 +01:00
|
|
|
unsigned int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
2015-01-30 20:37:14 +01:00
|
|
|
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
|
2016-11-20 18:09:08 +01:00
|
|
|
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kaempfer, z.B. Schattenritter. */
|
2015-01-30 20:37:14 +01:00
|
|
|
int alive; /* Die Partei hat den Kampf verlassen */
|
|
|
|
int removed; /* stoned */
|
|
|
|
int flee;
|
|
|
|
int dead;
|
|
|
|
int casualties; /* those dead that were real people, not undead! */
|
|
|
|
int healed;
|
|
|
|
unsigned int flags;
|
|
|
|
const struct faction *stealthfaction;
|
|
|
|
} side;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct battle {
|
2017-01-26 17:41:21 +01:00
|
|
|
struct selist *leaders;
|
2015-01-30 20:37:14 +01:00
|
|
|
struct region *region;
|
|
|
|
struct plane *plane;
|
|
|
|
bfaction *factions;
|
|
|
|
int nfactions;
|
|
|
|
int nfighters;
|
|
|
|
side sides[MAXSIDES];
|
|
|
|
int nsides;
|
2017-01-26 17:41:21 +01:00
|
|
|
struct selist *meffects;
|
2015-01-30 20:37:14 +01:00
|
|
|
int max_tactics;
|
|
|
|
int turn;
|
|
|
|
bool has_tactics_turn;
|
|
|
|
int keeploot;
|
|
|
|
bool reelarrow;
|
|
|
|
int alive;
|
|
|
|
struct {
|
|
|
|
const struct side *as;
|
|
|
|
const struct side *vs;
|
|
|
|
int alive;
|
|
|
|
int row;
|
|
|
|
int result;
|
|
|
|
} rowcache;
|
|
|
|
struct {
|
|
|
|
struct side *side;
|
|
|
|
int status;
|
|
|
|
int alive;
|
|
|
|
int minrow, maxrow;
|
|
|
|
int enemies[8];
|
|
|
|
} fast;
|
|
|
|
} battle;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct weapon {
|
|
|
|
int count, used;
|
|
|
|
const struct weapon_type *type;
|
|
|
|
int attackskill;
|
|
|
|
int defenseskill;
|
|
|
|
} weapon;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/*** fighter::person::flags ***/
|
2015-06-26 14:31:21 +02:00
|
|
|
#define FL_TIRED 1
|
2016-11-20 18:09:08 +01:00
|
|
|
#define FL_DAZZLED 2 /* durch Untote oder Daemonen eingeschuechtert */
|
2010-08-08 10:06:34 +02:00
|
|
|
#define FL_PANICED 4
|
2011-03-07 08:02:35 +01:00
|
|
|
#define FL_COURAGE 8 /* Helden fliehen nie */
|
2010-08-08 10:06:34 +02:00
|
|
|
#define FL_SLEEPING 16
|
2015-06-26 14:31:21 +02:00
|
|
|
#define FL_STUNNED 32 /* eine Runde keinen Angriff */
|
|
|
|
#define FL_HIT 64 /* the person at attacked */
|
2016-06-12 21:54:42 +02:00
|
|
|
#define FL_HEALING_USED 128 /* has used a healing potion */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct troop {
|
|
|
|
struct fighter *fighter;
|
|
|
|
int index;
|
|
|
|
} troop;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct armor {
|
2018-04-29 15:24:36 +02:00
|
|
|
struct armor *next; /* TODO: make this an array, not a list, like weapon */
|
2015-01-30 20:37:14 +01:00
|
|
|
const struct armor_type *atype;
|
|
|
|
int count;
|
|
|
|
} armor;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/*** fighter::flags ***/
|
2010-08-08 10:06:34 +02:00
|
|
|
#define FIG_ATTACKER 1<<0
|
|
|
|
#define FIG_NOLOOT 1<<1
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct fighter {
|
|
|
|
struct fighter *next;
|
|
|
|
struct side *side;
|
2016-11-20 18:09:08 +01:00
|
|
|
struct unit *unit; /* Die Einheit, die hier kaempft */
|
|
|
|
struct building *building; /* Gebaeude, in dem die Einheit evtl. steht */
|
2015-01-30 20:37:14 +01:00
|
|
|
status_t status; /* Kampfstatus */
|
|
|
|
struct weapon *weapons;
|
2016-11-20 18:09:08 +01:00
|
|
|
struct armor *armors; /* Anzahl Ruestungen jeden Typs */
|
2015-01-30 20:37:14 +01:00
|
|
|
int alive; /* Anzahl der noch nicht Toten in der Einheit */
|
2016-11-20 18:09:08 +01:00
|
|
|
int fighting; /* Anzahl der Kaempfer in der aktuellen Runde */
|
2015-01-30 20:37:14 +01:00
|
|
|
int removed; /* Anzahl Kaempfer, die nicht tot sind, aber
|
|
|
|
aus dem Kampf raus sind (zB weil sie
|
|
|
|
versteinert wurden). Diese werden auch
|
2016-11-20 18:09:08 +01:00
|
|
|
in alive noch mitgezaehlt! */
|
2015-01-30 20:37:14 +01:00
|
|
|
int magic; /* Magietalent der Einheit */
|
|
|
|
int horses; /* Anzahl brauchbarer Pferde der Einheit */
|
|
|
|
int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */
|
|
|
|
struct item *loot;
|
|
|
|
int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */
|
|
|
|
struct person {
|
|
|
|
int hp; /* Trefferpunkte der Personen */
|
|
|
|
int attack;
|
2018-10-13 20:30:28 +02:00
|
|
|
int defense;
|
2015-01-30 20:37:14 +01:00
|
|
|
int damage;
|
|
|
|
int flags;
|
|
|
|
int speed;
|
|
|
|
int reload;
|
|
|
|
int last_action;
|
|
|
|
struct weapon *missile; /* missile weapon */
|
|
|
|
struct weapon *melee; /* melee weapon */
|
|
|
|
} *person;
|
|
|
|
unsigned int flags;
|
|
|
|
struct {
|
|
|
|
int number; /* number of people who fled */
|
|
|
|
int hp; /* accumulated hp of fleeing people */
|
|
|
|
} run;
|
|
|
|
int kills;
|
|
|
|
int hits;
|
|
|
|
} fighter;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/* schilde */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
enum {
|
|
|
|
SHIELD_REDUCE,
|
|
|
|
SHIELD_ARMOR,
|
|
|
|
SHIELD_WIND,
|
|
|
|
SHIELD_BLOCK,
|
|
|
|
SHIELD_MAX
|
|
|
|
};
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
typedef struct meffect {
|
|
|
|
fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */
|
|
|
|
int typ; /* Wirkungsweise des Schilds */
|
|
|
|
int effect;
|
|
|
|
int duration;
|
|
|
|
} meffect;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
extern const troop no_troop;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/* BEGIN battle interface */
|
2015-05-12 23:28:25 +02:00
|
|
|
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
|
2015-01-30 20:37:14 +01:00
|
|
|
side * get_side(battle * b, const struct unit * u);
|
|
|
|
fighter * get_fighter(battle * b, const struct unit * u);
|
|
|
|
/* END battle interface */
|
2012-06-27 05:29:32 +02:00
|
|
|
|
2017-05-21 12:26:04 +02:00
|
|
|
void do_battles(void);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
/* for combat spells and special attacks */
|
|
|
|
enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 };
|
|
|
|
enum { ALLY_SELF, ALLY_ANY };
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-05-21 12:26:04 +02:00
|
|
|
int get_unitrow(const fighter * af, const side * vs);
|
|
|
|
|
|
|
|
troop select_enemy(struct fighter *af, int minrow, int maxrow,
|
2015-01-30 20:37:14 +01:00
|
|
|
int select);
|
2017-05-21 12:26:04 +02:00
|
|
|
troop select_ally(struct fighter *af, int minrow, int maxrow,
|
2015-01-30 20:37:14 +01:00
|
|
|
int allytype);
|
|
|
|
|
2015-11-03 14:22:50 +01:00
|
|
|
int count_enemies(struct battle *b, const struct fighter *af,
|
2015-01-30 20:37:14 +01:00
|
|
|
int minrow, int maxrow, int select);
|
2015-11-21 19:02:14 +01:00
|
|
|
int natural_armor(struct unit * u);
|
2018-09-11 17:17:47 +02:00
|
|
|
const struct armor_type *select_armor(struct troop t, bool shield);
|
|
|
|
struct weapon *select_weapon(const struct troop t, bool attacking, bool ismissile);
|
|
|
|
int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, const struct armor_type *armor, const struct armor_type *shield, bool magic);
|
2018-09-12 09:37:22 +02:00
|
|
|
int apply_resistance(int damage, struct troop dt, const struct weapon_type *dwtype, const struct armor_type *armor, const struct armor_type *shield, bool magic);
|
2015-11-03 14:22:50 +01:00
|
|
|
bool terminate(troop dt, troop at, int type, const char *damage,
|
2015-01-30 20:37:14 +01:00
|
|
|
bool missile);
|
2017-05-21 12:26:04 +02:00
|
|
|
void message_all(battle * b, struct message *m);
|
|
|
|
int hits(troop at, troop dt, weapon * awp);
|
|
|
|
void damage_building(struct battle *b, struct building *bldg,
|
2015-01-30 20:37:14 +01:00
|
|
|
int damage_abs);
|
2017-05-21 12:26:04 +02:00
|
|
|
|
|
|
|
typedef bool(*select_fun)(const struct side *vs, const struct fighter *fig, void *cbdata);
|
|
|
|
struct selist *select_fighters(struct battle *b, const struct side *vs, int mask, select_fun cb, void *cbdata);
|
2017-01-26 17:41:21 +01:00
|
|
|
struct selist *fighters(struct battle *b, const struct side *vs,
|
2015-01-30 20:37:14 +01:00
|
|
|
int minrow, int maxrow, int mask);
|
2017-05-21 12:26:04 +02:00
|
|
|
|
2015-05-30 17:29:01 +02:00
|
|
|
int count_allies(const struct side *as, int minrow, int maxrow,
|
2015-01-30 20:37:14 +01:00
|
|
|
int select, int allytype);
|
2017-05-21 12:26:04 +02:00
|
|
|
bool helping(const struct side *as, const struct side *ds);
|
|
|
|
void rmfighter(fighter * df, int i);
|
|
|
|
struct fighter *select_corpse(struct battle *b, struct fighter *af);
|
|
|
|
int statusrow(int status);
|
|
|
|
void drain_exp(struct unit *u, int d);
|
|
|
|
void kill_troop(troop dt);
|
|
|
|
void remove_troop(troop dt); /* not the same as the badly named rmtroop */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 11:13:25 +01:00
|
|
|
bool is_attacker(const fighter * fig);
|
|
|
|
struct battle *make_battle(struct region * r);
|
|
|
|
void free_battle(struct battle * b);
|
|
|
|
struct fighter *make_fighter(struct battle *b, struct unit *u,
|
2015-01-30 20:37:14 +01:00
|
|
|
struct side * s, bool attack);
|
2018-07-15 13:39:23 +02:00
|
|
|
int join_battle(struct battle * b, struct unit * u, bool attack, struct fighter ** cp);
|
2014-12-12 11:13:25 +01:00
|
|
|
struct side *make_side(struct battle * b, const struct faction * f,
|
2015-01-30 20:37:14 +01:00
|
|
|
const struct group * g, unsigned int flags,
|
|
|
|
const struct faction * stealthfaction);
|
2014-12-12 11:13:25 +01:00
|
|
|
int skilldiff(troop at, troop dt, int dist);
|
2015-06-26 14:31:21 +02:00
|
|
|
void force_leave(struct region *r, struct battle *b);
|
2017-12-31 15:05:49 +01:00
|
|
|
bool seematrix(const struct faction * f, const struct side * s);
|
|
|
|
const char *sidename(const struct side * s);
|
|
|
|
void battle_message_faction(struct battle * b, struct faction * f, struct message *m);
|
2011-03-13 02:01:20 +01:00
|
|
|
|
2018-05-03 23:00:28 +02:00
|
|
|
double tactics_chance(const struct unit *u, int skilldiff);
|
2010-08-08 10:06:34 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|