Merge branch 'master' into develop

Conflicts:
	res/core/messages.xml
	scripts/eressea/e3/init.lua
	scripts/eressea/xmas.lua
	scripts/eressea/xmasitems.lua
	src/buildno.h
	src/laws.c
This commit is contained in:
Enno Rehling 2015-12-26 14:45:51 +01:00
commit 2aafb841a5
19 changed files with 199 additions and 57 deletions

View File

@ -51,13 +51,13 @@
</string> </string>
<string name="newbie_info_1"> <string name="newbie_info_1">
<text locale="de">Bitte denke daran, deine Befehle mit dem Betreff <text locale="de">Bitte denke daran, deine Befehle mit dem Betreff
E3 BEFEHLE an eressea-server@eressea.de zu senden.</text> ERESSEA 3 BEFEHLE an eressea-server@eressea.de zu senden.</text>
<text locale="en">Remember to send your orders to <text locale="en">Remember to send your orders to
eressea-server@eressea.de with the subject E3 ORDERS.</text> eressea-server@eressea.de with the subject E3 ORDERS.</text>
</string> </string>
<string name="mailcmd"> <string name="mailcmd">
<text locale="de">E3 BEFEHLE</text> <text locale="de">ERESSEA 3 BEFEHLE</text>
<text locale="en">E3 ORDERS</text> <text locale="en">ERESSEA 3 ORDERS</text>
</string> </string>
<string name="defaultorder"> <string name="defaultorder">
<text locale="de">ARBEITEN</text> <text locale="de">ARBEITEN</text>

View File

@ -1591,6 +1591,14 @@
<text locale="de">Schneemann</text> <text locale="de">Schneemann</text>
<text locale="en">snowman</text> <text locale="en">snowman</text>
</string> </string>
<string name="snowglobe">
<text locale="de">Schneekugel</text>
<text locale="en">snow globe</text>
</string>
<string name="snowglobe_p">
<text locale="de">Schneekugeln</text>
<text locale="en">snow globes</text>
</string>
<string name="snowman_p"> <string name="snowman_p">
<text locale="de">Schneemänner</text> <text locale="de">Schneemänner</text>
<text locale="en">snowmen</text> <text locale="en">snowmen</text>

View File

@ -4,7 +4,18 @@
<text locale="de">Die Region ist verwüstet, der Boden karg.</text> <text locale="de">Die Region ist verwüstet, der Boden karg.</text>
<text locale="en">The region is ravaged, the ground infertile.</text> <text locale="en">The region is ravaged, the ground infertile.</text>
</message> </message>
<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"/>

View File

@ -22,6 +22,12 @@
</item> </item>
</resource> </resource>
<resource name="snowglobe">
<item notlost="yes" weight="1">
<function name="use" value="lua_useitem"/>
</item>
</resource>
<resource name="ring_of_levitation" appearance="ring"> <resource name="ring_of_levitation" appearance="ring">
<item notlost="yes" weight="0" cursed="true"> <item notlost="yes" weight="0" cursed="true">
<function name="use" value="lua_useitem"/> <function name="use" value="lua_useitem"/>

View File

