make maximum number of people transferred to a faction configurable

make E2 transfers basically unlimited.
This commit is contained in:
Enno Rehling 2015-03-13 21:10:39 +01:00
parent 8edafa19c5
commit 293190703f
3 changed files with 38 additions and 3 deletions

View File

@ -94,6 +94,7 @@
<param name="hunger.long" value="1"/>
<param name="init_spells" value="0"/>
<param name="rules.reserve.twophase" value="1"/>
<param name="rules.give.max_men" value="10000"/>
<param name="rules.check_overload" value="0"/>
<param name="rules.limit.faction" value="2500"/>
<param name="rules.maxskills.magic" value="5"/>

View File

@ -48,10 +48,13 @@
#include <stdlib.h>
/* 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;
}

View File

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