Merge branch 'master' of github.com:eressea/server

This commit is contained in:
Enno Rehling 2015-12-26 14:40:21 +01:00
commit e574919555
24 changed files with 300 additions and 194 deletions

View File

@ -51,13 +51,13 @@
</string>
<string name="newbie_info_1">
<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
eressea-server@eressea.de with the subject E3 ORDERS.</text>
</string>
<string name="mailcmd">
<text locale="de">E3 BEFEHLE</text>
<text locale="en">E3 ORDERS</text>
<text locale="de">ERESSEA 3 BEFEHLE</text>
<text locale="en">ERESSEA 3 ORDERS</text>
</string>
<string name="defaultorder">
<text locale="de">ARBEITEN</text>

View File

@ -1581,6 +1581,14 @@
<text locale="de">Schneemann</text>
<text locale="en">snowman</text>
</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">
<text locale="de">Schneemänner</text>
<text locale="en">snowmen</text>

View File

@ -1,5 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<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">
<type>
<arg name="unit" type="unit"/>

View File

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

View File

@ -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'),

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,3 +11,4 @@ require 'tests.common'
require 'tests.storage'
require 'tests.magicbag'
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 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)

View File

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

View File

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

View File

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

View File

@ -19,6 +19,7 @@ without prior permission by the authors of Eressea.
#include <util/bsdstring.h>
#include <util/functions.h>
#include <util/log.h>
#include <util/parser.h>
#include <util/resolve.h>
#include <kernel/config.h>
@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

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