diff --git a/scripts/eressea/e2/init.lua b/scripts/eressea/e2/init.lua index dd01a06d4..7193a721b 100644 --- a/scripts/eressea/e2/init.lua +++ b/scripts/eressea/e2/init.lua @@ -4,9 +4,8 @@ eressea.log.debug("rules for game E2") return { require('eressea'), require('eressea.autoseed'), - require('eressea.xmas2004'), - require('eressea.xmas2005'), - require('eressea.xmas2006'), + require('eressea.xmas'), + require('eressea.xmasitems'), require('eressea.wedding'), require('eressea.embassy'), require('eressea.eternath'), diff --git a/scripts/eressea/e3/init.lua b/scripts/eressea/e3/init.lua index 3132e63f5..9acda1093 100644 --- a/scripts/eressea/e3/init.lua +++ b/scripts/eressea/e3/init.lua @@ -5,7 +5,7 @@ eressea.log.debug("rules for game E3") return { require('eressea'), - require('eressea.xmas2009'), + require('eressea.xmasitems'), require('eressea.markets'), require('eressea.frost'), require('eressea.ents') diff --git a/scripts/eressea/xmas2004.lua b/scripts/eressea/xmas2004.lua deleted file mode 100644 index 79d2b0665..000000000 --- a/scripts/eressea/xmas2004.lua +++ /dev/null @@ -1,24 +0,0 @@ -function use_snowman(u, amount) - if amount>0 and u.region.terrain == "glacier" then - local man = unit.create(u.faction, u.region) - man.race = "snowman" - man.number = amount - return amount - end - return -4 -end - -local self = {} - -function self.update() - if not get_key("xm04") then - eressea.log.debug("Es weihnachtet sehr (2004)") - set_key("xm04", true) - for f in factions() do - f:add_item("speedsail", 1) - f:add_notice("santa2004") - end - end -end - -return self diff --git a/scripts/eressea/xmas2005.lua b/scripts/eressea/xmas2005.lua deleted file mode 100644 index 9bc0ac723..000000000 --- a/scripts/eressea/xmas2005.lua +++ /dev/null @@ -1,30 +0,0 @@ -function usepotion_message(u, potion) - msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", potion) - return msg -end - -function use_stardust(u, amount) - local p = u.region:get_resource("peasant") - p = math.ceil(1.5 * p) - u.region:set_resource("peasant", p) - local msg = usepotion_message(u, "stardust") - msg:send_region(u.region) - return amount -end - -local self = {} - -function self.update() - if not get_key("xm05") then - print("Es weihnachtet sehr (2005)") - set_key("xm05", true) - for f in factions() do - f:add_item("stardust", 1) - f:add_notice("santa2005") - end - end -end - -return self diff --git a/scripts/eressea/xmas2006.lua b/scripts/eressea/xmas2006.lua deleted file mode 100644 index 85a8b3d98..000000000 --- a/scripts/eressea/xmas2006.lua +++ /dev/null @@ -1,53 +0,0 @@ -function use_xmastree(u, amount) - u.region:set_key("xm06", true) - local msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", "xmastree") - msg:send_region(u.region) - return amount -end - -local self = {} - -function self.update() - local turn = get_turn() - local season = get_season(turn) - if season == "calendar::winter" then - eressea.log.debug("it is " .. season .. ", the christmas trees do their magic") - local msg = message.create("xmastree_effect") - for r in regions() do - if r:get_key("xm06") then - trees = r:get_resource("tree") - if trees*0.1>=1 then - r:set_resource("tree", trees * 1.1) - msg:send_region(r) - end - if clear then - end - end - end - else - local prevseason = get_season(turn-1) - if prevseason == "calendar::winter" then - -- we celebrate knut and kick out the trees. - for r in regions() do - if r:get_key("xm06") then - r:set_key("xm06", false) - end - end - end - end -end - -function self.init() - if not get_key("xm06") then - print("Es weihnachtet sehr (2006)") - set_key("xm06", true) - for f in factions() do - f:add_item("xmastree", 1) - f:add_notice("santa2006") - end - end -end - -return self diff --git a/scripts/eressea/xmas2009.lua b/scripts/eressea/xmas2009.lua deleted file mode 100644 index 64bcd7762..000000000 --- a/scripts/eressea/xmas2009.lua +++ /dev/null @@ -1,30 +0,0 @@ -function use_xmastree(u, amount) - if u.region.herb~=nil then - -- TODO: else? - local trees = u.region:get_resource("tree") - u.region:set_resource("tree", 10+trees) - local msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", "xmastree") - msg:send_region(u.region) - return amount - end - return 0 -end - -local xmas = {} - -function xmas.update() - if not get_key("xm09") then - print("Es weihnachtet sehr (2009)") - set_key("xm09", true) - for f in factions() do - f:add_item("xmastree", 1) - local msg = message.create("msg_event") - msg:set_string("string", translate("santa2006")) - msg:send_faction(f) - end - end -end - -return xmas diff --git a/scripts/eressea/xmasitems.lua b/scripts/eressea/xmasitems.lua index c39b648ca..bce82f7e4 100644 --- a/scripts/eressea/xmasitems.lua +++ b/scripts/eressea/xmasitems.lua @@ -24,6 +24,7 @@ function use_snowglobe(u, amount, token) local trans = transform[r.terrain] if trans then r.terrain = trans + return 1 else -- message "invalid terrain" end @@ -32,9 +33,8 @@ function use_snowglobe(u, amount, token) end else -- message "need to specify direction" - return -1 end - return 1 + return -1 end function use_snowman(u, amount) diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 92906667b..8505bfd39 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -201,18 +201,6 @@ function test_no_uruk() assert_equal(f1.race, "orc") end -function disable_test_snowglobe() - local r1 = region.create(0, 0, "glacier") - local r2 = region.create(1, 0, "ocean") - local f = faction.create("noreply@eressea.de", "human", "de") - local u = unit.create(f, r1, 1) - u:add_item("snowglobe", 1) - u:clear_orders() - u:add_order("BENUTZEN 1 Schneekugel Ost") - process_orders() - assert_equal("glacier", r2.terrain) -end - function test_snowman() local r = region.create(0, 0, "glacier") local f = faction.create("noreply@eressea.de", "human", "de") diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 45f0cfec5..cd6cf640a 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -11,3 +11,4 @@ require 'tests.common' require 'tests.storage' require 'tests.magicbag' require 'tests.process' +require 'tests.xmas' diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 07df8dde8..8c6acb895 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -1,5 +1,47 @@ +require "lunit" + +module("tests.xmas", package.seeall, lunit.testcase ) + +function setup() + eressea.free_game() + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("rules.grow.formula", "0") +end + +function test_snowglobe_fail() + local r1 = region.create(0, 0, "glacier") + local r2 = region.create(1, 0, "ocean") + local f = faction.create("snowglobe1@eressea.de", "human", "de") + local u = unit.create(f, r1, 1) + u:add_item("snowglobe", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Schneekugel Ost") + unit.create(f, r2, 1) -- unit in target region => fail + process_orders() + assert_equal('ocean', r2.terrain) +end + +function test_snowglobe() + local r1 = region.create(0, 0, "glacier") + local r2 = region.create(1, 0, "ocean") + local f = faction.create("snowglobe2@eressea.de", "human", "de") + local u = unit.create(f, r1, 1) + local have = 6 + u:add_item("snowglobe", have) + local xform = { ocean = "glacier", glacier = "glacier", firewall = "volcano", volcano = "mountain", desert = "plain", plain = "plain" } + u:clear_orders() + u:add_order("BENUTZEN 1 Schneekugel Ost") + for k, v in pairs(xform) do + r2.terrain = k + process_orders() + assert_equal(v, r2.terrain) + if k~=v then have=have - 1 end + assert_equal(have, u:get_item("snowglobe")) + end +end + local function use_tree(terrain) - local r = region.create(0,0, terrain) + local r = region.create(0, 0, terrain) local f = faction.create("noreply@eressea.de", "human", "de") local u1 = unit.create(f, r, 5) r:set_resource("tree", 0) diff --git a/src/laws.c b/src/laws.c index 5c6d5a46e..121b9d814 100755 --- a/src/laws.c +++ b/src/laws.c @@ -784,19 +784,14 @@ void demographics(void) } for (r = regions; r; r = r->next) { - ++r->age; /* also oceans. no idea why we didn't always do that */ + ++r->age; /* also oceans. no idea why we didn't always do that */ live(r); if (!fval(r->terrain, SEA_REGION)) { /* die Nachfrage nach Produkten steigt. */ struct demand *dmd; if (r->land) { - static int plant_rules = -1; - - if (plant_rules < 0) { - plant_rules = - get_param_int(global.parameters, "rules.grow.formula", 0); - } + int plant_rules = get_param_int(global.parameters, "rules.grow.formula", 2); for (dmd = r->land->demands; dmd; dmd = dmd->next) { if (dmd->value > 0 && dmd->value < MAXDEMAND) { float rise = DMRISE; @@ -822,11 +817,11 @@ void demographics(void) } } horses(r); - if (plant_rules == 0) { /* E1 */ + if (plant_rules == 2) { /* E2 */ growing_trees(r, current_season, last_weeks_season); growing_herbs(r, current_season, last_weeks_season); } - else { /* E3 */ + else if (plant_rules==1) { /* E3 */ growing_trees_e3(r, current_season, last_weeks_season); } }