forked from github/server
bug 2710: add tests, fix land movement
This commit is contained in:
parent
b50994bb9c
commit
fe463a9f44
|
@ -79,3 +79,66 @@ function test_no_guard_no_move_after_combat() -- bug 1493
|
|||
u1 = get_unit(uid1)
|
||||
assert_equal(r1, u1.region)
|
||||
end
|
||||
|
||||
function test_move_stops_guarding()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
local f = faction.create("human", "test@example.com", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("sword", 1)
|
||||
u:set_skill("melee", 2)
|
||||
u:add_order("NACH O")
|
||||
u:add_order("BEWACHE")
|
||||
u.guard = true
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
assert_false(u.guard)
|
||||
end
|
||||
|
||||
function test_move_to_same_region_stops_guarding()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
local f = faction.create("human", "test@example.com", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("horse", 1)
|
||||
u:add_item("sword", 1)
|
||||
u:set_skill("melee", 2)
|
||||
u:set_skill("riding", 2)
|
||||
u:add_order("NACH O W")
|
||||
u.guard = true
|
||||
process_orders()
|
||||
assert_equal(r1, u.region)
|
||||
assert_false(u.guard)
|
||||
end
|
||||
|
||||
function test_mover_cannot_start_guarding()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
local f = faction.create("human", "test@example.com", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("horse", 1)
|
||||
u:add_item("sword", 1)
|
||||
u:set_skill("melee", 2)
|
||||
u:set_skill("riding", 2)
|
||||
u:add_order("BEWACHE")
|
||||
u:add_order("NACH O")
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
assert_false(u.guard)
|
||||
end
|
||||
|
||||
function test_move_to_same_region_stops_guarding()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
local f = faction.create("human", "test@example.com", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("horse", 1)
|
||||
u:add_item("sword", 1)
|
||||
u:set_skill("melee", 2)
|
||||
u:set_skill("riding", 2)
|
||||
u:add_order("BEWACHE")
|
||||
u:add_order("NACH O W")
|
||||
process_orders()
|
||||
assert_equal(r1, u.region)
|
||||
assert_false(u.guard)
|
||||
end
|
||||
|
|
|
@ -165,3 +165,20 @@ function assert_capacity(text, u, silver, r1, r2, rx)
|
|||
process_orders()
|
||||
assert_equal(rx, u.region, text .. "unit should not move")
|
||||
end
|
||||
|
||||
function test_move_to_same_region_leaves_building()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
local f = faction.create("human", "test@example.com", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
local b = building.create(u.region, "castle")
|
||||
b.size = 2
|
||||
u.building = b
|
||||
assert_not_nil(u.building)
|
||||
u:add_item("horse", 1)
|
||||
u:set_skill("riding", 2)
|
||||
u:add_order("NACH O W")
|
||||
process_orders()
|
||||
assert_equal(r1, u.region)
|
||||
assert_nil(u.building)
|
||||
end
|
||||
|
|
|
@ -519,3 +519,31 @@ function test_build_convoy_max()
|
|||
assert_equal(100, sh.size)
|
||||
assert_equal(25, u:get_item('log'))
|
||||
end
|
||||
|
||||
function test_ship_crew_stops_guarding()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "ocean")
|
||||
local f = faction.create("human")
|
||||
local u1 = unit.create(f, r1, 1)
|
||||
local u2 = unit.create(f, r1, 1)
|
||||
local sh = ship.create(r1, "longboat")
|
||||
u1.ship = sh
|
||||
u2.ship = sh
|
||||
u1.name = 'Bolgrim'
|
||||
u1.name = 'Bolle'
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O W")
|
||||
u1:set_skill("sailing", 1) -- cptskill = 1
|
||||
u2:set_skill("sailing", 9) -- sumskill = 10
|
||||
u2:add_item("sword", 1)
|
||||
u2:set_skill("melee", 2)
|
||||
u2:add_order("BEWACHE")
|
||||
u2.guard = true
|
||||
process_orders()
|
||||
assert_false(u2.guard)
|
||||
assert_equal(sh, u1.ship)
|
||||
assert_equal(sh, u2.ship)
|
||||
assert_equal(r1, sh.region)
|
||||
assert_equal(r1, u1.region)
|
||||
assert_equal(r1, u2.region)
|
||||
end
|
||||
|
|
|
@ -271,7 +271,7 @@ static int tolua_unit_get_guard(lua_State * L)
|
|||
static int tolua_unit_set_guard(lua_State * L)
|
||||
{
|
||||
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||
unsigned int flags = (unsigned int)tolua_tonumber(L, 2, 0);
|
||||
int flags = tolua_toboolean(L, 2, 0);
|
||||
setguard(u, flags!=0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -705,16 +705,9 @@ bool can_survive(const unit * u, const region * r)
|
|||
return false;
|
||||
}
|
||||
|
||||
void move_unit(unit * u, region * r, unit ** ulist)
|
||||
void leave_region(unit* u)
|
||||
{
|
||||
assert(u && r);
|
||||
|
||||
assert(u->faction || !"this unit is dead");
|
||||
if (u->region == r)
|
||||
return;
|
||||
if (!ulist)
|
||||
ulist = (&r->units);
|
||||
if (u->region) {
|
||||
assert(u->region);
|
||||
setguard(u, false);
|
||||
fset(u, UFL_MOVED);
|
||||
if (u->ship || u->building) {
|
||||
|
@ -726,6 +719,19 @@ void move_unit(unit * u, region * r, unit ** ulist)
|
|||
leave(u, false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void move_unit(unit * u, region * r, unit ** ulist)
|
||||
{
|
||||
assert(u && r);
|
||||
|
||||
assert(u->faction || !"this unit is dead");
|
||||
if (!ulist) {
|
||||
ulist = (&r->units);
|
||||
}
|
||||
if (u->region) {
|
||||
leave_region(u);
|
||||
translist(&u->region->units, ulist, u);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -143,6 +143,7 @@ extern "C" {
|
|||
int get_modifier(const struct unit *u, skill_t sk, int level,
|
||||
const struct region *r, bool noitem);
|
||||
int remove_unit(struct unit **ulist, struct unit *u);
|
||||
void leave_region(struct unit* u);
|
||||
|
||||
/* looking up dead units' factions: */
|
||||
struct faction *dfindhash(int no);
|
||||
|
|
|
@ -4,6 +4,7 @@ IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug
|
|||
IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug
|
||||
IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug
|
||||
IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug
|
||||
IF EXIST ..\build-vs16 SET BUILD=..\build-vs16\eressea\Debug
|
||||
|
||||
SET SERVER=%BUILD%\eressea.exe
|
||||
%BUILD%\test_eressea.exe
|
||||
|
|
Loading…
Reference in New Issue