diff --git a/CMakeLists.txt b/CMakeLists.txt index aaf07e2a1..7cfd54e3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ CHECK_SYMBOL_EXISTS (sleep "unistd.h" HAVE_SLEEP) CHECK_SYMBOL_EXISTS (usleep "unistd.h" HAVE_USLEEP) CHECK_SYMBOL_EXISTS (access "unistd.h" HAVE_ACCESS) ENDIF(HAVE_UNISTD_H) +CHECK_SYMBOL_EXISTS (strlcpy "string.h" HAVE_STRLCPY) +CHECK_SYMBOL_EXISTS (strlcat "string.h" HAVE_STRLCAT) +CHECK_SYMBOL_EXISTS (slprintf "string.h" HAVE_SLPRINTF) CHECK_SYMBOL_EXISTS (strcasecmp "string.h" HAVE_STRCASECMP) CHECK_SYMBOL_EXISTS (strncasecmp "string.h" HAVE_STRNCASECMP) CHECK_SYMBOL_EXISTS (_strlwr "string.h" HAVE__STRLWR) diff --git a/autoconf.h.in b/autoconf.h.in index 5144d9ecc..1c151b6f9 100644 --- a/autoconf.h.in +++ b/autoconf.h.in @@ -26,6 +26,9 @@ #cmakedefine HAVE_MEMICMP 1 #cmakedefine HAVE__STRLWR 1 #cmakedefine HAVE_STRLWR 1 +#cmakedefine HAVE_STRLCPY 1 +#cmakedefine HAVE_STRLCAT 1 +#cmakedefine HAVE_SLPRINTF 1 #cmakedefine HAVE_SYS_STAT_MKDIR 1 #cmakedefine HAVE_DIRECT_MKDIR 1 #cmakedefine HAVE_DIRECT__MKDIR 1 diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 170621b48..980671bcf 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -94,6 +94,7 @@ + diff --git a/res/core/common/items.xml b/res/core/common/items.xml index 9508653e7..c8910e695 100644 --- a/res/core/common/items.xml +++ b/res/core/common/items.xml @@ -2,7 +2,7 @@ - + diff --git a/s/build b/s/build index 40ab81283..068a669a1 100755 --- a/s/build +++ b/s/build @@ -1,7 +1,7 @@ #!/bin/sh -ROOT=$(pwd) +ROOT=`pwd` while [ ! -d $ROOT/.git ]; do - ROOT=$(dirname $ROOT) + ROOT=`dirname $ROOT` done [ -z $BUILD ] && BUILD=Debug @@ -11,7 +11,7 @@ MACHINE=`uname -m` [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" BIN_DIR="build-$MACHINE-$CC-$BUILD" -[ -z "$JOBS" ] && JOBS=$(nproc) +[ -z "$JOBS" ] && [ "" != "which nproc" ] && JOBS=`nproc` DISTCC=`which distcc` if [ ! -z "$DISTCC" ] ; then JOBS=`distcc -j` diff --git a/scripts/config.lua b/scripts/config.lua index 1251c1e1c..8b61bcad2 100644 --- a/scripts/config.lua +++ b/scripts/config.lua @@ -4,5 +4,5 @@ if config.install then end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' require 'eressea' -require 'eressea.xmlconf' -return require('eressea.rules') +require 'eressea.xmlconf' -- read xml data + diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua index f5575428b..da0c60eb1 100644 --- a/scripts/eressea/wedding.lua +++ b/scripts/eressea/wedding.lua @@ -45,7 +45,7 @@ function wedding.update() if peacegate and hellgate then wedding_exchange(peacegate, hellgate) else - eressea.log.error("hellgate or peacegate not found!", hellgate, peacegate) + eressea.log.error("hellgate or peacegate not found!") end end diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index aff15eb06..9f08b0f54 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -5,7 +5,7 @@ path = 'scripts' if config.install then path = config.install .. '/' .. path package.path = package.path .. ';' .. config.install .. '/lunit/?.lua' - --needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) + --needed to find lunit if not run from eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index ca6206419..62bbd8758 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -712,7 +712,7 @@ function test_golem_use_four_iron() assert_equal(4, u1:get_item("towershield")) end -function skip_test_silver_weight_stops_movement() +function test_silver_weight_stops_movement() local r1 = region.create(1, 1, "plain") local r2 = region.create(2, 1, "plain") region.create(3, 1, "plain") @@ -729,7 +729,7 @@ function skip_test_silver_weight_stops_movement() assert_equal(r2, u1.region) end -function skip_test_silver_weight_stops_ship() +function test_silver_weight_stops_ship() local r1 = region.create(1, 1, "ocean") local r2 = region.create(2, 1, "ocean") region.create(3, 1, "ocean") @@ -771,15 +771,6 @@ function test_building_owner_can_enter_ship() assert_equal(null, u1.building, "owner of the building can not go into a ship") end -function test_weightless_silver() - local r1 = region.create(1, 2, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f1, r1, 1) - assert_equal(1000, u1.weight) - u1:add_item("money", 540) - assert_equal(1000, u1.weight) -end - function test_only_building_owner_can_set_not_paid() local r = region.create(0, 0, "plain") local f = faction.create("noreply@eressea.de", "human", "de") diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index a6265cde9..f0cd9335c 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -5,7 +5,15 @@ module ('tests.eressea.faction', package.seeall, lunit.testcase) local f function setup() + conf = [[{ + "races": { + "human" : {} + } + }]] + eressea.config.reset() + assert(eressea.config.parse(conf)==0) f = faction.create("faction@eressea.de", "human", "de") + assert(f~=nil) end function test_faction_flags() diff --git a/src/bind_faction.c b/src/bind_faction.c index df89f9d5a..cfe57ebb4 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -344,14 +344,14 @@ static int tolua_faction_create(lua_State * L) const char *email = tolua_tostring(L, 1, 0); const char *racename = tolua_tostring(L, 2, 0); const char *lang = tolua_tostring(L, 3, 0); - struct locale *loc = get_locale(lang); + struct locale *loc = lang ? get_locale(lang) : default_locale; faction *f = NULL; - const struct race *frace = rc_find(racename); + const struct race *frace = rc_find(racename ? racename : "human"); if (frace != NULL) { f = addfaction(email, NULL, frace, loc, 0); } if (!f) { - log_error("faction.create(%s, %s, %s)\n", email, racename, lang); + log_error("faction.create(%s, %s, %s)\n", email, frace->_name, locale_name(loc)); } tolua_pushusertype(L, f, TOLUA_CAST "faction"); return 1; diff --git a/src/give.c b/src/give.c index 7b9d2a3fb..d875dc34a 100644 --- a/src/give.c +++ b/src/give.c @@ -48,10 +48,13 @@ #include /* Wieviel Fremde eine Partei pro Woche aufnehmen kangiven */ -#define MAXNEWBIES 5 #define RESERVE_DONATIONS /* shall we reserve objects given to us by other factions? */ #define RESERVE_GIVE /* reserve anything that's given from one unit to another? */ +static int max_transfers(void) { + return get_param_int(global.parameters, "rules.give.max_men", 5); +} + static int GiveRestriction(void) { static int value = -1; @@ -300,7 +303,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) error = 96; } else if (u->faction != u2->faction) { - if (u2->faction->newbies + n > MAXNEWBIES) { + if (u2->faction->newbies + n > max_transfers()) { error = 129; } else if (u_race(u) != u2->faction->race) { @@ -473,7 +476,7 @@ void give_unit(unit * u, unit * u2, order * ord) cmistake(u, ord, 105, MSG_COMMERCE); return; } - if (u2->faction->newbies + n > MAXNEWBIES) { + if (u2->faction->newbies + n > max_transfers()) { cmistake(u, ord, 129, MSG_COMMERCE); return; } diff --git a/src/give.test.c b/src/give.test.c index 5437dfa5b..f1b13011d 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -72,6 +72,36 @@ static void test_give_men(CuTest * tc) { test_cleanup(); } +static void test_give_men_limit(CuTest * tc) { + struct give env; + message *msg; + test_cleanup(); + env.f2 = test_create_faction(0); + env.f1 = test_create_faction(0); + setup_give(&env); + set_param(&global.parameters, "rules.give.max_men", "1"); + + /* below the limit, give men, increase newbies counter */ + usetcontact(env.dst, env.src); + msg = give_men(1, env.src, env.dst, NULL); + CuAssertStrEquals(tc, "give_person", (const char *)msg->parameters[0].v); + CuAssertIntEquals(tc, 2, env.dst->number); + CuAssertIntEquals(tc, 0, env.src->number); + CuAssertIntEquals(tc, 1, env.f2->newbies); + msg_release(msg); + + /* beyond the limit, do nothing */ + usetcontact(env.src, env.dst); + msg = give_men(2, env.dst, env.src, NULL); + CuAssertStrEquals(tc, "error129", (const char *)msg->parameters[3].v); + CuAssertIntEquals(tc, 2, env.dst->number); + CuAssertIntEquals(tc, 0, env.src->number); + CuAssertIntEquals(tc, 0, env.f1->newbies); + msg_release(msg); + + test_cleanup(); +} + static void test_give_men_in_ocean(CuTest * tc) { struct give env; message * msg; @@ -247,6 +277,7 @@ CuSuite *get_give_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_give); SUITE_ADD_TEST(suite, test_give_men); + SUITE_ADD_TEST(suite, test_give_men_limit); SUITE_ADD_TEST(suite, test_give_men_in_ocean); SUITE_ADD_TEST(suite, test_give_men_none); SUITE_ADD_TEST(suite, test_give_men_too_many); diff --git a/src/kernel/config.h b/src/kernel/config.h index a10186e6d..caffedb9e 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -81,7 +81,6 @@ extern "C" { #define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */ #define NAMESIZE 128 /* max. Länge eines Namens, incl trailing 0 */ #define IDSIZE 16 /* max. Länge einer no (als String), incl trailing 0 */ -#define KEYWORDSIZE 16 /* max. Länge eines Keyword, incl trailing 0 */ #define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. Länge der Strings, die * von struct unitname, etc. zurückgegeben werden. ohne die 0 */ diff --git a/src/kernel/region.c b/src/kernel/region.c index 7f5d65ef6..807fb3d76 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -611,8 +611,8 @@ int rpeasants(const region * r) void rsetpeasants(region * r, int value) { - ((r)->land ? ((r)->land->peasants = - (value)) : (assert((value) >= 0), (value)), 0); + if (r->land) r->land->peasants = value; + else assert(value>=0); } int rmoney(const region * r) @@ -634,8 +634,8 @@ int rhorses(const region * r) void rsetmoney(region * r, int value) { - ((r)->land ? ((r)->land->money = - (value)) : (assert((value) >= 0), (value)), 0); + if (r->land) r->land->money = value; + else assert(value >= 0); } void r_setdemand(region * r, const luxury_type * ltype, int value) diff --git a/src/keyword.c b/src/keyword.c index fde981bb9..1ffdc4c3c 100644 --- a/src/keyword.c +++ b/src/keyword.c @@ -12,7 +12,7 @@ const char * keyword(keyword_t kwd) { - static char result[KEYWORDSIZE]; // FIXME: static return value + static char result[32]; // FIXME: static return value if (!result[0]) { strcpy(result, "keyword::"); } diff --git a/src/spells.c b/src/spells.c index 82aca3720..0826c7edf 100644 --- a/src/spells.c +++ b/src/spells.c @@ -545,7 +545,7 @@ static int sp_summon_familiar(castorder * co) cmistake(mage, co->order, 199, MSG_MAGIC); return 0; } - rc = select_familiar(mage->faction->race, mage->faction->magiegebiet); + rc = select_familiar(mage->_race, mage->faction->magiegebiet); if (rc == NULL) { log_error("could not find suitable familiar for %s.\n", mage->faction->race->_name); return 0;