Example #1
0
void remove_empty_factions(void)
{
    faction **fp;

    for (fp = &factions; *fp;) {
        faction *f = *fp;

        if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
            destroyfaction(fp);
        }
        else {
            fp = &(*fp)->next;
        }
    }
}
Example #2
0
static void test_group_readwrite_dead_faction(CuTest *tc) {
    gamedata data;
    storage store;
    faction *f, *f2;
    unit * u;
    group *g;
    ally *al;
    int fno;

    test_cleanup();
    f = test_create_faction(0);
    fno = f->no;
    CuAssertPtrEquals(tc, f, factions);
    CuAssertPtrEquals(tc, 0, f->next);
    f2 = test_create_faction(0);
    CuAssertPtrEquals(tc, f2, factions->next);
    u = test_create_unit(f2, test_create_region(0, 0, 0));
    CuAssertPtrNotNull(tc, u);
    g = join_group(u, "group");
    CuAssertPtrNotNull(tc, g);
    al = ally_add(&g->allies, f);
    CuAssertPtrNotNull(tc, al);

    CuAssertPtrEquals(tc, f, factions);
    destroyfaction(&factions);
    CuAssertTrue(tc, !f->_alive);
    CuAssertPtrEquals(tc, f2, factions);
    mstream_init(&data.strm);
    gamedata_init(&data, &store, RELEASE_VERSION);
    write_game(&data);
    free_gamedata();
    f = f2 = NULL;
    data.strm.api->rewind(data.strm.handle);
    read_game(&data);
    mstream_done(&data.strm);
    gamedata_done(&data);
    CuAssertPtrEquals(tc, 0, findfaction(fno));
    f2 = factions;
    CuAssertPtrNotNull(tc, f2);
    u = f2->units;
    CuAssertPtrNotNull(tc, u);
    g = get_group(u);
    CuAssertPtrNotNull(tc, g);
    CuAssertPtrEquals(tc, 0, g->allies);
    test_cleanup();
}
Example #3
0
static void test_destroyfaction_allies(CuTest *tc) {
    faction *f1, *f2;
    region *r;
    ally *al;

    test_cleanup();
    r = test_create_region(0, 0, 0);
    f1 = test_create_faction(0);
    test_create_unit(f1, r);
    f2 = test_create_faction(0);
    al = ally_add(&f1->allies, f2);
    al->status = HELP_FIGHT;
    CuAssertIntEquals(tc, HELP_FIGHT, alliedgroup(0, f1, f2, f1->allies, 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));
    test_cleanup();
}
Example #4
0
static int tolua_faction_destroy(lua_State * L)
{
    faction *f = (faction *)tolua_tousertype(L, 1, 0);
    destroyfaction(f);
    return 0;
}