Beispiel #1
0
int
alliedgroup(const struct faction *f,
    const struct faction *f2, const struct group *g, int mask)
{
    allies *all = g ? g->allies : f->allies;
    int status;

    if (!(faction_alive(f) && faction_alive(f2))) {
        return 0;
    }
    status = ally_get(all, f2) & mask;
    return alliance_status(f, f2, status);
}
Beispiel #2
0
/* Die Gruppe von Einheit u hat helfe zu f2 gesetzt. */
int alliedunit(const unit * u, const faction * f2, int mask)
{
    assert(u);
    assert(f2);
    assert(u->region);            /* the unit should be in a region, but it's possible that u->number==0 (TEMP units) */
    if (u->faction == f2) {
        return mask;
    }
    if (!faction_alive(f2)) {
        return 0;
    }
    if (u->faction != NULL && f2 != NULL) {
        group *g;

        if (mask & HELP_FIGHT) {
            if ((u->flags & UFL_DEFENDER) || (u->faction->flags & FFL_DEFENDER)) {
                faction *owner = region_get_owner(u->region);
                /* helps the owner of the region */
                if (owner == f2) {
                    return HELP_FIGHT;
                }
            }
        }

        g = get_group(u);
        if (g) {
            return alliedgroup(u->faction, f2, g, mask);
        }
        return alliedfaction(u->faction, f2, mask);
    }
    return 0;
}
Beispiel #3
0
static void test_addfaction(CuTest *tc) {
    faction *f = 0;
    const struct race *rc;
    const struct locale *lang;

    test_cleanup();
    rc = rc_get_or_create("human");
    lang = test_create_locale();
    f = addfaction("*****@*****.**", "hurrdurr", rc, lang, 1234);
    CuAssertPtrNotNull(tc, f);
    CuAssertPtrNotNull(tc, f->name);
    CuAssertPtrEquals(tc, NULL, (void *)f->units);
    CuAssertPtrEquals(tc, NULL, (void *)f->next);
    CuAssertPtrEquals(tc, NULL, (void *)f->banner);
    CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
    CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
    CuAssertPtrEquals(tc, (void *)factions, (void *)f);
    CuAssertStrEquals(tc, "*****@*****.**", f->email);
    CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
    CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
    CuAssertIntEquals(tc, 1234, f->subscription);
    CuAssertIntEquals(tc, FFL_ISNEW, f->flags);
    CuAssertIntEquals(tc, 0, f->age);
    CuAssertTrue(tc, faction_alive(f));
    CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
    CuAssertIntEquals(tc, turn, f->lastorders);
    CuAssertPtrEquals(tc, f, findfaction(f->no));
    test_cleanup();
}
Beispiel #4
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();
}