forked from github/server
parent
257ae38749
commit
3ea33c6895
3 changed files with 35 additions and 3 deletions
|
@ -15,6 +15,23 @@ local function error_message(msg, u, ord)
|
||||||
return -1
|
return -1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function usepotion_message(u, type)
|
||||||
|
msg = message.create("usepotion")
|
||||||
|
msg:set_unit("unit", u)
|
||||||
|
msg:set_resource("potion", type)
|
||||||
|
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 1
|
||||||
|
end
|
||||||
|
|
||||||
function use_snowglobe(u, amount, token, ord)
|
function use_snowglobe(u, amount, token, ord)
|
||||||
local transform = {
|
local transform = {
|
||||||
ocean = "glacier",
|
ocean = "glacier",
|
||||||
|
@ -59,9 +76,7 @@ function use_xmastree(u, amount)
|
||||||
local trees = u.region:get_resource("tree")
|
local trees = u.region:get_resource("tree")
|
||||||
u.region:set_key("xm06", true)
|
u.region:set_key("xm06", true)
|
||||||
u.region:set_resource("tree", 10+trees)
|
u.region:set_resource("tree", 10+trees)
|
||||||
local msg = message.create("usepotion")
|
local msg = usepotion_message(u, "xmastree")
|
||||||
msg:set_unit("unit", u)
|
|
||||||
msg:set_resource("potion", "xmastree")
|
|
||||||
msg:send_region(u.region)
|
msg:send_region(u.region)
|
||||||
return amount
|
return amount
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,3 +82,18 @@ function test_xmastree()
|
||||||
r = use_tree("plain")
|
r = use_tree("plain")
|
||||||
assert_equal(10, r:get_resource("tree"))
|
assert_equal(10, r:get_resource("tree"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_stardust()
|
||||||
|
-- fix random peasant changes:
|
||||||
|
eressea.settings.set("rules.economy.repopulate_maximum", 0)
|
||||||
|
local r = region.create(0, 0, "plain")
|
||||||
|
r:set_resource("peasant", 10)
|
||||||
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||||
|
local u = unit.create(f, r, 5)
|
||||||
|
u:add_item("stardust", 1)
|
||||||
|
u:clear_orders()
|
||||||
|
u:add_order("BENUTZEN 1 Sternenstaub")
|
||||||
|
process_orders()
|
||||||
|
assert_equal(15, r:get_resource("peasant"))
|
||||||
|
assert_equal(0, u:get_item('stardust'))
|
||||||
|
end
|
||||||
|
|
|
@ -458,6 +458,7 @@ static int tolua_region_create(lua_State * L)
|
||||||
const terrain_type *terrain = get_terrain(tname);
|
const terrain_type *terrain = get_terrain(tname);
|
||||||
region *r, *result;
|
region *r, *result;
|
||||||
if (!terrain) {
|
if (!terrain) {
|
||||||
|
log_error("lua: region.create with invalid terrain %s", tname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,6 +482,7 @@ static int tolua_region_create(lua_State * L)
|
||||||
tolua_pushusertype(L, result, TOLUA_CAST "region");
|
tolua_pushusertype(L, result, TOLUA_CAST "region");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
log_error("lua: region.create with invalid terrain %s", tname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue