Merge pull request #543 from ennorehling/bug-2228-tunneling

Bug 2228: piracy between land regions
This commit is contained in:
Enno Rehling 2016-08-20 19:33:04 +02:00 committed by GitHub
commit 17c88fa48d
7 changed files with 75 additions and 29 deletions

View File

@ -8,6 +8,31 @@ function setup()
eressea.settings.set("NewbieImmunity", "0") eressea.settings.set("NewbieImmunity", "0")
end end
function test_piracy()
local r = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local r3 = region.create(-1, 0, "ocean")
local f = faction.create("pirate@eressea.de", "human", "de")
local f2 = faction.create("elf@eressea.de", "human", "de")
local u1 = unit.create(f, r2, 1)
local u2 = unit.create(f2, r3, 1)
u1.ship = ship.create(r2, "longboat")
u2.ship = ship.create(r3, "longboat")
u1:set_skill("sailing", 10)
u2:set_skill("sailing", 10)
u1:clear_orders()
u1:add_order("PIRATERIE")
u2:clear_orders()
u2:add_order("NACH o")
process_orders()
-- write_reports()
assert_equal(r2, u1.region) -- should pass, but fails!!!
end
function test_dolphin_on_land() function test_dolphin_on_land()
local r1 = region.create(0, 0, "plain") local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain") local r2 = region.create(1, 0, "plain")

View File

@ -49,6 +49,8 @@ void game_done(void)
calendar_cleanup(); calendar_cleanup();
#endif #endif
free_functions(); free_functions();
free_config();
free_locales();
curses_done(); curses_done();
kernel_done(); kernel_done();
} }

View File

