From 8edafa19c5b7a98658f5502c98264ad77c42f483 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 20:39:36 +0100 Subject: [PATCH 1/3] fix faction.create locale handling --- scripts/run-tests-e2.lua | 2 +- src/bind_faction.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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/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; From 293190703fbc6fddd3025fc68c791cca5e71f0d1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 21:10:39 +0100 Subject: [PATCH 2/3] make maximum number of people transferred to a faction configurable make E2 transfers basically unlimited. --- conf/e2/config.xml | 1 + src/give.c | 9 ++++++--- src/give.test.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) 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/src/give.c b/src/give.c index 7b9d2a3fb..22f05f34c 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() { + 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); From 4d18fe68f8144a85e40194655909b0642dec449d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 21:56:18 +0100 Subject: [PATCH 3/3] gcc language purity complaint. --- src/give.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/give.c b/src/give.c index 22f05f34c..d875dc34a 100644 --- a/src/give.c +++ b/src/give.c @@ -51,7 +51,7 @@ #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() { +static int max_transfers(void) { return get_param_int(global.parameters, "rules.give.max_men", 5); }