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/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/conf/e4/config.json b/conf/e4/config.json index b6a0e16ab..a32d7aab7 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -1,7 +1,8 @@ { "include": [ "keywords.json", - "e3/terrains.xml" + "prefixes.json", + "e3/terrains.json" ], "settings": { "game.id": 4, 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/conf/prefixes.json b/conf/prefixes.json new file mode 100644 index 000000000..afe6069a8 --- /dev/null +++ b/conf/prefixes.json @@ -0,0 +1,33 @@ +{ + "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", + "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/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/common.lua b/scripts/tests/common.lua index 8ca7e478e..decd0c14b 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1085,3 +1085,35 @@ 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")) + + 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 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/CMakeLists.txt b/src/CMakeLists.txt index e5a05ff8b..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 @@ -86,6 +87,7 @@ set (ERESSEA_SRC names.c lighthouse.c reports.c + prefix.c donations.c seen.c eressea.c @@ -197,6 +199,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/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/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 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/kernel/config.c b/src/kernel/config.c index 747bfad80..f31083130 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 */ 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/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 2fd8e3efe..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 @@ -77,6 +81,24 @@ 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); + CuAssertPtrNotNull(tc, race_prefixes); + CuAssertStrEquals(tc, "snow", race_prefixes[0]); + CuAssertStrEquals(tc, "dark", race_prefixes[2]); + CuAssertPtrEquals(tc, 0, race_prefixes[3]); + test_cleanup(); +} + static void test_races(CuTest * tc) { const char * data = "{\"races\": { \"orc\" : { " @@ -553,6 +575,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..b10825dbd 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" @@ -2051,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); @@ -2157,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); diff --git a/src/laws.c b/src/laws.c index 20dd6010a..fce556ec7 100755 --- a/src/laws.c +++ b/src/laws.c @@ -35,6 +35,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spy.h" #include "study.h" #include "wormhole.h" +#include "prefix.h" +#include "calendar.h" /* kernel includes */ #include @@ -42,7 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include @@ -846,38 +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); - } -} - -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. @@ -1278,11 +1247,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..."); @@ -1468,7 +1432,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/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/prefix.c b/src/prefix.c new file mode 100644 index 000000000..b6adb7c02 --- /dev/null +++ b/src/prefix.c @@ -0,0 +1,38 @@ +#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) +{ + 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 *)); + } + 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 new file mode 100644 index 000000000..9c5b84907 --- /dev/null +++ b/src/prefix.h @@ -0,0 +1,17 @@ +#pragma once + +#ifndef PREFIX_H +#define PREFIX_H + +#ifdef __cplusplus +extern "C" { +#endif + + void add_raceprefix(const char *); + char **race_prefixes; // zero-terminated array of valid prefixes + void free_prefixes(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/prefix.test.c b/src/prefix.test.c new file mode 100644 index 000000000..44c0d845d --- /dev/null +++ b/src/prefix.test.c @@ -0,0 +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/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 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); 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)); diff --git a/tests/data/inactive b/tests/data/inactive new file mode 100644 index 000000000..7e1d0e64e --- /dev/null +++ b/tests/data/inactive @@ -0,0 +1,2 @@ +c93c:Menschen:1:4 +c93c:Menschen:1:4 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