Exemplo n.º 1
0
void test_upkeep_from_friend(CuTest * tc)
{
    region *r;
    unit *u1, *u2;
    faction *f1, *f2;
    const item_type *i_silver;

    test_cleanup();
    test_create_world();

    i_silver = it_find("money");
    assert(i_silver);
    r = findregion(0, 0);
    f1 = test_create_faction(test_create_race("human"));
    f2 = test_create_faction(test_create_race("human"));
    assert(f1 && f2);
    set_alliance(f1, f2, HELP_MONEY);
    u1 = test_create_unit(f1, r);
    u2 = test_create_unit(f2, r);
    assert(r && u1 && u2);

    set_param(&global.parameters, "rules.food.flags", "0");
    i_change(&u1->items, i_silver, 30);
    get_food(r);
    CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
    CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER));
    CuAssertIntEquals(tc, 0, fval(u2, UFL_HUNGER));
    get_food(r);
    CuAssertIntEquals(tc, 0, i_get(u1->items, i_silver));
    CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER));
    CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER));

    test_cleanup();
}
Exemplo n.º 2
0
static int tolua_faction_set_policy(lua_State * L)
{
    faction *self = (faction *)tolua_tousertype(L, 1, 0);
    faction *other = (faction *)tolua_tousertype(L, 2, 0);
    const char *policy = tolua_tostring(L, 3, 0);
    int value = tolua_toboolean(L, 4, 0);

    int mode;
    for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
        if (strcmp(policy, helpmodes[mode].name) == 0) {
            if (value) {
                set_alliance(self, other, get_alliance(self,
                    other) | helpmodes[mode].status);
            }
            else {
                set_alliance(self, other, get_alliance(self,
                    other) & ~helpmodes[mode].status);
            }
            break;
        }
    }

    return 0;
}