diff --git a/src/laws.c b/src/laws.c index 3994927a4..bd2abc9d8 100755 --- a/src/laws.c +++ b/src/laws.c @@ -993,31 +993,35 @@ static bool CheckOverload(void) return value; } -int enter_ship(unit * u, struct order *ord, int id, int report) +int enter_ship(unit * u, struct order *ord, int id, bool report) { region *r = u->region; ship *sh; + const race * rc = u_race(u); /* Muss abgefangen werden, sonst koennten Schwimmer an * Bord von Schiffen an Land gelangen. */ - if (!fval(u_race(u), RCF_CANSAIL) || (!fval(u_race(u), RCF_WALK) - && !fval(u_race(u), RCF_FLY))) { - cmistake(u, ord, 233, MSG_MOVE); + if (!(rc->flags & (RCF_CANSAIL|RCF_WALK|RCF_FLY))) { + if (report) { + cmistake(u, ord, 233, MSG_MOVE); + } return 0; } sh = findship(id); if (sh == NULL || sh->region != r) { - if (report) + if (report) { cmistake(u, ord, 20, MSG_MOVE); + } return 0; } if (sh == u->ship) { return 1; } if (!mayboard(u, sh)) { - if (report) + if (report) { cmistake(u, ord, 34, MSG_MOVE); + } return 0; } if (CheckOverload()) { diff --git a/src/laws.h b/src/laws.h index 64bbe7b65..5a7cd8024 100755 --- a/src/laws.h +++ b/src/laws.h @@ -44,15 +44,16 @@ extern "C" { void get_food(struct region * r); int can_contact(const struct region *r, const struct unit *u, const struct unit *u2); -/* eressea-specific. put somewhere else, please. */ + int enter_building(struct unit *u, struct order *ord, int id, bool report); + int enter_ship(struct unit *u, struct order *ord, int id, bool report); + + /* eressea-specific. put somewhere else, please. */ void processorders(void); extern struct attrib_type at_germs; extern int dropouts[2]; extern int *age; - 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); extern void defaultorders(void); diff --git a/src/laws.test.c b/src/laws.test.c index f6a001179..2280b155d 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -134,18 +134,64 @@ static void test_enter_building(CuTest * tc) rc->flags = RCF_WALK; u->building = 0; - enter_building(u, NULL, b->no, false); + CuAssertIntEquals(tc, 1, 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); + CuAssertIntEquals(tc, 1, 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); + CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false)); CuAssertPtrEquals(tc, 0, u->building); + CuAssertPtrEquals(tc, 0, u->faction->msgs); + + CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true)); + CuAssertPtrNotNull(tc, u->faction->msgs); + + test_cleanup(); +} + +static void test_enter_ship(CuTest * tc) +{ + unit *u; + region *r; + ship *sh; + 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); + sh = test_create_ship(r, st_get_or_create("boat")); + + rc->flags = RCF_WALK; + u->ship = 0; + CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false)); + CuAssertPtrEquals(tc, sh, u->ship); + + rc->flags = RCF_FLY; + u->ship = 0; + CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false)); + CuAssertPtrEquals(tc, sh, u->ship); + + rc->flags = RCF_CANSAIL; + u->ship = 0; + CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false)); + CuAssertPtrEquals(tc, sh, u->ship); + + rc->flags = RCF_SWIM; + u->ship = 0; + CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false)); + CuAssertPtrEquals(tc, 0, u->ship); + CuAssertPtrEquals(tc, 0, u->faction->msgs); + + CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true)); + CuAssertPtrNotNull(tc, u->faction->msgs); test_cleanup(); } @@ -479,5 +525,6 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit); SUITE_ADD_TEST(suite, test_contact); SUITE_ADD_TEST(suite, test_enter_building); + SUITE_ADD_TEST(suite, test_enter_ship); return suite; }