Einfacher Test

Plus Bugfix für Gebäude ohne Improvement, damit diese auch die gleiche
Funktionalität aus der XML nutzen können.
This commit is contained in:
CTD 2015-01-12 16:57:05 +01:00
parent 34fc1b3d34
commit d403afc7fc
2 changed files with 118 additions and 89 deletions

View File

@ -176,6 +176,34 @@ static void test_building_bonus_respects_size(CuTest * tc)
test_cleanup();
}
static void test_building_defence_bonus(CuTest * tc)
{
unit *au;
region *r;
building * bld;
building_type * btype;
faction * f;
int def;
test_cleanup();
test_create_world();
r = findregion(0, 0);
register_buildings();
btype = bt_get_or_create("castle");
btype->protection = get_function("building_protection");
btype->construction->defense_bonus = 3;
bld = test_create_building(r, btype);
bld->size = 1;
f = test_create_faction(rc_find("human"));
au = test_create_unit(f, r);
scale_number(au, 1);
u_set_building(au, bld);
def = btype->protection(bld, au, DEFENSE_BONUS);
CuAssertIntEquals(tc, 3, def);
test_cleanup();
}
CuSuite *get_battle_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -183,5 +211,6 @@ CuSuite *get_battle_suite(void)
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
SUITE_ADD_TEST(suite, test_building_defence_bonus);
return suite;
}

View File

@ -322,7 +322,7 @@ static int building_protection(building * b, unit * u, building_bonus bonus)
int i = 0;
int bsize = buildingeffsize(b, false);
const construction *cons = b->type->construction;
if (!cons || !cons->improvement) {
if (!cons) {
return 0;
}