forked from github/server
remove a faction from its alliance when it is dead.
This commit is contained in:
parent
872721dc0f
commit
04bf7153f0
|
@ -55,6 +55,9 @@ static void test_alliance_join(CuTest *tc) {
|
||||||
setalliance(fix.f2, al);
|
setalliance(fix.f2, al);
|
||||||
CuAssertPtrEquals(tc, fix.f1, alliance_get_leader(al));
|
CuAssertPtrEquals(tc, fix.f1, alliance_get_leader(al));
|
||||||
CuAssertTrue(tc, is_allied(fix.f1, fix.f2));
|
CuAssertTrue(tc, is_allied(fix.f1, fix.f2));
|
||||||
|
setalliance(fix.f1, 0);
|
||||||
|
CuAssertPtrEquals(tc, fix.f2, alliance_get_leader(al));
|
||||||
|
CuAssertTrue(tc, !is_allied(fix.f1, fix.f2));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -651,6 +651,9 @@ void remove_empty_factions(void)
|
||||||
*fp = f->next;
|
*fp = f->next;
|
||||||
funhash(f);
|
funhash(f);
|
||||||
free_faction(f);
|
free_faction(f);
|
||||||
|
if (f->alliance && f->alliance->_leader == f) {
|
||||||
|
setalliance(f, 0);
|
||||||
|
}
|
||||||
free(f);
|
free(f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|
||||||
#include <kernel/ally.h>
|
#include <kernel/ally.h>
|
||||||
|
#include <kernel/alliance.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
|
@ -30,6 +31,22 @@ static void test_remove_empty_factions_allies(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_remove_empty_factions_alliance(CuTest *tc) {
|
||||||
|
faction *f;
|
||||||
|
struct alliance *al;
|
||||||
|
region *r;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
r = test_create_region(0, 0, 0);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
al = makealliance(0, "Hodor");
|
||||||
|
setalliance(f, al);
|
||||||
|
CuAssertPtrEquals(tc, f, alliance_get_leader(al));
|
||||||
|
remove_empty_factions();
|
||||||
|
CuAssertPtrEquals(tc, 0, al->_leader);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_remove_empty_factions(CuTest *tc) {
|
static void test_remove_empty_factions(CuTest *tc) {
|
||||||
faction *f, *fm;
|
faction *f, *fm;
|
||||||
int fno;
|
int fno;
|
||||||
|
@ -130,6 +147,7 @@ CuSuite *get_faction_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_addfaction);
|
SUITE_ADD_TEST(suite, test_addfaction);
|
||||||
SUITE_ADD_TEST(suite, test_remove_empty_factions);
|
SUITE_ADD_TEST(suite, test_remove_empty_factions);
|
||||||
SUITE_ADD_TEST(suite, test_remove_empty_factions_allies);
|
SUITE_ADD_TEST(suite, test_remove_empty_factions_allies);
|
||||||
|
SUITE_ADD_TEST(suite, test_remove_empty_factions_alliance);
|
||||||
SUITE_ADD_TEST(suite, test_remove_dead_factions);
|
SUITE_ADD_TEST(suite, test_remove_dead_factions);
|
||||||
SUITE_ADD_TEST(suite, test_get_monsters);
|
SUITE_ADD_TEST(suite, test_get_monsters);
|
||||||
SUITE_ADD_TEST(suite, test_set_origin);
|
SUITE_ADD_TEST(suite, test_set_origin);
|
||||||
|
|
Loading…
Reference in New Issue