@ -1786,8 +1786,7 @@ bool can_takeoff(const ship * sh, const region * from, const region * to)
return true; return true;
} }
static void static void sail(unit * u, order * ord, region_list ** routep)
sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
{ {
region *starting_point = u->region; region *starting_point = u->region;
region *current_point, *last_point; region *current_point, *last_point;
@ -1909,12 +1908,10 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
} // storms_enabled } // storms_enabled
if (!fval(tthis, SEA_REGION)) { if (!fval(tthis, SEA_REGION)) {
if (!fval(tnext, SEA_REGION)) { if (!fval(tnext, SEA_REGION)) {
if (!move_on_land) { /* check that you're not traveling from one land region to another. */
/* check that you're not traveling from one land region to another. */ ADDMSG(&u->faction->msgs, msg_message("shipnoshore",
ADDMSG(&u->faction->msgs, msg_message("shipnoshore", "ship region", sh, next_point));
"ship region", sh, next_point)); break;
break;
}
} }
else { else {
if (!can_takeoff(sh, current_point, next_point)) { if (!can_takeoff(sh, current_point, next_point)) {
@ -2024,9 +2021,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
* transferiert wurden, kann der aktuelle Befehl gelöscht werden. */ * transferiert wurden, kann der aktuelle Befehl gelöscht werden. */
cycle_route(ord, u, step); cycle_route(ord, u, step);
set_order(&u->thisorder, NULL); set_order(&u->thisorder, NULL);
if (!move_on_land) { set_coast(sh, last_point, current_point);
set_coast(sh, last_point, current_point);
}
if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) { if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) {
ADDMSG(&f->msgs, msg_message("shipfly", "ship from to", sh, ADDMSG(&f->msgs, msg_message("shipfly", "ship from to", sh,
@ -2272,13 +2267,13 @@ static void travel(unit * u, region_list ** routep)
} }
} }
void move_cmd(unit * u, order * ord, bool move_on_land) void move_cmd(unit * u, order * ord)
{ {
region_list *route = NULL; region_list *route = NULL;
assert(u->number); assert(u->number);
if (u->ship && u == ship_owner(u->ship)) { if (u->ship && u == ship_owner(u->ship)) {
sail(u, ord, move_on_land, &route); sail(u, ord, &route);
} }
else { else {
travel(u, &route); travel(u, &route);
@ -2396,7 +2391,7 @@ int follow_ship(unit * u, order * ord)
init_tokens_str(command); init_tokens_str(command);
getstrtoken(); getstrtoken();
/* NACH ausführen */ /* NACH ausführen */
move_cmd(u, ord, false); move_cmd(u, ord);
return 1; /* true -> Einheitenliste von vorne durchgehen */ return 1; /* true -> Einheitenliste von vorne durchgehen */
} }
@ -2563,13 +2558,13 @@ void movement(void)
if (ships) { if (ships) {
if (u->ship && ship_owner(u->ship) == u) { if (u->ship && ship_owner(u->ship) == u) {
init_order(u->thisorder); init_order(u->thisorder);
move_cmd(u, u->thisorder, false); move_cmd(u, u->thisorder);
} }
} }
else { else {
if (!u->ship || ship_owner(u->ship) != u) { if (!u->ship || ship_owner(u->ship) != u) {
init_order(u->thisorder); init_order(u->thisorder);
move_cmd(u, u->thisorder, false); move_cmd(u, u->thisorder);
} }
} }
} }

View File

@ -74,7 +74,7 @@ extern "C" {
bool move_blocked(const struct unit *u, const struct region *src, bool move_blocked(const struct unit *u, const struct region *src,
const struct region *dest); const struct region *dest);
bool can_takeoff(const struct ship * sh, const struct region * from, const struct region * to); bool can_takeoff(const struct ship * sh, const struct region * from, const struct region * to);
void move_cmd(struct unit * u, struct order * ord, bool move_on_land); void move_cmd(struct unit * u, struct order * ord);
int follow_ship(struct unit * u, struct order * ord); int follow_ship(struct unit * u, struct order * ord);
#define SA_HARBOUR 1 #define SA_HARBOUR 1

View File

@ -206,7 +206,7 @@ void piracy_cmd(unit * u, order *ord)
/* Bewegung ausführen */ /* Bewegung ausführen */
init_order(u->thisorder); init_order(u->thisorder);
move_cmd(u, ord, true); move_cmd(u, ord);
} }
void age_piracy(region *r) { void age_piracy(region *r) {

View File

@ -178,22 +178,39 @@ static void test_piracy_cmd_walking(CuTest * tc) {
} }
static void test_piracy_cmd_land_to_land(CuTest * tc) { static void test_piracy_cmd_land_to_land(CuTest * tc) {
unit *pirate, *victim; unit *u;
order *ord; order *ord;
region *r; region *r;
faction *f;
int target;
const terrain_type *t_plain;
const ship_type *stype;
test_cleanup(); test_cleanup();
setup_pirate(&pirate, 0, 0, "boat", &ord, &victim, SEA_REGION, "boat"); setup_piracy();
set_level(pirate, SK_SAILING, pirate->ship->type->sumskill); t_plain = get_or_create_terrain("plain");
r = pirate->region; stype = test_create_shiptype("boat");
piracy_cmd(pirate, ord); // create a target:
CuAssertPtrEquals(tc, 0, pirate->thisorder); r = test_create_region(0, 0, t_plain);
CuAssertTrue(tc, pirate->region == r); f = test_create_faction(0);
/* TODO check message u = test_create_unit(f, r);
CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(pirate->faction->msgs, "travel")); u->ship = test_create_ship(r, stype);
*/ target = f->no;
// create a pirate:
r = test_create_region(1, 0, t_plain);
f = test_create_faction(0);
u = test_create_unit(f, r);
u->ship = test_create_ship(r, stype);
set_level(u, SK_SAILING, u->ship->type->sumskill);
ord = create_order(K_PIRACY, f->locale, "%s", itoa36(target));
piracy_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->thisorder);
CuAssertPtrEquals(tc, r, u->region);
// TODO check message
free_order(ord); free_order(ord);
test_cleanup(); test_cleanup();
@ -226,7 +243,7 @@ CuSuite *get_piracy_suite(void)
SUITE_ADD_TEST(suite, test_piracy_cmd_errors); SUITE_ADD_TEST(suite, test_piracy_cmd_errors);
SUITE_ADD_TEST(suite, test_piracy_cmd); SUITE_ADD_TEST(suite, test_piracy_cmd);
SUITE_ADD_TEST(suite, test_piracy_cmd_walking); SUITE_ADD_TEST(suite, test_piracy_cmd_walking);
DISABLE_TEST(suite, test_piracy_cmd_land_to_land); SUITE_ADD_TEST(suite, test_piracy_cmd_land_to_land);
SUITE_ADD_TEST(suite, test_piracy_cmd_swimmer); SUITE_ADD_TEST(suite, test_piracy_cmd_swimmer);
return suite; return suite;
} }

7
tests/drmemory.bat Normal file
View File

@ -0,0 +1,7 @@
cd c:\users\enno\documents\eressea\git\tests
"C:\Program Files (x86)\Dr. Memory\bin64\drmemory.exe" ..\build-vs14\eressea\Debug\eressea.exe -t184 test-turn.lua
del reports
del datum htpasswd parteien parteien.full passwd score turn
pause