forked from github/server
Some tests for WORK and wages.
This commit is contained in:
parent
cdb648b761
commit
b5624e6a8a
|
@ -108,7 +108,7 @@ end
|
|||
|
||||
function test_build_boat_high_skill()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("human", "skillz@example.com")
|
||||
local f = faction.create("human")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:set_skill("shipcraft", 5) -- humans get +1
|
||||
u:add_item("log", 10)
|
||||
|
@ -118,3 +118,86 @@ function test_build_boat_high_skill()
|
|||
assert_equal(5, u.ship.size)
|
||||
assert_equal(5, u:get_item('log'))
|
||||
end
|
||||
|
||||
function test_work()
|
||||
eressea.settings.set("rules.peasants.growth.factor", "0")
|
||||
local r = region.create(0, 0, "plain")
|
||||
r:set_resource('peasant', 1)
|
||||
r:set_resource('tree', 0)
|
||||
local f = faction.create("human")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_order('ARBEITE')
|
||||
r:set_resource('money', 0)
|
||||
|
||||
process_orders()
|
||||
assert_equal(10, u:get_item('money'))
|
||||
assert_equal(1, r:get_resource('money'))
|
||||
b = building.create(r, 'castle')
|
||||
|
||||
b.size = 2
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
process_orders()
|
||||
assert_equal(10, u:get_item('money'))
|
||||
assert_equal(1, r:get_resource('money'))
|
||||
|
||||
b.size = 10
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
process_orders()
|
||||
assert_equal(11, u:get_item('money'))
|
||||
assert_equal(2, r:get_resource('money'))
|
||||
|
||||
b.size = 50
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
process_orders()
|
||||
assert_equal(12, u:get_item('money'))
|
||||
assert_equal(3, r:get_resource('money'))
|
||||
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
b.size = 250
|
||||
process_orders()
|
||||
assert_equal(13, u:get_item('money'))
|
||||
assert_equal(4, r:get_resource('money'))
|
||||
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
b.size = 1250
|
||||
process_orders()
|
||||
assert_equal(14, u:get_item('money'))
|
||||
assert_equal(5, r:get_resource('money'))
|
||||
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
b.size = 6250
|
||||
process_orders()
|
||||
assert_equal(15, u:get_item('money'))
|
||||
assert_equal(6, r:get_resource('money'))
|
||||
end
|
||||
|
||||
function test_blessed_harvest()
|
||||
eressea.settings.set("rules.peasants.growth.factor", "0")
|
||||
local r = region.create(0, 0, "plain")
|
||||
r:set_resource('peasant', 1)
|
||||
r:set_resource('tree', 0)
|
||||
local f = faction.create("human")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_order('ARBEITE')
|
||||
r:set_resource('money', 0)
|
||||
r:add_curse('blessedharvest', nil, 2, 1, 1) -- duration, force, effect
|
||||
|
||||
process_orders()
|
||||
assert_equal(10, u:get_item('money')) -- only peasants benefit
|
||||
assert_equal(2, r:get_resource('money')) -- peasants work +1
|
||||
|
||||
b = building.create(r, 'castle')
|
||||
b.size = 6250
|
||||
r:set_resource('money', 0)
|
||||
u:add_item('money', -u:get_item('money'))
|
||||
assert_equal(1, r:get_curse('blessedharvest'))
|
||||
process_orders()
|
||||
assert_equal(15, u:get_item('money')) -- only peasants get +1
|
||||
assert_equal(7, r:get_resource('money')) -- peasants get +1
|
||||
end
|
||||
|
|
|
@ -699,6 +699,24 @@ static int tolua_distance(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_add_curse(lua_State *L) {
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
const curse_type *ctype = ct_find(name);
|
||||
if (ctype) {
|
||||
unit *u = (unit *)tolua_tousertype(L, 3, NULL);
|
||||
int duration = (int)tolua_tonumber(L, 4, 1);
|
||||
double vigour = tolua_tonumber(L, 5, 0.0);
|
||||
int effect = (int)tolua_tonumber(L, 6, vigour/2);
|
||||
curse * c = create_curse(u, &r->attribs, ctype, vigour, duration, effect, 0);
|
||||
if (c) {
|
||||
lua_pushinteger(L, c->no);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_curse(lua_State *L) {
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
|
@ -741,6 +759,7 @@ void tolua_region_open(lua_State * L)
|
|||
|
||||
tolua_function(L, TOLUA_CAST "count_msg_type", tolua_region_count_msg_type);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "add_curse", &tolua_region_add_curse);
|
||||
tolua_function(L, TOLUA_CAST "get_curse", &tolua_region_get_curse);
|
||||
tolua_function(L, TOLUA_CAST "has_attrib", &tolua_region_has_attrib);
|
||||
/* flags */
|
||||
|
|
Loading…
Reference in New Issue