diff --git a/conf/e3/config.xml b/conf/e3/config.xml
index 1a1f5f26f..0531f69d2 100644
--- a/conf/e3/config.xml
+++ b/conf/e3/config.xml
@@ -51,13 +51,13 @@
Bitte denke daran, deine Befehle mit dem Betreff
- E3 BEFEHLE an eressea-server@eressea.de zu senden.
+ ERESSEA 3 BEFEHLE an eressea-server@eressea.de zu senden.
Remember to send your orders to
eressea-server@eressea.de with the subject E3 ORDERS.
- E3 BEFEHLE
- E3 ORDERS
+ ERESSEA 3 BEFEHLE
+ ERESSEA 3 ORDERS
ARBEITEN
diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml
index f384f3a23..eaf008ac6 100644
--- a/res/core/de/strings.xml
+++ b/res/core/de/strings.xml
@@ -1591,6 +1591,14 @@
Schneemann
snowman
+
+ Schneekugel
+ snow globe
+
+
+ Schneekugeln
+ snow globes
+
Schneemänner
snowmen
diff --git a/res/core/messages.xml b/res/core/messages.xml
index 0090360b0..6b5b8bff0 100644
--- a/res/core/messages.xml
+++ b/res/core/messages.xml
@@ -4,7 +4,18 @@
Die Region ist verwüstet, der Boden karg.
The region is ravaged, the ground infertile.
-
+
+
+
+
+ 'Ho ho ho!' Ein dicker Gnom fliegt auf einem von
+ 8 Jungdrachen gezogenen Schlitten durch die Nacht und vermacht Deiner
+ Partei eine $resource($item,1). (Um diesen Gegenstand einer Einheit zu geben, gib
+ ihr den Befehl 'BEANSPRUCHE 1 $resource($item,1)').
+ 'Ho ho ho!' A fat little gnome Gnom on a sled
+ pulled by 8 young dragons flies through the stary night and presents
+ your faction with a $resource($item,1).
+
diff --git a/res/eressea/items.xml b/res/eressea/items.xml
index 076cc023c..8b2df7add 100644
--- a/res/eressea/items.xml
+++ b/res/eressea/items.xml
@@ -22,6 +22,12 @@
+
+ -
+
+
+
+
-
diff --git a/scripts/eressea/e3/init.lua b/scripts/eressea/e3/init.lua
index cb91b4713..9acda1093 100644
--- a/scripts/eressea/e3/init.lua
+++ b/scripts/eressea/e3/init.lua
@@ -5,7 +5,6 @@ eressea.log.debug("rules for game E3")
return {
require('eressea'),
- require('eressea.xmas'),
require('eressea.xmasitems'),
require('eressea.markets'),
require('eressea.frost'),
diff --git a/scripts/eressea/xmas.lua b/scripts/eressea/xmas.lua
index 37f2941f1..36e755f45 100644
--- a/scripts/eressea/xmas.lua
+++ b/scripts/eressea/xmas.lua
@@ -1,7 +1,7 @@
local gifts = {
e2 = {
- -- { year = 2015, turn = 960, item = 'snowglobe' },
- { year = 2009, turn = 624, key = 'xm09', item = 'xmastree' },
+ { year = 2015, turn = 959, item = 'snowglobe', msg='santa_f' },
+ { year = 2009, turn = 624, item = 'xmastree' },
{ year = 2006, turn = 468, key = 'xm06', item = 'snowman' },
{ year = 2005, turn = 416, key = 'xm05', item = 'stardust' },
{ year = 2004, turn = 364, key = 'xm04', item = 'speedsail' }
@@ -14,10 +14,17 @@ local gifts = {
local function give_gifts(gift)
eressea.log.info("Es weihnachtet sehr (" .. gift.year .. ")")
+ local msg = nil
+ if gift.msg then
+ msg = message.create(gift.msg)
+ msg:set_resource("item", gift.item)
+ end
if gift.item then
for f in factions() do
f:add_item(gift.item, 1)
- f:add_notice("santa" .. gift.year)
+ if msg then
+ msg:send_faction(f)
+ end
end
end
end
@@ -29,10 +36,8 @@ function self.init()
local tbl = gifts[config.rules]
if tbl then
for _, gift in ipairs(tbl) do
- if gift.turn then
- if gift.turn==turn then
- give_gifts(gift)
- end
+ if turn == gift.turn then
+ give_gifts(gift)
elseif gift.key and not get_key(gift.key) then
give_gifts(gift)
set_key(gift.key)
diff --git a/scripts/eressea/xmasitems.lua b/scripts/eressea/xmasitems.lua
index 8bfb1c8bb..bce82f7e4 100644
--- a/scripts/eressea/xmasitems.lua
+++ b/scripts/eressea/xmasitems.lua
@@ -1,3 +1,42 @@
+local function get_direction(locale, token)
+ local dir = eressea.locale.direction(locale, token)
+ if dir and dir>=0 then
+ return dir
+ end
+ return nil
+end
+
+function use_snowglobe(u, amount, token)
+ local transform = {
+ ocean = "glacier",
+ firewall = "volcano",
+ volcano = "mountain",
+ desert = "plain"
+ }
+ local direction = get_direction(u.faction.locale, token)
+ if direction then
+ local r = u.region:next(direction)
+ if r.units() then
+ -- message "target region not empty"
+ return -1
+ end
+ if r then
+ local trans = transform[r.terrain]
+ if trans then
+ r.terrain = trans
+ return 1
+ else
+ -- message "invalid terrain"
+ end
+ else
+ -- message "invalid terrain"
+ end
+ else
+ -- message "need to specify direction"
+ end
+ return -1
+end
+
function use_snowman(u, amount)
if amount>0 and u.region.terrain == "glacier" then
local man = unit.create(u.faction, u.region)
diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua
index 84f5dc3f9..4a2b3e59e 100644
--- a/scripts/run-tests-e2.lua
+++ b/scripts/run-tests-e2.lua
@@ -15,7 +15,6 @@ require 'eressea'
require 'eressea.xmlconf'
require 'eressea.path'
require 'tests.e2'
-require 'tests.xmas'
require 'lunit'
rules = require('eressea.' .. config.rules)
diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua
index 1e48cd40e..47bcca60b 100644
--- a/scripts/run-tests-e3.lua
+++ b/scripts/run-tests-e3.lua
@@ -15,7 +15,6 @@ require 'eressea'
require 'eressea.path'
require 'eressea.xmlconf'
require 'tests.e3'
-require 'tests.xmas'
require 'lunit'
eressea.settings.set("rules.alliances", "0")
diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua
index decd0c14b..43c77f93f 100644
--- a/scripts/tests/common.lua
+++ b/scripts/tests/common.lua
@@ -34,6 +34,14 @@ function setup()
eressea.settings.set("study.random_progress", "0")
end
+function test_locales()
+ assert_equal(2, eressea.locale.direction("de", "Ost"))
+ assert_equal(5, eressea.locale.direction("de", "westen"))
+ assert_equal(4, eressea.locale.direction("de", "sw"))
+ assert_equal(-1, eressea.locale.direction("de", "foo"))
+ assert_equal(-1, eressea.locale.direction("foo", "sw"))
+end
+
function test_flags()
local r = region.create(0, 0, "plain")
local f = faction.create("flags@eressea.de", "halfling", "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/bind_locale.c b/src/bind_locale.c
index a4c2ac0f0..992f140b7 100644
--- a/src/bind_locale.c
+++ b/src/bind_locale.c
@@ -1,5 +1,6 @@
#include "bind_locale.h"
#include "util/language.h"
+#include "direction.h"
void locale_create(const char *lang) {
get_or_create_locale(lang);
@@ -19,3 +20,11 @@ const char * locale_get(const char *lang, const char *key) {
}
return 0;
}
+
+int locale_direction(const char *lang, const char *str) {
+ struct locale *loc = get_locale(lang);
+ if (loc) {
+ return get_direction(str, loc);
+ }
+ return NODIRECTION;
+}
diff --git a/src/bind_locale.h b/src/bind_locale.h
index 87c0eb742..7391c2b05 100644
--- a/src/bind_locale.h
+++ b/src/bind_locale.h
@@ -7,6 +7,7 @@ extern "C" {
void locale_create(const char *lang);
void locale_set(const char *lang, const char *key, const char *str);
const char * locale_get(const char *lang, const char *key);
+ int locale_direction(const char *lang, const char *str);
#ifdef __cplusplus
}
diff --git a/src/bind_message.c b/src/bind_message.c
index bbbd2bc0b..34e43301a 100644
--- a/src/bind_message.c
+++ b/src/bind_message.c
@@ -57,22 +57,7 @@ static lua_message *msg_create_message(const char *type)
return lmsg;
}
-/*
- static void
- msg_destroy_message(lua_message * msg)
- {
- if (msg->msg) msg_release(msg->msg);
- if (msg->mtype) {
- int i;
- for (i=0;i!=msg->mtype->nparameters;++i) {
- if (msg->mtype->types[i]->release) {
- msg->mtype->types[i]->release(msg->args[i]);
- }
- }
- }
- }
- */
-int msg_set_resource(lua_message * msg, const char *param, const char *resname)
+static int msg_set_resource(lua_message * msg, const char *param, const char *resname)
{
if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param);
@@ -96,7 +81,7 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname)
return E_INVALID_MESSAGE;
}
-int msg_set_unit(lua_message * msg, const char *param, const unit * u)
+static int msg_set_unit(lua_message * msg, const char *param, const unit * u)
{
if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param);
@@ -115,7 +100,7 @@ int msg_set_unit(lua_message * msg, const char *param, const unit * u)
return E_INVALID_MESSAGE;
}
-int msg_set_region(lua_message * msg, const char *param, const region * r)
+static int msg_set_region(lua_message * msg, const char *param, const region * r)
{
if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param);
@@ -134,7 +119,7 @@ int msg_set_region(lua_message * msg, const char *param, const region * r)
return E_INVALID_MESSAGE;
}
-int msg_set_string(lua_message * msg, const char *param, const char *value)
+static int msg_set_string(lua_message * msg, const char *param, const char *value)
{
if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param);
@@ -155,7 +140,7 @@ int msg_set_string(lua_message * msg, const char *param, const char *value)
return E_INVALID_MESSAGE;
}
-int msg_set_int(lua_message * msg, const char *param, int value)
+static int msg_set_int(lua_message * msg, const char *param, int value)
{
if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param);
@@ -173,7 +158,7 @@ int msg_set_int(lua_message * msg, const char *param, int value)
return E_INVALID_MESSAGE;
}
-int msg_send_faction(lua_message * msg, faction * f)
+static int msg_send_faction(lua_message * msg, faction * f)
{
assert(f);
assert(msg);
@@ -188,7 +173,7 @@ int msg_send_faction(lua_message * msg, faction * f)
return E_INVALID_MESSAGE;
}
-int msg_send_region(lua_message * lmsg, region * r)
+static int msg_send_region(lua_message * lmsg, region * r)
{
if (lmsg->mtype) {
if (lmsg->msg == NULL) {
diff --git a/src/helpers.c b/src/helpers.c
index 21483fa50..0687793d4 100644
--- a/src/helpers.c
+++ b/src/helpers.c
@@ -19,6 +19,7 @@ without prior permission by the authors of Eressea.
#include
#include
#include
+#include
#include
#include
@@ -504,8 +505,8 @@ struct order *ord)
if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
lua_pushinteger(L, amount);
-
- if (lua_pcall(L, 2, 1, 0) != 0) {
+ lua_pushstring(L, getstrtoken());
+ if (lua_pcall(L, 3, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1);
diff --git a/src/laws.c b/src/laws.c
index 5ba995e72..c88145760 100755
--- a/src/laws.c
+++ b/src/laws.c
@@ -785,14 +785,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) {
- int plant_rules = config_get_int("rules.grow.formula", 0);
+ int plant_rules = config_get_int("rules.grow.formula", 2);
for (dmd = r->land->demands; dmd; dmd = dmd->next) {
if (dmd->value > 0 && dmd->value < MAXDEMAND) {
float rise = DMRISE;
@@ -818,11 +818,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);
}
}
@@ -3432,10 +3432,13 @@ void update_long_order(unit * u)
static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
{
int i;
- int target = read_unitid(u->faction, u->region);
+ int target = -1;
+
+ if (itype->useonother) {
+ target = read_unitid(u->faction, u->region);
+ }
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
-
if (amount > i) {
/* TODO: message? eg. "not enough %, using only %" */
amount = i;
@@ -3445,20 +3448,16 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
}
if (target == -1) {
- int result;
- if (itype->use == NULL) {
- return EUNUSABLE;
+ if (itype->use) {
+ int result = itype->use(u, itype, amount, ord);
+ if (result > 0) {
+ use_pooled(u, itype->rtype, GET_DEFAULT, result);
+ }
+ return result;
}
- result = itype->use ? itype->use(u, itype, amount, ord) : EUNUSABLE;
- if (result > 0) {
- use_pooled(u, itype->rtype, GET_DEFAULT, result);
- }
- return result;
+ return EUNUSABLE;
}
else {
- if (itype->useonother == NULL) {
- return EUNUSABLE;
- }
return itype->useonother(u, target, itype, amount, ord);
}
}
diff --git a/src/locale.pkg b/src/locale.pkg
index 9a2c420de..b14dc9261 100644
--- a/src/locale.pkg
+++ b/src/locale.pkg
@@ -7,5 +7,6 @@ module eressea {
void locale_create @ create(const char *lang);
void locale_set @ set(const char *lang, const char *key, const char *str);
const char * locale_get @ get(const char *lang, const char *key);
+ int locale_direction @ direction(const char *lang, const char *str);
}
}
diff --git a/src/locale.pkg.c b/src/locale.pkg.c
index 34517584f..1792b742e 100644
--- a/src/locale.pkg.c
+++ b/src/locale.pkg.c
@@ -20,7 +20,6 @@ LUALIB_API int luaopen_locale (lua_State* tolua_S);
#undef tolua_reg_types
#define tolua_reg_types tolua_reg_types_locale
-#include "bind_tolua.h"
#include "bind_locale.h"
/* function to register type */
@@ -113,6 +112,35 @@ static int tolua_locale_eressea_locale_get00(lua_State* tolua_S)
#endif
}
+/* function: locale_direction */
+static int tolua_locale_eressea_locale_direction00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isstring(tolua_S,1,0,&tolua_err) ||
+ !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const char* lang = ((const char*) tolua_tostring(tolua_S,1,0));
+ const char* str = ((const char*) tolua_tostring(tolua_S,2,0));
+ {
+ int tolua_ret = (int) locale_direction(lang,str);
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'direction'.",&tolua_err);
+ return 0;
+#endif
+}
+
/* Open lib function */
LUALIB_API int luaopen_locale (lua_State* tolua_S)
{
@@ -127,6 +155,7 @@ LUALIB_API int luaopen_locale (lua_State* tolua_S)
tolua_function(tolua_S,"create",tolua_locale_eressea_locale_create00);
tolua_function(tolua_S,"set",tolua_locale_eressea_locale_set00);
tolua_function(tolua_S,"get",tolua_locale_eressea_locale_get00);
+ tolua_function(tolua_S,"direction",tolua_locale_eressea_locale_direction00);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);