From 767ef13722f8a562b0c426fbcc0b4b59fb654f35 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:05:38 +0200 Subject: [PATCH 01/15] add a functional test for prefixes in E2 before refactoring any of that code. --- scripts/tests/e2/e2features.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index f5e40d42a..a80e6390e 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -335,3 +335,29 @@ function test_stonegolems() assert_equal(1 ,u2.number, "There shoud be one Stone Golems") -- end test Stone Golems four stones end + +local function set_order(u, str) + u:clear_orders() + u:add_order(str) +end + +function test_prefix() + local r0 = region.create(0, 0, "plain") + local f1 = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f1, r0, 1) + + set_order(u1, "PRAEFIX See") + process_orders() + assert_not_nil(u1:show():find("Seemensch")) + + u1.race = "elf" + assert_not_nil(u1:show():find("Seeelf")) + + set_order(u1, "PRAEFIX Mond") + process_orders() + assert_not_nil(u1:show():find("Mondelf")) + + set_order(u1, "PRAEFIX") + process_orders() + assert_not_nil(u1:show():find("Elf")) +end From f1476c21670fbffb8e40d3daac94cb6375f28707 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:24:10 +0200 Subject: [PATCH 02/15] refactoring: split out a module for race prefixes --- conf/prefix.json | 32 ++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 ++ src/kernel/jsonconf.test.c | 16 ++++++++++++++++ src/kernel/race.c | 16 ---------------- src/kernel/race.h | 3 --- src/kernel/xmlreader.c | 1 + src/laws.c | 1 + src/prefix.c | 21 +++++++++++++++++++++ src/prefix.h | 16 ++++++++++++++++ src/prefix.test.c | 9 +++++++++ src/test_eressea.c | 1 + 11 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 conf/prefix.json create mode 100644 src/prefix.c create mode 100644 src/prefix.h create mode 100644 src/prefix.test.c diff --git a/conf/prefix.json b/conf/prefix.json new file mode 100644 index 000000000..156bba332 --- /dev/null +++ b/conf/prefix.json @@ -0,0 +1,32 @@ +{ + "prefixes": [ + "Dunkel", + "Licht", + "Klein", + "Hoch", + "Huegel", + "Berg", + "Wald", + "Sumpf", + "Schnee", + "Sonnen", + "Mond", + "See", + "Tal", + "Schatten", + "Hoehlen", + "Blut", + "Wild", + "Chaos", + "Nacht", + "Nebel", + "Grau", + "Frost", + "Finster", + "Duester", + "flame", + "ice", + "star", + "black" + ] +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5a05ff8b..b2e9c5bfd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -86,6 +86,7 @@ set (ERESSEA_SRC names.c lighthouse.c reports.c + prefix.c donations.c seen.c eressea.c @@ -197,6 +198,7 @@ set(TESTS_SRC magic.test.c market.test.c move.test.c + prefix.test.c skill.test.c spells.test.c spy.test.c diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 2fd8e3efe..cdc396a31 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -77,6 +77,21 @@ static void test_settings(CuTest * tc) test_cleanup(); } +static void test_prefixes(CuTest * tc) +{ + const char * data = "{\"prefixes\": [ " + "\"snow\"," + "\"sea\"," + "\"dark\"" + "]}"; + cJSON *json = cJSON_Parse(data); + + test_cleanup(); + json_config(json); + // CuAssertStrEquals("dark", get_prefix("snow")); + test_cleanup(); +} + static void test_races(CuTest * tc) { const char * data = "{\"races\": { \"orc\" : { " @@ -553,6 +568,7 @@ CuSuite *get_jsonconf_suite(void) SUITE_ADD_TEST(suite, test_spells); SUITE_ADD_TEST(suite, test_flags); SUITE_ADD_TEST(suite, test_settings); + SUITE_ADD_TEST(suite, test_prefixes); SUITE_ADD_TEST(suite, test_infinitive_from_config); return suite; } diff --git a/src/kernel/race.c b/src/kernel/race.c index 155a1d326..748a5ee06 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -212,22 +212,6 @@ bool allowed_dragon(const region * src, const region * target) return allowed_fly(src, target); } -char **race_prefixes = NULL; - -extern void add_raceprefix(const char *prefix) -{ - static size_t size = 4; - static unsigned int next = 0; - if (race_prefixes == NULL) - race_prefixes = malloc(size * sizeof(char *)); - if (next + 1 == size) { - size *= 2; - race_prefixes = realloc(race_prefixes, size * sizeof(char *)); - } - race_prefixes[next++] = _strdup(prefix); - race_prefixes[next] = NULL; -} - bool r_insectstalled(const region * r) { return fval(r->terrain, ARCTIC_REGION); diff --git a/src/kernel/race.h b/src/kernel/race.h index b087825a6..0ae925c5d 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -249,9 +249,6 @@ extern "C" { extern bool r_insectstalled(const struct region *r); - extern void add_raceprefix(const char *); - extern char **race_prefixes; - extern void write_race_reference(const struct race *rc, struct storage *store); extern variant read_race_reference(struct storage *store); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 5d8f081cc..e46183cfe 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -28,6 +28,7 @@ without prior permission by the authors of Eressea. #include "spell.h" #include "spellbook.h" #include "calendar.h" +#include "prefix.h" #include "vortex.h" diff --git a/src/laws.c b/src/laws.c index 20dd6010a..7cd77bc96 100755 --- a/src/laws.c +++ b/src/laws.c @@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spy.h" #include "study.h" #include "wormhole.h" +#include "prefix.h" /* kernel includes */ #include diff --git a/src/prefix.c b/src/prefix.c new file mode 100644 index 000000000..d94dbb3dd --- /dev/null +++ b/src/prefix.c @@ -0,0 +1,21 @@ +#include "prefix.h" + +#include +#include +#include + +char **race_prefixes = NULL; + +void add_raceprefix(const char *prefix) +{ + static size_t size = 4; + static unsigned int next = 0; + if (race_prefixes == NULL) + race_prefixes = malloc(size * sizeof(char *)); + if (next + 1 == size) { + size *= 2; + race_prefixes = realloc(race_prefixes, size * sizeof(char *)); + } + race_prefixes[next++] = _strdup(prefix); + race_prefixes[next] = NULL; +} diff --git a/src/prefix.h b/src/prefix.h new file mode 100644 index 000000000..0b5bdcbe0 --- /dev/null +++ b/src/prefix.h @@ -0,0 +1,16 @@ +#pragma once + +#ifndef PREFIX_H +#define PREFIX_H + +#ifdef __cplusplus +extern "C" { +#endif + + void add_raceprefix(const char *); + char **race_prefixes; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/prefix.test.c b/src/prefix.test.c new file mode 100644 index 000000000..0ee02ec12 --- /dev/null +++ b/src/prefix.test.c @@ -0,0 +1,9 @@ +#include "prefix.h" + +#include + +CuSuite *get_prefix_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + return suite; +} \ No newline at end of file diff --git a/src/test_eressea.c b/src/test_eressea.c index bd72323b7..d5ab547ed 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -80,6 +80,7 @@ int RunAllTests(void) RUN_TESTS(suite, ally); RUN_TESTS(suite, messages); /* gamecode */ + RUN_TESTS(suite, prefix); RUN_TESTS(suite, battle); RUN_TESTS(suite, donations); RUN_TESTS(suite, travelthru); From 44d982d210685b00fd1d962788efe7ebc38f5b0d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:29:42 +0200 Subject: [PATCH 03/15] free race prefixes when the game is done (small memory leak). --- src/kernel/config.c | 2 ++ src/prefix.c | 11 +++++++++++ src/prefix.h | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 747bfad80..057c3efc0 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -74,6 +74,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "donations.h" +#include "prefix.h" #ifdef USE_LIBXML2 /* libxml includes */ @@ -1767,6 +1768,7 @@ void free_gamedata(void) free_units(); free_regions(); free_borders(); + free_prefixes(); for (i = 0; i != MAXLOCALES; ++i) { if (defaults[i]) { diff --git a/src/prefix.c b/src/prefix.c index d94dbb3dd..072e573ae 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -19,3 +19,14 @@ void add_raceprefix(const char *prefix) race_prefixes[next++] = _strdup(prefix); race_prefixes[next] = NULL; } + +void free_prefixes(void) { + int i; + if (race_prefixes) { + for (i = 0; race_prefixes[i]; ++i) { + free(race_prefixes[i]); + } + free(race_prefixes); + race_prefixes = 0; + } +} diff --git a/src/prefix.h b/src/prefix.h index 0b5bdcbe0..9c5b84907 100644 --- a/src/prefix.h +++ b/src/prefix.h @@ -8,7 +8,8 @@ extern "C" { #endif void add_raceprefix(const char *); - char **race_prefixes; + char **race_prefixes; // zero-terminated array of valid prefixes + void free_prefixes(void); #ifdef __cplusplus } From 9f6b37405625822552fd5c5b0f3cd2e71924ab53 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:33:25 +0200 Subject: [PATCH 04/15] add a (red) test for JSON prefixes. --- src/kernel/jsonconf.test.c | 9 ++++++++- src/prefix.c | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index cdc396a31..1547fde45 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -12,7 +12,11 @@ #include "spell.h" #include "order.h" #include "terrain.h" + +#include "prefix.h" + #include "util/language.h" + #include #include #include @@ -88,7 +92,10 @@ static void test_prefixes(CuTest * tc) test_cleanup(); json_config(json); - // CuAssertStrEquals("dark", get_prefix("snow")); + CuAssertPtrNotNull(tc, race_prefixes); + CuAssertStrEquals(tc, "snow", race_prefixes[0]); + CuAssertStrEquals(tc, "dark", race_prefixes[2]); + CuAssertPtrEquals(tc, 0, race_prefixes[3]); test_cleanup(); } diff --git a/src/prefix.c b/src/prefix.c index 072e573ae..ee9494e61 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -1,3 +1,4 @@ +#include #include "prefix.h" #include From f0e255924f0d3d088d5337dca3a8e6f2cb9b440f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:41:04 +0200 Subject: [PATCH 05/15] add a unit test for add/free prefixes. fix bad free_prefixes call site. --- src/kernel/config.c | 1 - src/laws.c | 2 +- src/prefix.test.c | 20 ++++++++++++++++++++ src/tests.c | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 057c3efc0..f31083130 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1768,7 +1768,6 @@ void free_gamedata(void) free_units(); free_regions(); free_borders(); - free_prefixes(); for (i = 0; i != MAXLOCALES; ++i) { if (defaults[i]) { diff --git a/src/laws.c b/src/laws.c index 7cd77bc96..1ca192f1a 100755 --- a/src/laws.c +++ b/src/laws.c @@ -1469,7 +1469,7 @@ static void init_prefixnames(void) in->next = pnames; in->lang = lang; - if (!exist) { + if (!exist && race_prefixes) { int key; for (key = 0; race_prefixes[key]; ++key) { variant var; diff --git a/src/prefix.test.c b/src/prefix.test.c index 0ee02ec12..44c0d845d 100644 --- a/src/prefix.test.c +++ b/src/prefix.test.c @@ -1,9 +1,29 @@ #include "prefix.h" +#include + +#include #include +static void test_add_prefix(CuTest *tc) { + test_cleanup(); + CuAssertPtrEquals(tc, 0, race_prefixes); + add_raceprefix("sea"); + CuAssertPtrNotNull(tc, race_prefixes); + CuAssertStrEquals(tc, "sea", race_prefixes[0]); + CuAssertPtrEquals(tc, 0, race_prefixes[1]); + add_raceprefix("moon"); + CuAssertStrEquals(tc, "sea", race_prefixes[0]); + CuAssertStrEquals(tc, "moon", race_prefixes[1]); + CuAssertPtrEquals(tc, 0, race_prefixes[2]); + free_prefixes(); + CuAssertPtrEquals(tc, 0, race_prefixes); + test_cleanup(); +} + CuSuite *get_prefix_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_add_prefix); return suite; } \ No newline at end of file diff --git a/src/tests.c b/src/tests.c index cda710ef7..e336c192a 100644 --- a/src/tests.c +++ b/src/tests.c @@ -2,6 +2,7 @@ #include "tests.h" #include "keyword.h" #include "seen.h" +#include "prefix.h" #include #include @@ -84,6 +85,7 @@ void test_cleanup(void) free_spellbooks(); free_gamedata(); free_seen(); + free_prefixes(); mt_clear(); if (!mt_find("missing_message")) { mt_register(mt_new_va("missing_message", "name:string", 0)); From 47c95aee358cd2b9bfccdb6ca9d31a53a7a9c46e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:49:12 +0200 Subject: [PATCH 06/15] implement JSON prefixes. fix free_prefixes not resetting size (TODO: quicklist). --- src/kernel/jsonconf.c | 17 +++++++++++++++++ src/prefix.c | 11 ++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index b9fe278b5..5fdd82e65 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -31,6 +31,9 @@ without prior permission by the authors of Eressea. #include "spellbook.h" #include "calendar.h" +/* game modules */ +#include "prefix.h" + /* util includes */ #include #include @@ -487,6 +490,17 @@ static void json_race(cJSON *json, race *rc) { } } +static void json_prefixes(cJSON *json) { + cJSON *child; + if (json->type != cJSON_Array) { + log_error("prefixes is not a json array: %d", json->type); + return; + } + for (child = json->child; child; child = child->next) { + add_raceprefix(child->valuestring); + } +} + static void json_terrains(cJSON *json) { cJSON *child; if (json->type != cJSON_Object) { @@ -837,6 +851,9 @@ void json_config(cJSON *json) { else if (strcmp(child->string, "spells") == 0) { json_spells(child); } + else if (strcmp(child->string, "prefixes") == 0) { + json_prefixes(child); + } else if (strcmp(child->string, "terrains") == 0) { json_terrains(child); init_terrains(); diff --git a/src/prefix.c b/src/prefix.c index ee9494e61..b6adb7c02 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -1,18 +1,23 @@ #include #include "prefix.h" +#include #include #include #include char **race_prefixes = NULL; +static size_t size = 4; +static unsigned int next = 0; void add_raceprefix(const char *prefix) { - static size_t size = 4; - static unsigned int next = 0; - if (race_prefixes == NULL) + assert(prefix); + if (race_prefixes == NULL) { + next = 0; + size = 4; race_prefixes = malloc(size * sizeof(char *)); + } if (next + 1 == size) { size *= 2; race_prefixes = realloc(race_prefixes, size * sizeof(char *)); From 13e1573611f3fc855b418049b1c0d08a95636753 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:54:09 +0200 Subject: [PATCH 07/15] moving the calendar module out of the kernel directory, it does not belong with the major game objects --- src/{kernel => }/calendar.c | 0 src/{kernel => }/calendar.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{kernel => }/calendar.c (100%) rename src/{kernel => }/calendar.h (100%) diff --git a/src/kernel/calendar.c b/src/calendar.c similarity index 100% rename from src/kernel/calendar.c rename to src/calendar.c diff --git a/src/kernel/calendar.h b/src/calendar.h similarity index 100% rename from src/kernel/calendar.h rename to src/calendar.h From 09efd9c2a985951d74f4965b75203d55a439d596 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:54:49 +0200 Subject: [PATCH 08/15] fix anything that uses the calendar module. opps. --- src/CMakeLists.txt | 1 + src/bindings.c | 2 +- src/economy.c | 2 +- src/gmtool.c | 2 +- src/kernel/CMakeLists.txt | 1 - src/laws.c | 2 +- src/move.c | 2 +- src/report.c | 2 +- src/summary.c | 2 +- 9 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b2e9c5bfd..0067463a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ TOLUA_BINDING(settings.pkg bind_settings.h) ENDIF() set (ERESSEA_SRC + calendar.c move.c spells.c battle.c diff --git a/src/bindings.c b/src/bindings.c index bc3accb69..c2f18d8d5 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -26,6 +26,7 @@ without prior permission by the authors of Eressea. #include "console.h" #include "reports.h" #include "seen.h" +#include "calendar.h" #include @@ -33,7 +34,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include diff --git a/src/economy.c b/src/economy.c index 7df3cd310..4aea89f80 100644 --- a/src/economy.c +++ b/src/economy.c @@ -32,10 +32,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "monster.h" #include "morale.h" #include "reports.h" +#include "calendar.h" /* kernel includes */ #include -#include #include #include #include diff --git a/src/gmtool.c b/src/gmtool.c index 3c0ad1136..dcdef8f45 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -18,6 +18,7 @@ #include "console.h" #include "listbox.h" #include "wormhole.h" +#include "calendar.h" #include #include @@ -30,7 +31,6 @@ #include #include -#include #include #include #include diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index bc2c20418..b1c3bcd0f 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -29,7 +29,6 @@ alliance.c ally.c build.c building.c -calendar.c command.c config.c connection.c diff --git a/src/laws.c b/src/laws.c index 1ca192f1a..c3e895757 100755 --- a/src/laws.c +++ b/src/laws.c @@ -36,6 +36,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "study.h" #include "wormhole.h" #include "prefix.h" +#include "calendar.h" /* kernel includes */ #include @@ -43,7 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/move.c b/src/move.c index 99e87c061..e1207f0fa 100644 --- a/src/move.c +++ b/src/move.c @@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include #include #include #include @@ -49,6 +48,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "direction.h" +#include "calendar.h" #include "skill.h" /* util includes */ diff --git a/src/report.c b/src/report.c index 998eab441..a48dd0150 100644 --- a/src/report.c +++ b/src/report.c @@ -41,13 +41,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" #include "upkeep.h" #include "vortex.h" +#include "calendar.h" /* kernel includes */ #include #include #include #include -#include #include #include #include diff --git a/src/summary.c b/src/summary.c index 43c540e55..f38839db0 100644 --- a/src/summary.c +++ b/src/summary.c @@ -15,9 +15,9 @@ #include "summary.h" #include "laws.h" #include "monster.h" +#include "calendar.h" #include -#include #include #include #include From 1b44e7332000f4f5c9fb152050f4bd9c2e48b451 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 13:35:59 +0200 Subject: [PATCH 09/15] remove prefixes.xml from E2 --- conf/e2/config.json | 1 + conf/e2/config.xml | 1 - conf/{prefix.json => prefixes.json} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename conf/{prefix.json => prefixes.json} (100%) diff --git a/conf/e2/config.json b/conf/e2/config.json index c8bedf2b3..946ddd1dc 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -1,6 +1,7 @@ { "include": [ "keywords.json", + "prefixes.json", "e2/terrains.json" ], "settings": { diff --git a/conf/e2/config.xml b/conf/e2/config.xml index cea730405..45870fded 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -16,7 +16,6 @@ - diff --git a/conf/prefix.json b/conf/prefixes.json similarity index 100% rename from conf/prefix.json rename to conf/prefixes.json From 3003b7fc6119902bba08423c2dbc791d6c9f9e07 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 13:37:43 +0200 Subject: [PATCH 10/15] remove prefixes from E3 move prefix test to common.lua --- conf/e3/config.json | 1 + conf/e3/config.xml | 1 - scripts/tests/common.lua | 26 ++++++++++++++++++++++++++ scripts/tests/e2/e2features.lua | 26 -------------------------- tests/data/inactive | 1 + 5 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 tests/data/inactive diff --git a/conf/e3/config.json b/conf/e3/config.json index d28dda80f..d831a0b3e 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -1,6 +1,7 @@ { "include": [ "keywords.json", + "prefixes.json", "e3/terrains.json" ], "settings": { diff --git a/conf/e3/config.xml b/conf/e3/config.xml index f1f403ecd..663b56d26 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -6,7 +6,6 @@ - diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 8ca7e478e..9c2549261 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1085,3 +1085,29 @@ function test_parser() os.remove(filename) assert_equal("Goldene Herde", u.name) end + +local function set_order(u, str) + u:clear_orders() + u:add_order(str) +end + +function test_prefix() + local r0 = region.create(0, 0, "plain") + local f1 = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f1, r0, 1) + + set_order(u1, "PRAEFIX See") + process_orders() + assert_not_nil(u1:show():find("Seemensch")) + + u1.race = "elf" + assert_not_nil(u1:show():find("Seeelf")) + + set_order(u1, "PRAEFIX Mond") + process_orders() + assert_not_nil(u1:show():find("Mondelf")) + + set_order(u1, "PRAEFIX") + process_orders() + assert_not_nil(u1:show():find("Elf")) +end diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index a80e6390e..f5e40d42a 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -335,29 +335,3 @@ function test_stonegolems() assert_equal(1 ,u2.number, "There shoud be one Stone Golems") -- end test Stone Golems four stones end - -local function set_order(u, str) - u:clear_orders() - u:add_order(str) -end - -function test_prefix() - local r0 = region.create(0, 0, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f1, r0, 1) - - set_order(u1, "PRAEFIX See") - process_orders() - assert_not_nil(u1:show():find("Seemensch")) - - u1.race = "elf" - assert_not_nil(u1:show():find("Seeelf")) - - set_order(u1, "PRAEFIX Mond") - process_orders() - assert_not_nil(u1:show():find("Mondelf")) - - set_order(u1, "PRAEFIX") - process_orders() - assert_not_nil(u1:show():find("Elf")) -end diff --git a/tests/data/inactive b/tests/data/inactive new file mode 100644 index 000000000..38dd0ad9a --- /dev/null +++ b/tests/data/inactive @@ -0,0 +1 @@ +c93c:Menschen:1:4 From c731edbfed1485732b931a8e966ae36b94a6bf01 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 13:38:31 +0200 Subject: [PATCH 11/15] remove prefixes.xml from E4, too --- conf/e4/config.json | 1 + conf/e4/config.xml | 1 - tests/data/inactive | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/e4/config.json b/conf/e4/config.json index b6a0e16ab..58ff28be4 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -1,6 +1,7 @@ { "include": [ "keywords.json", + "prefixes.json", "e3/terrains.xml" ], "settings": { diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 011f19821..2e68f6bf2 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -6,7 +6,6 @@ - diff --git a/tests/data/inactive b/tests/data/inactive index 38dd0ad9a..7e1d0e64e 100644 --- a/tests/data/inactive +++ b/tests/data/inactive @@ -1 +1,2 @@ c93c:Menschen:1:4 +c93c:Menschen:1:4 From aa32cf190ed11573b18352cc77c5117202dc63ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 13:40:10 +0200 Subject: [PATCH 12/15] remove xmlreader code for prefixes --- src/kernel/xmlreader.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index e46183cfe..b10825dbd 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -2052,38 +2052,6 @@ static int parse_strings(xmlDocPtr doc) return 0; } -static void -xml_readprefixes(xmlXPathContextPtr xpath, xmlNodePtr * nodeTab, int nodeNr, -bool names) -{ - int i; - - for (i = 0; i != nodeNr; ++i) { - xmlNodePtr node = nodeTab[i]; - xmlChar *propText = xmlNodeListGetString(node->doc, node->children, 1); - - if (propText != NULL) { - add_raceprefix((const char *)propText); - xmlFree(propText); - } - } -} - -static int parse_prefixes(xmlDocPtr doc) -{ - xmlXPathContextPtr xpath = xmlXPathNewContext(doc); - xmlXPathObjectPtr strings; - - /* reading eressea/strings/string */ - strings = xmlXPathEvalExpression(BAD_CAST "/eressea/prefixes/prefix", xpath); - xml_readprefixes(xpath, strings->nodesetval->nodeTab, - strings->nodesetval->nodeNr, false); - xmlXPathFreeObject(strings); - - xmlXPathFreeContext(xpath); - return 0; -} - static int parse_main(xmlDocPtr doc) { xmlXPathContextPtr xpath = xmlXPathNewContext(doc); @@ -2158,7 +2126,6 @@ void register_xmlreader(void) xml_register_callback(parse_main); xml_register_callback(parse_strings); - xml_register_callback(parse_prefixes); xml_register_callback(parse_messages); xml_register_callback(parse_resources); xml_register_callback(parse_rules); From 42f1030251c856c5ecfe675b6a28144b5e221809 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 14:10:08 +0200 Subject: [PATCH 13/15] separate test script for E4: even though it has mostly the same rules, it does not have xmastrees, and loads a different config remove dead `inactivefaction` function, we have no use for the file it creates. --- conf/e4/config.json | 2 +- s/runtests | 1 + scripts/run-tests-e2.lua | 1 + scripts/run-tests-e3.lua | 1 + scripts/run-tests-e4.lua | 23 +++++++++++++++++++++++ scripts/tests/e3/rules.lua | 21 --------------------- scripts/tests/xmas.lua | 20 ++++++++++++++++++++ src/laws.c | 23 ----------------------- tests/runtests.bat | 1 + 9 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 scripts/run-tests-e4.lua create mode 100644 scripts/tests/xmas.lua diff --git a/conf/e4/config.json b/conf/e4/config.json index 58ff28be4..a32d7aab7 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -2,7 +2,7 @@ "include": [ "keywords.json", "prefixes.json", - "e3/terrains.xml" + "e3/terrains.json" ], "settings": { "game.id": 4, diff --git a/s/runtests b/s/runtests index a0f50df1e..78c26eac0 100755 --- a/s/runtests +++ b/s/runtests @@ -19,6 +19,7 @@ cd $ROOT $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests.lua $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests-e2.lua $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests-e3.lua +$ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests-e4.lua rm -rf data reports orders.txt cd $OLDWPD diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 4a2b3e59e..84f5dc3f9 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -15,6 +15,7 @@ require 'eressea' require 'eressea.xmlconf' require 'eressea.path' require 'tests.e2' +require 'tests.xmas' require 'lunit' rules = require('eressea.' .. config.rules) diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 47bcca60b..1e48cd40e 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -15,6 +15,7 @@ require 'eressea' require 'eressea.path' require 'eressea.xmlconf' require 'tests.e3' +require 'tests.xmas' require 'lunit' eressea.settings.set("rules.alliances", "0") diff --git a/scripts/run-tests-e4.lua b/scripts/run-tests-e4.lua new file mode 100644 index 000000000..f827baec0 --- /dev/null +++ b/scripts/run-tests-e4.lua @@ -0,0 +1,23 @@ +-- Tests that work in E3. With game config of E3. +-- Tests are under scripts/test/e3 and all files must be in scripts/test/e3/init.lua + +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) +end +package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' + +config.rules = 'e4' + +require 'eressea' +require 'eressea.path' +require 'eressea.xmlconf' +require 'tests.e3' +require 'lunit' + +eressea.settings.set("rules.alliances", "0") +rules = require('eressea.' .. config.rules) +result = lunit.main() +return result.errors + result.failed diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 81bd1abe9..28b14fe10 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -199,27 +199,6 @@ function test_seecast() assert_equal(8, u2.region.x) end -local function use_tree(terrain) - local r = region.create(0,0, terrain) - local f = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f, r, 5) - r:set_resource("tree", 0) - u1:add_item("xmastree", 1) - u1:clear_orders() - u1:add_order("BENUTZEN 1 Weihnachtsbaum") - process_orders() - return r -end - -function test_xmastree() - local r - r = use_tree("ocean") - assert_equal(0, r:get_resource("tree")) - eressea.free_game() - r = use_tree("plain") - assert_equal(10, r:get_resource("tree")) -end - function test_fishing() eressea.settings.set("rules.food.flags", "0") local r = region.create(0,0, "ocean") diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua new file mode 100644 index 000000000..07df8dde8 --- /dev/null +++ b/scripts/tests/xmas.lua @@ -0,0 +1,20 @@ +local function use_tree(terrain) + local r = region.create(0,0, terrain) + local f = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f, r, 5) + r:set_resource("tree", 0) + u1:add_item("xmastree", 1) + u1:clear_orders() + u1:add_order("BENUTZEN 1 Weihnachtsbaum") + process_orders() + return r +end + +function test_xmastree() + local r + r = use_tree("ocean") + assert_equal(0, r:get_resource("tree")) + eressea.free_game() + r = use_tree("plain") + assert_equal(10, r:get_resource("tree")) +end diff --git a/src/laws.c b/src/laws.c index c3e895757..62c3a002a 100755 --- a/src/laws.c +++ b/src/laws.c @@ -861,24 +861,6 @@ static int modify(int i) } } -static void inactivefaction(faction * f) -{ - FILE *inactiveFILE; - char zText[128]; - - sprintf(zText, "%s/%s", datapath(), "inactive"); - inactiveFILE = fopen(zText, "a"); - - if (inactiveFILE) { - fprintf(inactiveFILE, "%s:%s:%d:%d\n", - factionid(f), - LOC(default_locale, rc_name_s(f->race, NAME_PLURAL)), - modify(count_all(f)), turn - f->lastorders); - - fclose(inactiveFILE); - } -} - /* test if the unit can slip through a siege undetected. * returns 0 if siege is successful, or 1 if the building is either * not besieged or the unit can slip through the siege due to better stealth. @@ -1279,11 +1261,6 @@ static void remove_idle_players(void) sprintf(info, "%d Einheiten, %d Personen, %d Silber", f->no_units, f->num_total, f->money); } - - if (NMRTimeout() > 0 && turn - f->lastorders >= (NMRTimeout() - 1)) { - inactivefaction(f); - continue; - } } log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben..."); diff --git a/tests/runtests.bat b/tests/runtests.bat index 3bb41c982..e070bac2d 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -5,5 +5,6 @@ SET SERVER=%BUILD%\eressea.exe %SERVER% ..\scripts\run-tests.lua %SERVER% ..\scripts\run-tests-e2.lua %SERVER% ..\scripts\run-tests-e3.lua +%SERVER% ..\scripts\run-tests-e4.lua PAUSE RMDIR /s /q reports From bd1b568da278d8d12a7252ca9ad3b7be6799529c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 14:13:45 +0200 Subject: [PATCH 14/15] =?UTF-8?q?Pr=C3=A4fix=20Erz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/prefixes.json | 3 ++- res/core/de/strings.xml | 5 +++++ scripts/tests/common.lua | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/conf/prefixes.json b/conf/prefixes.json index 156bba332..afe6069a8 100644 --- a/conf/prefixes.json +++ b/conf/prefixes.json @@ -27,6 +27,7 @@ "flame", "ice", "star", - "black" + "black", + "arch" ] } diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index d008a17ff..1e5dbb034 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -6833,6 +6833,11 @@ black + + Erz + arch + + Sternen star diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 9c2549261..decd0c14b 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1110,4 +1110,10 @@ function test_prefix() set_order(u1, "PRAEFIX") process_orders() assert_not_nil(u1:show():find("Elf")) + + set_order(u1, "PRAEFIX Erz") + process_orders() + assert_not_nil(u1:show():find("Erzelf")) + u1.faction.locale = "en" + assert_not_nil(u1:show():find("archelf")) end From 9563aa712fe2546e51ec9cc42e9187f5526743a4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 14:16:18 +0200 Subject: [PATCH 15/15] eliminate junk function --- src/laws.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/laws.c b/src/laws.c index 62c3a002a..fce556ec7 100755 --- a/src/laws.c +++ b/src/laws.c @@ -847,20 +847,6 @@ void demographics(void) /* ------------------------------------------------------------- */ -static int modify(int i) -{ - int c; - - c = i * 2 / 3; - - if (c >= 1) { - return (c + rng_int() % c); - } - else { - return (i); - } -} - /* test if the unit can slip through a siege undetected. * returns 0 if siege is successful, or 1 if the building is either * not besieged or the unit can slip through the siege due to better stealth.