2020-05-02 11:13:26 +02:00
|
|
|
local tcname = 'tests.e2.trees'
|
2020-05-03 16:52:40 +02:00
|
|
|
local lunit = require('lunit')
|
2020-05-02 11:13:26 +02:00
|
|
|
if _VERSION >= 'Lua 5.2' then
|
|
|
|
_ENV = module(tcname, 'seeall')
|
|
|
|
else
|
2020-05-03 16:52:40 +02:00
|
|
|
module(tcname, lunit.testcase, package.seeall)
|
2020-05-02 11:13:26 +02:00
|
|
|
end
|
2020-01-04 12:22:14 +01:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.game.reset()
|
|
|
|
eressea.settings.set("rules.food.flags", "4") -- food is free
|
2020-01-18 21:06:48 +01:00
|
|
|
eressea.settings.set("rules.treeseeds.chance", "0.0") -- trees make no seeds
|
|
|
|
eressea.settings.set("rules.grow.formula", "0") -- no tree or seed growth
|
2020-01-04 12:22:14 +01:00
|
|
|
eressea.settings.set("NewbieImmunity", "0")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_no_growth()
|
2020-01-18 21:06:48 +01:00
|
|
|
eressea.settings.set("rules.grow.formula", "2") -- E2 growth rules
|
2020-01-04 12:22:14 +01:00
|
|
|
set_turn(204)
|
|
|
|
assert_equal('spring', get_season())
|
|
|
|
local r = region.create(0, 0, 'plain')
|
2020-02-08 21:49:42 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2020-01-04 12:22:14 +01:00
|
|
|
r:set_resource('seed', 0)
|
|
|
|
r:set_resource('sapling', 0)
|
|
|
|
r:set_resource('tree', 0)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(0, r:get_resource('seed'))
|
|
|
|
assert_equal(0, r:get_resource('sapling'))
|
|
|
|
assert_equal(0, r:get_resource('tree'))
|
|
|
|
end
|
|
|
|
|
2020-01-18 21:06:48 +01:00
|
|
|
function test_spring_growth()
|
|
|
|
eressea.settings.set("rules.grow.formula", "2") -- E2 growth rules
|
|
|
|
set_turn(204)
|
|
|
|
assert_equal('spring', get_season())
|
|
|
|
local r = region.create(0, 0, 'plain')
|
2020-02-08 21:49:42 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2020-01-18 21:06:48 +01:00
|
|
|
r:set_resource('seed', 6)
|
|
|
|
r:set_resource('sapling', 17)
|
|
|
|
r:set_resource('tree', 0)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(5, r:get_resource('seed'))
|
|
|
|
assert_equal(16, r:get_resource('sapling'))
|
|
|
|
assert_equal(2, r:get_resource('tree'))
|
|
|
|
end
|
|
|
|
|
2020-01-07 20:28:43 +01:00
|
|
|
-- hebalism < T6 cannot plant
|
|
|
|
function test_plant_fail()
|
2020-01-04 12:22:14 +01:00
|
|
|
set_turn(184)
|
|
|
|
assert_equal('summer', get_season())
|
|
|
|
local f = faction.create('goblin')
|
|
|
|
local r = region.create(0, 0, 'plain')
|
2020-02-08 21:49:42 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2020-01-04 12:22:14 +01:00
|
|
|
r:set_resource('seed', 0)
|
|
|
|
r:set_resource('sapling', 0)
|
|
|
|
r:set_resource('tree', 0)
|
|
|
|
local u = unit.create(f, r)
|
2020-01-07 20:28:43 +01:00
|
|
|
u:set_skill('herbalism', 5)
|
2020-01-04 12:22:14 +01:00
|
|
|
u:add_item('seed', 40)
|
|
|
|
u:add_order("PFLANZE 20 Samen")
|
|
|
|
process_orders()
|
2020-01-07 20:28:43 +01:00
|
|
|
assert_equal(0, r:get_resource('seed'))
|
2020-01-04 12:22:14 +01:00
|
|
|
assert_equal(0, r:get_resource('sapling'))
|
|
|
|
assert_equal(0, r:get_resource('tree'))
|
2020-01-07 20:28:43 +01:00
|
|
|
assert_equal(40, u:get_item('seed'))
|
2020-01-04 12:22:14 +01:00
|
|
|
end
|
|
|
|
|
2020-01-07 20:28:43 +01:00
|
|
|
-- T6+ herbalism allows planting seeds at 1:1 rates
|
|
|
|
function test_plant_summer()
|
|
|
|
set_turn(184)
|
|
|
|
assert_equal('summer', get_season())
|
2020-01-04 12:22:14 +01:00
|
|
|
local f = faction.create('goblin')
|
|
|
|
local r = region.create(0, 0, 'plain')
|
2020-02-08 21:49:42 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2020-01-04 12:22:14 +01:00
|
|
|
r:set_resource('seed', 0)
|
|
|
|
r:set_resource('sapling', 0)
|
|
|
|
r:set_resource('tree', 0)
|
2020-01-07 20:28:43 +01:00
|
|
|
local u = unit.create(f, r)
|
|
|
|
u:set_skill('herbalism', 20)
|
|
|
|
u:add_item('seed', 40)
|
|
|
|
u:add_order("PFLANZE 20 Samen")
|
2020-01-04 12:22:14 +01:00
|
|
|
process_orders()
|
2020-01-07 20:28:43 +01:00
|
|
|
assert_equal(20, r:get_resource('seed'))
|
2020-01-04 12:22:14 +01:00
|
|
|
assert_equal(0, r:get_resource('sapling'))
|
|
|
|
assert_equal(0, r:get_resource('tree'))
|
2020-01-07 20:28:43 +01:00
|
|
|
assert_equal(20, u:get_item('seed'))
|
|
|
|
end
|
2020-01-04 12:22:14 +01:00
|
|
|
|
2020-01-07 20:28:43 +01:00
|
|
|
-- in spring, herbalism >= T12 plants saplings at 10:1 rate
|
|
|
|
function test_plant_spring_saplings()
|
2020-01-18 21:06:48 +01:00
|
|
|
set_turn(203)
|
2020-01-07 20:28:43 +01:00
|
|
|
assert_equal('spring', get_season())
|
|
|
|
local f = faction.create('goblin')
|
|
|
|
local r = region.create(0, 0, 'plain')
|
2020-01-18 21:06:48 +01:00
|
|
|
local u = unit.create(f, r)
|
2020-02-08 21:49:42 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2020-01-07 20:28:43 +01:00
|
|
|
r:set_resource('seed', 0)
|
|
|
|
r:set_resource('sapling', 0)
|
|
|
|
r:set_resource('tree', 0)
|
2020-01-18 21:06:48 +01:00
|
|
|
|
|
|
|
assert_equal('spring', get_season())
|
|
|
|
process_orders() -- to initialize at_germs
|
|
|
|
assert_equal(0, r:get_resource('sapling'))
|
|
|
|
assert_equal(0, r:get_resource('seed'))
|
|
|
|
assert_equal(0, r:get_resource('tree'))
|
|
|
|
|
|
|
|
assert_equal('spring', get_season())
|
2020-01-07 20:37:21 +01:00
|
|
|
u:set_skill('herbalism', 12)
|
|
|
|
u:add_item('seed', 20)
|
|
|
|
u:add_order("PFLANZE 20 Samen") -- limited by herbalism
|
2020-01-04 12:22:14 +01:00
|
|
|
process_orders()
|
2020-01-07 20:37:21 +01:00
|
|
|
assert_equal(1, r:get_resource('sapling'))
|
|
|
|
assert_equal(2, r:get_resource('seed'))
|
2020-01-04 12:22:14 +01:00
|
|
|
assert_equal(0, r:get_resource('tree'))
|
2020-01-07 20:37:21 +01:00
|
|
|
assert_equal(8, u:get_item('seed'))
|
2020-01-04 12:22:14 +01:00
|
|
|
end
|
2020-01-07 20:28:43 +01:00
|
|
|
|
|
|
|
-- herbalism < T12 means we are still planting seeds at 1:1
|
|
|
|
function test_plant_spring_seeds()
|
|
|
|
set_turn(204)
|
|
|
|
local f = faction.create('goblin')
|
|
|
|
local r = region.create(0, 0, 'plain')
|
2020-01-18 21:06:48 +01:00
|
|
|
local u = unit.create(f, r)
|
2020-02-08 21:49:42 +01:00
|
|
|
r:set_flag(1, false) -- no mallorn
|
2020-01-07 20:28:43 +01:00
|
|
|
r:set_resource('seed', 0)
|
|
|
|
r:set_resource('sapling', 0)
|
|
|
|
r:set_resource('tree', 0)
|
2020-01-18 21:06:48 +01:00
|
|
|
|
|
|
|
assert_equal('spring', get_season())
|
|
|
|
process_orders() -- to initialize at_germs
|
|
|
|
assert_equal(0, r:get_resource('sapling'))
|
|
|
|
assert_equal(0, r:get_resource('seed'))
|
|
|
|
assert_equal(0, r:get_resource('tree'))
|
|
|
|
|
|
|
|
assert_equal('spring', get_season())
|
2020-01-07 20:28:43 +01:00
|
|
|
u:set_skill('herbalism', 10)
|
|
|
|
u:add_item('seed', 40)
|
|
|
|
u:add_order("PFLANZE 10 Samen")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(0, r:get_resource('sapling'))
|
|
|
|
assert_equal(10, r:get_resource('seed'))
|
|
|
|
assert_equal(0, r:get_resource('tree'))
|
|
|
|
assert_equal(30, u:get_item('seed'))
|
|
|
|
end
|