paused factions are not allied to anyone.

This commit is contained in:
Enno Rehling 2021-05-21 21:37:07 +02:00
parent 48fd0bd4af
commit 202642e7d0
2 changed files with 44 additions and 2 deletions

View File

@ -308,7 +308,7 @@ alliedgroup(const struct faction *f,
allies *all = g ? g->allies : f->allies;
int status;
if (!(faction_alive(f) && faction_alive(f2))) {
if (is_paused(f) || (!(faction_alive(f) && faction_alive(f2)))) {
return 0;
}
status = ally_get(all, f2) & mask;
@ -329,7 +329,7 @@ int alliedunit(const unit * u, const faction * f2, int mask)
if (u->faction == f2) {
return mask;
}
if (!faction_alive(f2)) {
if (is_paused(u->faction) || !faction_alive(f2)) {
return 0;
}
if (u->faction != NULL && f2 != NULL) {

View File

@ -66,12 +66,54 @@ static void test_allies_set(CuTest *tc) {
test_teardown();
}
static void test_alliedfaction(CuTest *tc) {
struct faction *f1, *f2;
struct allies * al = NULL;
test_setup();
f1 = test_create_faction();
f2 = test_create_faction();
CuAssertIntEquals(tc, 0, alliedfaction(f1, f2, HELP_ALL));
ally_set(&f1->allies, f2, HELP_GIVE);
CuAssertIntEquals(tc, HELP_GIVE, alliedfaction(f1, f2, HELP_ALL));
ally_set(&f1->allies, f2, HELP_ALL);
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(f1, f2, HELP_ALL));
f1->flags |= FFL_PAUSED;
CuAssertIntEquals(tc, 0, alliedfaction(f1, f2, HELP_ALL));
test_teardown();
}
static void test_alliedunit(CuTest *tc) {
struct faction *f2, *f1;
struct unit *u;
struct allies *al = NULL;
test_setup();
u = test_create_unit(f1 = test_create_faction(), test_create_plain(0, 0));
f2 = test_create_faction();
CuAssertIntEquals(tc, 0, alliedunit(u, f2, HELP_ALL));
ally_set(&f1->allies, f2, HELP_GIVE);
CuAssertIntEquals(tc, HELP_GIVE, alliedunit(u, f2, HELP_ALL));
ally_set(&f1->allies, f2, HELP_ALL);
CuAssertIntEquals(tc, HELP_ALL, alliedunit(u, f2, HELP_ALL));
f1->flags |= FFL_PAUSED;
CuAssertIntEquals(tc, 0, alliedunit(u, f2, HELP_ALL));
test_teardown();
}
CuSuite *get_ally_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_allies);
SUITE_ADD_TEST(suite, test_allies_clone);
SUITE_ADD_TEST(suite, test_allies_set);
SUITE_ADD_TEST(suite, test_alliedfaction);
SUITE_ADD_TEST(suite, test_alliedunit);
return suite;
}