diff --git a/src/kernel/ally.c b/src/kernel/ally.c index e63d85cd2..b2796032f 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -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) { diff --git a/src/kernel/ally.test.c b/src/kernel/ally.test.c index 05477d372..48c8cc541 100644 --- a/src/kernel/ally.test.c +++ b/src/kernel/ally.test.c @@ -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; }