forked from github/server
export more battle functions for e4 combat
alliances have lists of diplomatic relations (enemies)
This commit is contained in:
parent
f893ea03b6
commit
5e3ce7ad4d
|
@ -40,6 +40,8 @@ extern "C" {
|
||||||
|
|
||||||
#define ALF_NON_ALLIED (1<<0) /* this alliance is just a default for a non-allied faction */
|
#define ALF_NON_ALLIED (1<<0) /* this alliance is just a default for a non-allied faction */
|
||||||
|
|
||||||
|
#define ALLY_ENEMY (1<<0)
|
||||||
|
|
||||||
typedef struct alliance {
|
typedef struct alliance {
|
||||||
struct alliance *next;
|
struct alliance *next;
|
||||||
struct faction *_leader;
|
struct faction *_leader;
|
||||||
|
@ -47,6 +49,7 @@ extern "C" {
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int id;
|
int id;
|
||||||
char *name;
|
char *name;
|
||||||
|
struct ally *allies;
|
||||||
} alliance;
|
} alliance;
|
||||||
|
|
||||||
extern alliance *alliances;
|
extern alliance *alliances;
|
||||||
|
|
|
@ -3137,6 +3137,45 @@ static int weapon_weight(const weapon * w, bool missile)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
side * get_side(battle * b, const const unit * u)
|
||||||
|
{
|
||||||
|
side * s;
|
||||||
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
|
if (s->faction==u->faction) {
|
||||||
|
fighter * fig;
|
||||||
|
for (fig=s->fighters;fig;fig=fig->next) {
|
||||||
|
if (fig->unit==u) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
side * find_side(battle * b, const faction * f, const group * g, int flags, const faction * stealthfaction)
|
||||||
|
{
|
||||||
|
side * s;
|
||||||
|
static int rule_anon_battle = -1;
|
||||||
|
|
||||||
|
if (rule_anon_battle < 0) {
|
||||||
|
rule_anon_battle = get_param_int(global.parameters, "rules.stealth.anon_battle", 1);
|
||||||
|
}
|
||||||
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
|
if (s->faction == f && s->group == g) {
|
||||||
|
int s1flags = flags | SIDE_HASGUARDS;
|
||||||
|
int s2flags = s->flags | SIDE_HASGUARDS;
|
||||||
|
if (rule_anon_battle && s->stealthfaction != stealthfaction) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (s1flags == s2flags) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
{
|
{
|
||||||
#define WMAX 20
|
#define WMAX 20
|
||||||
|
@ -3147,9 +3186,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
region *r = b->region;
|
region *r = b->region;
|
||||||
item *itm;
|
item *itm;
|
||||||
fighter *fig = NULL;
|
fighter *fig = NULL;
|
||||||
int i, tactics = eff_skill(u, SK_TACTICS, r);
|
int h, i, tactics = eff_skill(u, SK_TACTICS, r);
|
||||||
side *s2;
|
|
||||||
int h;
|
|
||||||
int berserk;
|
int berserk;
|
||||||
int strongmen;
|
int strongmen;
|
||||||
int speeded = 0, speed = 1;
|
int speeded = 0, speed = 1;
|
||||||
|
@ -3159,14 +3196,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
const attrib *a = a_find(u->attribs, &at_otherfaction);
|
const attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||||
const faction *stealthfaction = a ? get_otherfaction(a) : NULL;
|
const faction *stealthfaction = a ? get_otherfaction(a) : NULL;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
static int rule_anon_battle = -1;
|
|
||||||
|
|
||||||
assert(u->number);
|
assert(u->number);
|
||||||
|
|
||||||
if (rule_anon_battle < 0) {
|
|
||||||
rule_anon_battle =
|
|
||||||
get_param_int(global.parameters, "rules.stealth.anon_battle", 1);
|
|
||||||
}
|
|
||||||
if (fval(u, UFL_ANON_FACTION) != 0)
|
if (fval(u, UFL_ANON_FACTION) != 0)
|
||||||
flags |= SIDE_STEALTH;
|
flags |= SIDE_STEALTH;
|
||||||
if (!(AllianceAuto() & HELP_FIGHT) && fval(u, UFL_GROUP)) {
|
if (!(AllianceAuto() & HELP_FIGHT) && fval(u, UFL_GROUP)) {
|
||||||
|
@ -3180,20 +3211,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (s1 == NULL) {
|
if (s1 == NULL) {
|
||||||
for (s2 = b->sides; s2 != b->sides + b->nsides; ++s2) {
|
s1 = find_side(b, u->faction, g, flags, stealthfaction);
|
||||||
if (s2->faction == u->faction && s2->group == g) {
|
|
||||||
int s1flags = flags | SIDE_HASGUARDS;
|
|
||||||
int s2flags = s2->flags | SIDE_HASGUARDS;
|
|
||||||
if (rule_anon_battle && s2->stealthfaction != stealthfaction) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (s1flags == s2flags) {
|
|
||||||
s1 = s2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* aliances are moved out of make_fighter and will be handled later */
|
/* aliances are moved out of make_fighter and will be handled later */
|
||||||
if (!s1) {
|
if (!s1) {
|
||||||
s1 = make_side(b, u->faction, g, flags, stealthfaction);
|
s1 = make_side(b, u->faction, g, flags, stealthfaction);
|
||||||
|
@ -3459,6 +3477,23 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
return fig;
|
return fig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fighter * get_fighter(battle * b, const struct unit * u)
|
||||||
|
{
|
||||||
|
side * s;
|
||||||
|
|
||||||
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
|
fighter *fig;
|
||||||
|
if (s->faction == u->faction) {
|
||||||
|
for (fig = s->fighters; fig; fig = fig->next) {
|
||||||
|
if (fig->unit == u) {
|
||||||
|
return fig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
||||||
{
|
{
|
||||||
side *s;
|
side *s;
|
||||||
|
|
|
@ -114,9 +114,6 @@ extern "C" {
|
||||||
} fast;
|
} fast;
|
||||||
} battle;
|
} battle;
|
||||||
|
|
||||||
void battle_init(battle * b);
|
|
||||||
void battle_free(battle * b);
|
|
||||||
|
|
||||||
typedef struct weapon {
|
typedef struct weapon {
|
||||||
int count, used;
|
int count, used;
|
||||||
const struct weapon_type *type;
|
const struct weapon_type *type;
|
||||||
|
@ -208,6 +205,14 @@ extern "C" {
|
||||||
|
|
||||||
extern const troop no_troop;
|
extern const troop no_troop;
|
||||||
|
|
||||||
|
/* BEGIN battle interface */
|
||||||
|
void battle_init(battle * b);
|
||||||
|
void battle_free(battle * b);
|
||||||
|
side * find_side(battle * b, const struct faction * f, const struct group * g, int flags, const struct faction * stealthfaction);
|
||||||
|
side * get_side(battle * b, const struct unit * u);
|
||||||
|
fighter * get_fighter(battle * b, const struct unit * u);
|
||||||
|
/* END battle interface */
|
||||||
|
|
||||||
extern void do_battle(struct region *r);
|
extern void do_battle(struct region *r);
|
||||||
|
|
||||||
/* for combat spells and special attacks */
|
/* for combat spells and special attacks */
|
||||||
|
|
|
@ -119,6 +119,8 @@ extern "C" {
|
||||||
int status;
|
int status;
|
||||||
} ally;
|
} ally;
|
||||||
|
|
||||||
|
ally * ally_find(const ally *al, const struct faction *f);
|
||||||
|
|
||||||
void remove_empty_units_in_region(struct region *r);
|
void remove_empty_units_in_region(struct region *r);
|
||||||
void remove_empty_units(void);
|
void remove_empty_units(void);
|
||||||
void remove_empty_factions(void);
|
void remove_empty_factions(void);
|
||||||
|
|
|
@ -125,7 +125,7 @@ extern "C" {
|
||||||
extern void set_alliance(struct faction *a, struct faction *b, int status);
|
extern void set_alliance(struct faction *a, struct faction *b, int status);
|
||||||
extern int get_alliance(const struct faction *a, const struct faction *b);
|
extern int get_alliance(const struct faction *a, const struct faction *b);
|
||||||
|
|
||||||
extern struct alliance *f_get_alliance(const struct faction *a);
|
extern struct alliance *f_get_alliance(const struct faction *f);
|
||||||
|
|
||||||
extern void write_faction_reference(const struct faction *f,
|
extern void write_faction_reference(const struct faction *f,
|
||||||
struct storage *store);
|
struct storage *store);
|
||||||
|
|
|
@ -394,10 +394,6 @@ typedef enum {
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/* Prototypen */
|
/* Prototypen */
|
||||||
|
|
||||||
#define ALLIED_TAX 1
|
|
||||||
#define ALLIED_NOBLOCK 2
|
|
||||||
#define ALLIED_HELP 4
|
|
||||||
|
|
||||||
/* alle vierstelligen zahlen: */
|
/* alle vierstelligen zahlen: */
|
||||||
#define MAX_UNIT_NR (36*36*36*36-1)
|
#define MAX_UNIT_NR (36*36*36*36-1)
|
||||||
#define MAX_CONTAINER_NR (36*36*36*36-1)
|
#define MAX_CONTAINER_NR (36*36*36*36-1)
|
||||||
|
|
Loading…
Reference in New Issue