forked from github/server
tests for entering ships (but not yet full coverage)
This commit is contained in:
parent
64a2073033
commit
7d5109329f
14
src/laws.c
14
src/laws.c
|
@ -993,31 +993,35 @@ static bool CheckOverload(void)
|
||||||
return value;
|
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;
|
region *r = u->region;
|
||||||
ship *sh;
|
ship *sh;
|
||||||
|
const race * rc = u_race(u);
|
||||||
|
|
||||||
/* Muss abgefangen werden, sonst koennten Schwimmer an
|
/* Muss abgefangen werden, sonst koennten Schwimmer an
|
||||||
* Bord von Schiffen an Land gelangen. */
|
* Bord von Schiffen an Land gelangen. */
|
||||||
if (!fval(u_race(u), RCF_CANSAIL) || (!fval(u_race(u), RCF_WALK)
|
if (!(rc->flags & (RCF_CANSAIL|RCF_WALK|RCF_FLY))) {
|
||||||
&& !fval(u_race(u), RCF_FLY))) {
|
if (report) {
|
||||||
cmistake(u, ord, 233, MSG_MOVE);
|
cmistake(u, ord, 233, MSG_MOVE);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sh = findship(id);
|
sh = findship(id);
|
||||||
if (sh == NULL || sh->region != r) {
|
if (sh == NULL || sh->region != r) {
|
||||||
if (report)
|
if (report) {
|
||||||
cmistake(u, ord, 20, MSG_MOVE);
|
cmistake(u, ord, 20, MSG_MOVE);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (sh == u->ship) {
|
if (sh == u->ship) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!mayboard(u, sh)) {
|
if (!mayboard(u, sh)) {
|
||||||
if (report)
|
if (report) {
|
||||||
cmistake(u, ord, 34, MSG_MOVE);
|
cmistake(u, ord, 34, MSG_MOVE);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (CheckOverload()) {
|
if (CheckOverload()) {
|
||||||
|
|
|
@ -44,15 +44,16 @@ extern "C" {
|
||||||
void get_food(struct region * r);
|
void get_food(struct region * r);
|
||||||
int can_contact(const struct region *r, const struct unit *u, const struct unit *u2);
|
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);
|
void processorders(void);
|
||||||
extern struct attrib_type at_germs;
|
extern struct attrib_type at_germs;
|
||||||
|
|
||||||
extern int dropouts[2];
|
extern int dropouts[2];
|
||||||
extern int *age;
|
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 new_units(void);
|
||||||
extern void defaultorders(void);
|
extern void defaultorders(void);
|
||||||
|
|
|
@ -134,18 +134,64 @@ static void test_enter_building(CuTest * tc)
|
||||||
|
|
||||||
rc->flags = RCF_WALK;
|
rc->flags = RCF_WALK;
|
||||||
u->building = 0;
|
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);
|
CuAssertPtrEquals(tc, b, u->building);
|
||||||
|
|
||||||
rc->flags = RCF_FLY;
|
rc->flags = RCF_FLY;
|
||||||
u->building = 0;
|
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);
|
CuAssertPtrEquals(tc, b, u->building);
|
||||||
|
|
||||||
rc->flags = RCF_SWIM;
|
rc->flags = RCF_SWIM;
|
||||||
u->building = 0;
|
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->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();
|
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_cannot_create_unit_above_limit);
|
||||||
SUITE_ADD_TEST(suite, test_contact);
|
SUITE_ADD_TEST(suite, test_contact);
|
||||||
SUITE_ADD_TEST(suite, test_enter_building);
|
SUITE_ADD_TEST(suite, test_enter_building);
|
||||||
|
SUITE_ADD_TEST(suite, test_enter_ship);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue