From cf90f8cf931e5b89dec26af061e51daed92289b6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 22 Dec 2015 14:38:56 +0100 Subject: [PATCH] it's beginning to look a lot like christmas Conflicts: scripts/eressea/xmas.lua --- res/core/messages.xml | 15 ++++++++++++ scripts/eressea/xmas.lua | 49 ++++++++++++++++++++++++++++++++++++++++ src/bind_message.c | 29 ++++++------------------ 3 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 scripts/eressea/xmas.lua 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/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/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) {