forked from github/server
simplicate the use of ally.c
This commit is contained in:
parent
557c624200
commit
ac3a4d91c9
44
src/battle.c
44
src/battle.c
|
@ -281,19 +281,15 @@ static void set_friendly(side * as, side * ds)
|
||||||
as->relations[ds->index] |= E_FRIEND;
|
as->relations[ds->index] |= E_FRIEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int allysfm(const side * s, const faction * f, int mode)
|
static bool alliedside(const side * s, const faction * f, int mode)
|
||||||
{
|
{
|
||||||
if (s->faction == f)
|
if (s->faction == f) {
|
||||||
return mode;
|
return true;
|
||||||
if (s->group) {
|
|
||||||
return alliedgroup(s->battle->plane, s->faction, f, s->group->allies, mode);
|
|
||||||
}
|
}
|
||||||
return alliedfaction(s->battle->plane, s->faction, f, mode);
|
if (s->group) {
|
||||||
}
|
return alliedgroup(s->faction, f, s->group, mode) != 0;
|
||||||
|
}
|
||||||
static int allysf(const side * s, const faction * f)
|
return alliedfaction(s->faction, f, mode) != 0;
|
||||||
{
|
|
||||||
return allysfm(s, f, HELP_FIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dead_fighters(const fighter * df)
|
static int dead_fighters(const fighter * df)
|
||||||
|
@ -313,7 +309,7 @@ fighter *select_corpse(battle * b, fighter * af)
|
||||||
|
|
||||||
for (si = 0; si != b->nsides; ++si) {
|
for (si = 0; si != b->nsides; ++si) {
|
||||||
side *s = b->sides + si;
|
side *s = b->sides + si;
|
||||||
if (af == NULL || (!enemy_i(af->side, si) && allysf(af->side, s->faction))) {
|
if (af == NULL || (!enemy_i(af->side, si) && alliedside(af->side, s->faction, HELP_FIGHT))) {
|
||||||
maxcasualties += s->casualties;
|
maxcasualties += s->casualties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,7 +340,7 @@ bool helping(const side * as, const side * ds)
|
||||||
{
|
{
|
||||||
if (as->faction == ds->faction)
|
if (as->faction == ds->faction)
|
||||||
return true;
|
return true;
|
||||||
return (bool)(!enemy(as, ds) && allysf(as, ds->faction));
|
return (bool)(!enemy(as, ds) && alliedside(as, ds->faction, HELP_FIGHT));
|
||||||
}
|
}
|
||||||
|
|
||||||
int statusrow(int status)
|
int statusrow(int status)
|
||||||
|
@ -832,7 +828,7 @@ bool meffect_protection(battle * b, meffect * s, side * ds)
|
||||||
return false;
|
return false;
|
||||||
if (enemy(s->magician->side, ds))
|
if (enemy(s->magician->side, ds))
|
||||||
return false;
|
return false;
|
||||||
if (allysf(s->magician->side, ds->faction))
|
if (alliedside(s->magician->side, ds->faction, HELP_FIGHT))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1654,7 +1650,7 @@ selist *select_fighters(battle * b, const side * vs, int mask, select_fun cb, vo
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (mask == FS_HELP) {
|
else if (mask == FS_HELP) {
|
||||||
if (enemy(s, vs) || !allysf(s, vs->faction)) {
|
if (enemy(s, vs) || !alliedside(s, vs->faction, HELP_FIGHT)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3636,7 +3632,7 @@ static void join_allies(battle * b)
|
||||||
* vorgespiegelt wird, und er sich uns gegen<EFBFBD>ber nicht zu
|
* vorgespiegelt wird, und er sich uns gegen<EFBFBD>ber nicht zu
|
||||||
* erkennen gibt, helfen wir ihm nicht */
|
* erkennen gibt, helfen wir ihm nicht */
|
||||||
if (s->stealthfaction) {
|
if (s->stealthfaction) {
|
||||||
if (!allysfm(s, u->faction, HELP_FSTEALTH)) {
|
if (!alliedside(s, u->faction, HELP_FSTEALTH)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3690,19 +3686,15 @@ static void join_allies(battle * b)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sa = s + 1; sa != b->sides + b->nsides; ++sa) {
|
for (sa = s + 1; sa != b->sides + b->nsides; ++sa) {
|
||||||
plane *pl = rplane(r);
|
if (!enemy(s, sa) && !friendly(s, sa)) {
|
||||||
if (enemy(s, sa))
|
if (alliedfaction(f, sa->faction, HELP_FIGHT)) {
|
||||||
continue;
|
if (alliedfaction(sa->faction, f, HELP_FIGHT)) {
|
||||||
if (friendly(s, sa))
|
|
||||||
continue;
|
|
||||||
if (!alliedgroup(pl, f, sa->faction, f->allies, HELP_FIGHT))
|
|
||||||
continue;
|
|
||||||
if (!alliedgroup(pl, sa->faction, f, sa->faction->allies, HELP_FIGHT))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
set_friendly(s, sa);
|
set_friendly(s, sa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flee(const troop dt)
|
static void flee(const troop dt)
|
||||||
|
|
|
@ -1021,15 +1021,16 @@ static void cr_output_unit_compat(FILE * F, const faction * f,
|
||||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||||
|
|
||||||
/* prints allies */
|
/* prints allies */
|
||||||
static void show_allies_cr(FILE * F, const faction * f, const ally * sf)
|
static void show_allies_cr(FILE * F, const faction * f, const group *g)
|
||||||
{
|
{
|
||||||
|
ally * sf = g ? g->allies : f->allies;
|
||||||
for (; sf; sf = sf->next)
|
for (; sf; sf = sf->next)
|
||||||
if (sf->faction) {
|
if (sf->faction && faction_alive(sf->faction)) {
|
||||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
int mode = alliedgroup(f, sf->faction, g, HELP_ALL);
|
||||||
if (mode != 0 && sf->status > 0) {
|
if (mode != 0 && sf->status > 0) {
|
||||||
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
|
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
|
||||||
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
|
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
|
||||||
fprintf(F, "%d;Status\n", sf->status & HELP_ALL);
|
fprintf(F, "%d;Status\n", sf->status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1646,7 +1647,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
|
||||||
f->options &= (~flag);
|
f->options &= (~flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show_allies_cr(F, f, f->allies);
|
show_allies_cr(F, f, NULL);
|
||||||
{
|
{
|
||||||
group *g;
|
group *g;
|
||||||
for (g = f->groups; g; g = g->next) {
|
for (g = f->groups; g; g = g->next) {
|
||||||
|
@ -1659,7 +1660,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
|
||||||
fprintf(F, "\"%s\";typprefix\n",
|
fprintf(F, "\"%s\";typprefix\n",
|
||||||
translate(prefix, LOC(f->locale, prefix)));
|
translate(prefix, LOC(f->locale, prefix)));
|
||||||
}
|
}
|
||||||
show_allies_cr(F, f, g->allies);
|
show_allies_cr(F, f, g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,6 @@ static void test_cr_factionstealth(CuTest *tc) {
|
||||||
faction *f1, *f2;
|
faction *f1, *f2;
|
||||||
region *r;
|
region *r;
|
||||||
unit *u;
|
unit *u;
|
||||||
ally *al;
|
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
f1 = test_create_faction(NULL);
|
f1 = test_create_faction(NULL);
|
||||||
|
@ -298,8 +297,7 @@ static void test_cr_factionstealth(CuTest *tc) {
|
||||||
mstream_done(&strm);
|
mstream_done(&strm);
|
||||||
|
|
||||||
/* we see the same thing as them when we are an ally */
|
/* we see the same thing as them when we are an ally */
|
||||||
al = ally_add(&f1->allies, f2);
|
ally_set(&f1->allies, f2, HELP_FSTEALTH);
|
||||||
al->status = HELP_FSTEALTH;
|
|
||||||
mstream_init(&strm);
|
mstream_init(&strm);
|
||||||
cr_output_unit(&strm, f2, u, seen_unit);
|
cr_output_unit(&strm, f2, u, seen_unit);
|
||||||
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
|
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
|
||||||
|
|
|
@ -44,8 +44,7 @@ static void setup_give(struct give *env) {
|
||||||
env->itype = it_get_or_create(rt_get_or_create("money"));
|
env->itype = it_get_or_create(rt_get_or_create("money"));
|
||||||
env->itype->flags |= ITF_HERB;
|
env->itype->flags |= ITF_HERB;
|
||||||
if (env->f2) {
|
if (env->f2) {
|
||||||
ally * al = ally_add(&env->f2->allies, env->f1);
|
ally_set(&env->f2->allies, env->f1, HELP_GIVE);
|
||||||
al->status = HELP_GIVE;
|
|
||||||
env->dst = test_create_unit(env->f2, env->r);
|
env->dst = test_create_unit(env->f2, env->r);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "objtypes.h"
|
#include "objtypes.h"
|
||||||
#include "plane.h"
|
|
||||||
|
|
||||||
#include <kernel/attrib.h>
|
#include <kernel/attrib.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
|
@ -20,9 +19,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void read_allies(gamedata * data, faction *f)
|
void read_allies(gamedata * data, ally **sfp)
|
||||||
{
|
{
|
||||||
ally **sfp = &f->allies;
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int aid;
|
int aid;
|
||||||
READ_INT(data->store, &aid);
|
READ_INT(data->store, &aid);
|
||||||
|
@ -62,19 +60,6 @@ ally * ally_add(ally **al_p, struct faction *f) {
|
||||||
return al;
|
return al;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ally_remove(ally **al_p, struct faction *f) {
|
|
||||||
ally * al;
|
|
||||||
while (*al_p) {
|
|
||||||
al = *al_p;
|
|
||||||
if (al->faction == f) {
|
|
||||||
*al_p = al->next;
|
|
||||||
free(al);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
al_p = &al->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ally_flag(const char *s, int help_mask)
|
static int ally_flag(const char *s, int help_mask)
|
||||||
{
|
{
|
||||||
if ((help_mask & HELP_MONEY) && strcmp(s, "money") == 0)
|
if ((help_mask & HELP_MONEY) && strcmp(s, "money") == 0)
|
||||||
|
@ -114,11 +99,8 @@ int AllianceAuto(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
autoalliance(const plane * pl, const faction * sf, const faction * f2)
|
autoalliance(const faction * sf, const faction * f2)
|
||||||
{
|
{
|
||||||
if (pl && (pl->flags & PFL_FRIENDLY))
|
|
||||||
return HELP_ALL;
|
|
||||||
|
|
||||||
if (f_get_alliance(sf) != NULL && AllianceAuto()) {
|
if (f_get_alliance(sf) != NULL && AllianceAuto()) {
|
||||||
if (sf->alliance == f2->alliance)
|
if (sf->alliance == f2->alliance)
|
||||||
return AllianceAuto();
|
return AllianceAuto();
|
||||||
|
@ -195,9 +177,11 @@ static int AllianceRestricted(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
alliedgroup(const struct plane *pl, const struct faction *f,
|
alliedgroup(const struct faction *f,
|
||||||
const struct faction *f2, const struct ally *sf, int mode)
|
const struct faction *f2, const struct group *g, int mode)
|
||||||
{
|
{
|
||||||
|
ally *sf = g ? g->allies : f->allies;
|
||||||
|
|
||||||
if (!(faction_alive(f) && faction_alive(f2))) {
|
if (!(faction_alive(f) && faction_alive(f2))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -205,9 +189,9 @@ alliedgroup(const struct plane *pl, const struct faction *f,
|
||||||
sf = sf->next;
|
sf = sf->next;
|
||||||
}
|
}
|
||||||
if (sf == NULL) {
|
if (sf == NULL) {
|
||||||
mode = mode & autoalliance(pl, f, f2);
|
mode = mode & autoalliance(f, f2);
|
||||||
}
|
}
|
||||||
mode = ally_mode(sf, mode) | (mode & autoalliance(pl, f, f2));
|
mode = ally_mode(sf, mode) | (mode & autoalliance(f, f2));
|
||||||
if (AllianceRestricted()) {
|
if (AllianceRestricted()) {
|
||||||
if (a_find(f->attribs, &at_npcfaction)) {
|
if (a_find(f->attribs, &at_npcfaction)) {
|
||||||
return mode;
|
return mode;
|
||||||
|
@ -223,26 +207,24 @@ alliedgroup(const struct plane *pl, const struct faction *f,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
alliedfaction(const struct plane *pl, const struct faction *f,
|
alliedfaction(const struct faction *f, const struct faction *f2, int mode)
|
||||||
const struct faction *f2, int mode)
|
|
||||||
{
|
{
|
||||||
return alliedgroup(pl, f, f2, f->allies, mode);
|
return alliedgroup(f, f2, NULL, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Die Gruppe von Einheit u hat helfe zu f2 gesetzt. */
|
/* Die Gruppe von Einheit u hat helfe zu f2 gesetzt. */
|
||||||
int alliedunit(const unit * u, const faction * f2, int mode)
|
int alliedunit(const unit * u, const faction * f2, int mode)
|
||||||
{
|
{
|
||||||
int automode;
|
|
||||||
|
|
||||||
assert(u);
|
assert(u);
|
||||||
assert(f2);
|
assert(f2);
|
||||||
assert(u->region); /* the unit should be in a region, but it's possible that u->number==0 (TEMP units) */
|
assert(u->region); /* the unit should be in a region, but it's possible that u->number==0 (TEMP units) */
|
||||||
if (u->faction == f2)
|
if (u->faction == f2) {
|
||||||
return mode;
|
return mode;
|
||||||
|
}
|
||||||
|
if (!faction_alive(f2)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (u->faction != NULL && f2 != NULL) {
|
if (u->faction != NULL && f2 != NULL) {
|
||||||
ally *sf;
|
|
||||||
plane *pl;
|
|
||||||
|
|
||||||
if (mode & HELP_FIGHT) {
|
if (mode & HELP_FIGHT) {
|
||||||
if ((u->flags & UFL_DEFENDER) || (u->faction->flags & FFL_DEFENDER)) {
|
if ((u->flags & UFL_DEFENDER) || (u->faction->flags & FFL_DEFENDER)) {
|
||||||
faction *owner = region_get_owner(u->region);
|
faction *owner = region_get_owner(u->region);
|
||||||
|
@ -253,20 +235,44 @@ int alliedunit(const unit * u, const faction * f2, int mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pl = rplane(u->region);
|
|
||||||
automode = mode & autoalliance(pl, u->faction, f2);
|
|
||||||
|
|
||||||
if (pl != NULL && (pl->flags & PFL_NOALLIANCES))
|
|
||||||
mode = (mode & automode) | (mode & HELP_GIVE);
|
|
||||||
|
|
||||||
sf = u->faction->allies;
|
|
||||||
if (fval(u, UFL_GROUP)) {
|
if (fval(u, UFL_GROUP)) {
|
||||||
const attrib *a = a_find(u->attribs, &at_group);
|
const attrib *a = a_find(u->attribs, &at_group);
|
||||||
if (a != NULL)
|
if (a != NULL) {
|
||||||
sf = ((group *)a->data.v)->allies;
|
group *g = (group *)a->data.v;
|
||||||
|
return alliedgroup(u->faction, f2, g, mode);
|
||||||
}
|
}
|
||||||
return alliedgroup(pl, u->faction, f2, sf, mode);
|
}
|
||||||
|
return alliedfaction(u->faction, f2, mode);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ally_set(ally **allies, struct faction *f, int status) {
|
||||||
|
ally *al;
|
||||||
|
while (*allies) {
|
||||||
|
al = *allies;
|
||||||
|
if (al->faction == f) {
|
||||||
|
if (status != 0) {
|
||||||
|
al->status = status;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*allies = al->next;
|
||||||
|
free(al);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
allies = &al->next;
|
||||||
|
}
|
||||||
|
al = ally_add(allies, f);
|
||||||
|
al->status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ally_get(ally *allies, const struct faction *f) {
|
||||||
|
ally *al;
|
||||||
|
for (al = allies; al; al = al->next) {
|
||||||
|
if (al->faction == f) {
|
||||||
|
return al->status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct attrib_type;
|
struct attrib_type;
|
||||||
struct plane;
|
|
||||||
struct faction;
|
struct faction;
|
||||||
|
struct group;
|
||||||
struct gamedata;
|
struct gamedata;
|
||||||
struct unit;
|
struct unit;
|
||||||
|
|
||||||
|
@ -37,19 +37,21 @@ extern "C" {
|
||||||
int status;
|
int status;
|
||||||
} ally;
|
} ally;
|
||||||
|
|
||||||
void read_allies(struct gamedata * data, struct faction *f);
|
int ally_get(struct ally *allies, const struct faction *f);
|
||||||
|
void ally_set(struct ally **allies, struct faction *f, int status);
|
||||||
|
|
||||||
|
void read_allies(struct gamedata * data, struct ally **allies);
|
||||||
ally * ally_find(ally *al, const struct faction *f);
|
ally * ally_find(ally *al, const struct faction *f);
|
||||||
ally * ally_add(ally **al_p, struct faction *f);
|
ally * ally_add(ally **al_p, struct faction *f);
|
||||||
void ally_remove(ally **al_p, struct faction *f);
|
|
||||||
|
|
||||||
int AllianceAuto(void); /* flags that allied factions get automatically */
|
int AllianceAuto(void); /* flags that allied factions get automatically */
|
||||||
int HelpMask(void); /* flags restricted to allied factions */
|
int HelpMask(void); /* flags restricted to allied factions */
|
||||||
int alliedunit(const struct unit *u, const struct faction *f2,
|
int alliedunit(const struct unit *u, const struct faction *f2,
|
||||||
int mode);
|
int mode);
|
||||||
int alliedfaction(const struct plane *pl, const struct faction *f,
|
int alliedfaction(const struct faction *f, const struct faction *f2,
|
||||||
const struct faction *f2, int mode);
|
int mode);
|
||||||
int alliedgroup(const struct plane *pl, const struct faction *f,
|
int alliedgroup(const struct faction *f, const struct faction *f2,
|
||||||
const struct faction *f2, const struct ally *sf, int mode);
|
const struct group *g, int mode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,37 +7,22 @@
|
||||||
|
|
||||||
static void test_ally(CuTest * tc)
|
static void test_ally(CuTest * tc)
|
||||||
{
|
{
|
||||||
ally * al = 0;
|
ally * al = NULL;
|
||||||
struct faction * f1 = test_create_faction(NULL);
|
struct faction * f1 = test_create_faction(NULL);
|
||||||
|
|
||||||
ally_add(&al, f1);
|
ally_set(&al, f1, HELP_GUARD);
|
||||||
CuAssertPtrNotNull(tc, al);
|
CuAssertPtrNotNull(tc, al);
|
||||||
CuAssertPtrEquals(tc, f1, ally_find(al, f1)->faction);
|
CuAssertIntEquals(tc, HELP_GUARD, ally_get(al, f1));
|
||||||
|
|
||||||
ally_remove(&al, f1);
|
ally_set(&al, f1, 0);
|
||||||
CuAssertPtrEquals(tc, NULL, al);
|
CuAssertPtrEquals(tc, NULL, al);
|
||||||
CuAssertPtrEquals(tc, NULL, ally_find(al, f1));
|
CuAssertIntEquals(tc, 0, ally_get(al, f1));
|
||||||
}
|
|
||||||
|
|
||||||
static void test_ally_null(CuTest * tc)
|
|
||||||
{
|
|
||||||
ally *a1 = 0, *a2 = 0;
|
|
||||||
|
|
||||||
a1 = ally_add(&a1, 0);
|
|
||||||
a2 = ally_add(&a1, 0);
|
|
||||||
CuAssertPtrNotNull(tc, a1);
|
|
||||||
CuAssertPtrNotNull(tc, a2);
|
|
||||||
CuAssertPtrEquals(tc, a2, a1->next);
|
|
||||||
CuAssertPtrEquals(tc, NULL, a2->next);
|
|
||||||
free(a1);
|
|
||||||
free(a2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_ally_suite(void)
|
CuSuite *get_ally_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_ally);
|
SUITE_ADD_TEST(suite, test_ally);
|
||||||
SUITE_ADD_TEST(suite, test_ally_null);
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -496,7 +496,7 @@ void destroyfaction(faction ** fp)
|
||||||
|
|
||||||
handle_event(f->attribs, "destroy", f);
|
handle_event(f->attribs, "destroy", f);
|
||||||
if (f->alliance) {
|
if (f->alliance) {
|
||||||
setalliance(f, 0);
|
setalliance(f, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
funhash(f);
|
funhash(f);
|
||||||
|
@ -531,20 +531,9 @@ int get_alliance(const faction * a, const faction * b)
|
||||||
|
|
||||||
void set_alliance(faction * a, faction * b, int status)
|
void set_alliance(faction * a, faction * b, int status)
|
||||||
{
|
{
|
||||||
ally **sfp;
|
/* TODO: optimization (use allies_walk?) */
|
||||||
sfp = &a->allies;
|
int original = ally_get(a->allies, b);
|
||||||
while (*sfp) {
|
ally_set(&a->allies, b, status | original);
|
||||||
ally *sf = *sfp;
|
|
||||||
if (sf->faction == b)
|
|
||||||
break;
|
|
||||||
sfp = &sf->next;
|
|
||||||
}
|
|
||||||
if (*sfp == NULL) {
|
|
||||||
ally *sf = ally_add(sfp, b);
|
|
||||||
sf->status = status;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
(*sfp)->status |= status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void renumber_faction(faction * f, int no)
|
void renumber_faction(faction * f, int no)
|
||||||
|
|
|
@ -111,6 +111,8 @@ extern "C" {
|
||||||
void fhash(struct faction *f);
|
void fhash(struct faction *f);
|
||||||
void funhash(struct faction *f);
|
void funhash(struct faction *f);
|
||||||
|
|
||||||
|
int faction_ally_status(const faction *f, const faction *f2);
|
||||||
|
|
||||||
struct faction *findfaction(int n);
|
struct faction *findfaction(int n);
|
||||||
int max_magicians(const faction * f);
|
int max_magicians(const faction * f);
|
||||||
void set_show_item(faction * f, const struct item_type *itype);
|
void set_show_item(faction * f, const struct item_type *itype);
|
||||||
|
|
|
@ -29,20 +29,18 @@
|
||||||
static void test_destroyfaction_allies(CuTest *tc) {
|
static void test_destroyfaction_allies(CuTest *tc) {
|
||||||
faction *f1, *f2;
|
faction *f1, *f2;
|
||||||
region *r;
|
region *r;
|
||||||
ally *al;
|
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
f1 = test_create_faction(NULL);
|
f1 = test_create_faction(NULL);
|
||||||
test_create_unit(f1, r);
|
test_create_unit(f1, r);
|
||||||
f2 = test_create_faction(NULL);
|
f2 = test_create_faction(NULL);
|
||||||
al = ally_add(&f1->allies, f2);
|
ally_set(&f1->allies, f2, HELP_FIGHT);
|
||||||
al->status = HELP_FIGHT;
|
CuAssertIntEquals(tc, HELP_FIGHT, alliedfaction(f1, f2, HELP_ALL));
|
||||||
CuAssertIntEquals(tc, HELP_FIGHT, alliedgroup(0, f1, f2, f1->allies, HELP_ALL));
|
|
||||||
CuAssertPtrEquals(tc, f2, f1->next);
|
CuAssertPtrEquals(tc, f2, f1->next);
|
||||||
destroyfaction(&f1->next);
|
destroyfaction(&f1->next);
|
||||||
CuAssertIntEquals(tc, false, faction_alive(f2));
|
CuAssertIntEquals(tc, false, faction_alive(f2));
|
||||||
CuAssertIntEquals(tc, 0, alliedgroup(0, f1, f2, f1->allies, HELP_ALL));
|
CuAssertIntEquals(tc, 0, alliedfaction(f1, f2, HELP_ALL));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,11 +72,10 @@ static void init_group(faction * f, group * g)
|
||||||
ally *a, **an;
|
ally *a, **an;
|
||||||
|
|
||||||
an = &g->allies;
|
an = &g->allies;
|
||||||
for (a = f->allies; a; a = a->next)
|
for (a = f->allies; a; a = a->next) {
|
||||||
if (a->faction) {
|
if (a->faction) {
|
||||||
ally *ga = ally_add(an, a->faction);
|
ally_set(an, a->faction, a->status);
|
||||||
ga->status = a->status;
|
}
|
||||||
an = &ga->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +227,6 @@ void read_groups(gamedata *data, faction * f)
|
||||||
{
|
{
|
||||||
struct storage *store = data->store;
|
struct storage *store = data->store;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ally **pa;
|
|
||||||
group *g;
|
group *g;
|
||||||
int gid;
|
int gid;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
@ -238,19 +236,7 @@ void read_groups(gamedata *data, faction * f)
|
||||||
break;
|
break;
|
||||||
READ_STR(store, buf, sizeof(buf));
|
READ_STR(store, buf, sizeof(buf));
|
||||||
g = new_group(f, buf, gid);
|
g = new_group(f, buf, gid);
|
||||||
pa = &g->allies;
|
read_allies(data, &g->allies);
|
||||||
for (;;) {
|
|
||||||
ally *al;
|
|
||||||
int id;
|
|
||||||
READ_INT(store, &id);
|
|
||||||
if (id == 0) break;
|
|
||||||
al = ally_add(pa, NULL);
|
|
||||||
al->faction = findfaction(id);
|
|
||||||
if (!al->faction) {
|
|
||||||
ur_add(RESOLVE_FACTION | id, (void **)&al->faction, NULL);
|
|
||||||
}
|
|
||||||
READ_INT(store, &al->status);
|
|
||||||
}
|
|
||||||
read_attribs(data, &g->attribs, g);
|
read_attribs(data, &g->attribs, g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
|
||||||
faction *f, *f2;
|
faction *f, *f2;
|
||||||
unit * u;
|
unit * u;
|
||||||
group *g;
|
group *g;
|
||||||
ally *al;
|
|
||||||
int fno;
|
int fno;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
@ -42,8 +41,8 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
|
||||||
CuAssertPtrNotNull(tc, u);
|
CuAssertPtrNotNull(tc, u);
|
||||||
g = join_group(u, "group");
|
g = join_group(u, "group");
|
||||||
CuAssertPtrNotNull(tc, g);
|
CuAssertPtrNotNull(tc, g);
|
||||||
al = ally_add(&g->allies, f);
|
ally_set(&g->allies, f, HELP_GIVE);
|
||||||
CuAssertPtrNotNull(tc, al);
|
CuAssertPtrNotNull(tc, g->allies);
|
||||||
|
|
||||||
CuAssertPtrEquals(tc, f, factions);
|
CuAssertPtrEquals(tc, f, factions);
|
||||||
destroyfaction(&factions);
|
destroyfaction(&factions);
|
||||||
|
@ -73,7 +72,6 @@ static void test_group_readwrite(CuTest * tc)
|
||||||
{
|
{
|
||||||
faction * f;
|
faction * f;
|
||||||
group *g;
|
group *g;
|
||||||
ally *al;
|
|
||||||
int i;
|
int i;
|
||||||
gamedata data;
|
gamedata data;
|
||||||
storage store;
|
storage store;
|
||||||
|
@ -85,8 +83,7 @@ static void test_group_readwrite(CuTest * tc)
|
||||||
new_group(f, "NW", 42);
|
new_group(f, "NW", 42);
|
||||||
g = new_group(f, "Egoisten", 43);
|
g = new_group(f, "Egoisten", 43);
|
||||||
key_set(&g->attribs, 44, 44);
|
key_set(&g->attribs, 44, 44);
|
||||||
al = ally_add(&g->allies, f);
|
ally_set(&g->allies, f, HELP_GIVE);
|
||||||
al->status = HELP_GIVE;
|
|
||||||
write_groups(&store, f);
|
write_groups(&store, f);
|
||||||
WRITE_INT(&store, 47);
|
WRITE_INT(&store, 47);
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@ extern "C" {
|
||||||
struct plane;
|
struct plane;
|
||||||
struct storage;
|
struct storage;
|
||||||
|
|
||||||
#define PFL_NOCOORDS 1 /* not in use */
|
#define PFL_NOCOORDS 1 /* not implemented */
|
||||||
#define PFL_NORECRUITS 2
|
#define PFL_NORECRUITS 2 /* cannot recruit */
|
||||||
#define PFL_NOALLIANCES 4
|
#define PFL_NOALLIANCES 4 /* not implemented */
|
||||||
#define PFL_LOWSTEALING 8
|
#define PFL_LOWSTEALING 8 /* not implemented */
|
||||||
#define PFL_NOGIVE 16 /* Übergaben sind unmöglich */
|
#define PFL_NOGIVE 16 /* Übergaben sind unmöglich */
|
||||||
#define PFL_NOATTACK 32 /* Angriffe und Diebstähle sind unmöglich */
|
#define PFL_NOATTACK 32 /* Angriffe und Diebstähle sind unmöglich */
|
||||||
#define PFL_NOTERRAIN 64 /* Terraintyp wird nicht angezeigt TODO? */
|
#define PFL_NOTERRAIN 64 /* Terraintyp wird nicht angezeigt TODO? */
|
||||||
|
@ -40,7 +40,7 @@ extern "C" {
|
||||||
#define PFL_NOTEACH 512 /* Lehre außer Betrieb */
|
#define PFL_NOTEACH 512 /* Lehre außer Betrieb */
|
||||||
#define PFL_NOBUILD 1024 /* Bauen außer Betrieb */
|
#define PFL_NOBUILD 1024 /* Bauen außer Betrieb */
|
||||||
#define PFL_NOFEED 2048 /* Kein Unterhalt nötig */
|
#define PFL_NOFEED 2048 /* Kein Unterhalt nötig */
|
||||||
#define PFL_FRIENDLY 4096 /* everyone is your ally */
|
#define PFL_FRIENDLY 4096 /* not implemented */
|
||||||
#define PFL_NOORCGROWTH 8192 /* orcs don't grow */
|
#define PFL_NOORCGROWTH 8192 /* orcs don't grow */
|
||||||
#define PFL_NOMONSTERS 16384 /* no monster randenc */
|
#define PFL_NOMONSTERS 16384 /* no monster randenc */
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ void test_pool(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
struct resource_type *rtype;
|
struct resource_type *rtype;
|
||||||
ally *al;
|
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
@ -74,10 +73,9 @@ void test_pool(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_POOLED_SLACK, INT_MAX));
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_POOLED_SLACK, INT_MAX));
|
||||||
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_POOLED_SLACK | GET_POOLED_RESERVE, INT_MAX));
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_POOLED_SLACK | GET_POOLED_RESERVE, INT_MAX));
|
||||||
|
|
||||||
al = ally_add(&u3->faction->allies, f);
|
ally_set(&u3->faction->allies, f, HELP_GUARD);
|
||||||
al->status = HELP_GUARD;
|
|
||||||
CuAssertIntEquals(tc, 0, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
CuAssertIntEquals(tc, 0, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
||||||
al->status = HELP_MONEY;
|
ally_set(&u3->faction->allies, f, HELP_MONEY);
|
||||||
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_SLACK, INT_MAX));
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_SLACK, INT_MAX));
|
||||||
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_RESERVE, INT_MAX));
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_RESERVE, INT_MAX));
|
||||||
CuAssertIntEquals(tc, 400, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
CuAssertIntEquals(tc, 400, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
@ -117,7 +115,6 @@ void test_pool_use(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
struct item_type *itype;
|
struct item_type *itype;
|
||||||
ally *al;
|
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
@ -135,8 +132,7 @@ void test_pool_use(CuTest *tc) {
|
||||||
set_resvalue(u2, itype, 100);
|
set_resvalue(u2, itype, 100);
|
||||||
i_change(&u3->items, itype, 400);
|
i_change(&u3->items, itype, 400);
|
||||||
set_resvalue(u3, itype, 200);
|
set_resvalue(u3, itype, 200);
|
||||||
al = ally_add(&u3->faction->allies, f);
|
ally_set(&u3->faction->allies, f, HELP_MONEY);
|
||||||
al->status = HELP_MONEY;
|
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_SLACK, 10));
|
CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_SLACK, 10));
|
||||||
CuAssertIntEquals(tc, 40, use_pooled(u1, itype->rtype, GET_SLACK, 50));
|
CuAssertIntEquals(tc, 40, use_pooled(u1, itype->rtype, GET_SLACK, 50));
|
||||||
|
|
|
@ -1082,7 +1082,7 @@ faction *read_faction(gamedata * data)
|
||||||
/* mistakes were made in the past*/
|
/* mistakes were made in the past*/
|
||||||
f->options &= ~WANT_OPTION(O_JSON);
|
f->options &= ~WANT_OPTION(O_JSON);
|
||||||
}
|
}
|
||||||
read_allies(data, f);
|
read_allies(data, &f->allies);
|
||||||
read_groups(data, f);
|
read_groups(data, f);
|
||||||
f->spellbook = 0;
|
f->spellbook = 0;
|
||||||
if (data->version >= REGIONOWNER_VERSION) {
|
if (data->version >= REGIONOWNER_VERSION) {
|
||||||
|
@ -1145,19 +1145,15 @@ void write_faction(gamedata *data, const faction * f)
|
||||||
WRITE_SECTION(data->store);
|
WRITE_SECTION(data->store);
|
||||||
|
|
||||||
for (sf = f->allies; sf; sf = sf->next) {
|
for (sf = f->allies; sf; sf = sf->next) {
|
||||||
int no;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
assert(sf->faction);
|
assert(sf->faction);
|
||||||
|
|
||||||
no = sf->faction->no;
|
if (faction_alive(sf->faction)) {
|
||||||
status = alliedfaction(NULL, f, sf->faction, HELP_ALL);
|
if (sf->status != 0) {
|
||||||
|
WRITE_INT(data->store, sf->faction->no);
|
||||||
if (status != 0) {
|
|
||||||
WRITE_INT(data->store, no);
|
|
||||||
WRITE_INT(data->store, sf->status);
|
WRITE_INT(data->store, sf->status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
WRITE_INT(data->store, 0);
|
WRITE_INT(data->store, 0);
|
||||||
WRITE_SECTION(data->store);
|
WRITE_SECTION(data->store);
|
||||||
write_groups(data->store, f);
|
write_groups(data->store, f);
|
||||||
|
|
|
@ -250,7 +250,6 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
||||||
faction *f, *f2;
|
faction *f, *f2;
|
||||||
unit * u;
|
unit * u;
|
||||||
group *g;
|
group *g;
|
||||||
ally *al;
|
|
||||||
int fno;
|
int fno;
|
||||||
gamedata data;
|
gamedata data;
|
||||||
storage store;
|
storage store;
|
||||||
|
@ -269,8 +268,8 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
||||||
CuAssertPtrNotNull(tc, u);
|
CuAssertPtrNotNull(tc, u);
|
||||||
g = join_group(u, "group");
|
g = join_group(u, "group");
|
||||||
CuAssertPtrNotNull(tc, g);
|
CuAssertPtrNotNull(tc, g);
|
||||||
al = ally_add(&g->allies, f);
|
ally_set(&g->allies, f, HELP_GIVE);
|
||||||
CuAssertPtrNotNull(tc, al);
|
CuAssertPtrNotNull(tc, g->allies);
|
||||||
|
|
||||||
CuAssertPtrEquals(tc, f, factions);
|
CuAssertPtrEquals(tc, f, factions);
|
||||||
destroyfaction(&factions);
|
destroyfaction(&factions);
|
||||||
|
|
|
@ -800,7 +800,7 @@ void immigration(void)
|
||||||
void nmr_warnings(void)
|
void nmr_warnings(void)
|
||||||
{
|
{
|
||||||
faction *f, *fa;
|
faction *f, *fa;
|
||||||
#define FRIEND (HELP_GUARD|HELP_MONEY)
|
#define HELP_NMR (HELP_GUARD|HELP_MONEY)
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
|
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
|
||||||
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
|
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
|
||||||
|
@ -816,14 +816,12 @@ void nmr_warnings(void)
|
||||||
warn = 1;
|
warn = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (alliedfaction(NULL, f, fa, FRIEND)
|
else if (alliedfaction(f, fa, HELP_NMR) && alliedfaction(fa, f, HELP_NMR)) {
|
||||||
&& alliedfaction(NULL, fa, f, FRIEND)) {
|
|
||||||
warn = 1;
|
warn = 1;
|
||||||
}
|
}
|
||||||
if (warn) {
|
if (warn) {
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
msg =
|
msg = msg_message("warn_dropout", "faction turns", f,
|
||||||
msg_message("warn_dropout", "faction turns", f,
|
|
||||||
turn - f->lastorders);
|
turn - f->lastorders);
|
||||||
}
|
}
|
||||||
add_message(&fa->msgs, msg);
|
add_message(&fa->msgs, msg);
|
||||||
|
|
|
@ -222,7 +222,6 @@ static void test_rule_force_leave(CuTest *tc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_force_leave_buildings(CuTest *tc) {
|
static void test_force_leave_buildings(CuTest *tc) {
|
||||||
ally *al;
|
|
||||||
region *r;
|
region *r;
|
||||||
unit *u1, *u2, *u3;
|
unit *u1, *u2, *u3;
|
||||||
building * b;
|
building * b;
|
||||||
|
@ -245,8 +244,7 @@ static void test_force_leave_buildings(CuTest *tc) {
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(u3->faction->msgs, "force_leave_building"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(u3->faction->msgs, "force_leave_building"));
|
||||||
|
|
||||||
u_set_building(u3, b);
|
u_set_building(u3, b);
|
||||||
al = ally_add(&u1->faction->allies, u3->faction);
|
ally_set(&u1->faction->allies, u3->faction, HELP_GUARD);
|
||||||
al->status = HELP_GUARD;
|
|
||||||
force_leave(r, NULL);
|
force_leave(r, NULL);
|
||||||
CuAssertPtrEquals_Msg(tc, "allies should not be forced to leave", b, u3->building);
|
CuAssertPtrEquals_Msg(tc, "allies should not be forced to leave", b, u3->building);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
@ -1265,25 +1263,25 @@ static void test_ally_cmd(CuTest *tc) {
|
||||||
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
|
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, HELP_ALL, ally_get(u->faction->allies, f));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
|
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, 0, ally_get(u->faction->allies, f));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
|
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, HELP_GUARD, ally_get(u->faction->allies, f));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
|
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
|
||||||
ally_cmd(u, ord);
|
ally_cmd(u, ord);
|
||||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||||
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
CuAssertIntEquals(tc, 0, ally_get(u->faction->allies, f));
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
|
|
@ -153,7 +153,6 @@ static void test_ship_has_harbormaster_same_faction(CuTest * tc) {
|
||||||
static void test_ship_has_harbormaster_ally(CuTest * tc) {
|
static void test_ship_has_harbormaster_ally(CuTest * tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
move_fixture mf;
|
move_fixture mf;
|
||||||
ally *al;
|
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
setup_harbor(&mf);
|
setup_harbor(&mf);
|
||||||
|
@ -161,8 +160,7 @@ static void test_ship_has_harbormaster_ally(CuTest * tc) {
|
||||||
u = test_create_unit(test_create_faction(NULL), mf.r);
|
u = test_create_unit(test_create_faction(NULL), mf.r);
|
||||||
u->building = mf.b;
|
u->building = mf.b;
|
||||||
building_set_owner(u);
|
building_set_owner(u);
|
||||||
al = ally_add(&u->faction->allies, mf.u->faction);
|
ally_set(&u->faction->allies, mf.u->faction, HELP_GUARD);
|
||||||
al->status = HELP_GUARD;
|
|
||||||
|
|
||||||
CuAssertIntEquals(tc, SA_HARBOUR, check_ship_allowed(mf.sh, mf.r));
|
CuAssertIntEquals(tc, SA_HARBOUR, check_ship_allowed(mf.sh, mf.r));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
|
|
@ -1518,7 +1518,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
|
||||||
const ally *sf;
|
const ally *sf;
|
||||||
|
|
||||||
for (sf = allies; sf; sf = sf->next) {
|
for (sf = allies; sf; sf = sf->next) {
|
||||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
int mode = alliedfaction(f, sf->faction, HELP_ALL);
|
||||||
if (mode > 0) {
|
if (mode > 0) {
|
||||||
++allierte;
|
++allierte;
|
||||||
}
|
}
|
||||||
|
@ -1529,7 +1529,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
|
||||||
sbs_init(&sbs, buf, size);
|
sbs_init(&sbs, buf, size);
|
||||||
|
|
||||||
for (sf = allies; sf; sf = sf->next) {
|
for (sf = allies; sf; sf = sf->next) {
|
||||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
int mode = alliedfaction(f, sf->faction, HELP_ALL);
|
||||||
if (mode <= 0)
|
if (mode <= 0)
|
||||||
continue;
|
continue;
|
||||||
i++;
|
i++;
|
||||||
|
@ -1720,9 +1720,10 @@ static void list_address(struct stream *out, const faction * uf, selist * seenfa
|
||||||
str ? str : "");
|
str ? str : "");
|
||||||
if (uf == f)
|
if (uf == f)
|
||||||
label = '*';
|
label = '*';
|
||||||
else if (is_allied(uf, f))
|
else if (is_allied(uf, f)) {
|
||||||
label = 'o';
|
label = 'o';
|
||||||
else if (alliedfaction(NULL, uf, f, HELP_ALL))
|
}
|
||||||
|
else if (alliedfaction(uf, f, HELP_ALL))
|
||||||
label = '+';
|
label = '+';
|
||||||
paragraph(out, buf, 4, 0, label);
|
paragraph(out, buf, 4, 0, label);
|
||||||
}
|
}
|
||||||
|
|
|
@ -969,7 +969,7 @@ bufunit(const faction * f, const unit * u, seen_mode mode, char *buf,
|
||||||
|
|
||||||
dh = 0;
|
dh = 0;
|
||||||
if (!getarnt) {
|
if (!getarnt) {
|
||||||
if (alliedfaction(rplane(u->region), f, fv, HELP_ALL)) {
|
if (alliedfaction(f, fv, HELP_ALL)) {
|
||||||
dh = 1;
|
dh = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,6 @@ static void test_bufunit_fstealth(CuTest *tc) {
|
||||||
faction *f1, *f2;
|
faction *f1, *f2;
|
||||||
region *r;
|
region *r;
|
||||||
unit *u;
|
unit *u;
|
||||||
ally *al;
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
struct locale *lang;
|
struct locale *lang;
|
||||||
|
|
||||||
|
@ -232,8 +231,7 @@ static void test_bufunit_fstealth(CuTest *tc) {
|
||||||
u->flags &= ~UFL_ANON_FACTION;
|
u->flags &= ~UFL_ANON_FACTION;
|
||||||
|
|
||||||
/* we see the same thing as them when we are an ally */
|
/* we see the same thing as them when we are an ally */
|
||||||
al = ally_add(&f1->allies, f2);
|
ally_set(&f1->allies, f2, HELP_FSTEALTH);
|
||||||
al->status = HELP_FSTEALTH;
|
|
||||||
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
||||||
CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf);
|
CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf);
|
||||||
|
|
||||||
|
|
|
@ -636,7 +636,6 @@ static void test_teach_many_to_one(CuTest *tc) {
|
||||||
static void test_teach_message(CuTest *tc) {
|
static void test_teach_message(CuTest *tc) {
|
||||||
unit *u, *u1, *u2;
|
unit *u, *u1, *u2;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
ally *al;
|
|
||||||
teaching_info *teach;
|
teaching_info *teach;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
@ -652,8 +651,7 @@ static void test_teach_message(CuTest *tc) {
|
||||||
set_level(u1, SK_CROSSBOW, TEACHDIFFERENCE);
|
set_level(u1, SK_CROSSBOW, TEACHDIFFERENCE);
|
||||||
u1->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
u1->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
||||||
u2 = test_create_unit(test_create_faction(NULL), u->region);
|
u2 = test_create_unit(test_create_faction(NULL), u->region);
|
||||||
al = ally_add(&u->faction->allies, u2->faction);
|
ally_set(&u->faction->allies, u2->faction, HELP_GUARD);
|
||||||
al->status = HELP_GUARD;
|
|
||||||
set_level(u2, SK_CROSSBOW, TEACHDIFFERENCE);
|
set_level(u2, SK_CROSSBOW, TEACHDIFFERENCE);
|
||||||
u2->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
u2->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
||||||
CuAssertTrue(tc, !alliedunit(u, u1->faction, HELP_GUARD));
|
CuAssertTrue(tc, !alliedunit(u, u1->faction, HELP_GUARD));
|
||||||
|
|
Loading…
Reference in New Issue