Merge branch 'master' into develop

Conflicts:
	res/adamantium.xml
	res/core/resources/laen.xml
	scripts/tests/common.lua
	scripts/tests/e2/adamantium.lua
	scripts/tests/e2/e2features.lua
	scripts/tests/e2/items.lua
	scripts/tests/items.lua
	src/bind_unit.c
	src/economy.test.c
	src/kernel/resources.c
	src/util/attrib.c
This commit is contained in:
Enno Rehling 2017-03-26 21:01:21 +02:00
commit f2bb51b3ab
11 changed files with 277 additions and 65 deletions

View File

@ -2,6 +2,7 @@
"keywords": { "keywords": {
"en" : { "en" : {
"grow": [ "GROW", "BREED", "PLANT" ], "grow": [ "GROW", "BREED", "PLANT" ],
"promote": ["PROMOTE", "PROMOTION" ],
"combat": [ "COMBAT", "FIGHT" ] "combat": [ "COMBAT", "FIGHT" ]
}, },
"de": { "de": {

View File

@ -5,7 +5,8 @@
<item weight="200" score="200"> <item weight="200" score="200">
<construction skill="mining" minskill="8"/> <construction skill="mining" minskill="8"/>
</item> </item>
<modifier type="require" building="mine"/> <modifier building="mine" type="skill" value="1"/>
<modifier type="require" building="mine"/>
</resource> </resource>
<resource name="adamantiumaxe"> <resource name="adamantiumaxe">

View File

@ -1496,9 +1496,6 @@
<string name="prefix"> <string name="prefix">
<text locale="en">PREFIX</text> <text locale="en">PREFIX</text>
</string> </string>
<string name="promote">
<text locale="en">PROMOTION</text>
</string>
<string name="claim"> <string name="claim">
<text locale="en">CLAIM</text> <text locale="en">CLAIM</text>
</string> </string>

View File

@ -3,5 +3,6 @@
<item weight="200" score="100"> <item weight="200" score="100">
<construction skill="mining" minskill="7"/> <construction skill="mining" minskill="7"/>
</item> </item>
<modifier type="require" building="mine"/> <modifier building="mine" type="skill" value="1"/>
<modifier type="require" building="mine"/>
</resource> </resource>

View File

@ -5,6 +5,10 @@ local function _test_create_ship(r)
return s return s
end end
local function create_faction(race)
return faction.create(race, race .. '@eressea.de', "de")
end
local function one_unit(r, f) local function one_unit(r, f)
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", u.number * 100) u:add_item("money", u.number * 100)
@ -17,8 +21,8 @@ local function two_units(r, f1, f2)
end end
local function two_factions() local function two_factions()
local f1 = faction.create("human", "one@eressea.de", "de") local f1 = create_faction('human')
local f2 = faction.create("elf", "two@eressea.de", "de") local f2 = create_faction('elf')
return f1, f2 return f1, f2
end end
@ -44,7 +48,7 @@ end
function test_flags() function test_flags()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("halfling", "flags@eressea.de", "de") local f = create_faction('halfling')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local no = itoa36(f.id) local no = itoa36(f.id)
local flags = 50332673 local flags = 50332673
@ -62,7 +66,7 @@ function test_elvenhorse_requires_riding_5()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
region.create(1, 0, "plain") region.create(1, 0, "plain")
local goal = region.create(2, 0, "plain") local goal = region.create(2, 0, "plain")
local f = faction.create("halfling", "riding@eressea.de", "de") local f = create_faction('halfling')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("elvenhorse", 1) u:add_item("elvenhorse", 1)
u:set_skill("riding", 6)-- halfling has -1 modifier u:set_skill("riding", 6)-- halfling has -1 modifier
@ -76,7 +80,7 @@ function test_cannot_ride_elvenhorse_without_enough_skill()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local goal = region.create(1, 0, "plain") local goal = region.create(1, 0, "plain")
region.create(2, 0, "plain") region.create(2, 0, "plain")
local f = faction.create("halfling", "elvenhorse@eressea.de", "de") local f = create_faction('halfling')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("elvenhorse", 1) u:add_item("elvenhorse", 1)
u:set_skill("riding", 5) -- halfling has -1 modifier u:set_skill("riding", 5) -- halfling has -1 modifier
@ -96,7 +100,7 @@ end
function test_demon_food() function test_demon_food()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("demon", "demonfood@eressea.de", "de") local f = create_faction('demon')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local p = r:get_resource("peasant") local p = r:get_resource("peasant")
r:set_resource("peasant", 2000) r:set_resource("peasant", 2000)
@ -136,7 +140,7 @@ function test_plane()
local nx, ny = plane.normalize(pl, 4, 4) local nx, ny = plane.normalize(pl, 4, 4)
assert_equal(nx, -3, "normalization failed") assert_equal(nx, -3, "normalization failed")
assert_equal(ny, -3, "normalization failed") assert_equal(ny, -3, "normalization failed")
local f = faction.create("human", "plan@eressea.de", "de") local f = create_faction('human')
f.id = atoi36("tpla") f.id = atoi36("tpla")
local r, x, y local r, x, y
for x = -3, 3 do for y = -3, 3 do for x = -3, 3 do for y = -3, 3 do
@ -155,7 +159,7 @@ end
function test_read_write() function test_read_write()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "readwrite@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r) local u = unit.create(f, r)
u.number = 2 u.number = 2
local fno = f.id local fno = f.id
@ -184,7 +188,7 @@ end
function test_descriptions() function test_descriptions()
local info = "Descriptions can be very long. Bug 1984 behauptet, dass es Probleme gibt mit Beschreibungen die laenger als 120 Zeichen sind. This description is longer than 120 characters." local info = "Descriptions can be very long. Bug 1984 behauptet, dass es Probleme gibt mit Beschreibungen die laenger als 120 Zeichen sind. This description is longer than 120 characters."
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "descriptions@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local s = _test_create_ship(r) local s = _test_create_ship(r)
local b = building.create(r, "castle") local b = building.create(r, "castle")
@ -236,7 +240,7 @@ end
function test_faction() function test_faction()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "testfaction@eressea.de", "de") local f = create_faction('human')
assert(f) assert(f)
f.info = "Spazz" f.info = "Spazz"
assert(f.info=="Spazz") assert(f.info=="Spazz")
@ -259,7 +263,7 @@ end
function test_unit() function test_unit()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "testunit@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r) local u = unit.create(f, r)
u.number = 20 u.number = 20
u.name = "Enno" u.name = "Enno"
@ -292,7 +296,7 @@ end
function test_building() function test_building()
local u local u
local f = faction.create("human", "testbuilding@eressea.de", "de") local f = create_faction('human')
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local b = building.create(r, "castle") local b = building.create(r, "castle")
u = unit.create(f, r) u = unit.create(f, r)
@ -318,7 +322,7 @@ end
function test_message() function test_message()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "testmessage@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r) local u = unit.create(f, r)
local msg = message.create("item_create_spell") local msg = message.create("item_create_spell")
msg:set_unit("mage", u) msg:set_unit("mage", u)
@ -346,7 +350,7 @@ function test_events()
plain = region.create(0, 0, "plain") plain = region.create(0, 0, "plain")
skill = 8 skill = 8
f = faction.create("elf", "noreply2@eressea.de", "de") f = create_faction('elf')
f.age = 20 f.age = 20
u = unit.create(f, plain) u = unit.create(f, plain)
@ -356,7 +360,7 @@ function test_events()
u:add_order("NUMMER PARTEI test") u:add_order("NUMMER PARTEI test")
u:add_handler("message", msg_handler) u:add_handler("message", msg_handler)
msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken" msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken"
f = faction.create("elf", "noreply3@eressea.de", "de") f = create_faction('elf')
f.age = 20 f.age = 20
u = unit.create(f, plain) u = unit.create(f, plain)
@ -371,7 +375,7 @@ end
function test_renumber_ship() function test_renumber_ship()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply4@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r) local u = unit.create(f, r)
local s = ship.create(r, config.ships[1]) local s = ship.create(r, config.ships[1])
u.ship = s u.ship = s
@ -386,7 +390,7 @@ end
function test_recruit2() function test_recruit2()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply4@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r) local u = unit.create(f, r)
u.number = 1 u.number = 1
u:add_item("money", 2000) u:add_item("money", 2000)
@ -401,7 +405,7 @@ end
function test_guard() function test_guard()
region.create(1, 0, "plain") region.create(1, 0, "plain")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f1 = faction.create("human", "noreply5@eressea.de", "de") local f1 = create_faction('human')
f1.age = 20 f1.age = 20
local u1 = unit.create(f1, r, 10) local u1 = unit.create(f1, r, 10)
u1:add_item("sword", 10) u1:add_item("sword", 10)
@ -411,7 +415,7 @@ function test_guard()
u1:add_order("NACH O") u1:add_order("NACH O")
u1.name="Kalle Pimp" u1.name="Kalle Pimp"
local f2 = faction.create("human", "noreply6@eressea.de", "de") local f2 = create_faction('human')
f2.age = 20 f2.age = 20
local u2 = unit.create(f2, r, 1) local u2 = unit.create(f2, r, 1)
local u3 = unit.create(f2, r, 1) local u3 = unit.create(f2, r, 1)
@ -429,7 +433,7 @@ end
function test_recruit() function test_recruit()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply7@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r) local u = unit.create(f, r)
u.number = 1 u.number = 1
local n = 3 local n = 3
@ -445,7 +449,7 @@ end
function test_produce() function test_produce()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply8@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:clear_orders() u:clear_orders()
local sword = config.get_resource('sword') local sword = config.get_resource('sword')
@ -460,7 +464,7 @@ end
function test_work() function test_work()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply9@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", u.number * 10) -- humans cost 10 u:add_item("money", u.number * 10) -- humans cost 10
u:set_skill("herbalism", 5) u:set_skill("herbalism", 5)
@ -473,7 +477,7 @@ end
function test_upkeep() function test_upkeep()
eressea.settings.set("rules.food.flags", "0") eressea.settings.set("rules.food.flags", "0")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply10@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 5) local u = unit.create(f, r, 5)
u:add_item("money", u.number * 11) u:add_item("money", u.number * 11)
u:clear_orders() u:clear_orders()
@ -485,7 +489,7 @@ end
function test_id() function test_id()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply11@eressea.de", "de") local f = create_faction('human')
f.id = atoi36("42") f.id = atoi36("42")
assert_not_equal(f, get_faction(42)) assert_not_equal(f, get_faction(42))
assert_equal(f, get_faction("42")) assert_equal(f, get_faction("42"))
@ -521,7 +525,7 @@ function test_mallorn()
m:set_resource("tree", 100) m:set_resource("tree", 100)
assert_equal(100, m:get_resource("tree")) assert_equal(100, m:get_resource("tree"))
local f = faction.create("human", "noreply13@eressea.de", "de") local f = create_faction('human')
local u1 = unit.create(f, r, 1) local u1 = unit.create(f, r, 1)
u1:add_item("money", u1.number * 100) u1:add_item("money", u1.number * 100)
@ -558,7 +562,7 @@ function test_coordinate_translation()
local pl = plane.create(1, 500, 500, 1001, 1001) -- astralraum local pl = plane.create(1, 500, 500, 1001, 1001) -- astralraum
local pe = plane.create(1, -8761, 3620, 23, 23) -- eternath local pe = plane.create(1, -8761, 3620, 23, 23) -- eternath
local r = region.create(1000, 1000, "plain") local r = region.create(1000, 1000, "plain")
local f = faction.create("human", "noreply14@eressea.de", "de") local f = create_faction('human')
assert_not_equal(nil, r) assert_not_equal(nil, r)
assert_equal(r.x, 1000) assert_equal(r.x, 1000)
assert_equal(r.y, 1000) assert_equal(r.y, 1000)
@ -604,8 +608,8 @@ end
function test_building_other() function test_building_other()
local r = region.create(0,0, "plain") local r = region.create(0,0, "plain")
local f1 = faction.create("human", "noreply17@eressea.de", "de") local f1 = create_faction('human')
local f2 = faction.create("human", "noreply18@eressea.de", "de") local f2 = create_faction('human')
local b = building.create(r, "castle") local b = building.create(r, "castle")
b.size = 10 b.size = 10
local u1 = unit.create(f1, r, 3) local u1 = unit.create(f1, r, 3)
@ -632,7 +636,7 @@ end
local function _test_create_laen() local function _test_create_laen()
eressea.settings.set("rules.terraform.all", "1") eressea.settings.set("rules.terraform.all", "1")
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f1 = faction.create("human", "noreply19@eressea.de", "de") local f1 = create_faction('human')
local u1 = unit.create(f1, r, 1) local u1 = unit.create(f1, r, 1)
r:set_resource("laen", 50) r:set_resource("laen", 50)
return r, u1 return r, u1
@ -671,7 +675,7 @@ end
function test_mine() function test_mine()
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f1 = faction.create("human", "noreply20@eressea.de", "de") local f1 = create_faction('human')
local u1 = unit.create(f1, r, 1) local u1 = unit.create(f1, r, 1)
u1:add_item("money", 1000) u1:add_item("money", 1000)
@ -692,9 +696,9 @@ end
function test_guard_resources() function test_guard_resources()
-- this is not quite http://bugs.eressea.de/view.php?id=1756 -- this is not quite http://bugs.eressea.de/view.php?id=1756
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f1 = faction.create("human", "noreply21@eressea.de", "de") local f1 = create_faction('human')
f1.age=20 f1.age=20
local f2 = faction.create("human", "noreply22@eressea.de", "de") local f2 = create_faction('human')
f2.age=20 f2.age=20
local u1 = unit.create(f1, r, 1) local u1 = unit.create(f1, r, 1)
u1:add_item("money", 100) u1:add_item("money", 100)
@ -722,7 +726,7 @@ end
function test_hero_hero_transfer() function test_hero_hero_transfer()
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f = faction.create("human", "noreply23@eressea.de", "de") local f = create_faction('human')
f.age=20 f.age=20
local UFL_HERO = 128 local UFL_HERO = 128
@ -743,7 +747,7 @@ end
function test_hero_normal_transfer() function test_hero_normal_transfer()
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f = faction.create("human", "noreply24@eressea.de", "de") local f = create_faction('human')
f.age=20 f.age=20
local UFL_HERO = 128 local UFL_HERO = 128
@ -762,7 +766,7 @@ end
function test_expensive_skills_cost_money() function test_expensive_skills_cost_money()
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f = faction.create("elf", "noreply25@eressea.de", "de") local f = create_faction('elf')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", 10000) u:add_item("money", 10000)
u:clear_orders() u:clear_orders()
@ -775,7 +779,7 @@ end
function test_food_is_consumed() function test_food_is_consumed()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply26@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", 100) u:add_item("money", 100)
u:clear_orders() u:clear_orders()
@ -787,7 +791,7 @@ end
function test_food_can_override() function test_food_can_override()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply27@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", 100) u:add_item("money", 100)
u:clear_orders() u:clear_orders()
@ -799,7 +803,7 @@ end
function test_swim_and_survive() function test_swim_and_survive()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply28@eressea.de", "de") local f = create_faction('human')
f.nam = "chaos" f.nam = "chaos"
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
process_orders() process_orders()
@ -813,7 +817,7 @@ end
function test_swim_and_die() function test_swim_and_die()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply29@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local uid = u.id local uid = u.id
process_orders() process_orders()
@ -828,7 +832,7 @@ function test_ride_with_horse()
region.create(1, 0, "plain") region.create(1, 0, "plain")
region.create(2, 0, "plain") region.create(2, 0, "plain")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply30@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("horse", 1) u:add_item("horse", 1)
local horse_cfg = config.get_resource("horse") local horse_cfg = config.get_resource("horse")
@ -851,7 +855,7 @@ function test_ride_with_horses_and_cart()
region.create(1, 0, "plain") region.create(1, 0, "plain")
region.create(2, 0, "plain") region.create(2, 0, "plain")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply31@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local horse_cfg = config.get_resource("horse") local horse_cfg = config.get_resource("horse")
local cart_cfg = config.get_resource("cart") local cart_cfg = config.get_resource("cart")
@ -904,7 +908,7 @@ function test_walk_and_carry_the_cart()
region.create(1, 0, "plain") region.create(1, 0, "plain")
local r = region.create(2, 0, "plain") local r = region.create(2, 0, "plain")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply32@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 10) local u = unit.create(f, r, 10)
u:add_item("cart", 1) u:add_item("cart", 1)
@ -925,7 +929,7 @@ end
function test_bug_1795_limit() function test_bug_1795_limit()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de") local f = create_faction('human')
local u1 = one_unit(r,f) local u1 = one_unit(r,f)
u1:add_item("money", 100000000) u1:add_item("money", 100000000)
u1:add_order("REKRUTIEREN 9999") u1:add_order("REKRUTIEREN 9999")
@ -940,7 +944,7 @@ end
function test_bug_1795_demons() function test_bug_1795_demons()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("demon", "noreply@eressea.de", "de") local f = create_faction('demon')
local u1 = one_unit(r,f) local u1 = one_unit(r,f)
r:set_resource("peasant", 2000) r:set_resource("peasant", 2000)
local peasants = r:get_resource("peasant") local peasants = r:get_resource("peasant")
@ -966,7 +970,7 @@ end
function test_parser() function test_parser()
local r = region.create(0, 0, "mountain") local r = region.create(0, 0, "mountain")
local f = faction.create("human", "noreply@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local filename = "orders.txt" local filename = "orders.txt"
@ -991,7 +995,7 @@ end
function test_prefix() function test_prefix()
local r0 = region.create(0, 0, "plain") local r0 = region.create(0, 0, "plain")
local f1 = faction.create("human", "noreply@eressea.de", "de") local f1 = create_faction('human')
local u1 = unit.create(f1, r0, 1) local u1 = unit.create(f1, r0, 1)
set_order(u1, "PRAEFIX See") set_order(u1, "PRAEFIX See")
@ -1018,7 +1022,7 @@ end
function test_recruit() function test_recruit()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de") local f = create_faction('human')
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", 1000) u:add_item("money", 1000)

View File

@ -10,10 +10,14 @@ function setup()
eressea.settings.set("rules.encounters", "0") eressea.settings.set("rules.encounters", "0")
end end
local function create_faction(race)
return faction.create(race, race .. '@eressea.de', "de")
end
local function _test_create_adamantium() local function _test_create_adamantium()
eressea.settings.set("rules.terraform.all", "1") eressea.settings.set("rules.terraform.all", "1")
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f1 = faction.create("human", "noreply19@eressea.de", "de") local f1 = create_faction('human')
local u1 = unit.create(f1, r, 1) local u1 = unit.create(f1, r, 1)
r:set_resource("adamantium", 50) r:set_resource("adamantium", 50)
assert_equal(50, r:get_resource("adamantium")) assert_equal(50, r:get_resource("adamantium"))
@ -22,22 +26,21 @@ end
function test_adamantium1() function test_adamantium1()
local r, u1 = _test_create_adamantium() local r, u1 = _test_create_adamantium()
u1:add_item("money", 1000) u1:add_item("money", 1000)
u1:set_skill("mining", 8) u1:set_skill("mining", 14)
u1:clear_orders() u1:clear_orders()
u1:add_order("MACHEN Adamantium") u1:add_order("MACHEN Adamantium")
process_orders() process_orders()
-- adamantium needs a mine, so nothing happens:
assert_equal(0, u1:get_item("adamantium")) assert_equal(0, u1:get_item("adamantium"))
end end
function test_adamantium2() function test_adamantium2()
local r, u1 = _test_create_adamantium() local r, u1 = _test_create_adamantium()
u1.id = 42
u1:add_item("money", 1000) u1:add_item("money", 1000)
u1:set_skill("mining", 8) u1:set_skill("mining", 15)
u1:clear_orders() u1:clear_orders()
u1:add_order("MACHEN Adamantium") u1:add_order("MACHEN Adamantium")
@ -47,7 +50,7 @@ function test_adamantium2()
local adamantium = r:get_resource("adamantium") local adamantium = r:get_resource("adamantium")
process_orders() process_orders()
assert_equal(1, u1:get_item("adamantium")) assert_equal(2, u1:get_item("adamantium"))
assert_equal(adamantium - 1, r:get_resource("adamantium")) assert_equal(adamantium - 2, r:get_resource("adamantium"))
end end

View File

@ -1,3 +1,4 @@
require 'tests.e3.production'
require 'tests.e3.castles' require 'tests.e3.castles'
require 'tests.e3.stealth' require 'tests.e3.stealth'
require 'tests.e3.spells' require 'tests.e3.spells'

View File

@ -0,0 +1,179 @@
require "lunit"
module("tests.e3.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, race .. '@eressea.de', "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

0
src/bind_unit.c Executable file → Normal file
View File

View File

@ -1100,10 +1100,10 @@ static char *cr_output_resource(char *buf, const resource_type *rtype,
{ {
const char *name, *tname; const char *name, *tname;
assert(rtype); assert(rtype);
name = resourcename(rtype, 1); name = resourcename(rtype, NMF_PLURAL);
assert(name); assert(name);
buf += sprintf(buf, "RESOURCE %u\n", hashstring(rtype->_name)); buf += sprintf(buf, "RESOURCE %u\n", hashstring(rtype->_name));
tname = LOC(loc, rtype->_name); tname = LOC(loc, name);
assert(tname); assert(tname);
tname = translate(name, tname); tname = translate(name, tname);
assert(tname); assert(tname);
@ -1188,7 +1188,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s
} }
for (n = 0; n < size; ++n) { for (n = 0; n < size; ++n) {
if (result[n].level >= 0 && result[n].number >= 0) { if (result[n].level >= 0 && result[n].number >= 0) {
const char * name = resourcename(result[n].rtype, result[n].number != 1); const char * name = resourcename(result[n].rtype, 1);
assert(name); assert(name);
stream_printf(out, "%d;%s\n", result[n].number, crtag(name)); stream_printf(out, "%d;%s\n", result[n].number, crtag(name));
} }

View File

@ -11,6 +11,7 @@
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/ship.h> #include <kernel/ship.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/spell.h> #include <kernel/spell.h>
@ -52,8 +53,15 @@ static void test_cr_unit(CuTest *tc) {
static void setup_resources(void) { static void setup_resources(void) {
struct locale *lang; struct locale *lang;
item_type *itype;
test_setup(); test_setup();
itype = it_get_or_create(rt_get_or_create("stone"));
itype->rtype->flags = RTF_LIMITED | RTF_POOLED;
itype->construction = calloc(1, sizeof(construction));
itype->construction->skill = SK_QUARRYING;
itype->construction->minskill = 1;
rmt_create(itype->rtype);
init_resources(); init_resources();
lang = get_or_create_locale("de"); /* CR tags are translated from this */ lang = get_or_create_locale("de"); /* CR tags are translated from this */
locale_setstring(lang, "money", "Silber"); locale_setstring(lang, "money", "Silber");
@ -62,6 +70,8 @@ static void setup_resources(void) {
locale_setstring(lang, "horse_p", "Pferde"); locale_setstring(lang, "horse_p", "Pferde");
locale_setstring(lang, "peasant", "Bauer"); locale_setstring(lang, "peasant", "Bauer");
locale_setstring(lang, "peasant_p", "Bauern"); locale_setstring(lang, "peasant_p", "Bauern");
locale_setstring(lang, "stone", "Stein");
locale_setstring(lang, "stone_p", "Steine");
locale_setstring(lang, "tree", "Blume"); locale_setstring(lang, "tree", "Blume");
locale_setstring(lang, "tree_p", "Blumen"); locale_setstring(lang, "tree_p", "Blumen");
locale_setstring(lang, "sapling", "Schoessling"); locale_setstring(lang, "sapling", "Schoessling");
@ -77,25 +87,31 @@ static void test_cr_resources(CuTest *tc) {
char line[1024]; char line[1024];
faction *f; faction *f;
region *r; region *r;
unit *u;
setup_resources(); setup_resources();
f = test_create_faction(0); f = test_create_faction(0);
r = test_create_region(0, 0, 0); r = test_create_region(0, 0, 0);
u = test_create_unit(f, r);
set_level(u, SK_QUARRYING, 1);
r->land->horses = 1; r->land->horses = 1;
r->land->peasants = 200; r->land->peasants = 200;
r->land->money = 300; r->land->money = 300;
rsettrees(r, 0, 1); rsettrees(r, 0, 1);
rsettrees(r, 1, 2); rsettrees(r, 1, 2);
rsettrees(r, 2, 3); rsettrees(r, 2, 3);
region_setresource(r, get_resourcetype(R_STONE), 1);
mstream_init(&strm); mstream_init(&strm);
cr_output_resources(&strm, f, r, false); cr_output_resources(&strm, f, r, true);
strm.api->rewind(strm.handle); strm.api->rewind(strm.handle);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "3;Baeume", line); CuAssertStrEquals(tc, "3;Baeume", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "2;Schoesslinge", line); CuAssertStrEquals(tc, "2;Schoesslinge", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;Steine", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
@ -132,6 +148,15 @@ static void test_cr_resources(CuTest *tc) {
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;number", line); CuAssertStrEquals(tc, "1;number", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "\"Steine\";type", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;skill", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;number", line);
mstream_done(&strm); mstream_done(&strm);
test_cleanup(); test_cleanup();
} }