it's beginning to look a lot like christmas

Conflicts:
	scripts/eressea/xmas.lua
This commit is contained in:
Enno Rehling 2015-12-22 14:38:56 +01:00
parent 80e0707cb2
commit cf90f8cf93
3 changed files with 71 additions and 22 deletions

View File

@ -1,5 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<messages> <messages>
<message name="santa_f" section="events">
<type>
<arg name="item" type="resource"/>
</type>
<text locale="de">'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)').</text>
<text locale="en">'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).</text>
</message>
<message name="force_leave_ship" section="events"> <message name="force_leave_ship" section="events">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>

49
scripts/eressea/xmas.lua Normal file
View File

@ -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

View File

@ -57,22 +57,7 @@ static lua_message *msg_create_message(const char *type)
return lmsg; return lmsg;
} }
/* static int msg_set_resource(lua_message * msg, const char *param, const char *resname)
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)
{ {
if (msg->mtype) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); 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; 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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); 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; 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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); 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; 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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); 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; 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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); 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; 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(f);
assert(msg); assert(msg);
@ -188,7 +173,7 @@ int msg_send_faction(lua_message * msg, faction * f)
return E_INVALID_MESSAGE; 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->mtype) {
if (lmsg->msg == NULL) { if (lmsg->msg == NULL) {