2016-11-01 17:25:52 +01:00
|
|
|
#include <platform.h>
|
2014-08-31 08:58:55 +02:00
|
|
|
#include "upkeep.h"
|
|
|
|
|
2018-10-26 21:49:58 +02:00
|
|
|
#include <kernel/ally.h>
|
2014-08-31 08:58:55 +02:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
void test_upkeep_default(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2;
|
|
|
|
faction *f1, *f2;
|
|
|
|
const item_type *i_silver;
|
|
|
|
|
2016-08-29 15:21:28 +02:00
|
|
|
test_setup();
|
2017-03-10 21:29:37 +01:00
|
|
|
init_resources();
|
2014-08-31 08:58:55 +02:00
|
|
|
i_silver = it_find("money");
|
|
|
|
assert(i_silver);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2014-08-31 08:58:55 +02:00
|
|
|
f1 = test_create_faction(test_create_race("human"));
|
|
|
|
f2 = test_create_faction(test_create_race("human"));
|
|
|
|
assert(f1 && f2);
|
|
|
|
u1 = test_create_unit(f1, r);
|
|
|
|
u2 = test_create_unit(f2, r);
|
|
|
|
assert(r && u1 && u2);
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.food.flags", "0");
|
2014-08-31 08:58:55 +02:00
|
|
|
i_change(&u1->items, i_silver, 20);
|
|
|
|
get_food(r);
|
2017-02-18 21:15:14 +01:00
|
|
|
/* since u1 and u2 are not allied, u1 should not help u2 with upkeep */
|
2014-08-31 08:58:55 +02:00
|
|
|
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
|
|
|
|
CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER));
|
|
|
|
CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-31 08:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_upkeep_hunger_damage(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
unit *u1;
|
|
|
|
faction *f1;
|
|
|
|
const item_type *i_silver;
|
|
|
|
|
2016-08-29 15:21:28 +02:00
|
|
|
test_setup();
|
2017-03-10 21:29:37 +01:00
|
|
|
init_resources();
|
2014-08-31 08:58:55 +02:00
|
|
|
|
|
|
|
i_silver = it_find("money");
|
|
|
|
assert(i_silver);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2014-08-31 08:58:55 +02:00
|
|
|
f1 = test_create_faction(test_create_race("human"));
|
|
|
|
u1 = test_create_unit(f1, r);
|
|
|
|
assert(r && u1);
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.food.flags", "0");
|
2014-08-31 08:58:55 +02:00
|
|
|
u1->hp = 100;
|
|
|
|
get_food(r);
|
2017-02-18 21:15:14 +01:00
|
|
|
/* since u1 and u2 are not allied, u1 should not help u2 with upkeep */
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertTrue(tc, u1->hp < 100);
|
2014-08-31 08:58:55 +02:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-31 08:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_upkeep_from_pool(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2;
|
|
|
|
const item_type *i_silver;
|
|
|
|
|
2016-08-29 15:21:28 +02:00
|
|
|
test_setup();
|
2017-03-10 21:29:37 +01:00
|
|
|
init_resources();
|
2014-08-31 08:58:55 +02:00
|
|
|
|
|
|
|
i_silver = it_find("money");
|
|
|
|
assert(i_silver);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-11-19 20:57:10 +01:00
|
|
|
assert(r);
|
2014-08-31 08:58:55 +02:00
|
|
|
u1 = test_create_unit(test_create_faction(test_create_race("human")), r);
|
2015-07-06 19:53:09 +02:00
|
|
|
assert(u1);
|
2014-08-31 08:58:55 +02:00
|
|
|
u2 = test_create_unit(u1->faction, r);
|
2016-11-19 20:57:10 +01:00
|
|
|
assert(u2);
|
2014-08-31 08:58:55 +02:00
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.food.flags", "0");
|
2014-08-31 08:58:55 +02:00
|
|
|
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));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-31 08:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test_upkeep_from_friend(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2;
|
|
|
|
faction *f1, *f2;
|
|
|
|
const item_type *i_silver;
|
|
|
|
|
2016-08-29 15:21:28 +02:00
|
|
|
test_setup();
|
2017-03-10 21:29:37 +01:00
|
|
|
init_resources();
|
2014-08-31 08:58:55 +02:00
|
|
|
|
|
|
|
i_silver = it_find("money");
|
|
|
|
assert(i_silver);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2014-08-31 08:58:55 +02:00
|
|
|
f1 = test_create_faction(test_create_race("human"));
|
|
|
|
f2 = test_create_faction(test_create_race("human"));
|
|
|
|
assert(f1 && f2);
|
2018-10-26 21:49:58 +02:00
|
|
|
ally_set(&f1->allies, f2, HELP_MONEY);
|
2014-08-31 08:58:55 +02:00
|
|
|
u1 = test_create_unit(f1, r);
|
|
|
|
u2 = test_create_unit(f2, r);
|
|
|
|
assert(r && u1 && u2);
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.food.flags", "0");
|
2014-08-31 08:58:55 +02:00
|
|
|
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));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-31 08:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_upkeep_free(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
unit *u;
|
|
|
|
const item_type *i_silver;
|
|
|
|
|
2016-08-29 15:21:28 +02:00
|
|
|
test_setup();
|
2017-03-10 21:29:37 +01:00
|
|
|
init_resources();
|
2014-08-31 08:58:55 +02:00
|
|
|
|
|
|
|
i_silver = it_find("money");
|
|
|
|
assert(i_silver);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2014-08-31 08:58:55 +02:00
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), r);
|
|
|
|
assert(r && u);
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
config_set("rules.food.flags", "4"); /* FOOD_IS_FREE */
|
2014-08-31 08:58:55 +02:00
|
|
|
get_food(r);
|
|
|
|
CuAssertIntEquals(tc, 0, i_get(u->items, i_silver));
|
|
|
|
CuAssertIntEquals(tc, 0, fval(u, UFL_HUNGER));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-31 08:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_upkeep_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_upkeep_default);
|
|
|
|
SUITE_ADD_TEST(suite, test_upkeep_from_pool);
|
|
|
|
SUITE_ADD_TEST(suite, test_upkeep_from_friend);
|
|
|
|
SUITE_ADD_TEST(suite, test_upkeep_hunger_damage);
|
|
|
|
SUITE_ADD_TEST(suite, test_upkeep_free);
|
|
|
|
return suite;
|
|
|
|
}
|