simplicate the use of ally.c

This commit is contained in:
Enno Rehling 2018-10-26 19:47:50 +02:00
parent 557c624200
commit ac3a4d91c9
23 changed files with 140 additions and 203 deletions

View File

@ -281,19 +281,15 @@ static void set_friendly(side * as, side * ds)
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)
return mode;
if (s->faction == f) {
return true;
}
if (s->group) {
return alliedgroup(s->battle->plane, s->faction, f, s->group->allies, mode);
return alliedgroup(s->faction, f, s->group, mode) != 0;
}
return alliedfaction(s->battle->plane, s->faction, f, mode);
}
static int allysf(const side * s, const faction * f)
{
return allysfm(s, f, HELP_FIGHT);
return alliedfaction(s->faction, f, mode) != 0;
}
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) {
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;
}
}
@ -344,7 +340,7 @@ bool helping(const side * as, const side * ds)
{
if (as->faction == ds->faction)
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)
@ -832,7 +828,7 @@ bool meffect_protection(battle * b, meffect * s, side * ds)
return false;
if (enemy(s->magician->side, ds))
return false;
if (allysf(s->magician->side, ds->faction))
if (alliedside(s->magician->side, ds->faction, HELP_FIGHT))
return true;
return false;
}
@ -1654,7 +1650,7 @@ selist *select_fighters(battle * b, const side * vs, int mask, select_fun cb, vo
continue;
}
else if (mask == FS_HELP) {
if (enemy(s, vs) || !allysf(s, vs->faction)) {
if (enemy(s, vs) || !alliedside(s, vs->faction, HELP_FIGHT)) {
continue;
}
}
@ -3636,7 +3632,7 @@ static void join_allies(battle * b)
* vorgespiegelt wird, und er sich uns gegen<EFBFBD>ber nicht zu
* erkennen gibt, helfen wir ihm nicht */
if (s->stealthfaction) {
if (!allysfm(s, u->faction, HELP_FSTEALTH)) {
if (!alliedside(s, u->faction, HELP_FSTEALTH)) {
continue;
}
}
@ -3690,20 +3686,16 @@ static void join_allies(battle * b)
}
for (sa = s + 1; sa != b->sides + b->nsides; ++sa) {
plane *pl = rplane(r);
if (enemy(s, sa))
continue;
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;
if (!enemy(s, sa) && !friendly(s, sa)) {
if (alliedfaction(f, sa->faction, HELP_FIGHT)) {
if (alliedfaction(sa->faction, f, HELP_FIGHT)) {
set_friendly(s, sa);
}
}
}
}
}
}
static void flee(const troop dt)
{

View File

@ -1021,15 +1021,16 @@ static void cr_output_unit_compat(FILE * F, const faction * f,
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* 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)
if (sf->faction) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (sf->faction && faction_alive(sf->faction)) {
int mode = alliedgroup(f, sf->faction, g, HELP_ALL);
if (mode != 0 && sf->status > 0) {
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
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);
}
}
show_allies_cr(F, f, f->allies);
show_allies_cr(F, f, NULL);
{
group *g;
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",
translate(prefix, LOC(f->locale, prefix)));
}
show_allies_cr(F, f, g->allies);
show_allies_cr(F, f, g);
}
}

View File

