From 29c2e0b8f49d96489b53b3437bf5dc9df5feb75b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 29 Mar 2017 17:59:39 +0200 Subject: [PATCH 1/2] additional testing for race-related production rules. --- scripts/tests/e2/init.lua | 1 + scripts/tests/e2/production.lua | 229 ++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 scripts/tests/e2/production.lua diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 991014287..9a42c971a 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +require 'tests.e2.production' require 'tests.e2.adamantium' require 'tests.e2.undead' require 'tests.e2.shiplanding' diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua new file mode 100644 index 000000000..f120e6916 --- /dev/null +++ b/scripts/tests/e2/production.lua @@ -0,0 +1,229 @@ +require "lunit" + +module("tests.e2.production", package.seeall, lunit.testcase ) + +function setup() + eressea.game.reset() + eressea.settings.set("rules.food.flags", "4") -- food is free + eressea.settings.set("NewbieImmunity", "0") +end + +local function create_faction(race) + return faction.create(race .. '@eressea.de', race, "de") +end + +function test_laen_needs_mine() + -- some resources require a building + -- i.e. you cannot create laen without a mine + local r = region.create(0, 0, "mountain") + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('laen', 100) + u:add_order("MACHE Laen") + u:set_skill('mining', 7) + turn_process() + assert_equal(0, u:get_item('laen')) + assert_equal(100, r:get_resource('laen')) + assert_equal(1, f:count_msg_type("error104")) -- requires building + + u.building = building.create(u.region, "mine") + u.building.working = true + u.building.size = 10 + turn_process() + assert_equal(1, u:get_item('laen')) + assert_equal(99, r:get_resource('laen')) + + turn_end() +end + +function test_mine_laen_bonus() + -- some buildings grant a bonus on the production skill + -- i.e. a mine adds +1 to mining + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('laen', 100) + assert_equal(100, r:get_resource('laen')) + u:add_order("MACHE Laen") + u:set_skill('mining', 6) + u.building = building.create(u.region, "mine") + u.building.working = true + u.building.size = 10 + u.number = 2 + turn_process() -- T6 is not enough for laen + assert_equal(0, u:get_item('laen')) + assert_equal(100, r:get_resource('laen')) + assert_equal(1, f:count_msg_type("manufacture_skills")) + + u:set_skill('mining', 13) + turn_process() -- T13 is enough, the +1 produces one extra Laen + assert_equal(4, u:get_item('laen')) -- FAIL (3) + assert_equal(96, r:get_resource('laen')) + + turn_end() +end + +function test_mine_iron_bonus() + -- some buildings grant a bonus on the production skill + -- i.e. a mine adds +1 to mining iron + -- + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('iron', 100) + assert_equal(100, r:get_resource('iron')) + u:add_order("MACHE Eisen") + u:set_skill('mining', 1) + u.building = building.create(u.region, "mine") + u.building.working = false + u.building.size = 10 + u.number = 2 + turn_process() -- iron can be made without a working mine + assert_equal(2, u:get_item('iron')) + assert_equal(98, r:get_resource('iron')) + + u.building.working = true + turn_process() + assert_equal(6, u:get_item('iron')) + assert_equal(96, r:get_resource('iron')) + + turn_end() +end + +function test_quarry_bonus() + -- a quarry grants +1 to quarrying, and saves 50% stone + -- + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('stone', 100) + assert_equal(100, r:get_resource('stone')) + u:add_order("MACHE Stein") + u:set_skill('quarrying', 1) + u.number = 2 + u.building = building.create(u.region, 'quarry') + u.building.working = false + u.building.size = 10 + turn_process() + assert_equal(2, u:get_item('stone')) + assert_equal(98, r:get_resource('stone')) + + u.building.working = true + turn_process() + assert_equal(6, u:get_item('stone')) + assert_equal(96, r:get_resource('stone')) + + turn_end() +end + +function test_smithy_bonus_iron() +-- a smithy adds +1 to weaponsmithing, and saves 50% iron + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + u.building = building.create(u.region, 'smithy') + u.building.working = false + u.building.size = 10 + u:set_skill('weaponsmithing', 5) -- needs 3 + u:add_item('iron', 100) + u:add_order("MACHE Schwert") + turn_process() -- building disabled + assert_equal(1, u:get_item('sword')) + assert_equal(99, u:get_item('iron')) + + u.building.working = true + turn_process() -- building active + assert_equal(3, u:get_item('sword')) + assert_equal(98, u:get_item('iron')) + + turn_end() +end + +function test_smithy_bonus_mixed() +-- a smithy adds +1 to weaponsmithing, and saves 50% iron +-- it does not save any other resource, though. + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + u.building = building.create(u.region, 'smithy') + u.building.working = false + u.building.size = 10 + u:set_skill('weaponsmithing', 5) -- needs 3 + u:add_item('iron', 100) + u:add_item('log', 100) + u:add_order("MACHE Kriegsaxt") + turn_process() -- building disabled + assert_equal(1, u:get_item('axe')) + assert_equal(99, u:get_item('iron')) + assert_equal(99, u:get_item('log')) + + u.building.working = true + turn_process() -- building active + assert_equal(3, u:get_item('axe')) + assert_equal(98, u:get_item('iron')) + assert_equal(97, u:get_item('log')) + + turn_end() +end + +function test_greatbow_needs_elf() +-- only elves can build a greatbow + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + u:set_skill('weaponsmithing', 5) + u:add_item('mallorn', 2) + u:add_order("MACHE Elfenbogen") + turn_process() -- humans cannot do it + assert_equal(1, f:count_msg_type("error_cannotmake")) + assert_equal(0, u:get_item('greatbow')) + assert_equal(2, u:get_item('mallorn')) + + u.race = 'elf' + turn_process() -- but elves can + assert_equal(1, u:get_item('greatbow')) + assert_equal(0, u:get_item('mallorn')) +end + +function test_troll_quarrying_bonus() +-- Von Trollen abgebaute Steine werden nur zu 75% vom "Regionsvorrat" abgezogen. +-- Dieser Effekt ist kumulativ zu einem Steinbruch. + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource("stone", 100) + u:set_skill('quarrying', 4) + u:add_order("MACHE Steine") + turn_process() -- humans get no bonus + write_report(f) + assert_equal(4, u:get_item('stone')) + assert_equal(96, r:get_resource('stone')) + + u.race = 'troll' + u:set_skill('quarrying', 2) + turn_process() -- trolls have +2 to quarrying, and save 25% + assert_equal(8, u:get_item('stone')) + assert_equal(93, r:get_resource('stone')) +end + +function test_dwarf_mining_bonus() +-- Von Zwergen abgebautes Eisen wird nur zu 60% vom "Regionsvorrat" abgezogen. +-- Dieser Effekt ist kumulativ zu einem Bergwerk (siehe hier und hier). + +end From 570a25f6dd13198e4eb5080800d13865b36b502f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 30 Mar 2017 19:08:33 +0200 Subject: [PATCH 2/2] split production rules by games --- scripts/tests/e2/init.lua | 1 + scripts/tests/e2/production.lua | 166 -------------------------- scripts/tests/e3/init.lua | 2 +- scripts/tests/{e3 => }/production.lua | 2 +- 4 files changed, 3 insertions(+), 168 deletions(-) rename scripts/tests/{e3 => }/production.lua (98%) diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 9a42c971a..c75b05211 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -16,3 +16,4 @@ require 'tests.storage' require 'tests.magicbag' require 'tests.process' require 'tests.xmas' +require 'tests.production' diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index f120e6916..c6d074f50 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -12,172 +12,6 @@ local function create_faction(race) return faction.create(race .. '@eressea.de', race, "de") end -function test_laen_needs_mine() - -- some resources require a building - -- i.e. you cannot create laen without a mine - local r = region.create(0, 0, "mountain") - local f = create_faction('human') - local u = unit.create(f, r, 1) - - turn_begin() - r:set_resource('laen', 100) - u:add_order("MACHE Laen") - u:set_skill('mining', 7) - turn_process() - assert_equal(0, u:get_item('laen')) - assert_equal(100, r:get_resource('laen')) - assert_equal(1, f:count_msg_type("error104")) -- requires building - - u.building = building.create(u.region, "mine") - u.building.working = true - u.building.size = 10 - turn_process() - assert_equal(1, u:get_item('laen')) - assert_equal(99, r:get_resource('laen')) - - turn_end() -end - -function test_mine_laen_bonus() - -- some buildings grant a bonus on the production skill - -- i.e. a mine adds +1 to mining - local r = region.create(0, 0, 'mountain') - local f = create_faction('human') - local u = unit.create(f, r, 1) - - turn_begin() - r:set_resource('laen', 100) - assert_equal(100, r:get_resource('laen')) - u:add_order("MACHE Laen") - u:set_skill('mining', 6) - u.building = building.create(u.region, "mine") - u.building.working = true - u.building.size = 10 - u.number = 2 - turn_process() -- T6 is not enough for laen - assert_equal(0, u:get_item('laen')) - assert_equal(100, r:get_resource('laen')) - assert_equal(1, f:count_msg_type("manufacture_skills")) - - u:set_skill('mining', 13) - turn_process() -- T13 is enough, the +1 produces one extra Laen - assert_equal(4, u:get_item('laen')) -- FAIL (3) - assert_equal(96, r:get_resource('laen')) - - turn_end() -end - -function test_mine_iron_bonus() - -- some buildings grant a bonus on the production skill - -- i.e. a mine adds +1 to mining iron - -- - local r = region.create(0, 0, 'mountain') - local f = create_faction('human') - local u = unit.create(f, r, 1) - - turn_begin() - r:set_resource('iron', 100) - assert_equal(100, r:get_resource('iron')) - u:add_order("MACHE Eisen") - u:set_skill('mining', 1) - u.building = building.create(u.region, "mine") - u.building.working = false - u.building.size = 10 - u.number = 2 - turn_process() -- iron can be made without a working mine - assert_equal(2, u:get_item('iron')) - assert_equal(98, r:get_resource('iron')) - - u.building.working = true - turn_process() - assert_equal(6, u:get_item('iron')) - assert_equal(96, r:get_resource('iron')) - - turn_end() -end - -function test_quarry_bonus() - -- a quarry grants +1 to quarrying, and saves 50% stone - -- - local r = region.create(0, 0, 'mountain') - local f = create_faction('human') - local u = unit.create(f, r, 1) - - turn_begin() - r:set_resource('stone', 100) - assert_equal(100, r:get_resource('stone')) - u:add_order("MACHE Stein") - u:set_skill('quarrying', 1) - u.number = 2 - u.building = building.create(u.region, 'quarry') - u.building.working = false - u.building.size = 10 - turn_process() - assert_equal(2, u:get_item('stone')) - assert_equal(98, r:get_resource('stone')) - - u.building.working = true - turn_process() - assert_equal(6, u:get_item('stone')) - assert_equal(96, r:get_resource('stone')) - - turn_end() -end - -function test_smithy_bonus_iron() --- a smithy adds +1 to weaponsmithing, and saves 50% iron - local r = region.create(0, 0, 'mountain') - local f = create_faction('human') - local u = unit.create(f, r, 1) - - turn_begin() - u.building = building.create(u.region, 'smithy') - u.building.working = false - u.building.size = 10 - u:set_skill('weaponsmithing', 5) -- needs 3 - u:add_item('iron', 100) - u:add_order("MACHE Schwert") - turn_process() -- building disabled - assert_equal(1, u:get_item('sword')) - assert_equal(99, u:get_item('iron')) - - u.building.working = true - turn_process() -- building active - assert_equal(3, u:get_item('sword')) - assert_equal(98, u:get_item('iron')) - - turn_end() -end - -function test_smithy_bonus_mixed() --- a smithy adds +1 to weaponsmithing, and saves 50% iron --- it does not save any other resource, though. - local r = region.create(0, 0, 'mountain') - local f = create_faction('human') - local u = unit.create(f, r, 1) - - turn_begin() - u.building = building.create(u.region, 'smithy') - u.building.working = false - u.building.size = 10 - u:set_skill('weaponsmithing', 5) -- needs 3 - u:add_item('iron', 100) - u:add_item('log', 100) - u:add_order("MACHE Kriegsaxt") - turn_process() -- building disabled - assert_equal(1, u:get_item('axe')) - assert_equal(99, u:get_item('iron')) - assert_equal(99, u:get_item('log')) - - u.building.working = true - turn_process() -- building active - assert_equal(3, u:get_item('axe')) - assert_equal(98, u:get_item('iron')) - assert_equal(97, u:get_item('log')) - - turn_end() -end - function test_greatbow_needs_elf() -- only elves can build a greatbow local r = region.create(0, 0, 'mountain') diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index aa253157e..174452897 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -1,4 +1,3 @@ -require 'tests.e3.production' require 'tests.e3.castles' require 'tests.e3.stealth' require 'tests.e3.spells' @@ -11,3 +10,4 @@ require 'tests.common' -- require 'tests.report' require 'tests.magicbag' require 'tests.process' +require 'tests.production' diff --git a/scripts/tests/e3/production.lua b/scripts/tests/production.lua similarity index 98% rename from scripts/tests/e3/production.lua rename to scripts/tests/production.lua index 85fdeb638..5a1fcfc51 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/production.lua @@ -1,6 +1,6 @@ require "lunit" -module("tests.e3.production", package.seeall, lunit.testcase ) +module("tests.production", package.seeall, lunit.testcase ) function setup() eressea.game.reset()