testing christmas items, removing old xmas scripts

This commit is contained in:
Enno Rehling 2015-12-22 19:33:44 +01:00
parent e678c1bcce
commit b66b6f7f4c
11 changed files with 53 additions and 165 deletions

View File

@ -4,9 +4,8 @@ eressea.log.debug("rules for game E2")
return { return {
require('eressea'), require('eressea'),
require('eressea.autoseed'), require('eressea.autoseed'),
require('eressea.xmas2004'), require('eressea.xmas'),
require('eressea.xmas2005'), require('eressea.xmasitems'),
require('eressea.xmas2006'),
require('eressea.wedding'), require('eressea.wedding'),
require('eressea.embassy'), require('eressea.embassy'),
require('eressea.eternath'), require('eressea.eternath'),

View File

@ -5,7 +5,7 @@ eressea.log.debug("rules for game E3")
return { return {
require('eressea'), require('eressea'),
require('eressea.xmas2009'), require('eressea.xmasitems'),
require('eressea.markets'), require('eressea.markets'),
require('eressea.frost'), require('eressea.frost'),
require('eressea.ents') require('eressea.ents')

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -24,6 +24,7 @@ function use_snowglobe(u, amount, token)
local trans = transform[r.terrain] local trans = transform[r.terrain]
if trans then if trans then
r.terrain = trans r.terrain = trans
return 1
else else
-- message "invalid terrain" -- message "invalid terrain"
end end
@ -32,9 +33,8 @@ function use_snowglobe(u, amount, token)
end end
else else
-- message "need to specify direction" -- message "need to specify direction"
return -1
end end
return 1 return -1
end end
function use_snowman(u, amount) function use_snowman(u, amount)

View File

@ -201,18 +201,6 @@ function test_no_uruk()
assert_equal(f1.race, "orc") assert_equal(f1.race, "orc")
end 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() function test_snowman()
local r = region.create(0, 0, "glacier") local r = region.create(0, 0, "glacier")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")

View File

@ -11,3 +11,4 @@ require 'tests.common'
require 'tests.storage' require 'tests.storage'
require 'tests.magicbag' require 'tests.magicbag'
require 'tests.process' require 'tests.process'
require 'tests.xmas'

View File

@ -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 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 f = faction.create("noreply@eressea.de", "human", "de")
local u1 = unit.create(f, r, 5) local u1 = unit.create(f, r, 5)
r:set_resource("tree", 0) r:set_resource("tree", 0)

View File

@ -784,19 +784,14 @@ void demographics(void)
} }
for (r = regions; r; r = r->next) { 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); live(r);
if (!fval(r->terrain, SEA_REGION)) { if (!fval(r->terrain, SEA_REGION)) {
/* die Nachfrage nach Produkten steigt. */ /* die Nachfrage nach Produkten steigt. */
struct demand *dmd; struct demand *dmd;
if (r->land) { if (r->land) {
static int plant_rules = -1; int plant_rules = get_param_int(global.parameters, "rules.grow.formula", 2);
if (plant_rules < 0) {
plant_rules =
get_param_int(global.parameters, "rules.grow.formula", 0);
}
for (dmd = r->land->demands; dmd; dmd = dmd->next) { for (dmd = r->land->demands; dmd; dmd = dmd->next) {
if (dmd->value > 0 && dmd->value < MAXDEMAND) { if (dmd->value > 0 && dmd->value < MAXDEMAND) {
float rise = DMRISE; float rise = DMRISE;
@ -822,11 +817,11 @@ void demographics(void)
} }
} }
horses(r); horses(r);
if (plant_rules == 0) { /* E1 */ if (plant_rules == 2) { /* E2 */
growing_trees(r, current_season, last_weeks_season); growing_trees(r, current_season, last_weeks_season);
growing_herbs(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); growing_trees_e3(r, current_season, last_weeks_season);
} }
} }