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 3186dcc42..0f16f91b1 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -1581,6 +1581,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 a3d7ad6e8..c79416c25 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1,5 +1,20 @@ + + + + + + '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/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/xmas.lua b/scripts/eressea/xmas.lua new file mode 100644 index 000000000..36e755f45 --- /dev/null +++ b/scripts/eressea/xmas.lua @@ -0,0 +1,49 @@ +local gifts = { + e2 = { + { 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' } + }, + e3 = { + -- { year = 2015, turn = 338, item = 'snowglobe' }, + { year = 2009, turn = 26, key = 'xm09', item = 'xmastree' } + } +} + +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) + if msg then + msg:send_faction(f) + end + end + end +end + +local self = {} + +function self.init() + local turn = get_turn() + local tbl = gifts[config.rules] + if tbl then + for _, gift in ipairs(tbl) do + 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) + end + end + end +end + +return self 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 new file mode 100644 index 000000000..bce82f7e4 --- /dev/null +++ b/scripts/eressea/xmasitems.lua @@ -0,0 +1,97 @@ +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) + man.race = "snowman" + man.number = amount + return amount + end + return -4 +end + +function use_xmastree(u, amount) + if u.region.herb~=nil then + -- TODO: else? + 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") + msg:send_region(u.region) + return amount + end + return 0 +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 + +return self 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 a81a91679..c784e9901 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 @@ -509,8 +510,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 f508c4b69..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); } } @@ -3442,10 +3437,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; @@ -3455,20 +3453,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);