diff --git a/scripts/eressea/xmasitems.lua b/scripts/eressea/xmasitems.lua index 4f8a20767..b31691d72 100644 --- a/scripts/eressea/xmasitems.lua +++ b/scripts/eressea/xmasitems.lua @@ -15,6 +15,23 @@ local function error_message(msg, u, ord) return -1 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) local transform = { ocean = "glacier", @@ -59,9 +76,7 @@ function use_xmastree(u, amount) local trees = u.region:get_resource("tree") u.region:set_key("xm06", true) u.region:set_resource("tree", 10+trees) - local msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", "xmastree") + local msg = usepotion_message(u, "xmastree") msg:send_region(u.region) return amount end diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 7b4490d7a..e1cd4753b 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -82,3 +82,18 @@ function test_xmastree() r = use_tree("plain") assert_equal(10, r:get_resource("tree")) 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 diff --git a/src/bind_region.c b/src/bind_region.c index 519502162..a28b94c07 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -458,6 +458,7 @@ static int tolua_region_create(lua_State * L) const terrain_type *terrain = get_terrain(tname); region *r, *result; if (!terrain) { + log_error("lua: region.create with invalid terrain %s", tname); return 0; } @@ -481,6 +482,7 @@ static int tolua_region_create(lua_State * L) tolua_pushusertype(L, result, TOLUA_CAST "region"); return 1; } + log_error("lua: region.create with invalid terrain %s", tname); return 0; }