Merge pull request #157 from badgerman/develop

Make transfer of people configurable, and free in E2
This commit is contained in:
Enno Rehling 2015-03-13 22:13:07 +01:00
commit fdc58f0b8b
5 changed files with 42 additions and 7 deletions

View File

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

View File

@ -5,7 +5,7 @@ path = 'scripts'
if config.install then if config.install then
path = config.install .. '/' .. path path = config.install .. '/' .. path
package.path = package.path .. ';' .. config.install .. '/lunit/?.lua' 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 end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'

View File

@ -344,14 +344,14 @@ static int tolua_faction_create(lua_State * L)
const char *email = tolua_tostring(L, 1, 0); const char *email = tolua_tostring(L, 1, 0);
const char *racename = tolua_tostring(L, 2, 0); const char *racename = tolua_tostring(L, 2, 0);
const char *lang = tolua_tostring(L, 3, 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; faction *f = NULL;
const struct race *frace = rc_find(racename); const struct race *frace = rc_find(racename ? racename : "human");
if (frace != NULL) { if (frace != NULL) {
f = addfaction(email, NULL, frace, loc, 0); f = addfaction(email, NULL, frace, loc, 0);
} }
if (!f) { 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"); tolua_pushusertype(L, f, TOLUA_CAST "faction");
return 1; return 1;

View File

@ -48,10 +48,13 @@
#include <stdlib.h> #include <stdlib.h>
/* Wieviel Fremde eine Partei pro Woche aufnehmen kangiven */ /* 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_DONATIONS /* shall we reserve objects given to us by other factions? */
#define RESERVE_GIVE /* reserve anything that's given from one unit to another? */ #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 GiveRestriction(void)
{ {
static int value = -1; static int value = -1;
@ -300,7 +303,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord)
error = 96; error = 96;
} }
else if (u->faction != u2->faction) { else if (u->faction != u2->faction) {
if (u2->faction->newbies + n > MAXNEWBIES) { if (u2->faction->newbies + n > max_transfers()) {
error = 129; error = 129;
} }
else if (u_race(u) != u2->faction->race) { 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); cmistake(u, ord, 105, MSG_COMMERCE);
return; return;
} }
if (u2->faction->newbies + n > MAXNEWBIES) { if (u2->faction->newbies + n > max_transfers()) {
cmistake(u, ord, 129, MSG_COMMERCE); cmistake(u, ord, 129, MSG_COMMERCE);
return; return;
} }

View File

@ -72,6 +72,36 @@ static void test_give_men(CuTest * tc) {
test_cleanup(); 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) { static void test_give_men_in_ocean(CuTest * tc) {
struct give env; struct give env;
message * msg; message * msg;
@ -247,6 +277,7 @@ CuSuite *get_give_suite(void)
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_give); SUITE_ADD_TEST(suite, test_give);
SUITE_ADD_TEST(suite, test_give_men); 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_in_ocean);
SUITE_ADD_TEST(suite, test_give_men_none); SUITE_ADD_TEST(suite, test_give_men_none);
SUITE_ADD_TEST(suite, test_give_men_too_many); SUITE_ADD_TEST(suite, test_give_men_too_many);