@ -227,7 +227,6 @@ static void test_cr_factionstealth(CuTest *tc) {
faction *f1, *f2;
region *r;
unit *u;
ally *al;
test_setup();
f1 = test_create_faction(NULL);
@ -298,8 +297,7 @@ static void test_cr_factionstealth(CuTest *tc) {
mstream_done(&strm);
/* we see the same thing as them when we are an ally */
al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH;
ally_set(&f1->allies, f2, HELP_FSTEALTH);
mstream_init(&strm);
cr_output_unit(&strm, f2, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));

View File

@ -44,8 +44,7 @@ static void setup_give(struct give *env) {
env->itype = it_get_or_create(rt_get_or_create("money"));
env->itype->flags |= ITF_HERB;
if (env->f2) {
ally * al = ally_add(&env->f2->allies, env->f1);
al->status = HELP_GIVE;
ally_set(&env->f2->allies, env->f1, HELP_GIVE);
env->dst = test_create_unit(env->f2, env->r);
}
else {

View File

@ -8,7 +8,6 @@
#include "group.h"
#include "faction.h"
#include "objtypes.h"
#include "plane.h"
#include <kernel/attrib.h>
#include <util/strings.h>
@ -20,9 +19,8 @@
#include <string.h>
#include <stdlib.h>
void read_allies(gamedata * data, faction *f)
void read_allies(gamedata * data, ally **sfp)
{
ally **sfp = &f->allies;
for (;;) {
int aid;
READ_INT(data->store, &aid);
@ -62,19 +60,6 @@ ally * ally_add(ally **al_p, struct faction *f) {
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)
{
if ((help_mask & HELP_MONEY) && strcmp(s, "money") == 0)
@ -114,11 +99,8 @@ int AllianceAuto(void)
}
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 (sf->alliance == f2->alliance)
return AllianceAuto();
@ -195,9 +177,11 @@ static int AllianceRestricted(void)
}
int
alliedgroup(const struct plane *pl, const struct faction *f,
const struct faction *f2, const struct ally *sf, int mode)
alliedgroup(const struct faction *f,
const struct faction *f2, const struct group *g, int mode)
{
ally *sf = g ? g->allies : f->allies;
if (!(faction_alive(f) && faction_alive(f2))) {
return 0;
}
@ -205,9 +189,9 @@ alliedgroup(const struct plane *pl, const struct faction *f,
sf = sf->next;
}
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 (a_find(f->attribs, &at_npcfaction)) {
return mode;
@ -223,26 +207,24 @@ alliedgroup(const struct plane *pl, const struct faction *f,
}
int
alliedfaction(const struct plane *pl, const struct faction *f,
const struct faction *f2, int mode)
alliedfaction(const struct faction *f, 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. */
int alliedunit(const unit * u, const faction * f2, int mode)
{
int automode;
assert(u);
assert(f2);
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;
}
if (!faction_alive(f2)) {
return 0;
}
if (u->faction != NULL && f2 != NULL) {
ally *sf;
plane *pl;
if (mode & HELP_FIGHT) {
if ((u->flags & UFL_DEFENDER) || (u->faction->flags & FFL_DEFENDER)) {
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)) {
const attrib *a = a_find(u->attribs, &at_group);
if (a != NULL)
sf = ((group *)a->data.v)->allies;
if (a != NULL) {
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;
}
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;
}

View File

@ -24,8 +24,8 @@ extern "C" {
#endif
struct attrib_type;
struct plane;
struct faction;
struct group;
struct gamedata;
struct unit;
@ -37,19 +37,21 @@ extern "C" {
int status;
} 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_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 HelpMask(void); /* flags restricted to allied factions */
int alliedunit(const struct unit *u, const struct faction *f2,
int mode);
int alliedfaction(const struct plane *pl, const struct faction *f,
const struct faction *f2, int mode);
int alliedgroup(const struct plane *pl, const struct faction *f,
const struct faction *f2, const struct ally *sf, int mode);
int alliedfaction(const struct faction *f, const struct faction *f2,
int mode);
int alliedgroup(const struct faction *f, const struct faction *f2,
const struct group *g, int mode);
#ifdef __cplusplus
}

View File

@ -7,37 +7,22 @@
static void test_ally(CuTest * tc)
{
ally * al = 0;
ally * al = NULL;
struct faction * f1 = test_create_faction(NULL);
ally_add(&al, f1);
ally_set(&al, f1, HELP_GUARD);
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, ally_find(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);
CuAssertIntEquals(tc, 0, ally_get(al, f1));
}
CuSuite *get_ally_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_ally);
SUITE_ADD_TEST(suite, test_ally_null);
return suite;
}

View File

@ -496,7 +496,7 @@ void destroyfaction(faction ** fp)
handle_event(f->attribs, "destroy", f);
if (f->alliance) {
setalliance(f, 0);
setalliance(f, NULL);
}
funhash(f);
@ -531,20 +531,9 @@ int get_alliance(const faction * a, const faction * b)
void set_alliance(faction * a, faction * b, int status)
{
ally **sfp;
sfp = &a->allies;
while (*sfp) {
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;
/* TODO: optimization (use allies_walk?) */
int original = ally_get(a->allies, b);
ally_set(&a->allies, b, status | original);
}
void renumber_faction(faction * f, int no)

View File

@ -111,6 +111,8 @@ extern "C" {
void fhash(struct faction *f);
void funhash(struct faction *f);
int faction_ally_status(const faction *f, const faction *f2);
struct faction *findfaction(int n);
int max_magicians(const faction * f);
void set_show_item(faction * f, const struct item_type *itype);

View File

@ -29,20 +29,18 @@
static void test_destroyfaction_allies(CuTest *tc) {
faction *f1, *f2;
region *r;
ally *al;
test_setup();
r = test_create_region(0, 0, NULL);
f1 = test_create_faction(NULL);
test_create_unit(f1, r);
f2 = test_create_faction(NULL);
al = ally_add(&f1->allies, f2);
al->status = HELP_FIGHT;
CuAssertIntEquals(tc, HELP_FIGHT, alliedgroup(0, f1, f2, f1->allies, HELP_ALL));
ally_set(&f1->allies, f2, HELP_FIGHT);
CuAssertIntEquals(tc, HELP_FIGHT, alliedfaction(f1, f2, HELP_ALL));
CuAssertPtrEquals(tc, f2, f1->next);
destroyfaction(&f1->next);
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();
}

View File

@ -72,11 +72,10 @@ static void init_group(faction * f, group * g)
ally *a, **an;
an = &g->allies;
for (a = f->allies; a; a = a->next)
for (a = f->allies; a; a = a->next) {
if (a->faction) {
ally *ga = ally_add(an, a->faction);
ga->status = a->status;
an = &ga->next;
ally_set(an, a->faction, a->status);
}
}
}
@ -228,7 +227,6 @@ void read_groups(gamedata *data, faction * f)
{
struct storage *store = data->store;
for (;;) {
ally **pa;
group *g;
int gid;
char buf[1024];
@ -238,19 +236,7 @@ void read_groups(gamedata *data, faction * f)
break;
READ_STR(store, buf, sizeof(buf));
g = new_group(f, buf, gid);
pa = &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_allies(data, &g->allies);
read_attribs(data, &g->attribs, g);
}
}

View File

@ -28,7 +28,6 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
faction *f, *f2;
unit * u;
group *g;
ally *al;
int fno;
test_setup();
@ -42,8 +41,8 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
CuAssertPtrNotNull(tc, u);
g = join_group(u, "group");
CuAssertPtrNotNull(tc, g);
al = ally_add(&g->allies, f);
CuAssertPtrNotNull(tc, al);
ally_set(&g->allies, f, HELP_GIVE);
CuAssertPtrNotNull(tc, g->allies);
CuAssertPtrEquals(tc, f, factions);
destroyfaction(&factions);
@ -73,7 +72,6 @@ static void test_group_readwrite(CuTest * tc)
{
faction * f;
group *g;
ally *al;
int i;
gamedata data;
storage store;
@ -85,8 +83,7 @@ static void test_group_readwrite(CuTest * tc)
new_group(f, "NW", 42);
g = new_group(f, "Egoisten", 43);
key_set(&g->attribs, 44, 44);
al = ally_add(&g->allies, f);
al->status = HELP_GIVE;
ally_set(&g->allies, f, HELP_GIVE);
write_groups(&store, f);
WRITE_INT(&store, 47);

View File

@ -28,10 +28,10 @@ extern "C" {
struct plane;
struct storage;
#define PFL_NOCOORDS 1 /* not in use */
#define PFL_NORECRUITS 2
#define PFL_NOALLIANCES 4
#define PFL_LOWSTEALING 8
#define PFL_NOCOORDS 1 /* not implemented */
#define PFL_NORECRUITS 2 /* cannot recruit */
#define PFL_NOALLIANCES 4 /* not implemented */
#define PFL_LOWSTEALING 8 /* not implemented */
#define PFL_NOGIVE 16 /* Übergaben sind unmöglich */
#define PFL_NOATTACK 32 /* Angriffe und Diebstähle sind unmöglich */
#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_NOBUILD 1024 /* Bauen außer Betrieb */
#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_NOMONSTERS 16384 /* no monster randenc */

View File

@ -47,7 +47,6 @@ void test_pool(CuTest *tc) {
faction *f;
region *r;
struct resource_type *rtype;
ally *al;
test_setup();
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, 200, get_pooled(u1, rtype, GET_POOLED_SLACK | GET_POOLED_RESERVE, INT_MAX));
al = ally_add(&u3->faction->allies, f);
al->status = HELP_GUARD;
ally_set(&u3->faction->allies, f, HELP_GUARD);
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_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;
region *r;
struct item_type *itype;
ally *al;
test_setup();
test_create_world();
@ -135,8 +132,7 @@ void test_pool_use(CuTest *tc) {
set_resvalue(u2, itype, 100);
i_change(&u3->items, itype, 400);
set_resvalue(u3, itype, 200);
al = ally_add(&u3->faction->allies, f);
al->status = HELP_MONEY;
ally_set(&u3->faction->allies, f, HELP_MONEY);
CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_SLACK, 10));
CuAssertIntEquals(tc, 40, use_pooled(u1, itype->rtype, GET_SLACK, 50));

View File

@ -1082,7 +1082,7 @@ faction *read_faction(gamedata * data)
/* mistakes were made in the past*/
f->options &= ~WANT_OPTION(O_JSON);
}
read_allies(data, f);
read_allies(data, &f->allies);
read_groups(data, f);
f->spellbook = 0;
if (data->version >= REGIONOWNER_VERSION) {
@ -1145,19 +1145,15 @@ void write_faction(gamedata *data, const faction * f)
WRITE_SECTION(data->store);
for (sf = f->allies; sf; sf = sf->next) {
int no;
int status;
assert(sf->faction);
no = sf->faction->no;
status = alliedfaction(NULL, f, sf->faction, HELP_ALL);
if (status != 0) {
WRITE_INT(data->store, no);
if (faction_alive(sf->faction)) {
if (sf->status != 0) {
WRITE_INT(data->store, sf->faction->no);
WRITE_INT(data->store, sf->status);
}
}
}
WRITE_INT(data->store, 0);
WRITE_SECTION(data->store);
write_groups(data->store, f);

View File

@ -250,7 +250,6 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
faction *f, *f2;
unit * u;
group *g;
ally *al;
int fno;
gamedata data;
storage store;
@ -269,8 +268,8 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
CuAssertPtrNotNull(tc, u);
g = join_group(u, "group");
CuAssertPtrNotNull(tc, g);
al = ally_add(&g->allies, f);
CuAssertPtrNotNull(tc, al);
ally_set(&g->allies, f, HELP_GIVE);
CuAssertPtrNotNull(tc, g->allies);
CuAssertPtrEquals(tc, f, factions);
destroyfaction(&factions);

View File

@ -800,7 +800,7 @@ void immigration(void)
void nmr_warnings(void)
{
faction *f, *fa;
#define FRIEND (HELP_GUARD|HELP_MONEY)
#define HELP_NMR (HELP_GUARD|HELP_MONEY)
for (f = factions; f; f = f->next) {
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
@ -816,14 +816,12 @@ void nmr_warnings(void)
warn = 1;
}
}
else if (alliedfaction(NULL, f, fa, FRIEND)
&& alliedfaction(NULL, fa, f, FRIEND)) {
else if (alliedfaction(f, fa, HELP_NMR) && alliedfaction(fa, f, HELP_NMR)) {
warn = 1;
}
if (warn) {
if (msg == NULL) {
msg =
msg_message("warn_dropout", "faction turns", f,
msg = msg_message("warn_dropout", "faction turns", f,
turn - f->lastorders);
}
add_message(&fa->msgs, msg);

View File

@ -222,7 +222,6 @@ static void test_rule_force_leave(CuTest *tc) {
}
static void test_force_leave_buildings(CuTest *tc) {
ally *al;
region *r;
unit *u1, *u2, *u3;
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"));
u_set_building(u3, b);
al = ally_add(&u1->faction->allies, u3->faction);
al->status = HELP_GUARD;
ally_set(&u1->faction->allies, u3->faction, HELP_GUARD);
force_leave(r, NULL);
CuAssertPtrEquals_Msg(tc, "allies should not be forced to leave", b, u3->building);
test_teardown();
@ -1265,25 +1263,25 @@ static void test_ally_cmd(CuTest *tc) {
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
ally_cmd(u, ord);
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);
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
ally_cmd(u, ord);
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);
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
ally_cmd(u, ord);
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);
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);
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);
test_teardown();

View File

@ -153,7 +153,6 @@ static void test_ship_has_harbormaster_same_faction(CuTest * tc) {
static void test_ship_has_harbormaster_ally(CuTest * tc) {
unit *u;
move_fixture mf;
ally *al;
test_setup();
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->building = mf.b;
building_set_owner(u);
al = ally_add(&u->faction->allies, mf.u->faction);
al->status = HELP_GUARD;
ally_set(&u->faction->allies, mf.u->faction, HELP_GUARD);
CuAssertIntEquals(tc, SA_HARBOUR, check_ship_allowed(mf.sh, mf.r));
test_teardown();

View File

@ -1518,7 +1518,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
const ally *sf;
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) {
++allierte;
}
@ -1529,7 +1529,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
sbs_init(&sbs, buf, size);
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)
continue;
i++;
@ -1720,9 +1720,10 @@ static void list_address(struct stream *out, const faction * uf, selist * seenfa
str ? str : "");
if (uf == f)
label = '*';
else if (is_allied(uf, f))
else if (is_allied(uf, f)) {
label = 'o';
else if (alliedfaction(NULL, uf, f, HELP_ALL))
}
else if (alliedfaction(uf, f, HELP_ALL))
label = '+';
paragraph(out, buf, 4, 0, label);
}

View File

@ -969,7 +969,7 @@ bufunit(const faction * f, const unit * u, seen_mode mode, char *buf,
dh = 0;
if (!getarnt) {
if (alliedfaction(rplane(u->region), f, fv, HELP_ALL)) {
if (alliedfaction(f, fv, HELP_ALL)) {
dh = 1;
}
}

View File

@ -177,7 +177,6 @@ static void test_bufunit_fstealth(CuTest *tc) {
faction *f1, *f2;
region *r;
unit *u;
ally *al;
char buf[256];
struct locale *lang;
@ -232,8 +231,7 @@ static void test_bufunit_fstealth(CuTest *tc) {
u->flags &= ~UFL_ANON_FACTION;
/* we see the same thing as them when we are an ally */
al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH;
ally_set(&f1->allies, f2, HELP_FSTEALTH);
bufunit(f2, u, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf);

View File

@ -636,7 +636,6 @@ static void test_teach_many_to_one(CuTest *tc) {
static void test_teach_message(CuTest *tc) {
unit *u, *u1, *u2;
attrib *a;
ally *al;
teaching_info *teach;
test_setup();
@ -652,8 +651,7 @@ static void test_teach_message(CuTest *tc) {
set_level(u1, SK_CROSSBOW, TEACHDIFFERENCE);
u1->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
u2 = test_create_unit(test_create_faction(NULL), u->region);
al = ally_add(&u->faction->allies, u2->faction);
al->status = HELP_GUARD;
ally_set(&u->faction->allies, u2->faction, HELP_GUARD);
set_level(u2, SK_CROSSBOW, TEACHDIFFERENCE);
u2->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
CuAssertTrue(tc, !alliedunit(u, u1->faction, HELP_GUARD));