From 293190703fbc6fddd3025fc68c791cca5e71f0d1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 21:10:39 +0100 Subject: [PATCH] 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);