Expose the "working" flag for buildings to Lua.

Test working vs. unpaid harbour landigns with a ship.
This commit is contained in:
Enno Rehling 2014-07-04 22:07:57 -07:00
parent 26d6808ea1
commit 8fc137d780
5 changed files with 46 additions and 6 deletions

View file

@ -1074,6 +1074,7 @@ function test_lighthouse()
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local b = building.create(r, "lighthouse") local b = building.create(r, "lighthouse")
b.size = 100 b.size = 100
b.working = true
u.building = b u.building = b
u:set_skill("perception", 9) u:set_skill("perception", 9)
u:add_item("money", 1000) u:add_item("money", 1000)

View file

@ -283,6 +283,7 @@ function test_market()
for i = 0, 5 do for i = 0, 5 do
local rn = r:next(i) local rn = r:next(i)
end end
b.working = true
eressea.process.markets() eressea.process.markets()
u:add_item("money", -u:get_item("money")) -- now we only have herbs u:add_item("money", -u:get_item("money")) -- now we only have herbs
local len = 0 local len = 0

View file

@ -56,6 +56,23 @@ static int tolua_building_get_objects(lua_State * L)
return 1; return 1;
} }
static int tolua_building_set_working(lua_State * L)
{
building *self = (building *) tolua_tousertype(L, 1, 0);
bool flag = !!lua_toboolean(L, 2);
if (flag) self->flags |= BLD_WORKING;
else self->flags &= ~BLD_WORKING;
return 1;
}
static int tolua_building_get_working(lua_State * L)
{
building *self = (building *) tolua_tousertype(L, 1, 0);
bool flag = (self->flags&BLD_WORKING)!=0;
lua_pushboolean(L, flag);
return 1;
}
static int tolua_building_get_region(lua_State * L) static int tolua_building_get_region(lua_State * L)
{ {
building *self = (building *) tolua_tousertype(L, 1, 0); building *self = (building *) tolua_tousertype(L, 1, 0);
@ -242,7 +259,8 @@ void tolua_building_open(lua_State * L)
.property("type", &building_gettype) .property("type", &building_gettype)
.def_readwrite("size", &building::size) .def_readwrite("size", &building::size)
#endif #endif
tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0); tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0);
tolua_variable(L, TOLUA_CAST "working", tolua_building_get_working, tolua_building_set_working);
} }
tolua_endmodule(L); tolua_endmodule(L);

View file

@ -3,8 +3,8 @@ require "tests.settings"
require "tests.config" require "tests.config"
require "tests.locale" require "tests.locale"
require "tests.regions" require "tests.regions"
require "tests.ships"
require "tests.study" require "tests.study"
require "tests.movement"
require "tests.castles" require "tests.castles"
require "tests.spells" require "tests.spells"
require "tests.movement"
require "tests.ships"

View file

@ -22,7 +22,7 @@ function setup()
} }
}, },
"buildings" : { "buildings" : {
"harbour" : {} "harbour" : { "maintenance" : { "type" : "money", "amount" : 250, "flags" : [ "required" ] } }
}, },
"terrains" : { "terrains" : {
"ocean": { "flags" : [ "sea", "sail" ] }, "ocean": { "flags" : [ "sea", "sail" ] },
@ -90,7 +90,27 @@ function test_sail_to_forbidden_shore()
assert_equal(ocean, u.region) assert_equal(ocean, u.region)
end end
function test_sail_into_harbour() function test_sail_into_good_harbour()
local ocean = region.create(1, 0, "ocean")
local shore = region.create(0, 0, "glacier")
local f = faction.create("noreply@eressea.de", "human", "de")
local b = building.create(shore, "harbour")
local u
u = unit.create(f, shore, 1)
u:add_item("money", 250) -- building maintenance fee
u.building = b
u = unit.create(f, ocean, 1)
u.ship = ship.create(ocean, "boat")
u:set_skill("sailing", 10)
u:add_order("NACH W")
process_orders()
assert_equal(shore, u.region, "working harbour should let the ship land")
end
function test_sail_into_bad_harbour()
local ocean = region.create(1, 0, "ocean") local ocean = region.create(1, 0, "ocean")
local shore = region.create(0, 0, "glacier") local shore = region.create(0, 0, "glacier")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
@ -103,5 +123,5 @@ function test_sail_into_harbour()
assert_not_nil(b) assert_not_nil(b)
process_orders() process_orders()
assert_equal(shore, u.region) assert_equal(ocean, u.region, "harbour without owner should stop ship")
end end