diff --git a/src/laws.c b/src/laws.c index e22824789..3994927a4 100755 --- a/src/laws.c +++ b/src/laws.c @@ -1054,7 +1054,7 @@ int enter_ship(unit * u, struct order *ord, int id, int report) return 0; } -int enter_building(unit * u, order * ord, int id, int report) +int enter_building(unit * u, order * ord, int id, bool report) { region *r = u->region; building *b; diff --git a/src/laws.h b/src/laws.h index 869534212..64bbe7b65 100755 --- a/src/laws.h +++ b/src/laws.h @@ -51,7 +51,7 @@ extern "C" { extern int dropouts[2]; extern int *age; - extern int enter_building(struct unit *u, struct order *ord, int id, int report); + extern int enter_building(struct unit *u, struct order *ord, int id, bool report); extern int enter_ship(struct unit *u, struct order *ord, int id, int report); extern void new_units(void); diff --git a/src/laws.test.c b/src/laws.test.c index 65b360f6f..f6a001179 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -117,6 +117,39 @@ static void test_contact(CuTest * tc) CuAssertIntEquals(tc, 1, can_contact(r, u1, u2)); } +static void test_enter_building(CuTest * tc) +{ + unit *u; + region *r; + building *b; + race * rc; + + test_cleanup(); + test_create_world(); + + r = findregion(0, 0); + rc = rc_get_or_create("human"); + u = test_create_unit(test_create_faction(rc), r); + b = test_create_building(r, bt_get_or_create("castle")); + + rc->flags = RCF_WALK; + u->building = 0; + enter_building(u, NULL, b->no, false); + CuAssertPtrEquals(tc, b, u->building); + + rc->flags = RCF_FLY; + u->building = 0; + enter_building(u, NULL, b->no, false); + CuAssertPtrEquals(tc, b, u->building); + + rc->flags = RCF_SWIM; + u->building = 0; + enter_building(u, NULL, b->no, false); + CuAssertPtrEquals(tc, 0, u->building); + + test_cleanup(); +} + static void test_fishing_feeds_2_people(CuTest * tc) { const resource_type *rtype; @@ -445,5 +478,6 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_new_units); SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit); SUITE_ADD_TEST(suite, test_contact); + SUITE_ADD_TEST(suite, test_enter_building); return suite; }