From 9ba255e269a57156ac90dd2c587e4491571200a6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Mar 2018 19:07:05 +0100 Subject: [PATCH] allow a maxnmr setting in eressea.ini to override the nmr.timeout rule. --- src/laws.c | 10 +++++++++- src/laws.test.c | 15 +++++++++++++++ src/main.c | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/laws.c b/src/laws.c index f4f0f24ee..cf8f2668f 100644 --- a/src/laws.c +++ b/src/laws.c @@ -141,7 +141,15 @@ bool IsImmune(const faction * f) int NMRTimeout(void) { - return config_get_int("nmr.timeout", 0); + int nmr_timeout = config_get_int("nmr.timeout", 0); + int ini_timeout = config_get_int("game.maxnmr", 0); + if (nmr_timeout > 0) { + if (ini_timeout > nmr_timeout) { + return nmr_timeout; + } + return (ini_timeout > 0) ? ini_timeout : nmr_timeout; + } + return ini_timeout; } bool LongHunger(const struct unit *u) diff --git a/src/laws.test.c b/src/laws.test.c index edfdd6f4c..f9b4cfcf3 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1745,6 +1745,20 @@ static void test_cansee_sphere(CuTest *tc) { test_teardown(); } +static void test_nmr_timeout(CuTest *tc) { + test_setup(); + CuAssertIntEquals(tc, 0, NMRTimeout()); + config_set_int("nmr.timeout", 5); + CuAssertIntEquals(tc, 5, NMRTimeout()); + config_set_int("game.maxnmr", 4); + CuAssertIntEquals(tc, 4, NMRTimeout()); + config_set("nmr.timeout", NULL); + CuAssertIntEquals(tc, 4, NMRTimeout()); + config_set("game.maxnmr", NULL); + CuAssertIntEquals(tc, 0, NMRTimeout()); + test_teardown(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -1816,6 +1830,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_cansee); SUITE_ADD_TEST(suite, test_cansee_ring); SUITE_ADD_TEST(suite, test_cansee_sphere); + SUITE_ADD_TEST(suite, test_nmr_timeout); return suite; } diff --git a/src/main.c b/src/main.c index b2fb23a96..d337c29fc 100644 --- a/src/main.c +++ b/src/main.c @@ -83,6 +83,7 @@ static void load_inifile(void) static const char * valid_keys[] = { "game.id", "game.deadlog", + "game.maxnmr", "game.name", "game.start", "game.locale", @@ -257,7 +258,7 @@ static int parse_args(int argc, char **argv) return 0; } -#if defined(HAVE_BACKTRACE) +#ifdef HAVE_BACKTRACE #include #include