@ -5,7 +5,6 @@ eressea.log.debug("rules for game E3")
return { return {
require('eressea'), require('eressea'),
require('eressea.xmas'),
require('eressea.xmasitems'), require('eressea.xmasitems'),
require('eressea.markets'), require('eressea.markets'),
require('eressea.frost'), require('eressea.frost'),

View File

@ -1,7 +1,7 @@
local gifts = { local gifts = {
e2 = { e2 = {
-- { year = 2015, turn = 960, item = 'snowglobe' }, { year = 2015, turn = 959, item = 'snowglobe', msg='santa_f' },
{ year = 2009, turn = 624, key = 'xm09', item = 'xmastree' }, { year = 2009, turn = 624, item = 'xmastree' },
{ year = 2006, turn = 468, key = 'xm06', item = 'snowman' }, { year = 2006, turn = 468, key = 'xm06', item = 'snowman' },
{ year = 2005, turn = 416, key = 'xm05', item = 'stardust' }, { year = 2005, turn = 416, key = 'xm05', item = 'stardust' },
{ year = 2004, turn = 364, key = 'xm04', item = 'speedsail' } { year = 2004, turn = 364, key = 'xm04', item = 'speedsail' }
@ -14,10 +14,17 @@ local gifts = {
local function give_gifts(gift) local function give_gifts(gift)
eressea.log.info("Es weihnachtet sehr (" .. gift.year .. ")") 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 if gift.item then
for f in factions() do for f in factions() do
f:add_item(gift.item, 1) f:add_item(gift.item, 1)
f:add_notice("santa" .. gift.year) if msg then
msg:send_faction(f)
end
end end
end end
end end
@ -29,10 +36,8 @@ function self.init()
local tbl = gifts[config.rules] local tbl = gifts[config.rules]
if tbl then if tbl then
for _, gift in ipairs(tbl) do for _, gift in ipairs(tbl) do
if gift.turn then if turn == gift.turn then
if gift.turn==turn then give_gifts(gift)
give_gifts(gift)
end
elseif gift.key and not get_key(gift.key) then elseif gift.key and not get_key(gift.key) then
give_gifts(gift) give_gifts(gift)
set_key(gift.key) set_key(gift.key)

View File

@ -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) function use_snowman(u, amount)
if amount>0 and u.region.terrain == "glacier" then if amount>0 and u.region.terrain == "glacier" then
local man = unit.create(u.faction, u.region) local man = unit.create(u.faction, u.region)

View File

@ -15,7 +15,6 @@ require 'eressea'
require 'eressea.xmlconf' require 'eressea.xmlconf'
require 'eressea.path' require 'eressea.path'
require 'tests.e2' require 'tests.e2'
require 'tests.xmas'
require 'lunit' require 'lunit'
rules = require('eressea.' .. config.rules) rules = require('eressea.' .. config.rules)

View File

@ -15,7 +15,6 @@ require 'eressea'
require 'eressea.path' require 'eressea.path'
require 'eressea.xmlconf' require 'eressea.xmlconf'
require 'tests.e3' require 'tests.e3'
require 'tests.xmas'
require 'lunit' require 'lunit'
eressea.settings.set("rules.alliances", "0") eressea.settings.set("rules.alliances", "0")

View File

@ -34,6 +34,14 @@ function setup()
eressea.settings.set("study.random_progress", "0") eressea.settings.set("study.random_progress", "0")
end 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() function test_flags()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("flags@eressea.de", "halfling", "de") local f = faction.create("flags@eressea.de", "halfling", "de")

View File

@ -11,3 +11,4 @@ require 'tests.common'
require 'tests.storage' require 'tests.storage'
require 'tests.magicbag' require 'tests.magicbag'
require 'tests.process' require 'tests.process'
require 'tests.xmas'

View File

@ -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 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 f = faction.create("noreply@eressea.de", "human", "de")
local u1 = unit.create(f, r, 5) local u1 = unit.create(f, r, 5)
r:set_resource("tree", 0) r:set_resource("tree", 0)

View File

@ -1,5 +1,6 @@
#include "bind_locale.h" #include "bind_locale.h"
#include "util/language.h" #include "util/language.h"
#include "direction.h"
void locale_create(const char *lang) { void locale_create(const char *lang) {
get_or_create_locale(lang); get_or_create_locale(lang);
@ -19,3 +20,11 @@ const char * locale_get(const char *lang, const char *key) {
} }
return 0; 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;
}

View File

@ -7,6 +7,7 @@ extern "C" {
void locale_create(const char *lang); void locale_create(const char *lang);
void locale_set(const char *lang, const char *key, const char *str); void locale_set(const char *lang, const char *key, const char *str);
const char * locale_get(const char *lang, const char *key); const char * locale_get(const char *lang, const char *key);
int locale_direction(const char *lang, const char *str);
#ifdef __cplusplus #ifdef __cplusplus
} }

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) {

View File

@ -19,6 +19,7 @@ without prior permission by the authors of Eressea.
#include <util/bsdstring.h> #include <util/bsdstring.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/log.h> #include <util/log.h>
#include <util/parser.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <kernel/config.h> #include <kernel/config.h>
@ -504,8 +505,8 @@ struct order *ord)
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
lua_pushinteger(L, amount); lua_pushinteger(L, amount);
lua_pushstring(L, getstrtoken());
if (lua_pcall(L, 2, 1, 0) != 0) { if (lua_pcall(L, 3, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);

View File

@ -785,14 +785,14 @@ void demographics(void)
} }
for (r = regions; r; r = r->next) { 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); live(r);
if (!fval(r->terrain, SEA_REGION)) { if (!fval(r->terrain, SEA_REGION)) {
/* die Nachfrage nach Produkten steigt. */ /* die Nachfrage nach Produkten steigt. */
struct demand *dmd; struct demand *dmd;
if (r->land) { 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) { for (dmd = r->land->demands; dmd; dmd = dmd->next) {
if (dmd->value > 0 && dmd->value < MAXDEMAND) { if (dmd->value > 0 && dmd->value < MAXDEMAND) {
float rise = DMRISE; float rise = DMRISE;
@ -818,11 +818,11 @@ void demographics(void)
} }
} }
horses(r); horses(r);
if (plant_rules == 0) { /* E1 */ if (plant_rules == 2) { /* E2 */
growing_trees(r, current_season, last_weeks_season); growing_trees(r, current_season, last_weeks_season);
growing_herbs(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); 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) static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
{ {
int i; 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); i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
if (amount > i) { if (amount > i) {
/* TODO: message? eg. "not enough %, using only %" */ /* TODO: message? eg. "not enough %, using only %" */
amount = i; amount = i;
@ -3445,20 +3448,16 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
} }
if (target == -1) { if (target == -1) {
int result; if (itype->use) {
if (itype->use == NULL) { int result = itype->use(u, itype, amount, ord);
return EUNUSABLE; if (result > 0) {
use_pooled(u, itype->rtype, GET_DEFAULT, result);
}
return result;
} }
result = itype->use ? itype->use(u, itype, amount, ord) : EUNUSABLE; return EUNUSABLE;
if (result > 0) {
use_pooled(u, itype->rtype, GET_DEFAULT, result);
}
return result;
} }
else { else {
if (itype->useonother == NULL) {
return EUNUSABLE;
}
return itype->useonother(u, target, itype, amount, ord); return itype->useonother(u, target, itype, amount, ord);
} }
} }

View File

@ -7,5 +7,6 @@ module eressea {
void locale_create @ create(const char *lang); void locale_create @ create(const char *lang);
void locale_set @ set(const char *lang, const char *key, const char *str); void locale_set @ set(const char *lang, const char *key, const char *str);
const char * locale_get @ get(const char *lang, const char *key); const char * locale_get @ get(const char *lang, const char *key);
int locale_direction @ direction(const char *lang, const char *str);
} }
} }

View File

@ -20,7 +20,6 @@ LUALIB_API int luaopen_locale (lua_State* tolua_S);
#undef tolua_reg_types #undef tolua_reg_types
#define tolua_reg_types tolua_reg_types_locale #define tolua_reg_types tolua_reg_types_locale
#include "bind_tolua.h"
#include "bind_locale.h" #include "bind_locale.h"
/* function to register type */ /* function to register type */
@ -113,6 +112,35 @@ static int tolua_locale_eressea_locale_get00(lua_State* tolua_S)
#endif #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 */ /* Open lib function */
LUALIB_API int luaopen_locale (lua_State* tolua_S) 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,"create",tolua_locale_eressea_locale_create00);
tolua_function(tolua_S,"set",tolua_locale_eressea_locale_set00); tolua_function(tolua_S,"set",tolua_locale_eressea_locale_set00);
tolua_function(tolua_S,"get",tolua_locale_eressea_locale_get00); 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); tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);