diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 1053f8e28..1f57609c7 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -105,16 +105,20 @@ void allies_write(gamedata * data, const allies *alist) write_faction_reference(NULL, data->store); } -void allies_read(gamedata * data, allies **sfp) +void allies_read(gamedata * data, allies **p_al) { for (;;) { - int aid, state; + faction *f; + int aid, status; READ_INT(data->store, &aid); /* TODO: deal with unresolved factions, somehow */ - if (aid >=0) { + if (aid <= 0) { break; } - READ_INT(data->store, &state); + f = findfaction(aid); + if (!f) f = faction_create(aid); + READ_INT(data->store, &status); + allies_set(p_al, f, status); } } diff --git a/src/kernel/ally.test.c b/src/kernel/ally.test.c index 92011c566..0b17870bb 100644 --- a/src/kernel/ally.test.c +++ b/src/kernel/ally.test.c @@ -23,7 +23,7 @@ static void test_ally(CuTest * tc) test_teardown(); } -static void test_allies_clone(CuTest * tc) +static void test_ally_clone(CuTest * tc) { struct ally * al = NULL, *ac; struct faction * f; @@ -63,8 +63,8 @@ CuSuite *get_ally_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_ally); + SUITE_ADD_TEST(suite, test_ally_clone); SUITE_ADD_TEST(suite, test_allies); - SUITE_ADD_TEST(suite, test_allies_clone); return suite; }