From 5dcbb8a3f423a07b4ed600b0e52328ea5853fdc8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Aug 2016 10:28:09 +0200 Subject: [PATCH 001/271] add a very simple tst for unicode comparisons --- src/util/unicode.test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/util/unicode.test.c b/src/util/unicode.test.c index 958b695e2..3aff3a3a3 100644 --- a/src/util/unicode.test.c +++ b/src/util/unicode.test.c @@ -16,9 +16,17 @@ static void test_unicode_tolower(CuTest * tc) CuAssertStrEquals(tc, "helloX", buffer); } +static void test_unicode_compare(CuTest *tc) +{ + CuAssertIntEquals(tc, 0, unicode_utf8_strcasecmp("ABCDEFG", "abcdefg")); + CuAssertIntEquals(tc, 0, unicode_utf8_strcasecmp("abcdefg123", "ABCDEFG123")); + CuAssertIntEquals(tc, 1, unicode_utf8_strcasecmp("bacdefg123", "ABCDEFG123")); +} + CuSuite *get_unicode_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_unicode_tolower); + SUITE_ADD_TEST(suite, test_unicode_compare); return suite; } From 2de3c3179a1be88f83e0415187f23976791ab866 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 28 Nov 2016 08:39:07 +0100 Subject: [PATCH 002/271] develop branch is now base for 3.11 --- src/kernel/version.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/version.c b/src/kernel/version.c index 6de6ddb40..8add29ccc 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -5,7 +5,7 @@ #ifndef ERESSEA_VERSION // the version number, if it was not passed to make with -D -#define ERESSEA_VERSION "3.10.0-devel" +#define ERESSEA_VERSION "3.11.0-devel" #endif const char *eressea_version(void) { From 752b6526bd8a7bb77668ef285a4ff00791007358 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 19 Dec 2016 20:55:36 +0100 Subject: [PATCH 003/271] replace submodules --- .gitmodules | 9 +++------ clibs | 1 + critbit | 1 - quicklist | 1 - 4 files changed, 4 insertions(+), 8 deletions(-) create mode 160000 clibs delete mode 160000 critbit delete mode 160000 quicklist diff --git a/.gitmodules b/.gitmodules index 2242a8068..e9ea1e3ed 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,12 +4,6 @@ [submodule "cmake"] path = cmake url = https://github.com/ennorehling/cmake.git -[submodule "quicklist"] - path = quicklist - url = https://github.com/ennorehling/quicklist.git -[submodule "critbit"] - path = critbit - url = https://github.com/ennorehling/critbit.git [submodule "dlmalloc"] path = dlmalloc url = https://github.com/ennorehling/dlmalloc.git @@ -26,3 +20,6 @@ path = storage url = https://github.com/ennorehling/storage.git branch = master +[submodule "clibs"] + path = clibs + url = https://github.com/ennorehling/clibs diff --git a/clibs b/clibs new file mode 160000 index 000000000..f44b3e4e5 --- /dev/null +++ b/clibs @@ -0,0 +1 @@ +Subproject commit f44b3e4e5f08633e21e701b9af70927b707f38ab diff --git a/critbit b/critbit deleted file mode 160000 index 971836241..000000000 --- a/critbit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 971836241277e37274aa3110344836499816ff21 diff --git a/quicklist b/quicklist deleted file mode 160000 index f837dd31e..000000000 --- a/quicklist +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f837dd31e5fcf13c706db1ac2c86b7de3e706578 From 20fe039b1622e05b55563019c6c0f54afba86606 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 19 Dec 2016 21:35:02 +0100 Subject: [PATCH 004/271] use joint clibs directory instead of quicklist/critbit. --- CMakeLists.txt | 3 +-- clibs | 2 +- src/CMakeLists.txt | 9 +++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d60d3d721..cc7e8173d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,8 +68,7 @@ add_subdirectory (cutest) add_subdirectory (cJSON) add_subdirectory (storage) add_subdirectory (iniparser) -add_subdirectory (quicklist) -add_subdirectory (critbit) +add_subdirectory (clibs) add_subdirectory (process) add_subdirectory (src eressea) install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.xml") diff --git a/clibs b/clibs index f44b3e4e5..67e60390a 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f44b3e4e5f08633e21e701b9af70927b707f38ab +Subproject commit 67e60390a2e324c4b0a015bda3ca9a956c98343f diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a4445b55..ea76d4dbb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,10 +2,9 @@ cmake_minimum_required(VERSION 2.8) project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${CRITBIT_INCLUDE_DIR}) include_directories (${CJSON_INCLUDE_DIR}) +include_directories (${CLIBS_INCLUDE_DIR}) include_directories (${STORAGE_INCLUDE_DIR}) -include_directories (${QUICKLIST_INCLUDE_DIR}) include_directories (${CUTEST_INCLUDE_DIR}) include_directories (${LUA_INCLUDE_DIR}) include_directories (${TOLUA_INCLUDE_DIR}) @@ -181,9 +180,8 @@ target_link_libraries(eressea game ${TOLUA_LIBRARIES} ${LUA_LIBRARIES} - ${QUICKLIST_LIBRARIES} ${STORAGE_LIBRARIES} - ${CRITBIT_LIBRARIES} + ${CLIBS_LIBRARIES} ${CJSON_LIBRARIES} ${INIPARSER_LIBRARIES} ) @@ -239,9 +237,8 @@ target_link_libraries(test_eressea game ${CUTEST_LIBRARIES} ${LUA_LIBRARIES} - ${QUICKLIST_LIBRARIES} + ${CLIBS_LIBRARIES} ${STORAGE_LIBRARIES} - ${CRITBIT_LIBRARIES} ${CJSON_LIBRARIES} ${INIPARSER_LIBRARIES} ) From 2f52c226f0a2d9a01f98a2aabacda0bd593b28ab Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 22 Dec 2016 07:07:06 +0100 Subject: [PATCH 005/271] clibs MSVC compilation --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index 67e60390a..bce9b6568 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 67e60390a2e324c4b0a015bda3ca9a956c98343f +Subproject commit bce9b6568d4e9ace26c95a7740140cd71029b21f From cc227fb7070b9877c130061ba882c26794751eef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 23 Dec 2016 18:05:38 +0100 Subject: [PATCH 006/271] merge monster.c and monsters.c move RCF_DESERT handling to monsters.c --- src/CMakeLists.txt | 1 - src/battle.c | 2 +- src/bind_monsters.c | 1 - src/bindings.c | 2 +- src/chaos.c | 2 +- src/economy.c | 2 +- src/guard.c | 2 +- src/guard.test.c | 2 +- src/kernel/faction.test.c | 2 +- src/laws.c | 2 +- src/laws.test.c | 2 +- src/monster.c | 224 -------------------------------------- src/monster.h | 39 ------- src/monsters.c | 193 +++++++++++++++++++++++++++++++- src/monsters.h | 49 ++++++++- src/monsters.test.c | 1 - src/move.c | 2 +- src/races/zombies.c | 2 +- src/randenc.c | 19 +--- src/report.c | 2 +- src/spells.c | 2 +- src/study.c | 2 +- src/summary.c | 2 +- src/teleport.c | 2 +- src/upkeep.c | 2 +- 25 files changed, 249 insertions(+), 312 deletions(-) delete mode 100644 src/monster.c delete mode 100644 src/monster.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a4445b55..81a43e002 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,7 +114,6 @@ set (ERESSEA_SRC magic.c market.c morale.c - monster.c randenc.c renumber.c volcano.c diff --git a/src/battle.c b/src/battle.c index 7aa3e4cfa..ed83871ec 100644 --- a/src/battle.c +++ b/src/battle.c @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "chaos.h" #include "guard.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include "skill.h" diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 3e3f24bee..d7a3daab2 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,6 +1,5 @@ #include #include "spells/shipcurse.h" -#include "monster.h" #include "monsters.h" #include diff --git a/src/bindings.c b/src/bindings.c index aa2e177c1..f17ccc3a1 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -54,7 +54,7 @@ without prior permission by the authors of Eressea. #include "summary.h" #include "teleport.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include "market.h" #include diff --git a/src/chaos.c b/src/chaos.c index 942fb87bc..58cd7af73 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -19,7 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "chaos.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include diff --git a/src/economy.c b/src/economy.c index d3f6189fc..01954ff54 100644 --- a/src/economy.c +++ b/src/economy.c @@ -31,7 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spy.h" #include "study.h" #include "move.h" -#include "monster.h" +#include "monsters.h" #include "morale.h" #include "reports.h" #include "calendar.h" diff --git a/src/guard.c b/src/guard.c index ee26e467b..ec87ea46c 100644 --- a/src/guard.c +++ b/src/guard.c @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "guard.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include #include diff --git a/src/guard.test.c b/src/guard.test.c index 60e5453c6..c5bffeab5 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -2,7 +2,7 @@ #include "guard.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include #include diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 75ced96df..3d81b5d3c 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -10,7 +10,7 @@ #include #include -#include "monster.h" +#include "monsters.h" #include #include #include diff --git a/src/laws.c b/src/laws.c index 3fe53237e..e0bae8e41 100644 --- a/src/laws.c +++ b/src/laws.c @@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "keyword.h" #include "market.h" #include "morale.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include "randenc.h" #include "renumber.h" diff --git a/src/laws.test.c b/src/laws.test.c index 69e9f5e04..1bec0e6b4 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -2,7 +2,7 @@ #include "laws.h" #include "battle.h" #include "guard.h" -#include "monster.h" +#include "monsters.h" #include #include diff --git a/src/monster.c b/src/monster.c deleted file mode 100644 index 301b1b132..000000000 --- a/src/monster.c +++ /dev/null @@ -1,224 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#include -#include -#include "monster.h" - -/* gamecode includes */ -#include "economy.h" -#include "give.h" -#include "move.h" - -/* attributes includes */ -#include -#include -#include - -/* kernel includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* util includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* libc includes */ -#include -#include -#include - -#define MOVECHANCE 25 /* chance fuer bewegung */ - -#define MAXILLUSION_TEXTS 3 - -bool monster_is_waiting(const unit * u) -{ - int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED; - if (fval(u, test)) - return true; - return false; -} - -static void eaten_by_monster(unit * u) -{ - /* adjustment for smaller worlds */ - double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; - int n = 0; - int horse = -1; - const resource_type *rhorse = get_resourcetype(R_HORSE); - const race *rc = u_race(u); - attrib *a; - - a = a_find(rc->attribs, &at_scare); - if (a) { - n = rng_int() & a->data.i * u->number; - } else { - n = rng_int() % (u->number / 20 + 1); - horse = 0; - } - horse = horse ? i_get(u->items, rhorse->itype) : 0; - - n = (int)(n * multi); - if (n > 0) { - n = lovar(n); - n = _min(rpeasants(u->region), n); - - if (n > 0) { - deathcounts(u->region, n); - rsetpeasants(u->region, rpeasants(u->region) - n); - ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); - } - } - if (horse > 0) { - i_change(&u->items, rhorse->itype, -horse); - ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); - } -} - -static void absorbed_by_monster(unit * u) -{ - int n = rng_int() % (u->number / 20 + 1); - - if (n > 0) { - n = lovar(n); - n = _min(rpeasants(u->region), n); - if (n > 0) { - rsetpeasants(u->region, rpeasants(u->region) - n); - scale_number(u, u->number + n); - ADDMSG(&u->region->msgs, msg_message("absorbpeasants", - "unit race amount", u, u_race(u), n)); - } - } -} - -static int scareaway(region * r, int anzahl) -{ - int n, p, diff = 0, emigrants[MAXDIRECTIONS]; - direction_t d; - - anzahl = _min(_max(1, anzahl), rpeasants(r)); - - /* Wandern am Ende der Woche (normal) oder wegen Monster. Die - * Wanderung wird erst am Ende von demographics () ausgefuehrt. - * emigrants[] ist local, weil r->newpeasants durch die Monster - * vielleicht schon hochgezaehlt worden ist. */ - - for (d = 0; d != MAXDIRECTIONS; d++) - emigrants[d] = 0; - - p = rpeasants(r); - assert(p >= 0 && anzahl >= 0); - for (n = _min(p, anzahl); n; n--) { - direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); - region *rc = rconnect(r, dir); - - if (rc && fval(rc->terrain, LAND_REGION)) { - ++diff; - rc->land->newpeasants++; - emigrants[dir]++; - } - } - rsetpeasants(r, p - diff); - assert(p >= diff); - return diff; -} - -static void scared_by_monster(unit * u) -{ - int n; - const race *rc = u_race(u); - attrib *a; - a = a_find(rc->attribs, &at_scare); - if (a) { - n = rng_int() & a->data.i * u->number; - } else { - n = rng_int() % (u->number / 4 + 1); - } - if (n > 0) { - n = lovar(n); - n = _min(rpeasants(u->region), n); - if (n > 0) { - n = scareaway(u->region, n); - if (n > 0) { - ADDMSG(&u->region->msgs, msg_message("fleescared", - "amount unit", n, u)); - } - } - } -} - -void monster_kills_peasants(unit * u) -{ - if (!monster_is_waiting(u)) { - if (u_race(u)->flags & RCF_SCAREPEASANTS) { - scared_by_monster(u); - } - if (u_race(u)->flags & RCF_KILLPEASANTS) { - eaten_by_monster(u); - } - if (u_race(u)->flags & RCF_ABSORBPEASANTS) { - absorbed_by_monster(u); - } - } -} - -faction *get_or_create_monsters(void) -{ - faction *f = findfaction(MONSTER_ID); - if (!f) { - const race *rc = rc_get_or_create("dragon"); - const char *email = config_get("monster.email"); - f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, default_locale, 0); - renumber_faction(f, MONSTER_ID); - faction_setname(f, "Monster"); - fset(f, FFL_NPC | FFL_NOIDLEOUT); - } - return f; -} - -faction *get_monsters(void) { - return get_or_create_monsters(); -} - -void make_zombie(unit * u) -{ - u_setfaction(u, get_monsters()); - scale_number(u, 1); - u->hp = unit_max_hp(u) * u->number; - u_setrace(u, get_race(RC_ZOMBIE)); - u->irace = NULL; -} diff --git a/src/monster.h b/src/monster.h deleted file mode 100644 index 0f936b17d..000000000 --- a/src/monster.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef H_GC_MONSTER -#define H_GC_MONSTER -#ifdef __cplusplus -extern "C" { -#endif - - struct unit; - - void monster_kills_peasants(struct unit *u); - bool monster_is_waiting(const struct unit *u); - struct faction *get_monsters(void); - struct faction *get_or_create_monsters(void); - void make_zombie(struct unit * u); - -#define MONSTER_ID 666 -#define is_monsters(f) ((f->flags & FFL_NPC) && f==get_monsters()) - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/monsters.c b/src/monsters.c index cea817589..f1064b7fe 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -26,12 +26,12 @@ #include "chaos.h" #include "give.h" #include "guard.h" -#include "monster.h" #include "laws.h" #include "keyword.h" #include "study.h" /* attributes includes */ +#include #include #include @@ -72,8 +72,8 @@ #include #include -#define MOVECHANCE .25 /* chance fuer bewegung */ -#define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */ +#define DRAGON_RANGE 20 /* max. Distanz zum nächsten Drachenziel */ +#define MOVE_PERCENT 25 /* chance fuer bewegung */ #define MAXILLUSION_TEXTS 3 static double attack_chance; /* rules.monsters.attack_chance, or default 0.4 */ @@ -85,12 +85,12 @@ static void give_peasants(unit *u, const item_type *itype, int reduce) { } static double random_move_chance(void) { - static double rule; + static int rule; static int config; if (config_changed(&config)) { - rule = config_get_flt("rules.monsters.random_move_chance", MOVECHANCE); + rule = config_get_flt("rules.monsters.random_move_percent", MOVE_PERCENT); } - return rule; + return rule * 0.01; } static void reduce_weight(unit * u) @@ -165,6 +165,29 @@ static order *monster_attack(unit * u, const unit * target) return create_order(K_ATTACK, u->faction->locale, "%i", target->no); } +void monsters_desert(struct faction *monsters) +{ + region *r; + + assert(monsters!=NULL); + for (r = regions; r; r = r->next) { + unit *u; + + for (u = r->units; u; u = u->next) { + if (u->faction!=monsters + && (u_race(u)->flags & RCF_DESERT)) { + if (fval(u, UFL_ISNEW)) + continue; + if (rng_int() % 100 < 5) { + ADDMSG(&u->faction->msgs, msg_message("desertion", + "unit region", u, r)); + u_setfaction(u, monsters); + } + } + } + } +} + int monster_attacks(unit * monster, bool respect_buildings, bool rich_only) { region *r = monster->region; @@ -973,3 +996,161 @@ void spawn_undead(void) } } } + +bool monster_is_waiting(const unit * u) +{ + int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED; + if (fval(u, test)) + return true; + return false; +} + +static void eaten_by_monster(unit * u) +{ + /* adjustment for smaller worlds */ + double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; + int n = 0; + int horse = -1; + const resource_type *rhorse = get_resourcetype(R_HORSE); + const race *rc = u_race(u); + attrib *a; + + a = a_find(rc->attribs, &at_scare); + if (a) { + n = rng_int() & a->data.i * u->number; + } else { + n = rng_int() % (u->number / 20 + 1); + horse = 0; + } + horse = horse ? i_get(u->items, rhorse->itype) : 0; + + n = (int)(n * multi); + if (n > 0) { + n = lovar(n); + n = _min(rpeasants(u->region), n); + + if (n > 0) { + deathcounts(u->region, n); + rsetpeasants(u->region, rpeasants(u->region) - n); + ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); + } + } + if (horse > 0) { + i_change(&u->items, rhorse->itype, -horse); + ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); + } +} + +static void absorbed_by_monster(unit * u) +{ + int n = rng_int() % (u->number / 20 + 1); + + if (n > 0) { + n = lovar(n); + n = _min(rpeasants(u->region), n); + if (n > 0) { + rsetpeasants(u->region, rpeasants(u->region) - n); + scale_number(u, u->number + n); + ADDMSG(&u->region->msgs, msg_message("absorbpeasants", + "unit race amount", u, u_race(u), n)); + } + } +} + +static int scareaway(region * r, int anzahl) +{ + int n, p, diff = 0, emigrants[MAXDIRECTIONS]; + direction_t d; + + anzahl = _min(_max(1, anzahl), rpeasants(r)); + + /* Wandern am Ende der Woche (normal) oder wegen Monster. Die + * Wanderung wird erst am Ende von demographics () ausgefuehrt. + * emigrants[] ist local, weil r->newpeasants durch die Monster + * vielleicht schon hochgezaehlt worden ist. */ + + for (d = 0; d != MAXDIRECTIONS; d++) + emigrants[d] = 0; + + p = rpeasants(r); + assert(p >= 0 && anzahl >= 0); + for (n = _min(p, anzahl); n; n--) { + direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); + region *rc = rconnect(r, dir); + + if (rc && fval(rc->terrain, LAND_REGION)) { + ++diff; + rc->land->newpeasants++; + emigrants[dir]++; + } + } + rsetpeasants(r, p - diff); + assert(p >= diff); + return diff; +} + +static void scared_by_monster(unit * u) +{ + int n; + const race *rc = u_race(u); + attrib *a; + a = a_find(rc->attribs, &at_scare); + if (a) { + n = rng_int() & a->data.i * u->number; + } else { + n = rng_int() % (u->number / 4 + 1); + } + if (n > 0) { + n = lovar(n); + n = _min(rpeasants(u->region), n); + if (n > 0) { + n = scareaway(u->region, n); + if (n > 0) { + ADDMSG(&u->region->msgs, msg_message("fleescared", + "amount unit", n, u)); + } + } + } +} + +void monster_kills_peasants(unit * u) +{ + if (!monster_is_waiting(u)) { + if (u_race(u)->flags & RCF_SCAREPEASANTS) { + scared_by_monster(u); + } + if (u_race(u)->flags & RCF_KILLPEASANTS) { + eaten_by_monster(u); + } + if (u_race(u)->flags & RCF_ABSORBPEASANTS) { + absorbed_by_monster(u); + } + } +} + +faction *get_or_create_monsters(void) +{ + faction *f = findfaction(MONSTER_ID); + if (!f) { + const race *rc = rc_get_or_create("dragon"); + const char *email = config_get("monster.email"); + f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, default_locale, 0); + renumber_faction(f, MONSTER_ID); + faction_setname(f, "Monster"); + fset(f, FFL_NPC | FFL_NOIDLEOUT); + } + return f; +} + +faction *get_monsters(void) { + return get_or_create_monsters(); +} + +void make_zombie(unit * u) +{ + u_setfaction(u, get_monsters()); + scale_number(u, 1); + u->hp = unit_max_hp(u) * u->number; + u_setrace(u, get_race(RC_ZOMBIE)); + u->irace = NULL; +} diff --git a/src/monsters.h b/src/monsters.h index 02e41c0a4..52e9ebf37 100644 --- a/src/monsters.h +++ b/src/monsters.h @@ -1,8 +1,45 @@ -#pragma once +/* +Copyright (c) 1998-2015, Enno Rehling +Katja Zedel -struct unit; -struct region; -struct faction; +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. -struct unit *spawn_seaserpent(struct region *r, struct faction *f); -void spawn_dragons(void); +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#ifndef H_GC_MONSTER +#define H_GC_MONSTER +#ifdef __cplusplus +extern "C" { +#endif + + struct unit; + struct region; + struct faction; + + struct unit *spawn_seaserpent(struct region *r, struct faction *f); + void spawn_dragons(void); + void monsters_desert(struct faction *monsters); + + void monster_kills_peasants(struct unit *u); + bool monster_is_waiting(const struct unit *u); + struct faction *get_monsters(void); + struct faction *get_or_create_monsters(void); + void make_zombie(struct unit * u); + +#define MONSTER_ID 666 +#define is_monsters(f) ((f->flags & FFL_NPC) && f==get_monsters()) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/monsters.test.c b/src/monsters.test.c index ca793891c..e0eaa3ccc 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -10,7 +10,6 @@ #include #include -#include "monster.h" #include "monsters.h" #include "guard.h" #include "reports.h" diff --git a/src/move.c b/src/move.c index b6a908837..29e3a2ed5 100644 --- a/src/move.c +++ b/src/move.c @@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "travelthru.h" #include "vortex.h" -#include "monster.h" +#include "monsters.h" #include "lighthouse.h" #include "piracy.h" diff --git a/src/races/zombies.c b/src/races/zombies.c index d7f871dac..3e9303b38 100644 --- a/src/races/zombies.c +++ b/src/races/zombies.c @@ -24,7 +24,7 @@ /* util iclude */ #include -#include "monster.h" +#include "monsters.h" /* libc includes */ #include diff --git a/src/randenc.c b/src/randenc.c index a3c5ce303..536210b1f 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "volcano.h" #include "economy.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include "chaos.h" #include "study.h" @@ -826,22 +826,7 @@ void randomevents(void) /* monster-einheiten desertieren */ if (monsters) { - for (r = regions; r; r = r->next) { - unit *u; - - for (u = r->units; u; u = u->next) { - if (u->faction && !is_monsters(u->faction) - && (u_race(u)->flags & RCF_DESERT)) { - if (fval(u, UFL_ISNEW)) - continue; - if (rng_int() % 100 < 5) { - ADDMSG(&u->faction->msgs, msg_message("desertion", - "unit region", u, r)); - u_setfaction(u, monsters); - } - } - } - } + monsters_desert(monsters); } chaos_update(); diff --git a/src/report.c b/src/report.c index dd6b29525..7f9ede7e6 100644 --- a/src/report.c +++ b/src/report.c @@ -26,7 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "guard.h" #include "laws.h" #include "market.h" -#include "monster.h" +#include "monsters.h" #include "travelthru.h" /* modules includes */ diff --git a/src/spells.c b/src/spells.c index 57b1da3a5..7e7b5669a 100644 --- a/src/spells.c +++ b/src/spells.c @@ -22,7 +22,7 @@ #include "spells.h" #include "direction.h" #include "randenc.h" -#include "monster.h" +#include "monsters.h" #include "teleport.h" #include diff --git a/src/study.c b/src/study.c index 1dd4da8b8..2531c864a 100644 --- a/src/study.c +++ b/src/study.c @@ -24,7 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "study.h" #include "laws.h" #include "move.h" -#include "monster.h" +#include "monsters.h" #include "alchemy.h" #include "academy.h" diff --git a/src/summary.c b/src/summary.c index 2311b1994..8a3ee3c41 100644 --- a/src/summary.c +++ b/src/summary.c @@ -14,7 +14,7 @@ #include "summary.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include "calendar.h" #include diff --git a/src/teleport.c b/src/teleport.c index 74176f6af..f81f2f9f0 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "skill.h" -#include "monster.h" +#include "monsters.h" /* libc includes */ #include diff --git a/src/upkeep.c b/src/upkeep.c index 198ce73df..1cf41011f 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -16,7 +16,7 @@ #include "alchemy.h" #include "economy.h" -#include "monster.h" +#include "monsters.h" #include "donations.h" #include From 44652bae80295744f4cc7cf87bb09e711c43d3d4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 23 Dec 2016 23:58:24 +0100 Subject: [PATCH 007/271] fix flt/int compilation bug. --- src/monsters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monsters.c b/src/monsters.c index f1064b7fe..db34bff2c 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -88,7 +88,7 @@ static double random_move_chance(void) { static int rule; static int config; if (config_changed(&config)) { - rule = config_get_flt("rules.monsters.random_move_percent", MOVE_PERCENT); + rule = config_get_int("rules.monsters.random_move_percent", MOVE_PERCENT); } return rule * 0.01; } From ce17d7f2d73f3d80f89e542e49fa59cc4035d403 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 21:21:23 +0100 Subject: [PATCH 008/271] enable PAY NOT in E2 --- conf/e2/config.json | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index 217cfffe9..ce823a33d 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -5,7 +5,6 @@ "e2/terrains.json" ], "disabled": [ - "pay", "jsreport" ], "settings": { From f9fbe607663052f47a2179b89f6c96ca716995c3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 20:54:57 +0100 Subject: [PATCH 009/271] add a happy test for mt_new. refactor to not use strncpy. --- src/test_eressea.c | 1 + src/util/CMakeLists.txt | 2 +- src/util/message.c | 20 +++++++++++--------- src/util/message.test.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/util/message.test.c diff --git a/src/test_eressea.c b/src/test_eressea.c index 71cf008f2..6d2dead3f 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -65,6 +65,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(direction); ADD_SUITE(skill); ADD_SUITE(keyword); + ADD_SUITE(message); ADD_SUITE(order); ADD_SUITE(race); /* util */ diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 7eda87132..842bcf58c 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -14,7 +14,7 @@ gamedata.test.c language.test.c # lists.test.c # log.test.c -# message.test.c +message.test.c # nrmessage.test.c parser.test.c password.test.c diff --git a/src/util/message.c b/src/util/message.c index f19fc3313..5b6f12eb8 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -87,19 +87,21 @@ message_type *mt_new(const char *name, const char *args[]) for (i = 0; args[i]; ++i) { const char *x = args[i]; const char *spos = strchr(x, ':'); - if (spos == NULL) { - mtype->pnames[i] = _strdup(x); - mtype->types[i] = NULL; + struct arg_type *atype = NULL; + if (spos != NULL) { + atype = find_argtype(spos + 1); + } + if (!atype) { + log_error("unknown argument type %s for message type %s\n", spos + 1, mtype->name); + assert(atype); } else { - char *cp = strncpy((char *)malloc(spos - x + 1), x, spos - x); + char *cp; + cp = malloc(spos - x + 1); + memcpy(cp, x, spos - x); cp[spos - x] = '\0'; mtype->pnames[i] = cp; - mtype->types[i] = find_argtype(spos + 1); - if (mtype->types[i] == NULL) { - log_error("unknown argument type %s for message type %s\n", spos + 1, mtype->name); - } - assert(mtype->types[i]); + mtype->types[i] = atype; } } } diff --git a/src/util/message.test.c b/src/util/message.test.c new file mode 100644 index 000000000..d114e33f2 --- /dev/null +++ b/src/util/message.test.c @@ -0,0 +1,29 @@ +#include +#include "message.h" + +#include +#include + +static void test_mt_new(CuTest *tc) +{ + message_type *mt; + test_setup(); + mt = mt_new_va("test", "name:string", "number:int", NULL); + CuAssertPtrNotNull(tc, mt); + CuAssertStrEquals(tc, "test", mt->name); + CuAssertIntEquals(tc, 2, mt->nparameters); + CuAssertPtrNotNull(tc, mt->pnames); + CuAssertStrEquals(tc, "name", mt->pnames[0]); + CuAssertStrEquals(tc, "number", mt->pnames[1]); + CuAssertPtrNotNull(tc, mt->types); + CuAssertStrEquals(tc, "string", mt->types[0]->name); + CuAssertStrEquals(tc, "int", mt->types[1]->name); + test_cleanup(); +} + +CuSuite *get_message_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_mt_new); + return suite; +} From 946364268738ad3ad37af5014b594e789b17d2cd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:08:49 +0100 Subject: [PATCH 010/271] eliminate unnecessary strncpy use. --- src/report.c | 3 ++- src/reports.c | 6 +----- src/util/language.c | 25 ++++++++++++++++--------- src/util/language.test.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/report.c b/src/report.c index 7f9ede7e6..0d6d283dd 100644 --- a/src/report.c +++ b/src/report.c @@ -413,7 +413,8 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } else { char substr[32]; - strncpy(substr, syntaxp, cstr - syntaxp); + assert(sizeof(substr) > (cstr - syntaxp)); + memcpy(substr, syntaxp, cstr - syntaxp); substr[cstr - syntaxp] = 0; locp = LOC(lang, mkname("spellpar", substr)); syntaxp = substr + 1; diff --git a/src/reports.c b/src/reports.c index a8b9e5cfb..52278d270 100644 --- a/src/reports.c +++ b/src/reports.c @@ -849,10 +849,6 @@ const struct unit * u, struct skill * sv, int *dh, int days) void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark) { - - /* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer - * mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf. - * Vgl. spunit (). */ bool firstline; static char buf[REPORTWIDTH + 1]; // FIXME: static buffer, artificial limit size_t len = strlen(s); @@ -883,7 +879,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned if (!cut) { cut = s + _min(len, REPORTWIDTH); } - strncpy(buf + indent, s, cut - s); + memcpy(buf + indent, s, cut - s); buf[indent + (cut - s)] = 0; addstrlist(SP, buf); // TODO: too much string copying, cut out this function while (*cut == ' ') { diff --git a/src/util/language.c b/src/util/language.c index d8b899742..cb91d7419 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -101,16 +101,23 @@ locale *get_or_create_locale(const char *name) void make_locales(const char *str) { const char *tok = str; - while (*tok) { - char zText[32]; - while (*tok && *tok != ',') - ++tok; - strncpy(zText, str, tok - str); - zText[tok - str] = 0; - get_or_create_locale(zText); - if (*tok) { - str = ++tok; + while (tok) { + char zText[16]; + size_t len; + + tok = strchr(str, ','); + if (tok) { + len = tok - str; + assert(sizeof(zText) > len); + memcpy(zText, str, len); + str = tok + 1; } + else { + len = strlen(str); + memcpy(zText, str, len); + } + zText[len] = 0; + get_or_create_locale(zText); } } diff --git a/src/util/language.test.c b/src/util/language.test.c index 236eac497..40a6775fa 100644 --- a/src/util/language.test.c +++ b/src/util/language.test.c @@ -16,9 +16,20 @@ static void test_language(CuTest *tc) test_cleanup(); } +static void test_make_locales(CuTest *tc) +{ + test_setup(); + make_locales("aa,bb,cc"); + CuAssertPtrNotNull(tc, get_locale("aa")); + CuAssertPtrNotNull(tc, get_locale("bb")); + CuAssertPtrNotNull(tc, get_locale("cc")); + test_cleanup(); +} + CuSuite *get_language_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_language); + SUITE_ADD_TEST(suite, test_make_locales); return suite; } From 8d02d5a5aa23b3260cd4e83569ad9ee09bb73ff7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:24:31 +0100 Subject: [PATCH 011/271] never use strncpy, anywhere. --- src/bind_config.c | 3 ++- src/helpers.c | 2 +- src/util/log.test.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index 3959cc22c..929e4cca0 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ int config_parse(const char *json) if (xp >= ep) break; } xp = (ep > json + 10) ? ep - 10 : json; - strncpy(buffer, xp, sizeof(buffer)); + strlcpy(buffer, xp, sizeof(buffer)); buffer[9] = 0; log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer); } diff --git a/src/helpers.c b/src/helpers.c index aa9bc12eb..e9502e075 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -167,7 +167,7 @@ static int lua_callspell(castorder * co) if (hashpos != NULL) { ptrdiff_t len = hashpos - fname; assert(len < (ptrdiff_t) sizeof(fbuf)); - strncpy(fbuf, fname, len); + memcpy(fbuf, fname, len); fbuf[len] = '\0'; fname = fbuf; } diff --git a/src/util/log.test.c b/src/util/log.test.c index 95cbefa96..55616c026 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -12,7 +12,7 @@ void log_string(void *data, int level, const char *module, const char *format, v unused_arg(format); unused_arg(module); unused_arg(level); - strncpy(str, arg, 32); + strcpy(str, arg); } static void test_logging(CuTest * tc) From 262580f1d5d70b258138926e1304d5d0c7e5f77d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:37:52 +0100 Subject: [PATCH 012/271] gcc warning eliminated --- src/report.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/report.c b/src/report.c index 0d6d283dd..0c7697fe5 100644 --- a/src/report.c +++ b/src/report.c @@ -413,9 +413,10 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } else { char substr[32]; - assert(sizeof(substr) > (cstr - syntaxp)); - memcpy(substr, syntaxp, cstr - syntaxp); - substr[cstr - syntaxp] = 0; + size_t len = cstr - syntaxp; + assert(sizeof(substr) > len); + memcpy(substr, syntaxp, len); + substr[len] = 0; locp = LOC(lang, mkname("spellpar", substr)); syntaxp = substr + 1; } From f5419a7f456b6491d5482ef696e8c6f3ea0bdf48 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 22:47:50 +0100 Subject: [PATCH 013/271] remove superfluous quicklist includes. --- src/bind_faction.c | 2 -- src/bind_monsters.c | 2 -- src/creport.test.c | 1 - src/kernel/config.c | 1 - src/kernel/equipment.test.c | 2 -- src/kernel/spell.test.c | 1 - src/kernel/spellbook.test.c | 1 - src/report.test.c | 1 - src/spy.c | 2 -- 9 files changed, 13 deletions(-) diff --git a/src/bind_faction.c b/src/bind_faction.c index 36da798c1..109814717 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -32,8 +32,6 @@ without prior permission by the authors of Eressea. #include #include -#include - #include #include diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 3e3f24bee..54a9d0ba6 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -12,8 +12,6 @@ #include -#include - #include #include diff --git a/src/creport.test.c b/src/creport.test.c index 72669e99f..21a6c09b7 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/src/kernel/config.c b/src/kernel/config.c index f33303ead..2b1ae678d 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -63,7 +63,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 2911af1ea..a82f86674 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -7,8 +7,6 @@ #include #include -#include - #include #include diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index f61c0fffe..6bb2ac449 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/src/kernel/spellbook.test.c b/src/kernel/spellbook.test.c index 2f78fd87d..8b997557b 100644 --- a/src/kernel/spellbook.test.c +++ b/src/kernel/spellbook.test.c @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/src/report.test.c b/src/report.test.c index 202458db5..555d39408 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/src/spy.c b/src/spy.c index 22c548d68..86476bec7 100644 --- a/src/spy.c +++ b/src/spy.c @@ -49,8 +49,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - /* libc includes */ #include #include From 494643d65f399b1e7df8307e731382f92d52657e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Jan 2017 20:20:13 +0100 Subject: [PATCH 014/271] remove old & unused fix_famililar repair code. --- src/bind_monsters.c | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/bind_monsters.c b/src/bind_monsters.c index d7a3daab2..fd1130053 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -58,34 +58,6 @@ static int tolua_spawn_undead(lua_State * L) return 0; } -static int fix_familiars(struct lua_State *L) -{ - faction *f; - for (f = factions; f; f = f->next) { - unit *u; - for (u = f->units; u; u = u->nextF) { - struct sc_mage *mage = get_mage(u); - if (mage && is_familiar(u)) { - if (mage->spellbook && mage->magietyp == M_GRAY) { - equipment *eq; - char buffer[64]; - - spellbook_clear(mage->spellbook); - free(mage->spellbook); - mage->spellbook = 0; - - _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name); - eq = get_equipment(buffer); - if (eq) { - equip_unit_mask(u, eq, EQUIP_SPELLS); - } - } - } - } - } - return 0; -} - void bind_monsters(struct lua_State *L) { tolua_module(L, NULL, 0); @@ -95,7 +67,6 @@ void bind_monsters(struct lua_State *L) tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters); tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead); tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons); - tolua_function(L, TOLUA_CAST "fix_familiars", fix_familiars); tolua_function(L, TOLUA_CAST "get_monsters", tolua_get_monsters); } tolua_endmodule(L); From 3fb12d8f1ef0ee1a026d6d3ac76c393c89461d55 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Jan 2017 21:09:39 +0100 Subject: [PATCH 015/271] replace snprintf and the like. you cannot trust _snprintf in MSVC (no zero-termination). --- src/bind_storage.c | 4 +++- src/gmtool.c | 2 +- src/json.c | 6 +++--- src/kernel/item.c | 5 ++++- src/kernel/jsonconf.c | 7 ++++++- src/util/bsdstring.c | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bind_storage.c b/src/bind_storage.c index a81a3baeb..6b582e815 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -100,7 +100,9 @@ static int tolua_storage_tostring(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); char name[64]; - _snprintf(name, sizeof(name), "", (void *)data, data->version); + // safe to use sprintf here, because: + // %p is at most 16 characters, %d 20, text is 16, comes to 53 with \0 + sprintf(name, "", (void *)data, data->version); lua_pushstring(L, name); return 1; } diff --git a/src/gmtool.c b/src/gmtool.c index 7aab2fea7..b1b9a1bc1 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -1167,7 +1167,7 @@ static void handlekey(state * st, int c) region *first = (mr && mr->r && mr->r->next) ? mr->r->next : regions; if (findmode == 'f') { - snprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", locate); + slprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", locate); statusline(st->wnd_status->handle, sbuffer); f = findfaction(atoi36(locate)); if (f == NULL) { diff --git a/src/json.c b/src/json.c index 10322fe3f..2c27b9947 100644 --- a/src/json.c +++ b/src/json.c @@ -67,13 +67,13 @@ int json_export(stream * out, int flags) { cJSON *json, *root = cJSON_CreateObject(); assert(out && out->api); if (regions && (flags & EXPORT_REGIONS)) { - char id[32]; + char id[32]; // TODO: static_assert(INT_MAX < 10^32) region * r; plane * p; cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject()); for (p = planes; p; p = p->next) { cJSON *data; - _snprintf(id, sizeof(id), "%d", p->id); + sprintf(id, "%d", p->id); // safe, unless int is bigger than 64 bit cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", p->minx); cJSON_AddNumberToObject(data, "y", p->miny); @@ -85,7 +85,7 @@ int json_export(stream * out, int flags) { cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject()); for (r = regions; r; r = r->next) { cJSON *data; - _snprintf(id, sizeof(id), "%d", r->uid); + sprintf(id, "%d", r->uid); // safe, unless int is bigger than 64 bit cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "y", r->y); diff --git a/src/kernel/item.c b/src/kernel/item.c index 53fff79ab..9956f2a4a 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -156,7 +156,10 @@ const char *resourcename(const resource_type * rtype, int flags) } if (flags & NMF_PLURAL) { static char name[64]; // FIXME: static return value - _snprintf(name, sizeof(name), "%s_p", rtype->_name); + size_t len = strlen(rtype->_name); + assert(len <= sizeof(name) - 3); + memcpy(name, rtype->_name, len); + strcpy(name + len, "_p"); return name; } return rtype->_name; diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index d12238566..dccfbb68a 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -523,6 +523,8 @@ static void disable_feature(const char *str) { char name[32]; int k; skill_t sk; + size_t len; + sk = findskill(str); if (sk != NOSKILL) { enable_skill(sk, false); @@ -534,7 +536,10 @@ static void disable_feature(const char *str) { enable_keyword(k, false); return; } - _snprintf(name, sizeof(name), "%s.enabled", str); + len = strlen(str); + assert(len <= sizeof(name) - 9); + memcpy(name, str, len); + strcpy(name+len, ".enabled"); log_info("disable feature %s\n", name); config_set(name, "0"); } diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index 98d2d00f5..4fc56ce4e 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -13,7 +13,7 @@ int wrptr(char **ptr, size_t * size, int result) { size_t bytes = (size_t)result; if (result < 0) { - // _snprintf buffer was too small + // buffer was too small if (*size > 0) { **ptr = 0; *size = 0; From 6d60b48b3f95985aad55721bf275d309d84ac46d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Jan 2017 21:19:58 +0100 Subject: [PATCH 016/271] create_order takes variable arguments! more snprintf removal. --- src/give.test.c | 12 +++--------- src/kernel/jsonconf.c | 4 ++-- src/kernel/unit.test.c | 13 +++++-------- src/laws.test.c | 4 +--- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/give.test.c b/src/give.test.c index f2b0d60a9..029ee7c44 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -233,7 +233,6 @@ static void test_give_men_requires_contact(CuTest * tc) { struct give env = { 0 }; message * msg; order *ord; - char cmd[32]; test_setup_ex(tc); env.f1 = test_create_faction(0); @@ -244,8 +243,7 @@ static void test_give_men_requires_contact(CuTest * tc) { CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); - _snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no)); - ord = create_order(K_GIVE, env.f1->locale, cmd); + ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no)); test_clear_messages(env.f1); give_cmd(env.src, ord); CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person")); @@ -307,7 +305,6 @@ static void test_give(CuTest * tc) { static void test_give_cmd(CuTest * tc) { struct give env = { 0 }; struct order *ord; - char cmd[32]; test_setup_ex(tc); env.lang = test_create_locale(); @@ -316,8 +313,7 @@ static void test_give_cmd(CuTest * tc) { i_change(&env.src->items, env.itype, 10); - _snprintf(cmd, sizeof(cmd), "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); - ord = create_order(K_GIVE, env.f1->locale, cmd); + ord = create_order(K_GIVE, env.f1->locale, "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); assert(ord); give_cmd(env.src, ord); CuAssertIntEquals(tc, 5, i_get(env.src->items, env.itype)); @@ -330,7 +326,6 @@ static void test_give_cmd(CuTest * tc) { static void test_give_herbs(CuTest * tc) { struct give env = { 0 }; struct order *ord; - char cmd[32]; test_setup_ex(tc); test_create_world(); @@ -338,8 +333,7 @@ static void test_give_herbs(CuTest * tc) { setup_give(&env); i_change(&env.src->items, env.itype, 10); - _snprintf(cmd, sizeof(cmd), "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); - ord = create_order(K_GIVE, env.f1->locale, cmd); + ord = create_order(K_GIVE, env.f1->locale, "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); assert(ord); give_cmd(env.src, ord); diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index dccfbb68a..69e02c3a0 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -801,10 +801,10 @@ static void json_settings(cJSON *json) { else { char value[32]; if (child->type == cJSON_Number && child->valuedouble && child->valueintvaluedouble) { - _snprintf(value, sizeof(value), "%f", child->valuedouble); + sprintf(value, "%f", child->valuedouble); } else { - _snprintf(value, sizeof(value), "%d", child->valueint); + sprintf(value, "%d", child->valueint); } config_set(child->string, value); } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 752627144..1a481960d 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -140,37 +140,34 @@ static void test_scale_number(CuTest *tc) { static void test_unit_name(CuTest *tc) { unit *u; - char name[32]; test_cleanup(); test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); + renumber_unit(u, 666); unit_setname(u, "Hodor"); - _snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no)); - CuAssertStrEquals(tc, name, unitname(u)); + CuAssertStrEquals(tc, "Hodor (ii)", unitname(u)); test_cleanup(); } static void test_unit_name_from_race(CuTest *tc) { unit *u; - char name[32]; struct locale *lang; test_cleanup(); test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); + renumber_unit(u, 666); unit_setname(u, NULL); lang = get_or_create_locale("de"); locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch"); locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen"); - _snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no)); - CuAssertStrEquals(tc, name, unitname(u)); + CuAssertStrEquals(tc, "Mensch (ii)", unitname(u)); CuAssertStrEquals(tc, "Mensch", unit_getname(u)); u->number = 2; - _snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no)); - CuAssertStrEquals(tc, name, unitname(u)); + CuAssertStrEquals(tc, "Menschen (ii)", unitname(u)); CuAssertStrEquals(tc, "Menschen", unit_getname(u)); test_cleanup(); diff --git a/src/laws.test.c b/src/laws.test.c index 1bec0e6b4..d4753ec19 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -521,7 +521,6 @@ static void test_pay_cmd_other_building(CuTest *tc) { order *ord; faction *f; building *b; - char cmd[32]; test_setup(); setup_pay_cmd(&fix); @@ -531,8 +530,7 @@ static void test_pay_cmd_other_building(CuTest *tc) { config_set("rules.region_owner_pay_building", "lighthouse"); update_owners(b->region); - _snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no)); - ord = create_order(K_PAY, f->locale, cmd); + ord = create_order(K_PAY, f->locale, "NOT %s", itoa36(b->no)); assert(ord); CuAssertPtrEquals(tc, fix.u1, building_owner(b)); CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord)); From 3ff5a3155e5a058a415a46e7b77a5143ef947d03 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 12:54:49 +0100 Subject: [PATCH 017/271] do not update submodules before each build. add tolua to .gitignore, it's not a proper submodule. --- .gitignore | 81 +++++++++++++++++++++++++++--------------------------- s/build | 2 -- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 24219490f..4e63f5d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,40 +1,41 @@ -.vscode/ -*.orig -eressea.ini -Debug -Release - -# SlickEdit -*.vtg -*.vpwhistu - -# Microsoft Visual Studio build artefacts -src/Debug/ -src/Release/ -src/*.vcproj.*.user -Debug/ -Release/ -ipch/ -*.ipch -*.ncb -*.opensdf -*.pdb -*.sdf -*.suo -*.user - -*~ -*.bak -bin/ -build*/ -*.log -*.log.* -tags -Thumbs.db -.gdb_history -*.cfg -*.cmd -tmp/ -tests/config.lua -tests/reports/ -tests/data/185.dat +tolua/ +.vscode/ +*.orig +eressea.ini +Debug +Release + +# SlickEdit +*.vtg +*.vpwhistu + +# Microsoft Visual Studio build artefacts +src/Debug/ +src/Release/ +src/*.vcproj.*.user +Debug/ +Release/ +ipch/ +*.ipch +*.ncb +*.opensdf +*.pdb +*.sdf +*.suo +*.user + +*~ +*.bak +bin/ +build*/ +*.log +*.log.* +tags +Thumbs.db +.gdb_history +*.cfg +*.cmd +tmp/ +tests/config.lua +tests/reports/ +tests/data/185.dat diff --git a/s/build b/s/build index b59804626..01acc1ae2 100755 --- a/s/build +++ b/s/build @@ -33,8 +33,6 @@ if [ ! -d $ROOT/$BUILD ]; then exit fi -git submodule update - echo "build eressea" cd $ROOT/$BUILD VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') From 8b7dae6977d643cdfc422c4e08b717e0261d33cc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 16:31:05 +0100 Subject: [PATCH 018/271] kill autoconf.h, replace platform.h for C99 compatibility work --- CMakeLists.txt | 50 ---------- autoconf.h.in | 36 ------- src/academy.c | 2 +- src/alchemy.c | 10 +- src/attributes/dict.c | 8 +- src/attributes/hate.c | 2 +- src/attributes/moved.c | 2 +- src/attributes/movement.c | 2 +- src/attributes/racename.c | 4 +- src/attributes/raceprefix.c | 4 +- src/battle.c | 66 ++++++------- src/battle.h | 1 + src/bind_building.c | 2 +- src/bind_dict.c | 2 +- src/bind_gmtool.c | 6 +- src/bind_monsters.c | 2 +- src/bind_region.c | 2 +- src/bind_ship.c | 2 +- src/bind_storage.c | 2 +- src/building_action.c | 10 +- src/creport.c | 8 +- src/economy.c | 64 ++++++------- src/give.c | 4 +- src/give.test.c | 6 +- src/gmtool.c | 4 +- src/guard.h | 3 + src/items.c | 2 +- src/items/artrewards.c | 2 +- src/items/demonseye.c | 4 +- src/items/speedsail.c | 4 +- src/items/weapons.c | 2 +- src/items/xerewards.c | 2 +- src/json.c | 4 +- src/kernel/alliance.c | 4 +- src/kernel/ally.c | 6 +- src/kernel/build.c | 34 +++---- src/kernel/building.c | 10 +- src/kernel/building.h | 2 + src/kernel/building.test.c | 2 +- src/kernel/config.c | 13 +-- src/kernel/config.h | 1 + src/kernel/connection.c | 68 ++++++------- src/kernel/connection.h | 2 +- src/kernel/curse.c | 20 ++-- src/kernel/curse.h | 2 + src/kernel/equipment.c | 8 +- src/kernel/faction.c | 10 +- src/kernel/faction.h | 2 + src/kernel/group.c | 4 +- src/kernel/item.c | 24 ++--- src/kernel/jsonconf.c | 12 +-- src/kernel/messages.c | 4 +- src/kernel/order.c | 2 +- src/kernel/plane.c | 2 +- src/kernel/pool.c | 10 +- src/kernel/race.c | 4 +- src/kernel/region.c | 16 ++-- src/kernel/region.h | 1 + src/kernel/resources.c | 4 +- src/kernel/save.c | 24 ++--- src/kernel/save.test.c | 8 +- src/kernel/ship.c | 10 +- src/kernel/spell.c | 2 +- src/kernel/spellbook.c | 2 +- src/kernel/terrain.c | 2 +- src/kernel/unit.c | 18 ++-- src/kernel/unit.test.c | 14 +-- src/kernel/xmlreader.c | 24 ++--- src/laws.c | 86 ++++++++--------- src/laws.h | 1 + src/laws.test.c | 2 +- src/lighthouse.c | 4 +- src/lighthouse.h | 2 + src/listbox.c | 2 +- src/magic.c | 42 ++++---- src/magic.h | 1 + src/market.test.c | 2 +- src/modules/arena.c | 14 +-- src/modules/autoseed.c | 10 +- src/modules/museum.c | 8 +- src/modules/score.c | 2 +- src/monsters.c | 16 ++-- src/morale.c | 2 +- src/move.c | 24 ++--- src/move.h | 5 +- src/names.c | 6 +- src/platform.h | 180 ++--------------------------------- src/prefix.c | 2 +- src/races/dragons.c | 2 +- src/races/races.c | 2 +- src/races/zombies.c | 8 +- src/randenc.c | 4 +- src/report.c | 80 ++++++++-------- src/report.test.c | 6 +- src/reports.c | 44 ++++----- src/skill.h | 2 +- src/spells.c | 103 ++++++++++---------- src/spells/borders.c | 8 +- src/spells/borders.h | 3 + src/spells/buildingcurse.c | 2 +- src/spells/combatspells.c | 30 +++--- src/spells/flyingship.h | 2 + src/spells/regioncurse.c | 28 +++--- src/spells/shipcurse.c | 6 +- src/spells/unitcurse.c | 16 ++-- src/spy.c | 6 +- src/sqlite.c | 4 +- src/study.c | 18 ++-- src/summary.c | 8 +- src/test_eressea.c | 2 +- src/travelthru.test.c | 2 +- src/triggers/changefaction.c | 2 +- src/triggers/changerace.c | 2 +- src/triggers/clonedied.c | 2 +- src/triggers/createcurse.c | 2 +- src/triggers/createunit.c | 2 +- src/triggers/gate.c | 2 +- src/triggers/giveitem.c | 2 +- src/triggers/killunit.c | 2 +- src/triggers/shock.c | 6 +- src/triggers/timeout.c | 2 +- src/triggers/unitmessage.c | 6 +- src/upkeep.c | 12 +-- src/util/attrib.c | 2 +- src/util/attrib.h | 2 + src/util/attrib.test.c | 2 +- src/util/crmessage.c | 10 +- src/util/event.c | 4 +- src/util/goodies.c | 2 +- src/util/language.c | 8 +- src/util/language.h | 2 +- src/util/lists.c | 2 +- src/util/log.test.c | 6 +- src/util/message.c | 2 +- src/util/nrmessage.c | 6 +- src/util/translation.c | 12 +-- src/vortex.c | 14 +-- src/vortex.h | 5 + src/wormhole.c | 2 +- 139 files changed, 698 insertions(+), 917 deletions(-) delete mode 100644 autoconf.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index d60d3d721..9b26ecb6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,56 +14,6 @@ find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) -INCLUDE (CheckIncludeFiles) -INCLUDE (CheckSymbolExists) -CHECK_INCLUDE_FILES (stdbool.h HAVE_STDBOOL_H) -CHECK_INCLUDE_FILES (windows.h HAVE_WINDOWS_H) -CHECK_INCLUDE_FILES (io.h HAVE_IO_H) -CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H) -CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) -IF (HAVE_IO_H) -CHECK_SYMBOL_EXISTS (_access "io.h" HAVE__ACCESS) -ENDIF (HAVE_IO_H) -IF (HAVE_WINDOWS_H) -CHECK_SYMBOL_EXISTS (_sleep "windows.h" HAVE__SLEEP) -ENDIF(HAVE_WINDOWS_H) -IF(HAVE_STDBOOL_H) -CHECK_SYMBOL_EXISTS (_Bool "stdbool.h" HAVE__BOOL) -ENDIF(HAVE_STDBOOL_H) -IF(HAVE_UNISTD_H) -CHECK_SYMBOL_EXISTS (sleep "unistd.h" HAVE_SLEEP) -CHECK_SYMBOL_EXISTS (usleep "unistd.h" HAVE_USLEEP) -CHECK_SYMBOL_EXISTS (access "unistd.h" HAVE_ACCESS) -ENDIF(HAVE_UNISTD_H) -CHECK_SYMBOL_EXISTS (strlcpy "string.h" HAVE_STRLCPY) -CHECK_SYMBOL_EXISTS (strlcat "string.h" HAVE_STRLCAT) -CHECK_SYMBOL_EXISTS (slprintf "string.h" HAVE_SLPRINTF) -CHECK_SYMBOL_EXISTS (strcasecmp "string.h" HAVE_STRCASECMP) -CHECK_SYMBOL_EXISTS (strncasecmp "string.h" HAVE_STRNCASECMP) -CHECK_SYMBOL_EXISTS (_strlwr "string.h" HAVE__STRLWR) -CHECK_SYMBOL_EXISTS (_strcmpl "string.h" HAVE__STRCMPL) -CHECK_SYMBOL_EXISTS (_strdup "string.h" HAVE__STRDUP) -CHECK_SYMBOL_EXISTS (_stricmp "string.h" HAVE__STRICMP) -CHECK_SYMBOL_EXISTS (_memicmp "string.h" HAVE__MEMICMP) -CHECK_SYMBOL_EXISTS (strcmpl "string.h" HAVE_STRCMPL) -CHECK_SYMBOL_EXISTS (strdup "string.h" HAVE_STRDUP) -CHECK_SYMBOL_EXISTS (stricmp "string.h" HAVE_STRICMP) -CHECK_SYMBOL_EXISTS (memicmp "string.h" HAVE_MEMICMP) -CHECK_SYMBOL_EXISTS (strlwr "string.h" HAVE_STRLWR) -CHECK_SYMBOL_EXISTS (snprintf "stdio.h" HAVE_SNPRINTF) -CHECK_SYMBOL_EXISTS (_snprintf "stdio.h" HAVE__SNPRINTF) -CHECK_SYMBOL_EXISTS (mkdir "sys/stat.h" HAVE_SYS_STAT_MKDIR) -CHECK_SYMBOL_EXISTS (mkdir "direct.h" HAVE_DIRECT_MKDIR) -CHECK_SYMBOL_EXISTS (_mkdir "direct.h" HAVE_DIRECT__MKDIR) - -CONFIGURE_FILE ( - ${CMAKE_CURRENT_SOURCE_DIR}/autoconf.h.in - ${CMAKE_BINARY_DIR}/include/autoconf.h) -INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include) - -## skip compiler/libc detection and force cmake autoconf: -#add_definitions(-DUSE_AUTOCONF) - add_subdirectory (cutest) add_subdirectory (cJSON) add_subdirectory (storage) diff --git a/autoconf.h.in b/autoconf.h.in deleted file mode 100644 index f3f197db1..000000000 --- a/autoconf.h.in +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#ifndef CMAKE_AUTOCONF_H -#define CMAKE_AUTOCONF_H -#cmakedefine HAVE_STDBOOL_H 1 -#cmakedefine HAVE_STRINGS_H 1 -#cmakedefine HAVE_WINDOWS_H 1 -#cmakedefine HAVE_IO_H 1 -#cmakedefine HAVE_UNISTD_H 1 -#cmakedefine HAVE__BOOL 1 -#cmakedefine HAVE_STRCASECMP 1 -#cmakedefine HAVE_STRNCASECMP 1 -#cmakedefine HAVE__STRICMP 1 -#cmakedefine HAVE_SNPRINTF 1 -#cmakedefine HAVE__SNPRINTF 1 -#cmakedefine HAVE_ACCESS 1 -#cmakedefine HAVE__ACCESS 1 -#cmakedefine HAVE_SLEEP 1 -#cmakedefine HAVE_USLEEP 1 -#cmakedefine HAVE__SLEEP 1 -#cmakedefine HAVE_STRDUP 1 -#cmakedefine HAVE__STRDUP 1 -#cmakedefine HAVE_STRICMP 1 -#cmakedefine HAVE__STRCMPL 1 -#cmakedefine HAVE_STRCMPL 1 -#cmakedefine HAVE__MEMICMP 1 -#cmakedefine HAVE_MEMICMP 1 -#cmakedefine HAVE__STRLWR 1 -#cmakedefine HAVE_STRLWR 1 -#cmakedefine HAVE_STRLCPY 1 -#cmakedefine HAVE_STRLCAT 1 -#cmakedefine HAVE_SLPRINTF 1 -#cmakedefine HAVE_SYS_STAT_MKDIR 1 -#cmakedefine HAVE_DIRECT_MKDIR 1 -#cmakedefine HAVE_DIRECT__MKDIR 1 - -#endif diff --git a/src/academy.c b/src/academy.c index f6b70873e..496c1ef8e 100644 --- a/src/academy.c +++ b/src/academy.c @@ -35,7 +35,7 @@ bool academy_can_teach(unit *teacher, unit *student, skill_t sk) { const struct building_type *btype = bt_find("academy"); if (active_building(teacher, btype) && active_building(student, btype)) { int j = study_cost(student, sk); - j = _max(50, j * 2); + j = MAX(50, j * 2); /* kann Einheit das zahlen? */ return get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j; /* sonst nehmen sie nicht am Unterricht teil */ diff --git a/src/alchemy.c b/src/alchemy.c index 9bc180700..ddbe46b8e 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -73,12 +73,12 @@ void herbsearch(unit * u, int max) } if (max) - max = _min(max, rherbs(r)); + max = MIN(max, rherbs(r)); else max = rherbs(r); herbsfound = ntimespprob(effsk * u->number, (double)rherbs(r) / 100.0F, -0.01F); - herbsfound = _min(herbsfound, max); + herbsfound = MIN(herbsfound, max); rsetherbs(r, (short) (rherbs(r) - herbsfound)); if (herbsfound) { @@ -156,7 +156,7 @@ static int potion_water_of_life(unit * u, region *r, int amount) { } static int potion_healing(unit * u, int amount) { - u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount); + u->hp = MIN(unit_max_hp(u) * u->number, u->hp + 400 * amount); return amount; } @@ -182,7 +182,7 @@ static int potion_power(unit *u, int amount) { amount = use; } /* Verf�nffacht die HP von max. 10 Personen in der Einheit */ - u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4; + u->hp += MIN(u->number, 10 * amount) * unit_max_hp(u) * 4; return amount; } @@ -248,7 +248,7 @@ static void free_potiondelay(attrib * a) { static int age_potiondelay(attrib * a, void *owner) { potiondelay *pd = (potiondelay *)a->data.v; - unused_arg(owner); + UNUSED_ARG(owner); pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount); return AT_AGE_REMOVE; } diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 2bba9ea7b..a3f034145 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -103,7 +103,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data) float flt; READ_STR(store, name, sizeof(name)); - dd->name = _strdup(name); + dd->name = strdup(name); READ_INT(store, &n); dd->type = (dict_type)n; switch (dd->type) { @@ -122,7 +122,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data) break; case TSTRING: READ_STR(store, name, sizeof(name)); - dd->data.str = _strdup(name); + dd->data.str = strdup(name); break; case TBUILDING: result = @@ -199,7 +199,7 @@ struct attrib *dict_create(const char *name, dict_type type, variant value) { attrib *a = a_new(&at_dict); dict_data *data = (dict_data *)a->data.v; - data->name = _strdup(name); + data->name = strdup(name); dict_set(a, type, value); return a; @@ -214,7 +214,7 @@ void dict_set(attrib * a, dict_type type, variant value) data->type = type; switch (type) { case TSTRING: - data->data.str = value.v ? _strdup(value.v) : NULL; + data->data.str = value.v ? strdup(value.v) : NULL; break; case TINTEGER: data->data.i = value.i; diff --git a/src/attributes/hate.c b/src/attributes/hate.c index 98a36a029..17155fc71 100644 --- a/src/attributes/hate.c +++ b/src/attributes/hate.c @@ -30,7 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int verify_hate(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); if (a->data.v == NULL) { return 0; } diff --git a/src/attributes/moved.c b/src/attributes/moved.c index 3da2a4c3b..c66a5489c 100644 --- a/src/attributes/moved.c +++ b/src/attributes/moved.c @@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int age_moved(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); --a->data.i; return a->data.i > 0; } diff --git a/src/attributes/movement.c b/src/attributes/movement.c index 874da5eb3..4d79039ef 100644 --- a/src/attributes/movement.c +++ b/src/attributes/movement.c @@ -67,7 +67,7 @@ void set_movement(attrib ** alist, int type) static int age_speedup(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); if (a->data.sa[0] > 0) { assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN); assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX); diff --git a/src/attributes/racename.c b/src/attributes/racename.c index b408cbf6a..c45fa3815 100644 --- a/src/attributes/racename.c +++ b/src/attributes/racename.c @@ -43,7 +43,7 @@ void set_racename(attrib ** palist, const char *name) attrib *a = a_find(*palist, &at_racename); if (!a && name) { a = a_add(palist, a_new(&at_racename)); - a->data.v = _strdup(name); + a->data.v = strdup(name); } else if (a && !name) { a_remove(palist, a); @@ -51,7 +51,7 @@ void set_racename(attrib ** palist, const char *name) else if (a) { if (strcmp(a->data.v, name) != 0) { free(a->data.v); - a->data.v = _strdup(name); + a->data.v = strdup(name); } } } diff --git a/src/attributes/raceprefix.c b/src/attributes/raceprefix.c index 15f0036c1..a87edfb80 100644 --- a/src/attributes/raceprefix.c +++ b/src/attributes/raceprefix.c @@ -41,7 +41,7 @@ void set_prefix(attrib ** ap, const char *str) free(a->data.v); } assert(a->type == &at_raceprefix); - a->data.v = _strdup(str); + a->data.v = strdup(str); } const char *get_prefix(attrib * a) @@ -53,7 +53,7 @@ const char *get_prefix(attrib * a) str = (char *)a->data.v; /* conversion of old prefixes */ if (strncmp(str, "prefix_", 7) == 0) { - ((attrib *)a)->data.v = _strdup(str + 7); + ((attrib *)a)->data.v = strdup(str + 7); free(str); str = (char *)a->data.v; } diff --git a/src/battle.c b/src/battle.c index ed83871ec..3b34cd162 100644 --- a/src/battle.c +++ b/src/battle.c @@ -440,7 +440,7 @@ static int get_row(const side * s, int row, const side * vs) /* every entry in the size[] array means someone trying to defend us. * 'retreat' is the number of rows falling. */ - result = _max(FIRST_ROW, row - retreat); + result = MAX(FIRST_ROW, row - retreat); return result; } @@ -600,12 +600,12 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking) if (u_race(u) == get_race(RC_ORC)) { int sword = effskill(u, SK_MELEE, 0); int spear = effskill(u, SK_SPEAR, 0); - skill = _max(sword, spear) - 3; + skill = MAX(sword, spear) - 3; if (attacking) { - skill = _max(skill, u_race(u)->at_default); + skill = MAX(skill, u_race(u)->at_default); } else { - skill = _max(skill, u_race(u)->df_default); + skill = MAX(skill, u_race(u)->df_default); } } else { @@ -685,7 +685,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type) /* only half against trolls */ if (skl > 0) { if (type == BONUS_SKILL) { - int dmg = _min(skl, 8); + int dmg = MIN(skl, 8); if (u_race(enemy.fighter->unit) == get_race(RC_TROLL)) { dmg = dmg / 4; } @@ -696,7 +696,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type) } else { skl = skl / 2; - return _min(skl, 4); + return MIN(skl, 4); } } } @@ -1008,7 +1008,7 @@ static void vampirism(troop at, int damage) if (gain > 0) { int maxhp = unit_max_hp(at.fighter->unit); at.fighter->person[at.index].hp = - _min(gain + at.fighter->person[at.index].hp, maxhp); + MIN(gain + at.fighter->person[at.index].hp, maxhp); } } } @@ -1203,15 +1203,15 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* TODO not sure if res could be > 1 here */ if (magic) { - da = (int)(_max(da * res, 0)); + da = (int)(MAX(da * res, 0)); } if (type != AT_COMBATSPELL && type != AT_SPELL) { if (rule_damage & DAMAGE_CRITICAL) { double kritchance = (sk * 3 - sd) / 200.0; - kritchance = _max(kritchance, 0.005); - kritchance = _min(0.9, kritchance); + kritchance = MAX(kritchance, 0.005); + kritchance = MIN(0.9, kritchance); while (chance(kritchance)) { if (bdebug) { @@ -1238,11 +1238,11 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* Skilldifferenzbonus */ if (rule_damage & DAMAGE_SKILL_BONUS) { - da += _max(0, (sk - sd) / DAMAGE_QUOTIENT); + da += MAX(0, (sk - sd) / DAMAGE_QUOTIENT); } } - rda = _max(da - ar, 0); + rda = MAX(da - ar, 0); if ((u_race(du)->battle_flags & BF_INV_NONMAGIC) && !magic) rda = 0; @@ -1275,7 +1275,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) } /* gibt R�stung +effect f�r duration Treffer */ if (me->typ == SHIELD_ARMOR) { - rda = _max(rda - me->effect, 0); + rda = MAX(rda - me->effect, 0); me->duration--; } } @@ -1474,7 +1474,7 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select) minrow = FIGHT_ROW; maxrow = BEHIND_ROW; } - minrow = _max(minrow, FIGHT_ROW); + minrow = MAX(minrow, FIGHT_ROW); enemies = count_enemies(b, af, minrow, maxrow, select); @@ -1574,7 +1574,7 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist) dt = select_enemy(at.fighter, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); } else { - mindist = _max(mindist, FIGHT_ROW); + mindist = MAX(mindist, FIGHT_ROW); dt = select_enemy(at.fighter, mindist, maxdist, SELECT_ADVANCE); } @@ -1735,7 +1735,7 @@ void do_combatmagic(battle * b, combatmagic_t was) level = eff_spelllevel(mage, sp, level, 1); if (sl > 0) - level = _min(sl, level); + level = MIN(sl, level); if (level < 0) { report_failed_spell(b, mage, sp); free_order(ord); @@ -1822,7 +1822,7 @@ static void do_combatspell(troop at) level = eff_spelllevel(caster, sp, fi->magic, 1); if ((sl = get_combatspelllevel(caster, 1)) > 0) - level = _min(level, sl); + level = MIN(level, sl); if (fumble(r, caster, sp, level)) { report_failed_spell(b, caster, sp); @@ -2056,7 +2056,7 @@ void dazzle(battle * b, troop * td) void damage_building(battle * b, building * bldg, int damage_abs) { - bldg->size = _max(1, bldg->size - damage_abs); + bldg->size = MAX(1, bldg->size - damage_abs); /* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb�ude passen. */ @@ -2332,7 +2332,7 @@ void do_regenerate(fighter * af) while (ta.index--) { struct person *p = af->person + ta.index; p->hp += effskill(au, SK_STAMINA, 0); - p->hp = _min(unit_max_hp(au), p->hp); + p->hp = MIN(unit_max_hp(au), p->hp); } } @@ -2391,10 +2391,10 @@ double fleechance(unit * u) if (u_race(u) == get_race(RC_HALFLING)) { c += 0.20; - c = _min(c, 0.90); + c = MIN(c, 0.90); } else { - c = _min(c, 0.75); + c = MIN(c, 0.75); } if (a != NULL) @@ -2518,7 +2518,7 @@ static void loot_items(fighter * corpse) float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */ int maxloot = (int)((float)itm->number * lootfactor); if (maxloot > 0) { - int i = _min(10, maxloot); + int i = MIN(10, maxloot); for (; i != 0; --i) { int loot = maxloot / i; @@ -2599,7 +2599,7 @@ static void battle_effects(battle * b, int dead_players) { region *r = b->region; int dead_peasants = - _min(rpeasants(r), (int)(dead_players * PopulationDamage())); + MIN(rpeasants(r), (int)(dead_players * PopulationDamage())); if (dead_peasants) { deathcounts(r, dead_peasants + dead_players); add_chaoscount(r, dead_peasants / 2); @@ -3092,7 +3092,7 @@ static void print_stats(battle * b) for (s = b->sides; s != b->sides + b->nsides; ++s) { if (!ql_empty(s->leader.fighters)) { - b->max_tactics = _max(b->max_tactics, s->leader.value); + b->max_tactics = MAX(b->max_tactics, s->leader.value); } } @@ -3258,7 +3258,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) /* change_effect wird in ageing gemacht */ /* Effekte von Artefakten */ - strongmen = _min(fig->unit->number, trollbelts(u)); + strongmen = MIN(fig->unit->number, trollbelts(u)); /* Hitpoints, Attack- und Defence-Boni f�r alle Personen */ for (i = 0; i < fig->alive; i++) { @@ -3448,7 +3448,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) else p_bonus += 3; } while (rnd >= 97); - bonus = _max(p_bonus, bonus); + bonus = MAX(p_bonus, bonus); } tactics += bonus; } @@ -3519,11 +3519,11 @@ static const char *simplename(region * r) const char *cp = rname(r, default_locale); for (i = 0; *cp && i != 16; ++i, ++cp) { int c = *(unsigned char *)cp; - while (c && !isalpha(c) && !isxspace(c)) { + while (c && !isalpha(c) && !isspace(c)) { ++cp; c = *(unsigned char *)cp; } - if (isxspace(c)) + if (isspace(c)) name[i] = '_'; else name[i] = *cp; @@ -3546,10 +3546,10 @@ battle *make_battle(region * r) bld->sizeleft = bld->size; if (battledebug) { - char zText[MAX_PATH]; - char zFilename[MAX_PATH]; + char zText[4096]; + char zFilename[4096]; join_path(basepath(), "battles", zText, sizeof(zText)); - if (_mkdir(zText) != 0) { + if (mkdir(zText, 0777) != 0) { log_error("could not create subdirectory for battle logs: %s", zText); battledebug = false; } @@ -4104,7 +4104,7 @@ static void battle_flee(battle * b) troop dt; int runners = 0; /* Flucht nicht bei mehr als 600 HP. Damit Wyrme t�tbar bleiben. */ - int runhp = _min(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status))); + int runhp = MIN(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status))); if (u->ship && fval(u->region->terrain, SEA_REGION)) { /* keine Flucht von Schiffen auf hoher See */ @@ -4147,7 +4147,7 @@ static void battle_flee(battle * b) if (fig->person[dt.index].flags & FL_PANICED) { ispaniced = EFFECT_PANIC_SPELL; } - if (chance(_min(fleechance(u) + ispaniced, 0.90))) { + if (chance(MIN(fleechance(u) + ispaniced, 0.90))) { ++runners; flee(dt); } diff --git a/src/battle.h b/src/battle.h index 007bda008..060906958 100644 --- a/src/battle.h +++ b/src/battle.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_BATTLE #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/bind_building.c b/src/bind_building.c index 3724d4db5..f8cf4e6df 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -92,7 +92,7 @@ static int tolua_building_set_info(lua_State * L) const char *info = tolua_tostring(L, 2, 0); free(self->display); if (info) - self->display = _strdup(info); + self->display = strdup(info); else self->display = NULL; return 0; diff --git a/src/bind_dict.c b/src/bind_dict.c index 32d3c498d..40f73690f 100644 --- a/src/bind_dict.c +++ b/src/bind_dict.c @@ -106,7 +106,7 @@ static int tolua_dict_set_string(lua_State * L) attrib *a = a_find(*self, &at_dict); variant val; - val.v = _strdup(value); + val.v = strdup(value); for (; a && a->type == &at_dict; a = a->next) { if (strcmp(dict_name(a), name) == 0) { diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index 3c07bb3b7..e4ae939f9 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -133,14 +133,14 @@ static int tolua_selected_regions(lua_State * L) static int tolua_state_open(lua_State * L) { - unused_arg(L); + UNUSED_ARG(L); state_open(); return 0; } static int tolua_state_close(lua_State * L) { - unused_arg(L); + UNUSED_ARG(L); state_close(current_state); return 0; } @@ -188,7 +188,7 @@ static void lua_paint_info(struct window *wnd, const struct state *st) break; else { size_t len = end - str; - int bytes = _min((int)len, size); + int bytes = MIN((int)len, size); mvwaddnstr(win, line++, 1, str, bytes); wclrtoeol(win); str = end + 1; diff --git a/src/bind_monsters.c b/src/bind_monsters.c index d7a3daab2..bd0ef39e3 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -74,7 +74,7 @@ static int fix_familiars(struct lua_State *L) free(mage->spellbook); mage->spellbook = 0; - _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name); + snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name); eq = get_equipment(buffer); if (eq) { equip_unit_mask(u, eq, EQUIP_SPELLS); diff --git a/src/bind_region.c b/src/bind_region.c index 1296e4a65..2e328dc96 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -615,7 +615,7 @@ static int tolua_plane_set_name(lua_State * L) const char *str = tolua_tostring(L, 2, 0); free(self->name); if (str) - self->name = _strdup(str); + self->name = strdup(str); else self->name = 0; return 0; diff --git a/src/bind_ship.c b/src/bind_ship.c index f1c1c412a..95006cf5f 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -94,7 +94,7 @@ static int tolua_ship_set_display(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); free(self->display); - self->display = _strdup(tolua_tostring(L, 2, 0)); + self->display = strdup(tolua_tostring(L, 2, 0)); return 0; } diff --git a/src/bind_storage.c b/src/bind_storage.c index a81a3baeb..d2b66f03d 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -100,7 +100,7 @@ static int tolua_storage_tostring(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); char name[64]; - _snprintf(name, sizeof(name), "", (void *)data, data->version); + snprintf(name, sizeof(name), "", (void *)data, data->version); lua_pushstring(L, name); return 1; } diff --git a/src/building_action.c b/src/building_action.c index 5c533f4d0..f72af4412 100644 --- a/src/building_action.c +++ b/src/building_action.c @@ -93,7 +93,7 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store) const char *fname = data->fname; const char *fparam = data->param; - unused_arg(owner); + UNUSED_ARG(owner); WRITE_TOK(store, fname); WRITE_TOK(store, fparam ? fparam : NULLSTRING); } @@ -116,7 +116,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data) b = 0; } else { - bd->fname = _strdup(name); + bd->fname = strdup(name); } READ_TOK(store, name, sizeof(name)); if (strcmp(name, "tnnL") == 0) { @@ -127,7 +127,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data) if (strcmp(name, NULLSTRING) == 0) bd->param = 0; else { - bd->param = _strdup(name); + bd->param = strdup(name); } if (result == 0 && !b) { return AT_READ_FAIL; @@ -146,8 +146,8 @@ void building_addaction(building * b, const char *fname, const char *param) { attrib *a = a_add(&b->attribs, a_new(&at_building_action)); building_action *data = (building_action *)a->data.v; - data->fname = _strdup(fname); + data->fname = strdup(fname); if (param) { - data->param = _strdup(param); + data->param = strdup(param); } } diff --git a/src/creport.c b/src/creport.c index eeb2a1202..bd9c97ec6 100644 --- a/src/creport.c +++ b/src/creport.c @@ -125,7 +125,7 @@ static const char *translate(const char *key, const char *value) } else t = malloc(sizeof(translation)); - t->key = _strdup(key); + t->key = strdup(key); t->value = value; t->next = translation_table[kk]; translation_table[kk] = t; @@ -361,7 +361,7 @@ static int cr_race(variant var, char *buffer, const void *userdata) static int cr_alliance(variant var, char *buffer, const void *userdata) { const alliance *al = (const alliance *)var.v; - unused_arg(userdata); + UNUSED_ARG(userdata); if (al != NULL) { sprintf(buffer, "%d", al->id); } @@ -372,7 +372,7 @@ static int cr_skill(variant var, char *buffer, const void *userdata) { const faction *report = (const faction *)userdata; skill_t sk = (skill_t)var.i; - unused_arg(userdata); + UNUSED_ARG(userdata); if (sk != NOSKILL) sprintf(buffer, "\"%s\"", translate(mkname("skill", skillnames[sk]), skillname(sk, @@ -385,7 +385,7 @@ static int cr_skill(variant var, char *buffer, const void *userdata) static int cr_order(variant var, char *buffer, const void *userdata) { order *ord = (order *)var.v; - unused_arg(userdata); + UNUSED_ARG(userdata); if (ord != NULL) { char cmd[ORDERSIZE]; char *wp = buffer; diff --git a/src/economy.c b/src/economy.c index 01954ff54..7edbbcb12 100644 --- a/src/economy.c +++ b/src/economy.c @@ -337,11 +337,11 @@ static int do_recruiting(recruitment * recruits, int available) int number, dec; double multi = 2.0 * rc->recruit_multi; - number = _min(req->qty, (int)(get / multi)); + number = MIN(req->qty, (int)(get / multi)); if (rc->recruitcost) { int afford = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, number * rc->recruitcost) / rc->recruitcost; - number = _min(number, afford); + number = MIN(number, afford); } if (u->number + number > UNIT_MAXSIZE) { ADDMSG(&u->faction->msgs, msg_feedback(u, req->ord, "error_unit_size", @@ -551,7 +551,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) if (recruitcost > 0) { int pooled = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, recruitcost * n); - n = _min(n, pooled / recruitcost); + n = MIN(n, pooled / recruitcost); } u->wants = n; @@ -990,12 +990,12 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) rring = get_resourcetype(R_RING_OF_NIMBLEFINGER); if (rring) { int dm = i_get(u->items, rring->itype); - amount += skill * _min(u->number, dm) * (roqf_factor() - 1); + amount += skill * MIN(u->number, dm) * (roqf_factor() - 1); } /* Schaffenstrunk: */ if ((dm = get_effect(u, oldpotiontype[P_DOMORE])) != 0) { - dm = _min(dm, u->number); + dm = MIN(dm, u->number); change_effect(u, oldpotiontype[P_DOMORE], -dm); amount += dm * skill; /* dm Personen produzieren doppelt */ } @@ -1091,7 +1091,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) } need = norders; - avail = _min(avail, norders); + avail = MIN(avail, norders); if (need > 0) { int use = 0; for (al = alist; al; al = al->next) @@ -1106,7 +1106,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) use += x; norders -= want; need -= x; - al->get = _min(al->want, al->get + (int)(x / al->save)); + al->get = MIN(al->want, al->get + (int)(x / al->save)); } } if (use) { @@ -1139,7 +1139,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) avail = 0; } - avail = _min(avail, norders); + avail = MIN(avail, norders); for (al = alist; al; al = al->next) { if (avail > 0) { int want = required(al->want, al->save); @@ -1149,7 +1149,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) ++x; avail -= x; norders -= want; - al->get = _min(al->want, (int)(x / al->save)); + al->get = MIN(al->want, (int)(x / al->save)); if (rdata->produce) { int use = required(al->get, al->save); if (use) @@ -1625,7 +1625,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) k -= a->data.i; } - n = _min(n, k); + n = MIN(n, k); if (!n) { cmistake(u, ord, 102, MSG_COMMERCE); @@ -1936,7 +1936,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) /* Ein Händler kann nur 10 Güter pro Talentpunkt verkaufen. */ - n = _min(n, u->number * 10 * effskill(u, SK_TRADE, 0)); + n = MIN(n, u->number * 10 * effskill(u, SK_TRADE, 0)); if (!n) { cmistake(u, ord, 54, MSG_COMMERCE); @@ -1966,11 +1966,11 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) if (o->type.ltype == ltype && o->unit->faction == u->faction) { int fpool = o->qty - get_pooled(o->unit, itype->rtype, GET_RESERVE, INT_MAX); - available -= _max(0, fpool); + available -= MAX(0, fpool); } } - n = _min(n, available); + n = MIN(n, available); if (n <= 0) { cmistake(u, ord, 264, MSG_COMMERCE); @@ -1995,7 +1995,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) k -= a->data.i; } - n = _min(n, k); + n = MIN(n, k); assert(n >= 0); /* die Menge der verkauften Güter merken */ a->data.i += n; @@ -2052,7 +2052,7 @@ static void expandstealing(region * r, request * stealorders) n = 10; } if (n > 0) { - n = _min(n, g_requests[j].unit->wants); + n = MIN(n, g_requests[j].unit->wants); use_pooled(u, rsilver, GET_ALL, n); g_requests[j].unit->n = n; change_money(g_requests[j].unit, n); @@ -2106,8 +2106,8 @@ static void plant(unit * u, int raw) return; } - n = _min(skill * u->number, n); - n = _min(raw, n); + n = MIN(skill * u->number, n); + n = MIN(raw, n); /* Für jedes Kraut Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) @@ -2152,14 +2152,14 @@ static void planttrees(unit * u, int raw) } /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ - raw = _min(raw, skill * u->number); + raw = MIN(raw, skill * u->number); n = get_pooled(u, rtype, GET_DEFAULT, raw); if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } - n = _min(raw, n); + n = MIN(raw, n); /* Für jeden Samen Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { @@ -2209,7 +2209,7 @@ static void breedtrees(unit * u, int raw) } /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ - raw = _min(skill * u->number, raw); + raw = MIN(skill * u->number, raw); n = get_pooled(u, rtype, GET_DEFAULT, raw); /* Samen prüfen */ if (n == 0) { @@ -2217,7 +2217,7 @@ static void breedtrees(unit * u, int raw) msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } - n = _min(raw, n); + n = MIN(raw, n); /* Für jeden Samen Talent*5% Erfolgschance. */ for (i = n; i > 0; i--) { @@ -2259,7 +2259,7 @@ static void breedhorses(unit * u) } effsk = effskill(u, SK_HORSE_TRAINING, 0); n = u->number * effsk; - n = _min(n, horses); + n = MIN(n, horses); for (c = 0; c < n; c++) { if (rng_int() % 100 < effsk) { @@ -2508,7 +2508,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) } } - i = _min(u->number, i_get(u->items, rring->itype)); + i = MIN(u->number, i_get(u->items, rring->itype)); if (i > 0) { n *= STEALINCOME * (u->number + i * (roqf_factor() - 1)); } @@ -2530,7 +2530,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - produceexp(u, SK_STEALTH, _min(n, u->number)); + produceexp(u, SK_STEALTH, MIN(n, u->number)); } /* ------------------------------------------------------------- */ @@ -2554,7 +2554,7 @@ static void expandentertainment(region * r) entertaining -= o->qty; /* Nur soviel PRODUCEEXP wie auch tatsächlich gemacht wurde */ - produceexp(u, SK_ENTERTAINMENT, _min(u->n, u->number)); + produceexp(u, SK_ENTERTAINMENT, MIN(u->n, u->number)); add_income(u, IC_ENTERTAIN, o->qty, u->n); fset(u, UFL_LONGACTION | UFL_NOTMOVING); } @@ -2605,7 +2605,7 @@ void entertain_cmd(unit * u, struct order *ord) max_e = getuint(); if (max_e != 0) { - u->wants = _min(u->wants, max_e); + u->wants = MIN(u->wants, max_e); } o = nextentertainer++; o->unit = u; @@ -2665,7 +2665,7 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork) if (blessedharvest_ct) { int happy = (int)curse_geteffect(get_curse(r->attribs, blessedharvest_ct)); - happy = _min(happy, jobs); + happy = MIN(happy, jobs); earnings += happy; } } @@ -2819,10 +2819,10 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) max = INT_MAX; } if (!playerrace(u_race(u))) { - u->wants = _min(income(u), max); + u->wants = MIN(income(u), max); } else { - u->wants = _min(n * effskill(u, SK_TAXING, 0) * taxperlevel, max); + u->wants = MIN(n * effskill(u, SK_TAXING, 0) * taxperlevel, max); } u2 = is_guarded(r, u); @@ -2893,12 +2893,12 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders) max = INT_MAX; } if (!playerrace(u_race(u))) { - u->wants = _min(income(u), max); + u->wants = MIN(income(u), max); } else { /* For player start with 20 Silver +10 every 5 level of close combat skill*/ - int skbonus = (_max(effskill(u, SK_MELEE, 0), effskill(u, SK_SPEAR, 0)) * 2 / 10) + 2; - u->wants = _min(n * skbonus * 10, max); + int skbonus = (MAX(effskill(u, SK_MELEE, 0), effskill(u, SK_SPEAR, 0)) * 2 / 10) + 2; + u->wants = MIN(n * skbonus * 10, max); } o = (request *)calloc(1, sizeof(request)); diff --git a/src/give.c b/src/give.c index 524a27017..4f8417bf2 100644 --- a/src/give.c +++ b/src/give.c @@ -156,7 +156,7 @@ struct order *ord) assert(itype != NULL); n = get_pooled(src, item2resource(itype), GET_SLACK | GET_POOLED_SLACK, want); - n = _min(want, n); + n = MIN(want, n); r = n; if (dest && src->faction != dest->faction && src->faction->age < GiveRestriction()) { @@ -772,7 +772,7 @@ void give_cmd(unit * u, order * ord) msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); return; } - n = _min(u->number, n); + n = MIN(u->number, n); msg = u2 ? give_men(n, u, u2, ord) : disband_men(n, u, ord); if (msg) { ADDMSG(&u->faction->msgs, msg); diff --git a/src/give.test.c b/src/give.test.c index f2b0d60a9..b6c845450 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -244,7 +244,7 @@ static void test_give_men_requires_contact(CuTest * tc) { CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); - _snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no)); + snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no)); ord = create_order(K_GIVE, env.f1->locale, cmd); test_clear_messages(env.f1); give_cmd(env.src, ord); @@ -316,7 +316,7 @@ static void test_give_cmd(CuTest * tc) { i_change(&env.src->items, env.itype, 10); - _snprintf(cmd, sizeof(cmd), "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); + snprintf(cmd, sizeof(cmd), "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); ord = create_order(K_GIVE, env.f1->locale, cmd); assert(ord); give_cmd(env.src, ord); @@ -338,7 +338,7 @@ static void test_give_herbs(CuTest * tc) { setup_give(&env); i_change(&env.src->items, env.itype, 10); - _snprintf(cmd, sizeof(cmd), "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); + snprintf(cmd, sizeof(cmd), "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); ord = create_order(K_GIVE, env.f1->locale, cmd); assert(ord); diff --git a/src/gmtool.c b/src/gmtool.c index 7aab2fea7..a8881abd9 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -427,7 +427,7 @@ static void paint_info_region(window * wnd, const state * st) int line = 0, maxline = getmaxy(win) - 2; map_region *mr = cursor_region(&st->display, &st->cursor); - unused_arg(st); + UNUSED_ARG(st); werase(win); wxborder(win); if (mr && mr->r) { @@ -1398,7 +1398,7 @@ int curses_readline(struct lua_State *L, char *buffer, size_t size, const char *prompt) { - unused_arg(L); + UNUSED_ARG(L); askstring(hstatus, prompt, buffer, size); return buffer[0] != 0; } diff --git a/src/guard.h b/src/guard.h index 4fb6cbf56..101369f40 100644 --- a/src/guard.h +++ b/src/guard.h @@ -2,6 +2,9 @@ #ifndef H_GUARD #define H_GUARD + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/items.c b/src/items.c index 6fbf957b3..6e995edaa 100644 --- a/src/items.c +++ b/src/items.c @@ -122,7 +122,7 @@ struct order *ord) double force; spell *sp = find_spell("antimagiczone"); attrib **ap = &r->attribs; - unused_arg(ord); + UNUSED_ARG(ord); assert(sp); /* Reduziert die Stärke jedes Spruchs um effect */ diff --git a/src/items/artrewards.c b/src/items/artrewards.c index 602841d23..23ab2119e 100644 --- a/src/items/artrewards.c +++ b/src/items/artrewards.c @@ -45,7 +45,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int age_peaceimmune(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } diff --git a/src/items/demonseye.c b/src/items/demonseye.c index ffc1c5179..563a16047 100644 --- a/src/items/demonseye.c +++ b/src/items/demonseye.c @@ -38,8 +38,8 @@ summon_igjarjuk(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { struct plane *p = rplane(u->region); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(amount); + UNUSED_ARG(itype); if (p != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", "")); return EUNUSABLE; diff --git a/src/items/speedsail.c b/src/items/speedsail.c index 8bdaa41ab..cb40e9a8c 100644 --- a/src/items/speedsail.c +++ b/src/items/speedsail.c @@ -42,8 +42,8 @@ use_speedsail(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { struct plane *p = rplane(u->region); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(amount); + UNUSED_ARG(itype); if (p != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", "")); } diff --git a/src/items/weapons.c b/src/items/weapons.c index 1806e61a0..a23110a81 100644 --- a/src/items/weapons.c +++ b/src/items/weapons.c @@ -106,7 +106,7 @@ int *casualties) } enemies = count_enemies(b, af, FIGHT_ROW, FIGHT_ROW, SELECT_ADVANCE); - enemies = _min(enemies, CATAPULT_ATTACKS); + enemies = MIN(enemies, CATAPULT_ATTACKS); if (enemies == 0) { return true; /* allow further attacks */ } diff --git a/src/items/xerewards.c b/src/items/xerewards.c index ab5226a32..a6d1ad2ea 100644 --- a/src/items/xerewards.c +++ b/src/items/xerewards.c @@ -72,7 +72,7 @@ struct order *ord) } for (i = 0; i != amount; ++i) { - sp += _max(25, max_spellpoints(u->region, u) / 2); + sp += MAX(25, max_spellpoints(u->region, u) / 2); change_spellpoints(u, sp); } diff --git a/src/json.c b/src/json.c index 10322fe3f..0a78a3fa9 100644 --- a/src/json.c +++ b/src/json.c @@ -73,7 +73,7 @@ int json_export(stream * out, int flags) { cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject()); for (p = planes; p; p = p->next) { cJSON *data; - _snprintf(id, sizeof(id), "%d", p->id); + snprintf(id, sizeof(id), "%d", p->id); cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", p->minx); cJSON_AddNumberToObject(data, "y", p->miny); @@ -85,7 +85,7 @@ int json_export(stream * out, int flags) { cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject()); for (r = regions; r; r = r->next) { cJSON *data; - _snprintf(id, sizeof(id), "%d", r->uid); + snprintf(id, sizeof(id), "%d", r->uid); cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "y", r->y); diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 36d054323..b53c46dc7 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -82,7 +82,7 @@ alliance *new_alliance(int id, const char *name) { al = calloc(1, sizeof(alliance)); al->id = id; if (name) { - al->name = _strdup(name); + al->name = strdup(name); } else { al->flags |= ALF_NON_ALLIED; @@ -446,7 +446,7 @@ void alliance_setname(alliance * self, const char *name) { free(self->name); if (name) - self->name = _strdup(name); + self->name = strdup(name); else self->name = NULL; } diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 5a5a5b1c3..759d556f4 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -76,7 +76,7 @@ int AllianceAuto(void) const char *str = config_get("alliance.auto"); value = 0; if (str != NULL) { - char *sstr = _strdup(str); + char *sstr = strdup(str); char *tok = strtok(sstr, " "); while (tok) { value |= ally_flag(tok, -1); @@ -136,7 +136,7 @@ int HelpMask(void) if (config_changed(&config)) { const char *str = config_get("rules.help.mask"); if (str != NULL) { - char *sstr = _strdup(str); + char *sstr = strdup(str); char *tok = strtok(sstr, " "); while (tok) { rule |= ally_flag(tok, -1); @@ -156,7 +156,7 @@ static int AllianceRestricted(void) const char *str = config_get("alliance.restricted"); int rule = 0; if (str != NULL) { - char *sstr = _strdup(str); + char *sstr = strdup(str); char *tok = strtok(sstr, " "); while (tok) { rule |= ally_flag(tok, -1); diff --git a/src/kernel/build.c b/src/kernel/build.c index b5a1b3417..dff51cf6c 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -123,11 +123,11 @@ static void destroy_road(unit * u, int nmax, struct order *ord) } road = rroad(r, d); - n = _min(n, road); + n = MIN(n, road); if (n != 0) { region *r2 = rconnect(r, d); int willdo = effskill(u, SK_ROAD_BUILDING, 0) * u->number; - willdo = _min(willdo, n); + willdo = MIN(willdo, n); if (willdo == 0) { /* TODO: error message */ } @@ -327,7 +327,7 @@ void build_road(unit * u, int size, direction_t d) } if (size > 0) - left = _min(size, left); + left = MIN(size, left); /* baumaximum anhand der rohstoffe */ if (u_race(u) == get_race(RC_STONEGOLEM)) { n = u->number * GOLEM_STONE; @@ -339,7 +339,7 @@ void build_road(unit * u, int size, direction_t d) return; } } - left = _min(n, left); + left = MIN(n, left); /* n = maximum by skill. try to maximize it */ n = u->number * effsk; @@ -347,7 +347,7 @@ void build_road(unit * u, int size, direction_t d) const resource_type *ring = get_resourcetype(R_RING_OF_NIMBLEFINGER); item *itm = ring ? *i_find(&u->items, ring->itype) : 0; if (itm != NULL && itm->number > 0) { - int rings = _min(u->number, itm->number); + int rings = MIN(u->number, itm->number); n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; } } @@ -355,15 +355,15 @@ void build_road(unit * u, int size, direction_t d) int dm = get_effect(u, oldpotiontype[P_DOMORE]); if (dm != 0) { int todo = (left - n + effsk - 1) / effsk; - todo = _min(todo, u->number); - dm = _min(dm, todo); + todo = MIN(todo, u->number); + dm = MIN(dm, todo); change_effect(u, oldpotiontype[P_DOMORE], -dm); n += dm * effsk; } /* Auswirkung Schaffenstrunk */ } /* make minimum of possible and available: */ - n = _min(left, n); + n = MIN(left, n); /* n is now modified by several special effects, so we have to * minimize it again to make sure the road will not grow beyond @@ -380,7 +380,7 @@ void build_road(unit * u, int size, direction_t d) else { use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n); /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - produceexp(u, SK_ROAD_BUILDING, _min(n, u->number)); + produceexp(u, SK_ROAD_BUILDING, MIN(n, u->number)); } ADDMSG(&u->faction->msgs, msg_message("buildroad", "region unit size", r, u, n)); @@ -486,7 +486,7 @@ int build(unit * u, const construction * ctype, int completed, int want) if (dm != 0) { /* Auswirkung Schaffenstrunk */ - dm = _min(dm, u->number); + dm = MIN(dm, u->number); change_effect(u, oldpotiontype[P_DOMORE], -dm); skills += dm * effsk; } @@ -545,7 +545,7 @@ int build(unit * u, const construction * ctype, int completed, int want) item *itm = ring ? *i_find(&u->items, ring->itype) : 0; int i = itm ? itm->number : 0; if (i > 0) { - int rings = _min(u->number, i); + int rings = MIN(u->number, i); n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; } } @@ -553,7 +553,7 @@ int build(unit * u, const construction * ctype, int completed, int want) if (want < n) n = want; if (type->maxsize > 0) { - n = _min(type->maxsize - completed, n); + n = MIN(type->maxsize - completed, n); if (type->improvement == NULL) { want = n; } @@ -626,7 +626,7 @@ int build(unit * u, const construction * ctype, int completed, int want) completed = completed + n; } /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - produceexp(u, ctype->skill, _min(made, u->number)); + produceexp(u, ctype->skill, MIN(made, u->number)); return made; } @@ -671,7 +671,7 @@ int maxbuild(const unit * u, const construction * cons) return 0; } else - maximum = _min(maximum, have / need); + maximum = MIN(maximum, have / need); } return maximum; } @@ -879,7 +879,7 @@ static void build_ship(unit * u, ship * sh, int want) } if (sh->damage && can) { - int repair = _min(sh->damage, can * DAMAGE_SCALE); + int repair = MIN(sh->damage, can * DAMAGE_SCALE); n += repair / DAMAGE_SCALE; if (repair % DAMAGE_SCALE) ++n; @@ -923,7 +923,7 @@ order * ord) return; } if (want > 0) - want = _min(want, msize); + want = MIN(want, msize); else want = msize; @@ -982,7 +982,7 @@ void continue_ship(unit * u, int want) return; } if (want > 0) - want = _min(want, msize); + want = MIN(want, msize); else want = msize; diff --git a/src/kernel/building.c b/src/kernel/building.c index 8d76df030..fa7fe8688 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -127,7 +127,7 @@ building_type *bt_get_or_create(const char *name) building_type *btype = bt_find_i(name); if (btype == NULL) { btype = calloc(sizeof(building_type), 1); - btype->_name = _strdup(name); + btype->_name = strdup(name); btype->auraregen = 1.0; btype->maxsize = -1; btype->capacity = 1; @@ -143,7 +143,7 @@ int buildingcapacity(const building * b) { if (b->type->capacity >= 0) { if (b->type->maxcapacity >= 0) { - return _min(b->type->maxcapacity, b->size * b->type->capacity); + return MIN(b->type->maxcapacity, b->size * b->type->capacity); } return b->size * b->type->capacity; } @@ -420,7 +420,7 @@ building *new_building(const struct building_type * btype, region * r, } assert(bname); slprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no)); - b->name = _strdup(bname); + b->name = strdup(bname); return b; } @@ -619,7 +619,7 @@ void building_setname(building * self, const char *name) { free(self->name); if (name) - self->name = _strdup(name); + self->name = strdup(name); else self->name = NULL; } @@ -779,7 +779,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) /* Godcurse: Income -10 */ ctype = ct_find("godcursezone"); if (ctype && curse_active(get_curse(r->attribs, ctype))) { - wage = _max(0, wage - 10); + wage = MAX(0, wage - 10); } /* Bei einer D�rre verdient man nur noch ein Viertel */ diff --git a/src/kernel/building.h b/src/kernel/building.h index 92b006b98..235c2d806 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -23,6 +23,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index d15c82c8e..3b296a6fe 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -22,7 +22,7 @@ static void test_register_building(CuTest * tc) test_cleanup(); btype = (building_type *)calloc(sizeof(building_type), 1); - btype->_name = _strdup("herp"); + btype->_name = strdup("herp"); CuAssertIntEquals(tc, true, bt_changed(&cache)); CuAssertIntEquals(tc, false, bt_changed(&cache)); bt_register(btype); diff --git a/src/kernel/config.c b/src/kernel/config.c index f33303ead..1f3cd92b2 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -92,6 +92,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include struct settings global = { "Eressea", /* gamename */ @@ -362,7 +363,7 @@ void init_locale(struct locale *lang) str = "gwyrrd illaun draig cerddor tybied"; } - sstr = _strdup(str); + sstr = strdup(str); tok = strtok(sstr, " "); while (tok) { const char *name; @@ -473,7 +474,7 @@ int check_param(const struct param *p, const char *key, const char *searchvalue) if (!value) { return 0; } - char *p_value = _strdup(value); + char *p_value = strdup(value); const char *delimiter = " ,;"; char *v = strtok(p_value, delimiter); @@ -536,7 +537,7 @@ static const char * relpath(char *buf, size_t sz, const char *path) { static const char *g_datadir; const char *datapath(void) { - static char zText[MAX_PATH]; + static char zText[4096]; if (g_datadir) return g_datadir; return relpath(zText, sizeof(zText), "data"); @@ -550,7 +551,7 @@ void set_datapath(const char *path) static const char *g_reportdir; const char *reportpath(void) { - static char zText[MAX_PATH]; + static char zText[4096]; if (g_reportdir) return g_reportdir; return relpath(zText, sizeof(zText), "reports"); @@ -563,12 +564,12 @@ void set_reportpath(const char *path) int create_directories(void) { int err; - err = _mkdir(datapath()); + err = mkdir(datapath(), 0777); if (err) { if (errno == EEXIST) errno = 0; else return err; } - err = _mkdir(reportpath()); + err = mkdir(reportpath(), 0777); if (err && errno == EEXIST) { errno = 0; } diff --git a/src/kernel/config.h b/src/kernel/config.h index 91d5d576f..096d54da4 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -25,6 +25,7 @@ extern "C" { /* this should always be the first thing included after platform.h */ #include +#include #include "types.h" struct param; diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 6eccf1f0c..405b013ee 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -131,7 +131,7 @@ static connection **get_borders_i(const region * r1, const region * r2) int key = reg_hashkey(r1); int k2 = reg_hashkey(r2); - key = _min(k2, key) % BORDER_MAXHASH; + key = MIN(k2, key) % BORDER_MAXHASH; bp = &borders[key]; while (*bp) { connection *b = *bp; @@ -258,31 +258,31 @@ void b_write(const connection * b, storage * store) bool b_transparent(const connection * b, const struct faction *f) { - unused_arg(b); - unused_arg(f); + UNUSED_ARG(b); + UNUSED_ARG(f); return true; } bool b_opaque(const connection * b, const struct faction * f) { - unused_arg(b); - unused_arg(f); + UNUSED_ARG(b); + UNUSED_ARG(f); return false; } bool b_blockall(const connection * b, const unit * u, const region * r) { - unused_arg(u); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(r); + UNUSED_ARG(b); return true; } bool b_blocknone(const connection * b, const unit * u, const region * r) { - unused_arg(u); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(r); + UNUSED_ARG(b); return false; } @@ -294,39 +294,39 @@ bool b_rvisible(const connection * b, const region * r) bool b_fvisible(const connection * b, const struct faction * f, const region * r) { - unused_arg(r); - unused_arg(f); - unused_arg(b); + UNUSED_ARG(r); + UNUSED_ARG(f); + UNUSED_ARG(b); return true; } bool b_uvisible(const connection * b, const unit * u) { - unused_arg(u); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(b); return true; } bool b_rinvisible(const connection * b, const region * r) { - unused_arg(r); - unused_arg(b); + UNUSED_ARG(r); + UNUSED_ARG(b); return false; } bool b_finvisible(const connection * b, const struct faction * f, const region * r) { - unused_arg(r); - unused_arg(f); - unused_arg(b); + UNUSED_ARG(r); + UNUSED_ARG(f); + UNUSED_ARG(b); return false; } bool b_uinvisible(const connection * b, const unit * u) { - unused_arg(u); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(b); return false; } @@ -380,9 +380,9 @@ static const char *b_namewall(const connection * b, const region * r, { const char *bname = "wall"; - unused_arg(f); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(f); + UNUSED_ARG(r); + UNUSED_ARG(b); if (gflags & GF_ARTICLE) bname = "a_wall"; if (gflags & GF_PURE) @@ -421,9 +421,9 @@ border_type bt_noway = { static const char *b_namefogwall(const connection * b, const region * r, const struct faction *f, int gflags) { - unused_arg(f); - unused_arg(b); - unused_arg(r); + UNUSED_ARG(f); + UNUSED_ARG(b); + UNUSED_ARG(r); if (gflags & GF_PURE) return "fogwall"; if (gflags & GF_ARTICLE) @@ -434,7 +434,7 @@ static const char *b_namefogwall(const connection * b, const region * r, static bool b_blockfogwall(const connection * b, const unit * u, const region * r) { - unused_arg(b); + UNUSED_ARG(b); if (!u) return true; return (bool)(effskill(u, SK_PERCEPTION, r) > 4); /* Das ist die alte Nebelwand */ @@ -459,8 +459,8 @@ static const char *b_nameillusionwall(const connection * b, const region * r, const struct faction *f, int gflags) { int fno = b->data.i; - unused_arg(b); - unused_arg(r); + UNUSED_ARG(b); + UNUSED_ARG(r); if (gflags & GF_PURE) return (f && fno == f->no) ? "illusionwall" : "wall"; if (gflags & GF_ARTICLE) { @@ -496,7 +496,7 @@ static const char *b_nameroad(const connection * b, const region * r, int local = (r == b->from) ? b->data.sa[0] : b->data.sa[1]; static char buffer[64]; - unused_arg(f); + UNUSED_ARG(f); if (gflags & GF_PURE) return "road"; if (gflags & GF_ARTICLE) { @@ -512,7 +512,7 @@ static const char *b_nameroad(const connection * b, const region * r, } } else { - int percent = _max(1, 100 * local / r->terrain->max_road); + int percent = MAX(1, 100 * local / r->terrain->max_road); if (local) { slprintf(buffer, sizeof(buffer), LOC(f->locale, mkname("border", "a_road_percent")), percent); diff --git a/src/kernel/connection.h b/src/kernel/connection.h index 7eef0f52a..80177c638 100644 --- a/src/kernel/connection.h +++ b/src/kernel/connection.h @@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_BORDER #include - +#include #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 123f858f5..22b87e738 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -109,7 +109,7 @@ int curse_age(attrib * a, void *owner) curse *c = (curse *)a->data.v; int result = 0; - unused_arg(owner); + UNUSED_ARG(owner); c_clearflag(c, CURSE_ISNEW); if (c_flags(c) & CURSE_NOAGE) { @@ -122,7 +122,7 @@ int curse_age(attrib * a, void *owner) c->duration = 0; } else if (c->duration != INT_MAX) { - c->duration = _max(0, c->duration - 1); + c->duration = MAX(0, c->duration - 1); } return (c->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -348,7 +348,7 @@ const curse_type *ct_find(const char *c) return type; } else { - size_t k = _min(c_len, strlen(type->cname)); + size_t k = MIN(c_len, strlen(type->cname)); if (!memcmp(c, type->cname, k)) { return type; } @@ -507,7 +507,7 @@ int get_cursedmen(unit * u, const curse * c) cursedmen = c->data.i; } - return _min(u->number, cursedmen); + return MIN(u->number, cursedmen); } /* setzt die Anzahl der betroffenen Personen auf cursedmen */ @@ -596,7 +596,7 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, /* es gibt schon eins diese Typs */ if (c && ct->mergeflags != NO_MERGE) { if (ct->mergeflags & M_DURATION) { - c->duration = _max(c->duration, duration); + c->duration = MAX(c->duration, duration); } if (ct->mergeflags & M_SUMDURATION) { c->duration += duration; @@ -605,10 +605,10 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, c->effect += effect; } if (ct->mergeflags & M_MAXEFFECT) { - c->effect = _max(c->effect, effect); + c->effect = MAX(c->effect, effect); } if (ct->mergeflags & M_VIGOUR) { - c->vigour = _max(vigour, c->vigour); + c->vigour = MAX(vigour, c->vigour); } if (ct->mergeflags & M_VIGOUR_ADD) { c->vigour = vigour + c->vigour; @@ -792,9 +792,9 @@ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, { struct message *msg; - unused_arg(typ); - unused_arg(self); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(self); + UNUSED_ARG(obj); msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no); if (msg == NULL) { diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 29498f4d2..4cff4f9a1 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "objtypes.h" +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 8266ada9a..1587e7531 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -47,7 +47,7 @@ equipment *create_equipment(const char *eqname) int i = eq ? strcmp(eq->name, eqname) : 1; if (i > 0) { eq = (equipment *)calloc(1, sizeof(equipment)); - eq->name = _strdup(eqname); + eq->name = strdup(eqname); eq->next = *eqp; memset(eq->skills, 0, sizeof(eq->skills)); *eqp = eq; @@ -78,7 +78,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value) { if (eq != NULL) { if (value != NULL) { - eq->skills[sk] = _strdup(value); + eq->skills[sk] = strdup(value); } else if (eq->skills[sk]) { free(eq->skills[sk]); @@ -98,7 +98,7 @@ void equipment_addspell(equipment * eq, const char * name, int level) lazy_spell *ls = malloc(sizeof(lazy_spell)); ls->sp = NULL; ls->level = level; - ls->name = _strdup(name); + ls->name = strdup(name); ql_push(&eq->spells, ls); } } @@ -115,7 +115,7 @@ equipment_setitem(equipment * eq, const item_type * itype, const char *value) if (idata == NULL) { idata = (itemdata *)malloc(sizeof(itemdata)); idata->itype = itype; - idata->value = _strdup(value); + idata->value = strdup(value); idata->next = eq->items; eq->items = idata; } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index d332bf604..2c6d4d244 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -274,7 +274,7 @@ faction *addfaction(const char *email, const char *password, fhash(f); slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no)); - f->name = _strdup(buf); + f->name = strdup(buf); if (!f->race) { log_warning("creating a faction that has no race", itoa36(f->no)); @@ -523,7 +523,7 @@ void faction_setname(faction * self, const char *name) { free(self->name); if (name) - self->name = _strdup(name); + self->name = strdup(name); } const char *faction_getemail(const faction * self) @@ -535,7 +535,7 @@ void faction_setemail(faction * self, const char *email) { free(self->email); if (email) - self->email = _strdup(email); + self->email = strdup(email); } const char *faction_getbanner(const faction * self) @@ -547,7 +547,7 @@ void faction_setbanner(faction * self, const char *banner) { free(self->banner); if (banner) - self->banner = _strdup(banner); + self->banner = strdup(banner); } void faction_setpassword(faction * f, const char *pwhash) @@ -555,7 +555,7 @@ void faction_setpassword(faction * f, const char *pwhash) assert(pwhash); // && pwhash[0] == '$'); free(f->_password); - f->_password = _strdup(pwhash); + f->_password = strdup(pwhash); } bool valid_race(const struct faction *f, const struct race *rc) diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 82ae89ea4..de55ad1fe 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "skill.h" #include "types.h" #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/group.c b/src/kernel/group.c index 8753531a3..06f2f9f49 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -57,8 +57,8 @@ group *new_group(faction * f, const char *name, int gid) gp = &(*gp)->next; *gp = g; - maxgid = _max(gid, maxgid); - g->name = _strdup(name); + maxgid = MAX(gid, maxgid); + g->name = strdup(name); g->gid = gid; g->nexthash = ghash[index]; diff --git a/src/kernel/item.c b/src/kernel/item.c index 53fff79ab..441346be8 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -156,7 +156,7 @@ const char *resourcename(const resource_type * rtype, int flags) } if (flags & NMF_PLURAL) { static char name[64]; // FIXME: static return value - _snprintf(name, sizeof(name), "%s_p", rtype->_name); + snprintf(name, sizeof(name), "%s_p", rtype->_name); return name; } return rtype->_name; @@ -186,7 +186,7 @@ resource_type *rt_get_or_create(const char *name) { perror("resource_type allocation failed"); } else { - rtype->_name = _strdup(name); + rtype->_name = strdup(name); rt_register(rtype); return rt_find(name); } @@ -282,8 +282,8 @@ weapon_type *new_weapontype(item_type * itype, wtype = calloc(sizeof(weapon_type), 1); if (damage) { - wtype->damage[0] = _strdup(damage[0]); - wtype->damage[1] = _strdup(damage[1]); + wtype->damage[0] = strdup(damage[0]); + wtype->damage[1] = strdup(damage[1]); } wtype->defmod = defmod; wtype->flags |= wflags; @@ -342,7 +342,7 @@ void it_set_appearance(item_type *itype, const char *appearance) { assert(itype); assert(itype->rtype); if (appearance) { - itype->_appearance[0] = _strdup(appearance); + itype->_appearance[0] = strdup(appearance); itype->_appearance[1] = strcat(strcpy((char *)malloc(strlen((char *)appearance) + 3), (char *)appearance), "_p"); } else { itype->_appearance[0] = 0; @@ -676,9 +676,9 @@ struct order *ord) direction_t d; message *msg = msg_message("meow", ""); - unused_arg(ord); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(ord); + UNUSED_ARG(amount); + UNUSED_ARG(itype); add_message(&u->region->msgs, msg); for (d = 0; d < MAXDIRECTIONS; d++) { @@ -717,7 +717,7 @@ struct order *ord) c = create_curse(u, &u->attribs, ct_find("skillmod"), power, duration, effect, u->number); c->data.i = SK_TACTICS; - unused_arg(ord); + UNUSED_ARG(ord); } use_pooled(u, itype->rtype, GET_DEFAULT, amount); ADDMSG(&u->faction->msgs, msg_message("use_tacticcrystal", @@ -746,14 +746,14 @@ mod_elves_only(const unit * u, const region * r, skill_t sk, int value) { if (u_race(u) == get_race(RC_ELF)) return value; - unused_arg(r); + UNUSED_ARG(r); return -118; } static int mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value) { - unused_arg(r); + UNUSED_ARG(r); if (u_race(u) == get_race(RC_DWARF) || (u_race(u)->flags & RCF_IRONGOLEM)) { return value; } @@ -764,7 +764,7 @@ static int heal(unit * user, int effect) { int req = unit_max_hp(user) * user->number - user->hp; if (req > 0) { - req = _min(req, effect); + req = MIN(req, effect); effect -= req; user->hp += req; } diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index d12238566..509470406 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -224,7 +224,7 @@ static void json_terrain_production(cJSON *json, terrain_production *prod) { if (dst) { free(*dst); assert(child->type == cJSON_String); - *dst = _strdup(child->valuestring); + *dst = strdup(child->valuestring); } } } @@ -453,7 +453,7 @@ static void json_race(cJSON *json, race *rc) { switch (child->type) { case cJSON_String: if (strcmp(child->string, "damage") == 0) { - rc->def_damage = _strdup(child->valuestring); + rc->def_damage = strdup(child->valuestring); } break; case cJSON_Number: @@ -534,7 +534,7 @@ static void disable_feature(const char *str) { enable_keyword(k, false); return; } - _snprintf(name, sizeof(name), "%s.enabled", str); + snprintf(name, sizeof(name), "%s.enabled", str); log_info("disable feature %s\n", name); config_set(name, "0"); } @@ -594,7 +594,7 @@ static void json_spells(cJSON *json) { sp->fumble = (fumble_f)get_function(item->valuestring); } else if (strcmp(item->string, "syntax") == 0) { - sp->syntax = _strdup(item->valuestring); + sp->syntax = strdup(item->valuestring); } } } @@ -796,10 +796,10 @@ static void json_settings(cJSON *json) { else { char value[32]; if (child->type == cJSON_Number && child->valuedouble && child->valueintvaluedouble) { - _snprintf(value, sizeof(value), "%f", child->valuedouble); + snprintf(value, sizeof(value), "%f", child->valuedouble); } else { - _snprintf(value, sizeof(value), "%d", child->valueint); + snprintf(value, sizeof(value), "%d", child->valueint); } config_set(child->string, value); } diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 566e9bdef..89278624f 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -212,7 +212,7 @@ caddmessage(region * r, faction * f, const char *s, msg_t mtype, int level) { message *m = NULL; - unused_arg(level); + UNUSED_ARG(level); switch (mtype) { case MSG_INCOME: assert(f); @@ -275,7 +275,7 @@ message * msg_error(const unit * u, struct order *ord, int mno) { message * cmistake(const unit * u, struct order *ord, int mno, int mtype) { message * result; - unused_arg(mtype); + UNUSED_ARG(mtype); result = msg_error(u, ord, mno); ADDMSG(&u->faction->msgs, result); return result; diff --git a/src/kernel/order.c b/src/kernel/order.c index 3fd1dc92f..776190b67 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -405,7 +405,7 @@ order *parse_order(const char *s, const struct locale * lang) } } if (kwd != NOKEYWORD) { - while (isxspace(*(unsigned char *)sptr)) ++sptr; + while (isspace(*(unsigned char *)sptr)) ++sptr; s = sptr; return create_order_i(kwd, s, persistent, lang); } diff --git a/src/kernel/plane.c b/src/kernel/plane.c index 7e9650d13..0b2fdc0d3 100644 --- a/src/kernel/plane.c +++ b/src/kernel/plane.c @@ -234,7 +234,7 @@ plane *create_new_plane(int id, const char *name, int minx, int maxx, int miny, pl->next = NULL; pl->id = id; if (name) - pl->name = _strdup(name); + pl->name = strdup(name); pl->minx = minx; pl->maxx = maxx; pl->miny = miny; diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 5609d211f..702f86e0f 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -168,7 +168,7 @@ int count) use = have; else if (rtype->itype && mode & (GET_SLACK | GET_RESERVE)) { int reserve = get_reservation(u, rtype->itype); - int slack = _max(0, have - reserve); + int slack = MAX(0, have - reserve); if (mode & GET_RESERVE) use = have - slack; else if (mode & GET_SLACK) @@ -209,18 +209,18 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) } if ((mode & GET_SLACK) && (mode & GET_RESERVE)) { - n = _min(use, have); + n = MIN(use, have); } else if (rtype->itype) { int reserve = get_reservation(u, rtype->itype); - int slack = _max(0, have - reserve); + int slack = MAX(0, have - reserve); if (mode & GET_RESERVE) { n = have - slack; - n = _min(use, n); + n = MIN(use, n); change_reservation(u, rtype->itype, -n); } else if (mode & GET_SLACK) { - n = _min(use, slack); + n = MIN(use, slack); } } if (n > 0) { diff --git a/src/kernel/race.c b/src/kernel/race.c index decc3b7bb..a78a9e340 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -241,7 +241,7 @@ race *rc_create(const char *zName) log_error("race '%s' has an invalid name. remove spaces\n", zName); assert(strchr(zName, ' ') == NULL); } - rc->_name = _strdup(zName); + rc->_name = strdup(zName); rc->precombatspell = NULL; rc->attack[0].type = AT_COMBATSPELL; @@ -288,7 +288,7 @@ const char* rc_name(const race * rc, name_t n, char *name, size_t size) { default: assert(!"invalid name_t enum in rc_name_s"); } if (postfix) { - _snprintf(name, size, "race::%s%s", rc->_name, postfix); + snprintf(name, size, "race::%s%s", rc->_name, postfix); return name; } return NULL; diff --git a/src/kernel/region.c b/src/kernel/region.c index d937f8b68..cade135c7 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -138,7 +138,7 @@ int region_maxworkers(const region *r) { int size = production(r); int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE; - return _max(size - treespace, _min(size / 10, 200)); + return MAX(size - treespace, MIN(size / 10, 200)); } int deathcount(const region * r) @@ -403,7 +403,7 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height) int dx = x1 - x2; int dy = y1 - y2; int result, dist; - int mindist = _min(width, height) >> 1; + int mindist = MIN(width, height) >> 1; /* Bei negativem dy am Ursprung spiegeln, das veraendert * den Abstand nicht @@ -426,13 +426,13 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height) if (result <= mindist) return result; } - dist = _max(dx, height - dy); + dist = MAX(dx, height - dy); if (dist >= 0 && dist < result) { result = dist; if (result <= mindist) return result; } - dist = _max(width - dx, dy); + dist = MAX(width - dx, dy); if (dist >= 0 && dist < result) result = dist; return result; @@ -1215,7 +1215,7 @@ void terraform_region(region * r, const terrain_type * terrain) if (!fval(r, RF_CHAOTIC)) { int peasants; peasants = (region_maxworkers(r) * (20 + dice_rand("6d10"))) / 100; - rsetpeasants(r, _max(100, peasants)); + rsetpeasants(r, MAX(100, peasants)); rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL, INT_MAX) + 1) + rng_int() % 5)); } @@ -1395,7 +1395,7 @@ faction *update_owners(region * r) else if (f || new_owner->faction != region_get_last_owner(r)) { alliance *al = region_get_alliance(r); if (al && new_owner->faction->alliance == al) { - int morale = _max(0, region_get_morale(r) - MORALE_TRANSFER); + int morale = MAX(0, region_get_morale(r) - MORALE_TRANSFER); region_set_morale(r, morale, turn); } else { @@ -1418,7 +1418,7 @@ faction *update_owners(region * r) void region_setinfo(struct region *r, const char *info) { free(r->display); - r->display = info ? _strdup(info) : 0; + r->display = info ? strdup(info) : 0; } const char *region_getinfo(const region * r) @@ -1430,7 +1430,7 @@ void region_setname(struct region *r, const char *name) { if (r->land) { free(r->land->name); - r->land->name = name ? _strdup(name) : 0; + r->land->name = name ? strdup(name) : 0; } } diff --git a/src/kernel/region.h b/src/kernel/region.h index fcc5f08b0..9fa1a2daa 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_REGION #include +#include #include "types.h" #include "direction.h" diff --git a/src/kernel/resources.c b/src/kernel/resources.c index e064150e6..e32c7ad55 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -111,7 +111,7 @@ static void terraform_default(struct rawmaterial *res, const region * r) res->amount = (int)(res->amount * modifier); /* random adjustment, +/- 91% */ if (res->amount < 1) res->amount = 1; - unused_arg(r); + UNUSED_ARG(r); } #ifdef RANDOM_CHANGE @@ -205,7 +205,7 @@ struct rawmaterial_type *rmt_create(const struct resource_type *rtype, const char *name) { rawmaterial_type *rmtype = malloc(sizeof(rawmaterial_type)); - rmtype->name = _strdup(name); + rmtype->name = strdup(name); rmtype->rtype = rtype; rmtype->terraform = terraform_default; rmtype->update = NULL; diff --git a/src/kernel/save.c b/src/kernel/save.c index 2f157af41..de6f8aac1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -436,7 +436,7 @@ void read_planes(gamedata *data) { } pl->id = id; READ_STR(store, name, sizeof(name)); - pl->name = _strdup(name); + pl->name = strdup(name); READ_INT(store, &pl->minx); READ_INT(store, &pl->maxx); READ_INT(store, &pl->miny); @@ -668,7 +668,7 @@ unit *read_unit(struct gamedata *data) if (unicode_utf8_trim(obuf)!=0) { log_warning("trim unit %s name to '%s'", itoa36(u->no), obuf); } - u->_name = obuf[0] ? _strdup(obuf) : 0; + u->_name = obuf[0] ? strdup(obuf) : 0; if (lomem) { READ_STR(data->store, NULL, 0); } @@ -677,7 +677,7 @@ unit *read_unit(struct gamedata *data) if (unicode_utf8_trim(obuf)!=0) { log_warning("trim unit %s info to '%s'", itoa36(u->no), obuf); } - u->display = obuf[0] ? _strdup(obuf) : 0; + u->display = obuf[0] ? strdup(obuf) : 0; } READ_INT(data->store, &number); set_number(u, number); @@ -933,7 +933,7 @@ static region *readregion(struct gamedata *data, int x, int y) if (unicode_utf8_trim(name)!=0) { log_warning("trim region %d name to '%s'", uid, name); }; - r->land->name = _strdup(name); + r->land->name = strdup(name); } if (r->land) { int i; @@ -1034,7 +1034,7 @@ static region *readregion(struct gamedata *data, int x, int y) read_items(data->store, &r->land->items); if (data->version >= REGIONOWNER_VERSION) { READ_INT(data->store, &n); - region_set_morale(r, _max(0, (short)n), -1); + region_set_morale(r, MAX(0, (short)n), -1); read_owner(data, &r->land->ownership); } } @@ -1192,7 +1192,7 @@ static char * getpasswd(int fno) { assert(line[slen] == '\n'); line[slen] = 0; fclose(F); - return _strdup(line + len + 1); + return strdup(line + len + 1); } } fclose(F); @@ -1285,12 +1285,12 @@ faction *read_faction(struct gamedata * data) if (unicode_utf8_trim(name)!=0) { log_warning("trim faction %s name to '%s'", itoa36(f->no), name); }; - f->name = _strdup(name); + f->name = strdup(name); READ_STR(data->store, name, sizeof(name)); if (unicode_utf8_trim(name)!=0) { log_warning("trim faction %s banner to '%s'", itoa36(f->no), name); }; - f->banner = _strdup(name); + f->banner = strdup(name); log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no)); @@ -1528,7 +1528,7 @@ struct building *read_building(gamedata *data) { if (unicode_utf8_trim(name)!=0) { log_warning("trim building %s name to '%s'", itoa36(b->no), name); } - b->name = _strdup(name); + b->name = strdup(name); if (lomem) { READ_STR(store, NULL, 0); } @@ -1537,7 +1537,7 @@ struct building *read_building(gamedata *data) { if (unicode_utf8_trim(name)!=0) { log_warning("trim building %s info to '%s'", itoa36(b->no), name); } - b->display = _strdup(name); + b->display = strdup(name); } READ_INT(store, &b->size); READ_STR(store, name, sizeof(name)); @@ -1581,7 +1581,7 @@ ship *read_ship(struct gamedata *data) if (unicode_utf8_trim(name)!=0) { log_warning("trim ship %s name to '%s'", itoa36(sh->no), name); } - sh->name = _strdup(name); + sh->name = strdup(name); if (lomem) { READ_STR(store, NULL, 0); } @@ -1590,7 +1590,7 @@ ship *read_ship(struct gamedata *data) if (unicode_utf8_trim(name)!=0) { log_warning("trim ship %s info to '%s'", itoa36(sh->no), name); } - sh->display = _strdup(name); + sh->display = strdup(name); } READ_STR(store, name, sizeof(name)); sh->type = st_find(name); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 6a2758a1d..c05ce4455 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -91,7 +91,7 @@ static void test_readwrite_faction(CuTest * tc) test_setup(); f = test_create_faction(0); free(f->name); - f->name = _strdup(" Hodor "); + f->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", f->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); @@ -120,7 +120,7 @@ static void test_readwrite_region(CuTest * tc) test_setup(); r = test_create_region(0, 0, 0); free(r->land->name); - r->land->name = _strdup(" Hodor "); + r->land->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", r->land->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); @@ -150,7 +150,7 @@ static void test_readwrite_building(CuTest * tc) r = test_create_region(0, 0, 0); b = test_create_building(r, 0); free(b->name); - b->name = _strdup(" Hodor "); + b->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", b->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); @@ -183,7 +183,7 @@ static void test_readwrite_ship(CuTest * tc) r = test_create_region(0, 0, 0); sh = test_create_ship(r, 0); free(sh->name); - sh->name = _strdup(" Hodor "); + sh->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", sh->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 6898630ff..817d54970 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -109,7 +109,7 @@ ship_type *st_get_or_create(const char * name) { ship_type * st = st_find_i(name); if (!st) { st = (ship_type *)calloc(sizeof(ship_type), 1); - st->_name = _strdup(name); + st->_name = strdup(name); st->storm = 1.0; ql_push(&shiptypes, (void *)st); } @@ -202,7 +202,7 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang) } assert(sname); slprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no)); - sh->name = _strdup(buffer); + sh->name = strdup(buffer); shash(sh); if (r) { addlist(&r->ships, sh); @@ -333,8 +333,8 @@ int shipspeed(const ship * sh, const unit * u) int crew = crew_skill(sh); int crew_bonus = (crew / sh->type->sumskill / 2) - 1; if (crew_bonus > 0) { - bonus = _min(bonus, crew_bonus); - bonus = _min(bonus, sh->type->range_max - sh->type->range); + bonus = MIN(bonus, crew_bonus); + bonus = MIN(bonus, sh->type->range_max - sh->type->range); } else { bonus = 0; @@ -458,7 +458,7 @@ void write_ship_reference(const struct ship *sh, struct storage *store) void ship_setname(ship * self, const char *name) { free(self->name); - self->name = name ? _strdup(name) : 0; + self->name = name ? strdup(name) : 0; } const char *ship_getname(const ship * self) diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 8e14ec2c0..3201a6677 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -78,7 +78,7 @@ spell * create_spell(const char * name, unsigned int id) len = cb_new_kv(name, len, &sp, sizeof(sp), buffer); if (cb_insert(&cb_spells, buffer, len) == CB_SUCCESS) { sp->id = id ? id : hashstring(name); - sp->sname = _strdup(name); + sp->sname = strdup(name); add_spell(&spells, sp); return sp; } diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index da8fcd563..13f8a04f7 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -16,7 +16,7 @@ spellbook * create_spellbook(const char * name) { spellbook *result = (spellbook *)malloc(sizeof(spellbook)); - result->name = name ? _strdup(name) : 0; + result->name = name ? strdup(name) : 0; result->spells = 0; return result; } diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index ac4a49fe9..ca72e3060 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -110,7 +110,7 @@ terrain_type * get_or_create_terrain(const char *name) { if (!terrain) { terrain = (terrain_type *)calloc(sizeof(terrain_type), 1); if (terrain) { - terrain->_name = _strdup(name); + terrain->_name = strdup(name); terrain->next = registered_terrains; registered_terrains = terrain; if (strcmp("plain", name) == 0) { diff --git a/src/kernel/unit.c b/src/kernel/unit.c index f06c4c252..29766d4ef 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -123,7 +123,7 @@ unit *findunitr(const region * r, int n) // TODO: deprecated, replace with findunit(n) unit *findunitg(int n, const region * hint) { - unused_arg(hint); + UNUSED_ARG(hint); /* Abfangen von Syntaxfehlern. */ if (n <= 0) return NULL; @@ -511,7 +511,7 @@ int a_readprivate(attrib * a, void *owner, gamedata *data) struct storage *store = data->store; char lbuf[DISPLAYSIZE]; READ_STR(store, lbuf, sizeof(lbuf)); - a->data.v = _strdup(lbuf); + a->data.v = strdup(lbuf); return (a->data.v) ? AT_READ_OK : AT_READ_FAIL; } @@ -562,7 +562,7 @@ void usetprivate(unit * u, const char *str) if (a->data.v) { free(a->data.v); } - a->data.v = _strdup(str); + a->data.v = strdup(str); } /*********************/ @@ -809,8 +809,8 @@ void set_level(unit * u, skill_t sk, int value) static int leftship_age(struct attrib *a, void *owner) { /* must be aged, so it doesn't affect report generation (cansee) */ - unused_arg(a); - unused_arg(owner); + UNUSED_ARG(a); + UNUSED_ARG(owner); return AT_AGE_REMOVE; /* remove me */ } @@ -1390,7 +1390,7 @@ int invisible(const unit * target, const unit * viewer) else { int hidden = item_invis(target); if (hidden) { - hidden = _min(hidden, target->number); + hidden = MIN(hidden, target->number); if (viewer) { const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); hidden -= i_get(viewer->items, rtype->itype); @@ -1533,7 +1533,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, u->hp = unit_max_hp(u) * number; if (dname) { - u->_name = _strdup(dname); + u->_name = strdup(dname); } else if (urace->generate_name || playerrace(urace)) { name_unit(u); @@ -1640,7 +1640,7 @@ void unit_setname(unit * u, const char *name) { free(u->_name); if (name && name[0]) - u->_name = _strdup(name); + u->_name = strdup(name); else u->_name = NULL; } @@ -1654,7 +1654,7 @@ void unit_setinfo(unit * u, const char *info) { free(u->display); if (info) - u->display = _strdup(info); + u->display = strdup(info); else u->display = NULL; } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 752627144..f242dbb1c 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -146,7 +146,7 @@ static void test_unit_name(CuTest *tc) { test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); unit_setname(u, "Hodor"); - _snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no)); + snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no)); CuAssertStrEquals(tc, name, unitname(u)); test_cleanup(); } @@ -164,12 +164,12 @@ static void test_unit_name_from_race(CuTest *tc) { locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch"); locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen"); - _snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no)); + snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no)); CuAssertStrEquals(tc, name, unitname(u)); CuAssertStrEquals(tc, "Mensch", unit_getname(u)); u->number = 2; - _snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no)); + snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no)); CuAssertStrEquals(tc, name, unitname(u)); CuAssertStrEquals(tc, "Menschen", unit_getname(u)); @@ -243,9 +243,9 @@ static void test_default_name(CuTest *tc) { } static int cb_skillmod(const unit *u, const region *r, skill_t sk, int level) { - unused_arg(u); - unused_arg(r); - unused_arg(sk); + UNUSED_ARG(u); + UNUSED_ARG(r); + UNUSED_ARG(sk); return level + 3; } @@ -398,7 +398,7 @@ static void test_unit_description(CuTest *tc) { u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0)); CuAssertPtrEquals(tc, 0, u->display); CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale)); - u->display = _strdup("Hodor"); + u->display = strdup("Hodor"); CuAssertStrEquals(tc, "Hodor", u_description(u, NULL)); CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale)); test_cleanup(); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 640a28940..2f38cdab3 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -94,8 +94,8 @@ static xmlChar *xml_cleanup_string(xmlChar * str) while (*read) { /* eat leading whitespace */ - if (*read && isxspace(*read)) { - while (*read && isxspace(*read)) { + if (*read && isspace(*read)) { + while (*read && isspace(*read)) { ++read; } *write++ = ' '; @@ -379,7 +379,7 @@ static int parse_calendar(xmlDocPtr doc) first_turn = xml_ivalue(calendar, "start", first_turn); if (propValue) { free(agename); - agename = _strdup(mkname("calendar", (const char *)propValue)); + agename = strdup(mkname("calendar", (const char *)propValue)); xmlFree(propValue); } @@ -398,7 +398,7 @@ static int parse_calendar(xmlDocPtr doc) xmlNodePtr week = nsetWeeks->nodeTab[i]; xmlChar *propValue = xmlGetProp(week, BAD_CAST "name"); if (propValue) { - weeknames[i] = _strdup(mkname("calendar", (const char *)propValue)); + weeknames[i] = strdup(mkname("calendar", (const char *)propValue)); weeknames2[i] = malloc(strlen(weeknames[i]) + 3); sprintf(weeknames2[i], "%s_d", weeknames[i]); xmlFree(propValue); @@ -421,7 +421,7 @@ static int parse_calendar(xmlDocPtr doc) xmlChar *propValue = xmlGetProp(season, BAD_CAST "name"); if (propValue) { seasonnames[i] = - _strdup(mkname("calendar", (const char *)propValue)); + strdup(mkname("calendar", (const char *)propValue)); xmlFree(propValue); } } @@ -451,7 +451,7 @@ static int parse_calendar(xmlDocPtr doc) xmlFree(newyear); newyear = NULL; } - monthnames[i] = _strdup(mkname("calendar", (const char *)propValue)); + monthnames[i] = strdup(mkname("calendar", (const char *)propValue)); xmlFree(propValue); } if (nsetSeasons) { @@ -663,7 +663,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) xmlFree(propValue); propValue = xmlGetProp(node, BAD_CAST "value"); - wtype->damage[pos] = _strdup((const char *)propValue); // TODO: this is a memory leak + wtype->damage[pos] = strdup((const char *)propValue); // TODO: this is a memory leak if (k == 0) wtype->damage[1 - pos] = wtype->damage[pos]; xmlFree(propValue); @@ -1426,13 +1426,13 @@ static int parse_spells(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "parameters"); if (propValue) { - sp->parameter = _strdup((const char *)propValue); + sp->parameter = strdup((const char *)propValue); xmlFree(propValue); } propValue = xmlGetProp(node, BAD_CAST "syntax"); if (propValue) { - sp->syntax = _strdup((const char *)propValue); + sp->syntax = strdup((const char *)propValue); xmlFree(propValue); } #ifdef TODO /* no longer need it, spellbooks! */ @@ -1628,7 +1628,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "damage"); assert(propValue != NULL); - rc->def_damage = _strdup((const char *)propValue); + rc->def_damage = strdup((const char *)propValue); xmlFree(propValue); rc->magres = (float)xml_fvalue(node, "magres", rc->magres); @@ -1869,7 +1869,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "damage"); if (propValue != NULL) { - attack->data.dice = _strdup((const char *)propValue); + attack->data.dice = strdup((const char *)propValue); xmlFree(propValue); } else { @@ -1932,7 +1932,7 @@ static int parse_messages(xmlDocPtr doc) (const char *)propType); xmlFree(propName); xmlFree(propType); - argv[k] = _strdup(zBuffer); + argv[k] = strdup(zBuffer); } argv[result->nodesetval->nodeNr] = NULL; } diff --git a/src/laws.c b/src/laws.c index e0bae8e41..7baadcf29 100644 --- a/src/laws.c +++ b/src/laws.c @@ -209,7 +209,7 @@ static void live(region * r) } /* bestes Talent raussuchen */ if (sb != NULL) { - int weeks = _min(effect, u->number); + int weeks = MIN(effect, u->number); reduce_skill(u, sb, weeks); ADDMSG(&u->faction->msgs, msg_message("dumbeffect", "unit weeks skill", u, weeks, (skill_t)sb->id)); @@ -267,7 +267,7 @@ static void calculate_emigration(region * r) int max_emigration = MAX_EMIGRATION(rp2 - maxp2); if (max_emigration > 0) { - max_emigration = _min(max_emigration, max_immigrants); + max_emigration = MIN(max_emigration, max_immigrants); r->land->newpeasants += max_emigration; rc->land->newpeasants -= max_emigration; max_immigrants -= max_emigration; @@ -318,7 +318,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance) double mean; if (luck == 0) return 0; - mean = peasant_luck_factor() * peasant_growth_factor() * _min(luck, peasants); + mean = peasant_luck_factor() * peasant_growth_factor() * MIN(luck, peasants); mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE); births = RAND_ROUND(normalvariate(mean, variance * mean)); @@ -357,7 +357,7 @@ static void peasants(region * r) /* Alle werden satt, oder halt soviele für die es auch Geld gibt */ - satiated = _min(peasants, money / maintenance_cost(NULL)); + satiated = MIN(peasants, money / maintenance_cost(NULL)); rsetmoney(r, money - satiated * maintenance_cost(NULL)); /* Von denjenigen, die nicht satt geworden sind, verhungert der @@ -366,7 +366,7 @@ static void peasants(region * r) /* Es verhungert maximal die unterernährten Bevölkerung. */ - n = _min(peasants - satiated, rpeasants(r)); + n = MIN(peasants - satiated, rpeasants(r)); dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE); if (dead > 0) { @@ -447,7 +447,7 @@ static void horses(region * r) /* Logistisches Wachstum, Optimum bei halbem Maximalbesatz. */ maxhorses = region_maxworkers(r) / 10; - maxhorses = _max(0, maxhorses); + maxhorses = MAX(0, maxhorses); horses = rhorses(r); if (horses > 0) { if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) { @@ -481,7 +481,7 @@ static void horses(region * r) if (r2 && fval(r2->terrain, WALK_INTO)) { int pt = (rhorses(r) * HORSEMOVE) / 100; pt = (int)normalvariate(pt, pt / 4.0); - pt = _max(0, pt); + pt = MAX(0, pt); if (fval(r2, RF_MIGRATION)) rsethorses(r2, rhorses(r2) + pt); else { @@ -594,7 +594,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) a = a_find(r->attribs, &at_germs); if (a && last_weeks_season == SEASON_SPRING) { /* ungekeimte Samen bleiben erhalten, Sprößlinge wachsen */ - sprout = _min(a->data.sa[1], rtrees(r, 1)); + sprout = MIN(a->data.sa[1], rtrees(r, 1)); /* aus dem gesamt Sprößlingepool abziehen */ rsettrees(r, 1, rtrees(r, 1) - sprout); /* zu den Bäumen hinzufügen */ @@ -614,7 +614,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) /* Grundchance 1.0% */ /* Jeder Elf in der Region erhöht die Chance marginal */ - elves = _min(elves, production(r) / 8); + elves = MIN(elves, production(r) / 8); if (elves) { seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY); } @@ -680,7 +680,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) /* Raubbau abfangen, es dürfen nie mehr Samen wachsen, als aktuell * in der Region sind */ - seeds = _min(a->data.sa[0], rtrees(r, 0)); + seeds = MIN(a->data.sa[0], rtrees(r, 0)); sprout = 0; for (i = 0; i < seeds; i++) { @@ -700,7 +700,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) * der Region entfernt werden können, da Jungbäume in der gleichen * Runde nachwachsen, wir also nicht mehr zwischen diesjährigen und * 'alten' Jungbäumen unterscheiden könnten */ - sprout = _min(a->data.sa[1], rtrees(r, 1)); + sprout = MIN(a->data.sa[1], rtrees(r, 1)); grownup_trees = 0; for (i = 0; i < sprout; i++) { @@ -740,7 +740,7 @@ void immigration(void) for (r = regions; r; r = r->next) { if (r->land && r->land->newpeasants) { int rp = rpeasants(r) + r->land->newpeasants; - rsetpeasants(r, _max(0, rp)); + rsetpeasants(r, MAX(0, rp)); } /* Genereate some (0-6 depending on the income) peasants out of nothing */ /* if less than 50 are in the region and there is space and no monster or demon units in the region */ @@ -843,7 +843,7 @@ void demographics(void) calculate_emigration(r); peasants(r); if (r->age > 20) { - double mwp = _max(region_maxworkers(r), 1); + double mwp = MAX(region_maxworkers(r), 1); double prob = pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0) * PLAGUE_CHANCE; @@ -1280,7 +1280,7 @@ static void remove_idle_players(void) } log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben..."); - age = calloc(_max(4, turn + 1), sizeof(int)); + age = calloc(MAX(4, turn + 1), sizeof(int)); for (fp = &factions; *fp;) { faction *f = *fp; if (!is_monsters(f)) { @@ -1621,7 +1621,7 @@ int display_cmd(unit * u, struct order *ord) free(*s); if (s2) { - *s = _strdup(s2); + *s = strdup(s2); if (strlen(s2) >= DISPLAYSIZE) { (*s)[DISPLAYSIZE] = 0; } @@ -1665,7 +1665,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2) unicode_utf8_trim(name); free(*s); - *s = _strdup(name); + *s = strdup(name); return 0; } @@ -2154,7 +2154,7 @@ int banner_cmd(unit * u, struct order *ord) const char * s = getstrtoken(); free(u->faction->banner); - u->faction->banner = s ? _strdup(s) : 0; + u->faction->banner = s ? strdup(s) : 0; add_message(&u->faction->msgs, msg_message("changebanner", "value", u->faction->banner)); @@ -2356,23 +2356,23 @@ static void display_race(unit * u, const race * rc) } } if (rc->battle_flags & BF_EQUIPMENT) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"))) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_PIERCE) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"))) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_CUT) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"))) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_BASH) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"))) != 0) WARN_STATIC_BUFFER(); } - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks"))) != 0) WARN_STATIC_BUFFER(); for (a = 0; a < RACE_ATTACKS; a++) { @@ -2385,12 +2385,12 @@ static void display_race(unit * u, const race * rc) switch (rc->attack[a].type) { case AT_STANDARD: bytes = - (size_t)_snprintf(bufp, size, "%s (%s)", + (size_t)snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_standard"), rc->def_damage); break; case AT_NATURAL: bytes = - (size_t)_snprintf(bufp, size, "%s (%s)", + (size_t)snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); break; case AT_SPELL: @@ -2398,11 +2398,11 @@ static void display_race(unit * u, const race * rc) case AT_DRAIN_ST: case AT_DRAIN_EXP: case AT_DAZZLE: - bytes = (size_t)_snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); + bytes = (size_t)snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); break; case AT_STRUCTURAL: bytes = - (size_t)_snprintf(bufp, size, "%s (%s)", + (size_t)snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); break; default: @@ -2670,7 +2670,7 @@ int combatspell_cmd(unit * u, struct order *ord) if (findparam(s, u->faction->locale) == P_LEVEL) { /* Merken, setzen kommt erst später */ level = getint(); - level = _max(0, level); + level = MAX(0, level); s = gettoken(token, sizeof(token)); } @@ -2903,14 +2903,14 @@ static void age_stonecircle(building *b) { float effect = 100; /* the mage reactivates the circle */ c = create_curse(mage, &rt->attribs, ct_astralblock, - (float)_max(1, sk), _max(1, sk / 2), effect, 0); + (float)MAX(1, sk), MAX(1, sk / 2), effect, 0); ADDMSG(&r->msgs, msg_message("astralshield_activate", "region unit", r, mage)); } else { int sk = effskill(mage, SK_MAGIC, 0); - c->duration = _max(c->duration, sk / 2); - c->vigour = _max(c->vigour, (float)sk); + c->duration = MAX(c->duration, sk / 2); + c->vigour = MAX(c->vigour, (float)sk); } } } @@ -2955,12 +2955,12 @@ static void ageing(void) /* Goliathwasser */ int i = get_effect(u, oldpotiontype[P_STRONG]); if (i > 0) { - change_effect(u, oldpotiontype[P_STRONG], -1 * _min(u->number, i)); + change_effect(u, oldpotiontype[P_STRONG], -1 * MIN(u->number, i)); } /* Berserkerblut */ i = get_effect(u, oldpotiontype[P_BERSERK]); if (i > 0) { - change_effect(u, oldpotiontype[P_BERSERK], -1 * _min(u->number, i)); + change_effect(u, oldpotiontype[P_BERSERK], -1 * MIN(u->number, i)); } if (is_cursed(u->attribs, C_OLDRACE, 0)) { @@ -3034,7 +3034,7 @@ static int maxunits(const faction * f) if (flimit == 0) { return alimit; } - return _min(alimit, flimit); + return MIN(alimit, flimit); } int checkunitnumber(const faction * f, int add) @@ -3130,7 +3130,7 @@ void new_units(void) s = gettoken(token, sizeof(token)); if (s && s[0]) { - name = _strdup(s); + name = strdup(s); } u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u); if (name != NULL) @@ -3361,7 +3361,7 @@ void monthly_healing(void) p *= heal_factor(u); if (u->hp < umhp) { - double maxheal = _max(u->number, umhp / 20.0); + double maxheal = MAX(u->number, umhp / 20.0); int addhp; if (active_building(u, bt_find("inn"))) { p *= 1.5; @@ -3376,7 +3376,7 @@ void monthly_healing(void) ++addhp; /* Aufaddieren der geheilten HP. */ - u->hp = _min(u->hp + addhp, umhp); + u->hp = MIN(u->hp + addhp, umhp); /* soll man an negativer regeneration sterben können? */ assert(u->hp > 0); @@ -3701,7 +3701,7 @@ int claim_cmd(unit * u, struct order *ord) if (itype) { item **iclaim = i_find(&u->faction->items, itype); if (iclaim && *iclaim) { - n = _min(n, (*iclaim)->number); + n = MIN(n, (*iclaim)->number); i_change(iclaim, itype, -n); i_change(&u->items, itype, n); } @@ -3962,7 +3962,7 @@ int armedmen(const unit * u, bool siege_weapons) if (n >= u->number) break; } - n = _min(n, u->number); + n = MIN(n, u->number); } } return n; @@ -3998,9 +3998,9 @@ int siege_cmd(unit * u, order * ord) rt_catapult = rt_find("catapult"); d = i_get(u->items, rt_catapult->itype); - d = _min(u->number, d); + d = MIN(u->number, d); pooled = get_pooled(u, rt_catapultammo, GET_DEFAULT, d); - d = _min(pooled, d); + d = MIN(pooled, d); if (effskill(u, SK_CATAPULT, 0) >= 1) { katapultiere = d; d *= effskill(u, SK_CATAPULT, 0); @@ -4027,11 +4027,11 @@ int siege_cmd(unit * u, order * ord) * einheiten wieder abgesucht werden muessen! */ usetsiege(u, b); - b->besieged += _max(bewaffnete, katapultiere); + b->besieged += MAX(bewaffnete, katapultiere); /* definitiver schaden eingeschraenkt */ - d = _min(d, b->size - 1); + d = MIN(d, b->size - 1); /* meldung, schaden anrichten */ if (d && !curse_active(get_curse(b->attribs, magicwalls_ct))) { @@ -4270,7 +4270,7 @@ void processorders(void) void update_subscriptions(void) { FILE *F; - char zText[MAX_PATH]; + char zText[4096]; join_path(basepath(), "subscriptions", zText, sizeof(zText)); F = fopen(zText, "r"); diff --git a/src/laws.h b/src/laws.h index 0adb010d2..f05c11ab4 100755 --- a/src/laws.h +++ b/src/laws.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_GC_LAWS #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/laws.test.c b/src/laws.test.c index 1bec0e6b4..b5471243a 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -531,7 +531,7 @@ static void test_pay_cmd_other_building(CuTest *tc) { config_set("rules.region_owner_pay_building", "lighthouse"); update_owners(b->region); - _snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no)); + snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no)); ord = create_order(K_PAY, f->locale, cmd); assert(ord); CuAssertPtrEquals(tc, fix.u1, building_owner(b)); diff --git a/src/lighthouse.c b/src/lighthouse.c index 09c9b7d11..d29d58b71 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -83,8 +83,8 @@ int lighthouse_range(const building * b, const faction * f) } else if (f == NULL || u->faction == f) { int sk = effskill(u, SK_PERCEPTION, 0) / 3; - d = _max(d, sk); - d = _min(maxd, d); + d = MAX(d, sk); + d = MIN(maxd, d); if (d == maxd) break; } diff --git a/src/lighthouse.h b/src/lighthouse.h index 3bf970bf1..f2974ddf1 100644 --- a/src/lighthouse.h +++ b/src/lighthouse.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef LIGHTHOUSE_H #define LIGHTHOUSE_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/listbox.c b/src/listbox.c index 332041454..057240fad 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -27,7 +27,7 @@ insert_selection(list_selection ** p_sel, list_selection * prev, const char *str, void *payload) { list_selection *sel = calloc(sizeof(list_selection), 1); - sel->str = _strdup(str); + sel->str = strdup(str); sel->data = payload; if (*p_sel) { list_selection *s; diff --git a/src/magic.c b/src/magic.c index 2299e6523..dc56ad5ff 100644 --- a/src/magic.c +++ b/src/magic.c @@ -118,7 +118,7 @@ static double MagicPower(double force) if (force > 0) { const char *str = config_get("magic.power"); double value = str ? atof(str) : 1.0; - return _max(value * force, 1.0f); + return MAX(value * force, 1.0f); } return 0; } @@ -146,7 +146,7 @@ static void a_writeicastle(const attrib * a, const void *owner, struct storage *store) { icastle_data *data = (icastle_data *)a->data.v; - unused_arg(owner); + UNUSED_ARG(owner); WRITE_TOK(store, data->type->_name); WRITE_INT(store, data->time); } @@ -543,7 +543,7 @@ int get_combatspelllevel(const unit * u, int nr) assert(nr < MAXCOMBATSPELLS); if (m) { int level = effskill(u, SK_MAGIC, 0); - return _min(m->combatspells[nr].level, level); + return MIN(m->combatspells[nr].level, level); } return -1; } @@ -679,7 +679,7 @@ int change_spellpoints(unit * u, int mp) } /* verhindere negative Magiepunkte */ - sp = _max(m->spellpoints + mp, 0); + sp = MAX(m->spellpoints + mp, 0); m->spellpoints = sp; return sp; @@ -739,7 +739,7 @@ int max_spellpoints(const region * r, const unit * u) if (n > 0) { msp = (msp * n) / 100; } - return _max((int)msp, 0); + return MAX((int)msp, 0); } int change_maxspellpoints(unit * u, int csp) @@ -774,7 +774,7 @@ int countspells(unit * u, int step) count = m->spellcount + step; /* negative Werte abfangen. */ - m->spellcount = _max(0, count); + m->spellcount = MAX(0, count); return m->spellcount; } @@ -867,7 +867,7 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range) } else if (sp->components[k].cost == SPC_LEVEL) { costtyp = SPC_LEVEL; - cast_level = _min(cast_level, maxlevel); + cast_level = MIN(cast_level, maxlevel); /* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden * sein, ansonsten schlägt der Spruch fehl */ } @@ -885,7 +885,7 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range) if (sb) { spellbook_entry * sbe = spellbook_get(sb, sp); if (sbe) { - return _min(cast_level, sbe->level); + return MIN(cast_level, sbe->level); } } log_error("spell %s is not in the spellbook for %s\n", sp->sname, unitname(u)); @@ -1103,7 +1103,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order } } } - return _max(force, 0); + return MAX(force, 0); } /* ------------------------------------------------------------- */ @@ -1278,8 +1278,8 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) break; } - probability = _max(0.02, probability + t_bonus * 0.01); - probability = _min(0.98, probability); + probability = MAX(0.02, probability + t_bonus * 0.01); + probability = MIN(0.98, probability); /* gibt true, wenn die Zufallszahl kleiner als die chance ist und * false, wenn sie gleich oder größer ist, dh je größer die @@ -1421,7 +1421,7 @@ static void do_fumble(castorder * co) case 2: /* temporary skill loss */ - duration = _max(rng_int() % level / 2, 2); + duration = MAX(rng_int() % level / 2, 2); effect = level / -2.0; c = create_curse(u, &u->attribs, ct_find("skillmod"), level, duration, effect, 1); @@ -1529,14 +1529,14 @@ void regenerate_aura(void) reg_aura -= regen; if (chance(reg_aura)) ++regen; - regen = _max(1, regen); - regen = _min((auramax - aura), regen); + regen = MAX(1, regen); + regen = MIN((auramax - aura), regen); aura += regen; ADDMSG(&u->faction->msgs, msg_message("regenaura", "unit region amount", u, r, regen)); } - set_spellpoints(u, _min(aura, auramax)); + set_spellpoints(u, MIN(aura, auramax)); } } } @@ -1853,7 +1853,7 @@ static int addparam_string(const char *const param[], spllprm ** spobjp) spobj->flag = 0; spobj->typ = SPP_STRING; - spobj->data.xs = _strdup(param[0]); + spobj->data.xs = strdup(param[0]); return 1; } @@ -2428,7 +2428,7 @@ static int age_unit(attrib * a, void *owner) /* if unit is gone or dead, remove the attribute */ { unit *u = (unit *)a->data.v; - unused_arg(owner); + UNUSED_ARG(owner); return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -2567,7 +2567,7 @@ static castorder *cast_cmd(unit * u, order * ord) /* für Syntax ' STUFE x REGION y z ' */ if (param == P_LEVEL) { int p = getint(); - level = _min(p, level); + level = MIN(p, level); if (level < 1) { /* Fehler "Das macht wenig Sinn" */ syntax_error(u, ord); @@ -2597,7 +2597,7 @@ static castorder *cast_cmd(unit * u, order * ord) * hier nach REGION nochmal auf STUFE prüfen */ if (param == P_LEVEL) { int p = getint(); - level = _min(p, level); + level = MIN(p, level); if (level < 1) { /* Fehler "Das macht wenig Sinn" */ syntax_error(u, ord); @@ -2728,7 +2728,7 @@ static castorder *cast_cmd(unit * u, order * ord) * löschen, zaubern kann er noch */ range *= 2; set_order(&caster->thisorder, NULL); - level = _min(level, effskill(caster, SK_MAGIC, 0) / 2); + level = MIN(level, effskill(caster, SK_MAGIC, 0) / 2); } } /* Weitere Argumente zusammenbasteln */ @@ -2751,7 +2751,7 @@ static castorder *cast_cmd(unit * u, order * ord) break; } } - params[p++] = _strdup(s); + params[p++] = strdup(s); } params[p] = 0; args = diff --git a/src/magic.h b/src/magic.h index 59ef92475..964783c32 100644 --- a/src/magic.h +++ b/src/magic.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_MAGIC #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/market.test.c b/src/market.test.c index 43e070b5e..6f1d74b88 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -46,7 +46,7 @@ static void test_market_curse(CuTest * tc) config_set("rules.region_owners", "1"); btype = (building_type *)calloc(1, sizeof(building_type)); - btype->_name = _strdup("market"); + btype->_name = strdup("market"); bt_register(btype); terrain = get_terrain("plain"); diff --git a/src/modules/arena.c b/src/modules/arena.c index a912d273a..fbc3f0673 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -99,9 +99,9 @@ order * ord) if (u->building != arena_tower(u->faction->magiegebiet) && leave_fail(u)) { return -1; } - unused_arg(amount); - unused_arg(ord); - unused_arg(itype); + UNUSED_ARG(amount); + UNUSED_ARG(ord); + UNUSED_ARG(itype); assert(!"not implemented"); return 0; } @@ -120,9 +120,9 @@ enter_arena(unit * u, const item_type * itype, int amount, order * ord) region *r = u->region; unit *u2; int fee = 2000; - unused_arg(ord); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(ord); + UNUSED_ARG(amount); + UNUSED_ARG(itype); if (u->faction->score > fee * 5) { score_t score = u->faction->score / 5; if (score < INT_MAX) { @@ -212,7 +212,7 @@ static int caldera_handle(trigger * t, void *data) else { log_error("could not perform caldera::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 5420406c0..54fd7411e 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -199,7 +199,7 @@ newfaction *read_newfactions(const char *filename) free(nf); continue; } - nf->password = _strdup(password); + nf->password = strdup(password); nf->race = rc_find(race); nf->subscription = subscription; if (alliances != NULL) { @@ -962,8 +962,8 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi q = region_quality(r, rn); if (q >= MIN_QUALITY && nfactions < numfactions && *players) { starting_region(players, r, rn); - minq = _min(minq, q); - maxq = _max(maxq, q); + minq = MIN(minq, q); + maxq = MAX(maxq, q); ++nfactions; } } @@ -977,8 +977,8 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi q = region_quality(r, rn); if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) { starting_region(players, r, rn); - minq = _min(minq, q); - maxq = _max(maxq, q); + minq = MIN(minq, q); + maxq = MAX(maxq, q); ++nfactions; } } diff --git a/src/modules/museum.c b/src/modules/museum.c index e934a71a4..af37019d0 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -310,7 +310,7 @@ order * ord) unit *warden = findunit(atoi36("mwar")); int unit_cookie; - unused_arg(amount); + UNUSED_ARG(amount); /* Prüfen ob in Eingangshalle */ if (u->region->x != 9525 || u->region->y != 9525) { @@ -365,7 +365,7 @@ order * ord) region *r = u->region; plane *pl = rplane(r); - unused_arg(amount); + UNUSED_ARG(amount); /* Pruefen ob in normaler Plane und nur eine Person */ if (pl != get_homeplane()) { @@ -417,8 +417,8 @@ static const char *b_namequestportal(const connection * b, const region * r, { const char *bname; int lock = b->data.i; - unused_arg(b); - unused_arg(r); + UNUSED_ARG(b); + UNUSED_ARG(r); if (gflags & GF_ARTICLE) { if (lock > 0) { diff --git a/src/modules/score.c b/src/modules/score.c index 8213b8985..0776d6507 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -67,7 +67,7 @@ void score(void) region *r; faction *fc; score_t allscores = 0; - char path[MAX_PATH]; + char path[4096]; for (fc = factions; fc; fc = fc->next) fc->score = 0; diff --git a/src/monsters.c b/src/monsters.c index db34bff2c..b613f48cc 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -100,7 +100,7 @@ static void reduce_weight(unit * u) int horses = get_resource(u, get_resourcetype(R_HORSE)); if (horses > 0) { - horses = _min(horses, (u->number * 2)); + horses = MIN(horses, (u->number * 2)); change_resource(u, get_resourcetype(R_HORSE), -horses); } @@ -129,7 +129,7 @@ static void reduce_weight(unit * u) if (itype->weight >= 10 && itype->rtype->wtype == 0 && itype->rtype->atype == 0) { if (itype->capacity < itype->weight) { - int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); + int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } @@ -144,7 +144,7 @@ static void reduce_weight(unit * u) const item_type *itype = itm->type; weight += itm->number * itype->weight; if (itype->capacity < itype->weight) { - int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); + int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } @@ -1027,7 +1027,7 @@ static void eaten_by_monster(unit * u) n = (int)(n * multi); if (n > 0) { n = lovar(n); - n = _min(rpeasants(u->region), n); + n = MIN(rpeasants(u->region), n); if (n > 0) { deathcounts(u->region, n); @@ -1047,7 +1047,7 @@ static void absorbed_by_monster(unit * u) if (n > 0) { n = lovar(n); - n = _min(rpeasants(u->region), n); + n = MIN(rpeasants(u->region), n); if (n > 0) { rsetpeasants(u->region, rpeasants(u->region) - n); scale_number(u, u->number + n); @@ -1062,7 +1062,7 @@ static int scareaway(region * r, int anzahl) int n, p, diff = 0, emigrants[MAXDIRECTIONS]; direction_t d; - anzahl = _min(_max(1, anzahl), rpeasants(r)); + anzahl = MIN(MAX(1, anzahl), rpeasants(r)); /* Wandern am Ende der Woche (normal) oder wegen Monster. Die * Wanderung wird erst am Ende von demographics () ausgefuehrt. @@ -1074,7 +1074,7 @@ static int scareaway(region * r, int anzahl) p = rpeasants(r); assert(p >= 0 && anzahl >= 0); - for (n = _min(p, anzahl); n; n--) { + for (n = MIN(p, anzahl); n; n--) { direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); region *rc = rconnect(r, dir); @@ -1102,7 +1102,7 @@ static void scared_by_monster(unit * u) } if (n > 0) { n = lovar(n); - n = _min(rpeasants(u->region), n); + n = MIN(rpeasants(u->region), n); if (n > 0) { n = scareaway(u->region, n); if (n > 0) { diff --git a/src/morale.c b/src/morale.c index 8dc22ccb5..1bdf2363d 100644 --- a/src/morale.c +++ b/src/morale.c @@ -73,7 +73,7 @@ void morale_update(region *r) { void morale_change(region *r, int value) { int morale = region_get_morale(r); if (morale > 0) { - morale = _max(0, morale - value); + morale = MAX(0, morale - value); region_set_morale(r, morale, turn); } } diff --git a/src/move.c b/src/move.c index 126557d58..62300beb1 100644 --- a/src/move.c +++ b/src/move.c @@ -151,8 +151,8 @@ static void shiptrail_finalize(attrib * a) static int shiptrail_age(attrib * a, void *owner) { traveldir *t = (traveldir *)(a->data.v); - unused_arg(owner); + (void)owner; t->age--; return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -267,12 +267,12 @@ static int ridingcapacity(unit * u) ** tragen nichts (siehe walkingcapacity). Ein Wagen zählt nur, wenn er ** von zwei Pferden gezogen wird */ - animals = _min(animals, effskill(u, SK_RIDING, 0) * u->number * 2); + animals = MIN(animals, effskill(u, SK_RIDING, 0) * u->number * 2); if (fval(u_race(u), RCF_HORSE)) animals += u->number; /* maximal diese Pferde können zum Ziehen benutzt werden */ - vehicles = _min(animals / HORSESNEEDED, vehicles); + vehicles = MIN(animals / HORSESNEEDED, vehicles); return vehicles * vcap + animals * acap; } @@ -291,7 +291,7 @@ int walkingcapacity(const struct unit *u) /* Das Gewicht, welches die Pferde tragen, plus das Gewicht, welches * die Leute tragen */ - pferde_fuer_wagen = _min(animals, effskill(u, SK_RIDING, 0) * u->number * 4); + pferde_fuer_wagen = MIN(animals, effskill(u, SK_RIDING, 0) * u->number * 4); if (fval(u_race(u), RCF_HORSE)) { animals += u->number; people = 0; @@ -301,7 +301,7 @@ int walkingcapacity(const struct unit *u) } /* maximal diese Pferde können zum Ziehen benutzt werden */ - wagen_mit_pferden = _min(vehicles, pferde_fuer_wagen / HORSESNEEDED); + wagen_mit_pferden = MIN(vehicles, pferde_fuer_wagen / HORSESNEEDED); n = wagen_mit_pferden * vcap; @@ -311,7 +311,7 @@ int walkingcapacity(const struct unit *u) wagen_ohne_pferde = vehicles - wagen_mit_pferden; /* Genug Trolle, um die Restwagen zu ziehen? */ - wagen_mit_trollen = _min(u->number / 4, wagen_ohne_pferde); + wagen_mit_trollen = MIN(u->number / 4, wagen_ohne_pferde); /* Wagenkapazität hinzuzählen */ n += wagen_mit_trollen * vcap; @@ -335,7 +335,7 @@ int walkingcapacity(const struct unit *u) int belts = i_get(u->items, rbelt->itype); if (belts) { int multi = config_get_int("rules.trollbelt.multiplier", STRENGTHMULTIPLIER); - n += _min(people, belts) * (multi - 1) * u_race(u)->capacity; + n += MIN(people, belts) * (multi - 1) * u_race(u)->capacity; } } @@ -366,7 +366,7 @@ static int canwalk(unit * u) effsk = effskill(u, SK_RIDING, 0); maxwagen = effsk * u->number * 2; if (u_race(u) == get_race(RC_TROLL)) { - maxwagen = _max(maxwagen, u->number / 4); + maxwagen = MAX(maxwagen, u->number / 4); } maxpferde = effsk * u->number * 4 + u->number; @@ -505,7 +505,7 @@ static double overload(const region * r, ship * sh) double ovl = n / (double)sh->type->cargo; if (mcabins) - ovl = _max(ovl, p / (double)mcabins); + ovl = MAX(ovl, p / (double)mcabins); return ovl; } } @@ -752,7 +752,7 @@ double damage_overload(double overload) badness = overload - overload_worse(); if (badness >= 0) { assert(overload_worst() > overload_worse() || !"overload.worst must be > overload.worse"); - damage += _min(badness, overload_worst() - overload_worse()) * + damage += MIN(badness, overload_worst() - overload_worse()) * (overload_max_damage() - damage) / (overload_worst() - overload_worse()); } @@ -946,7 +946,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) guard_count += u->number; double prob_u = (sk - stealth) * skill_prob; /* amulet counts at most once */ - prob_u += _min(1, _min(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; + prob_u += MIN(1, MIN(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; if (u->building && (u->building->type == castle_bt) && u == building_owner(u->building)) prob_u += castle_prob*buildingeffsize(u->building, 0); if (prob_u >= prob) { @@ -1985,7 +1985,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) const luxury_type *ltype = resource2luxury(itm->type->rtype); if (ltype != NULL && itm->number > 0) { int st = itm->number * effskill(harbourmaster, SK_TRADE, 0) / 50; - st = _min(itm->number, st); + st = MIN(itm->number, st); if (st > 0) { i_change(&u2->items, itm->type, -st); diff --git a/src/move.h b/src/move.h index 14c040493..4d0b4e9f2 100644 --- a/src/move.h +++ b/src/move.h @@ -16,11 +16,12 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#include "direction.h" +#include + #ifndef H_KRNL_MOVEMENT #define H_KRNL_MOVEMENT -#include "direction.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/src/names.c b/src/names.c index cf1cdb910..248084828 100644 --- a/src/names.c +++ b/src/names.c @@ -365,7 +365,7 @@ static void dracoid_name(unit * u) size_t sz; /* ignore u */ - unused_arg(u); + UNUSED_ARG(u); /* Wieviele Mittelteile? */ mid_syllabels = rng_int() % 4; @@ -425,8 +425,8 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) } } - /* Buchstaben pro Teilkürzel = _max(1,max/AnzWort) */ - bpt = (c > 0) ? _max(1, maxchars / c) : 1; + /* Buchstaben pro Teilkürzel = MAX(1,max/AnzWort) */ + bpt = (c > 0) ? MAX(1, maxchars / c) : 1; /* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */ diff --git a/src/platform.h b/src/platform.h index c781021ae..2f114cec5 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,179 +1,15 @@ -/* -Copyright (c) 1998-2015, Enno Rehling - Katja Zedel +#pragma once -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. +#ifndef UNILIB_H +#define UNILIB_H -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef PLATFORM_H -#define PLATFORM_H - -#ifdef NDEBUG -#define LOMEM +#ifndef MAX_PATH +# define MAX_PATH 4096 #endif -// enable X/Open 7 extensions (like strdup): -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 700 -#endif +#define UNUSED_ARG(a) (void)(a) -// enable bsd string extensions, since glibc 2.12 (_BSD_SOURCE is dead): -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L -#endif - -#ifndef USE_AUTOCONF -#define USE_AUTOCONF - -#ifdef _MSC_VER -#undef USE_AUTOCONF -#define HAVE_STDBOOL_H -#define HAVE_DIRECT__MKDIR -#define HAVE__ACCESS - -#define VC_EXTRALEAN -#define WIN32_LEAN_AND_MEAN -#pragma warning(push) -#pragma warning(disable:4820 4255 4668) -# include -# include -#pragma warning(pop) -# undef MOUSE_MOVED -# define STDIO_CP 1252 /* log.c, convert to console character set */ -# pragma warning (disable: 4201 4214 4514 4115 4711) -#if _MSC_VER >= 1900 -# pragma warning(disable: 4710) -/* warning C4710: function not inlined */ -# pragma warning(disable: 4456) -/* warning C4456 : declaration of hides previous local declaration */ -# pragma warning(disable: 4457) -/* warning C4457: declaration of hides function parameter */ -# pragma warning(disable: 4459) -/* warning C4459: declaration of hides global declaration */ -#endif -# pragma warning(disable: 4056) -/* warning C4056: overflow in floating point constant arithmetic */ -# pragma warning(disable: 4201) -/* warning C4201: nonstandard extension used : nameless struct/union */ -# pragma warning(disable: 4214) -/* warning C4214: nonstandard extension used : bit field types other than int */ -# pragma warning(disable: 4100) -/* warning C4100: : unreferenced formal parameter */ -# pragma warning(disable: 4996) -/* is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */ -# pragma warning(disable: 4668) -/* : bytes padding after data member */ -# pragma warning(disable: 4820) - -/* warning C4100: was declared deprecated */ -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE -#endif - -/* - * http://msdn2.microsoft.com/en-us/library/ms235505(VS.80).aspx - * Defining _CRT_DISABLE_PERFCRIT_LOCKS forces all I/O operations to assume a - * single-threaded I/O model and use the _nolock forms of the functions. - */ -#ifndef _CRT_DISABLE_PERFCRIT_LOCKS -#define _CRT_DISABLE_PERFCRIT_LOCKS -#endif - -#elif __GNUC__ -#undef USE_AUTOCONF -#define HAVE_SNPRINTF -#define HAVE_SYS_STAT_MKDIR -#define HAVE_STRDUP -#define HAVE_UNISTD_H -#endif -#endif - -#ifdef USE_AUTOCONF -// unknown toolchain, using autoconf -#include -#endif - -#define unused_arg (void) - -#define iswxspace(c) (c==160 || iswspace(c)) -#define isxspace(c) (c==160 || isspace(c)) - -#define TOLUA_CAST (char*) - -#if !defined(MAX_PATH) -#if defined(PATH_MAX) -# define MAX_PATH PATH_MAX -#else -# define MAX_PATH 256 -#endif -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -#if defined(HAVE_STDBOOL_H) -# include -#else -# ifndef HAVE__BOOL -# ifdef __cplusplus -typedef bool _Bool; -# else -typedef unsigned char _Bool; -# endif -# endif -# define bool _Bool -# define false 0 -# define true 1 -# define __bool_true_false_are_defined 1 -#endif - -#ifndef HAVE__ACCESS -#ifdef HAVE_ACCESS -#define _access(path, mode) access(path, mode) -#endif -#endif - -#if defined(HAVE_DIRECT__MKDIR) -#include -#elif defined(HAVE_DIRECT_MKDIR) -#include -#define _mkdir(a) mkdir(a) -#elif defined(HAVE_SYS_STAT_MKDIR) -#include -#define _mkdir(a) mkdir(a, 0777) -#endif - -#ifndef _min -#define _min(a,b) ((a) < (b) ? (a) : (b)) -#endif -#ifndef _max -#define _max(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#if !defined(HAVE__STRDUP) -#if defined(HAVE_STRDUP) -#undef _strdup -#define _strdup strdup -#endif -#endif - -#if !defined(HAVE__SNPRINTF) -#if defined(HAVE_SNPRINTF) -#define _snprintf snprintf -#endif -#endif +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif - diff --git a/src/prefix.c b/src/prefix.c index a6564b6e8..1a22e6982 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -30,7 +30,7 @@ int add_raceprefix(const char *prefix) race_prefixes = tmp; size *= 2; } - race_prefixes[next++] = _strdup(prefix); + race_prefixes[next++] = strdup(prefix); race_prefixes[next] = NULL; return 0; } diff --git a/src/races/dragons.c b/src/races/dragons.c index 222d63c89..aa79a783a 100644 --- a/src/races/dragons.c +++ b/src/races/dragons.c @@ -22,7 +22,7 @@ /* util includes */ #include -#define age_chance(a,b,p) (_max(0,a-b)*p) +#define age_chance(a,b,p) (MAX(0,a-b)*p) #define DRAGONAGE 27 #define WYRMAGE 68 diff --git a/src/races/races.c b/src/races/races.c index 2c6cfffa9..8af9cf2ed 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -42,7 +42,7 @@ static void oldfamiliars(unit * u) char fname[64]; /* these familiars have no special skills. */ - _snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); + snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); create_mage(u, M_GRAY); equip_unit(u, get_equipment(fname)); } diff --git a/src/races/zombies.c b/src/races/zombies.c index 3e9303b38..ea26298b2 100644 --- a/src/races/zombies.c +++ b/src/races/zombies.c @@ -33,7 +33,7 @@ #define UNDEAD_BREAKUP 25 /* chance dafuer */ #define UNDEAD_BREAKUP_FRACTION (25+rng_int()%70) /* anteil der weg geht */ -#define age_chance(a,b,p) (_max(0,a-b)*p) +#define age_chance(a,b,p) (MAX(0,a-b)*p) void make_undead_unit(unit * u) { @@ -70,7 +70,7 @@ void age_undead(unit * u) void age_skeleton(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = _max(1, u->number / 2); + int n = MAX(1, u->number / 2); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_SKELETON_LORD)); u->irace = NULL; @@ -82,7 +82,7 @@ void age_skeleton(unit * u) void age_zombie(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = _max(1, u->number / 2); + int n = MAX(1, u->number / 2); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_ZOMBIE_LORD)); u->irace = NULL; @@ -94,7 +94,7 @@ void age_zombie(unit * u) void age_ghoul(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = _max(1, u->number / 2); + int n = MAX(1, u->number / 2); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_GHOUL_LORD)); u->irace = NULL; diff --git a/src/randenc.c b/src/randenc.c index 536210b1f..ab51d64b1 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -785,7 +785,7 @@ static void rotting_herbs(void) if (fval(itm->type, ITF_HERB)) { double nv = normalvariate(k, k / 4); int inv = (int)nv; - int delta = _min(n, inv); + int delta = MIN(n, inv); if (!i_change(itmp, itm->type, -delta)) { continue; } @@ -814,7 +814,7 @@ void randomevents(void) while (*blist) { building *b = *blist; if (fval(b->type, BTF_DECAY) && !building_owner(b)) { - b->size -= _max(1, (b->size * 20) / 100); + b->size -= MAX(1, (b->size * 20) / 100); if (b->size == 0) { remove_building(blist, r->buildings); } diff --git a/src/report.c b/src/report.c index 0c7697fe5..9b5e243b4 100644 --- a/src/report.c +++ b/src/report.c @@ -269,17 +269,17 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc /* Reihenfolge beachten: Erst REGION, dann STUFE! */ if (sp->sptyp & FARCASTING) { - bytes = _snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION])); + bytes = snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION])); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (sp->sptyp & SPELLLEVEL) { - bytes = _snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL])); + bytes = snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL])); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)_snprintf(bufp, size, " \"%s\"", spell_name(sp, lang)); + bytes = (int)snprintf(bufp, size, " \"%s\"", spell_name(sp, lang)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -305,12 +305,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc if (cp == 'u') { targetp = targets + 1; locp = LOC(lang, targetp->vars); - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -318,12 +318,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc else if (cp == 's') { targetp = targets + 2; locp = LOC(lang, targetp->vars); - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -342,12 +342,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc else if (cp == 'b') { targetp = targets + 3; locp = LOC(lang, targetp->vars); - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -382,17 +382,17 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc if (targetp->param && targetp->vars) { locp = LOC(lang, targetp->vars); bytes = - (int)_snprintf(bufp, size, " %s <%s>", parameters[targetp->param], + (int)snprintf(bufp, size, " %s <%s>", parameters[targetp->param], locp); if (multi) { if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } } else { bytes = - (int)_snprintf(bufp, size, " %s", parameters[targetp->param]); + (int)snprintf(bufp, size, " %s", parameters[targetp->param]); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -422,10 +422,10 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } if (*params == '?') { ++params; - bytes = (int)_snprintf(bufp, size, " [<%s>]", locp); + bytes = (int)snprintf(bufp, size, " [<%s>]", locp); } else { - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -494,18 +494,18 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la bufp = buf; if (sp->sptyp & SPELLLEVEL) { bytes = - _snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, + snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR) { - bytes = _snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); + bytes = snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } } else { - bytes = _snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); + bytes = snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); if (wrptr(&bufp, &size, bytes) != 0) { WARN_STATIC_BUFFER(); } @@ -929,7 +929,7 @@ static void describe(struct stream *out, const region * r, faction * f) } if (!e) { e = calloc(sizeof(struct edge), 1); - e->name = _strdup(name); + e->name = strdup(name); e->transparent = transparent; e->next = edges; edges = e; @@ -945,13 +945,13 @@ static void describe(struct stream *out, const region * r, faction * f) WARN_STATIC_BUFFER(); if (r->seen.mode == seen_travel) { - bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); } else if (r->seen.mode == seen_neighbour) { - bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); } else if (r->seen.mode == seen_lighthouse) { - bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); } else { bytes = 0; @@ -974,7 +974,7 @@ static void describe(struct stream *out, const region * r, faction * f) saplings = rtrees(r, 1); if (production(r)) { if (trees > 0 || saplings > 0) { - bytes = _snprintf(bufp, size, ", %d/%d ", trees, saplings); + bytes = snprintf(bufp, size, ", %d/%d ", trees, saplings); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1004,7 +1004,7 @@ static void describe(struct stream *out, const region * r, faction * f) for (n = 0; n < numresults; ++n) { if (result[n].number >= 0 && result[n].level >= 0) { - bytes = _snprintf(bufp, size, ", %d %s/%d", result[n].number, + bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number, LOC(f->locale, result[n].name), result[n].level); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1015,14 +1015,14 @@ static void describe(struct stream *out, const region * r, faction * f) /* peasants & silver */ if (rpeasants(r)) { int n = rpeasants(r); - bytes = _snprintf(bufp, size, ", %d", n); + bytes = snprintf(bufp, size, ", %d", n); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (r->land->ownership) { const char *str = LOC(f->locale, mkname("morale", itoa10(region_get_morale(r)))); - bytes = _snprintf(bufp, size, " %s", str); + bytes = snprintf(bufp, size, " %s", str); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1041,7 +1041,7 @@ static void describe(struct stream *out, const region * r, faction * f) } } if (rmoney(r) && r->seen.mode >= seen_travel) { - bytes = _snprintf(bufp, size, ", %d ", rmoney(r)); + bytes = snprintf(bufp, size, ", %d ", rmoney(r)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = @@ -1053,7 +1053,7 @@ static void describe(struct stream *out, const region * r, faction * f) /* Pferde */ if (rhorses(r)) { - bytes = _snprintf(bufp, size, ", %d ", rhorses(r)); + bytes = snprintf(bufp, size, ", %d ", rhorses(r)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = @@ -1141,7 +1141,7 @@ static void describe(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); f_regionid(r2, f, regname, sizeof(regname)); - bytes = _snprintf(bufp, size, trailinto(r2, f->locale), regname); + bytes = snprintf(bufp, size, trailinto(r2, f->locale), regname); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1453,7 +1453,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) bufp = buf; size = sizeof(buf) - 1; - bytes = _snprintf(bufp, size, "%s %s; %s [%d,%d$", + bytes = snprintf(bufp, size, "%s %s; %s [%d,%d$", LOC(u->faction->locale, parameters[P_UNIT]), itoa36(u->no), unit_getname(u), u->number, get_money(u)); if (wrptr(&bufp, &size, bytes) != 0) @@ -1631,7 +1631,7 @@ static void allies(struct stream *out, const faction * f) if (f->allies) { int bytes; size_t size = sizeof(buf); - bytes = _snprintf(buf, size, "%s ", LOC(f->locale, "faction_help")); + bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help")); size -= bytes; show_allies(f, f->allies, buf + bytes, size); paragraph(out, buf, 0, 0, 0); @@ -1642,7 +1642,7 @@ static void allies(struct stream *out, const faction * f) if (g->allies) { int bytes; size_t size = sizeof(buf); - bytes = _snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help")); + bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help")); size -= bytes; show_allies(f, g->allies, buf + bytes, size); paragraph(out, buf, 0, 0, 0); @@ -1781,12 +1781,12 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, getshipweight(sh, &n, &p); n = (n + 99) / 100; /* 1 Silber = 1 GE */ - bytes = _snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), + bytes = snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), LOC(f->locale, sh->type->_name), n, shipcapacity(sh) / 100); } else { bytes = - _snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, + snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, sh->type->_name)); } if (wrptr(&bufp, &size, bytes) != 0) @@ -1794,7 +1794,7 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */ if (sh->size != sh->type->construction->maxsize) { - bytes = _snprintf(bufp, size, ", %s (%d/%d)", + bytes = snprintf(bufp, size, ", %s (%d/%d)", LOC(f->locale, "nr_undercons"), sh->size, sh->type->construction->maxsize); if (wrptr(&bufp, &size, bytes) != 0) @@ -1803,7 +1803,7 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, if (sh->damage) { int percent = ship_damage_percent(sh); bytes = - _snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); + snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1852,7 +1852,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio lang = f->locale; newline(out); bytes = - _snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang, + snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang, "nr_size"), b->size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1867,7 +1867,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio if (owner && owner->faction == f) { /* illusion. report real type */ name = LOC(lang, bname); - bytes = _snprintf(bufp, size, " (%s)", name); + bytes = snprintf(bufp, size, " (%s)", name); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -2168,7 +2168,7 @@ report_plaintext(const char *filename, report_context * ctx, bufp = buf; size = sizeof(buf) - 1; - bytes = _snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); + bytes = snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); for (op = 0; op != MAXOPTIONS; op++) { @@ -2220,14 +2220,14 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); centre(out, LOC(f->locale, pname), true); - _snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), + snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), ptype->level); centre(out, buf, true); newline(out); bufp = buf; size = sizeof(buf) - 1; - bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); + bytes = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); diff --git a/src/report.test.c b/src/report.test.c index 202458db5..ab7c377ce 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -140,7 +140,7 @@ static void cleanup_spell_fixture(spell_fixture *spf) { static void set_parameter(spell_fixture spell, char *value) { free(spell.sp->parameter); - spell.sp->parameter = _strdup(value); + spell.sp->parameter = strdup(value); } static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) { @@ -211,14 +211,14 @@ static void test_write_spell_syntax(CuTest *tc) { set_parameter(spell, "bc"); free(spell.sp->syntax); - spell.sp->syntax = _strdup("hodor"); + spell.sp->syntax = strdup("hodor"); check_spell_syntax(tc, "bc hodor", &spell, " ZAUBERE \"Testzauber\" "); free(spell.sp->syntax); spell.sp->syntax = 0; set_parameter(spell, "c?"); free(spell.sp->syntax); - spell.sp->syntax = _strdup("hodor"); + spell.sp->syntax = strdup("hodor"); check_spell_syntax(tc, "c?", &spell, " ZAUBERE \"Testzauber\" []"); free(spell.sp->syntax); spell.sp->syntax = 0; diff --git a/src/reports.c b/src/reports.c index 52278d270..b31ecac19 100644 --- a/src/reports.c +++ b/src/reports.c @@ -529,7 +529,7 @@ size_t size) if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) { faction *f = get_otherfaction(a_otherfaction); int result = - _snprintf(bufp, size, ", %s (%s)", factionname(f), + snprintf(bufp, size, ", %s (%s)", factionname(f), factionname(u->faction)); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); @@ -544,7 +544,7 @@ size_t size) bufp = STRLCPY(bufp, ", ", size); - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d ", u->number))) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d ", u->number))) WARN_STATIC_BUFFER(); pzTmp = get_racename(u->attribs); @@ -641,7 +641,7 @@ size_t size) bufp = STRLCPY(bufp, ", ", size); if (!dh) { - result = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); + result = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); dh = 1; @@ -650,7 +650,7 @@ size_t size) bufp = STRLCPY(bufp, ic, size); } else { - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d %s", in, ic))) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d %s", in, ic))) WARN_STATIC_BUFFER(); } } @@ -661,7 +661,7 @@ size_t size) if (book) { quicklist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC, 0); - int result = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); + int result = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); if (wrptr(&bufp, &size, result) != 0) { WARN_STATIC_BUFFER(); } @@ -671,7 +671,7 @@ size_t size) if (sbe->level <= maxlevel) { int result = 0; if (!header) { - result = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); + result = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); header = 1; } else { @@ -690,7 +690,7 @@ size_t size) } if (i != MAXCOMBATSPELLS) { int result = - _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); + snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); @@ -708,7 +708,7 @@ size_t size) int sl = get_combatspelllevel(u, i); bufp = STRLCPY(bufp, spell_name(sp, u->faction->locale), size); if (sl > 0) { - result = _snprintf(bufp, size, " (%d)", sl); + result = snprintf(bufp, size, " (%d)", sl); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); } @@ -819,13 +819,13 @@ const struct unit * u, struct skill * sv, int *dh, int days) if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) { i = u_geteffstealth(u); if (i >= 0) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d/", i)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0) WARN_STATIC_BUFFER(); } } effsk = eff_skill(u, sv, 0); - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d", effsk)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d", effsk)) != 0) WARN_STATIC_BUFFER(); if (u->faction->options & want(O_SHOWSKCHANGE)) { @@ -836,11 +836,11 @@ const struct unit * u, struct skill * sv, int *dh, int days) oldeff = sv->old + get_modifier(u, sv->id, sv->old, u->region, false); } - oldeff = _max(0, oldeff); + oldeff = MAX(0, oldeff); diff = effsk - oldeff; if (diff != 0) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0) WARN_STATIC_BUFFER(); } } @@ -877,7 +877,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned firstline = false; } if (!cut) { - cut = s + _min(len, REPORTWIDTH); + cut = s + MIN(len, REPORTWIDTH); } memcpy(buf + indent, s, cut - s); buf[indent + (cut - s)] = 0; @@ -1412,7 +1412,7 @@ int write_reports(faction * f, time_t ltime) int error = 0; do { char filename[32]; - char path[MAX_PATH]; + char path[4096]; sprintf(filename, "%d-%s.%s", turn, itoa36(f->no), rtype->extension); join_path(reportpath(), filename, path, sizeof(path)); @@ -1482,7 +1482,7 @@ int reports(void) FILE *mailit; time_t ltime = time(NULL); int retval = 0; - char path[MAX_PATH]; + char path[4096]; const char * rpath = reportpath(); log_info("Writing reports for turn %d:", turn); @@ -1509,7 +1509,7 @@ int reports(void) static variant var_copy_string(variant x) { - x.v = x.v ? _strdup((const char *)x.v) : 0; + x.v = x.v ? strdup((const char *)x.v) : 0; return x; } @@ -1613,7 +1613,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size) pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl); len = strlcpy(buffer, rname(r, f ? f->locale : 0), size); - _snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); + snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); buffer[size - 1] = 0; len = strlen(buffer); } @@ -1864,7 +1864,7 @@ static void eval_order(struct opstack **stack, const void *userdata) size_t len; variant var; - unused_arg(userdata); + UNUSED_ARG(userdata); write_order(ord, buf, sizeof(buf)); len = strlen(buf); var.v = strcpy(balloc(len + 1), buf); @@ -1884,7 +1884,7 @@ static void eval_resources(struct opstack **stack, const void *userdata) while (res != NULL && size > 4) { const char *rname = resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0); - int result = _snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname)); + int result = snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname)); if (wrptr(&bufp, &size, result) != 0 || size < sizeof(buf) / 2) { WARN_STATIC_BUFFER(); break; @@ -1948,7 +1948,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) variant var; char *bufp = buf; #ifdef _SECURECRT_ERRCODE_VALUES_DEFINED - /* stupid MS broke _snprintf */ + /* stupid MS broke snprintf */ int eold = errno; #endif @@ -1959,7 +1959,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) const char *trail = trailinto(r, lang); const char *rn = f_regionid_s(r, report); - if (wrptr(&bufp, &size, _snprintf(bufp, size, trail, rn)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, trail, rn)) != 0) WARN_STATIC_BUFFER(); if (i + 2 < end) { @@ -2015,7 +2015,7 @@ static void eval_int36(struct opstack **stack, const void *userdata) var.v = strcpy(balloc(len + 1), c); opush(stack, var); - unused_arg(userdata); + UNUSED_ARG(userdata); } /*** END MESSAGE RENDERING ***/ diff --git a/src/skill.h b/src/skill.h index 8b0c0c155..24f96a844 100644 --- a/src/skill.h +++ b/src/skill.h @@ -3,7 +3,7 @@ #ifndef H_SKILL_H #define H_SKILL_H -#include +#include struct locale; typedef enum { diff --git a/src/spells.c b/src/spells.c index 7e7b5669a..6ed38d022 100644 --- a/src/spells.c +++ b/src/spells.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -149,7 +150,7 @@ static void magicanalyse_region(region * r, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); found = true; if (chance(probability)) { /* Analyse geglueckt */ @@ -190,7 +191,7 @@ static void magicanalyse_unit(unit * u, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -231,7 +232,7 @@ static void magicanalyse_building(building * b, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -272,7 +273,7 @@ static void magicanalyse_ship(ship * sh, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -704,7 +705,7 @@ static int sp_destroy_magic(castorder * co) "unit region command", mage, mage->region, co->order)); } - return _max(succ, 1); + return MAX(succ, 1); } /* ------------------------------------------------------------- */ @@ -773,7 +774,7 @@ static int sp_transferaura(castorder * co) return 0; } - gain = _min(aura, scm_src->spellpoints) / multi; + gain = MIN(aura, scm_src->spellpoints) / multi; scm_src->spellpoints -= gain * multi; scm_dst->spellpoints += gain; @@ -912,7 +913,7 @@ static int sp_summonent(castorder * co) return 0; } - ents = _min((int)(power * power), rtrees(r, 2)); + ents = MIN((int)(power * power), rtrees(r, 2)); u = create_unit(r, mage->faction, ents, get_race(RC_TREEMAN), 0, NULL, mage); @@ -1304,7 +1305,7 @@ static int sp_rosthauch(castorder * co) for (; iweapon != NULL; iweapon = iweapon->next) { item **ip = i_find(&u->items, iweapon->type); if (*ip) { - float chance = (float)_min((*ip)->number, force); + float chance = (float)MIN((*ip)->number, force); if (iweapon->chance < 1.0) { chance *= iweapon->chance; } @@ -1343,7 +1344,7 @@ static int sp_rosthauch(castorder * co) * unguenstigsten Fall kann pro Stufe nur eine Waffe verzaubert werden, * darum wird hier nur fuer alle Faelle in denen noch weniger Waffen * betroffen wurden ein Kostennachlass gegeben */ - return _min(success, cast_level); + return MIN(success, cast_level); } /* ------------------------------------------------------------- */ @@ -1373,7 +1374,7 @@ static int sp_kaelteschutz(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; double force = co->force; - int duration = _max(cast_level, (int)force) + 1; + int duration = MAX(cast_level, (int)force) + 1; spellparameter *pa = co->par; double effect; @@ -2137,8 +2138,8 @@ static int sp_drought(castorder * co) */ c = get_curse(r->attribs, ct_find("drought")); if (c) { - c->vigour = _max(c->vigour, power); - c->duration = _max(c->duration, (int)power); + c->vigour = MAX(c->vigour, power); + c->duration = MAX(c->duration, (int)power); } else { double effect = 4.0; @@ -2335,8 +2336,8 @@ static int sp_earthquake(castorder * co) if (burg->size != 0 && !is_cursed(burg->attribs, C_MAGICWALLS, 0)) { /* Magieresistenz */ if (!target_resists_magic(mage, burg, TYP_BUILDING, 0)) { - kaputt = _min(10 * cast_level, burg->size / 4); - kaputt = _max(kaputt, 1); + kaputt = MIN(10 * cast_level, burg->size / 4); + kaputt = MAX(kaputt, 1); burg->size -= kaputt; if (burg->size == 0) { /* TODO: sollten die Insassen nicht Schaden nehmen? */ @@ -2501,7 +2502,7 @@ static int sp_forest_fire(castorder * co) * das Zaubern. Patzer werden warscheinlicher. * Jeder Zauber muss erst gegen den Wiederstand des Fluchs gezaubert * werden und schwaecht dessen Antimagiewiederstand um 1. - * Wirkt _max(Stufe(Magier) - Stufe(Ziel), rand(3)) Wochen + * Wirkt MAX(Stufe(Magier) - Stufe(Ziel), rand(3)) Wochen * Patzer: * Magier wird selbst betroffen * @@ -2529,7 +2530,7 @@ static int sp_fumblecurse(castorder * co) rx = rng_int() % 3; sx = cast_level - effskill(target, SK_MAGIC, 0); - duration = _max(sx, rx) + 1; + duration = MAX(sx, rx) + 1; effect = force / 2; c = create_curse(mage, &target->attribs, ct_find("fumble"), @@ -2695,8 +2696,8 @@ static int sp_firewall(castorder * co) } else { fd = (wall_data *)b->data.v; - fd->force = (int)_max(fd->force, force / 2 + 0.5); - fd->countdown = _max(fd->countdown, cast_level + 1); + fd->force = (int)MAX(fd->force, force / 2 + 0.5); + fd->countdown = MAX(fd->countdown, cast_level + 1); } /* melden, 1x pro Partei */ @@ -2938,7 +2939,7 @@ attrib_type at_deathcloud_compat = { * Ruestung wirkt nicht * Patzer: * Magier geraet in den Staub und verliert zufaellige Zahl von HP bis -* auf _max(hp,2) +* auf MAX(hp,2) * Besonderheiten: * Nicht als curse implementiert, was schlecht ist - man kann dadurch * kein dispell machen. Wegen fix unter Zeitdruck erstmal nicht zu @@ -3361,7 +3362,7 @@ static int sp_summonundead(castorder * co) return 0; } - undead = _min(deathcount(r), 2 + lovar(force)); + undead = MIN(deathcount(r), 2 + lovar(force)); if (cast_level <= 8) { race = get_race(RC_SKELETON); @@ -3409,7 +3410,7 @@ static int sp_auraleak(castorder * co) int cast_level = co->level; message *msg; - lost = _min(0.95, cast_level * 0.05); + lost = MIN(0.95, cast_level * 0.05); for (u = r->units; u; u = u->next) { if (is_mage(u)) { @@ -3792,8 +3793,8 @@ static int sp_raisepeasantmob(castorder * co) anteil = 6 + (rng_int() % 4); n = rpeasants(r) * anteil / 10; - n = _max(0, n); - n = _min(n, rpeasants(r)); + n = MAX(0, n); + n = MIN(n, rpeasants(r)); if (n <= 0) { report_failure(mage, co->order); @@ -4032,13 +4033,13 @@ static int sp_recruit(castorder * co) n = (pow(force, 1.6) * 100) / f->race->recruitcost; if (rc->recruit_multi > 0) { double multp = (double)maxp / rc->recruit_multi; - n = _min(multp, n); - n = _max(n, 1); + n = MIN(multp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - (int)(n * rc->recruit_multi)); } else { - n = _min(maxp, n); - n = _max(n, 1); + n = MIN(maxp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - (int)n); } @@ -4083,13 +4084,13 @@ static int sp_bigrecruit(castorder * co) n = (int)force + lovar((force * force * 1000) / (float)f->race->recruitcost); if (f->race == get_race(RC_ORC)) { - n = _min(2 * maxp, n); - n = _max(n, 1); + n = MIN(2 * maxp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - (n + 1) / 2); } else { - n = _min(maxp, n); - n = _max(n, 1); + n = MIN(maxp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - n); } @@ -4178,7 +4179,7 @@ static int sp_pump(castorder * co) * Betoert eine Einheit, so das sie ihm den groe�ten Teil ihres Bargelds * und 50% ihres Besitzes schenkt. Sie behaelt jedoch immer soviel, wie * sie zum ueberleben braucht. Wirkt gegen Magieresistenz. - * _min(Stufe*1000$, u->money - maintenace) + * MIN(Stufe*1000$, u->money - maintenace) * Von jedem Item wird 50% abgerundet ermittelt und uebergeben. Dazu * kommt Itemzahl%2 mit 50% chance * @@ -4215,8 +4216,8 @@ static int sp_seduce(castorder * co) int loot; if (itm->type->rtype == rsilver) { loot = - _min(cast_level * 1000, get_money(target) - (maintenance_cost(target))); - loot = _max(loot, 0); + MIN(cast_level * 1000, get_money(target) - (maintenance_cost(target))); + loot = MAX(loot, 0); } else { loot = itm->number / 2; @@ -4224,7 +4225,7 @@ static int sp_seduce(castorder * co) loot += rng_int() % 2; } if (loot > 0) { - loot = _min(loot, (int)(force * 5)); + loot = MIN(loot, (int)(force * 5)); } } if (loot > 0) { @@ -4341,7 +4342,7 @@ static int sp_headache(castorder * co) } if (smax != NULL) { /* wirkt auf maximal 10 Personen */ - unsigned int change = _min(10, target->number) * (rng_uint() % 2 + 1) / target->number; + unsigned int change = MIN(10, target->number) * (rng_uint() % 2 + 1) / target->number; reduce_skill(target, smax, change); } set_order(&target->thisorder, NULL); @@ -4385,7 +4386,7 @@ static int sp_raisepeasants(castorder * co) "error_nopeasants", "")); return 0; } - bauern = _min(rpeasants(r), (int)(power * 250)); + bauern = MIN(rpeasants(r), (int)(power * 250)); rsetpeasants(r, rpeasants(r) - bauern); u2 = @@ -4468,7 +4469,7 @@ int sp_puttorest(castorder * co) message *seen = msg_message("puttorest", "mage", mage); message *unseen = msg_message("puttorest", "mage", NULL); - laid_to_rest = _max(laid_to_rest, dead); + laid_to_rest = MAX(laid_to_rest, dead); deathcounts(r, -laid_to_rest); @@ -4713,7 +4714,7 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) /* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken, * also duration+2 */ - duration = (int)_max(1, power / 2); /* Stufe 1 macht sonst mist */ + duration = (int)MAX(1, power / 2); /* Stufe 1 macht sonst mist */ duration = 2 + rng_int() % duration; /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ @@ -4752,7 +4753,7 @@ int sp_clonecopy(castorder * co) return 0; } - _snprintf(name, sizeof(name), (const char *)LOC(mage->faction->locale, + slprintf(name, sizeof(name), (const char *)LOC(mage->faction->locale, "clone_of"), unitname(mage)); clone = create_unit(target_region, mage->faction, 1, get_race(RC_CLONE), 0, name, @@ -4855,7 +4856,7 @@ int sp_sweetdreams(castorder * co) cmistake(mage, co->order, 40, MSG_EVENT); continue; } - men = _min(opfer, u->number); + men = MIN(opfer, u->number); opfer -= men; /* Nichts machen als ein entsprechendes Attribut an die Einheit legen. */ @@ -4969,7 +4970,7 @@ int sp_itemcloak(castorder * co) spellparameter *pa = co->par; int cast_level = co->level; double power = co->force; - int duration = (int)_max(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ + int duration = (int)MAX(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ /* wenn kein Ziel gefunden, Zauber abbrechen */ if (pa->param[0]->flag == TARGET_NOTFOUND) @@ -5027,7 +5028,7 @@ int sp_resist_magic_bonus(castorder * co) u = pa->param[n]->data.u; - m = _min(u->number, victims); + m = MIN(u->number, victims); victims -= m; create_curse(mage, &u->attribs, ct_find("magicresistance"), @@ -5043,8 +5044,8 @@ int sp_resist_magic_bonus(castorder * co) msg_release(msg); } - cast_level = _min(cast_level, (int)(cast_level * (victims + 4) / maxvictims)); - return _max(cast_level, 1); + cast_level = MIN(cast_level, (int)(cast_level * (victims + 4) / maxvictims)); + return MAX(cast_level, 1); } /** spell 'Astraler Weg'. @@ -5656,7 +5657,7 @@ int sp_showastral(castorder * co) free_regionlist(rl); return cast_level; - unused_arg(co); + UNUSED_ARG(co); return 0; } #endif @@ -5907,7 +5908,7 @@ int sp_permtransfer(castorder * co) return 0; } - aura = _min(get_spellpoints(mage) - spellcost(mage, sp), aura); + aura = MIN(get_spellpoints(mage) - spellcost(mage, sp), aura); change_maxspellpoints(mage, -aura); change_spellpoints(mage, -aura); @@ -6216,7 +6217,7 @@ int sp_speed2(castorder * co) spellparameter *pa = co->par; maxmen = 2 * cast_level * cast_level; - dur = _max(1, cast_level / 2); + dur = MAX(1, cast_level / 2); for (n = 0; n < pa->length; n++) { double effect; @@ -6230,7 +6231,7 @@ int sp_speed2(castorder * co) u = pa->param[n]->data.u; - men = _min(maxmen, u->number); + men = MIN(maxmen, u->number); effect = 2; create_curse(mage, &u->attribs, ct_find("speed"), force, dur, effect, men); maxmen -= men; @@ -6241,7 +6242,7 @@ int sp_speed2(castorder * co) "unit region amount", mage, mage->region, used)); /* Effektiv benoetigten cast_level (mindestens 1) zurueckgeben */ used = (int)sqrt(used / 2); - return _max(1, used); + return MAX(1, used); } /* ------------------------------------------------------------- */ @@ -6324,7 +6325,7 @@ int sp_q_antimagie(castorder * co) ADDMSG(&mage->faction->msgs, msg_message("destroy_magic_noeffect", "unit region command", mage, mage->region, co->order)); } - return _max(succ, 1); + return MAX(succ, 1); } /* ------------------------------------------------------------- */ diff --git a/src/spells/borders.c b/src/spells/borders.c index 04f7e15f4..00019e92c 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -206,7 +206,7 @@ struct region *from, struct region *to, bool routing) wall_data *fd = (wall_data *)b->data.v; if (!routing && fd->active) { int hp = dice(3, fd->force) * u->number; - hp = _min(u->hp, hp); + hp = MIN(u->hp, hp); u->hp -= hp; if (u->hp) { ADDMSG(&u->faction->msgs, msg_message("firewall_damage", @@ -227,9 +227,9 @@ static const char *b_namefirewall(const connection * b, const region * r, const faction * f, int gflags) { const char *bname; - unused_arg(f); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(f); + UNUSED_ARG(r); + UNUSED_ARG(b); if (gflags & GF_ARTICLE) bname = "a_firewall"; else diff --git a/src/spells/borders.h b/src/spells/borders.h index 31823df94..b14661b9f 100644 --- a/src/spells/borders.h +++ b/src/spells/borders.h @@ -1,5 +1,8 @@ #ifndef H_KRNL_CURSES #define H_KRNL_CURSES + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/spells/buildingcurse.c b/src/spells/buildingcurse.c index 01b0435ab..158383fd2 100644 --- a/src/spells/buildingcurse.c +++ b/src/spells/buildingcurse.c @@ -36,7 +36,7 @@ message *cinfo_building(const void *obj, objtype_t typ, const curse * c, int self) { const building *b = (const building *)obj; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_BUILDING); assert(obj); assert(c); diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index da7e7085a..0e1a27e75 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -337,14 +337,14 @@ int sp_combatrosthauch(struct castorder * co) if (force <= 0) break; - /* da n _min(force, x), sollte force maximal auf 0 sinken */ + /* da n MIN(force, x), sollte force maximal auf 0 sinken */ assert(force >= 0); if (df->weapons) { int w; for (w = 0; df->weapons[w].type != NULL; ++w) { weapon *wp = df->weapons; - int n = _min(force, wp->used); + int n = MIN(force, wp->used); if (n) { requirement *mat = wp->type->itype->construction->materials; bool iron = false; @@ -921,7 +921,7 @@ int sp_shadowknights(struct castorder * co) region *r = b->region; unit *mage = fi->unit; attrib *a; - int force = _max(1, (int)get_force(power, 3)); + int force = MAX(1, (int)get_force(power, 3)); message *msg; u = @@ -1015,7 +1015,7 @@ int sp_chaosrow(struct castorder * co) continue; if (power <= 0.0) break; - /* force sollte wegen des _max(0,x) nicht unter 0 fallen k�nnen */ + /* force sollte wegen des MAX(0,x) nicht unter 0 fallen k�nnen */ if (is_magic_resistant(mage, df->unit, 0)) continue; @@ -1050,7 +1050,7 @@ int sp_chaosrow(struct castorder * co) } k += df->alive; } - power = _max(0, power - n); + power = MAX(0, power - n); } ql_free(fgs); @@ -1154,12 +1154,12 @@ int sp_hero(struct castorder * co) switch (sp->id) { case SPL_HERO: df_bonus = (int)(power / 5); - force = _max(1, lovar(get_force(power, 4))); + force = MAX(1, lovar(get_force(power, 4))); break; default: df_bonus = 1; - force = _max(1, (int)power); + force = MAX(1, (int)power); } allies = @@ -1208,7 +1208,7 @@ int sp_berserk(struct castorder * co) switch (sp->id) { case SPL_BERSERK: case SPL_BLOODTHIRST: - at_bonus = _max(1, level / 3); + at_bonus = MAX(1, level / 3); df_malus = 2; force = (int)get_force(power, 2); break; @@ -1264,7 +1264,7 @@ int sp_frighten(struct castorder * co) int targets = 0; message *m; - at_malus = _max(1, level - 4); + at_malus = MAX(1, level - 4); df_malus = 2; force = (int)get_force(power, 2); @@ -1545,7 +1545,7 @@ int sp_fumbleshield(struct castorder * co) case SPL_CERDDOR_FUMBLESHIELD: case SPL_TYBIED_FUMBLESHIELD: duration = 100; - effect = _max(1, 25 - level); + effect = MAX(1, 25 - level); break; default: @@ -1596,7 +1596,7 @@ int sp_reanimate(struct castorder * co) } healable = count_healable(b, fi); - healable = (int)_min(k, healable); + healable = (int)MIN(k, healable); while (healable--) { fighter *tf = select_corpse(b, fi); if (tf != NULL && tf->side->casualties > 0 @@ -1649,7 +1649,7 @@ int sp_keeploot(struct castorder * co) message_all(b, m); msg_release(m); - b->keeploot = (int)_max(25, b->keeploot + 5 * power); + b->keeploot = (int)MAX(25, b->keeploot + 5 * power); return level; } @@ -1680,10 +1680,10 @@ static int heal_fighters(quicklist * fgs, int *power, bool heal_monsters) ++wound; if (wound > 0 && wound < hp) { - int heal = _min(healhp, wound); + int heal = MIN(healhp, wound); assert(heal >= 0); df->person[n].hp += heal; - healhp = _max(0, healhp - heal); + healhp = MAX(0, healhp - heal); ++healed; if (healhp <= 0) break; @@ -1834,7 +1834,7 @@ int sp_undeadhero(struct castorder * co) } ql_free(fgs); - level = _min(level, undead); + level = MIN(level, undead); if (undead == 0) { msg = msg_message("summonundead_effect_0", "mage region", mage, mage->region); diff --git a/src/spells/flyingship.h b/src/spells/flyingship.h index 8b7bf0874..52013ac13 100644 --- a/src/spells/flyingship.h +++ b/src/spells/flyingship.h @@ -3,6 +3,8 @@ #ifndef FLYINGSHIP_H #define FLYINGSHIP_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 3d7593484..b10f3046f 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -45,8 +45,8 @@ static message *cinfo_cursed_by_the_gods(const void *obj, objtype_t typ, { region *r = (region *)obj; - unused_arg(typ); - unused_arg(self); + UNUSED_ARG(typ); + UNUSED_ARG(self); assert(typ == TYP_REGION); if (r->terrain->flags & SEA_REGION) { @@ -68,9 +68,9 @@ static struct curse_type ct_godcursezone = { static message *cinfo_dreamcurse(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(self); - unused_arg(typ); - unused_arg(obj); + UNUSED_ARG(self); + UNUSED_ARG(typ); + UNUSED_ARG(obj); assert(typ == TYP_REGION); if (c->effect > 0) { @@ -94,9 +94,9 @@ static struct curse_type ct_gbdream = { static message *cinfo_magicstreet(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); - unused_arg(self); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(self); + UNUSED_ARG(obj); assert(typ == TYP_REGION); /* Warnung vor Auflösung */ @@ -117,9 +117,9 @@ static struct curse_type ct_magicstreet = { static message *cinfo_antimagiczone(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); - unused_arg(self); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(self); + UNUSED_ARG(obj); assert(typ == TYP_REGION); /* Magier spüren eine Antimagiezone */ @@ -139,7 +139,7 @@ const curse * c, int self) unit *u = NULL; unit *mage = c->magician; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_REGION); r = (region *)obj; @@ -167,8 +167,8 @@ static struct curse_type ct_antimagiczone = { static message *cinfo_farvision(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(obj); assert(typ == TYP_REGION); diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index 59cc534d4..b6a722ad3 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -38,8 +38,8 @@ message *cinfo_ship(const void *obj, objtype_t typ, const curse * c, int self) { message *msg; - unused_arg(typ); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(obj); assert(typ == TYP_SHIP); if (self != 0) { /* owner or inside */ @@ -62,7 +62,7 @@ static message *cinfo_shipnodrift(const void *obj, objtype_t typ, const curse * { ship *sh = (ship *)obj; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_SHIP); if (self != 0) { diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index 6e769145e..ded4a1676 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -46,7 +46,7 @@ static message *cinfo_auraboost(const void *obj, objtype_t typ, const curse * c, int self) { struct unit *u = (struct unit *)obj; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (self != 0) { @@ -80,7 +80,7 @@ static message *cinfo_slave(const void *obj, objtype_t typ, const curse * c, int self) { unit *u; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); u = (unit *)obj; @@ -104,7 +104,7 @@ cinfo_slave static message *cinfo_calm(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (c->magician && c->magician->faction) { @@ -133,7 +133,7 @@ static struct curse_type ct_calmmonster = { static message *cinfo_speed(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (self != 0) { @@ -156,7 +156,7 @@ static struct curse_type ct_speed = { */ message *cinfo_unit(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); assert(obj); @@ -181,7 +181,7 @@ static struct curse_type ct_orcish = { static message *cinfo_kaelteschutz(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (self != 0) { @@ -233,7 +233,7 @@ static message *cinfo_sparkle(const void *obj, objtype_t typ, const curse * c, }; int m, begin = 0, end = 0; unit *u; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); u = (unit *)obj; @@ -324,7 +324,7 @@ write_skill(struct storage *store, const curse * c, const void *target) static message *cinfo_skillmod(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); if (self != 0) { unit *u = (unit *)obj; diff --git a/src/spy.c b/src/spy.c index 22c548d68..a7d08d42e 100644 --- a/src/spy.c +++ b/src/spy.c @@ -148,7 +148,7 @@ int spy_cmd(unit * u, struct order *ord) * Fuer jeden Talentpunkt, den das Spionagetalent das Tarnungstalent * des Opfers uebersteigt, erhoeht sich dieses um 5%*/ spy = effskill(u, SK_SPY, 0) - effskill(target, SK_STEALTH, r); - spychance = 0.1 + _max(spy * 0.05, 0.0); + spychance = 0.1 + MAX(spy * 0.05, 0.0); if (chance(spychance)) { produceexp(u, SK_SPY, u->number); @@ -164,7 +164,7 @@ int spy_cmd(unit * u, struct order *ord) - (effskill(u, SK_STEALTH, 0) + effskill(u, SK_SPY, 0) / 2); if (invisible(u, target) >= u->number) { - observe = _min(observe, 0); + observe = MIN(observe, 0); } /* Anschliessend wird - unabhaengig vom Erfolg - gewuerfelt, ob der @@ -354,7 +354,7 @@ static int top_skill(region * r, faction * f, ship * sh, skill_t sk) for (u = r->units; u; u = u->next) { if (u->ship == sh && u->faction == f) { int s = effskill(u, sk, 0); - value = _max(s, value); + value = MAX(s, value); } } return value; diff --git a/src/sqlite.c b/src/sqlite.c index 42bfdb3b5..aea0f5d20 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -94,9 +94,9 @@ read_factions(sqlite3 * db, int game_id) { text = (const char *)sqlite3_column_text(stmt, 1); if (text) dbf->no = atoi36(text); text = (const char *)sqlite3_column_text(stmt, 2); - if (text) dbf->name = _strdup(text); + if (text) dbf->name = strdup(text); text = (const char *)sqlite3_column_text(stmt, 3); - if (text) dbf->email = _strdup(text); + if (text) dbf->email = strdup(text); ql_push(&result, dbf); res = sqlite3_step(stmt); } diff --git a/src/study.c b/src/study.c index 58cd068f2..b69b4359f 100644 --- a/src/study.c +++ b/src/study.c @@ -201,7 +201,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, * steigen. * * n ist die Anzahl zusaetzlich gelernter Tage. n darf max. die Differenz - * von schon gelernten Tagen zum _max(30 Tage pro Mann) betragen. */ + * von schon gelernten Tagen zum MAX(30 Tage pro Mann) betragen. */ if (magic_lowskill(student)) { cmistake(teacher, teacher->thisorder, 292, MSG_EVENT); @@ -215,7 +215,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, n -= teach->value; } - n = _min(n, nteaching); + n = MIN(n, nteaching); if (n != 0) { if (teach == NULL) { @@ -267,7 +267,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, * die Talentaenderung (enno). */ - nteaching = _max(0, nteaching - student->number * 30); + nteaching = MAX(0, nteaching - student->number * 30); } return n; @@ -303,7 +303,7 @@ int teach_cmd(unit * u, struct order *ord) teaching = u->number * 30 * TEACHNUMBER; if ((i = get_effect(u, oldpotiontype[P_FOOL])) > 0) { /* Trank "Dumpfbackenbrot" */ - i = _min(i, u->number * TEACHNUMBER); + i = MIN(i, u->number * TEACHNUMBER); /* Trank wirkt pro Schueler, nicht pro Lehrer */ teaching -= i * 30; change_effect(u, oldpotiontype[P_FOOL], -i); @@ -604,7 +604,7 @@ int study_cmd(unit * u, order * ord) } /* Akademie: */ if (active_building(u, bt_find("academy"))) { - studycost = _max(50, studycost * 2); + studycost = MAX(50, studycost * 2); } if (sk == SK_MAGIC) { @@ -691,11 +691,11 @@ int study_cmd(unit * u, order * ord) if (studycost) { int cost = studycost * u->number; money = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, cost); - money = _min(money, cost); + money = MIN(money, cost); } if (money < studycost * u->number) { studycost = p; /* Ohne Univertreurung */ - money = _min(money, studycost); + money = MIN(money, studycost); if (p > 0 && money < studycost * u->number) { cmistake(u, ord, 65, MSG_EVENT); multi = money / (double)(studycost * u->number); @@ -715,12 +715,12 @@ int study_cmd(unit * u, order * ord) } if (get_effect(u, oldpotiontype[P_WISE])) { - l = _min(u->number, get_effect(u, oldpotiontype[P_WISE])); + l = MIN(u->number, get_effect(u, oldpotiontype[P_WISE])); teach->value += l * 10; change_effect(u, oldpotiontype[P_WISE], -l); } if (get_effect(u, oldpotiontype[P_FOOL])) { - l = _min(u->number, get_effect(u, oldpotiontype[P_FOOL])); + l = MIN(u->number, get_effect(u, oldpotiontype[P_FOOL])); teach->value -= l * 30; change_effect(u, oldpotiontype[P_FOOL], -l); } diff --git a/src/summary.c b/src/summary.c index 8a3ee3c41..32416a263 100644 --- a/src/summary.c +++ b/src/summary.c @@ -97,8 +97,8 @@ int update_nmrs(void) if (timeout>0) { if (nmr < 0 || nmr > timeout) { log_error("faction %s has %d NMR", itoa36(f->no), nmr); - nmr = _max(0, nmr); - nmr = _min(nmr, timeout); + nmr = MAX(0, nmr); + nmr = MIN(nmr, timeout); } if (nmr > 0) { log_debug("faction %s has %d NMR", itoa36(f->no), nmr); @@ -164,7 +164,7 @@ static char *gamedate2(const struct locale *lang) static void writeturn(void) { - char zText[MAX_PATH]; + char zText[4096]; FILE *f; join_path(basepath(), "datum", zText, sizeof(zText)); @@ -190,7 +190,7 @@ void report_summary(summary * s, summary * o, bool full) FILE *F = NULL; int i, newplayers = 0; faction *f; - char zText[MAX_PATH]; + char zText[4096]; int timeout = NMRTimeout(); if (full) { diff --git a/src/test_eressea.c b/src/test_eressea.c index 6d2dead3f..02d52c5ed 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -33,7 +33,7 @@ static void add_suite(CuSuite *(*csuite)(void), const char *name, int argc, char } if (s) { s->next = suites; - s->name = _strdup(name); + s->name = strdup(name); s->csuite = csuite(); suites = s; } diff --git a/src/travelthru.test.c b/src/travelthru.test.c index be87743d2..09d807674 100644 --- a/src/travelthru.test.c +++ b/src/travelthru.test.c @@ -15,7 +15,7 @@ struct attrib; static void count_travelers(region *r, unit *u, void *cbdata) { int *n = (int *)cbdata; - unused_arg(r); + UNUSED_ARG(r); *n += u->number; } diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index 37d993f4a..3de537c7b 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -70,7 +70,7 @@ static int changefaction_handle(trigger * t, void *data) else { log_error("could not perform changefaction::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/changerace.c b/src/triggers/changerace.c index f38b7f3d5..a9f282698 100644 --- a/src/triggers/changerace.c +++ b/src/triggers/changerace.c @@ -74,7 +74,7 @@ static int changerace_handle(trigger * t, void *data) else { log_error("could not perform changerace::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/clonedied.c b/src/triggers/clonedied.c index 642b50ab0..f3d1fc00b 100644 --- a/src/triggers/clonedied.c +++ b/src/triggers/clonedied.c @@ -58,7 +58,7 @@ static int clonedied_handle(trigger * t, void *data) } else log_error("could not perform clonedied::handle()\n"); - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index 040a4e7b7..3eb0891ca 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -76,7 +76,7 @@ static int createcurse_handle(trigger * t, void *data) else { log_error("could not perform createcurse::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 5952c88bc..41573d86b 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -74,7 +74,7 @@ static int createunit_handle(trigger * t, void *data) else { log_error("could not perform createunit::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/gate.c b/src/triggers/gate.c index e681efc04..c70163a14 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -57,7 +57,7 @@ static int gate_handle(trigger * t, void *data) log_error("could not perform gate::handle()\n"); return -1; } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/giveitem.c b/src/triggers/giveitem.c index 6b0e8f8c7..9bc2c56e1 100644 --- a/src/triggers/giveitem.c +++ b/src/triggers/giveitem.c @@ -70,7 +70,7 @@ static int giveitem_handle(trigger * t, void *data) else { log_error("could not perform giveitem::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/killunit.c b/src/triggers/killunit.c index 22ad27896..3e6c9defe 100644 --- a/src/triggers/killunit.c +++ b/src/triggers/killunit.c @@ -48,7 +48,7 @@ static int killunit_handle(trigger * t, void *data) /* we can't remove_unit() here, because that's what's calling us. */ set_number(u, 0); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 7c54676e0..31424e979 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -60,8 +60,8 @@ static void do_shock(unit * u, const char *reason) if (u->number > 0) { /* HP - Verlust */ int hp = (unit_max_hp(u) * u->number) / 10; - hp = _min(u->hp, hp); - u->hp = _max(1, hp); + hp = MIN(u->hp, hp); + u->hp = MAX(1, hp); } /* Aura - Verlust */ @@ -102,7 +102,7 @@ static int shock_handle(trigger * t, void *data) if (u && u->number) { do_shock(u, "trigger"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/timeout.c b/src/triggers/timeout.c index 10e4d08be..43bb061c8 100644 --- a/src/triggers/timeout.c +++ b/src/triggers/timeout.c @@ -61,7 +61,7 @@ static int timeout_handle(trigger * t, void *data) handle_triggers(&td->triggers, NULL); return -1; } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/unitmessage.c b/src/triggers/unitmessage.c index 0c1e80124..7ba97d9bc 100644 --- a/src/triggers/unitmessage.c +++ b/src/triggers/unitmessage.c @@ -71,7 +71,7 @@ static int unitmessage_handle(trigger * t, void *data) td->level); } } - unused_arg(data); + UNUSED_ARG(data); return 0; } @@ -92,7 +92,7 @@ static int unitmessage_read(trigger * t, gamedata *data) int result = read_reference(&td->target, data, read_unit_reference, resolve_unit); READ_TOK(data->store, zText, sizeof(zText)); - td->string = _strdup(zText); + td->string = strdup(zText); READ_INT(data->store, &td->type); READ_INT(data->store, &td->level); @@ -117,7 +117,7 @@ trigger *trigger_unitmessage(unit * target, const char *string, int type, trigger *t = t_new(&tt_unitmessage); unitmessage_data *td = (unitmessage_data *)t->data.v; td->target = target; - td->string = _strdup(string); + td->string = strdup(string); td->type = type; td->level = level; return t; diff --git a/src/upkeep.c b/src/upkeep.c index 1cf41011f..94cbc341d 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -47,7 +47,7 @@ static void help_feed(unit * donor, unit * u, int *need_p) { int need = *need_p; int give = get_money(donor) - lifestyle(donor); - give = _min(need, give); + give = MIN(need, give); if (give > 0) { change_money(donor, -give); @@ -161,7 +161,7 @@ void get_food(region * r) * food from the peasants - should not be used with WORK */ if (owner != NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) { int rm = rmoney(r); - int use = _min(rm, need); + int use = MIN(rm, need); rsetmoney(r, rm - use); need -= use; } @@ -174,7 +174,7 @@ void get_food(region * r) for (v = r->units; need && v; v = v->next) { if (v->faction == u->faction && help_money(v)) { int give = get_money(v) - lifestyle(v); - give = _min(need, give); + give = MIN(need, give); if (give > 0) { change_money(v, -give); change_money(u, give); @@ -191,7 +191,7 @@ void get_food(region * r) int need = lifestyle(u); faction *f = u->faction; - need -= _max(0, get_money(u)); + need -= MAX(0, get_money(u)); if (need > 0) { unit *v; @@ -247,7 +247,7 @@ void get_food(region * r) unit *donor = u; while (donor != NULL && hungry > 0) { int blut = get_effect(donor, pt_blood); - blut = _min(blut, hungry); + blut = MIN(blut, hungry); if (blut) { change_effect(donor, pt_blood, -blut); hungry -= blut; @@ -295,7 +295,7 @@ void get_food(region * r) /* 3. Von den überlebenden das Geld abziehen: */ for (u = r->units; u; u = u->next) { - int need = _min(get_money(u), lifestyle(u)); + int need = MIN(get_money(u), lifestyle(u)); change_money(u, -need); } } diff --git a/src/util/attrib.c b/src/util/attrib.c index 4bdf35bfa..a99a70ba3 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -124,7 +124,7 @@ int a_readstring(attrib * a, void *owner, struct gamedata *data) len += DISPLAYSIZE - 1; } else { - result = _strdup(buf); + result = strdup(buf); } } while (e == ENOMEM); a->data.v = result; diff --git a/src/util/attrib.h b/src/util/attrib.h index d93ce1240..45dc9b942 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef ATTRIB_H #define ATTRIB_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/attrib.test.c b/src/util/attrib.test.c index 7fa2ef82c..b44afeec2 100644 --- a/src/util/attrib.test.c +++ b/src/util/attrib.test.c @@ -119,7 +119,7 @@ static void test_attrib_rwstring(CuTest *tc) { attrib a = { 0 }; test_setup(); - a.data.v = _strdup("Hello World"); + a.data.v = strdup("Hello World"); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); a_writestring(&a, NULL, &store); diff --git a/src/util/crmessage.c b/src/util/crmessage.c index 98afe0f05..47bb6bf7d 100644 --- a/src/util/crmessage.c +++ b/src/util/crmessage.c @@ -145,21 +145,21 @@ int cr_render(const message * msg, char *buffer, const void *userdata) int cr_string(variant var, char *buffer, const void *userdata) { sprintf(buffer, "\"%s\"", (const char *)var.v); - unused_arg(userdata); + UNUSED_ARG(userdata); return 0; } int cr_int(variant var, char *buffer, const void *userdata) { sprintf(buffer, "%d", var.i); - unused_arg(userdata); + UNUSED_ARG(userdata); return 0; } int cr_ignore(variant var, char *buffer, const void *userdata) { - unused_arg(var); - unused_arg(buffer); - unused_arg(userdata); + UNUSED_ARG(var); + UNUSED_ARG(buffer); + UNUSED_ARG(userdata); return -1; } diff --git a/src/util/event.c b/src/util/event.c index cdf178aec..78a6d6fbc 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -153,7 +153,7 @@ static int read_handler(attrib * a, void *owner, gamedata *data) handler_info *hi = (handler_info *)a->data.v; READ_TOK(store, zText, sizeof(zText)); - hi->event = _strdup(zText); + hi->event = strdup(zText); read_triggers(data, &hi->triggers); if (hi->triggers != NULL) { return AT_READ_OK; @@ -200,7 +200,7 @@ void add_trigger(struct attrib **ap, const char *eventname, struct trigger *t) if (a == NULL || a->type != &at_eventhandler) { a = a_add(ap, a_new(&at_eventhandler)); td = (handler_info *)a->data.v; - td->event = _strdup(eventname); + td->event = strdup(eventname); } tp = &td->triggers; while (*tp) diff --git a/src/util/goodies.c b/src/util/goodies.c index 2444d0f47..c478bcf83 100644 --- a/src/util/goodies.c +++ b/src/util/goodies.c @@ -113,7 +113,7 @@ int set_email(char **pemail, const char *newmail) free(*pemail); *pemail = 0; if (newmail) { - *pemail = _strdup(newmail); + *pemail = strdup(newmail); } return 0; } diff --git a/src/util/language.c b/src/util/language.c index cb91d7419..efd5cd5f7 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -86,7 +86,7 @@ locale *get_or_create_locale(const char *name) *lp = l = (locale *)calloc(sizeof(locale), 1); assert_alloc(l); l->hashkey = hkey; - l->name = _strdup(name); + l->name = strdup(name); l->index = nextlocaleindex++; assert(nextlocaleindex <= MAXLOCALES); if (default_locale == NULL) default_locale = l; @@ -209,15 +209,15 @@ void locale_setstring(locale * lang, const char *key, const char *value) find->nexthash = lang->strings[id]; lang->strings[id] = find; find->hashkey = hkey; - find->key = _strdup(key); - find->str = _strdup(value); + find->key = strdup(key); + find->str = strdup(value); } else { if (strcmp(find->str, value) != 0) { log_warning("multiple translations for key %s\n", key); } free(find->str); - find->str = _strdup(value); + find->str = strdup(value); } } diff --git a/src/util/language.h b/src/util/language.h index a90398cc0..36bc58378 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -19,7 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef MY_LOCALE_H #define MY_LOCALE_H -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/util/lists.c b/src/util/lists.c index d61327fa0..be3deeffd 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -127,7 +127,7 @@ void addstrlist(strlist ** SP, const char *s) { strlist *slist = malloc(sizeof(strlist)); slist->next = NULL; - slist->s = _strdup(s); + slist->s = strdup(s); addlist(SP, slist); } diff --git a/src/util/log.test.c b/src/util/log.test.c index 55616c026..1558ee3e3 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -9,9 +9,9 @@ void log_string(void *data, int level, const char *module, const char *format, va_list args) { char *str = (char *)data; const char *arg = va_arg(args, const char *); - unused_arg(format); - unused_arg(module); - unused_arg(level); + UNUSED_ARG(format); + UNUSED_ARG(module); + UNUSED_ARG(level); strcpy(str, arg); } diff --git a/src/util/message.c b/src/util/message.c index 5b6f12eb8..b5a9592bd 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -73,7 +73,7 @@ message_type *mt_new(const char *name, const char *args[]) while (args[nparameters]) ++nparameters; } mtype->key = 0; - mtype->name = _strdup(name); + mtype->name = strdup(name); mtype->nparameters = nparameters; if (nparameters > 0) { mtype->pnames = (char **)malloc(sizeof(char *) * nparameters); diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index e3b0bcc0b..8156b9784 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -91,7 +91,7 @@ const nrsection *section_add(const char *name) } if (!*mcp) { nrsection *mc = calloc(sizeof(nrsection), 1); - mc->name = _strdup(name); + mc->name = strdup(name); *mcp = mc; } return *mcp; @@ -130,14 +130,14 @@ const char *string, int level, const char *section) nrt->section = NULL; nrtypes[hash] = nrt; assert(string && *string); - nrt->string = _strdup(string); + nrt->string = strdup(string); *c = '\0'; for (i = 0; i != mtype->nparameters; ++i) { if (i != 0) *c++ = ' '; c += strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames)); } - nrt->vars = _strdup(zNames); + nrt->vars = strdup(zNames); } } diff --git a/src/util/translation.c b/src/util/translation.c index 829a1fe05..b0933d322 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -414,7 +414,7 @@ static void eval_lt(opstack ** stack, const void *userdata) int b = opop_i(stack); int rval = (b < a) ? 1 : 0; opush_i(stack, rval); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_eq(opstack ** stack, const void *userdata) @@ -423,7 +423,7 @@ static void eval_eq(opstack ** stack, const void *userdata) int b = opop_i(stack); int rval = (a == b) ? 1 : 0; opush_i(stack, rval); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_add(opstack ** stack, const void *userdata) @@ -431,14 +431,14 @@ static void eval_add(opstack ** stack, const void *userdata) int a = opop_i(stack); int b = opop_i(stack); opush_i(stack, a + b); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_isnull(opstack ** stack, const void *userdata) { /* (int, int) -> int */ void *a = opop_v(stack); opush_i(stack, (a == NULL) ? 1 : 0); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_if(opstack ** stack, const void *userdata) @@ -447,14 +447,14 @@ static void eval_if(opstack ** stack, const void *userdata) void *b = opop_v(stack); int cond = opop_i(stack); opush_v(stack, cond ? b : a); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_strlen(opstack ** stack, const void *userdata) { /* string -> int */ const char *c = (const char *)opop_v(stack); opush_i(stack, c ? (int)strlen(c) : 0); - unused_arg(userdata); + UNUSED_ARG(userdata); } #include "base36.h" diff --git a/src/vortex.c b/src/vortex.c index 725460ce2..7b6206d03 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -70,7 +70,7 @@ static void a_freedirection(attrib * a) static int a_agedirection(attrib * a, void *owner) { spec_direction *d = (spec_direction *)(a->data.v); - unused_arg(owner); + (void)owner; --d->duration; return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -81,14 +81,14 @@ static int a_readdirection(attrib * a, void *owner, struct gamedata *data) spec_direction *d = (spec_direction *)(a->data.v); char lbuf[32]; - unused_arg(owner); + (void)owner; READ_INT(store, &d->x); READ_INT(store, &d->y); READ_INT(store, &d->duration); READ_TOK(store, lbuf, sizeof(lbuf)); - d->desc = _strdup(lbuf); + d->desc = strdup(lbuf); READ_TOK(store, lbuf, sizeof(lbuf)); - d->keyword = _strdup(lbuf); + d->keyword = strdup(lbuf); d->active = true; return AT_READ_OK; } @@ -98,7 +98,7 @@ a_writedirection(const attrib * a, const void *owner, struct storage *store) { spec_direction *d = (spec_direction *)(a->data.v); - unused_arg(owner); + (void)owner; WRITE_INT(store, d->x); WRITE_INT(store, d->y); WRITE_INT(store, d->duration); @@ -143,8 +143,8 @@ attrib *create_special_direction(region * r, region * rt, int duration, d->x = rt->x; d->y = rt->y; d->duration = duration; - d->desc = _strdup(desc); - d->keyword = _strdup(keyword); + d->desc = strdup(desc); + d->keyword = strdup(keyword); return a; } diff --git a/src/vortex.h b/src/vortex.h index af41b6111..993f5cdab 100644 --- a/src/vortex.h +++ b/src/vortex.h @@ -1,5 +1,10 @@ +#pragma once + #ifndef H_VORTEX #define H_VORTEX + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/wormhole.c b/src/wormhole.c index 6a115a9f7..46425a0c1 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -63,7 +63,7 @@ static int wormhole_age(struct attrib *a, void *owner) region *r = entry->region; unit *u = r->units; - unused_arg(owner); + UNUSED_ARG(owner); for (; u != NULL && maxtransport != 0; u = u->next) { if (u->building == entry) { message *m = NULL; From ddd074f393f3203feb1d3fc236f6af610c6d02d9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:05:48 +0100 Subject: [PATCH 019/271] continue fixing compilation (gcc/clang) --- src/bind_faction.c | 1 + src/kernel/alliance.h | 3 +++ src/kernel/order.h | 1 + src/keyword.h | 2 ++ src/platform.h | 3 +++ src/util/filereader.c | 15 ++++++++------- src/util/parser.c | 8 ++++---- src/util/parser.h | 1 + src/util/password.h | 1 + src/util/rand.h | 4 ++++ src/util/translation.c | 1 + 11 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/bind_faction.c b/src/bind_faction.c index 36da798c1..2ace2ae52 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -36,6 +36,7 @@ without prior permission by the authors of Eressea. #include #include +#include typedef struct helpmode { const char *name; diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index 907fc65f7..4be05b871 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_ALLIANCE #define H_KRNL_ALLIANCE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/order.h b/src/kernel/order.h index 69cf1ea33..7f4b00a5e 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -15,6 +15,7 @@ #include "keyword.h" #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/keyword.h b/src/keyword.h index e60d0731f..1d8f04bb2 100644 --- a/src/keyword.h +++ b/src/keyword.h @@ -2,6 +2,8 @@ #define H_KEYWORD_H #include "kernel/types.h" +#include + #ifdef __cplusplus extern "C" { diff --git a/src/platform.h b/src/platform.h index 2f114cec5..7f82f46a8 100644 --- a/src/platform.h +++ b/src/platform.h @@ -3,6 +3,8 @@ #ifndef UNILIB_H #define UNILIB_H +#define _POSIX_C_SOURCE 200809L + #ifndef MAX_PATH # define MAX_PATH 4096 #endif @@ -12,4 +14,5 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define TOLUA_CAST (char*) #endif diff --git a/src/util/filereader.c b/src/util/filereader.c index 3223ca2ab..d36d3ca71 100644 --- a/src/util/filereader.c +++ b/src/util/filereader.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -30,7 +31,7 @@ static int eatwhite(const char *ptr, size_t * total_size) ret = unicode_utf8_to_ucs4(&ucs, ptr, &size); if (ret != 0) break; - if (!iswxspace((wint_t)ucs)) + if (!iswspace((wint_t)ucs)) break; *total_size += size; ptr += size; @@ -52,7 +53,7 @@ static const char *getbuf_latin1(FILE * F) if (bp == NULL) return NULL; - while (*bp && isxspace(*(unsigned char *)bp)) + while (*bp && isspace(*(unsigned char *)bp)) ++bp; /* eatwhite */ comment = (bool)(comment && cont); @@ -113,15 +114,15 @@ static const char *getbuf_latin1(FILE * F) if (iscntrl(c)) { if (!comment && cp < fbuf + MAXLINE) { - *cp++ = isxspace(c) ? ' ' : '?'; + *cp++ = isspace(c) ? ' ' : '?'; } ++bp; continue; } - else if (isxspace(c)) { + else if (isspace(c)) { if (!quote) { ++bp; - while (*bp && isxspace(*(unsigned char *)bp)) + while (*bp && isspace(*(unsigned char *)bp)) ++bp; /* eatwhite */ if (!comment && *bp && *bp != COMMENT_CHAR && cp < fbuf + MAXLINE) *(cp++) = ' '; @@ -136,7 +137,7 @@ static const char *getbuf_latin1(FILE * F) } else if (c == CONTINUE_CHAR) { const char *end = ++bp; - while (*end && isxspace(*(unsigned char *)end)) + while (*end && isspace(*(unsigned char *)end)) ++end; /* eatwhite */ if (*end == '\0') { bp = end; @@ -269,7 +270,7 @@ static const char *getbuf_utf8(FILE * F) break; } - if (iswxspace((wint_t)ucs)) { + if (iswspace((wint_t)ucs)) { if (!quote) { bp += size; ret = eatwhite(bp, &size); diff --git a/src/util/parser.c b/src/util/parser.c index 0fbde6769..bbdb5ac7e 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -32,7 +32,7 @@ static int eatwhitespace_c(const char **str_p) for (;;) { unsigned char utf8_character = (unsigned char)*str; if (~utf8_character & 0x80) { - if (!iswxspace(utf8_character)) + if (!iswspace(utf8_character)) break; ++str; } @@ -42,7 +42,7 @@ static int eatwhitespace_c(const char **str_p) log_warning("illegal character sequence in UTF8 string: %s\n", str); break; } - if (!iswxspace((wint_t)ucs)) + if (!iswspace((wint_t)ucs)) break; str += len; } @@ -106,7 +106,7 @@ void skip_token(void) log_warning("illegal character sequence in UTF8 string: %s\n", states->current_token); } } - if (iswxspace((wint_t)ucs) && quotechar == 0) { + if (iswspace((wint_t)ucs) && quotechar == 0) { return; } else { @@ -163,7 +163,7 @@ char *parse_token(const char **str, char *lbuf, size_t buflen) copy = true; escape = false; } - else if (iswxspace((wint_t)ucs)) { + else if (iswspace((wint_t)ucs)) { if (quotechar == 0) break; copy = true; diff --git a/src/util/parser.h b/src/util/parser.h index 802fc56cb..0c8306931 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -12,6 +12,7 @@ #define UTIL_PARSER_H #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/util/password.h b/src/util/password.h index e1d49fb6d..b83d544a6 100644 --- a/src/util/password.h +++ b/src/util/password.h @@ -1,5 +1,6 @@ #pragma once +#include #define PASSWORD_PLAINTEXT 0 #define PASSWORD_DEFAULT PASSWORD_PLAINTEXT diff --git a/src/util/rand.h b/src/util/rand.h index 9fb3f2f69..e9d9062b7 100644 --- a/src/util/rand.h +++ b/src/util/rand.h @@ -1,3 +1,4 @@ +#pragma once /* Copyright (c) 1998-2015, Enno Rehling Katja Zedel + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/translation.c b/src/util/translation.c index b0933d322..c733cc272 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -21,6 +21,7 @@ /* libc includes */ #include #include +#include #include #include From b27e1a01aab35c0c1c185cafae488e3312ea3018 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:07:36 +0100 Subject: [PATCH 020/271] continued work for MSVC compilation --- src/alchemy.c | 4 ++++ src/battle.c | 11 +++++++++-- src/donations.c | 1 + src/economy.c | 38 +++++++++++++++++++------------------- src/kernel/messages.h | 2 +- src/move.c | 11 +++++++++-- src/names.c | 2 +- src/platform.h | 23 +++++++++++++++++++++++ src/reports.c | 16 ++++++++-------- src/spells.c | 8 +++++++- src/spells/combatspells.c | 4 ++-- src/util/rand.h | 3 +++ 12 files changed, 87 insertions(+), 36 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index ddbe46b8e..81244eba1 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -162,6 +162,7 @@ static int potion_healing(unit * u, int amount) { static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { attrib *a = (attrib *)a_find(r->attribs, atype); + UNUSED_ARG(u); if (!a) { a = a_add(&r->attribs, a_new(atype)); } @@ -170,6 +171,7 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { } static int potion_truth(unit *u) { + UNUSED_ARG(u); // TODO: this potion does nothing! // fset(u, UFL_DISBELIEVES); return 1; @@ -304,6 +306,7 @@ static void a_writeeffect(const attrib * a, const void *owner, struct storage *store) { effect_data *edata = (effect_data *)a->data.v; + UNUSED_ARG(owner); WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0)); WRITE_INT(store, edata->value); } @@ -316,6 +319,7 @@ static int a_readeffect(attrib * a, void *owner, struct gamedata *data) effect_data *edata = (effect_data *)a->data.v; char zText[32]; + UNUSED_ARG(owner); READ_TOK(store, zText, sizeof(zText)); rtype = rt_find(zText); diff --git a/src/battle.c b/src/battle.c index 3b34cd162..7e5c4b9d8 100644 --- a/src/battle.c +++ b/src/battle.c @@ -509,6 +509,9 @@ contest_new(int skilldiff, const troop dt, const armor_type * ar, const armor_type * sh) { double tohit = 0.5 + skilldiff * 0.1; + + UNUSED_ARG(sh); + UNUSED_ARG(ar); if (tohit < 0.5) tohit = 0.5; if (chance(tohit)) { @@ -839,6 +842,7 @@ int select_magicarmor(troop t) /* Sind side ds und Magier des meffect verb�ndet, dann return 1*/ bool meffect_protection(battle * b, meffect * s, side * ds) { + UNUSED_ARG(b); if (!s->magician->alive) return false; if (s->duration <= 0) @@ -853,6 +857,7 @@ bool meffect_protection(battle * b, meffect * s, side * ds) /* Sind side as und Magier des meffect verfeindet, dann return 1*/ bool meffect_blocked(battle * b, meffect * s, side * as) { + UNUSED_ARG(b); if (!s->magician->alive) return false; if (s->duration <= 0) @@ -1763,8 +1768,8 @@ void do_combatmagic(battle * b, combatmagic_t was) for (co = spellranks[rank].begin; co; co = co->next) { fighter *fig = co->magician.fig; const spell *sp = co->sp; - int level = co->level; + level = co->level; if (!sp->cast) { log_error("spell '%s' has no function.\n", sp->sname); } @@ -2040,6 +2045,7 @@ int hits(troop at, troop dt, weapon * awp) void dazzle(battle * b, troop * td) { + UNUSED_ARG(b); /* Nicht kumulativ ! */ #ifdef TODO_RUNESWORD if (td->fighter->weapon[WP_RUNESWORD].count > td->index) { @@ -2487,6 +2493,7 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype) static int loot_quota(const unit * src, const unit * dst, const item_type * type, int n) { + UNUSED_ARG(type); if (dst && src && src->faction != dst->faction) { double divisor = config_get_flt("rules.items.loot_divisor", 1); assert(divisor <= 0 || divisor >= 1); @@ -2636,7 +2643,6 @@ static void reorder_fleeing(region * r) static void aftermath(battle * b) { region *r = b->region; - ship *sh; side *s; int dead_players = 0; bfaction *bf; @@ -2833,6 +2839,7 @@ static void aftermath(battle * b) * dieses Schiff besch�digt. Andernfalls ein Schiff, welches * evt. zuvor verlassen wurde. */ if (ships_damaged) { + ship *sh; if (du->ship) sh = du->ship; else diff --git a/src/donations.c b/src/donations.c index 8f820df2b..7d2f15816 100644 --- a/src/donations.c +++ b/src/donations.c @@ -1,3 +1,4 @@ +#include #include #include "donations.h" diff --git a/src/economy.c b/src/economy.c index 7edbbcb12..16b201555 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1041,10 +1041,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) static int required(int want, double save) { - int norders = (int)(want * save); - if (norders < want * save) - ++norders; - return norders; + int req = (int)(want * save); + if (req < want * save) + ++req; + return req; } static void @@ -1058,7 +1058,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (rm != NULL) { do { int avail = rm->amount; - int norders = 0; + int nreq = 0; allocation *al; if (avail <= 0) { @@ -1077,7 +1077,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (effskill(al->unit, itype->construction->skill, 0) >= rm->level + itype->construction->minskill - 1) { if (req) { - norders += req; + nreq += req; } else { fset(al, AFL_DONE); @@ -1089,22 +1089,22 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) fset(al, AFL_LOWSKILL); } } - need = norders; + need = nreq; - avail = MIN(avail, norders); + avail = MIN(avail, nreq); if (need > 0) { int use = 0; for (al = alist; al; al = al->next) if (!fval(al, AFL_DONE)) { if (avail > 0) { int want = required(al->want - al->get, al->save); - int x = avail * want / norders; + int x = avail * want / nreq; /* Wenn Rest, dann würfeln, ob ich was bekomme: */ - if (rng_int() % norders < (avail * want) % norders) + if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; use += x; - norders -= want; + nreq -= want; need -= x; al->get = MIN(al->want, al->get + (int)(x / al->save)); } @@ -1113,7 +1113,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) assert(use <= rm->amount); rm->type->use(rm, r, use); } - assert(avail == 0 || norders == 0); + assert(avail == 0 || nreq == 0); } first = false; } while (need > 0); @@ -1124,13 +1124,13 @@ static void attrib_allocation(const resource_type * rtype, region * r, allocation * alist) { allocation *al; - int norders = 0; + int nreq = 0; attrib *a = a_find(rtype->attribs, &at_resourcelimit); resource_limit *rdata = (resource_limit *)a->data.v; int avail = rdata->value; for (al = alist; al; al = al->next) { - norders += required(al->want, al->save); + nreq += required(al->want, al->save); } if (rdata->limit) { @@ -1139,16 +1139,16 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) avail = 0; } - avail = MIN(avail, norders); + avail = MIN(avail, nreq); for (al = alist; al; al = al->next) { if (avail > 0) { int want = required(al->want, al->save); - int x = avail * want / norders; + int x = avail * want / nreq; /* Wenn Rest, dann würfeln, ob ich was bekomme: */ - if (rng_int() % norders < (avail * want) % norders) + if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; - norders -= want; + nreq -= want; al->get = MIN(al->want, (int)(x / al->save)); if (rdata->produce) { int use = required(al->get, al->save); @@ -1157,7 +1157,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) } } } - assert(avail == 0 || norders == 0); + assert(avail == 0 || nreq == 0); } typedef void(*allocate_function) (const resource_type *, struct region *, diff --git a/src/kernel/messages.h b/src/kernel/messages.h index 866eecba7..a42342153 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -57,7 +57,7 @@ extern "C" { struct mlist ** merge_messages(message_list *mlist, message_list *append); void split_messages(message_list *mlist, struct mlist **split); -#define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } } +#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { assert(mx->refcount>=1); add_message(msgs, mx); msg_release(mx); } } void syntax_error(const struct unit *u, struct order *ord); struct message * cmistake(const struct unit *u, struct order *ord, int mno, int mtype); diff --git a/src/move.c b/src/move.c index 62300beb1..0184d22ca 100644 --- a/src/move.c +++ b/src/move.c @@ -163,6 +163,7 @@ static int shiptrail_read(attrib * a, void *owner, struct gamedata *data) int n; traveldir *t = (traveldir *)(a->data.v); + UNUSED_ARG(owner); READ_INT(store, &t->no); READ_INT(store, &n); t->dir = (direction_t)n; @@ -174,6 +175,8 @@ static void shiptrail_write(const attrib * a, const void *owner, struct storage *store) { traveldir *t = (traveldir *)(a->data.v); + + UNUSED_ARG(owner); WRITE_INT(store, t->no); WRITE_INT(store, t->dir); WRITE_INT(store, t->age); @@ -204,6 +207,8 @@ static bool entrance_allowed(const struct unit *u, const struct region *r) return true; return false; #else + UNUSED_ARG(u); + UNUSED_ARG(r); return true; #endif } @@ -466,6 +471,8 @@ static int canride(unit * u) static bool cansail(const region * r, ship * sh) { + UNUSED_ARG(r); + /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction || sh->type->construction->improvement == NULL); @@ -490,6 +497,8 @@ static bool cansail(const region * r, ship * sh) static double overload(const region * r, ship * sh) { + UNUSED_ARG(r); + /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction || sh->type->construction->improvement == NULL); @@ -1761,8 +1770,6 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) * befahrene Region. */ while (next_point && current_point != next_point && step < k) { - const char *token; - int error; const terrain_type *tthis = current_point->terrain; /* these values need to be updated if next_point changes (due to storms): */ const terrain_type *tnext = next_point->terrain; diff --git a/src/names.c b/src/names.c index 248084828..969e278d8 100644 --- a/src/names.c +++ b/src/names.c @@ -394,8 +394,8 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) size_t size; int result; + UNUSED_ARG(buflen); /* Prüfen, ob Kurz genug */ - if (strlen(s) <= maxchars) { return s; } diff --git a/src/platform.h b/src/platform.h index 2f114cec5..57f4cd720 100644 --- a/src/platform.h +++ b/src/platform.h @@ -3,6 +3,21 @@ #ifndef UNILIB_H #define UNILIB_H +#ifdef _MSC_VER +#ifndef __STDC__ +#define __STDC__ 1 // equivalent to /Za +#endif +#define NO_STRDUP +#define NO_MKDIR +#define mkdir(d, a) _mkdir(d) +#define _CRT_SECURE_NO_WARNINGS +#pragma warning(disable: 4710 4820) +#pragma warning(disable: 4100) // unreferenced formal parameter +#pragma warning(disable: 4456) // declaration hides previous +#pragma warning(disable: 4457) // declaration hides function parameter +#pragma warning(disable: 4459) // declaration hides global +#endif + #ifndef MAX_PATH # define MAX_PATH 4096 #endif @@ -12,4 +27,12 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#ifdef NO_STRDUP +char * strdup(const char *s); +#endif + +#ifdef NO_MKDIR +int mkdir(const char *pathname, int mode); +#endif + #endif diff --git a/src/reports.c b/src/reports.c index b31ecac19..6d0aaba37 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1907,23 +1907,23 @@ static void eval_regions(struct opstack **stack, const void *userdata) const faction *report = (const faction *)userdata; int i = opop(stack).i; int end, begin = opop(stack).i; - const arg_regions *regions = (const arg_regions *)opop(stack).v; + const arg_regions *aregs = (const arg_regions *)opop(stack).v; char buf[256]; size_t size = sizeof(buf) - 1; variant var; char *bufp = buf; - if (regions == NULL) { + if (aregs == NULL) { end = begin; } else { if (i >= 0) end = begin + i; else - end = regions->nregions + i; + end = aregs->nregions + i; } for (i = begin; i < end; ++i) { - const char *rname = (const char *)regionname(regions->regions[i], report); + const char *rname = (const char *)regionname(aregs->regions[i], report); bufp = STRLCPY(bufp, rname, size); if (i + 1 < end && size > 2) { @@ -1942,7 +1942,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) const faction *report = (const faction *)userdata; const struct locale *lang = report ? report->locale : default_locale; int i, end = 0, begin = 0; - const arg_regions *regions = (const arg_regions *)opop(stack).v; + const arg_regions *aregs = (const arg_regions *)opop(stack).v; char buf[512]; size_t size = sizeof(buf) - 1; variant var; @@ -1952,10 +1952,10 @@ static void eval_trail(struct opstack **stack, const void *userdata) int eold = errno; #endif - if (regions != NULL) { - end = regions->nregions; + if (aregs != NULL) { + end = aregs->nregions; for (i = begin; i < end; ++i) { - region *r = regions->regions[i]; + region *r = aregs->regions[i]; const char *trail = trailinto(r, lang); const char *rn = f_regionid_s(r, report); diff --git a/src/spells.c b/src/spells.c index 6ed38d022..0bb6df5af 100644 --- a/src/spells.c +++ b/src/spells.c @@ -398,6 +398,7 @@ static void report_effect(region * r, unit * mage, message * seen, message * unseen) { int err = report_action(r, mage, seen, ACTION_RESET | ACTION_CANSEE); + UNUSED_ARG(unseen); if (err) { report_action(r, mage, seen, ACTION_CANNOTSEE); } @@ -2895,6 +2896,8 @@ static int dc_read_compat(struct attrib *a, void *target, gamedata *data) float strength; int rx, ry; + UNUSED_ARG(a); + UNUSED_ARG(target); READ_INT(store, &duration); READ_FLT(store, &strength); READ_INT(store, &var.i); @@ -3119,8 +3122,10 @@ static bool chaosgate_valid(const connection * b) } static struct region *chaosgate_move(const connection * b, struct unit *u, -struct region *from, struct region *to, bool routing) + struct region *from, struct region *to, bool routing) { + UNUSED_ARG(from); + UNUSED_ARG(b); if (!routing) { int maxhp = u->hp / 4; if (maxhp < u->number) @@ -6438,6 +6443,7 @@ int sp_break_curse(castorder * co) /* ------------------------------------------------------------- */ int sp_becomewyrm(castorder * co) { + UNUSED_ARG(co); return 0; } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 0e1a27e75..227d94858 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -826,8 +826,8 @@ int sp_shadowcall(struct castorder * co) attrib *a; int force = (int)(get_force(power, 3) / 2); unit *u; - const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" }; - const race *rc = rc_find(races[rng_int() % 3]); + const char *rcnames[3] = { "shadowbat", "nightmare", "vampunicorn" }; + const race *rc = rc_find(rcnames[rng_int() % 3]); message *msg; u = create_unit(r, mage->faction, force, rc, 0, NULL, mage); diff --git a/src/util/rand.h b/src/util/rand.h index 9fb3f2f69..2aabb8571 100644 --- a/src/util/rand.h +++ b/src/util/rand.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef RAND_H #define RAND_H + +#include + #ifdef __cplusplus extern "C" { #endif From ba2f35e44f26ac9e42466048fc90b2470a197692 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:20:47 +0100 Subject: [PATCH 021/271] more stbool.h includes, MSVC has no unlink --- src/attributes/key.h | 3 +++ src/donations.test.c | 1 + src/give.h | 3 +++ src/kernel/command.test.c | 2 ++ src/market.h | 3 +++ src/monsters.h | 3 +++ src/platform.h | 5 ++++- src/renumber.test.c | 1 + src/reports.h | 2 +- src/summary.h | 2 ++ src/util/xml.h | 2 ++ 11 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/attributes/key.h b/src/attributes/key.h index 89292db1d..d2cea1ff0 100644 --- a/src/attributes/key.h +++ b/src/attributes/key.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_ATTRIBUTE_KEY #define H_ATTRIBUTE_KEY + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/donations.test.c b/src/donations.test.c index 068aba74a..09cd31977 100644 --- a/src/donations.test.c +++ b/src/donations.test.c @@ -1,3 +1,4 @@ +#include #include "donations.h" #include diff --git a/src/give.h b/src/give.h index 9c06e89ca..94eee729c 100644 --- a/src/give.h +++ b/src/give.h @@ -12,6 +12,9 @@ */ #ifndef H_GC_GIVE #define H_GC_GIVE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/command.test.c b/src/kernel/command.test.c index f38c7e443..25e75fdc3 100644 --- a/src/kernel/command.test.c +++ b/src/kernel/command.test.c @@ -10,7 +10,9 @@ without prior permission by the authors of Eressea. */ +#include #include "command.h" + #include "unit.h" #include "order.h" diff --git a/src/market.h b/src/market.h index a74c88391..74dc8db17 100644 --- a/src/market.h +++ b/src/market.h @@ -12,6 +12,9 @@ without prior permission by the authors of Eressea. */ #ifndef H_GC_MARKET #define H_GC_MARKET + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/monsters.h b/src/monsters.h index 52e9ebf37..a5a3ccd15 100644 --- a/src/monsters.h +++ b/src/monsters.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_GC_MONSTER #define H_GC_MONSTER + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/platform.h b/src/platform.h index f3fd9fbae..88bff8ad5 100644 --- a/src/platform.h +++ b/src/platform.h @@ -9,7 +9,7 @@ #endif #define NO_STRDUP #define NO_MKDIR -#define mkdir(d, a) _mkdir(d) +#define NO_UNLINK #define _CRT_SECURE_NO_WARNINGS #pragma warning(disable: 4710 4820) #pragma warning(disable: 4100) // unreferenced formal parameter @@ -38,4 +38,7 @@ char * strdup(const char *s); int mkdir(const char *pathname, int mode); #endif +#ifdef NO_UNLINK +int unlink(const char *pathname); +#endif #endif diff --git a/src/renumber.test.c b/src/renumber.test.c index 6c3f0f17b..8f6f91a59 100644 --- a/src/renumber.test.c +++ b/src/renumber.test.c @@ -1,3 +1,4 @@ +#include #include "renumber.h" #include diff --git a/src/reports.h b/src/reports.h index e5fd976e3..99dd7ebf6 100644 --- a/src/reports.h +++ b/src/reports.h @@ -20,10 +20,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_REPORTS #define H_KRNL_REPORTS -#include #include #include #include +#include struct stream; struct seen_region; diff --git a/src/summary.h b/src/summary.h index ea8daeee1..b12d74009 100644 --- a/src/summary.h +++ b/src/summary.h @@ -11,6 +11,8 @@ #ifndef H_GC_SUMMARY #define H_GC_SUMMARY +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/xml.h b/src/util/xml.h index 921cd3f53..bd22e3e0a 100644 --- a/src/util/xml.h +++ b/src/util/xml.h @@ -13,6 +13,8 @@ #ifndef H_UTIL_XML #define H_UTIL_XML +#include + #ifdef __cplusplus extern "C" { #endif From f8ff9ffda5613b4b85d9e7412d3a40710baeaf75 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:40:01 +0100 Subject: [PATCH 022/271] compiles with gcc on rpi --- src/kernel/jsonconf.test.c | 2 +- src/kernel/save.c | 2 +- src/platform.h | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 76784ed56..950868046 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -448,7 +448,7 @@ static void test_configs(CuTest * tc) CuAssertPtrEquals(tc, 0, buildingtypes); json_config(json); CuAssertPtrNotNull(tc, buildingtypes); - if (unlink("test.json")!=0 && errno==ENOENT) { + if (remove("test.json")!=0 && errno==ENOENT) { errno = 0; } cJSON_Delete(json); diff --git a/src/kernel/save.c b/src/kernel/save.c index de6f8aac1..9825a5b55 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1830,7 +1830,7 @@ int writegame(const char *filename) join_path(datapath(), filename, path, sizeof(path)); #ifdef HAVE_UNISTD_H /* make sure we don't overwrite an existing file (hard links) */ - if (unlink(path)!=0) { + if (remove(path)!=0) { if (errno==ENOENT) { errno = 0; } diff --git a/src/platform.h b/src/platform.h index 88bff8ad5..355b995d2 100644 --- a/src/platform.h +++ b/src/platform.h @@ -9,7 +9,6 @@ #endif #define NO_STRDUP #define NO_MKDIR -#define NO_UNLINK #define _CRT_SECURE_NO_WARNINGS #pragma warning(disable: 4710 4820) #pragma warning(disable: 4100) // unreferenced formal parameter @@ -38,7 +37,4 @@ char * strdup(const char *s); int mkdir(const char *pathname, int mode); #endif -#ifdef NO_UNLINK -int unlink(const char *pathname); -#endif #endif From a4d8d36aec81317d108c6648d26856e34b87e19a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 14:53:35 +0100 Subject: [PATCH 023/271] issue #621: delete battledebug code --- src/battle.c | 156 ++------------------------------------------------- src/battle.h | 1 - src/main.c | 3 - 3 files changed, 6 insertions(+), 154 deletions(-) diff --git a/src/battle.c b/src/battle.c index 7e5c4b9d8..d802c0785 100644 --- a/src/battle.c +++ b/src/battle.c @@ -93,12 +93,6 @@ typedef enum combatmagic { DO_POSTCOMBATSPELL } combatmagic_t; -/* globals */ -bool battledebug = false; - -static int obs_count = 0; -static FILE *bdebug; - #define MINSPELLRANGE 1 #define MAXSPELLRANGE 7 @@ -1219,9 +1213,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) kritchance = MIN(0.9, kritchance); while (chance(kritchance)) { - if (bdebug) { - fprintf(bdebug, "%s/%d lands a critical hit\n", itoa36(au->no), at.index); - } da += dice_rand(damage); } } @@ -1302,10 +1293,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) } if (df->person[dt.index].hp > 0) { /* Hat �berlebt */ - if (bdebug) { - fprintf(bdebug, "Damage %d, armor %d: %d -> %d HP\n", - da, ar, df->person[dt.index].hp + rda, df->person[dt.index].hp); - } if (u_race(au) == get_race(RC_DAEMON)) { if (!(df->person[dt.index].flags & (FL_COURAGE | FL_DAZZLED))) { df->person[dt.index].flags |= FL_DAZZLED; @@ -1334,10 +1321,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) } ++at.fighter->kills; - if (bdebug) { - fprintf(bdebug, "Damage %d, armor %d, type %d: %d -> %d HP, tot.\n", - da, ar, type, df->person[dt.index].hp + rda, df->person[dt.index].hp); - } for (pitm = &du->items; *pitm;) { item *itm = *pitm; const item_type *itype = itm->type; @@ -1979,20 +1962,6 @@ int getreload(troop at) return at.fighter->person[at.index].reload; } -static void -debug_hit(troop at, const weapon * awp, troop dt, const weapon * dwp, -int skdiff, int dist, bool success) -{ - fprintf(bdebug, "%.4s/%d [%6s/%d] %s %.4s/%d [%6s/%d] with %d, distance %d\n", - itoa36(at.fighter->unit->no), at.index, - LOC(default_locale, awp ? resourcename(awp->type->itype->rtype, - 0) : "unarmed"), weapon_effskill(at, dt, awp, true, dist > 1), - success ? "hits" : "misses", itoa36(dt.fighter->unit->no), dt.index, - LOC(default_locale, dwp ? resourcename(dwp->type->itype->rtype, - 0) : "unarmed"), weapon_effskill(dt, at, dwp, false, dist > 1), skdiff, - dist); -} - int hits(troop at, troop dt, weapon * awp) { fighter *af = at.fighter, *df = dt.fighter; @@ -2032,14 +2001,8 @@ int hits(troop at, troop dt, weapon * awp) shield = select_armor(dt, false); } if (contest(skdiff, dt, armor, shield)) { - if (bdebug) { - debug_hit(at, awp, dt, dwp, skdiff, dist, true); - } return 1; } - if (bdebug) { - debug_hit(at, awp, dt, dwp, skdiff, dist, false); - } return 0; } @@ -2190,11 +2153,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) } } if (reload && wp && wp->type->reload && !getreload(ta)) { - int i = setreload(ta); - if (bdebug) { - fprintf(bdebug, "%s/%d reloading %d turns\n", itoa36(au->no), - ta.index, i); - } + setreload(ta); } } } @@ -2874,13 +2833,6 @@ static void aftermath(battle * b) } reorder_fleeing(r); - - if (bdebug) { - fprintf(bdebug, "The battle lasted %d turns, %s and %s.\n", - b->turn, - b->has_tactics_turn ? "had a tactic turn" : "had no tactic turn", - ships_damaged ? "was relevant" : "was not relevant."); - } } static void battle_punit(unit * u, battle * b) @@ -2894,10 +2846,6 @@ static void battle_punit(unit * u, battle * b) spunit(&S, f, u, 4, seen_battle); for (x = S; x; x = x->next) { fbattlerecord(b, f, x->s); - if (bdebug && u->faction == f) { - fputs(x->s, bdebug); - fputc('\n', bdebug); - } } if (S) freestrlist(S); @@ -3077,17 +3025,6 @@ static void print_stats(battle * b) fbattlerecord(b, f, buf); } - if (bdebug && s->faction) { - if (f_get_alliance(s->faction)) { - fprintf(bdebug, "##### %s (%s/%d)\n", s->faction->name, - itoa36(s->faction->no), - s->faction->alliance ? s->faction->alliance->id : 0); - } - else { - fprintf(bdebug, "##### %s (%s)\n", s->faction->name, - itoa36(s->faction->no)); - } - } print_fighters(b, s); } @@ -3519,28 +3456,6 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) return false; } -static const char *simplename(region * r) -{ - int i; - static char name[17]; - const char *cp = rname(r, default_locale); - for (i = 0; *cp && i != 16; ++i, ++cp) { - int c = *(unsigned char *)cp; - while (c && !isalpha(c) && !isspace(c)) { - ++cp; - c = *(unsigned char *)cp; - } - if (isspace(c)) - name[i] = '_'; - else - name[i] = *cp; - if (c == 0) - break; - } - name[i] = 0; - return name; -} - battle *make_battle(region * r) { battle *b = (battle *)calloc(1, sizeof(battle)); @@ -3552,29 +3467,6 @@ battle *make_battle(region * r) for (bld = r->buildings; bld != NULL; bld = bld->next) bld->sizeleft = bld->size; - if (battledebug) { - char zText[4096]; - char zFilename[4096]; - join_path(basepath(), "battles", zText, sizeof(zText)); - if (mkdir(zText, 0777) != 0) { - log_error("could not create subdirectory for battle logs: %s", zText); - battledebug = false; - } - else { - sprintf(zFilename, "battle-%d-%s.log", obs_count++, simplename(r)); - join_path(zText, zFilename, zText, sizeof(zText)); - bdebug = fopen(zText, "w"); - if (!bdebug) - log_error("battles cannot be debugged"); - else { - const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; - fwrite(utf8_bom, 1, 3, bdebug); - fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r, - default_locale)); - } - } - } - b->region = r; b->plane = getplane(r); /* Finde alle Parteien, die den Kampf beobachten k�nnen: */ @@ -3644,10 +3536,6 @@ static void battle_free(battle * b) { void free_battle(battle * b) { - if (bdebug) { - fclose(bdebug); - } - while (b->factions) { bfaction *bf = b->factions; b->factions = bf->next; @@ -3812,13 +3700,7 @@ static void join_allies(battle * b) } /* keine Einw�nde, also soll er mitmachen: */ if (c == NULL) { - if (join_battle(b, u, false, &c)) { - if (battledebug) { - fprintf(bdebug, "%s joins to help %s against %s.\n", - unitname(u), factionname(s->faction), factionname(se->faction)); - } - } - else if (c == NULL) { + if (!join_battle(b, u, false, &c)) { continue; } } @@ -3826,12 +3708,7 @@ static void join_allies(battle * b) /* the enemy of my friend is my enemy: */ for (se = b->sides; se != s_end; ++se) { if (se->faction != u->faction && enemy(s, se)) { - if (set_enemy(se, c->side, false) && battledebug) { - fprintf(bdebug, - "%u/%s hates %u/%s because they are enemies with %u/%s.\n", - c->side->index, sidename(c->side), se->index, sidename(se), - s->index, sidename(s)); - } + set_enemy(se, c->side, false); } } } @@ -4012,18 +3889,8 @@ static bool start_battle(region * r, battle ** bp) } b = make_battle(r); } - if (join_battle(b, u, true, &c1)) { - if (battledebug) { - fprintf(bdebug, "%s joins by attacking %s.\n", - unitname(u), unitname(u2)); - } - } - if (join_battle(b, u2, false, &c2)) { - if (battledebug) { - fprintf(bdebug, "%s joins because of an attack from %s.\n", - unitname(u2), unitname(u)); - } - } + join_battle(b, u, true, &c1); + join_battle(b, u2, false, &c2); /* Hat die attackierte Einheit keinen Noaid-Status, * wird das Flag von der Faction genommen, andere @@ -4036,11 +3903,7 @@ static bool start_battle(region * r, battle ** bp) * Pr�combataura bei kurzem Kampf. */ c1->side->bf->attacker = true; - if (set_enemy(c1->side, c2->side, true) && battledebug) { - fprintf(bdebug, "%u/%s hates %u/%s because they attacked them.\n", - c2->side->index, sidename(c2->side), - c1->side->index, sidename(c1->side)); - } + set_enemy(c1->side, c2->side, true); fighting = true; } } @@ -4159,10 +4022,6 @@ static void battle_flee(battle * b) flee(dt); } } - if (bdebug && runners > 0) { - fprintf(bdebug, "Fleeing: %d from %s\n", runners, - itoa36(fig->unit->no)); - } } } } @@ -4265,9 +4124,6 @@ void do_battle(region * r) log_debug("battle in %s (%d, %d) : ", regionname(r, 0), r->x, r->y); for (; battle_report(b) && b->turn <= max_turns; ++b->turn) { - if (bdebug) { - fprintf(bdebug, "*** Turn: %d\n", b->turn); - } battle_flee(b); battle_update(b); battle_attacks(b); diff --git a/src/battle.h b/src/battle.h index 060906958..4d29f1a7f 100644 --- a/src/battle.h +++ b/src/battle.h @@ -225,7 +225,6 @@ extern "C" { } meffect; extern const troop no_troop; - extern bool battledebug; /* BEGIN battle interface */ side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); diff --git a/src/main.c b/src/main.c index 44c1b9e2d..5e998f835 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "eressea.h" -#include "battle.h" #ifdef USE_CURSES #include "gmtool.h" #endif @@ -71,8 +70,6 @@ static void load_inifile(dictionary * d) lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; verbosity = iniparser_getint(d, "eressea:verbose", 2); - battledebug = iniparser_getint(d, "eressea:debug", battledebug) ? 1 : 0; - str = iniparser_getstring(d, "eressea:locales", "de,en"); make_locales(str); From d8e6e80b03f615ec3b92cfba1b8cfe62b95c14b3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 14:55:03 +0100 Subject: [PATCH 024/271] issue #478: re-enable -Werror --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81a43e002..cc7087635 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ COMPILE_DEFINITIONS ERESSEA_VERSION="${ERESSEA_VERSION}") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=unused-but-set-variable") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") From d73c7609498016d025378a08c12b3fd42311887c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 15:09:02 +0100 Subject: [PATCH 025/271] do not set -Werror twice --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc7087635..81a43e002 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ COMPILE_DEFINITIONS ERESSEA_VERSION="${ERESSEA_VERSION}") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=unused-but-set-variable") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") From 084b4ed3878c4aa3d36898ba5c0898e74da8256d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 14 Jan 2017 17:19:08 +0100 Subject: [PATCH 026/271] github issue #626: installing in non-standard paths --- s/cmake-init | 3 ++- s/install | 2 -- s/setup | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/s/cmake-init b/s/cmake-init index ea94afb7c..84a1d9cdb 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -35,12 +35,13 @@ if [ -d $HOME/usr ]; then PREFIX_PATH=$HOME/usr:$HOME/usr/local:$PREFIX_PATH fi +DEST=$(dirname $ROOT)/server ARGS=" -DCMAKE_MODULE_PATH=$ROOT/cmake/Modules \ -DCMAKE_BUILD_TYPE=$BUILD \ -DCMAKE_LIBRARY_PATH=$LIBRARY_PATH \ -DCMAKE_INCLUDE_PATH=$INCLUDE_PATH \ -DCMAKE_PREFIX_PATH=$PREFIX_PATH \ - -DCMAKE_INSTALL_PREFIX=$HOME/eressea/server" + -DCMAKE_INSTALL_PREFIX=$DEST" git submodule update --init diff --git a/s/install b/s/install index 416d07f9a..962961063 100755 --- a/s/install +++ b/s/install @@ -8,8 +8,6 @@ while [ ! -d $ROOT/.git ]; do fi done -DEST=$(dirname $ROOT)/server - [ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" [ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" [ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" diff --git a/s/setup b/s/setup index 0839d5b8f..fc5fb9874 100755 --- a/s/setup +++ b/s/setup @@ -1,5 +1,15 @@ #!/bin/bash +ROOT=$(pwd) +while [ ! -d $ROOT/.git ]; do + ROOT=$(dirname $ROOT) + if [ "/" = "$ROOT" ]; then + echo "could not find root, are you in the git repository?" + exit + fi +done +ERESSEA=$(dirname $ROOT) + function abort() { echo $1 [ -z $2 ] && exit -1 @@ -37,7 +47,6 @@ while getopts :d:g:r:s:hfn o; do done [ $game -gt 0 ] || abort "must use a positive integer for game id" -[ -d $ERESSEA ] || abort "invalid or missing env variable ERESSEA ($ERESSEA)" [ -z $SOURCE ] && SOURCE=$ERESSEA/$src [ -d $SOURCE ] || abort "invalid source directory $SOURCE" [ -z $rules ] && rules=e$game @@ -46,7 +55,8 @@ done [ -e $TOOLS ] || TOOLS=$SOURCE/bin [ -z $INIFILE ] && INIFILE=$TOOLS/inifile [ -e $INIFILE ] || INIFILE=$TOOLS/iniparser/inifile -#[ -e $INIFILE ] || abort "tool is not installed: $INIFILE" + +[ -e $SOURCE/conf/$rules/config.xml ] || abort "cannot find conf/$rules/config.xml" cd $ERESSEA if [ -d $dir ] ; then From 0261cb45c1389e0d0c571362cd8afb92b8d42e18 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 08:32:31 +0100 Subject: [PATCH 027/271] move orders-accept configuration to eressea.ini install lunit, too --- CMakeLists.txt | 1 + conf/eressea.ini | 3 ++ process/orders-accept | 111 ++++++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b26ecb6e..15629bf4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,4 +25,5 @@ add_subdirectory (src eressea) install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.xml") install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.json") install(DIRECTORY scripts DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua") +install(DIRECTORY lunit DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua") install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/conf/eressea.ini b/conf/eressea.ini index e14d0af50..c2f7bbb7f 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -1,3 +1,6 @@ +[game] +email = Eressea Server +name = Eressea [eressea] base = . diff --git a/process/orders-accept b/process/orders-accept index 151f0b196..49bdc3cb0 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -3,22 +3,50 @@ from email.Utils import parseaddr from email.Parser import Parser -from os import mkdir, rename, stat, utime, unlink, symlink -from os.path import exists +import os +import os.path +import ConfigParser from re import compile, IGNORECASE from stat import ST_MTIME from string import upper, split, replace import logging -from sys import argv, stdin, exit +import sys +from sys import stdin from time import ctime, sleep, time from socket import gethostname from rfc822 import parsedate_tz, mktime_tz -LOG_FILENAME='/home/eressea/log/orders.log' +if 'ERESSEA' in os.environ: + dir = os.environ['ERESSEA'] +elif 'HOME' in os.environ: + dir = os.path.join(os.environ['HOME'], '/eressea') +else: # WTF? No HOME? + dir = "/home/eressea/eressea" +if not os.path.isdir(dir): + print "please set the ERESSEA environment variable to the install path" + sys.exit(1) +rootdir = dir + +try: + game = int(sys.argv[1]) +except: + game = sys.argv[1] +gamedir = os.path.join(rootdir, "game-%d" % (game, )) +frommail = 'Eressea Server ' +gamename = 'Eressea' +inifile = os.path.join(gamedir, 'eressea.ini') +if not os.path.exists(inifile): + print "no such file: " . inifile +else: + config = ConfigParser.ConfigParser() + config.read(inifile) + if config.has_option('game', 'email'): + frommail = config.get('game', 'email') + if config.has_option('game', 'name'): + gamename = config.get('game', 'name') + config = None prefix = 'turn-' hostname = gethostname() -# base directory for all your games: -rootdir = "/home/eressea" orderbase = "orders.dir" sendmail = True # maximum number of reports per sender: @@ -28,36 +56,21 @@ writeheaders = True # reject all html email? rejecthtml = True -games = [ - { - "from" : "Eressea Server ", - "prefix" : "Eressea" - }, - { - "from" : "Eressea Server ", - "prefix": "E3" - }, - { - "from" : "Eressea Server ", - "prefix": "E4" - }, -] - def unlock_file(filename): try: - unlink(filename+".lock") + os.unlink(filename+".lock") except: print "could not unlock %s.lock, file not found" % filename def lock_file(filename): i = 0 wait = 1 - if not exists(filename): + if not os.path.exists(filename): file=open(filename, "w") file.close() while True: try: - symlink(filename, filename+".lock") + os.symlink(filename, filename+".lock") return except: i = i+1 @@ -74,17 +87,17 @@ messages = { "software and re-send the orders.", "multipart-de" : - "FEHLER: Die von dir eingeschickte Mail enthält keinen " \ + "FEHLER: Die von dir eingeschickte Mail enth�lt keinen " \ "Text. Evtl. hast Du den Zug als HTML oder als anderweitig " \ - "ungültig formatierte Mail ingeschickt. Wir können ihn " \ - "deshalb nicht berücksichtigen. Schicke den Zug nochmals " \ + "ung�ltig formatierte Mail ingeschickt. Wir k�nnen ihn " \ + "deshalb nicht ber�cksichtigen. Schicke den Zug nochmals " \ "als reinen Text ohne Formatierungen ein.", "maildate-de": - "Es erreichte uns bereits ein Zug mit einem späteren " \ + "Es erreichte uns bereits ein Zug mit einem sp�teren " \ "Absendedatum (%s > %s). Entweder ist deine " \ "Systemzeit verstellt, oder ein Zug hat einen anderen Zug von " \ - "dir auf dem Transportweg überholt. Entscheidend für die " \ + "dir auf dem Transportweg �berholt. Entscheidend f�r die " \ "Auswertungsreihenfolge ist das Absendedatum, d.h. der Date:-Header " \ "deiner Mail.", @@ -173,8 +186,8 @@ def available_file(dirname, basename): ver = 0 maxdate = 0 filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver) - while exists(filename): - maxdate = max(stat(filename)[ST_MTIME], maxdate) + while os.path.exists(filename): + maxdate = max(os.stat(filename)[ST_MTIME], maxdate) ver = ver + 1 filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver) if ver >= maxfiles: @@ -234,7 +247,7 @@ def copy_orders(message, filename, sender): from os.path import split dirname, basename = split(filename) dirname = dirname + '/headers' - if not exists(dirname): mkdir(dirname) + if not os.path.exists(dirname): os.mkdir(dirname) outfile = open(dirname + '/' + basename, "w") for name, value in message.items(): outfile.write(name + ": " + value + "\n") @@ -265,16 +278,14 @@ def copy_orders(message, filename, sender): # create a file, containing: # game=0 locale=de file=/path/to/filename email=rcpt@domain.to def accept(game, locale, stream, extend=None): - global rootdir, orderbase + global rootdir, orderbase, gamedir, gamename, frommail if extend is not None: orderbase = orderbase + ".pre-" + extend - gamename = games[game-2]["prefix"] - gamedir = rootdir+"/eressea/game-%d" % (game, ) - savedir = gamedir+"/"+orderbase + savedir = os.path.join(gamedir, orderbase) # check if it's one of the pre-sent orders. # create the save-directories if they don't exist - if not exists(gamedir): mkdir(gamedir) - if not exists(savedir): mkdir(savedir) + if not os.path.exists(gamedir): os.mkdir(gamedir) + if not os.path.exists(savedir): os.mkdir(savedir) # parse message message = Parser().parse(stream) sender = get_sender(message) @@ -298,7 +309,7 @@ def accept(game, locale, stream, extend=None): maildate = message.get("Date") if maildate != None: turndate = mktime_tz(parsedate_tz(maildate)) - utime(filename, (turndate, turndate)) + os.utime(filename, (turndate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) if turndate < maxdate: logger.warning("inconsistent message date " + sender) @@ -313,9 +324,9 @@ def accept(game, locale, stream, extend=None): warning = " (" + messages["error-" + locale] + ")" msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n" logger.warning("rejected - no text/plain in orders from " + sender) - unlink(filename) + os.unlink(filename) savedir = savedir + "/rejected" - if not exists(savedir): mkdir(savedir) + if not os.path.exists(savedir): os.mkdir(savedir) lock_file(gamedir + "/orders.queue") maxdate, filename = available_file(savedir, prefix + sender) store_message(message, filename) @@ -323,7 +334,6 @@ def accept(game, locale, stream, extend=None): fail = True if sendmail and warning is not None: - frommail = games[key]["from"] subject = gamename + " " + messages["subject-"+locale] + warning mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg from smtplib import SMTP @@ -347,22 +357,15 @@ def accept(game, locale, stream, extend=None): return 0 # the main body of the script: +LOG_FILENAME=os.path.join(rootdir, 'log/orders.log') logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME) logger = logging delay=None # TODO: parse the turn delay -try: - game = int(argv[1]) -except: - game = argv[1] - if game[:3]=='e3a': - game = 3 - elif game[:7]=='eressea': - game = 2 -locale = argv[2] +locale = sys.argv[2] infile = stdin -if len(argv)>3: - infile = open(argv[3], "r") +if len(sys.argv)>3: + infile = open(sys.argv[3], "r") retval = accept(game, locale, infile, delay) if infile!=stdin: infile.close() -exit(retval) +sys.exit(retval) From 1b2bfc79952c38b1886e3d38be6de8951b57a72c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 18:44:58 +0100 Subject: [PATCH 028/271] rename [eressea] section to [game] --- conf/eressea.ini | 5 +- process/orders-accept | 49 ++++++++++--------- process/orders-process | 107 +++++++++++++++++++++++++---------------- s/setup | 4 +- src/main.c | 14 +++--- 5 files changed, 102 insertions(+), 77 deletions(-) diff --git a/conf/eressea.ini b/conf/eressea.ini index c2f7bbb7f..b6db180ca 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -1,8 +1,7 @@ [game] -email = Eressea Server +email = eressea-server@kn-bremen.de +sender = Eressea Server name = Eressea - -[eressea] base = . report = reports verbose = 0 diff --git a/process/orders-accept b/process/orders-accept index 49bdc3cb0..78af0a056 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -27,13 +27,12 @@ if not os.path.isdir(dir): sys.exit(1) rootdir = dir -try: - game = int(sys.argv[1]) -except: - game = sys.argv[1] +game = int(sys.argv[1]) gamedir = os.path.join(rootdir, "game-%d" % (game, )) -frommail = 'Eressea Server ' +frommail = 'eressea-server@kn-bremen.de' gamename = 'Eressea' +sender = '%s Server <%s>' % (gamename, frommail) + inifile = os.path.join(gamedir, 'eressea.ini') if not os.path.exists(inifile): print "no such file: " . inifile @@ -44,6 +43,10 @@ else: frommail = config.get('game', 'email') if config.has_option('game', 'name'): gamename = config.get('game', 'name') + if config.has_option('game', 'sender'): + sender = config.get('game', 'sender') + else: + sender = "%s Server <%s>" % (gamename, frommail) config = None prefix = 'turn-' hostname = gethostname() @@ -278,7 +281,7 @@ def copy_orders(message, filename, sender): # create a file, containing: # game=0 locale=de file=/path/to/filename email=rcpt@domain.to def accept(game, locale, stream, extend=None): - global rootdir, orderbase, gamedir, gamename, frommail + global rootdir, orderbase, gamedir, gamename, sender if extend is not None: orderbase = orderbase + ".pre-" + extend savedir = os.path.join(gamedir, orderbase) @@ -288,21 +291,21 @@ def accept(game, locale, stream, extend=None): if not os.path.exists(savedir): os.mkdir(savedir) # parse message message = Parser().parse(stream) - sender = get_sender(message) - logger = logging.getLogger(sender) + email = get_sender(message) + logger = logging.getLogger(email) # write syslog - if sender is None or valid_email(sender)==0: - logger.warning("invalid email address: " + str(sender)) + if email is None or valid_email(email)==0: + logger.warning("invalid email address: " + str(email)) return -1 - logger.info("received orders from " + sender) + logger.info("received orders from " + email) # get an available filename lock_file(gamedir + "/orders.queue") - maxdate, filename = available_file(savedir, prefix + sender) + maxdate, filename = available_file(savedir, prefix + email) if filename is None: - logger.warning("more than " + str(maxfiles) + " orders from " + sender) + logger.warning("more than " + str(maxfiles) + " orders from " + email) return -1 # copy the orders to the file - text_ok = copy_orders(message, filename, sender) + text_ok = copy_orders(message, filename, email) unlock_file(gamedir + "/orders.queue") warning, msg, fail = None, "", False @@ -312,47 +315,47 @@ def accept(game, locale, stream, extend=None): os.utime(filename, (turndate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) if turndate < maxdate: - logger.warning("inconsistent message date " + sender) + logger.warning("inconsistent message date " + email) warning = " (" + messages["warning-" + locale] + ")" msg = msg + formatpar(messages["maildate-" + locale] % (ctime(maxdate),ctime(turndate)), 76, 2) + "\n" else: - logger.warning("missing message date " + sender) + logger.warning("missing message date " + email) warning = " (" + messages["warning-" + locale] + ")" msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n" if not text_ok: warning = " (" + messages["error-" + locale] + ")" msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n" - logger.warning("rejected - no text/plain in orders from " + sender) + logger.warning("rejected - no text/plain in orders from " + email) os.unlink(filename) savedir = savedir + "/rejected" if not os.path.exists(savedir): os.mkdir(savedir) lock_file(gamedir + "/orders.queue") - maxdate, filename = available_file(savedir, prefix + sender) + maxdate, filename = available_file(savedir, prefix + email) store_message(message, filename) unlock_file(gamedir + "/orders.queue") fail = True if sendmail and warning is not None: subject = gamename + " " + messages["subject-"+locale] + warning - mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg + mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, sender, email) + msg from smtplib import SMTP server = SMTP("localhost") - server.sendmail(frommail, sender, mail) + server.sendmail(sender, email, mail) server.close() if not sendmail: - print text_ok, fail, sender + print text_ok, fail, email print filename if not fail: lock_file(gamedir + "/orders.queue") queue = open(gamedir + "/orders.queue", "a") - queue.write("email=%s file=%s locale=%s game=%s\n" % (sender, filename, locale, game)) + queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game)) queue.close() unlock_file(gamedir + "/orders.queue") - logger.info("done - accepted orders from " + sender) + logger.info("done - accepted orders from " + email) return 0 diff --git a/process/orders-process b/process/orders-process index 753385e2e..b33cc05bf 100755 --- a/process/orders-process +++ b/process/orders-process @@ -2,7 +2,9 @@ # -*- coding: iso-8859-1 -*- from os import unlink, symlink, rename, popen, tmpfile -from os.path import exists +import os +import os.path +import ConfigParser from re import compile, IGNORECASE from string import split, join, upper, strip from sys import argv, exit @@ -14,9 +16,8 @@ from epasswd import EPasswd def pwd_get_email(faction, pwd, pwdfile=None): return None -def splitfilename(filename): - from os.path import split - return split(filename) +def split_filename(filename): + return os.path.split(filename) def unlock_file(filename): try: @@ -28,7 +29,7 @@ def unlock_file(filename): def lock_file(filename): i = 0 wait = 1 - if not exists(filename): + if not os.path.exists(filename): file=open(filename, "w") file.close() while True: @@ -62,17 +63,47 @@ messages = { "error-en": "Error", } +game = int(sys.argv[1]) +echeck_cmd = "/home/eressea/echeck/echeck.sh" +maxlines = 25 # base directory for all your games: -rootdir = "/home/eressea/eressea" -frommail = "Eressea Server " -orderbase = "orders.dir" -sendmail = True -maxlines = 25 -echeck_cmd = "/home/eressea/echeck/echeck.sh" +install_dir = "/home/eressea/eressea" +if 'ERESSEA' in os.environ: + install_dir = os.environ['ERESSEA'] +elif 'HOME' in os.environ: + install_dir = os.path.join(os.environ['HOME'], '/eressea') +if not os.path.isdir(install_dir): + print "please set the ERESSEA environment variable to the install path" + sys.exit(1) + +game_dir = os.path.join(install_dir, "game-%d" % (game, )) +frommail = 'eressea-server@kn-bremen.de' +gamename = 'Eressea' +sender = '%s Server <%s>' % (gamename, frommail) + +inifile = os.path.join(gamedir, 'eressea.ini') +if not os.path.exists(inifile): + print "no such file: " . inifile +else: + config = ConfigParser.ConfigParser() + config.read(inifile) + if config.has_option('game', 'email'): + frommail = config.get('game', 'email') + if config.has_option('game', 'name'): + gamename = config.get('game', 'name') + if config.has_option('game', 'sender'): + sender = config.get('game', 'sender') + else: + sender = "%s Server <%s>" % (gamename, frommail) + config = None + +queue_file = os.path.join(game_dir, "orders.queue") +if not os.path.exists(queue_file): + exit(0) # regular expression that finds the start of a faction -fact_re = compile("^\s*(eressea|vinyambar|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE) +fact_re = compile("^\s*(eressea|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE) def check_pwd(filename, email, pw_data): results = [] @@ -98,7 +129,7 @@ def check_pwd(filename, email, pw_data): return results def echeck(filename, locale, rules): - dirname, filename = splitfilename(filename) + dirname, filename = split_filename(filename) stream = popen("%s %s %s %s %s" % (echeck_cmd, locale, filename, dirname, rules), 'r') lines = stream.readlines() if len(lines)==0: @@ -111,14 +142,6 @@ def echeck(filename, locale, rules): stream.close() return mail -## the main body of the script -game = int(argv[1]) - -basedir = rootdir + "/game-%d" % (game, ) -queuename = basedir + "/orders.queue" -if not exists(queuename): - exit(0) - # parse the queue file - #print "connecting to SMTP..." from smtplib import SMTP @@ -127,16 +150,17 @@ try: except: print "could not connect to SMTP server" exit(0) + #print "reading password file..." -pw_data = EPasswd(basedir + "/passwd") +pw_data = EPasswd(os.path.join(game_dir,"passwd")) #print "reading orders.queue..." # move the queue file to a save space while locking it: try: - lock_file(queuename) + lock_file(queue_file) except: exit(0) -queuefile = open(queuename, "r") +queuefile = open(queue_file, "r") lines = queuefile.readlines() queuefile.close() @@ -154,9 +178,9 @@ tmpfile.close() openlog("orders") -unlink(queuename) +unlink(queue_file) try: - unlock_file(queuename) + unlock_file(queue_file) except: pass @@ -170,15 +194,15 @@ for line in lines: email = dict["email"] locale = dict["locale"] game = int(dict["game"]) - file = dict["file"] + infile = dict["file"] gamename='[E%d]' % game rules='e%d' % game warning = "" failed = True - results = check_pwd(file, email, pw_data) - logfile = open(basedir+"/zug.log", "a") - dirname, filename = splitfilename(file) - msg = messages["validate-"+locale] + " " + filename + "\n\n" + results = check_pwd(infile, email, pw_data) + logfile = open(os.path.join(game_dir, "zug.log"), "a") + dirname, filename = split_filename(infile) + msg = messages["validate-"+locale] + " " + infilename + "\n\n" for faction, game_email, success, pwd in results: msg = msg + messages["faction-"+locale] + " " + faction + "\n" if success: failed = False @@ -189,25 +213,24 @@ for line in lines: if failed: warning = " (" + messages["warning-" + locale] + ")" - syslog("failed - no valid password in " + file) + syslog("failed - no valid password in " + infile) else: - result = echeck(file, locale, rules) - if email=='eressea': - print result - continue - elif result is None: + result = None + if os.path.exists(echeck_cmd): + result = echeck(infile, locale, rules) + if result is None: # echeck did not finish - msg = msg + "Echeck was killed. Your turn was accepted, but could not be verified.\n" + msg = msg + "Echeck is broken. Your turn was accepted, but could not be verified.\n" warning = " (" + messages["warning-" + locale] + ")" - syslog("process - echeck got killed, " + file) + syslog("process - echeck broken, " + infile) else: msg = msg + result - syslog("process - checked orders in " + file) + syslog("process - checked orders in " + infile) subject = gamename + " " + messages["subject-" + locale] + warning - msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, frommail, email) + msg + msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, sender, email) + msg try: - server.sendmail(frommail, email, msg) + server.sendmail(sender, email, msg) except: syslog("failed - cannot send to " + email) diff --git a/s/setup b/s/setup index fc5fb9874..d8ffa74ad 100755 --- a/s/setup +++ b/s/setup @@ -94,8 +94,8 @@ touch eressea.ini } ini_start -ini_sec eressea -ini_add eressea locales de,en +ini_sec game +ini_add game locales de,en ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit diff --git a/src/main.c b/src/main.c index 5e998f835..2d81041ec 100644 --- a/src/main.c +++ b/src/main.c @@ -54,23 +54,23 @@ static void load_inifile(dictionary * d) assert(d); - str = iniparser_getstring(d, "eressea:base", basedir); + str = iniparser_getstring(d, "game:base", basedir); if (str != basedir) { set_basepath(str); } - str = iniparser_getstring(d, "eressea:report", reportdir); + str = iniparser_getstring(d, "game:report", reportdir); if (str != reportdir) { set_reportpath(str); } - str = iniparser_getstring(d, "eressea:data", datadir); + str = iniparser_getstring(d, "game:data", datadir); if (str != datadir) { set_datapath(str); } - lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; + lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0; - verbosity = iniparser_getint(d, "eressea:verbose", 2); - str = iniparser_getstring(d, "eressea:locales", "de,en"); + verbosity = iniparser_getint(d, "game:verbose", 2); + str = iniparser_getstring(d, "game:locales", "de,en"); make_locales(str); if (global.inifile) iniparser_freedict(global.inifile); @@ -84,7 +84,7 @@ static void parse_config(const char *filename) load_inifile(d); log_debug("reading from configuration file %s\n", filename); - memdebug = iniparser_getint(d, "eressea:memcheck", memdebug); + memdebug = iniparser_getint(d, "game:memcheck", memdebug); #ifdef USE_CURSES /* only one value in the [editor] section */ force_color = iniparser_getint(d, "editor:color", force_color); From 0909b0b8405e965826cd4348d65ae6c6559bfc5c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 20:05:33 +0100 Subject: [PATCH 029/271] we do not need eressea.conf --- process/send-bz2-report | 1 - process/sendreport.sh | 1 - process/sendreports.sh | 1 - 3 files changed, 3 deletions(-) diff --git a/process/send-bz2-report b/process/send-bz2-report index e9962d539..983564bea 100755 --- a/process/send-bz2-report +++ b/process/send-bz2-report @@ -8,7 +8,6 @@ if [ ! -f reports.txt ]; then exit -2 fi source $HOME/bin/functions.sh -source $ERESSEA/etc/eressea.conf TEMPLATE=report-mail.txt if [ "$1" == "-Lde" ] diff --git a/process/sendreport.sh b/process/sendreport.sh index 1b9af1d35..93d52f0b4 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -8,7 +8,6 @@ if [ -z $ERESSEA ]; then exit -2 fi source $HOME/bin/functions.sh -source $HOME/etc/eressea.conf GAME=$1 EMAIL=$2 diff --git a/process/sendreports.sh b/process/sendreports.sh index fc24200b6..c2bfa741c 100755 --- a/process/sendreports.sh +++ b/process/sendreports.sh @@ -8,7 +8,6 @@ if [ -z $ERESSEA ]; then exit -2 fi source $HOME/bin/functions.sh -source $ERESSEA/etc/eressea.conf if [ ! -z $1 ]; then GAME=$ERESSEA/game-$1 From 9c699634779c355179224976ec232ab6498683fd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 22:39:38 +0100 Subject: [PATCH 030/271] change error message categories. also removing some unused messages and code that supports them. https://bugs.eressea.de/view.php?id=2270 --- res/core/messages.xml | 117 +++++++--------------------------------- src/kernel/messages.c | 18 ------- src/kernel/types.h | 2 - src/util/unicode.test.c | 17 ++++++ 4 files changed, 36 insertions(+), 118 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 260f76c70..41569d9f3 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1804,7 +1804,7 @@ "$unit($unit) in $region($region): '$order($command)' - Der Magier erschafft ein Traumgebäude." "$unit($unit) in $region($region): '$order($command)' - The magician creates an illusionary building." - + @@ -2402,7 +2402,7 @@ "Eine Botschaft von $unit.dative($unit) in $region($region): 'Ups! Quack, Quack!'" "A message from $unit($unit) in $region($region): 'Oops! Croak, Croak!'" - + @@ -2412,7 +2412,7 @@ "$unit($unit) in $region($region): '$order($command)' - $unit($mage) kann Zauber, die durch $unit($unit) gewirkt werden, nicht zusätzlich in die Ferne richten." "$unit($unit) in $region($region): '$order($command)' - $unit($mage) cannot direct spells that are channeled through $unit($unit) into distant regions." - + @@ -2552,13 +2552,6 @@ "$unit($unit) in $region($region) regeneriert $int($amount) Aura." "$unit($unit) regenerates $int($amount) aura in $region($region)." - - - - - "$string" - "$string" - @@ -2596,13 +2589,6 @@ "$unit($teacher) lehrt $unit($student) $skill($skill)." "$unit($teacher) teaches $unit($student) $skill($skill)." - - - - - "$string" - "$string" - @@ -2834,13 +2820,6 @@ "$unit($unit) baut für $int($size) an $ship($ship) weiter." "$unit($unit) builds $int($size) more on $ship($ship)." - - - - - "$string" - "$string" - @@ -2878,15 +2857,7 @@ "$unit($unit) $if($eq($mode,1),"reitet", "wandert") von $region($start) nach $region($end).$if($isnull($regions),""," Dabei wurde $trail($regions) durchquert.")" "$unit($unit) $if($eq($mode,1),"rides", "walks") from $region($start) to $region($end)$if($isnull($regions),""," by way of $trail($regions)")." - - - - - - "$unit($unit) entdeckt dass im $direction($direction) $terrain($region) ist." - "$unit($unit) discovered that $terrain($region) lies in the $direction($direction)." - - + @@ -2895,7 +2866,7 @@ "$unit($unit) entdeckt, dass $region($region) $localize($terrain) ist." "$unit($unit) discovered that $region($region) is $localize($terrain)." - + @@ -2903,7 +2874,7 @@ "$unit($unit) ist in dieser Runde gelandet und kann nicht weiter ins Landesinnere nach $region($region) vorstossen." "$unit($unit) has just landed and cannot continue moving to $region($region)." - + @@ -2911,7 +2882,7 @@ "Die Mannschaft der $ship($ship) kann in letzter Sekunde verhindern, dass das Schiff in $region($region) auf Land aufläuft." "At the very last moment, the crew of the $ship($ship) saved the ship from running aground in $region($region)." - + @@ -2919,7 +2890,7 @@ "Die $ship($ship) konnte in $region($region) nicht einreisen, die Küste ist zu gefährlich für das Schiff." "The $ship($ship) could not berth in $region($region). The coast is too dangerous for the vessel." - + @@ -2927,7 +2898,7 @@ "Die Mannschaft der $ship($ship) weigert sich, nach $direction($direction) zu reisen." "The crew of the $ship($ship) refuses to travel to the $direction($direction)." - + @@ -2935,7 +2906,7 @@ "Die Mannschaft der $ship($ship) weigert sich, nach $region($region) zu reisen." "The crew of the $ship($ship) refuses to travel to $region($region)." - + @@ -2943,7 +2914,7 @@ "$unit($unit) weigert sich, nach $direction($direction) zu reisen." "$unit($unit) refuses to travel to the $direction($direction)." - + @@ -2951,7 +2922,7 @@ "$unit($unit) weigert sich, nach $region($region) zu reisen." "$unit($unit) refuses to travel to $region($region)." - + @@ -2959,7 +2930,7 @@ "Die $ship($ship) konnte $region($region) nicht verlassen." "The $ship($ship) could not leave $region($region)." - + @@ -2968,35 +2939,7 @@ "$unit($unit) wurde in $region($region) von $unit.dative($guard) aufgehalten." "$unit($unit) was kept in $region($region) by $unit($guard)." - - - - - "Wir haben den Krieg mit $faction($faction) beendet." - "We declared peace with $faction($faction)." - - - - - - "$faction($faction) hat den Krieg mit uns beendet." - "$faction($faction) has declared peace with us." - - - - - - "Wir haben $faction($faction) den Krieg erklärt." - "We declared war on $faction($faction)." - - - - - - "$faction($faction) hat uns den Krieg erklärt." - "$faction($faction) has declared war on us." - - + @@ -3005,7 +2948,7 @@ "$unit($unit) konnte nicht von $region($region) nach $region($target) reisen, da der Besitzer der Region es verhinderte." "$unit($unit) could not travel from $region($region) to $region($target) because the owner denied entrance." - + @@ -3029,7 +2972,7 @@ "$unit($follower) konnte $unit($unit) nicht folgen." "$unit($follower) could not follow $unit($unit)." - + @@ -3037,7 +2980,7 @@ "$unit($unit) entdeckt, dass es keinen Weg nach $direction($direction) gibt." "$unit($unit) discovers that there is no route going $direction($direction)." - + @@ -3046,13 +2989,6 @@ "$unit($unit) konnte von $region($region) nicht nach $direction($direction) ausreisen, der Nebel war zu dicht." "$unit($unit) could not travel $direction($direction) from $region($region), the fog was too dense." - - - - - "$string" - "$string" - @@ -6945,13 +6881,6 @@ "$unit($unit) in $region($region): '$order($command)' - Man benötigt mindestens $int($minskill) $skill($skill), um $resource($product,0) zu produzieren." "$unit($unit) in $region($region): '$order($command)' - You need at least $int($minskill) $skill($skill), to produce $resource($product,0)." - - - - - "$string" - "$string" - @@ -6959,13 +6888,6 @@ "$string" "$string" - - - - - "$string" - "$string" - @@ -6997,7 +6919,6 @@ "$unit($target) erhält $int($amount) $resource($resource,$amount) von $unit($unit)." "$unit($target) receives $int($amount) $resource($resource,$amount) from $unit($unit)." - @@ -7200,7 +7121,7 @@ "$unit($unit) in $region($region): '$order($command)' - No pyramids may be build in this region. The closest region to build a pyramid in is between $int($mindist) and $int($maxdist) regions away." - + @@ -7621,7 +7542,7 @@ "Heer $int($index)($abbrev): $int($dead) Tote, $int($fled) Geflohene, $int($survived) Ãœberlebende." "Army $int($index)($abbrev): $int($dead) dead, $int($fled) fled, $int($survived) survivors." - + diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 89278624f..cb859df96 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -214,29 +214,11 @@ caddmessage(region * r, faction * f, const char *s, msg_t mtype, int level) UNUSED_ARG(level); switch (mtype) { - case MSG_INCOME: - assert(f); - m = add_message(&f->msgs, msg_message("msg_economy", "string", s)); - break; case MSG_BATTLE: assert(0 || !"battle messages must not use addmessage"); break; - case MSG_MOVE: - assert(f); - m = add_message(&f->msgs, msg_message("msg_movement", "string", s)); - break; - case MSG_COMMERCE: - assert(f); - m = add_message(&f->msgs, msg_message("msg_economy", "string", s)); - break; - case MSG_PRODUCE: - assert(f); - m = add_message(&f->msgs, msg_message("msg_production", "string", s)); - break; case MSG_MAGIC: - case MSG_COMMENT: case MSG_MESSAGE: - case MSG_ORCVERMEHRUNG: case MSG_EVENT: /* Botschaften an REGION oder einzelne PARTEI */ m = msg_message("msg_event", "string", s); diff --git a/src/kernel/types.h b/src/kernel/types.h index da4fefecf..92f471688 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -146,9 +146,7 @@ typedef enum { /* Fehler und Meldungen im Report */ MSG_INCOME, MSG_COMMERCE, MSG_PRODUCE, - MSG_ORCVERMEHRUNG, MSG_MESSAGE, - MSG_COMMENT, MSG_MAGIC, MAX_MSG } msg_t; diff --git a/src/util/unicode.test.c b/src/util/unicode.test.c index ef07c944c..a6268186e 100644 --- a/src/util/unicode.test.c +++ b/src/util/unicode.test.c @@ -100,9 +100,26 @@ static void test_unicode_utf8_to_ucs(CuTest *tc) { CuAssertIntEquals(tc, 1, sz); } +static void test_unicode_bug2262(CuTest *tc) { + char name[7]; + ucs4_t ucs; + size_t sz; + + strcpy(name, "utende"); + CuAssertIntEquals(tc, 0, unicode_utf8_to_ucs4(&ucs, name, &sz)); + CuAssertIntEquals(tc, 1, sz); + CuAssertIntEquals(tc, 'u', ucs); + CuAssertIntEquals(tc, 0, unicode_utf8_trim(name)); + + name[0] = -4; // latin1: ü should fail to decode + CuAssertIntEquals(tc, EILSEQ, unicode_utf8_to_ucs4(&ucs, name, &sz)); + CuAssertIntEquals(tc, EILSEQ, unicode_utf8_trim(name)); +} + CuSuite *get_unicode_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_unicode_bug2262); SUITE_ADD_TEST(suite, test_unicode_tolower); SUITE_ADD_TEST(suite, test_unicode_trim); SUITE_ADD_TEST(suite, test_unicode_utf8_to_other); From 23e0943baa70204f7dc9523e849e96f1c7420411 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 18:53:11 +0100 Subject: [PATCH 031/271] read game configuration data from .ini file --- src/kernel/config.c | 34 ++++++++++++++++++++++++++++++++++ src/kernel/config.h | 1 + src/main.c | 1 + 3 files changed, 36 insertions(+) diff --git a/src/kernel/config.c b/src/kernel/config.c index 1f3cd92b2..955a9d598 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -713,6 +713,40 @@ bool config_changed(int *cache_key) { return false; } +#define MAXKEYS 16 +void config_set_from(const dictionary *d) +{ + int s, nsec = iniparser_getnsec(d); + for (s=0;s!=nsec;++s) { + char key[128]; + const char *sec = iniparser_getsecname(d, s); + int k, nkeys = iniparser_getsecnkeys(d, sec); + const char *akeys[MAXKEYS]; + const char ** keys = akeys; + size_t slen = strlen(sec); + assert(slenMAXKEYS) { + keys = malloc(sizeof(const char *) * nkeys); + } + iniparser_getseckeys(d, sec, keys); + for (k=0;k!=nkeys;++k) { + const char *val; + size_t klen = strlen(keys[k]); + assert(klen+slen+1 Date: Sat, 21 Jan 2017 19:53:47 +0100 Subject: [PATCH 032/271] issue #629: fix eressea.ini config fixed reading of ini data into config (keys have a . here, not a :). added a test. removed obsolete global.inifile variable. --- src/bindings.c | 10 +++++----- src/bindings.h | 6 +++--- src/kernel/config.c | 10 +++++----- src/kernel/config.h | 5 +++-- src/kernel/config.test.c | 17 +++++++++++++++++ src/main.c | 17 ++++++++--------- 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index f17ccc3a1..94e78fb70 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -978,7 +978,7 @@ static int tolua_report_unit(lua_State * L) return 1; } -static void parse_inifile(lua_State * L, dictionary * d, const char *section) +static void parse_inifile(lua_State * L, const dictionary * d, const char *section) { int i; const char *arg; @@ -1018,7 +1018,7 @@ static void parse_inifile(lua_State * L, dictionary * d, const char *section) void tolua_bind_open(lua_State * L); -int tolua_bindings_open(lua_State * L) +int tolua_bindings_open(lua_State * L, const dictionary *inifile) { tolua_open(L); @@ -1072,7 +1072,7 @@ int tolua_bindings_open(lua_State * L) tolua_module(L, TOLUA_CAST "config", 1); tolua_beginmodule(L, TOLUA_CAST "config"); { - parse_inifile(L, global.inifile, "lua"); + parse_inifile(L, inifile, "lua"); tolua_variable(L, TOLUA_CAST "locales", &config_get_locales, 0); tolua_function(L, TOLUA_CAST "get_resource", &config_get_resource); tolua_variable(L, TOLUA_CAST "buildings", &config_get_buildings, 0); @@ -1142,12 +1142,12 @@ void lua_done(lua_State * L) { lua_close(L); } -lua_State *lua_init(void) { +lua_State *lua_init(const dictionary *inifile) { lua_State *L = luaL_newstate(); openlibs(L); register_tolua_helpers(); - tolua_bindings_open(L); + tolua_bindings_open(L, inifile); tolua_eressea_open(L); #ifdef USE_SQLITE tolua_sqlite_open(L); diff --git a/src/bindings.h b/src/bindings.h index 6c71ecf94..2db83248d 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -16,10 +16,10 @@ extern "C" { struct lua_State; struct quicklist; + struct _dictionary_; int tolua_sqlite_open(struct lua_State *L); - int tolua_bindings_open(struct lua_State *L); - int tolua_spelllist_next(struct lua_State *L); + int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); int tolua_quicklist_push(struct lua_State *L, const char *list_type, @@ -28,7 +28,7 @@ extern "C" { int log_lua_error(struct lua_State *L); void lua_done(struct lua_State *L); - struct lua_State *lua_init(void); + struct lua_State *lua_init(const struct _dictionary_ *d); int eressea_run(struct lua_State *L, const char *luafile); #ifdef __cplusplus diff --git a/src/kernel/config.c b/src/kernel/config.c index 955a9d598..4b8bc7e72 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -721,12 +721,12 @@ void config_set_from(const dictionary *d) char key[128]; const char *sec = iniparser_getsecname(d, s); int k, nkeys = iniparser_getsecnkeys(d, sec); - const char *akeys[MAXKEYS]; - const char ** keys = akeys; + char *akeys[MAXKEYS]; + char ** keys = akeys; size_t slen = strlen(sec); assert(slenMAXKEYS) { keys = malloc(sizeof(const char *) * nkeys); } @@ -735,8 +735,8 @@ void config_set_from(const dictionary *d) const char *val; size_t klen = strlen(keys[k]); assert(klen+slen+1 #include #include "types.h" -struct param; + + struct param; + struct _dictionary_; #define DISPLAYSIZE 8192 /* max. L�nge einer Beschreibung, incl trailing 0 */ #define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */ @@ -108,7 +110,6 @@ struct param; struct attrib *attribs; unsigned int data_turn; void *vm_state; - struct _dictionary_ *inifile; struct global_functions { int(*wage) (const struct region * r, const struct faction * f, const struct race * rc, int in_turn); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index 405587443..719ff840e 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -233,9 +235,24 @@ static void test_rules(CuTest *tc) { CuAssertIntEquals(tc, 1000, rule_faction_limit()); } +static void test_config_inifile(CuTest *tc) { + dictionary *ini; + test_setup(); + ini = dictionary_new(0); + dictionary_set(ini, "game", NULL); + iniparser_set(ini, "game:id", "42"); + iniparser_set(ini, "game:name", "Eressea"); + config_set_from(ini); + CuAssertStrEquals(tc, "Eressea", config_get("game.name")); + CuAssertIntEquals(tc, 42, game_id()); + iniparser_freedict(ini); + test_cleanup(); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_config_inifile); SUITE_ADD_TEST(suite, test_config_cache); SUITE_ADD_TEST(suite, test_get_set_param); SUITE_ADD_TEST(suite, test_param_int); diff --git a/src/main.c b/src/main.c index 97c84dffe..777770f0a 100644 --- a/src/main.c +++ b/src/main.c @@ -72,12 +72,9 @@ static void load_inifile(dictionary * d) verbosity = iniparser_getint(d, "game:verbose", 2); str = iniparser_getstring(d, "game:locales", "de,en"); make_locales(str); - - if (global.inifile) iniparser_freedict(global.inifile); - global.inifile = d; } -static void parse_config(const char *filename) +static dictionary *parse_config(const char *filename) { dictionary *d = iniparser_load(filename); if (d) { @@ -92,6 +89,7 @@ static void parse_config(const char *filename) gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage); #endif } + return d; } static int usage(const char *prog, const char *arg) @@ -272,10 +270,11 @@ int main(int argc, char **argv) { int err = 0; lua_State *L; + dictionary *d; setup_signal_handler(); /* ini file sets defaults for arguments*/ - parse_config(inifile); - if (!global.inifile) { + d = parse_config(inifile); + if (!d) { log_error("could not open ini configuration %s\n", inifile); } /* parse arguments again, to override ini file */ @@ -283,7 +282,7 @@ int main(int argc, char **argv) locale_init(); - L = lua_init(); + L = lua_init(d); game_init(); bind_monsters(L); err = eressea_run(L, luafile); @@ -294,8 +293,8 @@ int main(int argc, char **argv) game_done(); lua_done(L); log_close(); - if (global.inifile) { - iniparser_freedict(global.inifile); + if (d) { + iniparser_freedict(d); } return 0; } From 75a97c2977bcb68ff1f3d5fb5e7f8d99e1d789b5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 20:39:46 +0100 Subject: [PATCH 033/271] fix gcc build, introduce a hard limit on ini section size --- src/kernel/config.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 4b8bc7e72..4459ce44a 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -721,15 +721,12 @@ void config_set_from(const dictionary *d) char key[128]; const char *sec = iniparser_getsecname(d, s); int k, nkeys = iniparser_getsecnkeys(d, sec); - char *akeys[MAXKEYS]; - char ** keys = akeys; + const char *keys[MAXKEYS]; size_t slen = strlen(sec); + assert(nkeys <= MAXKEYS); assert(slenMAXKEYS) { - keys = malloc(sizeof(const char *) * nkeys); - } iniparser_getseckeys(d, sec, keys); for (k=0;k!=nkeys;++k) { const char *val; @@ -741,9 +738,6 @@ void config_set_from(const dictionary *d) config_set(key, val); } } - if (keys!=akeys) { - free(keys); - } } } From 8c4cccbc65a9bdf8668a31a341c25d3e1548b9a6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 20:51:08 +0100 Subject: [PATCH 034/271] fix valgrind error. I did not understand what keys look like, then effed up when fixing that. --- src/kernel/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 4459ce44a..88130056b 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -732,7 +732,7 @@ void config_set_from(const dictionary *d) const char *val; size_t klen = strlen(keys[k]); assert(klen+slen+1 Date: Sat, 21 Jan 2017 20:59:16 +0100 Subject: [PATCH 035/271] config.json settings shall not override eressea.ini --- src/kernel/jsonconf.c | 4 +++- src/kernel/jsonconf.test.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 414704309..03e210ce0 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -806,7 +806,9 @@ static void json_settings(cJSON *json) { else { sprintf(value, "%d", child->valueint); } - config_set(child->string, value); + if (config_get(child->string) == NULL) { + config_set(child->string, value); + } } } } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 950868046..93fcd8d10 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -69,12 +69,15 @@ static void test_settings(CuTest * tc) "\"string\" : \"1d4\"," "\"integer\" : 14," "\"true\": true," + "\"game.id\": 4," "\"false\": false," "\"float\" : 1.5 }}"; cJSON *json = cJSON_Parse(data); test_cleanup(); + config_set("game.id", "42"); // should not be replaced json_config(json); + CuAssertStrEquals(tc, "42", config_get("game.id")); CuAssertStrEquals(tc, "1", config_get("true")); CuAssertStrEquals(tc, "0", config_get("false")); CuAssertStrEquals(tc, "1d4", config_get("string")); From f633099b97aef8f119d2af56146df3a16d4e3336 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 21:03:48 +0100 Subject: [PATCH 036/271] add game id to eressea.ini --- s/setup | 1 + 1 file changed, 1 insertion(+) diff --git a/s/setup b/s/setup index d8ffa74ad..848175ddc 100755 --- a/s/setup +++ b/s/setup @@ -96,6 +96,7 @@ touch eressea.ini ini_start ini_sec game ini_add game locales de,en +ini_add id $game ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit From 446e58c3831bfbcd49cf2b61caed466ef528133e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 04:46:36 +0100 Subject: [PATCH 037/271] use the email address from eressea.ini in CR mailto --- conf/e2/config.xml | 4 ---- conf/e3/config.xml | 4 ---- conf/e4/config.xml | 4 ---- src/creport.c | 7 +++++-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 0441a46f6..9e32218da 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -53,10 +53,6 @@ - - eressea-server@eressea.kn-bremen.de - eressea-server@eressea.kn-bremen.de - Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 2 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. diff --git a/conf/e3/config.xml b/conf/e3/config.xml index c8c5dbb06..6a5b18b84 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -45,10 +45,6 @@ - - eressea-server@eressea.kn-bremen.de - eressea-server@eressea.kn-bremen.de - Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 3 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. diff --git a/conf/e4/config.xml b/conf/e4/config.xml index b188f7d79..3209c8eed 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -46,10 +46,6 @@ - - eressea-server@eressea.kn-bremen.de - eressea-server@eressea.kn-bremen.de - Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 4 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. diff --git a/src/creport.c b/src/creport.c index bd9c97ec6..34cff9de3 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1475,7 +1475,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) faction *f = ctx->f; const char *prefix; region *r; - const char *mailto = LOC(f->locale, "mailto"); + const char *mailto = config_get("game.email"); const attrib *a; FILE *F = fopen(filename, "w"); static const race *rc_human; @@ -1510,8 +1510,11 @@ report_computer(const char *filename, report_context * ctx, const char *bom) fprintf(F, "%d;Zeitalter\n", era); fprintf(F, "\"%s\";Build\n", eressea_version()); if (mailto != NULL) { + // char mailcmd[64]; + // snprintf(mailcmd, sizeof(mailcmd), "%s %d, %s", game_name(), game_id(), LOC(f->locale, "mailcmd")); + const char * mailcmd = LOC(f->locale, "mailcmd"); fprintf(F, "\"%s\";mailto\n", mailto); - fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd")); + fprintf(F, "\"%s\";mailcmd\n", mailcmd); } show_alliances_cr(F, f); From 1a20d6e5c6036be83a18c6eec5bf4a2f5994c2a0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 04:55:19 +0100 Subject: [PATCH 038/271] use FACTION in text template, not ERESSEA --- src/report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/report.c b/src/report.c index 9b5e243b4..3c15f54f4 100644 --- a/src/report.c +++ b/src/report.c @@ -1408,7 +1408,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) newline(out); newline(out); - sprintf(buf, "%s %s \"password\"", LOC(f->locale, "ERESSEA"), itoa36(f->no)); + sprintf(buf, "%s %s \"password\"", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no)); rps_nowrap(out, buf); newline(out); newline(out); From cacb4505671dd43bf32f980b1a4536d4a459df93 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 05:13:44 +0100 Subject: [PATCH 039/271] game.start in eressea.ini overrides calendar --- s/setup | 3 ++- src/bindings.c | 2 +- src/calendar.c | 9 +++++++-- src/calendar.h | 6 +++--- src/kernel/xmlreader.c | 7 ++++++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/s/setup b/s/setup index 848175ddc..e3e8e113d 100755 --- a/s/setup +++ b/s/setup @@ -96,7 +96,8 @@ touch eressea.ini ini_start ini_sec game ini_add game locales de,en -ini_add id $game +ini_add game id $game +ini_add game start 1 ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit diff --git a/src/bindings.c b/src/bindings.c index 94e78fb70..14eae1c56 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -948,7 +948,7 @@ static int init_data(const char *filename, const char *catalog) return l; } if (turn < 0) { - turn = first_turn; + turn = first_turn(); } return 0; } diff --git a/src/calendar.c b/src/calendar.c index 7a27328a7..2099b6631 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1,10 +1,10 @@ #include #include "calendar.h" +#include #include #include -int first_turn = 0; int first_month = 0; int weeks_per_month = 4; int months_per_year = 12; @@ -16,10 +16,15 @@ int *month_season = NULL; char *agename = NULL; int seasons = 0; +int first_turn(void) +{ + return config_get_int("game.start", 1); +} + const gamedate *get_gamedate(int turn, gamedate * gd) { int weeks_per_year = months_per_year * weeks_per_month; - int t = turn - first_turn; + int t = turn - first_turn(); assert(gd); if (t < 0) diff --git a/src/calendar.h b/src/calendar.h index 86f665c1a..d398cd77c 100644 --- a/src/calendar.h +++ b/src/calendar.h @@ -13,7 +13,6 @@ extern "C" { }; extern char *agename; - extern int first_turn; extern int first_month; extern int seasons; @@ -35,8 +34,9 @@ extern "C" { int week; } gamedate; - extern const gamedate *get_gamedate(int turn, gamedate * gd); - extern void calendar_cleanup(void); +const gamedate *get_gamedate(int turn, gamedate * gd); +void calendar_cleanup(void); +int first_turn(void); #ifdef __cplusplus } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2f38cdab3..2ba9d785a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -375,8 +375,13 @@ static int parse_calendar(xmlDocPtr doc) xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons; xmlChar *propValue = xmlGetProp(calendar, BAD_CAST "name"); xmlChar *newyear = xmlGetProp(calendar, BAD_CAST "newyear"); + xmlChar *start; - first_turn = xml_ivalue(calendar, "start", first_turn); + start = xmlGetProp(calendar, BAD_CAST "start"); + if (start && config_get("game.start")==NULL) { + config_set("game.start", (const char *)start); + xmlFree(start); + } if (propValue) { free(agename); agename = strdup(mkname("calendar", (const char *)propValue)); From d29fd96f59f38ef0c91414356660935406c3612a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 08:03:12 +0100 Subject: [PATCH 040/271] no starting equipment. do not let the addplayer function give equipment. rename equipment for autoseed. --- conf/e2/config.xml | 2 +- conf/e3/config.xml | 8 -------- conf/e4/config.xml | 9 --------- res/eressea/equipment.xml | 22 +++++++++++----------- scripts/eressea/autoseed.lua | 6 +++--- src/kernel/faction.c | 6 ------ 6 files changed, 15 insertions(+), 38 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 9e32218da..5affea141 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -42,7 +42,7 @@ - + diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 6a5b18b84..35716f332 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -28,14 +28,6 @@ - - - - - - - - diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 3209c8eed..ac962202c 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -27,15 +27,6 @@ - - - - - - - - - diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml index bf7e38376..efd4f2a3b 100644 --- a/res/eressea/equipment.xml +++ b/res/eressea/equipment.xml @@ -2,18 +2,18 @@ - + - + - + @@ -21,30 +21,30 @@ - + - + - + - + - + - + @@ -58,12 +58,12 @@ - + - + diff --git a/scripts/eressea/autoseed.lua b/scripts/eressea/autoseed.lua index 562c39361..822725804 100644 --- a/scripts/eressea/autoseed.lua +++ b/scripts/eressea/autoseed.lua @@ -64,9 +64,9 @@ local function seed(r, email, race, lang) assert(f) local u = unit.create(f, r) assert(u) - equip_unit(u, "new_faction") - equip_unit(u, "first_unit") - equip_unit(u, "first_" .. race, 7) -- disable old callbacks + equip_unit(u, "autoseed_faction") + equip_unit(u, "autoseed_unit") + equip_unit(u, "autoseed_" .. race, 7) unit.create(f, r, 5):set_skill("mining", 30) unit.create(f, r, 5):set_skill("quarrying", 30) f:set_origin(r) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 2c6d4d244..e3b80566d 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alliance.h" #include "ally.h" #include "curse.h" -#include "equipment.h" #include "group.h" #include "item.h" #include "messages.h" @@ -286,15 +285,10 @@ faction *addfaction(const char *email, const char *password, unit *addplayer(region * r, faction * f) { unit *u; - char buffer[32]; assert(f->units == NULL); faction_setorigin(f, 0, r->x, r->y); u = create_unit(r, f, 1, f->race, 0, NULL, NULL); - equip_items(&u->faction->items, get_equipment("new_faction")); - equip_unit(u, get_equipment("first_unit")); - sprintf(buffer, "first_%s", u_race(u)->_name); - equip_unit(u, get_equipment(buffer)); u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { From 8d4a83d1b4fc5255104e68ac27d357c09fc75000 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 11:38:01 +0100 Subject: [PATCH 041/271] make these modules optional --- scripts/eressea/autoseed.lua | 1 + scripts/eressea/embassy.lua | 8 +++++--- scripts/eressea/eternath.lua | 2 +- scripts/eressea/ponnuki.lua | 1 + scripts/eressea/wedding.lua | 1 + scripts/eressea/xmas.lua | 2 ++ 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/eressea/autoseed.lua b/scripts/eressea/autoseed.lua index 822725804..9e5060f85 100644 --- a/scripts/eressea/autoseed.lua +++ b/scripts/eressea/autoseed.lua @@ -1,3 +1,4 @@ +if not config.autoseed then return nil end local autoseed = {} -- minimum required resources in the 7-hex neighborhood: diff --git a/scripts/eressea/embassy.lua b/scripts/eressea/embassy.lua index efbe248b7..82bce62c2 100644 --- a/scripts/eressea/embassy.lua +++ b/scripts/eressea/embassy.lua @@ -1,8 +1,5 @@ -- Muschelplateau -local embassy = {} -local home = nil - -- global exports (use item) function use_seashell(u, amount) -- Muschelplateau... @@ -17,6 +14,11 @@ function use_seashell(u, amount) return -4 end +if not config.embassy then return nil end + +local embassy = {} +local home = nil + function embassy.init() home = get_region(165,30) if home==nil then diff --git a/scripts/eressea/eternath.lua b/scripts/eressea/eternath.lua index 858a8d462..063577b74 100644 --- a/scripts/eressea/eternath.lua +++ b/scripts/eressea/eternath.lua @@ -1,5 +1,5 @@ -- DEPRECATED - +if not config.eternath then return nil end -- implements parts of a quest in E2 -- this module is deprecated, because it puts functions in the global environment for at_building_action diff --git a/scripts/eressea/ponnuki.lua b/scripts/eressea/ponnuki.lua index 994a16ff0..96bb0b5f1 100644 --- a/scripts/eressea/ponnuki.lua +++ b/scripts/eressea/ponnuki.lua @@ -1,3 +1,4 @@ +if not config.ponnuki then return nil end local ponnuki = {} local directions = { "NW", "NO", "O", "SO", "SW", "W" } diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua index 812bd3269..2c06d9891 100644 --- a/scripts/eressea/wedding.lua +++ b/scripts/eressea/wedding.lua @@ -1,4 +1,5 @@ -- DEPRECATED +if not config.wedding then return nil end -- this script contains the action functions for the two portals -- used on the jadee/wildente wedding island. the two _action functions diff --git a/scripts/eressea/xmas.lua b/scripts/eressea/xmas.lua index 36e755f45..0316e6265 100644 --- a/scripts/eressea/xmas.lua +++ b/scripts/eressea/xmas.lua @@ -1,3 +1,5 @@ +if not config.xmas then return nil end + local gifts = { e2 = { { year = 2015, turn = 959, item = 'snowglobe', msg='santa_f' }, From 1c7f3fab4440b0c8bd34a7806ec07a269886681a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:38:41 +0100 Subject: [PATCH 042/271] emit a password message for newbie factions --- src/kernel/faction.c | 1 + src/kernel/faction.h | 5 +++-- src/laws.c | 1 + src/reports.c | 8 ++++++++ src/reports.test.c | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index e3b80566d..e884a2d9b 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -249,6 +249,7 @@ faction *addfaction(const char *email, const char *password, if (!password) password = itoa36(rng_int()); faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); + f->flags |= FFL_PWMSG; f->alliance_joindate = turn; f->lastorders = turn; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index de55ad1fe..b4768e982 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -37,10 +37,11 @@ extern "C" { extern struct attrib_type at_maxmagicians; /* faction flags */ -#define FFL_NEWID (1<<0) /* Die Partei hat bereits einmal ihre no gewechselt */ +#define FFL_NEWID (1<<0) // Die Partei hat bereits einmal ihre no gewechselt #define FFL_ISNEW (1<<1) +#define FFL_PWMSG (1<<2) // received a "new password" message #define FFL_QUIT (1<<3) -#define FFL_CURSED (1<<4) /* you're going to have a bad time */ +#define FFL_CURSED (1<<4) // you're going to have a bad time #define FFL_DEFENDER (1<<10) #define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */ #define FFL_NOAID (1<<21) /* Hilfsflag Kampf */ diff --git a/src/laws.c b/src/laws.c index 7baadcf29..112d15fd2 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2214,6 +2214,7 @@ int password_cmd(unit * u, struct order *ord) faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT)); ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf)); + u->faction->flags |= FFL_PWMSG; return 0; } diff --git a/src/reports.c b/src/reports.c index 6d0aaba37..0da8aed94 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1336,6 +1336,14 @@ void prepare_report(report_context *ctx, faction *f) rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name); } + if (f->age<=2) { + if ((f->flags&FFL_PWMSG)==0) { + // TODO: this assumes unencrypted passwords + f->flags |= FFL_PWMSG; + ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->_password)); + } + } + ctx->f = f; ctx->report_time = time(NULL); ctx->addresses = NULL; diff --git a/src/reports.test.c b/src/reports.test.c index c9fe39c19..389d9c130 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -226,6 +226,23 @@ static void test_arg_resources(CuTest *tc) { test_cleanup(); } +static void test_newbie_password_message(CuTest *tc) { + report_context ctx; + faction *f; + test_setup(); + f = test_create_faction(0); + f->age = 5; + CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + prepare_report(&ctx, f); + CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd")); + f->age=2; + prepare_report(&ctx, f); + CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd")); + test_cleanup(); +} + static void test_prepare_travelthru(CuTest *tc) { report_context ctx; faction *f, *f2; @@ -465,6 +482,7 @@ static void test_seen_travelthru(CuTest *tc) { CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_newbie_password_message); SUITE_ADD_TEST(suite, test_prepare_report); SUITE_ADD_TEST(suite, test_seen_neighbours); SUITE_ADD_TEST(suite, test_seen_travelthru); From 2c6ae9baef473bd4f7e08ba00be3a3b16a595e16 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:43:48 +0100 Subject: [PATCH 043/271] remove ERESSEA keyword from "bad password" message. --- res/core/messages.xml | 5 ++--- src/kernel/save.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 41569d9f3..130b58d03 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3306,11 +3306,10 @@ - - "ERESSEA $int36($faction) \"${password}\" - Deine Befehle hatten ein falsches Passwort." - "ERESSEA $int36($faction) \"${password}\" - Your orders had the wrong password." + "Deine Befehle hatten ein falsches Passwort (${password})." + "Your orders had the wrong password (${password})." diff --git a/src/kernel/save.c b/src/kernel/save.c index 9825a5b55..5b5a5898f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -235,8 +235,7 @@ static faction *factionorders(void) if (!checkpasswd(f, (const char *)pass)) { log_debug("Invalid password for faction %s", itoa36(fid)); - ADDMSG(&f->msgs, msg_message("wrongpasswd", "faction password", - f->no, pass)); + ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", pass)); return 0; } /* Die Partei hat sich zumindest gemeldet, so dass sie noch From 7b55a57610b3e8d54ad2b1a6d6f8642ca9ae391f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:51:32 +0100 Subject: [PATCH 044/271] remove sqlite3 code and dependency --- CMakeLists.txt | 1 - process/sendreport.sh | 6 -- src/CMakeLists.txt | 12 --- src/bind_sqlite.c | 95 -------------------- src/bindings.c | 3 - src/bindings.h | 1 - src/sqlite.c | 204 ------------------------------------------ 7 files changed, 322 deletions(-) delete mode 100644 src/bind_sqlite.c delete mode 100644 src/sqlite.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 15629bf4c..8f6953b7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ project (eressea-server C) enable_testing() find_package (LibXml2) -find_package (SQLite3) find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) diff --git a/process/sendreport.sh b/process/sendreport.sh index 93d52f0b4..81d16813c 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -39,9 +39,3 @@ fi source ${FACTION}.sh $EMAIL || reply "Unbekannte Partei $FACTION" -if [ -e $ERESSEA/game-$GAME/eressea.db ]; then - SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)" - OWNER=$(sqlite3 $ERESSEA/game-$GAME/eressea.db "$SQL") - echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ - | mutt -s "Reportnachforderung Partei ${FACTION}" $OWNER -fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81a43e002..499b36409 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -157,13 +157,6 @@ set(SERVER_SRC bind_unit.c ) -if (SQLITE3_FOUND) -set (SERVER_SRC ${SERVER_SRC} - sqlite.c - bind_sqlite.c -) -endif (SQLITE3_FOUND) - if (CURSES_FOUND) set (SERVER_SRC ${SERVER_SRC} gmtool.c @@ -255,11 +248,6 @@ add_test(server test_eressea) install(TARGETS eressea DESTINATION "bin") -if (SQLITE3_FOUND) -target_link_libraries(eressea ${SQLITE3_LIBRARIES}) -add_definitions(-DUSE_SQLITE) -endif(SQLITE3_FOUND) - if (CURSES_FOUND) include_directories (${CURSES_INCLUDE_DIR}) target_link_libraries(eressea ${CURSES_LIBRARIES}) diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c deleted file mode 100644 index e8c9b7565..000000000 --- a/src/bind_sqlite.c +++ /dev/null @@ -1,95 +0,0 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ - -#include - -#include "bind_unit.h" -#include "bindings.h" - -#include -#include -#include - -#define LTYPE_DB TOLUA_CAST "db" - -extern int db_update_factions(sqlite3 * db, bool force, int game); -static int tolua_db_update_factions(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - db_update_factions(db, tolua_toboolean(L, 2, 0), game_id()); - return 0; -} - -extern int db_update_scores(sqlite3 * db, bool force); -static int tolua_db_update_scores(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - db_update_scores(db, tolua_toboolean(L, 2, 0)); - return 0; -} - -static int tolua_db_execute(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - const char *sql = tolua_tostring(L, 2, 0); - - int res = sqlite3_exec(db, sql, 0, 0, 0); - - lua_pushinteger(L, res); - return 1; -} - -static int tolua_db_close(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - sqlite3_close(db); - return 0; -} - -static int tolua_db_create(lua_State * L) -{ - sqlite3 *db; - const char *dbname = tolua_tostring(L, 1, 0); - int result = sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE, 0); - if (result == SQLITE_OK) { - tolua_pushusertype(L, (void *)db, LTYPE_DB); - return 1; - } - return 0; -} - -int tolua_sqlite_open(lua_State * L) -{ - /* register user types */ - - tolua_usertype(L, LTYPE_DB); - - tolua_module(L, NULL, 0); - tolua_beginmodule(L, NULL); - { - tolua_cclass(L, LTYPE_DB, LTYPE_DB, TOLUA_CAST "", NULL); - tolua_beginmodule(L, LTYPE_DB); - { - tolua_function(L, TOLUA_CAST "open", &tolua_db_create); - tolua_function(L, TOLUA_CAST "close", &tolua_db_close); - - tolua_function(L, TOLUA_CAST "update_factions", - &tolua_db_update_factions); - tolua_function(L, TOLUA_CAST "update_scores", &tolua_db_update_scores); - tolua_function(L, TOLUA_CAST "execute", &tolua_db_execute); - } - tolua_endmodule(L); - - } - tolua_endmodule(L); - return 0; -} diff --git a/src/bindings.c b/src/bindings.c index 14eae1c56..b466ce35f 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1149,9 +1149,6 @@ lua_State *lua_init(const dictionary *inifile) { register_tolua_helpers(); tolua_bindings_open(L, inifile); tolua_eressea_open(L); -#ifdef USE_SQLITE - tolua_sqlite_open(L); -#endif tolua_unit_open(L); tolua_building_open(L); tolua_ship_open(L); diff --git a/src/bindings.h b/src/bindings.h index 2db83248d..be60102a2 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -18,7 +18,6 @@ extern "C" { struct quicklist; struct _dictionary_; - int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); diff --git a/src/sqlite.c b/src/sqlite.c deleted file mode 100644 index aea0f5d20..000000000 --- a/src/sqlite.c +++ /dev/null @@ -1,204 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -faction *get_faction_by_id(int uid) -{ - faction *f; - for (f = factions; f; f = f->next) { - if (f->subscription == uid) { - return f; - } - } - return NULL; -} - -/* -typedef struct stmt_cache { -sqlite3 *db; -sqlite3_stmt *stmt; -const char *sql; -int inuse; -} stmt_cache; - -#define MAX_STMT_CACHE 64 -static stmt_cache cache[MAX_STMT_CACHE]; -static int cache_insert; - -static sqlite3_stmt *stmt_cache_get(sqlite3 * db, const char *sql) -{ -int i; -sqlite3_stmt *stmt; - -for (i = 0; i != MAX_STMT_CACHE && cache[i].db; ++i) { -if (cache[i].sql == sql && cache[i].db == db) { -cache[i].inuse = 1; -stmt = cache[i].stmt; -sqlite3_reset(stmt); -sqlite3_clear_bindings(stmt); -return stmt; -} -} -if (i == MAX_STMT_CACHE) { -while (cache[cache_insert].inuse) { -cache[cache_insert].inuse = 0; -cache_insert = (cache_insert + 1) & (MAX_STMT_CACHE - 1); -} -i = cache_insert; -stmt = cache[i].stmt; -sqlite3_finalize(stmt); -} -cache[i].inuse = 1; -cache[i].db = db; -cache[i].sql = sql; -sqlite3_prepare_v2(db, sql, -1, &cache[i].stmt, NULL); -return cache[i].stmt; -} -*/ -typedef struct db_faction { - int uid; - int no; - char *email; - char *name; -} db_faction; - -static struct quicklist * -read_factions(sqlite3 * db, int game_id) { - int res; - quicklist *result = 0; - const char * sql = - "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" - " LEFT OUTER JOIN faction_data fd" - " WHERE f.id=fd.faction_id AND f.game_id=? AND" - " fd.turn=(SELECT MAX(turn) FROM faction_data fx WHERE fx.faction_id=f.id)" - " ORDER BY f.id"; - sqlite3_stmt *stmt = 0; - sqlite3_prepare_v2(db, sql, -1, &stmt, 0); - sqlite3_bind_int(stmt, 1, game_id); - - res = sqlite3_step(stmt); - while (res == SQLITE_ROW) { - const char * text; - db_faction * dbf = (db_faction*)calloc(1, sizeof(db_faction)); - dbf->uid = (int)sqlite3_column_int64(stmt, 0); - text = (const char *)sqlite3_column_text(stmt, 1); - if (text) dbf->no = atoi36(text); - text = (const char *)sqlite3_column_text(stmt, 2); - if (text) dbf->name = strdup(text); - text = (const char *)sqlite3_column_text(stmt, 3); - if (text) dbf->email = strdup(text); - ql_push(&result, dbf); - res = sqlite3_step(stmt); - } - sqlite3_finalize(stmt); - return result; -} - -static int insert_faction(sqlite3 *db, int game_id, faction *f) { - const char *sql = "INSERT INTO faction (game_id, race) VALUES (?, ?)"; - sqlite3_stmt *stmt = 0; - sqlite3_prepare_v2(db, sql, -1, &stmt, 0); - sqlite3_bind_int(stmt, 1, game_id); - sqlite3_bind_text(stmt, 2, f->race->_name, -1, SQLITE_STATIC); - sqlite3_step(stmt); - sqlite3_finalize(stmt); - return (int)sqlite3_last_insert_rowid(db); -} - -static void update_faction(sqlite3 *db, const faction *f) { - char code[5]; - const char *sql = - "INSERT INTO faction_data (faction_id, code, name, email, lang, turn)" - " VALUES (?, ?, ?, ?, ?, ?)"; - sqlite3_stmt *stmt = 0; - strcpy(code, itoa36(f->no)); - sqlite3_prepare_v2(db, sql, -1, &stmt, 0); - sqlite3_bind_int(stmt, 1, f->subscription); - sqlite3_bind_text(stmt, 2, code, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, f->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 4, f->email, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 5, locale_name(f->locale), -1, SQLITE_STATIC); - sqlite3_bind_int(stmt, 6, turn); - sqlite3_step(stmt); - sqlite3_finalize(stmt); -} - -int db_update_factions(sqlite3 * db, bool force, int game_id) { - quicklist *ql = read_factions(db, game_id); - faction *f; - sqlite3_exec(db, "BEGIN", 0, 0, 0); - for (f = factions; f; f = f->next) { - bool update = force; - db_faction *dbf = 0; - ql_iter it = qli_init(&ql); - while (qli_more(it)) { - db_faction *df = (db_faction*)qli_next(&it); - if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { - dbf = df; - } - if (f->subscription == df->uid) { - dbf = df; - break; - } - } - if (dbf) { - if (dbf->uid != f->subscription) { - log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); - f->subscription = dbf->uid; - } - update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); - } - else { - f->subscription = insert_faction(db, game_id, f); - log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); - update = true; - } - if (update) { - update_faction(db, f); - log_debug("faction %s updated\n", itoa36(f->no)); - } - } - sqlite3_exec(db, "COMMIT", 0, 0, 0); - return SQLITE_OK; -} - -int db_update_scores(sqlite3 * db, bool force) -{ - /* - const char *sql_ins = - "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; - sqlite3_stmt *stmt_ins = stmt_cache_get(db, sql_ins); - const char *sql_upd = - "UPDATE score set value=? WHERE faction_id=? AND turn=?"; - sqlite3_stmt *stmt_upd = stmt_cache_get(db, sql_upd); - faction *f; - sqlite3_exec(db, "BEGIN", 0, 0, 0); - for (f = factions; f; f = f->next) { - int res; - sqlite3_bind_int(stmt_ins, 1, f->score); - sqlite3_bind_int64(stmt_ins, 2, f->subscription); - sqlite3_bind_int(stmt_ins, 3, turn); - res = sqlite3_step(stmt_ins); - if (res == SQLITE_CONSTRAINT) { - sqlite3_bind_int(stmt_upd, 1, f->score); - sqlite3_bind_int64(stmt_upd, 2, f->subscription); - sqlite3_bind_int(stmt_upd, 3, turn); - res = sqlite3_step(stmt_upd); - sqlite3_reset(stmt_upd); - } - sqlite3_reset(stmt_ins); - } - sqlite3_exec(db, "COMMIT", 0, 0, 0); - */ - return SQLITE_OK; -} From baa210d1a9d1055f62ff14cd2533a4b908be22db Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:57:25 +0100 Subject: [PATCH 045/271] Revert "remove sqlite3 code and dependency" This reverts commit 7b55a57610b3e8d54ad2b1a6d6f8642ca9ae391f. --- CMakeLists.txt | 1 + process/sendreport.sh | 6 ++ src/CMakeLists.txt | 12 +++ src/bind_sqlite.c | 95 ++++++++++++++++++++ src/bindings.c | 3 + src/bindings.h | 1 + src/sqlite.c | 204 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 322 insertions(+) create mode 100644 src/bind_sqlite.c create mode 100644 src/sqlite.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f6953b7f..15629bf4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ project (eressea-server C) enable_testing() find_package (LibXml2) +find_package (SQLite3) find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) diff --git a/process/sendreport.sh b/process/sendreport.sh index 81d16813c..93d52f0b4 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -39,3 +39,9 @@ fi source ${FACTION}.sh $EMAIL || reply "Unbekannte Partei $FACTION" +if [ -e $ERESSEA/game-$GAME/eressea.db ]; then + SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)" + OWNER=$(sqlite3 $ERESSEA/game-$GAME/eressea.db "$SQL") + echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ + | mutt -s "Reportnachforderung Partei ${FACTION}" $OWNER +fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 499b36409..81a43e002 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -157,6 +157,13 @@ set(SERVER_SRC bind_unit.c ) +if (SQLITE3_FOUND) +set (SERVER_SRC ${SERVER_SRC} + sqlite.c + bind_sqlite.c +) +endif (SQLITE3_FOUND) + if (CURSES_FOUND) set (SERVER_SRC ${SERVER_SRC} gmtool.c @@ -248,6 +255,11 @@ add_test(server test_eressea) install(TARGETS eressea DESTINATION "bin") +if (SQLITE3_FOUND) +target_link_libraries(eressea ${SQLITE3_LIBRARIES}) +add_definitions(-DUSE_SQLITE) +endif(SQLITE3_FOUND) + if (CURSES_FOUND) include_directories (${CURSES_INCLUDE_DIR}) target_link_libraries(eressea ${CURSES_LIBRARIES}) diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c new file mode 100644 index 000000000..e8c9b7565 --- /dev/null +++ b/src/bind_sqlite.c @@ -0,0 +1,95 @@ +/* ++-------------------+ +| | Enno Rehling +| Eressea PBEM host | Christian Schlittchen +| (c) 1998 - 2008 | Katja Zedel +| | Henning Peters ++-------------------+ + +This program may not be used, modified or distributed +without prior permission by the authors of Eressea. +*/ + +#include + +#include "bind_unit.h" +#include "bindings.h" + +#include +#include +#include + +#define LTYPE_DB TOLUA_CAST "db" + +extern int db_update_factions(sqlite3 * db, bool force, int game); +static int tolua_db_update_factions(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + db_update_factions(db, tolua_toboolean(L, 2, 0), game_id()); + return 0; +} + +extern int db_update_scores(sqlite3 * db, bool force); +static int tolua_db_update_scores(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + db_update_scores(db, tolua_toboolean(L, 2, 0)); + return 0; +} + +static int tolua_db_execute(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + const char *sql = tolua_tostring(L, 2, 0); + + int res = sqlite3_exec(db, sql, 0, 0, 0); + + lua_pushinteger(L, res); + return 1; +} + +static int tolua_db_close(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + sqlite3_close(db); + return 0; +} + +static int tolua_db_create(lua_State * L) +{ + sqlite3 *db; + const char *dbname = tolua_tostring(L, 1, 0); + int result = sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE, 0); + if (result == SQLITE_OK) { + tolua_pushusertype(L, (void *)db, LTYPE_DB); + return 1; + } + return 0; +} + +int tolua_sqlite_open(lua_State * L) +{ + /* register user types */ + + tolua_usertype(L, LTYPE_DB); + + tolua_module(L, NULL, 0); + tolua_beginmodule(L, NULL); + { + tolua_cclass(L, LTYPE_DB, LTYPE_DB, TOLUA_CAST "", NULL); + tolua_beginmodule(L, LTYPE_DB); + { + tolua_function(L, TOLUA_CAST "open", &tolua_db_create); + tolua_function(L, TOLUA_CAST "close", &tolua_db_close); + + tolua_function(L, TOLUA_CAST "update_factions", + &tolua_db_update_factions); + tolua_function(L, TOLUA_CAST "update_scores", &tolua_db_update_scores); + tolua_function(L, TOLUA_CAST "execute", &tolua_db_execute); + } + tolua_endmodule(L); + + } + tolua_endmodule(L); + return 0; +} diff --git a/src/bindings.c b/src/bindings.c index b466ce35f..14eae1c56 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1149,6 +1149,9 @@ lua_State *lua_init(const dictionary *inifile) { register_tolua_helpers(); tolua_bindings_open(L, inifile); tolua_eressea_open(L); +#ifdef USE_SQLITE + tolua_sqlite_open(L); +#endif tolua_unit_open(L); tolua_building_open(L); tolua_ship_open(L); diff --git a/src/bindings.h b/src/bindings.h index be60102a2..2db83248d 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -18,6 +18,7 @@ extern "C" { struct quicklist; struct _dictionary_; + int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); diff --git a/src/sqlite.c b/src/sqlite.c new file mode 100644 index 000000000..aea0f5d20 --- /dev/null +++ b/src/sqlite.c @@ -0,0 +1,204 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +faction *get_faction_by_id(int uid) +{ + faction *f; + for (f = factions; f; f = f->next) { + if (f->subscription == uid) { + return f; + } + } + return NULL; +} + +/* +typedef struct stmt_cache { +sqlite3 *db; +sqlite3_stmt *stmt; +const char *sql; +int inuse; +} stmt_cache; + +#define MAX_STMT_CACHE 64 +static stmt_cache cache[MAX_STMT_CACHE]; +static int cache_insert; + +static sqlite3_stmt *stmt_cache_get(sqlite3 * db, const char *sql) +{ +int i; +sqlite3_stmt *stmt; + +for (i = 0; i != MAX_STMT_CACHE && cache[i].db; ++i) { +if (cache[i].sql == sql && cache[i].db == db) { +cache[i].inuse = 1; +stmt = cache[i].stmt; +sqlite3_reset(stmt); +sqlite3_clear_bindings(stmt); +return stmt; +} +} +if (i == MAX_STMT_CACHE) { +while (cache[cache_insert].inuse) { +cache[cache_insert].inuse = 0; +cache_insert = (cache_insert + 1) & (MAX_STMT_CACHE - 1); +} +i = cache_insert; +stmt = cache[i].stmt; +sqlite3_finalize(stmt); +} +cache[i].inuse = 1; +cache[i].db = db; +cache[i].sql = sql; +sqlite3_prepare_v2(db, sql, -1, &cache[i].stmt, NULL); +return cache[i].stmt; +} +*/ +typedef struct db_faction { + int uid; + int no; + char *email; + char *name; +} db_faction; + +static struct quicklist * +read_factions(sqlite3 * db, int game_id) { + int res; + quicklist *result = 0; + const char * sql = + "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" + " LEFT OUTER JOIN faction_data fd" + " WHERE f.id=fd.faction_id AND f.game_id=? AND" + " fd.turn=(SELECT MAX(turn) FROM faction_data fx WHERE fx.faction_id=f.id)" + " ORDER BY f.id"; + sqlite3_stmt *stmt = 0; + sqlite3_prepare_v2(db, sql, -1, &stmt, 0); + sqlite3_bind_int(stmt, 1, game_id); + + res = sqlite3_step(stmt); + while (res == SQLITE_ROW) { + const char * text; + db_faction * dbf = (db_faction*)calloc(1, sizeof(db_faction)); + dbf->uid = (int)sqlite3_column_int64(stmt, 0); + text = (const char *)sqlite3_column_text(stmt, 1); + if (text) dbf->no = atoi36(text); + text = (const char *)sqlite3_column_text(stmt, 2); + if (text) dbf->name = strdup(text); + text = (const char *)sqlite3_column_text(stmt, 3); + if (text) dbf->email = strdup(text); + ql_push(&result, dbf); + res = sqlite3_step(stmt); + } + sqlite3_finalize(stmt); + return result; +} + +static int insert_faction(sqlite3 *db, int game_id, faction *f) { + const char *sql = "INSERT INTO faction (game_id, race) VALUES (?, ?)"; + sqlite3_stmt *stmt = 0; + sqlite3_prepare_v2(db, sql, -1, &stmt, 0); + sqlite3_bind_int(stmt, 1, game_id); + sqlite3_bind_text(stmt, 2, f->race->_name, -1, SQLITE_STATIC); + sqlite3_step(stmt); + sqlite3_finalize(stmt); + return (int)sqlite3_last_insert_rowid(db); +} + +static void update_faction(sqlite3 *db, const faction *f) { + char code[5]; + const char *sql = + "INSERT INTO faction_data (faction_id, code, name, email, lang, turn)" + " VALUES (?, ?, ?, ?, ?, ?)"; + sqlite3_stmt *stmt = 0; + strcpy(code, itoa36(f->no)); + sqlite3_prepare_v2(db, sql, -1, &stmt, 0); + sqlite3_bind_int(stmt, 1, f->subscription); + sqlite3_bind_text(stmt, 2, code, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 3, f->name, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 4, f->email, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 5, locale_name(f->locale), -1, SQLITE_STATIC); + sqlite3_bind_int(stmt, 6, turn); + sqlite3_step(stmt); + sqlite3_finalize(stmt); +} + +int db_update_factions(sqlite3 * db, bool force, int game_id) { + quicklist *ql = read_factions(db, game_id); + faction *f; + sqlite3_exec(db, "BEGIN", 0, 0, 0); + for (f = factions; f; f = f->next) { + bool update = force; + db_faction *dbf = 0; + ql_iter it = qli_init(&ql); + while (qli_more(it)) { + db_faction *df = (db_faction*)qli_next(&it); + if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { + dbf = df; + } + if (f->subscription == df->uid) { + dbf = df; + break; + } + } + if (dbf) { + if (dbf->uid != f->subscription) { + log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); + f->subscription = dbf->uid; + } + update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); + } + else { + f->subscription = insert_faction(db, game_id, f); + log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); + update = true; + } + if (update) { + update_faction(db, f); + log_debug("faction %s updated\n", itoa36(f->no)); + } + } + sqlite3_exec(db, "COMMIT", 0, 0, 0); + return SQLITE_OK; +} + +int db_update_scores(sqlite3 * db, bool force) +{ + /* + const char *sql_ins = + "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; + sqlite3_stmt *stmt_ins = stmt_cache_get(db, sql_ins); + const char *sql_upd = + "UPDATE score set value=? WHERE faction_id=? AND turn=?"; + sqlite3_stmt *stmt_upd = stmt_cache_get(db, sql_upd); + faction *f; + sqlite3_exec(db, "BEGIN", 0, 0, 0); + for (f = factions; f; f = f->next) { + int res; + sqlite3_bind_int(stmt_ins, 1, f->score); + sqlite3_bind_int64(stmt_ins, 2, f->subscription); + sqlite3_bind_int(stmt_ins, 3, turn); + res = sqlite3_step(stmt_ins); + if (res == SQLITE_CONSTRAINT) { + sqlite3_bind_int(stmt_upd, 1, f->score); + sqlite3_bind_int64(stmt_upd, 2, f->subscription); + sqlite3_bind_int(stmt_upd, 3, turn); + res = sqlite3_step(stmt_upd); + sqlite3_reset(stmt_upd); + } + sqlite3_reset(stmt_ins); + } + sqlite3_exec(db, "COMMIT", 0, 0, 0); + */ + return SQLITE_OK; +} From 2c38883362690c333f88238cc2da9d0eabfae82a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 13:09:32 +0100 Subject: [PATCH 046/271] configure dbname in eressea.ini (or don't use DB if not --- scripts/run-turn.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 7ee9165ca..92efa8a14 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -26,15 +26,17 @@ function callbacks(rules, name, ...) end local function dbupdate() - update_scores() - dbname = config.dbname or 'eressea.db' - edb = db.open(config.basepath..'/'..dbname) - if edb~=nil then - edb:update_factions() - edb:update_scores() - else - eressea.log.error("could not open "..config.basepath..'/'..dbname) - end + update_scores() + if config.dbname then + dbname = config.basepath..'/'..config.dbname + edb = db.open(dbame) + if edb~=nil then + edb:update_factions() + edb:update_scores() + else + eressea.log.error("could not open "..dbname) + end + end end local function write_emails(locales) From 9e9cd6ae79faf2f0b388b55273b5d2ca942562ff Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:01:09 +0100 Subject: [PATCH 047/271] try loading config.lua and custom.lua files, if they exist. --- src/bindings.c | 68 ++++++++++++++++++++++++++++++++--------------- src/kernel/save.h | 1 - 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 14eae1c56..cce07c33e 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1168,32 +1168,56 @@ lua_State *lua_init(const dictionary *inifile) { return L; } +static int run_script(lua_State *L, const char *luafile) { + int err; + FILE *F; + + F = fopen(luafile, "r"); + if (!F) { + log_debug("dofile('%s'): %s", luafile, strerror(errno)); + return errno; + } + fclose(F); + + log_debug("executing script %s", luafile); + lua_getglobal(L, "dofile"); + lua_pushstring(L, luafile); + err = lua_pcall(L, 1, 1, -3); /* error handler (debug.traceback) is now at stack -3 */ + if (err != 0) { + log_lua_error(L); + assert(!"Lua syntax error? check log."); + } + else { + if (lua_isnumber(L, -1)) { + err = (int)lua_tonumber(L, -1); + } + lua_pop(L, 1); + } + return err; +} + int eressea_run(lua_State *L, const char *luafile) { - int err = 0; - + int err; global.vm_state = L; + + /* push an error handling function on the stack: */ + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + lua_remove(L, -2); + + /* try to run configuration scripts: */ + err = run_script(L, "config.lua"); + err = run_script(L, "custom.lua"); + /* run the main script */ if (luafile) { - log_debug("executing script %s\n", luafile); - - lua_getglobal(L, "debug"); - lua_getfield(L, -1, "traceback"); - lua_remove(L, -2); - lua_getglobal(L, "dofile"); - lua_pushstring(L, luafile); - err = lua_pcall(L, 1, 1, -3); - if (err != 0) { - log_lua_error(L); - assert(!"Lua syntax error? check log."); - } - else { - if (lua_isnumber(L, -1)) { - err = (int)lua_tonumber(L, -1); - } - lua_pop(L, 1); - } - return err; + err = run_script(L, luafile); } - return lua_console(L); + else { + err = lua_console(L); + } + /* pop error handler off the stack: */ + lua_pop(L, 1); + return err; } diff --git a/src/kernel/save.h b/src/kernel/save.h index be78b9c68..4ead34efe 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -44,7 +44,6 @@ extern "C" { extern int enc_gamedata; int readorders(const char *filename); - int creategame(void); int readgame(const char *filename); int writegame(const char *filename); From 09d4316568c5aa720d654bbc7013d637f3482256 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:03:46 +0100 Subject: [PATCH 048/271] missing includE --- src/bindings.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bindings.c b/src/bindings.c index cce07c33e..aae564478 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -80,6 +80,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #define TOLUA_PKG(NAME) extern void tolua_##NAME##_open(lua_State * L) From 0270b3fb8a16d08d4b00b002d0a11aa402d7e5fb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:28:04 +0100 Subject: [PATCH 049/271] rename create_equipment function --- src/bindings.c | 6 +++--- src/kernel/equipment.c | 2 +- src/kernel/equipment.h | 2 +- src/kernel/equipment.test.c | 2 +- src/kernel/xmlreader.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index aae564478..fad958cd4 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -83,7 +83,7 @@ without prior permission by the authors of Eressea. #include #include -#define TOLUA_PKG(NAME) extern void tolua_##NAME##_open(lua_State * L) +#define TOLUA_PKG(NAME) void tolua_##NAME##_open(lua_State * L) TOLUA_PKG(eressea); TOLUA_PKG(process); @@ -328,7 +328,7 @@ static int tolua_addequipment(lua_State * L) if (iname != NULL) { const struct item_type *itype = it_find(iname); if (itype != NULL) { - equipment_setitem(create_equipment(eqname), itype, value); + equipment_setitem(get_or_create_equipment(eqname), itype, value); result = 0; } } @@ -461,7 +461,7 @@ static int tolua_equipment_setitem(lua_State * L) if (iname != NULL) { const struct item_type *itype = it_find(iname); if (itype != NULL) { - equipment_setitem(create_equipment(eqname), itype, value); + equipment_setitem(get_or_create_equipment(eqname), itype, value); result = 0; } } diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 1587e7531..7874a2c32 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -39,7 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static equipment *equipment_sets; -equipment *create_equipment(const char *eqname) +equipment *get_or_create_equipment(const char *eqname) { equipment **eqp = &equipment_sets; for (;;) { diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 5c7b3407b..84fe55722 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -56,7 +56,7 @@ extern "C" { void equipment_done(void); - struct equipment *create_equipment(const char *eqname); + struct equipment *get_or_create_equipment(const char *eqname); struct equipment *get_equipment(const char *eqname); void equipment_setitem(struct equipment *eq, diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 2911af1ea..ad69bec10 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -29,7 +29,7 @@ void test_equipment(CuTest * tc) CuAssertPtrNotNull(tc, sp); CuAssertPtrEquals(tc, 0, get_equipment("herpderp")); - eq = create_equipment("herpderp"); + eq = get_or_create_equipment("herpderp"); CuAssertPtrEquals(tc, eq, get_equipment("herpderp")); equipment_setitem(eq, it_horses, "1"); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2ba9d785a..cba01bc7b 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1266,7 +1266,7 @@ add_subsets(xmlDocPtr doc, equipment * eq, xmlNodeSetPtr nsetSubsets) assert(propValue != NULL); eq->subsets[i].sets[set].chance = chance; eq->subsets[i].sets[set].set = - create_equipment((const char *)propValue); + get_or_create_equipment((const char *)propValue); xmlFree(propValue); } } @@ -1296,7 +1296,7 @@ static int parse_equipment(xmlDocPtr doc) xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); if (propName != NULL) { - equipment *eq = create_equipment((const char *)propName); + equipment *eq = get_or_create_equipment((const char *)propName); xmlXPathObjectPtr xpathResult; xpath->node = node; From 4cbeb03590a87cb86275c08bd69eb11fe33ec9c1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:35:54 +0100 Subject: [PATCH 050/271] clean the quipment interface for lua a little bit. --- conf/e2/config.xml | 2 +- src/bindings.c | 18 ------------------ src/kernel/faction.c | 6 ++++++ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 5affea141..8389ba470 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -29,7 +29,7 @@ - + diff --git a/src/bindings.c b/src/bindings.c index fad958cd4..b6be1ccba 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -319,23 +319,6 @@ static int tolua_dice_rand(lua_State * L) return 1; } -static int tolua_addequipment(lua_State * L) -{ - const char *eqname = tolua_tostring(L, 1, 0); - const char *iname = tolua_tostring(L, 2, 0); - const char *value = tolua_tostring(L, 3, 0); - int result = -1; - if (iname != NULL) { - const struct item_type *itype = it_find(iname); - if (itype != NULL) { - equipment_setitem(get_or_create_equipment(eqname), itype, value); - result = 0; - } - } - lua_pushinteger(L, result); - return 1; -} - static int tolua_get_season(lua_State * L) { int turnno = (int)tolua_tonumber(L, 1, 0); @@ -1112,7 +1095,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "get_season", tolua_get_season); tolua_function(L, TOLUA_CAST "equipment_setitem", tolua_equipment_setitem); tolua_function(L, TOLUA_CAST "equip_unit", tolua_equipunit); - tolua_function(L, TOLUA_CAST "add_equipment", tolua_addequipment); tolua_function(L, TOLUA_CAST "atoi36", tolua_atoi36); tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36); tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index e884a2d9b..d67619752 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alliance.h" #include "ally.h" #include "curse.h" +#include "equipment.h" #include "group.h" #include "item.h" #include "messages.h" @@ -286,10 +287,15 @@ faction *addfaction(const char *email, const char *password, unit *addplayer(region * r, faction * f) { unit *u; + const struct equipment* eq; assert(f->units == NULL); faction_setorigin(f, 0, r->x, r->y); u = create_unit(r, f, 1, f->race, 0, NULL, NULL); + eq = get_equipment("first_unit"); + if (eq) { + equip_items(&u->items, eq); + } u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { From f09259f2b3a7d057ec0d742661d8e4cad83cbf45 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:51:20 +0100 Subject: [PATCH 051/271] eliminate duplicate password message --- scripts/tests/faction.lua | 2 +- src/kernel/faction.c | 11 +++++------ src/kernel/faction.test.c | 2 +- src/reports.test.c | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index 38fdc4eb7..87a6b5100 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -17,7 +17,7 @@ function setup() end function test_faction_flags() - assert_equal(2, f.flags) -- FFL_ISNEW + assert_equal(6, f.flags) -- FFL_ISNEW|FFL_PWMSG f.flags = 42 assert_equal(42, f.flags) end diff --git a/src/kernel/faction.c b/src/kernel/faction.c index d67619752..6b601f002 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -247,11 +247,6 @@ faction *addfaction(const char *email, const char *password, log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email); } - if (!password) password = itoa36(rng_int()); - faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); - ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); - f->flags |= FFL_PWMSG; - f->alliance_joindate = turn; f->lastorders = turn; f->_alive = true; @@ -260,7 +255,11 @@ faction *addfaction(const char *email, const char *password, f->magiegebiet = 0; f->locale = loc; f->subscription = subscription; - f->flags = FFL_ISNEW; + f->flags = FFL_ISNEW|FFL_PWMSG; + + if (!password) password = itoa36(rng_int()); + faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); + ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); f->options = want(O_REPORT) | want(O_ZUGVORLAGE) | want(O_COMPUTER) | want(O_COMPRESS) | diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 3d81b5d3c..441ca5038 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) { CuAssertTrue(tc, checkpasswd(f, "hurrdurr")); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); CuAssertIntEquals(tc, 1234, f->subscription); - CuAssertIntEquals(tc, FFL_ISNEW, f->flags); + CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags); CuAssertIntEquals(tc, 0, f->age); CuAssertTrue(tc, faction_alive(f)); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); diff --git a/src/reports.test.c b/src/reports.test.c index 389d9c130..728145758 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -232,7 +232,7 @@ static void test_newbie_password_message(CuTest *tc) { test_setup(); f = test_create_faction(0); f->age = 5; - CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + f->flags = 0; prepare_report(&ctx, f); CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd")); From aa66e5d39f3f78f73a7e84ef961e2f65029172b3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 19:06:37 +0100 Subject: [PATCH 052/271] remove unused equipment sets (from an unrealized feature). --- res/e3a/equipment.xml | 69 ------------------------------------------- 1 file changed, 69 deletions(-) diff --git a/res/e3a/equipment.xml b/res/e3a/equipment.xml index bbd2ac5b7..9fe133f48 100644 --- a/res/e3a/equipment.xml +++ b/res/e3a/equipment.xml @@ -1,78 +1,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 94fcef2fac2146cb19b30a4fdd8bbc73d3be8d05 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 19:32:03 +0100 Subject: [PATCH 053/271] the locales module is deprecated. let's do this in custom.lua from now on. --- scripts/eressea/e2/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/eressea/e2/init.lua b/scripts/eressea/e2/init.lua index ed996c395..722078741 100644 --- a/scripts/eressea/e2/init.lua +++ b/scripts/eressea/e2/init.lua @@ -11,7 +11,7 @@ return { require('eressea.tunnels'), require('eressea.ponnuki'), require('eressea.astral'), - require('eressea.locales'), +-- require('eressea.locales'), require('eressea.jsreport'), require('eressea.ents'), require('eressea.cursed') From 9ccaab6516cbec55f6bff76fcce2be586994ff5d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 20:19:32 +0100 Subject: [PATCH 054/271] Korrekte Email-Subject und Adresse, auch im NR. Eliminate crufty per-game strings. --- conf/e2/config.xml | 12 ------------ conf/e3/config.xml | 12 ------------ conf/e4/config.xml | 12 ------------ res/core/de/strings.xml | 6 ++++++ res/core/messages.xml | 10 ++++++++++ src/creport.c | 4 +--- src/kernel/config.c | 17 +++++++++++++++-- src/kernel/config.h | 1 + src/kernel/config.test.c | 2 ++ src/report.c | 17 +++++++++++------ src/reports.c | 7 +++++++ src/reports.h | 1 + 12 files changed, 54 insertions(+), 47 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 8389ba470..56c622d04 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -52,16 +52,4 @@ - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA 2 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. - Remember to send your orders to - eressea-server@eressea.kn-bremen.de with the subject ERESSEA 2 ORDERS. - - - ERESSEA 2 BEFEHLE - ERESSEA 2 ORDERS - - diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 35716f332..ac05d5a5a 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -36,16 +36,4 @@ - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA 3 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. - Remember to send your orders to - eressea-server@eressea.kn-bremen.de with the subject E3 ORDERS. - - - ERESSEA 3 BEFEHLE - ERESSEA 3 ORDERS - - diff --git a/conf/e4/config.xml b/conf/e4/config.xml index ac962202c..f9ede1a27 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -36,16 +36,4 @@ - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA 4 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. - Remember to send your orders to - eressea-server@eressea.kn-bremen.de with the subject ERESSEA 4 ORDERS. - - - ERESSEA 4 BEFEHLE - ERESSEA 4 ORDERS - - diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index b23d44ffb..7d31fc678 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -6,6 +6,12 @@ _x: preposition (15 /Schlumpf/schwerter) _a: including article (ein Schlumpf, a smurf) --> + + + BEFEHLE + ORDERS + + Wirbel vortex diff --git a/res/core/messages.xml b/res/core/messages.xml index 130b58d03..6892ec4e5 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1,5 +1,15 @@ + + + + + + Bitte denke daran, deine Befehle mit dem Betreff + $subject an $email zu senden. + Remember to send your orders to + $email with the subject ${subject}. + diff --git a/src/creport.c b/src/creport.c index 34cff9de3..e8e401190 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1510,9 +1510,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) fprintf(F, "%d;Zeitalter\n", era); fprintf(F, "\"%s\";Build\n", eressea_version()); if (mailto != NULL) { - // char mailcmd[64]; - // snprintf(mailcmd, sizeof(mailcmd), "%s %d, %s", game_name(), game_id(), LOC(f->locale, "mailcmd")); - const char * mailcmd = LOC(f->locale, "mailcmd"); + const char * mailcmd = get_mailcmd(f->locale); fprintf(F, "\"%s\";mailto\n", mailto); fprintf(F, "\"%s\";mailcmd\n", mailcmd); } diff --git a/src/kernel/config.c b/src/kernel/config.c index 88130056b..80a78df36 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -803,12 +803,25 @@ void free_gamedata(void) } } -const char * game_name(void) { +const char * game_name(void) +{ const char * param = config_get("game.name"); return param ? param : global.gamename; } +const char * game_name_upper(void) +{ + static char result[32]; // FIXME: static result + char *r = result; + const char *param = game_name(); + const char *c = param; + while (*c && (r-result)age <= 2) { - const char *s; - s = locale_getstring(f->locale, "newbie_info_game"); - if (s) { - newline(out); - centre(out, s, true); + const char *email; + const char *subject; + email = config_get("game.email"); + subject = get_mailcmd(f->locale); + m = msg_message("newbie_info_game", "email subject", email, subject); + if (m) { + nr_render(m, f->locale, buf, sizeof(buf), f); + msg_release(m); + centre(out, buf, true); } if ((f->options & want(O_COMPUTER)) == 0) { - f->options |= want(O_COMPUTER); + const char *s; s = locale_getstring(f->locale, "newbie_info_cr"); if (s) { newline(out); centre(out, s, true); } + f->options |= want(O_COMPUTER); } } newline(out); diff --git a/src/reports.c b/src/reports.c index 0da8aed94..c6df944a3 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1945,6 +1945,13 @@ static void eval_regions(struct opstack **stack, const void *userdata) opush(stack, var); } +const char *get_mailcmd(const struct locale *loc) +{ + static char result[64]; // FIXME: static return buffer + snprintf(result, sizeof(result), "%s %d %s", game_name_upper(), game_id(), LOC(loc, "mailcmd")); + return result; +} + static void eval_trail(struct opstack **stack, const void *userdata) { /* order -> string */ const faction *report = (const faction *)userdata; diff --git a/src/reports.h b/src/reports.h index 99dd7ebf6..cc197bed4 100644 --- a/src/reports.h +++ b/src/reports.h @@ -129,6 +129,7 @@ extern "C" { int stream_printf(struct stream * out, const char *format, ...); int count_travelthru(struct region *r, const struct faction *f); + const char *get_mailcmd(const struct locale *loc); #define GR_PLURAL 0x01 /* grammar: plural */ #define MAX_INVENTORY 128 /* maimum number of different items in an inventory */ From 30665f874a23f2c02b89096d27a3a58e21061839 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 20:32:54 +0100 Subject: [PATCH 055/271] fix game_name, remove it from rules --- conf/e2/config.json | 2 -- conf/e3/config.json | 2 -- conf/e4/config.json | 2 -- res/core/de/strings.xml | 2 -- src/kernel/config.c | 2 +- 5 files changed, 1 insertion(+), 9 deletions(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index ce823a33d..ca157f501 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -8,8 +8,6 @@ "jsreport" ], "settings": { - "game.id": 2, - "game.name": "Eressea", "orders.default": "work", "NewbieImmunity": 8, "modules.wormholes": true, diff --git a/conf/e3/config.json b/conf/e3/config.json index 30bc7e599..fd533070e 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -25,8 +25,6 @@ "jsreport" ], "settings": { - "game.id": 3, - "game.name": "E3", "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, diff --git a/conf/e4/config.json b/conf/e4/config.json index cbe273af6..91961258a 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -25,8 +25,6 @@ "jsreport" ], "settings": { - "game.id": 4, - "game.name": "Deveron", "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 7d31fc678..bccfdd165 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -6,12 +6,10 @@ _x: preposition (15 /Schlumpf/schwerter) _a: including article (ein Schlumpf, a smurf) --> - BEFEHLE ORDERS - Wirbel vortex diff --git a/src/kernel/config.c b/src/kernel/config.c index 80a78df36..403c80050 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -815,7 +815,7 @@ const char * game_name_upper(void) char *r = result; const char *param = game_name(); const char *c = param; - while (*c && (r-result)r) { *r++ = (char)toupper(*c++); } *r = '\0'; From 3a07d43321c12958d4d4a73cbfe11de3054aa18f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 21:02:15 +0100 Subject: [PATCH 056/271] specify a game id, because there is one in the data --- tests/eressea.ini | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/eressea.ini b/tests/eressea.ini index e84171d45..faf4b1b9e 100644 --- a/tests/eressea.ini +++ b/tests/eressea.ini @@ -1,10 +1,8 @@ -[eressea] -base = . -report = reports +[game] +name = Eressea +id = 2 +email = eressea-server@kn-bremen.de verbose = 0 -lomem = 0 -debug = 0 -memcheck = 0 locales = de,en [lua] From 23d1355fa1f871a2e23f1272c0f97e43a65e41de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 09:22:29 +0100 Subject: [PATCH 057/271] FACTION and PARTEI should both start orders. --- src/kernel/save.c | 24 ++++++++++++++++++++++-- tests/orders.184 | 5 +++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 5b5a5898f..402ffac8d 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -252,6 +252,26 @@ static faction *factionorders(void) return f; } +static param_t next_param(const char *s, const struct locale *lang) { + param_t p; + if (!s || s[0] == '@') { + return NOPARAM; + } + p = findparam(s, lang); + if (p==NOPARAM) { + const struct locale *loc; + for (loc=locales;loc;loc=nextlocale(loc)) { + if (loc!=lang) { + p = findparam(s, lang); + if (p==P_FACTION || p==P_GAMENAME) { + break; + } + } + } + } + return p; +} + int readorders(const char *filename) { FILE *F = NULL; @@ -279,7 +299,7 @@ int readorders(const char *filename) const char *s; init_tokens_str(b); s = gettoken(token, sizeof(token)); - p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM; + p = next_param(s, lang); switch (p) { case P_GAMENAME: case P_FACTION: @@ -308,7 +328,7 @@ int readorders(const char *filename) p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM; } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); - } + } break; /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue diff --git a/tests/orders.184 b/tests/orders.184 index 980993481..315c180d5 100644 --- a/tests/orders.184 +++ b/tests/orders.184 @@ -1,4 +1,4 @@ -ERESSEA 6rLo "6rLo" +PARTEI 6rLo "6rLo" EINHEIT 7Lgf NACH NW NW NAECHSTER @@ -6,7 +6,8 @@ ERESSEA w86y "w86y" EINHEIT uc3u STIRB "mrqa" NAECHSTER -ERESSEA ngij "ngij" + +FACTION ngij "ngij" EINHEIT iwbz HELFE w86y ALLES EINHEIT j536 From e19f0ad381def077d6550c2c3f68e14061f102cd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 10:47:49 +0100 Subject: [PATCH 058/271] issue #633: parse FACTION/PARTEI in any language. added a test since the first fix did not work. --- src/kernel/config.c | 21 +++++++++++++++++++++ src/kernel/config.h | 1 + src/kernel/config.test.c | 24 ++++++++++++++++++++++++ src/kernel/save.c | 22 +--------------------- src/util/language.c | 7 ++++--- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 403c80050..acf762638 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -214,6 +214,27 @@ param_t findparam(const char *s, const struct locale * lang) return result; } +param_t findparam_block(const char *s, const struct locale *lang, bool any_locale) +{ + param_t p; + if (!s || s[0] == '@') { + return NOPARAM; + } + p = findparam(s, lang); + if (any_locale && p==NOPARAM) { + const struct locale *loc; + for (loc=locales;loc;loc=nextlocale(loc)) { + if (loc!=lang) { + p = findparam(s, loc); + if (p==P_FACTION || p==P_GAMENAME) { + break; + } + } + } + } + return p; +} + param_t findparam_ex(const char *s, const struct locale * lang) { param_t result = findparam(s, lang); diff --git a/src/kernel/config.h b/src/kernel/config.h index 43189400c..b51ba2725 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -45,6 +45,7 @@ extern "C" { int findoption(const char *s, const struct locale *lang); param_t findparam(const char *s, const struct locale *lang); + param_t findparam_block(const char *s, const struct locale *lang, bool any_locale); param_t findparam_ex(const char *s, const struct locale * lang); bool isparam(const char *s, const struct locale * lang, param_t param); param_t getparam(const struct locale *lang); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index ca362d6a1..72b2387ac 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -251,9 +251,33 @@ static void test_config_inifile(CuTest *tc) { test_cleanup(); } +static void test_findparam(CuTest *tc) { + struct locale *en, *de; + test_setup(); + en = get_or_create_locale("en"); + locale_setstring(en, parameters[P_FACTION], "FACTION"); + CuAssertIntEquals(tc, NOPARAM, findparam("FACTION", en)); + init_parameters(en); + CuAssertIntEquals(tc, P_FACTION, findparam("FACTION", en)); + de = get_or_create_locale("de"); + locale_setstring(de, parameters[P_FACTION], "PARTEI"); + CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", de)); + init_parameters(de); + CuAssertIntEquals(tc, P_FACTION, findparam("PARTEI", de)); + CuAssertIntEquals(tc, NOPARAM, findparam("HODOR", de)); + + CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", en)); + CuAssertIntEquals(tc, NOPARAM, findparam_block("HODOR", de, false)); + CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", de, true)); + CuAssertIntEquals(tc, NOPARAM, findparam_block("PARTEI", en, false)); + CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", en, true)); + test_cleanup(); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_findparam); SUITE_ADD_TEST(suite, test_config_inifile); SUITE_ADD_TEST(suite, test_config_cache); SUITE_ADD_TEST(suite, test_get_set_param); diff --git a/src/kernel/save.c b/src/kernel/save.c index 402ffac8d..66c680476 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -252,26 +252,6 @@ static faction *factionorders(void) return f; } -static param_t next_param(const char *s, const struct locale *lang) { - param_t p; - if (!s || s[0] == '@') { - return NOPARAM; - } - p = findparam(s, lang); - if (p==NOPARAM) { - const struct locale *loc; - for (loc=locales;loc;loc=nextlocale(loc)) { - if (loc!=lang) { - p = findparam(s, lang); - if (p==P_FACTION || p==P_GAMENAME) { - break; - } - } - } - } - return p; -} - int readorders(const char *filename) { FILE *F = NULL; @@ -299,7 +279,7 @@ int readorders(const char *filename) const char *s; init_tokens_str(b); s = gettoken(token, sizeof(token)); - p = next_param(s, lang); + p = findparam_block(s, lang, true); switch (p) { case P_GAMENAME: case P_FACTION: diff --git a/src/util/language.c b/src/util/language.c index efd5cd5f7..300e69103 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -295,10 +295,11 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ // TODO: swap the name of s and key const char * s = string_cb(i); if (s) { - struct critbit_tree ** cb = (struct critbit_tree **)tokens; const char * key = locale_string(lang, s, false); - if (!key) key = s; - add_translation(cb, key, i); + if (key) { + struct critbit_tree ** cb = (struct critbit_tree **)tokens; + add_translation(cb, key, i); + } } } } From 646e6f7197477787337cccb00165cc962cbfdc27 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 11:13:01 +0100 Subject: [PATCH 059/271] refactor and annotate volcano outbreaks. add configuration options to control volcano behavior. --- src/volcano.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/volcano.c b/src/volcano.c index 60beeaed7..a9a4f0ba7 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -55,7 +55,7 @@ static int nb_armor(const unit * u, int index) if (!(u_race(u)->battle_flags & BF_EQUIPMENT)) return 0; - /* Normale Rüstung */ + /* Normale R�stung */ for (itm = u->items; itm; itm = itm->next) { const armor_type *atype = itm->type->rtype->atype; @@ -169,11 +169,11 @@ static region *rrandneighbour(region * r) for (i = 0; i != MAXDIRECTIONS; i++) { c++; } - /* Zufällig eine auswählen */ + /* Zuf�llig eine ausw�hlen */ rr = rng_int() % c; - /* Durchzählen */ + /* Durchz�hlen */ c = -1; for (i = 0; i != MAXDIRECTIONS; i++) { @@ -204,7 +204,7 @@ volcano_destruction(region * volcano, region * r, const char *damage) else { /* Produktion vierteln ... */ a->data.sa[0] = (short)percent; - /* Für 6-17 Runden */ + /* F�r 6-17 Runden */ a->data.sa[1] = (short)(a->data.sa[1] + time); } @@ -255,6 +255,14 @@ void volcano_outbreak(region * r, region *rn) } } +static bool stop_smoke_chance(void) { + return rng_int() % 100 < 12; +} + +static bool outbreak_chance(void) { + return rng_int() % 100 < 8; +} + void volcano_update(void) { region *r; @@ -270,13 +278,16 @@ void volcano_update(void) r->terrain = t_volcano; } else { - if (rng_int() % 100 < 12) { + if (stop_smoke_chance()) { ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r)); r->terrain = t_volcano; } - else if (r->uid == 1246051340 || (r->age > 20 && rng_int() % 100 < 8)) { + else if (r->uid == 1246051340 || outbreak_chance()) { + // HACK: a fixed E4-only region-uid in Code. + // FIXME: In E4 gibt es eine Ebene #1246051340, die Smalland heisst. + // da das kein aktiver Vulkan ist, ist dieser Test da nicht idiotisch? + // das sollte bestimmt rn betreffen? region *rn; - /* Zufällige Nachbarregion verwüsten */ rn = rrandneighbour(r); volcano_outbreak(r, rn); r->terrain = t_volcano; From 6d9d920f81ed39f7a37cfef560782f48b8ea1252 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 11:44:34 +0100 Subject: [PATCH 060/271] fix issue #477 (intermittent volcano) --- scripts/tests/xmas.lua | 2 ++ src/volcano.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 7ac4ce731..5477e08ab 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -8,6 +8,8 @@ function setup() eressea.settings.set("rules.grow.formula", "0") eressea.settings.set("rules.peasants.growth.factor", "0") eressea.settings.set("volcano.active.percent", "0") + eressea.settings.set("volcano.outbreak.percent", "0") + eressea.settings.set("volcano.stop.percent", "0") end function test_snowglobe_fail() diff --git a/src/volcano.c b/src/volcano.c index a9a4f0ba7..89a865017 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -256,11 +256,19 @@ void volcano_outbreak(region * r, region *rn) } static bool stop_smoke_chance(void) { - return rng_int() % 100 < 12; + static int cache, percent = 0; + if (config_changed(&cache)) { + percent = config_get_int("volcano.stop.percent", 12); + } + return percent!=0 && (rng_int() % 100) < percent; } static bool outbreak_chance(void) { - return rng_int() % 100 < 8; + static int cache, percent = 0; + if (config_changed(&cache)) { + percent = config_get_int("volcano.outbreak.percent", 8); + } + return percent!=0 && (rng_int() % 100) < percent; } void volcano_update(void) From 99274e3ab16e4e514dd926618d2b80911f0177dd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 21:35:01 +0100 Subject: [PATCH 061/271] make runtests.bat not crash. disable auto-load of config.lua (sob). free messages and config in config.reset(). --- scripts/tests/laws.lua | 2 ++ src/bind_config.c | 3 +++ src/bindings.c | 2 +- src/laws.c | 3 ++- src/util/nrmessage.c | 13 +++++++++++++ src/util/nrmessage.h | 16 +++++++++------- src/util/nrmessage_struct.h | 4 ++-- 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index f0fef15a9..6f41fc54b 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -95,6 +95,7 @@ function test_force_leave_postcombat() u1.building = b1 u2.building = b1 eressea.settings.set("rules.owners.force_leave", "1") + eressea.settings.set("NewbieImmunity", "0") u1:clear_orders() u1:add_order("ATTACKIERE " .. itoa36(u2.id)) u2:clear_orders() @@ -109,6 +110,7 @@ function test_force_leave_postcombat() end end assert_not_equal(nil, u3) + assert_equal(nil, u2.building) assert_equal(nil, u3.building) assert_equal(1, u3.number) end diff --git a/src/bind_config.c b/src/bind_config.c index 929e4cca0..faf543f47 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,9 @@ void config_reset(void) { default_locale = 0; + free_config(); free_locales(); + free_nrmesssages(); free_spells(); free_buildingtypes(); free_shiptypes(); diff --git a/src/bindings.c b/src/bindings.c index b6be1ccba..80021f01e 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1190,7 +1190,7 @@ int eressea_run(lua_State *L, const char *luafile) lua_remove(L, -2); /* try to run configuration scripts: */ - err = run_script(L, "config.lua"); + // err = run_script(L, "config.lua"); err = run_script(L, "custom.lua"); /* run the main script */ diff --git a/src/laws.c b/src/laws.c index 112d15fd2..62ec2665d 100644 --- a/src/laws.c +++ b/src/laws.c @@ -119,7 +119,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. int NewbieImmunity(void) { - return config_get_int("NewbieImmunity", 0); + int result = config_get_int("NewbieImmunity", 0); + return result; } bool IsImmune(const faction * f) diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index 8156b9784..717c4dc1f 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -178,3 +178,16 @@ const char *nrt_section(const nrmessage_type * nrt) { return nrt ? nrt->section : NULL; } + +void free_nrmesssages(void) { + int i; + for (i = 0; i != NRT_MAXHASH; ++i) { + while (nrtypes[i]) { + nrmessage_type *nr = nrtypes[i]; + nrtypes[i] = nr->next; + free(nr->string); + free(nr->vars); + free(nr); + } + } +} diff --git a/src/util/nrmessage.h b/src/util/nrmessage.h index 122b1f1a8..6cc02bfe2 100644 --- a/src/util/nrmessage.h +++ b/src/util/nrmessage.h @@ -31,18 +31,20 @@ extern "C" { extern nrsection *sections; - extern void nrt_register(const struct message_type *mtype, + void free_nrmesssages(void); + + void nrt_register(const struct message_type *mtype, const struct locale *lang, const char *script, int level, const char *section); - extern struct nrmessage_type *nrt_find(const struct locale *, + struct nrmessage_type *nrt_find(const struct locale *, const struct message_type *); - extern const char *nrt_string(const struct nrmessage_type *type); - extern const char *nrt_section(const struct nrmessage_type *mt); + const char *nrt_string(const struct nrmessage_type *type); + const char *nrt_section(const struct nrmessage_type *mt); - extern size_t nr_render(const struct message *msg, const struct locale *lang, + size_t nr_render(const struct message *msg, const struct locale *lang, char *buffer, size_t size, const void *userdata); - extern int nr_level(const struct message *msg); - extern const char *nr_section(const struct message *msg); + int nr_level(const struct message *msg); + const char *nr_section(const struct message *msg); /* before: * fogblock;movement:0;de;{unit} konnte von {region} nicht nach {$dir direction} ausreisen, der Nebel war zu dicht. diff --git a/src/util/nrmessage_struct.h b/src/util/nrmessage_struct.h index 6a3a1d9b0..57f8e644d 100644 --- a/src/util/nrmessage_struct.h +++ b/src/util/nrmessage_struct.h @@ -8,8 +8,8 @@ typedef struct nrmessage_type { const struct message_type *mtype; const struct locale *lang; - const char *string; - const char *vars; + char *string; + char *vars; struct nrmessage_type *next; int level; const char *section; From 404ac546faced49442cd75404ac3cbedf51b4431 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 24 Jan 2017 10:36:27 +0100 Subject: [PATCH 062/271] BUG 2273: runtests.bat fails when config is auto-loaded. run rules tests with the correct configuration, ignore .ini file setting. still not enabling auto-load again, use custom.lua instead. --- scripts/tests/e3/castles.lua | 2 +- tests/runtests.bat | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index 1fd4e13e9..df395ed3d 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -46,7 +46,7 @@ end function test_build_packice() local r = region.create(0, 0, "packice") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("packice@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:clear_orders() u:add_item("stone", 10) diff --git a/tests/runtests.bat b/tests/runtests.bat index e79d27baa..996fb47b7 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -6,9 +6,9 @@ IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug SET SERVER=%BUILD%\eressea.exe %BUILD%\test_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 +%SERVER% -re2 ..\scripts\run-tests-e2.lua +%SERVER% -re3 ..\scripts\run-tests-e3.lua +%SERVER% -re4 ..\scripts\run-tests-e4.lua PAUSE RMDIR /s /q reports DEL score score.alliances datum turn From b170a30faa13acc20d40af97d9b5e5c90b58f7ea Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 18:17:19 +0100 Subject: [PATCH 063/271] add a function to compare size of occupied castles --- src/kernel/building.c | 13 ++++++++++++- src/kernel/building.h | 2 ++ src/kernel/building.test.c | 26 ++++++++++++++++++++++++++ src/kernel/region.c | 14 +++++++++++--- src/kernel/region.test.c | 25 +++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index fa7fe8688..9f6a8a421 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -335,7 +335,18 @@ const building_type *findbuildingtype(const char *name, return (const building_type *)type.v; } -static int building_protection(const building * b, const unit * u, building_bonus bonus) +int cmp_castle_size(const building * b, const building * a) +{ + if (!b || !b->type->protection || !building_owner(b)) { + return -1; + } + if (!a || !a->type->protection || !building_owner(a)) { + return 1; + } + return b->size - a->size; +} + +int building_protection(const building * b, const unit * u, building_bonus bonus) { int i = 0; int bsize = buildingeffsize(b, false); diff --git a/src/kernel/building.h b/src/kernel/building.h index 235c2d806..673675348 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -85,6 +85,8 @@ extern "C" { extern struct quicklist *buildingtypes; extern struct attrib_type at_building_action; + int cmp_castle_size(const struct building * b, const struct building * a); + int building_protection(const struct building * b, const struct unit * u, building_bonus bonus); building_type *bt_get_or_create(const char *name); bool bt_changed(int *cache); const building_type *bt_find(const char *name); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 3b296a6fe..89e2b978c 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -493,9 +493,35 @@ static void test_building_type(CuTest *tc) { test_cleanup(); } +static void test_cmp_castle_size(CuTest *tc) { + region *r; + building *b1, *b2; + building_type *bt_castle; + unit *u1, *u2; + + test_setup(); + bt_castle = test_create_buildingtype("castle"); + bt_castle->protection = building_protection; + r = test_create_region(0, 0, 0); + b1 = test_create_building(r, bt_castle); + b2 = test_create_building(r, bt_castle); + u1 = test_create_unit(test_create_faction(0), r); + u_set_building(u1, b1); + u2 = test_create_unit(test_create_faction(0), r); + u_set_building(u2, b2); + b1->size = 5; + b2->size = 10; + CuAssertTrue(tc, cmp_castle_size(b1, b2)<0); + CuAssertTrue(tc, cmp_castle_size(b2, b1)>0); + CuAssertTrue(tc, cmp_castle_size(b1, NULL)>0); + CuAssertTrue(tc, cmp_castle_size(NULL, b1)<0); + test_cleanup(); +} + CuSuite *get_building_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_cmp_castle_size); SUITE_ADD_TEST(suite, test_register_building); SUITE_ADD_TEST(suite, test_btype_defaults); SUITE_ADD_TEST(suite, test_building_set_owner); diff --git a/src/kernel/region.c b/src/kernel/region.c index cade135c7..06d2d9d7c 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1324,9 +1324,17 @@ struct message *msg) struct faction *region_get_owner(const struct region *r) { - assert(rule_region_owners()); - if (r->land && r->land->ownership) { - return r->land->ownership->owner; + if (r->land) { + if (rule_region_owners()) { + if (r->land->ownership) { + return r->land->ownership->owner; + } + } + else { + building *b = largestbuilding(r, cmp_castle_size, false); + unit * u = b ? building_owner(b) : NULL; + return u ? u->faction : NULL; + } } return NULL; } diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c index 01ecae2a8..8cf08a62c 100644 --- a/src/kernel/region.test.c +++ b/src/kernel/region.test.c @@ -1,6 +1,8 @@ #include #include "region.h" +#include "building.h" +#include "unit.h" #include "terrain.h" #include "item.h" @@ -31,9 +33,32 @@ void test_terraform(CuTest *tc) { test_cleanup(); } +static void test_region_get_owner(CuTest *tc) { + region *r; + building *b1, *b2; + building_type *bt_castle; + unit *u1, *u2; + + test_setup(); + bt_castle = test_create_buildingtype("castle"); + bt_castle->protection = building_protection; + r = test_create_region(0, 0, 0); + b1 = test_create_building(r, bt_castle); + b2 = test_create_building(r, bt_castle); + b1->size = 5; + b2->size = 10; + u1 = test_create_unit(test_create_faction(0), r); + u_set_building(u1, b1); + u2 = test_create_unit(test_create_faction(0), r); + u_set_building(u2, b2); + CuAssertPtrEquals(tc, u2->faction, region_get_owner(r)); + test_cleanup(); +} + CuSuite *get_region_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_terraform); + SUITE_ADD_TEST(suite, test_region_get_owner); return suite; } From 77cbd04cfac763fc1a4793c6ab6b07a450ce822d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 20:57:54 +0100 Subject: [PATCH 064/271] BENENNE REGION ist jeder Einheit des Regionsbesitzers erlaubt --- src/kernel/building.test.c | 7 ++----- src/kernel/config.c | 2 +- src/kernel/region.test.c | 7 ++----- src/laws.c | 11 +---------- src/laws.test.c | 39 +++++++++++++++++++++++++++++++++----- src/tests.c | 9 +++++++-- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 89e2b978c..e02d16556 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -496,15 +496,12 @@ static void test_building_type(CuTest *tc) { static void test_cmp_castle_size(CuTest *tc) { region *r; building *b1, *b2; - building_type *bt_castle; unit *u1, *u2; test_setup(); - bt_castle = test_create_buildingtype("castle"); - bt_castle->protection = building_protection; r = test_create_region(0, 0, 0); - b1 = test_create_building(r, bt_castle); - b2 = test_create_building(r, bt_castle); + b1 = test_create_building(r, NULL); + b2 = test_create_building(r, NULL); u1 = test_create_unit(test_create_faction(0), r); u_set_building(u1, b1); u2 = test_create_unit(test_create_faction(0), r); diff --git a/src/kernel/config.c b/src/kernel/config.c index acf762638..efe66b2f1 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -204,7 +204,7 @@ param_t findparam(const char *s, const struct locale * lang) void **tokens = get_translations(lang, UT_PARAMS); critbit_tree *cb = (critbit_tree *)*tokens; if (!cb) { - log_error("no parameters defined in locale %s", locale_name(lang)); + log_warning("no parameters defined in locale %s", locale_name(lang)); } else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { cb_get_kv(match, &i, sizeof(int)); diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c index 8cf08a62c..892b37a8e 100644 --- a/src/kernel/region.test.c +++ b/src/kernel/region.test.c @@ -36,15 +36,12 @@ void test_terraform(CuTest *tc) { static void test_region_get_owner(CuTest *tc) { region *r; building *b1, *b2; - building_type *bt_castle; unit *u1, *u2; test_setup(); - bt_castle = test_create_buildingtype("castle"); - bt_castle->protection = building_protection; r = test_create_region(0, 0, 0); - b1 = test_create_building(r, bt_castle); - b2 = test_create_building(r, bt_castle); + b1 = test_create_building(r, NULL); + b2 = test_create_building(r, NULL); b1->size = 5; b2->size = 10; u1 = test_create_unit(test_create_faction(0), r); diff --git a/src/laws.c b/src/laws.c index 62ec2665d..59bf9efc8 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1892,16 +1892,7 @@ int name_cmd(struct unit *u, struct order *ord) break; case P_REGION: - if (!b) { - cmistake(u, ord, 145, MSG_EVENT); - break; - } - if (building_owner(b) != u) { - cmistake(u, ord, 148, MSG_EVENT); - break; - } - - if (b != largestbuilding(r, get_cmp_region_owner(), false)) { + if (u->faction != region_get_owner(r)) { cmistake(u, ord, 147, MSG_EVENT); break; } diff --git a/src/laws.test.c b/src/laws.test.c index d4753ec19..67a9bb810 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -812,10 +812,7 @@ static void test_name_region(CuTest *tc) { f = u->faction; ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); - name_cmd(u, ord); - CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error145")); - - u->building = test_create_building(u->region, 0); + u_set_building(u, test_create_building(u->region, 0)); name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->region->land->name); free_order(ord); @@ -1060,7 +1057,7 @@ static void test_name_cmd(CuTest *tc) { free_order(ord); ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_BUILDING])); - u->building = test_create_building(u->region, 0); + u_set_building(u, test_create_building(u->region, 0)); name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->building->name); free_order(ord); @@ -1073,6 +1070,37 @@ static void test_name_cmd(CuTest *tc) { test_cleanup(); } +static void test_name_cmd_2274(CuTest *tc) { + unit *u1, *u2, *u3; + faction *f; + region *r; + + test_setup(); + r = test_create_region(0, 0, 0); + u1 = test_create_unit(test_create_faction(0), r); + u2 = test_create_unit(test_create_faction(0), r); + u3 = test_create_unit(u2->faction, r); + u_set_building(u1, test_create_building(r, NULL)); + u1->building->size = 10; + u_set_building(u2, test_create_building(r, NULL)); + u2->building->size = 20; + + f = u2->faction; + u2->thisorder = create_order(K_NAME, f->locale, "%s Heimat", LOC(f->locale, parameters[P_REGION])); + name_cmd(u2, u2->thisorder); + CuAssertStrEquals(tc, "Heimat", r->land->name); + f = u3->faction; + u3->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); + name_cmd(u3, u3->thisorder); + CuAssertStrEquals(tc, "Hodor", r->land->name); + f = u1->faction; + u1->thisorder = create_order(K_NAME, f->locale, "%s notallowed", LOC(f->locale, parameters[P_REGION])); + name_cmd(u1, u1->thisorder); + CuAssertStrEquals(tc, "Hodor", r->land->name); + + test_cleanup(); +} + static void test_ally_cmd(CuTest *tc) { unit *u; faction * f; @@ -1481,6 +1509,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_name_cmd); + SUITE_ADD_TEST(suite, test_name_cmd_2274); SUITE_ADD_TEST(suite, test_ally_cmd_errors); SUITE_ADD_TEST(suite, test_long_order_normal); SUITE_ADD_TEST(suite, test_long_order_none); diff --git a/src/tests.c b/src/tests.c index 15ae677fe..eb2631afe 100644 --- a/src/tests.c +++ b/src/tests.c @@ -225,8 +225,13 @@ building * test_create_building(region * r, const building_type * btype) { building * b; assert(r); - b = new_building(btype ? btype : test_create_buildingtype("castle"), r, default_locale); - b->size = b->type->maxsize > 0 ? b->type->maxsize : 1; + if (!btype) { + building_type *bt_castle = test_create_buildingtype("castle"); + bt_castle->protection = building_protection; + btype = bt_castle; + } + b = new_building(btype, r, default_locale); + b->size = btype->maxsize > 0 ? btype->maxsize : 1; return b; } From 30fc6f3e919b2ebfc31af6480d63b24b24e6cdeb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 21:03:08 +0100 Subject: [PATCH 065/271] BESCHREIBE REGION ist jeder Einheit des Regionsbesitzers erlaubt --- src/laws.c | 20 +------------------- src/laws.test.c | 5 +++++ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/laws.c b/src/laws.c index 59bf9efc8..b99b2d3f2 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1538,16 +1538,6 @@ int prefix_cmd(unit * u, struct order *ord) return 0; } -static cmp_building_cb get_cmp_region_owner(void) -{ - if (rule_region_owners()) { - return &cmp_current_owner; - } - else { - return &cmp_wage; - } -} - int display_cmd(unit * u, struct order *ord) { char token[128]; @@ -1597,15 +1587,7 @@ int display_cmd(unit * u, struct order *ord) break; case P_REGION: - if (!u->building) { - cmistake(u, ord, 145, MSG_EVENT); - break; - } - if (building_owner(u->building) != u) { - cmistake(u, ord, 148, MSG_EVENT); - break; - } - if (u->building != largestbuilding(r, get_cmp_region_owner(), false)) { + if (u->faction != region_get_owner(r)) { cmistake(u, ord, 147, MSG_EVENT); break; } diff --git a/src/laws.test.c b/src/laws.test.c index 67a9bb810..5eb742809 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -229,6 +229,11 @@ static void test_display_cmd(CuTest *tc) { CuAssertPtrEquals(tc, NULL, u->display); free_order(ord); + ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); + CuAssertIntEquals(tc, 0, display_cmd(u, ord)); + CuAssertPtrEquals(tc, NULL, r->display); + free_order(ord); + test_cleanup(); } From 78e43bd62e0e8bc9bf29eff0a2e1faa714c506db Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 21:26:30 +0100 Subject: [PATCH 066/271] hack compress to not use /home/enno/bin script --- process/compress.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/compress.sh b/process/compress.sh index ff152b9f1..e50cf1940 100755 --- a/process/compress.sh +++ b/process/compress.sh @@ -20,5 +20,5 @@ if [ ! -d $GAME/reports ]; then fi cd $GAME/reports -$HOME/bin/compress.py $TURN "$GAME_NAME" +$ERESSEA/server/bin/compress.py $TURN "$GAME_NAME" cd - From 955997d58c66cd21775f6b99573cd9c76a69ea8a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 06:00:01 +0100 Subject: [PATCH 067/271] WIP: use latest clibs with selist. adding a transitional quicklist.c module to reduce work. --- clibs | 2 +- src/CMakeLists.txt | 1 + src/donations.c | 4 ++-- src/quicklist.c | 4 ++++ src/quicklist.h | 14 ++++++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/quicklist.c create mode 100644 src/quicklist.h diff --git a/clibs b/clibs index bce9b6568..339ac5680 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit bce9b6568d4e9ace26c95a7740140cd71029b21f +Subproject commit 339ac5680ec9027c88c4516c72b9da8233b6f3e3 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea76d4dbb..06af86c8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,6 +88,7 @@ set (ERESSEA_SRC move.c piracy.c spells.c + quicklist.c battle.c alchemy.c academy.c diff --git a/src/donations.c b/src/donations.c index 8f820df2b..c6e4308ac 100644 --- a/src/donations.c +++ b/src/donations.c @@ -54,8 +54,8 @@ void add_donation(faction * f1, faction * f2, int amount, region * r) } void free_donations(void) { - ql_foreach(transfers, free); - ql_free(transfers); + selist_foreach(transfers, free); + selist_free(transfers); transfers = 0; } diff --git a/src/quicklist.c b/src/quicklist.c new file mode 100644 index 000000000..75d7b8641 --- /dev/null +++ b/src/quicklist.c @@ -0,0 +1,4 @@ +#include "quicklist.h" + +bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); +bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); diff --git a/src/quicklist.h b/src/quicklist.h new file mode 100644 index 000000000..fe2f26991 --- /dev/null +++ b/src/quicklist.h @@ -0,0 +1,14 @@ +#pragma once + +#define selist quicklist +#define selist_free ql_free +#define selist_get ql_get +#define selist_push ql_push +#define selist_empty ql_empty +#define selist_advance ql_advance +#include +#include + +typedef void(*ql_cb)(void *); +bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); +bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); From d9213c8f253decc10ea788569bd6365f8ad5d932 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 10:12:12 +0100 Subject: [PATCH 068/271] WIP: still converting to clibs/selist --- clibs | 2 +- src/donations.c | 24 ++++++++++-------------- src/kernel/curse.c | 2 +- src/kernel/spell.c | 2 +- src/quicklist.c | 30 ++++++++++++++++++++++++++++-- src/quicklist.h | 5 +++++ src/travelthru.c | 28 ++++++++++++++++++++-------- src/util/message.c | 2 +- 8 files changed, 67 insertions(+), 28 deletions(-) diff --git a/clibs b/clibs index 339ac5680..daa9de083 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 339ac5680ec9027c88c4516c72b9da8233b6f3e3 +Subproject commit daa9de08314a75a4d77ef4e08c713088a96a5ca5 diff --git a/src/donations.c b/src/donations.c index c6e4308ac..0b1413a5f 100644 --- a/src/donations.c +++ b/src/donations.c @@ -59,22 +59,18 @@ void free_donations(void) { transfers = 0; } -static void report_transfer(faction *f1, faction *f2, region *r, int amount) { - struct message *msg = msg_message("donation", - "from to amount", f1, f2, amount); - r_addmessage(r, f1, msg); - r_addmessage(r, f2, msg); - msg_release(msg); +static void report_transfer(void *data) { + transfer *tf = (transfer *)data; + if (tf->amount > 0) { + struct message *msg = msg_message("donation", + "from to amount", tf->f1, tf->f2, tf->amount); + r_addmessage(tf->r, tf->f1, msg); + r_addmessage(tf->r, tf->f2, msg); + msg_release(msg); + } } void report_donations(void) { - ql_iter qli = qli_init(&transfers); - - while (qli_more(qli)) { - transfer *tf = (transfer *)qli_next(&qli); - if (tf->amount > 0) { - report_transfer(tf->f1, tf->f2, tf->r, tf->amount); - } - } + selist_foreach(transfers, report_transfer); } diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 123f858f5..5e2086476 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -308,7 +308,7 @@ void ct_register(const curse_type * ct) unsigned int hash = tolower(ct->cname[0]) & 0xFF; quicklist **ctlp = cursetypes + hash; - ql_set_insert(ctlp, (void *)ct); + selist_set_insert(ctlp, (void *)ct, NULL); ++ct_changes; } diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 8e14ec2c0..2644f341f 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -57,7 +57,7 @@ void free_spells(void) { void add_spell(struct quicklist **slistp, spell * sp) { - if (!ql_set_insert(slistp, sp)) { + if (!selist_set_insert(slistp, sp, NULL)) { log_error("add_spell: the list already contains the spell '%s'.\n", sp->sname); } } diff --git a/src/quicklist.c b/src/quicklist.c index 75d7b8641..2b760019c 100644 --- a/src/quicklist.c +++ b/src/quicklist.c @@ -1,4 +1,30 @@ #include "quicklist.h" +#include -bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); -bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); +bool ql_set_remove(struct quicklist **qlp, const void *data) +{ + int qi, qn; + quicklist *ql = *qlp; + + if (!ql) + return false; + + qn = selist_length(ql); + for (qi = 0; qi != qn; ++qi) { + void *qd = selist_get(ql, qi); + if (qd == data) { + return selist_delete(qlp, qi) == 0; + } + } + return false; +} + +bool ql_set_insert(struct quicklist **qlp, void *data) +{ + return selist_set_insert(qlp, data, NULL); +} + +bool ql_set_find(struct quicklist **qlp, int *qip, const void *data) +{ + return selist_set_find(qlp, qip, data, NULL); +} diff --git a/src/quicklist.h b/src/quicklist.h index fe2f26991..c0446b471 100644 --- a/src/quicklist.h +++ b/src/quicklist.h @@ -2,7 +2,11 @@ #define selist quicklist #define selist_free ql_free +#define selist_delete ql_delete +#define selist_foreach ql_foreach #define selist_get ql_get +#define selist_replace ql_replace +#define selist_length ql_length #define selist_push ql_push #define selist_empty ql_empty #define selist_advance ql_advance @@ -12,3 +16,4 @@ typedef void(*ql_cb)(void *); bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); + diff --git a/src/travelthru.c b/src/travelthru.c index 5e6cac41b..04ca6cee5 100644 --- a/src/travelthru.c +++ b/src/travelthru.c @@ -99,18 +99,30 @@ bool travelthru_cansee(const struct region *r, const struct faction *f, const st return false; } -void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *cbdata) +struct cb_data { + void(*call)(region *, struct unit *, void *); + void *data; + struct region *r; +}; + +void cb_map(void *data, void *ex) { + struct cb_data *cb = (struct cb_data *)ex; + struct unit *u = (struct unit *)data; + cb->call(cb->r, u, cb->data); +} + +void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *data) { attrib *a; + struct cb_data cbdata; + assert(r); + cbdata.call = cb; + cbdata.data = data; + cbdata.r = r; a = a_find(r->attribs, &at_travelunit); if (a) { - quicklist *ql; - ql_iter qi; - ql = (quicklist *)a->data.v; - for (qi = qli_init(&ql); qli_more(qi);) { - unit *u = (unit *)qli_next(&qi); - cb(r, u, cbdata); - } + quicklist *ql = (quicklist *)a->data.v; + selist_foreach_ex(ql, cb_map, &cbdata); } } diff --git a/src/util/message.c b/src/util/message.c index f19fc3313..46bfec969 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -215,7 +215,7 @@ const message_type *mt_register(message_type * type) unsigned int hash = hashstring(type->name) % MT_MAXHASH; quicklist **qlp = messagetypes + hash; - if (ql_set_insert(qlp, type)) { + if (selist_set_insert(qlp, type, NULL)) { type->key = mt_id(type); } return type; From 138258310968652cab4a6a7b0da14047902f5597 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 10:15:26 +0100 Subject: [PATCH 069/271] fix compilation (but not linking). --- src/sqlite.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sqlite.c b/src/sqlite.c index 42bfdb3b5..99c72d9ec 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -136,10 +136,12 @@ static void update_faction(sqlite3 *db, const faction *f) { int db_update_factions(sqlite3 * db, bool force, int game_id) { quicklist *ql = read_factions(db, game_id); faction *f; + if (!ql) return SQLITE_OK; sqlite3_exec(db, "BEGIN", 0, 0, 0); for (f = factions; f; f = f->next) { bool update = force; db_faction *dbf = 0; +#ifdef SELIST_TODO ql_iter it = qli_init(&ql); while (qli_more(it)) { db_faction *df = (db_faction*)qli_next(&it); @@ -151,6 +153,7 @@ int db_update_factions(sqlite3 * db, bool force, int game_id) { break; } } +#endif if (dbf) { if (dbf->uid != f->subscription) { log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); From c72b050a4235ea0aa84f0cdc8e67a7704beed06c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 10:53:52 +0100 Subject: [PATCH 070/271] WIP: quicklist->selist shim can compile and link, but tests crash --- src/donations.c | 12 ++++++------ src/quicklist.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/quicklist.h | 19 +++++++++---------- src/reports.c | 2 +- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/donations.c b/src/donations.c index 0b1413a5f..4dee36444 100644 --- a/src/donations.c +++ b/src/donations.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ typedef struct transfer { int amount; } transfer; -static quicklist *transfers = 0; +static selist *transfers = 0; int cmp_transfer(const void *v1, const void *v2) { const transfer *t1 = (const transfer *)v1; @@ -35,22 +35,22 @@ int cmp_transfer(const void *v1, const void *v2) { void add_donation(faction * f1, faction * f2, int amount, region * r) { transfer tr, *tf; - quicklist *ql = transfers; + selist *ql = transfers; int qi = 0; tr.r = r; tr.f1 = f1; tr.f2 = f2; tr.amount = amount; - if (ql_set_find_ex(&ql, &qi, &tr, cmp_transfer)) { - tf = (transfer *)ql_get(ql, qi); + if (selist_set_find(&ql, &qi, &tr, cmp_transfer)) { + tf = (transfer *)selist_get(ql, qi); tf->amount += amount; } else { tf = malloc(sizeof(transfer)); memcpy(tf, &tr, sizeof(transfer)); } - ql_set_insert_ex(&transfers, tf, cmp_transfer); + selist_set_insert(&transfers, tf, cmp_transfer); } void free_donations(void) { diff --git a/src/quicklist.c b/src/quicklist.c index 2b760019c..6fb567a64 100644 --- a/src/quicklist.c +++ b/src/quicklist.c @@ -1,6 +1,51 @@ #include "quicklist.h" #include +void ql_push(struct quicklist **qlp, void *el) +{ + selist_push(qlp, el); +} + +int ql_length(const struct quicklist *ql) +{ + return selist_length(ql); +} + +void * ql_replace(struct quicklist *ql, int index, void *el) +{ + return selist_replace(ql, index, el); +} + +void *ql_get(struct quicklist *ql, int index) +{ + return selist_get(ql, index); +} + +int ql_delete(struct quicklist **qlp, int index) +{ + return selist_delete(qlp, index); +} + +bool ql_empty(const struct quicklist *ql) +{ + return selist_empty(ql); +} + +void ql_foreach(struct quicklist *ql, selist_cb cb) +{ + selist_foreach(ql, cb); +} + +int ql_advance(struct quicklist **qlp, int *index, int stride) +{ + return selist_advance(qlp, index, stride); +} + +void ql_free(struct quicklist *ql) +{ + selist_free(ql); +} + bool ql_set_remove(struct quicklist **qlp, const void *data) { int qi, qn; diff --git a/src/quicklist.h b/src/quicklist.h index c0446b471..f5a85a354 100644 --- a/src/quicklist.h +++ b/src/quicklist.h @@ -1,18 +1,17 @@ #pragma once #define selist quicklist -#define selist_free ql_free -#define selist_delete ql_delete -#define selist_foreach ql_foreach -#define selist_get ql_get -#define selist_replace ql_replace -#define selist_length ql_length -#define selist_push ql_push -#define selist_empty ql_empty -#define selist_advance ql_advance #include -#include +int ql_advance(struct quicklist **qlp, int *index, int stride); +void ql_foreach(struct quicklist *ql, selist_cb cb); +void ql_free(struct quicklist *ql); +int ql_delete(struct quicklist **qlp, int index); +void ql_push(struct quicklist **qlp, void *el); +int ql_length(const struct quicklist *ql); +void * ql_replace(struct quicklist *ql, int index, void *el); +void *ql_get(struct quicklist *ql, int index); +bool ql_empty(const struct quicklist *ql); typedef void(*ql_cb)(void *); bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); diff --git a/src/reports.c b/src/reports.c index a8b9e5cfb..3e139fdda 100644 --- a/src/reports.c +++ b/src/reports.c @@ -989,7 +989,7 @@ int cmp_faction(const void *lhs, const void *rhs) { } static void add_seen_faction_i(struct quicklist **flist, faction *f) { - ql_set_insert_ex(flist, f, cmp_faction); + selist_set_insert(flist, f, cmp_faction); } void add_seen_faction(faction *self, faction *seen) { From 2ace44d385ab00cfb0c5f1d91e1ea719781a9e30 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 16:05:44 +0100 Subject: [PATCH 071/271] fix duplicate cutest library conflict and crash --- .gitmodules | 3 --- CMakeLists.txt | 1 - clibs | 2 +- cutest | 1 - src/CMakeLists.txt | 3 +-- 5 files changed, 2 insertions(+), 8 deletions(-) delete mode 160000 cutest diff --git a/.gitmodules b/.gitmodules index e9ea1e3ed..7dff5ab6a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "dlmalloc"] path = dlmalloc url = https://github.com/ennorehling/dlmalloc.git -[submodule "cutest"] - path = cutest - url = https://github.com/ennorehling/cutest.git [submodule "iniparser"] path = iniparser url = https://github.com/ennorehling/iniparser.git diff --git a/CMakeLists.txt b/CMakeLists.txt index cc7e8173d..f6b931e61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,6 @@ INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include) ## skip compiler/libc detection and force cmake autoconf: #add_definitions(-DUSE_AUTOCONF) -add_subdirectory (cutest) add_subdirectory (cJSON) add_subdirectory (storage) add_subdirectory (iniparser) diff --git a/clibs b/clibs index daa9de083..1052905e0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit daa9de08314a75a4d77ef4e08c713088a96a5ca5 +Subproject commit 1052905e08314de8778750d7585474182723111e diff --git a/cutest b/cutest deleted file mode 160000 index 6e268687d..000000000 --- a/cutest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6e268687dbf6ae55afb63210c3753530d216a622 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 06af86c8b..6eacaae0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,6 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR}) include_directories (${CJSON_INCLUDE_DIR}) include_directories (${CLIBS_INCLUDE_DIR}) include_directories (${STORAGE_INCLUDE_DIR}) -include_directories (${CUTEST_INCLUDE_DIR}) include_directories (${LUA_INCLUDE_DIR}) include_directories (${TOLUA_INCLUDE_DIR}) include_directories (${BSON_INCLUDE_DIR}) @@ -236,7 +235,7 @@ set(TESTS_SRC add_executable(test_eressea ${TESTS_SRC}) target_link_libraries(test_eressea game - ${CUTEST_LIBRARIES} + cutest ${LUA_LIBRARIES} ${CLIBS_LIBRARIES} ${STORAGE_LIBRARIES} From a4badc0a75695d044b8ed5be798a525cab28f0a6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 17:41:21 +0100 Subject: [PATCH 072/271] remove quicklist shim, use selist everywhere --- src/CMakeLists.txt | 1 - src/battle.c | 44 +++++++++++----------- src/battle.h | 12 +++--- src/bind_unit.c | 8 ++-- src/bindings.c | 42 ++++++++++----------- src/bindings.h | 6 +-- src/creport.c | 16 ++++---- src/kernel/alliance.c | 19 +++++----- src/kernel/alliance.h | 3 +- src/kernel/alliance.test.c | 6 +-- src/kernel/building.c | 22 +++++------ src/kernel/building.h | 2 +- src/kernel/connection.c | 12 +++--- src/kernel/curse.c | 28 +++++++------- src/kernel/equipment.c | 14 +++---- src/kernel/equipment.h | 2 +- src/kernel/faction.c | 12 +++--- src/kernel/faction.h | 3 +- src/kernel/faction.test.c | 6 +-- src/kernel/pathfinder.c | 8 ++-- src/kernel/pathfinder.h | 2 +- src/kernel/save.c | 4 +- src/kernel/ship.c | 22 +++++------ src/kernel/ship.h | 2 +- src/kernel/spell.c | 20 +++++----- src/kernel/spell.h | 6 +-- src/kernel/spellbook.c | 30 +++++++-------- src/kernel/spellbook.h | 4 +- src/kernel/types.h | 2 +- src/laws.c | 8 ++-- src/magic.c | 30 +++++++-------- src/magic.h | 4 +- src/magic.test.c | 12 +++--- src/market.c | 16 ++++---- src/modules/autoseed.c | 42 ++++++++++----------- src/monsters.c | 10 ++--- src/quicklist.c | 75 -------------------------------------- src/quicklist.h | 18 --------- src/report.c | 10 ++--- src/reports.c | 53 +++++++++++++-------------- src/reports.h | 8 ++-- src/reports.test.c | 14 +++---- src/spells/combatspells.c | 66 ++++++++++++++++----------------- src/sqlite.c | 20 +++++----- src/travelthru.c | 14 +++---- src/util/message.c | 18 ++++----- src/wormhole.c | 20 +++++----- src/wormhole.test.c | 12 +++--- 48 files changed, 360 insertions(+), 448 deletions(-) delete mode 100644 src/quicklist.c delete mode 100644 src/quicklist.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6eacaae0b..a3f81e1a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,7 +87,6 @@ set (ERESSEA_SRC move.c piracy.c spells.c - quicklist.c battle.c alchemy.c academy.c diff --git a/src/battle.c b/src/battle.c index 7aa3e4cfa..28a08c6f3 100644 --- a/src/battle.c +++ b/src/battle.c @@ -64,7 +64,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -1248,7 +1248,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) rda = 0; else { int qi; - quicklist *ql; + selist *ql; unsigned int i = 0; if (u_race(du)->battle_flags & BF_RES_PIERCE) @@ -1262,8 +1262,8 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) rda /= 2; /* Schilde */ - for (qi = 0, ql = b->meffects; ql; ql_advance(&ql, &qi, 1)) { - meffect *me = (meffect *)ql_get(ql, qi); + for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) { + meffect *me = (meffect *)selist_get(ql, qi); if (meffect_protection(b, me, ds) != 0) { assert(0 <= rda); /* rda sollte hier immer mindestens 0 sein */ /* jeder Schaden wird um effect% reduziert bis der Schild duration @@ -1603,11 +1603,11 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist) return dt; } -quicklist *fighters(battle * b, const side * vs, int minrow, int maxrow, +selist *fighters(battle * b, const side * vs, int minrow, int maxrow, int mask) { side *s; - quicklist *fightervp = 0; + selist *fightervp = 0; assert(vs != NULL); @@ -1629,7 +1629,7 @@ quicklist *fighters(battle * b, const side * vs, int minrow, int maxrow, for (fig = s->fighters; fig; fig = fig->next) { int row = get_unitrow(fig, vs); if (row >= minrow && row <= maxrow) { - ql_push(&fightervp, fig); + selist_push(&fightervp, fig); } } } @@ -1801,7 +1801,7 @@ static void do_combatspell(troop at) unit *caster = fi->unit; battle *b = fi->side->battle; region *r = b->region; - quicklist *ql; + selist *ql; int level, qi; double power; int fumblechance = 0; @@ -1830,8 +1830,8 @@ static void do_combatspell(troop at) return; } - for (qi = 0, ql = b->meffects; ql; ql_advance(&ql, &qi, 1)) { - meffect *mblock = (meffect *)ql_get(ql, qi); + for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) { + meffect *mblock = (meffect *)selist_get(ql, qi); if (mblock->typ == SHIELD_BLOCK) { if (meffect_blocked(b, mblock, fi->side) != 0) { fumblechance += mblock->duration; @@ -2341,11 +2341,11 @@ static void add_tactics(tactics * ta, fighter * fig, int value) if (value == 0 || value < ta->value) return; if (value > ta->value) { - ql_free(ta->fighters); + selist_free(ta->fighters); ta->fighters = 0; } - ql_push(&ta->fighters, fig); - ql_push(&fig->side->battle->leaders, fig); + selist_push(&ta->fighters, fig); + selist_push(&fig->side->battle->leaders, fig); ta->value = value; } @@ -3091,7 +3091,7 @@ static void print_stats(battle * b) b->max_tactics = 0; for (s = b->sides; s != b->sides + b->nsides; ++s) { - if (!ql_empty(s->leader.fighters)) { + if (!selist_empty(s->leader.fighters)) { b->max_tactics = _max(b->max_tactics, s->leader.value); } } @@ -3099,11 +3099,11 @@ static void print_stats(battle * b) if (b->max_tactics > 0) { for (s = b->sides; s != b->sides + b->nsides; ++s) { if (s->leader.value == b->max_tactics) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = s->leader.fighters; ql; ql_advance(&ql, &qi, 1)) { - fighter *tf = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = s->leader.fighters; ql; selist_advance(&ql, &qi, 1)) { + fighter *tf = (fighter *)selist_get(ql, qi); unit *u = tf->unit; message *m = NULL; if (!is_attacker(tf)) { @@ -3599,7 +3599,7 @@ battle *make_battle(region * r) static void free_side(side * si) { - ql_free(si->leader.fighters); + selist_free(si->leader.fighters); } static void free_fighter(fighter * fig) @@ -3647,9 +3647,9 @@ void free_battle(battle * b) free(bf); } - ql_free(b->leaders); - ql_foreach(b->meffects, free); - ql_free(b->meffects); + selist_free(b->leaders); + selist_foreach(b->meffects, free); + selist_free(b->meffects); battle_free(b); } @@ -4242,7 +4242,7 @@ void do_battle(region * r) freset(sh, SF_DAMAGED); /* Gibt es eine Taktikrunde ? */ - if (!ql_empty(b->leaders)) { + if (!selist_empty(b->leaders)) { b->turn = 0; b->has_tactics_turn = true; } diff --git a/src/battle.h b/src/battle.h index 007bda008..cee894b6c 100644 --- a/src/battle.h +++ b/src/battle.h @@ -25,6 +25,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + struct message; + struct selist; + /** more defines **/ #define FS_ENEMY 1 #define FS_HELP 2 @@ -43,7 +46,6 @@ extern "C" { #define LAST_ROW FLEE_ROW #define MAXSIDES 192 /* if there are ever more than this, we're fucked. */ - struct message; typedef struct bfaction { struct bfaction *next; @@ -53,7 +55,7 @@ extern "C" { } bfaction; typedef struct tactics { - struct quicklist *fighters; + struct selist *fighters; int value; } tactics; @@ -86,7 +88,7 @@ extern "C" { } side; typedef struct battle { - struct quicklist *leaders; + struct selist *leaders; struct region *region; struct plane *plane; bfaction *factions; @@ -94,7 +96,7 @@ extern "C" { int nfighters; side sides[MAXSIDES]; int nsides; - struct quicklist *meffects; + struct selist *meffects; int max_tactics; int turn; bool has_tactics_turn; @@ -253,7 +255,7 @@ extern "C" { extern int hits(troop at, troop dt, weapon * awp); extern void damage_building(struct battle *b, struct building *bldg, int damage_abs); - struct quicklist *fighters(struct battle *b, const struct side *vs, + struct selist *fighters(struct battle *b, const struct side *vs, int minrow, int maxrow, int mask); int count_allies(const struct side *as, int minrow, int maxrow, int select, int allytype); diff --git a/src/bind_unit.c b/src/bind_unit.c index 42fafae39..1983e0f62 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -46,7 +46,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include @@ -753,12 +753,12 @@ static int tolua_unit_get_spells(lua_State * L) unit *self = (unit *) tolua_tousertype(L, 1, 0); sc_mage *mage = self ? get_mage(self) : 0; spellbook *sb = mage ? mage->spellbook : 0; - quicklist *slist = 0; + selist *slist = 0; if (sb) { - quicklist **slist_ptr = &sb->spells; + selist **slist_ptr = &sb->spells; slist = *slist_ptr; } - return tolua_quicklist_push(L, "spellbook", "spell_entry", slist); + return tolua_selist_push(L, "spellbook", "spell_entry", slist); } static int tolua_unit_get_orders(lua_State * L) diff --git a/src/bindings.c b/src/bindings.c index aa2e177c1..53eafdcb4 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -66,7 +66,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include #include @@ -114,16 +114,16 @@ int tolua_orderlist_next(lua_State * L) return 0; } -static int tolua_quicklist_iter(lua_State * L) +static int tolua_selist_iter(lua_State * L) { - quicklist **qlp = (quicklist **)lua_touserdata(L, lua_upvalueindex(1)); - quicklist *ql = *qlp; + selist **qlp = (selist **)lua_touserdata(L, lua_upvalueindex(1)); + selist *ql = *qlp; if (ql != NULL) { int index = (int)lua_tointeger(L, lua_upvalueindex(2)); const char *type = lua_tostring(L, lua_upvalueindex(3)); - void *data = ql_get(ql, index); + void *data = selist_get(ql, index); tolua_pushusertype(L, data, TOLUA_CAST type); - ql_advance(qlp, &index, 1); + selist_advance(qlp, &index, 1); lua_pushinteger(L, index); lua_replace(L, lua_upvalueindex(2)); return 1; @@ -131,18 +131,18 @@ static int tolua_quicklist_iter(lua_State * L) return 0; } -int tolua_quicklist_push(struct lua_State *L, const char *list_type, - const char *elem_type, struct quicklist *list) +int tolua_selist_push(struct lua_State *L, const char *list_type, + const char *elem_type, struct selist *list) { if (list) { - quicklist **qlist_ptr = - (quicklist **)lua_newuserdata(L, sizeof(quicklist *)); + selist **qlist_ptr = + (selist **)lua_newuserdata(L, sizeof(selist *)); *qlist_ptr = list; luaL_getmetatable(L, list_type); lua_setmetatable(L, -2); lua_pushinteger(L, 0); lua_pushstring(L, elem_type); - lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ + lua_pushcclosure(L, tolua_selist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ } else { lua_pushnil(L); @@ -671,7 +671,7 @@ static int tolua_get_factions(lua_State * L) static int tolua_get_alliance_factions(lua_State * L) { alliance *self = (alliance *)tolua_tousertype(L, 1, 0); - return tolua_quicklist_push(L, "faction_list", "faction", self->members); + return tolua_selist_push(L, "faction_list", "faction", self->members); } static int tolua_get_alliance_id(lua_State * L) @@ -697,11 +697,11 @@ static int tolua_set_alliance_name(lua_State * L) static int config_get_ships(lua_State * L) { - quicklist *ql; + selist *ql; int qi, i = 0; - lua_createtable(L, ql_length(shiptypes), 0); - for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { - ship_type *stype = (ship_type *)ql_get(ql, qi); + lua_createtable(L, selist_length(shiptypes), 0); + for (qi = 0, ql = shiptypes; ql; selist_advance(&ql, &qi, 1)) { + ship_type *stype = (ship_type *)selist_get(ql, qi); tolua_pushstring(L, TOLUA_CAST stype->_name); lua_rawseti(L, -2, ++i); } @@ -710,11 +710,11 @@ static int config_get_ships(lua_State * L) static int config_get_buildings(lua_State * L) { - quicklist *ql; + selist *ql; int qi, i = 0; - lua_createtable(L, ql_length(buildingtypes), 0); - for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { - building_type *btype = (building_type *)ql_get(ql, qi); + lua_createtable(L, selist_length(buildingtypes), 0); + for (qi = 0, ql = buildingtypes; ql; selist_advance(&ql, &qi, 1)) { + building_type *btype = (building_type *)selist_get(ql, qi); tolua_pushstring(L, TOLUA_CAST btype->_name); lua_rawseti(L, -2, ++i); } @@ -936,7 +936,7 @@ static int tolua_get_spell_entry_level(lua_State * L) static int tolua_get_spells(lua_State * L) { - return tolua_quicklist_push(L, "spell_list", "spell", spells); + return tolua_selist_push(L, "spell_list", "spell", spells); } static int init_data(const char *filename, const char *catalog) diff --git a/src/bindings.h b/src/bindings.h index 6c71ecf94..8eda1178b 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -15,15 +15,15 @@ extern "C" { #endif struct lua_State; - struct quicklist; + struct selist; int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L); int tolua_spelllist_next(struct lua_State *L); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); - int tolua_quicklist_push(struct lua_State *L, const char *list_type, - const char *elem_type, struct quicklist *list); + int tolua_selist_push(struct lua_State *L, const char *list_type, + const char *elem_type, struct selist *list); int log_lua_error(struct lua_State *L); diff --git a/src/creport.c b/src/creport.c index eeb2a1202..6cd9b7a27 100644 --- a/src/creport.c +++ b/src/creport.c @@ -68,7 +68,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include @@ -712,11 +712,11 @@ static void cr_output_spells(stream *out, const unit * u, int maxlevel) if (book) { const faction * f = u->faction; - quicklist *ql; + selist *ql; int qi, header = 0; - for (ql = book->spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { spell * sp = sbe->sp; const char *name = translate(mkname("spell", sp->sname), spell_name(sp, f->locale)); @@ -1027,12 +1027,12 @@ static void show_alliances_cr(FILE * F, const faction * f) /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /* this is a copy of laws.c->find_address output changed. */ -static void cr_find_address(FILE * F, const faction * uf, quicklist * addresses) +static void cr_find_address(FILE * F, const faction * uf, selist * addresses) { int i = 0; - quicklist *flist = addresses; + selist *flist = addresses; while (flist) { - const faction *f = (const faction *)ql_get(flist, i); + const faction *f = (const faction *)selist_get(flist, i); if (uf != f) { fprintf(F, "PARTEI %d\n", f->no); fprintf(F, "\"%s\";Parteiname\n", f->name); @@ -1045,7 +1045,7 @@ static void cr_find_address(FILE * F, const faction * uf, quicklist * addresses) fprintf(F, "%d;alliance\n", f->alliance->id); } } - ql_advance(&flist, &i, 1); + selist_advance(&flist, &i, 1); } } diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 36d054323..32c58e246 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -31,10 +31,11 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include +#include + /* libc includes */ #include #include @@ -49,7 +50,7 @@ void free_alliances(void) alliances = al->next; free(al->name); if (al->members) { - ql_free(al->members); + selist_free(al->members); } free(al); } @@ -115,7 +116,7 @@ faction *alliance_get_leader(alliance * al) { if (!al->_leader) { if (al->members) { - al->_leader = (faction *)ql_get(al->members, 0); + al->_leader = (faction *)selist_get(al->members, 0); } } return al->_leader; @@ -356,19 +357,19 @@ void setalliance(faction * f, alliance * al) return; if (f->alliance != NULL) { int qi; - quicklist **flistp = &f->alliance->members; + selist **flistp = &f->alliance->members; - for (qi = 0; *flistp; ql_advance(flistp, &qi, 1)) { - faction *data = (faction *)ql_get(*flistp, qi); + for (qi = 0; *flistp; selist_advance(flistp, &qi, 1)) { + faction *data = (faction *)selist_get(*flistp, qi); if (data == f) { - ql_delete(flistp, qi); + selist_delete(flistp, qi); break; } } if (f->alliance->_leader == f) { if (f->alliance->members) { - f->alliance->_leader = (faction *)ql_get(f->alliance->members, 0); + f->alliance->_leader = (faction *)selist_get(f->alliance->members, 0); } else { f->alliance->_leader = NULL; @@ -378,7 +379,7 @@ void setalliance(faction * f, alliance * al) f->alliance = al; f->alliance_joindate = turn; if (al != NULL) { - ql_push(&al->members, f); + selist_push(&al->members, f); if (al->_leader == NULL) { al->_leader = f; } diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index 907fc65f7..fac2dfd38 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -27,6 +27,7 @@ extern "C" { struct unit; struct faction; struct region; + struct selist; enum { ALLIANCE_KICK, @@ -46,7 +47,7 @@ extern "C" { typedef struct alliance { struct alliance *next; struct faction *_leader; - struct quicklist *members; + struct selist *members; int flags; int id; char *name; diff --git a/src/kernel/alliance.test.c b/src/kernel/alliance.test.c index 72a31a42c..c0ec03fbc 100644 --- a/src/kernel/alliance.test.c +++ b/src/kernel/alliance.test.c @@ -7,7 +7,7 @@ #include "alliance.h" #include #include -#include +#include #include @@ -76,10 +76,10 @@ static void test_alliance_dead_faction(CuTest *tc) { setalliance(f, al); setalliance(f2, al); CuAssertPtrEquals(tc, f, alliance_get_leader(al)); - CuAssertIntEquals(tc, 2, ql_length(al->members)); + CuAssertIntEquals(tc, 2, selist_length(al->members)); CuAssertPtrEquals(tc, al, f->alliance); destroyfaction(&factions); - CuAssertIntEquals(tc, 1, ql_length(al->members)); + CuAssertIntEquals(tc, 1, selist_length(al->members)); CuAssertPtrEquals(tc, f2, alliance_get_leader(al)); CuAssertPtrEquals(tc, NULL, f->alliance); CuAssertTrue(tc, !f->_alive); diff --git a/src/kernel/building.c b/src/kernel/building.c index 8d76df030..b445019de 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -41,7 +41,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -62,18 +62,18 @@ typedef struct building_typelist { building_type *type; } building_typelist; -quicklist *buildingtypes = NULL; +selist *buildingtypes = NULL; /* Returns a building type for the (internal) name */ static building_type *bt_find_i(const char *name) { - quicklist *ql; + selist *ql; int qi; assert(name); - for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { - building_type *btype = (building_type *)ql_get(ql, qi); + for (qi = 0, ql = buildingtypes; ql; selist_advance(&ql, &qi, 1)) { + building_type *btype = (building_type *)selist_get(ql, qi); if (strcmp(btype->_name, name) == 0) return btype; } @@ -102,7 +102,7 @@ void bt_register(building_type * type) if (type->init) { type->init(type); } - ql_push(&buildingtypes, (void *)type); + selist_push(&buildingtypes, (void *)type); ++bt_changes; } @@ -115,8 +115,8 @@ static void free_buildingtype(void *ptr) { } void free_buildingtypes(void) { - ql_foreach(buildingtypes, free_buildingtype); - ql_free(buildingtypes); + selist_foreach(buildingtypes, free_buildingtype); + selist_free(buildingtypes); buildingtypes = 0; ++bt_changes; } @@ -314,15 +314,15 @@ const building_type *findbuildingtype(const char *name, bn = bn->next; } if (!bn) { - quicklist *ql = buildingtypes; + selist *ql = buildingtypes; int qi; bn = (local_names *)calloc(sizeof(local_names), 1); bn->next = bnames; bn->lang = lang; - for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { - building_type *btype = (building_type *)ql_get(ql, qi); + for (qi = 0, ql = buildingtypes; ql; selist_advance(&ql, &qi, 1)) { + building_type *btype = (building_type *)selist_get(ql, qi); const char *n = LOC(lang, btype->_name); type.v = (void *)btype; diff --git a/src/kernel/building.h b/src/kernel/building.h index 92b006b98..754f38f07 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -80,7 +80,7 @@ extern "C" { struct attrib *attribs; } building_type; - extern struct quicklist *buildingtypes; + extern struct selist *buildingtypes; extern struct attrib_type at_building_action; building_type *bt_get_or_create(const char *name); diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 6eccf1f0c..082039f1b 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -345,7 +345,7 @@ attrib_type at_countdown = { void age_borders(void) { - quicklist *deleted = NULL, *ql; + selist *deleted = NULL, *ql; int i; for (i = 0; i != BORDER_MAXHASH; ++i) { @@ -355,17 +355,17 @@ void age_borders(void) for (; b; b = b->next) { if (b->type->age) { if (b->type->age(b) == AT_AGE_REMOVE) { - ql_push(&deleted, b); + selist_push(&deleted, b); } } } } } - for (ql = deleted, i = 0; ql; ql_advance(&ql, &i, 1)) { - connection *b = (connection *)ql_get(ql, i); + for (ql = deleted, i = 0; ql; selist_advance(&ql, &i, 1)) { + connection *b = (connection *)selist_get(ql, i); erase_border(b); } - ql_free(deleted); + selist_free(deleted); } /******** diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 5e2086476..c0e353b4f 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -287,10 +287,10 @@ attrib_type at_curse = { /* Spruch identifizieren */ #include -#include +#include #define MAXCTHASH 128 -static quicklist *cursetypes[MAXCTHASH]; +static selist *cursetypes[MAXCTHASH]; static int ct_changes = 1; bool ct_changed(int *cache) @@ -306,7 +306,7 @@ bool ct_changed(int *cache) void ct_register(const curse_type * ct) { unsigned int hash = tolower(ct->cname[0]) & 0xFF; - quicklist **ctlp = cursetypes + hash; + selist **ctlp = cursetypes + hash; selist_set_insert(ctlp, (void *)ct, NULL); ++ct_changes; @@ -315,16 +315,16 @@ void ct_register(const curse_type * ct) void ct_remove(const char *c) { unsigned int hash = tolower(c[0]); - quicklist *ctl = cursetypes[hash]; + selist *ctl = cursetypes[hash]; if (ctl) { int qi; - for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { - curse_type *type = (curse_type *)ql_get(ctl, qi); + for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) { + curse_type *type = (curse_type *)selist_get(ctl, qi); if (strcmp(c, type->cname) == 0) { - ql_delete(&ctl, qi); + selist_delete(&ctl, qi); ++ct_changes; break; } @@ -335,14 +335,14 @@ void ct_remove(const char *c) const curse_type *ct_find(const char *c) { unsigned int hash = tolower(c[0]); - quicklist *ctl = cursetypes[hash]; + selist *ctl = cursetypes[hash]; if (ctl) { size_t c_len = strlen(c); int qi; - for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { - curse_type *type = (curse_type *)ql_get(ctl, qi); + for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) { + curse_type *type = (curse_type *)selist_get(ctl, qi); if (strcmp(c, type->cname) == 0) { return type; @@ -360,12 +360,12 @@ const curse_type *ct_find(const char *c) void ct_checknames(void) { int i, qi; - quicklist *ctl; + selist *ctl; for (i = 0; i < MAXCTHASH; ++i) { ctl = cursetypes[i]; - for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { - curse_type *type = (curse_type *)ql_get(ctl, qi); + for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) { + curse_type *type = (curse_type *)selist_get(ctl, qi); curse_name(type, default_locale); } @@ -847,7 +847,7 @@ double destr_curse(curse * c, int cast_level, double force) void curses_done(void) { int i; for (i = 0; i != MAXCTHASH; ++i) { - ql_free(cursetypes[i]); + selist_free(cursetypes[i]); cursetypes[i] = 0; } ++ct_changes; diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 8266ada9a..de539223f 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -28,7 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spell.h" /* util includes */ -#include +#include #include #include @@ -99,7 +99,7 @@ void equipment_addspell(equipment * eq, const char * name, int level) ls->sp = NULL; ls->level = level; ls->name = _strdup(name); - ql_push(&eq->spells, ls); + selist_push(&eq->spells, ls); } } @@ -156,12 +156,12 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) if (mask & EQUIP_SPELLS) { if (eq->spells) { - quicklist * ql = eq->spells; + selist * ql = eq->spells; int qi; sc_mage * mage = get_mage(u); - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - lazy_spell *sbe = (lazy_spell *)ql_get(ql, qi); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + lazy_spell *sbe = (lazy_spell *)selist_get(ql, qi); if (!sbe->sp) { sbe->sp = find_spell(sbe->name); free(sbe->name); @@ -250,8 +250,8 @@ void equipment_done(void) { *eqp = eq->next; free(eq->name); if (eq->spells) { - ql_foreach(eq->spells, free_ls); - ql_free(eq->spells); + selist_foreach(eq->spells, free_ls); + selist_free(eq->spells); } while (eq->items) { itemdata *next = eq->items->next; diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 5c7b3407b..4081ab748 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -48,7 +48,7 @@ extern "C" { char *name; struct itemdata *items; char *skills[MAXSKILLS]; - struct quicklist *spells; + struct selist *spells; struct subset *subsets; struct equipment *next; void(*callback) (const struct equipment *, struct unit *); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index d332bf604..4d2e6ae7b 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -51,7 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include /* libc includes */ @@ -102,7 +102,7 @@ static void free_faction(faction * f) free(f->_password); free(f->name); if (f->seen_factions) { - ql_free(f->seen_factions); + selist_free(f->seen_factions); f->seen_factions = 0; } @@ -366,7 +366,7 @@ void destroyfaction(faction ** fp) } if (f->seen_factions) { - ql_free(f->seen_factions); + selist_free(f->seen_factions); f->seen_factions = 0; } @@ -593,11 +593,11 @@ static int allied_skillcount(const faction * f, skill_t sk) { int num = 0; alliance *a = f_get_alliance(f); - quicklist *members = a->members; + selist *members = a->members; int qi; - for (qi = 0; members; ql_advance(&members, &qi, 1)) { - faction *m = (faction *)ql_get(members, qi); + for (qi = 0; members; selist_advance(&members, &qi, 1)) { + faction *m = (faction *)selist_get(members, qi); num += count_skill(m, sk); } return num; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 82ae89ea4..d6419dd2f 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -31,6 +31,7 @@ extern "C" { struct seen_region; struct attrib_type; struct gamedata; + struct selist; extern struct attrib_type at_maxmagicians; @@ -95,7 +96,7 @@ extern "C" { struct message_list *msgs; } *battles; struct item *items; /* items this faction can claim */ - struct quicklist *seen_factions; + struct selist *seen_factions; bool _alive; /* enno: sollte ein flag werden */ } faction; diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 75ced96df..596c92907 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -13,7 +13,7 @@ #include "monster.h" #include #include -#include +#include #include #include @@ -47,10 +47,10 @@ static void test_remove_empty_factions_alliance(CuTest *tc) { al = makealliance(0, "Hodor"); setalliance(f, al); CuAssertPtrEquals(tc, f, alliance_get_leader(al)); - CuAssertIntEquals(tc, 1, ql_length(al->members)); + CuAssertIntEquals(tc, 1, selist_length(al->members)); remove_empty_factions(); CuAssertPtrEquals(tc, 0, al->_leader); - CuAssertIntEquals(tc, 0, ql_length(al->members)); + CuAssertIntEquals(tc, 0, selist_length(al->members)); test_cleanup(); } diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 8ae9bf128..ba45f926c 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -18,7 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include "pathfinder.h" #include "region.h" @@ -102,10 +102,10 @@ static void free_nodes(node * root) } } -struct quicklist *regions_in_range(struct region *start, int maxdist, +struct selist *regions_in_range(struct region *start, int maxdist, bool(*allowed) (const struct region *, const struct region *)) { - quicklist * rlist = NULL; + selist * rlist = NULL; node *root = new_node(start, 0, NULL); node **end = &root->next; node *n = root; @@ -127,7 +127,7 @@ struct quicklist *regions_in_range(struct region *start, int maxdist, continue; /* can't go there */ /* add the region to the list of available ones. */ - ql_push(&rlist, rn); + selist_push(&rlist, rn); /* make sure we don't go here again, and put the region into the set for further BFS'ing */ diff --git a/src/kernel/pathfinder.h b/src/kernel/pathfinder.h index 81692e835..682fa4d25 100644 --- a/src/kernel/pathfinder.h +++ b/src/kernel/pathfinder.h @@ -34,7 +34,7 @@ extern "C" { const struct region *target); extern bool allowed_walk(const struct region *src, const struct region *target); - extern struct quicklist *regions_in_range(struct region *src, int maxdist, + extern struct selist *regions_in_range(struct region *src, int maxdist, bool(*allowed) (const struct region *, const struct region *)); extern void pathfinder_cleanup(void); diff --git a/src/kernel/save.c b/src/kernel/save.c index 2f157af41..68c89070c 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -71,7 +71,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include #include #include @@ -1266,7 +1266,7 @@ faction *read_faction(struct gamedata * data) assert(!al->members || !"non-allied dummy-alliance has more than one member"); } - ql_push(&al->members, f); + selist_push(&al->members, f); } else if (rule_region_owners()) { /* compat fix for non-allied factions */ diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 6898630ff..1790afb5d 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -38,7 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include @@ -51,7 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -quicklist *shiptypes = NULL; +selist *shiptypes = NULL; static local_names *snames; @@ -66,15 +66,15 @@ const ship_type *findshiptype(const char *name, const struct locale *lang) sn = sn->next; } if (!sn) { - quicklist *ql; + selist *ql; int qi; sn = (local_names *)calloc(sizeof(local_names), 1); sn->next = snames; sn->lang = lang; - for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { - ship_type *stype = (ship_type *)ql_get(ql, qi); + for (qi = 0, ql = shiptypes; ql; selist_advance(&ql, &qi, 1)) { + ship_type *stype = (ship_type *)selist_get(ql, qi); variant var2; const char *n = LOC(lang, stype->_name); var2.v = (void *)stype; @@ -89,11 +89,11 @@ const ship_type *findshiptype(const char *name, const struct locale *lang) static ship_type *st_find_i(const char *name) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { - ship_type *stype = (ship_type *)ql_get(ql, qi); + for (qi = 0, ql = shiptypes; ql; selist_advance(&ql, &qi, 1)) { + ship_type *stype = (ship_type *)selist_get(ql, qi); if (strcmp(stype->_name, name) == 0) { return stype; } @@ -111,7 +111,7 @@ ship_type *st_get_or_create(const char * name) { st = (ship_type *)calloc(sizeof(ship_type), 1); st->_name = _strdup(name); st->storm = 1.0; - ql_push(&shiptypes, (void *)st); + selist_push(&shiptypes, (void *)st); } return st; } @@ -250,8 +250,8 @@ static void free_shiptype(void *ptr) { } void free_shiptypes(void) { - ql_foreach(shiptypes, free_shiptype); - ql_free(shiptypes); + selist_foreach(shiptypes, free_shiptype); + selist_free(shiptypes); shiptypes = 0; } diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 964ee2124..285c29cc0 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -63,7 +63,7 @@ extern "C" { struct construction *construction; /* how to build a ship */ } ship_type; - extern struct quicklist *shiptypes; + extern struct selist *shiptypes; /* Alte Schiffstypen: */ diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 2644f341f..4540029e2 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -26,7 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include /* libc includes */ #include @@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include static critbit_tree cb_spells; -quicklist * spells; +selist * spells; static void free_spell(spell *sp) { free(sp->syntax); @@ -50,12 +50,12 @@ static void free_spell_cb(void *cbdata) { void free_spells(void) { cb_clear(&cb_spells); - ql_foreach(spells, free_spell_cb); - ql_free(spells); + selist_foreach(spells, free_spell_cb); + selist_free(spells); spells = 0; } -void add_spell(struct quicklist **slistp, spell * sp) +void add_spell(struct selist **slistp, spell * sp) { if (!selist_set_insert(slistp, sp, NULL)) { log_error("add_spell: the list already contains the spell '%s'.\n", sp->sname); @@ -123,19 +123,19 @@ spell *find_spell(const char *name) spell *find_spellbyid(unsigned int id) { - quicklist *ql; + selist *ql; int qi; if (id == 0) return NULL; - for (qi = 0, ql = spells; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *)ql_get(ql, qi); + for (qi = 0, ql = spells; ql; selist_advance(&ql, &qi, 1)) { + spell *sp = (spell *)selist_get(ql, qi); if (sp->id == id) { return sp; } } - for (qi = 0, ql = spells; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *)ql_get(ql, qi); + for (qi = 0, ql = spells; ql; selist_advance(&ql, &qi, 1)) { + spell *sp = (spell *)selist_get(ql, qi); unsigned int hashid = hashstring(sp->sname); if (hashid == id) { return sp; diff --git a/src/kernel/spell.h b/src/kernel/spell.h index b447f51d4..f74fda6e2 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -27,7 +27,7 @@ extern "C" { struct region; struct spell; struct spell_component; - struct quicklist; + struct selist; struct attrib_type; typedef int(*spell_f)(struct castorder * co); @@ -50,13 +50,13 @@ extern "C" { struct spell * create_spell(const char * name, unsigned int id); struct spell * find_spell(const char *name); struct spell * find_spellbyid(unsigned int i); - void add_spell(struct quicklist **slistp, spell * sp); + void add_spell(struct selist **slistp, spell * sp); void free_spells(void); /** globals **/ extern struct attrib_type at_unitdissolve; extern struct attrib_type at_wdwpyramid; - extern struct quicklist * spells; + extern struct selist * spells; #ifdef __cplusplus } #endif diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index da8fcd563..7673324f8 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -58,12 +58,12 @@ void read_spellbook(spellbook **bookp, gamedata *data, int(*get_level)(const spe void write_spellbook(const struct spellbook *book, struct storage *store) { - quicklist *ql; + selist *ql; int qi; if (book) { - for (ql = book->spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); WRITE_TOK(store, sbe->sp->sname); WRITE_INT(store, sbe->level); } @@ -84,30 +84,30 @@ void spellbook_add(spellbook *sb, struct spell * sp, int level) sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); sbe->sp = sp; sbe->level = level; - ql_push(&sb->spells, sbe); + selist_push(&sb->spells, sbe); } void spellbook_clear(spellbook *sb) { - quicklist *ql; + selist *ql; int qi; assert(sb); - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); free(sbe); } - ql_free(sb->spells); + selist_free(sb->spells); free(sb->name); } int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), void * data) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); int result = callback(sbe, data); if (result) { return result; @@ -119,11 +119,11 @@ int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp) { if (sb) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); if (sp == sbe->sp) { return sbe; } diff --git a/src/kernel/spellbook.h b/src/kernel/spellbook.h index 84ec0ce5f..75a420c06 100644 --- a/src/kernel/spellbook.h +++ b/src/kernel/spellbook.h @@ -26,7 +26,7 @@ extern "C" { struct spell; struct storage; struct gamedata; - struct quicklist; + struct selist; typedef struct spellbook_entry { struct spell * sp; @@ -36,7 +36,7 @@ extern "C" { typedef struct spellbook { char * name; - struct quicklist * spells; + struct selist * spells; } spellbook; spellbook * create_spellbook(const char * name); diff --git a/src/kernel/types.h b/src/kernel/types.h index da4fefecf..2b63f7e07 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -43,7 +43,7 @@ struct luxury_type; struct order; struct plane; struct potion_type; -struct quicklist; +struct selist; struct race; struct region; struct region_list; diff --git a/src/laws.c b/src/laws.c index 3fe53237e..5a68c72f0 100644 --- a/src/laws.c +++ b/src/laws.c @@ -89,7 +89,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include /* libc includes */ #include @@ -3478,10 +3478,10 @@ static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel) { assert(dst); if (src && src->spells) { - quicklist *ql; + selist *ql; int qi; - for (qi = 0, ql = src->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = src->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { if (!spellbook_get(dst, sbe->sp)) { spellbook_add(dst, sbe->sp, sbe->level); diff --git a/src/magic.c b/src/magic.c index 2299e6523..dbdc1abe8 100644 --- a/src/magic.c +++ b/src/magic.c @@ -58,7 +58,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include @@ -231,7 +231,7 @@ bool FactionSpells(void) return rule != 0; } -void read_spells(struct quicklist **slistp, magic_t mtype, +void read_spells(struct selist **slistp, magic_t mtype, struct storage *store) { for (;;) { @@ -305,13 +305,13 @@ static int read_mage(attrib * a, void *owner, struct gamedata *data) return AT_READ_OK; } -void write_spells(struct quicklist *slist, struct storage *store) +void write_spells(struct selist *slist, struct storage *store) { - quicklist *ql; + selist *ql; int qi; - for (ql = slist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *)ql_get(ql, qi); + for (ql = slist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spell *sp = (spell *)selist_get(ql, qi); WRITE_TOK(store, sp->sname); } WRITE_TOK(store, "end"); @@ -424,11 +424,11 @@ static bool already_seen(const faction * f, const spell * sp) void show_new_spells(faction * f, int level, const spellbook *book) { if (book) { - quicklist *ql = book->spells; + selist *ql = book->spells; int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= level) { if (!already_seen(f, sbe->sp)) { @@ -451,14 +451,14 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells { spellbook_entry *commonspells[MAXSPELLS]; int qi, numspells = 0; - quicklist *ql; + selist *ql; if (level <= f->max_spelllevel) { return; } - for (qi = 0, ql = book->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = book->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= level) { commonspells[numspells++] = sbe; } @@ -2956,14 +2956,14 @@ const char *curse_name(const curse_type * ctype, const struct locale *lang) } static void select_spellbook(void **tokens, spellbook *sb, const struct locale * lang) { - quicklist * ql; + selist * ql; int qi; assert(sb); assert(lang); - for (qi = 0, ql = sb->spells; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi); + for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); spell *sp = sbe->sp; const char *n = spell_name(sp, lang); diff --git a/src/magic.h b/src/magic.h index 59ef92475..d1ae286d0 100644 --- a/src/magic.h +++ b/src/magic.h @@ -348,8 +348,8 @@ extern "C" { struct order *ord, const struct spllprm *spobj); bool FactionSpells(void); - void write_spells(struct quicklist *slist, struct storage *store); - void read_spells(struct quicklist **slistp, magic_t mtype, + void write_spells(struct selist *slist, struct storage *store); + void read_spells(struct selist **slistp, magic_t mtype, struct storage *store); struct spellbook * get_spellbook(const char * name); diff --git a/src/magic.test.c b/src/magic.test.c index 4ba867b96..befd1986d 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -41,7 +41,7 @@ void test_updatespells(CuTest * tc) CuAssertPtrEquals(tc, 0, f->spellbook); pick_random_spells(f, 1, book, 1); CuAssertPtrNotNull(tc, f->spellbook); - CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells)); + CuAssertIntEquals(tc, 1, selist_length(f->spellbook->spells)); CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp)); free_spellbook(book); test_cleanup(); @@ -370,10 +370,10 @@ void test_hasspell(CuTest * tc) test_cleanup(); } -static quicklist * casts; +static selist * casts; static int cast_fireball(struct castorder * co) { - ql_push(&casts, co); + selist_push(&casts, co); return 0; } @@ -401,8 +401,8 @@ void test_multi_cast(CuTest *tc) { CuAssertPtrEquals(tc, casts, 0); magic(); CuAssertPtrNotNull(tc, casts); - CuAssertIntEquals(tc, 2, ql_length(casts)); - ql_free(casts); + CuAssertIntEquals(tc, 2, selist_length(casts)); + selist_free(casts); test_cleanup(); } diff --git a/src/market.c b/src/market.c index cef84b9b2..42819325f 100644 --- a/src/market.c +++ b/src/market.c @@ -17,7 +17,7 @@ without prior permission by the authors of Eressea. #include #include -#include +#include #include #include @@ -92,7 +92,7 @@ bool markets_module(void) void do_markets(void) { - quicklist *traders = 0; + selist *traders = 0; unit *markets[MAX_MARKETS]; region *r; for (r = regions; r; r = r->next) { @@ -124,7 +124,7 @@ void do_markets(void) attrib *a = a_find(u->attribs, &at_market); if (a == NULL) { a = a_add(&u->attribs, a_new(&at_market)); - ql_push(&traders, u); + selist_push(&traders, u); } items = (item *)a->data.v; i_change(&items, lux, 1); @@ -138,7 +138,7 @@ void do_markets(void) attrib *a = a_find(u->attribs, &at_market); if (a == NULL) { a = a_add(&u->attribs, a_new(&at_market)); - ql_push(&traders, u); + selist_push(&traders, u); } items = (item *)a->data.v; i_change(&items, herb, 1); @@ -151,10 +151,10 @@ void do_markets(void) } if (traders) { - quicklist *qliter = traders; + selist *qliter = traders; int qli = 0; - for (qli = 0; qliter; ql_advance(&qliter, &qli, 1)) { - unit *u = (unit *)ql_get(qliter, qli); + for (qli = 0; qliter; selist_advance(&qliter, &qli, 1)) { + unit *u = (unit *)selist_get(qliter, qli); attrib *a = a_find(u->attribs, &at_market); item *items = (item *)a->data.v; @@ -176,6 +176,6 @@ void do_markets(void) a_remove(&u->attribs, a); } - ql_free(traders); + selist_free(traders); } } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 5420406c0..925fae349 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include @@ -295,17 +295,17 @@ static bool virgin_region(const region * r) return true; } -static quicklist * get_island(region * root) +static selist * get_island(region * root) { - quicklist * ql, *result = 0; + selist * ql, *result = 0; int qi = 0; fset(root, RF_MARK); - ql_push(&result, root); + selist_push(&result, root); - for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) { + for (ql = result, qi = 0; ql; selist_advance(&ql, &qi, 1)) { int dir; - region *r = (region *)ql_get(ql, qi); + region *r = (region *)selist_get(ql, qi); region * next[MAXDIRECTIONS]; get_neighbours(r, next); @@ -314,13 +314,13 @@ static quicklist * get_island(region * root) region *rn = next[dir]; if (rn != NULL && rn->land && !fval(rn, RF_MARK)) { fset(rn, RF_MARK); - ql_push(&result, rn); + selist_push(&result, rn); } } } - for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = result, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); freset(r, RF_MARK); } return result; @@ -330,14 +330,14 @@ static void get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p) { int qi, size = 0, maxage = 0, inhabited = 0; - quicklist *ql, *island = NULL; + selist *ql, *island = NULL; - ql_push(&island, root); + selist_push(&island, root); fset(root, RF_MARK); - for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) { + for (ql = island, qi = 0; ql; selist_advance(&ql, &qi, 1)) { int d; - region *r = (region *)ql_get(ql, qi); + region *r = (region *)selist_get(ql, qi); if (r->units) { unit *u; for (u = r->units; u; u = u->next) { @@ -351,16 +351,16 @@ get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p) for (d = 0; d != MAXDIRECTIONS; ++d) { region *rn = rconnect(r, d); if (rn && !fval(rn, RF_MARK) && rn->land) { - ql_push(&island, rn); + selist_push(&island, rn); fset(rn, RF_MARK); } } } - for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = island, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); freset(r, RF_MARK); } - ql_free(island); + selist_free(island); if (size_p) *size_p = size; if (inhabited_p) @@ -502,11 +502,11 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) } if (rmin != NULL) { faction *f; - quicklist *ql, *rlist = get_island(rmin); + selist *ql, *rlist = get_island(rmin); int qi; - for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); unit *u; for (u = r->units; u; u = u->next) { f = u->faction; @@ -516,7 +516,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) } } } - ql_free(rlist); + selist_free(rlist); if (psize > 0) { for (f = factions; f; f = f->next) { freset(f, FFL_MARK); diff --git a/src/monsters.c b/src/monsters.c index cea817589..6e6630fe8 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -65,7 +65,7 @@ #include #include -#include +#include /* libc includes */ #include @@ -428,11 +428,11 @@ static attrib *set_new_dragon_target(unit * u, region * r, int range) { int max_affinity = 0; region *max_region = NULL; - quicklist *ql, *rlist = regions_in_range(r, range, allowed_dragon); + selist *ql, *rlist = regions_in_range(r, range, allowed_dragon); int qi; - for (qi = 0, ql = rlist; ql; ql_advance(&ql, &qi, 1)) { - region *r2 = (region *)ql_get(ql, qi); + for (qi = 0, ql = rlist; ql; selist_advance(&ql, &qi, 1)) { + region *r2 = (region *)selist_get(ql, qi); int affinity = dragon_affinity_value(r2, u); if (affinity > max_affinity) { max_affinity = affinity; @@ -440,7 +440,7 @@ static attrib *set_new_dragon_target(unit * u, region * r, int range) } } - ql_free(rlist); + selist_free(rlist); if (max_region && max_region != r) { attrib *a = a_find(u->attribs, &at_targetregion); diff --git a/src/quicklist.c b/src/quicklist.c deleted file mode 100644 index 6fb567a64..000000000 --- a/src/quicklist.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "quicklist.h" -#include - -void ql_push(struct quicklist **qlp, void *el) -{ - selist_push(qlp, el); -} - -int ql_length(const struct quicklist *ql) -{ - return selist_length(ql); -} - -void * ql_replace(struct quicklist *ql, int index, void *el) -{ - return selist_replace(ql, index, el); -} - -void *ql_get(struct quicklist *ql, int index) -{ - return selist_get(ql, index); -} - -int ql_delete(struct quicklist **qlp, int index) -{ - return selist_delete(qlp, index); -} - -bool ql_empty(const struct quicklist *ql) -{ - return selist_empty(ql); -} - -void ql_foreach(struct quicklist *ql, selist_cb cb) -{ - selist_foreach(ql, cb); -} - -int ql_advance(struct quicklist **qlp, int *index, int stride) -{ - return selist_advance(qlp, index, stride); -} - -void ql_free(struct quicklist *ql) -{ - selist_free(ql); -} - -bool ql_set_remove(struct quicklist **qlp, const void *data) -{ - int qi, qn; - quicklist *ql = *qlp; - - if (!ql) - return false; - - qn = selist_length(ql); - for (qi = 0; qi != qn; ++qi) { - void *qd = selist_get(ql, qi); - if (qd == data) { - return selist_delete(qlp, qi) == 0; - } - } - return false; -} - -bool ql_set_insert(struct quicklist **qlp, void *data) -{ - return selist_set_insert(qlp, data, NULL); -} - -bool ql_set_find(struct quicklist **qlp, int *qip, const void *data) -{ - return selist_set_find(qlp, qip, data, NULL); -} diff --git a/src/quicklist.h b/src/quicklist.h deleted file mode 100644 index f5a85a354..000000000 --- a/src/quicklist.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#define selist quicklist -#include - -int ql_advance(struct quicklist **qlp, int *index, int stride); -void ql_foreach(struct quicklist *ql, selist_cb cb); -void ql_free(struct quicklist *ql); -int ql_delete(struct quicklist **qlp, int index); -void ql_push(struct quicklist **qlp, void *el); -int ql_length(const struct quicklist *ql); -void * ql_replace(struct quicklist *ql, int index, void *el); -void *ql_get(struct quicklist *ql, int index); -bool ql_empty(const struct quicklist *ql); -typedef void(*ql_cb)(void *); -bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); -bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs)); - diff --git a/src/report.c b/src/report.c index dd6b29525..e754c3fb2 100644 --- a/src/report.c +++ b/src/report.c @@ -82,7 +82,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include @@ -1733,16 +1733,16 @@ static void rpline(struct stream *out) swrite(line, sizeof(line), 1, out); } -static void list_address(struct stream *out, const faction * uf, quicklist * seenfactions) +static void list_address(struct stream *out, const faction * uf, selist * seenfactions) { int qi = 0; - quicklist *flist = seenfactions; + selist *flist = seenfactions; centre(out, LOC(uf->locale, "nr_addresses"), false); newline(out); while (flist != NULL) { - const faction *f = (const faction *)ql_get(flist, qi); + const faction *f = (const faction *)selist_get(flist, qi); if (!is_monsters(f)) { char buf[8192]; char label = '-'; @@ -1757,7 +1757,7 @@ static void list_address(struct stream *out, const faction * uf, quicklist * see label = '+'; paragraph(out, buf, 4, 0, label); } - ql_advance(&flist, &qi, 1); + selist_advance(&flist, &qi, 1); } newline(out); rpline(out); diff --git a/src/reports.c b/src/reports.c index 3e139fdda..8ffb823a5 100644 --- a/src/reports.c +++ b/src/reports.c @@ -57,7 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include /* libc includes */ #include @@ -659,15 +659,15 @@ size_t size) spellbook *book = unit_get_spellbook(u); if (book) { - quicklist *ql = book->spells; + selist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC, 0); int result = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); if (wrptr(&bufp, &size, result) != 0) { WARN_STATIC_BUFFER(); } - for (header = 0, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + for (header = 0, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { int result = 0; if (!header) { @@ -973,8 +973,7 @@ int stealth_modifier(seen_mode mode) } } -void transfer_seen(quicklist ** dst, quicklist ** src) -{ +static void transfer_seen(selist ** dst, selist ** src) { assert(!*dst); *dst = *src; *src = NULL; @@ -988,7 +987,7 @@ int cmp_faction(const void *lhs, const void *rhs) { return -1; } -static void add_seen_faction_i(struct quicklist **flist, faction *f) { +static void add_seen_faction_i(struct selist **flist, faction *f) { selist_set_insert(flist, f, cmp_faction); } @@ -998,7 +997,7 @@ void add_seen_faction(faction *self, faction *seen) { typedef struct address_data { faction *f, *lastf; - quicklist **flist; + selist **flist; int stealthmod; } address_data; @@ -1020,7 +1019,7 @@ static void cb_add_address(region *r, unit *ut, void *cbdata) { } } -static void add_travelthru_addresses(region *r, faction *f, quicklist **flist, int stealthmod) { +static void add_travelthru_addresses(region *r, faction *f, selist **flist, int stealthmod) { // for each traveling unit: add the faction of any unit is can see address_data cbdata = { 0 }; cbdata.f = f; @@ -1034,18 +1033,18 @@ static void get_addresses(report_context * ctx) /* "TODO: travelthru" */ region *r; const faction *lastf = NULL; - quicklist *flist = 0; + selist *flist = 0; transfer_seen(&flist, &ctx->f->seen_factions); ctx->f->seen_factions = NULL; /* do not delete it twice */ - ql_push(&flist, ctx->f); + selist_push(&flist, ctx->f); if (f_get_alliance(ctx->f)) { - quicklist *ql = ctx->f->alliance->members; + selist *ql = ctx->f->alliance->members; int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - add_seen_faction_i(&flist, (faction *)ql_get(ql, qi)); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + add_seen_faction_i(&flist, (faction *)selist_get(ql, qi)); } } @@ -1130,31 +1129,31 @@ void reports_done(void) { } } -static quicklist *get_regions_distance(region * root, int radius) +static selist *get_regions_distance(region * root, int radius) { - quicklist *ql, *rlist = NULL; + selist *ql, *rlist = NULL; int qi = 0; - ql_push(&rlist, root); + selist_push(&rlist, root); fset(root, RF_MARK); ql = rlist; while (ql) { - region *r = (region *)ql_get(ql, qi); + region *r = (region *)selist_get(ql, qi); region * next[MAXDIRECTIONS]; int d; get_neighbours(r, next); for (d = 0; d != MAXDIRECTIONS; ++d) { if (next[d] && !fval(next[d], RF_MARK) && distance(next[d], root) <= radius) { - ql_push(&rlist, next[d]); + selist_push(&rlist, next[d]); fset(next[d], RF_MARK); } } - ql_advance(&ql, &qi, 1); + selist_advance(&ql, &qi, 1); } - for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *r = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *r = (region *)selist_get(ql, qi); freset(r, RF_MARK); } return rlist; @@ -1190,16 +1189,16 @@ static void add_seen_nb(faction *f, region *r, seen_mode mode) { */ static void prepare_lighthouse(faction *f, region *r, int range) { - quicklist *ql, *rlist = get_regions_distance(r, range); + selist *ql, *rlist = get_regions_distance(r, range); int qi; - for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { - region *rl = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) { + region *rl = (region *)selist_get(ql, qi); if (!fval(rl->terrain, FORBIDDEN_REGION)) { add_seen_nb(f, rl, seen_lighthouse); } } - ql_free(rlist); + selist_free(rlist); } void reorder_units(region * r) @@ -1393,7 +1392,7 @@ void prepare_report(report_context *ctx, faction *f) void finish_reports(report_context *ctx) { region *r; - ql_free(ctx->addresses); + selist_free(ctx->addresses); for (r = ctx->first; r != ctx->last; r = r->next) { r->seen.mode = seen_none; } diff --git a/src/reports.h b/src/reports.h index e5fd976e3..d69b9a88b 100644 --- a/src/reports.h +++ b/src/reports.h @@ -25,12 +25,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -struct stream; -struct seen_region; #ifdef __cplusplus extern "C" { #endif + struct selist; + struct stream; + struct seen_region; + /* Alter, ab dem der Score angezeigt werden soll: */ #define DISPLAYSCORE 12 /* Breite einer Reportzeile: */ @@ -71,7 +73,7 @@ extern "C" { typedef struct report_context { struct faction *f; - struct quicklist *addresses; + struct selist *addresses; struct region *first, *last; void *userdata; time_t report_time; diff --git a/src/reports.test.c b/src/reports.test.c index c9fe39c19..1794f1cff 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include @@ -108,14 +108,14 @@ static void test_seen_faction(CuTest *tc) { f1 = test_create_faction(rc); f2 = test_create_faction(rc); add_seen_faction(f1, f2); - CuAssertPtrEquals(tc, f2, ql_get(f1->seen_factions, 0)); - CuAssertIntEquals(tc, 1, ql_length(f1->seen_factions)); + CuAssertPtrEquals(tc, f2, selist_get(f1->seen_factions, 0)); + CuAssertIntEquals(tc, 1, selist_length(f1->seen_factions)); add_seen_faction(f1, f2); - CuAssertIntEquals(tc, 1, ql_length(f1->seen_factions)); + CuAssertIntEquals(tc, 1, selist_length(f1->seen_factions)); add_seen_faction(f1, f1); - CuAssertIntEquals(tc, 2, ql_length(f1->seen_factions)); - f2 = (faction *)ql_get(f1->seen_factions, 1); - f1 = (faction *)ql_get(f1->seen_factions, 0); + CuAssertIntEquals(tc, 2, selist_length(f1->seen_factions)); + f2 = (faction *)selist_get(f1->seen_factions, 1); + f1 = (faction *)selist_get(f1->seen_factions, 0); CuAssertTrue(tc, f1->no < f2->no); test_cleanup(); } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index da7e7085a..10f1711ef 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -38,7 +38,7 @@ #include #include -#include +#include /* libc includes */ #include @@ -295,15 +295,15 @@ int sp_stun(struct castorder * co) /** randomly shuffle an array * for correctness, see Donald E. Knuth, The Art of Computer Programming */ -static void scramble_fighters(quicklist * ql) +static void scramble_fighters(selist * ql) { - int qi, qlen = ql_length(ql); + int qi, qlen = selist_length(ql); for (qi = 0; qi != qlen; ++qi) { int qj = qi + (rng_int() % (qlen - qi)); - void *a = ql_get(ql, qi); - void *b = ql_replace(ql, qj, a); - ql_replace(ql, qi, b); + void *a = selist_get(ql, qi); + void *b = selist_replace(ql, qj, a); + selist_replace(ql, qi, b); } } @@ -314,7 +314,7 @@ int sp_combatrosthauch(struct castorder * co) int level = co->level; double power = co->force; battle *b = fi->side->battle; - quicklist *ql, *fgs; + selist *ql, *fgs; int force = lovar(power * 15); int qi, k = 0; @@ -329,8 +329,8 @@ int sp_combatrosthauch(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, BEHIND_ROW - 1, FS_ENEMY); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); if (df->alive == 0) continue; @@ -378,7 +378,7 @@ int sp_combatrosthauch(struct castorder * co) } } } - ql_free(fgs); + selist_free(fgs); if (k == 0) { /* keine Waffen mehr da, die zerst�rt werden k�nnten */ @@ -720,7 +720,7 @@ int sp_immolation(struct castorder * co) troop at; int force, qi, killed = 0; const char *damage; - quicklist *fgs, *ql; + selist *fgs, *ql; message *m; /* 2d4 HP */ @@ -740,8 +740,8 @@ int sp_immolation(struct castorder * co) at.index = 0; fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_ENEMY); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); int n = df->alive - df->removed; troop dt; @@ -755,7 +755,7 @@ int sp_immolation(struct castorder * co) if (force == 0) break; } - ql_free(fgs); + selist_free(fgs); m = msg_message("battle::combatspell", "mage spell killed", fi->unit, sp, @@ -987,7 +987,7 @@ int sp_chaosrow(struct castorder * co) const spell * sp = co->sp; battle *b = fi->side->battle; unit *mage = fi->unit; - quicklist *fgs, *ql; + selist *fgs, *ql; message *m; const char *mtype; int qi, k = 0; @@ -1007,8 +1007,8 @@ int sp_chaosrow(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, NUMROWS, FS_ENEMY); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); int n = df->unit->number; if (df->alive == 0) @@ -1052,7 +1052,7 @@ int sp_chaosrow(struct castorder * co) } power = _max(0, power - n); } - ql_free(fgs); + selist_free(fgs); if (sp->id == SPL_CHAOSROW) { mtype = (k > 0) ? "sp_chaosrow_effect_1" : "sp_chaosrow_effect_0"; @@ -1077,7 +1077,7 @@ int sp_flee(struct castorder * co) const spell * sp = co->sp; battle *b = fi->side->battle; unit *mage = fi->unit; - quicklist *fgs, *ql; + selist *fgs, *ql; int force, n, qi; int panik = 0; message *msg; @@ -1106,8 +1106,8 @@ int sp_flee(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_ENEMY); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); for (n = 0; n != df->alive; ++n) { if (force < 0) @@ -1128,7 +1128,7 @@ int sp_flee(struct castorder * co) } } } - ql_free(fgs); + selist_free(fgs); msg = msg_message("sp_flee_effect_1", "mage spell amount", mage, sp, panik); message_all(b, msg); @@ -1457,7 +1457,7 @@ static void do_meffect(fighter * af, int typ, int effect, int duration) { battle *b = af->side->battle; meffect *me = (meffect *)malloc(sizeof(struct meffect)); - ql_push(&b->meffects, me); + selist_push(&b->meffects, me); me->magician = af; me->typ = typ; me->effect = effect; @@ -1654,13 +1654,13 @@ int sp_keeploot(struct castorder * co) return level; } -static int heal_fighters(quicklist * fgs, int *power, bool heal_monsters) +static int heal_fighters(selist * fgs, int *power, bool heal_monsters) { int healhp = *power, healed = 0, qi; - quicklist *ql; + selist *ql; - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); if (healhp <= 0) break; @@ -1705,7 +1705,7 @@ int sp_healing(struct castorder * co) unit *mage = fi->unit; int j = 0; int healhp = (int)power * 200; - quicklist *fgs; + selist *fgs; message *msg; bool use_item = has_ao_healing(mage); @@ -1723,7 +1723,7 @@ int sp_healing(struct castorder * co) scramble_fighters(fgs); j += heal_fighters(fgs, &healhp, false); j += heal_fighters(fgs, &healhp, true); - ql_free(fgs); + selist_free(fgs); if (j <= 0) { level = j; @@ -1750,7 +1750,7 @@ int sp_undeadhero(struct castorder * co) battle *b = fi->side->battle; unit *mage = fi->unit; region *r = b->region; - quicklist *fgs, *ql; + selist *fgs, *ql; int qi, n, undead = 0; message *msg; int force = (int)get_force(power, 0); @@ -1760,8 +1760,8 @@ int sp_undeadhero(struct castorder * co) fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_ENEMY | FS_HELP); scramble_fighters(fgs); - for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { - fighter *df = (fighter *)ql_get(ql, qi); + for (qi = 0, ql = fgs; ql; selist_advance(&ql, &qi, 1)) { + fighter *df = (fighter *)selist_get(ql, qi); unit *du = df->unit; if (force <= 0) @@ -1832,7 +1832,7 @@ int sp_undeadhero(struct castorder * co) } } } - ql_free(fgs); + selist_free(fgs); level = _min(level, undead); if (undead == 0) { diff --git a/src/sqlite.c b/src/sqlite.c index 99c72d9ec..6acaf4116 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,10 +72,10 @@ typedef struct db_faction { char *name; } db_faction; -static struct quicklist * +static struct selist * read_factions(sqlite3 * db, int game_id) { int res; - quicklist *result = 0; + selist *result = 0; const char * sql = "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" " LEFT OUTER JOIN faction_data fd" @@ -97,7 +97,7 @@ read_factions(sqlite3 * db, int game_id) { if (text) dbf->name = _strdup(text); text = (const char *)sqlite3_column_text(stmt, 3); if (text) dbf->email = _strdup(text); - ql_push(&result, dbf); + selist_push(&result, dbf); res = sqlite3_step(stmt); } sqlite3_finalize(stmt); @@ -134,7 +134,7 @@ static void update_faction(sqlite3 *db, const faction *f) { } int db_update_factions(sqlite3 * db, bool force, int game_id) { - quicklist *ql = read_factions(db, game_id); + selist *ql = read_factions(db, game_id); faction *f; if (!ql) return SQLITE_OK; sqlite3_exec(db, "BEGIN", 0, 0, 0); @@ -142,7 +142,7 @@ int db_update_factions(sqlite3 * db, bool force, int game_id) { bool update = force; db_faction *dbf = 0; #ifdef SELIST_TODO - ql_iter it = qli_init(&ql); + selist_iter it = qli_init(&ql); while (qli_more(it)) { db_faction *df = (db_faction*)qli_next(&it); if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { @@ -178,12 +178,12 @@ int db_update_factions(sqlite3 * db, bool force, int game_id) { int db_update_scores(sqlite3 * db, bool force) { /* - const char *sql_ins = + const char *sselist_ins = "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; - sqlite3_stmt *stmt_ins = stmt_cache_get(db, sql_ins); - const char *sql_upd = + sqlite3_stmt *stmt_ins = stmt_cache_get(db, sselist_ins); + const char *sselist_upd = "UPDATE score set value=? WHERE faction_id=? AND turn=?"; - sqlite3_stmt *stmt_upd = stmt_cache_get(db, sql_upd); + sqlite3_stmt *stmt_upd = stmt_cache_get(db, sselist_upd); faction *f; sqlite3_exec(db, "BEGIN", 0, 0, 0); for (f = factions; f; f = f->next) { diff --git a/src/travelthru.c b/src/travelthru.c index 04ca6cee5..a546c976c 100644 --- a/src/travelthru.c +++ b/src/travelthru.c @@ -33,14 +33,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include #include static void travel_done(attrib *a) { - quicklist *ql = (quicklist *)a->data.v; - ql_free(ql); + selist *ql = (selist *)a->data.v; + selist_free(ql); } /*********************/ @@ -67,7 +67,7 @@ void travelthru_add(region * r, unit * u) region *next[MAXDIRECTIONS]; int d; attrib *a; - quicklist *ql; + selist *ql; assert(r); assert(u); @@ -76,10 +76,10 @@ void travelthru_add(region * r, unit * u) if (!a) { a = a_add(&r->attribs, a_new(&at_travelunit)); } - ql = (quicklist *)a->data.v; + ql = (selist *)a->data.v; fset(r, RF_TRAVELUNIT); - ql_push(&ql, u); + selist_push(&ql, u); a->data.v = ql; /* the first and last region of the faction gets reset, because travelthrough @@ -122,7 +122,7 @@ void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void cbdata.r = r; a = a_find(r->attribs, &at_travelunit); if (a) { - quicklist *ql = (quicklist *)a->data.v; + selist *ql = (selist *)a->data.v; selist_foreach_ex(ql, cb_map, &cbdata); } } diff --git a/src/util/message.c b/src/util/message.c index 46bfec969..f76409e53 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -16,7 +16,7 @@ #include "strings.h" #include "log.h" -#include "quicklist.h" +#include "selist.h" /* libc includes */ #include @@ -160,7 +160,7 @@ message *msg_create(const struct message_type *mtype, variant args[]) } #define MT_MAXHASH 1021 -static quicklist *messagetypes[MT_MAXHASH]; +static selist *messagetypes[MT_MAXHASH]; static void mt_free(void *val) { message_type *mtype = (message_type *)val; @@ -177,9 +177,9 @@ static void mt_free(void *val) { void mt_clear(void) { int i; for (i = 0; i != MT_MAXHASH; ++i) { - quicklist *ql = messagetypes[i]; - ql_foreach(ql, mt_free); - ql_free(ql); + selist *ql = messagetypes[i]; + selist_foreach(ql, mt_free); + selist_free(ql); messagetypes[i] = 0; } } @@ -187,11 +187,11 @@ void mt_clear(void) { const message_type *mt_find(const char *name) { unsigned int hash = hashstring(name) % MT_MAXHASH; - quicklist *ql = messagetypes[hash]; + selist *ql = messagetypes[hash]; int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - message_type *data = (message_type *)ql_get(ql, qi); + for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { + message_type *data = (message_type *)selist_get(ql, qi); if (strcmp(data->name, name) == 0) { return data; } @@ -213,7 +213,7 @@ static unsigned int mt_id(const message_type * mtype) const message_type *mt_register(message_type * type) { unsigned int hash = hashstring(type->name) % MT_MAXHASH; - quicklist **qlp = messagetypes + hash; + selist **qlp = messagetypes + hash; if (selist_set_insert(qlp, type, NULL)) { type->key = mt_id(type); diff --git a/src/wormhole.c b/src/wormhole.c index 6a115a9f7..dd105b302 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include @@ -155,8 +155,8 @@ make_wormhole(const building_type * bt_wormhole, region * r1, region * r2) #define WORMHOLE_CHANCE 10000 -static void select_wormhole_regions(quicklist **rlistp, int *countp) { - quicklist *rlist = 0; +static void select_wormhole_regions(selist **rlistp, int *countp) { + selist *rlist = 0; region *r = regions; int count = 0; @@ -170,7 +170,7 @@ static void select_wormhole_regions(quicklist **rlistp, int *countp) { } if (r == NULL) break; - ql_push(&rlist, r); + selist_push(&rlist, r); ++count; r = r->next; } @@ -179,12 +179,12 @@ static void select_wormhole_regions(quicklist **rlistp, int *countp) { *rlistp = rlist; } -void sort_wormhole_regions(quicklist *rlist, region **match, int count) { - quicklist *ql; +void sort_wormhole_regions(selist *rlist, region **match, int count) { + selist *ql; int qi, i = 0; - for (ql = rlist, qi = 0; i != count; ql_advance(&ql, &qi, 1)) { - match[i++] = (region *)ql_get(ql, qi); + for (ql = rlist, qi = 0; i != count; selist_advance(&ql, &qi, 1)) { + match[i++] = (region *)selist_get(ql, qi); } qsort(match, count, sizeof(region *), cmp_age); } @@ -200,7 +200,7 @@ void make_wormholes(region **match, int count, const building_type *bt_wormhole) void wormholes_update(void) { const building_type *bt_wormhole = bt_find("wormhole"); - quicklist *rlist = 0; + selist *rlist = 0; int count = 0; region **match; @@ -214,7 +214,7 @@ void wormholes_update(void) } match = (region **)malloc(sizeof(region *) * count); sort_wormhole_regions(rlist, match, count); - ql_free(rlist); + selist_free(rlist); make_wormholes(match, count, bt_wormhole); free(match); } diff --git a/src/wormhole.test.c b/src/wormhole.test.c index ec93c5b4c..4f3036200 100644 --- a/src/wormhole.test.c +++ b/src/wormhole.test.c @@ -10,11 +10,11 @@ #include -#include +#include #include -void sort_wormhole_regions(quicklist *rlist, region **match, int count); +void sort_wormhole_regions(selist *rlist, region **match, int count); void make_wormholes(region **match, int count, const building_type *bt_wormhole); static void test_make_wormholes(CuTest *tc) { @@ -42,7 +42,7 @@ static void test_make_wormholes(CuTest *tc) { static void test_sort_wormhole_regions(CuTest *tc) { region *r1, *r2, *match[2]; terrain_type *t_plain; - quicklist *rlist = 0; + selist *rlist = 0; test_setup(); t_plain = test_create_terrain("plain", LAND_REGION); @@ -50,12 +50,12 @@ static void test_sort_wormhole_regions(CuTest *tc) { r2 = test_create_region(1, 0, t_plain); r1->age = 4; r2->age = 2; - ql_push(&rlist, r1); - ql_push(&rlist, r2); + selist_push(&rlist, r1); + selist_push(&rlist, r2); sort_wormhole_regions(rlist, match, 2); CuAssertPtrEquals(tc, r2, match[0]); CuAssertPtrEquals(tc, r1, match[1]); - ql_free(rlist); + selist_free(rlist); test_cleanup(); } From d42f1767ff67be1d7dec0000847ad708dc389d2f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Dec 2016 21:21:50 +0100 Subject: [PATCH 073/271] add a test for teach-messages. vheck that they are generated for students and teachers. --- src/study.test.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/study.test.c b/src/study.test.c index 47976930d..54e32bf28 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -2,6 +2,7 @@ #include "study.h" +#include #include #include #include @@ -10,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -483,6 +485,7 @@ static void test_teach_one_to_many(CuTest *tc) { static void test_teach_many_to_one(CuTest *tc) { unit *u, *u1, *u2; + test_setup(); init_resources(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -505,6 +508,47 @@ static void test_teach_many_to_one(CuTest *tc) { test_cleanup(); } +static void test_teach_message(CuTest *tc) { + unit *u, *u1, *u2; + attrib *a; + ally *al; + teaching_info *teach; + + test_setup(); + init_resources(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + scale_number(u, 20); + u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW"); + u1 = test_create_unit(test_create_faction(0), u->region); + set_level(u1, SK_CROSSBOW, TEACHDIFFERENCE); + u1->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no)); + u2 = test_create_unit(test_create_faction(0), u->region); + al = ally_add(&u->faction->allies, u2->faction); + al->status = HELP_GUARD; + set_level(u2, SK_CROSSBOW, TEACHDIFFERENCE); + u2->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no)); + CuAssertTrue(tc, !alliedunit(u, u1->faction, HELP_GUARD)); + CuAssertTrue(tc, alliedunit(u, u2->faction, HELP_GUARD)); + teach_cmd(u1, u1->thisorder); + teach_cmd(u2, u2->thisorder); + a = a_find(u->attribs, &at_learning); + CuAssertPtrNotNull(tc, a); + CuAssertPtrNotNull(tc, a->data.v); + teach = (teaching_info *)a->data.v; + CuAssertPtrNotNull(tc, teach->teachers); + CuAssertIntEquals(tc, 600, teach->value); + CuAssertPtrEquals(tc, u1, teach->teachers[0]); + CuAssertPtrEquals(tc, u2, teach->teachers[1]); + CuAssertPtrEquals(tc, NULL, teach->teachers[2]); + study_cmd(u, u->thisorder); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher")); + CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "teach_student")); + a = a_find(u->attribs, &at_learning); + CuAssertPtrEquals(tc, NULL, a); + test_cleanup(); +} + static void test_teach_many_to_many(CuTest *tc) { unit *s1, *s2, *t1, *t2; region *r; @@ -554,6 +598,7 @@ CuSuite *get_study_suite(void) SUITE_ADD_TEST(suite, test_teach_one_to_many); SUITE_ADD_TEST(suite, test_teach_many_to_one); SUITE_ADD_TEST(suite, test_teach_many_to_many); + SUITE_ADD_TEST(suite, test_teach_message); SUITE_ADD_TEST(suite, test_teach_two_skills); SUITE_ADD_TEST(suite, test_learn_skill_single); SUITE_ADD_TEST(suite, test_learn_skill_multi); From 61f3585ad7ba9f1d91aaeb74e3c4b34def4debc7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Dec 2016 21:29:07 +0100 Subject: [PATCH 074/271] unlimited teachers. quicklist replaces fixed array. --- src/study.c | 25 +++++++------------------ src/study.h | 4 ++-- src/study.test.c | 10 ++++++---- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/study.c b/src/study.c index 1dd4da8b8..f3372334a 100644 --- a/src/study.c +++ b/src/study.c @@ -53,6 +53,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include + /* libc includes */ #include #include @@ -216,24 +218,11 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, n = _min(n, nteaching); if (n != 0) { - int index = 0; - if (teach == NULL) { a = a_add(&student->attribs, a_new(&at_learning)); teach = (teaching_info *)a->data.v; } - else { - while (teach->teachers[index] && index != MAXTEACHERS) - ++index; - } - if (index < MAXTEACHERS) - teach->teachers[index++] = teacher; - if (index < MAXTEACHERS) { - teach->teachers[index] = NULL; - } - else { - log_error("MAXTEACHERS=%d is too low for student %s, teacher %s", MAXTEACHERS, unitname(student), unitname(teacher)); - } + ql_push(&teach->teachers, teacher); teach->value += n; if (student->building && teacher->building == student->building) { @@ -717,7 +706,7 @@ int study_cmd(unit * u, order * ord) a = a_add(&u->attribs, a_new(&at_learning)); teach = (teaching_info *)a->data.v; assert(teach); - teach->teachers[0] = 0; + teach->teachers = NULL; } if (money > 0) { use_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, money); @@ -766,9 +755,9 @@ int study_cmd(unit * u, order * ord) learn_skill(u, sk, days); if (a != NULL) { - int index = 0; - while (teach->teachers[index] && index != MAXTEACHERS) { - unit *teacher = teach->teachers[index++]; + ql_iter qli = qli_init(&teach->teachers); + while (qli_more(qli)) { + unit *teacher = (unit *)qli_next(&qli); if (teacher->faction != u->faction) { bool feedback = alliedunit(u, teacher->faction, HELP_GUARD); if (feedback) { diff --git a/src/study.h b/src/study.h index 20903583a..8067bc9bd 100644 --- a/src/study.h +++ b/src/study.h @@ -27,6 +27,7 @@ extern "C" { #endif struct unit; + struct quicklist; int teach_cmd(struct unit *u, struct order *ord); int study_cmd(struct unit *u, struct order *ord); @@ -45,10 +46,9 @@ extern "C" { void demon_skillchange(struct unit *u); -#define MAXTEACHERS 32 #define TEACHNUMBER 10 typedef struct teaching_info { - struct unit *teachers[MAXTEACHERS]; + struct quicklist *teachers; int value; } teaching_info; diff --git a/src/study.test.c b/src/study.test.c index 54e32bf28..4c1e5f171 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -18,9 +18,11 @@ #include #include +#include +#include + #include -#include #define MAXLOG 4 typedef struct log_entry { @@ -537,9 +539,9 @@ static void test_teach_message(CuTest *tc) { teach = (teaching_info *)a->data.v; CuAssertPtrNotNull(tc, teach->teachers); CuAssertIntEquals(tc, 600, teach->value); - CuAssertPtrEquals(tc, u1, teach->teachers[0]); - CuAssertPtrEquals(tc, u2, teach->teachers[1]); - CuAssertPtrEquals(tc, NULL, teach->teachers[2]); + CuAssertIntEquals(tc, 2, ql_length(teach->teachers)); + CuAssertPtrEquals(tc, u1, ql_get(teach->teachers, 0)); + CuAssertPtrEquals(tc, u2, ql_get(teach->teachers, 1)); study_cmd(u, u->thisorder); CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher")); CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher")); From 70dfe20e6208f8c9d9b7feceb2128760ece8d09a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Dec 2016 22:40:06 +0100 Subject: [PATCH 075/271] small edit (int->bool) --- src/guard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/guard.c b/src/guard.c index ee26e467b..4b0c63e22 100644 --- a/src/guard.c +++ b/src/guard.c @@ -128,7 +128,7 @@ bool is_guard(const struct unit * u) unit *is_guarded(region * r, unit * u) { unit *u2; - int noguards = 1; + bool noguards = true; if (!fval(r, RF_GUARDED)) { return NULL; @@ -140,7 +140,7 @@ unit *is_guarded(region * r, unit * u) for (u2 = r->units; u2; u2 = u2->next) { if (is_guardian_r(u2)) { - noguards = 0; + noguards = false; if (is_guardian_u(u2, u)) { /* u2 is our guard. stop processing (we might have to go further next time) */ return u2; From 5cb67e1da09a016fe9a9bf994522248a94ecf658 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Dec 2016 07:29:43 +0100 Subject: [PATCH 076/271] start writing a test (WIP). --- src/move.c | 2 +- src/move.h | 2 ++ src/move.test.c | 26 +++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/move.c b/src/move.c index b6a908837..e6469cc4a 100644 --- a/src/move.c +++ b/src/move.c @@ -571,7 +571,7 @@ direction_t reldirection(const region * from, const region * to) return NODIRECTION; } -static void leave_trail(ship * sh, region * from, region_list * route) +void leave_trail(ship * sh, region * from, region_list * route) { region *r = from; diff --git a/src/move.h b/src/move.h index 6363fe2f9..14c040493 100644 --- a/src/move.h +++ b/src/move.h @@ -63,6 +63,8 @@ extern "C" { int enoughsailors(const struct ship *sh, int sumskill); bool canswim(struct unit *u); bool canfly(struct unit *u); + void leave_trail(struct ship *sh, struct region *from, + struct region_list *route); struct ship *move_ship(struct ship *sh, struct region *from, struct region *to, struct region_list *route); int walkingcapacity(const struct unit *u); diff --git a/src/move.test.c b/src/move.test.c index bc93ec124..bdd4a62a8 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -478,7 +478,7 @@ static void test_drifting_ships(CuTest *tc) { region *r1, *r2, *r3; terrain_type *t_ocean, *t_plain; ship_type *st_boat; - test_cleanup(); + test_setup(); t_ocean = test_create_terrain("ocean", SEA_REGION); t_plain = test_create_terrain("plain", LAND_REGION); r1 = test_create_region(0, 0, t_ocean); @@ -491,11 +491,35 @@ static void test_drifting_ships(CuTest *tc) { test_cleanup(); } +static void test_ship_leave_trail(CuTest *tc) { + ship *s1, *s2; + region *r1, *r2; + terrain_type *t_ocean; + ship_type *st_boat; + region_list *route = NULL; + + test_setup(); + t_ocean = test_create_terrain("ocean", SEA_REGION); + r1 = test_create_region(0, 0, t_ocean); + add_regionlist(&route, r2 = test_create_region(1, 0, t_ocean)); + add_regionlist(&route, test_create_region(2, 0, t_ocean)); + st_boat = test_create_shiptype("boat"); + s1 = test_create_ship(r1, st_boat); + s2 = test_create_ship(r1, st_boat); + leave_trail(s1, r1, route); + leave_trail(s2, r1, route); +// CuAssertPtrNotNull(tc, r1->attribs); + CuAssertPtrNotNull(tc, r2->attribs); + free_regionlist(route); + test_cleanup(); +} + CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_walkingcapacity); SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast); + SUITE_ADD_TEST(suite, test_ship_leave_trail); SUITE_ADD_TEST(suite, test_ship_allowed_without_harbormaster); SUITE_ADD_TEST(suite, test_ship_blocked_by_harbormaster); SUITE_ADD_TEST(suite, test_ship_has_harbormaster_contact); From 13128be0aa6db3803081cd0f9e182febb67fb946 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Dec 2016 17:16:10 +0100 Subject: [PATCH 077/271] add a failing test for bug 2266 --- src/lighthouse.c | 2 +- src/lighthouse.h | 2 +- src/move.test.c | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lighthouse.c b/src/lighthouse.c index d962b9b76..09c9b7d11 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -14,7 +14,7 @@ #include #include -const attrib_type at_lighthouse = { +attrib_type at_lighthouse = { "lighthouse" /* Rest ist NULL; tempor�res, nicht alterndes Attribut */ }; diff --git a/src/lighthouse.h b/src/lighthouse.h index 518b05b5a..3bf970bf1 100644 --- a/src/lighthouse.h +++ b/src/lighthouse.h @@ -29,7 +29,7 @@ extern "C" { struct building; struct attrib; - extern const struct attrib_type at_lighthouse; + extern struct attrib_type at_lighthouse; /* leuchtturm */ bool check_leuchtturm(struct region *r, struct faction *f); void update_lighthouse(struct building *lh); diff --git a/src/move.test.c b/src/move.test.c index bdd4a62a8..6a2a0e7db 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -3,6 +3,7 @@ #include "move.h" #include "keyword.h" +#include "lighthouse.h" #include #include @@ -501,15 +502,21 @@ static void test_ship_leave_trail(CuTest *tc) { test_setup(); t_ocean = test_create_terrain("ocean", SEA_REGION); r1 = test_create_region(0, 0, t_ocean); - add_regionlist(&route, r2 = test_create_region(1, 0, t_ocean)); add_regionlist(&route, test_create_region(2, 0, t_ocean)); + add_regionlist(&route, r2 = test_create_region(1, 0, t_ocean)); st_boat = test_create_shiptype("boat"); s1 = test_create_ship(r1, st_boat); s2 = test_create_ship(r1, st_boat); leave_trail(s1, r1, route); + a_add(&r1->attribs, a_new(&at_lighthouse)); leave_trail(s2, r1, route); -// CuAssertPtrNotNull(tc, r1->attribs); - CuAssertPtrNotNull(tc, r2->attribs); + a_add(&r2->attribs, a_new(&at_lighthouse)); + CuAssertPtrEquals(tc, &at_shiptrail, (void *)r1->attribs->type); + CuAssertPtrEquals(tc, &at_shiptrail, (void *)r1->attribs->next->type); + CuAssertPtrEquals(tc, &at_lighthouse, (void *)r1->attribs->next->next->type); + CuAssertPtrEquals(tc, &at_shiptrail, (void *)r2->attribs->type); + CuAssertPtrEquals(tc, &at_shiptrail, (void *)r2->attribs->next->type); + CuAssertPtrEquals(tc, &at_lighthouse, (void *)r2->attribs->next->next->type); free_regionlist(route); test_cleanup(); } From 129f6fb68af8651008bd14e542bff5774846561b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Dec 2016 17:17:04 +0100 Subject: [PATCH 078/271] fix bug 2266 --- src/move.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/move.c b/src/move.c index e6469cc4a..f1b2311f1 100644 --- a/src/move.c +++ b/src/move.c @@ -595,7 +595,7 @@ void leave_trail(ship * sh, region * from, region_list * route) a = a->next; } - if (a == NULL) { + if (a == NULL || a->type != &at_shiptrail) { a = a_add(&(r->attribs), a_new(&at_shiptrail)); td = (traveldir *)a->data.v; td->no = sh->no; From f297d89958ed5c59a9b668320e9befc2765b1e26 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 23 Dec 2016 18:05:38 +0100 Subject: [PATCH 079/271] merge monster.c and monsters.c move RCF_DESERT handling to monsters.c --- src/CMakeLists.txt | 1 - src/battle.c | 2 +- src/bind_monsters.c | 1 - src/bindings.c | 2 +- src/chaos.c | 2 +- src/economy.c | 2 +- src/guard.c | 2 +- src/guard.test.c | 2 +- src/kernel/faction.test.c | 2 +- src/laws.c | 2 +- src/laws.test.c | 2 +- src/monster.c | 224 -------------------------------------- src/monster.h | 39 ------- src/monsters.c | 193 +++++++++++++++++++++++++++++++- src/monsters.h | 49 ++++++++- src/monsters.test.c | 1 - src/move.c | 2 +- src/races/zombies.c | 2 +- src/randenc.c | 19 +--- src/report.c | 2 +- src/spells.c | 2 +- src/study.c | 2 +- src/summary.c | 2 +- src/teleport.c | 2 +- src/upkeep.c | 2 +- 25 files changed, 249 insertions(+), 312 deletions(-) delete mode 100644 src/monster.c delete mode 100644 src/monster.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3f81e1a2..39d290560 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -112,7 +112,6 @@ set (ERESSEA_SRC magic.c market.c morale.c - monster.c randenc.c renumber.c volcano.c diff --git a/src/battle.c b/src/battle.c index 28a08c6f3..9d2d09cc0 100644 --- a/src/battle.c +++ b/src/battle.c @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "chaos.h" #include "guard.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include "skill.h" diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 54a9d0ba6..53a569311 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,6 +1,5 @@ #include #include "spells/shipcurse.h" -#include "monster.h" #include "monsters.h" #include diff --git a/src/bindings.c b/src/bindings.c index 53eafdcb4..13b562af6 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -54,7 +54,7 @@ without prior permission by the authors of Eressea. #include "summary.h" #include "teleport.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include "market.h" #include diff --git a/src/chaos.c b/src/chaos.c index 942fb87bc..58cd7af73 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -19,7 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "chaos.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include diff --git a/src/economy.c b/src/economy.c index d3f6189fc..01954ff54 100644 --- a/src/economy.c +++ b/src/economy.c @@ -31,7 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spy.h" #include "study.h" #include "move.h" -#include "monster.h" +#include "monsters.h" #include "morale.h" #include "reports.h" #include "calendar.h" diff --git a/src/guard.c b/src/guard.c index 4b0c63e22..07640452c 100644 --- a/src/guard.c +++ b/src/guard.c @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "guard.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include #include diff --git a/src/guard.test.c b/src/guard.test.c index 60e5453c6..c5bffeab5 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -2,7 +2,7 @@ #include "guard.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include #include diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 596c92907..3bfc36ca8 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -10,7 +10,7 @@ #include #include -#include "monster.h" +#include "monsters.h" #include #include #include diff --git a/src/laws.c b/src/laws.c index 5a68c72f0..d311f698e 100644 --- a/src/laws.c +++ b/src/laws.c @@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "keyword.h" #include "market.h" #include "morale.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include "randenc.h" #include "renumber.h" diff --git a/src/laws.test.c b/src/laws.test.c index 69e9f5e04..1bec0e6b4 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -2,7 +2,7 @@ #include "laws.h" #include "battle.h" #include "guard.h" -#include "monster.h" +#include "monsters.h" #include #include diff --git a/src/monster.c b/src/monster.c deleted file mode 100644 index 301b1b132..000000000 --- a/src/monster.c +++ /dev/null @@ -1,224 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#include -#include -#include "monster.h" - -/* gamecode includes */ -#include "economy.h" -#include "give.h" -#include "move.h" - -/* attributes includes */ -#include -#include -#include - -/* kernel includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* util includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* libc includes */ -#include -#include -#include - -#define MOVECHANCE 25 /* chance fuer bewegung */ - -#define MAXILLUSION_TEXTS 3 - -bool monster_is_waiting(const unit * u) -{ - int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED; - if (fval(u, test)) - return true; - return false; -} - -static void eaten_by_monster(unit * u) -{ - /* adjustment for smaller worlds */ - double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; - int n = 0; - int horse = -1; - const resource_type *rhorse = get_resourcetype(R_HORSE); - const race *rc = u_race(u); - attrib *a; - - a = a_find(rc->attribs, &at_scare); - if (a) { - n = rng_int() & a->data.i * u->number; - } else { - n = rng_int() % (u->number / 20 + 1); - horse = 0; - } - horse = horse ? i_get(u->items, rhorse->itype) : 0; - - n = (int)(n * multi); - if (n > 0) { - n = lovar(n); - n = _min(rpeasants(u->region), n); - - if (n > 0) { - deathcounts(u->region, n); - rsetpeasants(u->region, rpeasants(u->region) - n); - ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); - } - } - if (horse > 0) { - i_change(&u->items, rhorse->itype, -horse); - ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); - } -} - -static void absorbed_by_monster(unit * u) -{ - int n = rng_int() % (u->number / 20 + 1); - - if (n > 0) { - n = lovar(n); - n = _min(rpeasants(u->region), n); - if (n > 0) { - rsetpeasants(u->region, rpeasants(u->region) - n); - scale_number(u, u->number + n); - ADDMSG(&u->region->msgs, msg_message("absorbpeasants", - "unit race amount", u, u_race(u), n)); - } - } -} - -static int scareaway(region * r, int anzahl) -{ - int n, p, diff = 0, emigrants[MAXDIRECTIONS]; - direction_t d; - - anzahl = _min(_max(1, anzahl), rpeasants(r)); - - /* Wandern am Ende der Woche (normal) oder wegen Monster. Die - * Wanderung wird erst am Ende von demographics () ausgefuehrt. - * emigrants[] ist local, weil r->newpeasants durch die Monster - * vielleicht schon hochgezaehlt worden ist. */ - - for (d = 0; d != MAXDIRECTIONS; d++) - emigrants[d] = 0; - - p = rpeasants(r); - assert(p >= 0 && anzahl >= 0); - for (n = _min(p, anzahl); n; n--) { - direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); - region *rc = rconnect(r, dir); - - if (rc && fval(rc->terrain, LAND_REGION)) { - ++diff; - rc->land->newpeasants++; - emigrants[dir]++; - } - } - rsetpeasants(r, p - diff); - assert(p >= diff); - return diff; -} - -static void scared_by_monster(unit * u) -{ - int n; - const race *rc = u_race(u); - attrib *a; - a = a_find(rc->attribs, &at_scare); - if (a) { - n = rng_int() & a->data.i * u->number; - } else { - n = rng_int() % (u->number / 4 + 1); - } - if (n > 0) { - n = lovar(n); - n = _min(rpeasants(u->region), n); - if (n > 0) { - n = scareaway(u->region, n); - if (n > 0) { - ADDMSG(&u->region->msgs, msg_message("fleescared", - "amount unit", n, u)); - } - } - } -} - -void monster_kills_peasants(unit * u) -{ - if (!monster_is_waiting(u)) { - if (u_race(u)->flags & RCF_SCAREPEASANTS) { - scared_by_monster(u); - } - if (u_race(u)->flags & RCF_KILLPEASANTS) { - eaten_by_monster(u); - } - if (u_race(u)->flags & RCF_ABSORBPEASANTS) { - absorbed_by_monster(u); - } - } -} - -faction *get_or_create_monsters(void) -{ - faction *f = findfaction(MONSTER_ID); - if (!f) { - const race *rc = rc_get_or_create("dragon"); - const char *email = config_get("monster.email"); - f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, default_locale, 0); - renumber_faction(f, MONSTER_ID); - faction_setname(f, "Monster"); - fset(f, FFL_NPC | FFL_NOIDLEOUT); - } - return f; -} - -faction *get_monsters(void) { - return get_or_create_monsters(); -} - -void make_zombie(unit * u) -{ - u_setfaction(u, get_monsters()); - scale_number(u, 1); - u->hp = unit_max_hp(u) * u->number; - u_setrace(u, get_race(RC_ZOMBIE)); - u->irace = NULL; -} diff --git a/src/monster.h b/src/monster.h deleted file mode 100644 index 0f936b17d..000000000 --- a/src/monster.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef H_GC_MONSTER -#define H_GC_MONSTER -#ifdef __cplusplus -extern "C" { -#endif - - struct unit; - - void monster_kills_peasants(struct unit *u); - bool monster_is_waiting(const struct unit *u); - struct faction *get_monsters(void); - struct faction *get_or_create_monsters(void); - void make_zombie(struct unit * u); - -#define MONSTER_ID 666 -#define is_monsters(f) ((f->flags & FFL_NPC) && f==get_monsters()) - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/monsters.c b/src/monsters.c index 6e6630fe8..ea80b9740 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -26,12 +26,12 @@ #include "chaos.h" #include "give.h" #include "guard.h" -#include "monster.h" #include "laws.h" #include "keyword.h" #include "study.h" /* attributes includes */ +#include #include #include @@ -72,8 +72,8 @@ #include #include -#define MOVECHANCE .25 /* chance fuer bewegung */ -#define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */ +#define DRAGON_RANGE 20 /* max. Distanz zum nächsten Drachenziel */ +#define MOVE_PERCENT 25 /* chance fuer bewegung */ #define MAXILLUSION_TEXTS 3 static double attack_chance; /* rules.monsters.attack_chance, or default 0.4 */ @@ -85,12 +85,12 @@ static void give_peasants(unit *u, const item_type *itype, int reduce) { } static double random_move_chance(void) { - static double rule; + static int rule; static int config; if (config_changed(&config)) { - rule = config_get_flt("rules.monsters.random_move_chance", MOVECHANCE); + rule = config_get_flt("rules.monsters.random_move_percent", MOVE_PERCENT); } - return rule; + return rule * 0.01; } static void reduce_weight(unit * u) @@ -165,6 +165,29 @@ static order *monster_attack(unit * u, const unit * target) return create_order(K_ATTACK, u->faction->locale, "%i", target->no); } +void monsters_desert(struct faction *monsters) +{ + region *r; + + assert(monsters!=NULL); + for (r = regions; r; r = r->next) { + unit *u; + + for (u = r->units; u; u = u->next) { + if (u->faction!=monsters + && (u_race(u)->flags & RCF_DESERT)) { + if (fval(u, UFL_ISNEW)) + continue; + if (rng_int() % 100 < 5) { + ADDMSG(&u->faction->msgs, msg_message("desertion", + "unit region", u, r)); + u_setfaction(u, monsters); + } + } + } + } +} + int monster_attacks(unit * monster, bool respect_buildings, bool rich_only) { region *r = monster->region; @@ -973,3 +996,161 @@ void spawn_undead(void) } } } + +bool monster_is_waiting(const unit * u) +{ + int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED; + if (fval(u, test)) + return true; + return false; +} + +static void eaten_by_monster(unit * u) +{ + /* adjustment for smaller worlds */ + double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; + int n = 0; + int horse = -1; + const resource_type *rhorse = get_resourcetype(R_HORSE); + const race *rc = u_race(u); + attrib *a; + + a = a_find(rc->attribs, &at_scare); + if (a) { + n = rng_int() & a->data.i * u->number; + } else { + n = rng_int() % (u->number / 20 + 1); + horse = 0; + } + horse = horse ? i_get(u->items, rhorse->itype) : 0; + + n = (int)(n * multi); + if (n > 0) { + n = lovar(n); + n = _min(rpeasants(u->region), n); + + if (n > 0) { + deathcounts(u->region, n); + rsetpeasants(u->region, rpeasants(u->region) - n); + ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); + } + } + if (horse > 0) { + i_change(&u->items, rhorse->itype, -horse); + ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); + } +} + +static void absorbed_by_monster(unit * u) +{ + int n = rng_int() % (u->number / 20 + 1); + + if (n > 0) { + n = lovar(n); + n = _min(rpeasants(u->region), n); + if (n > 0) { + rsetpeasants(u->region, rpeasants(u->region) - n); + scale_number(u, u->number + n); + ADDMSG(&u->region->msgs, msg_message("absorbpeasants", + "unit race amount", u, u_race(u), n)); + } + } +} + +static int scareaway(region * r, int anzahl) +{ + int n, p, diff = 0, emigrants[MAXDIRECTIONS]; + direction_t d; + + anzahl = _min(_max(1, anzahl), rpeasants(r)); + + /* Wandern am Ende der Woche (normal) oder wegen Monster. Die + * Wanderung wird erst am Ende von demographics () ausgefuehrt. + * emigrants[] ist local, weil r->newpeasants durch die Monster + * vielleicht schon hochgezaehlt worden ist. */ + + for (d = 0; d != MAXDIRECTIONS; d++) + emigrants[d] = 0; + + p = rpeasants(r); + assert(p >= 0 && anzahl >= 0); + for (n = _min(p, anzahl); n; n--) { + direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); + region *rc = rconnect(r, dir); + + if (rc && fval(rc->terrain, LAND_REGION)) { + ++diff; + rc->land->newpeasants++; + emigrants[dir]++; + } + } + rsetpeasants(r, p - diff); + assert(p >= diff); + return diff; +} + +static void scared_by_monster(unit * u) +{ + int n; + const race *rc = u_race(u); + attrib *a; + a = a_find(rc->attribs, &at_scare); + if (a) { + n = rng_int() & a->data.i * u->number; + } else { + n = rng_int() % (u->number / 4 + 1); + } + if (n > 0) { + n = lovar(n); + n = _min(rpeasants(u->region), n); + if (n > 0) { + n = scareaway(u->region, n); + if (n > 0) { + ADDMSG(&u->region->msgs, msg_message("fleescared", + "amount unit", n, u)); + } + } + } +} + +void monster_kills_peasants(unit * u) +{ + if (!monster_is_waiting(u)) { + if (u_race(u)->flags & RCF_SCAREPEASANTS) { + scared_by_monster(u); + } + if (u_race(u)->flags & RCF_KILLPEASANTS) { + eaten_by_monster(u); + } + if (u_race(u)->flags & RCF_ABSORBPEASANTS) { + absorbed_by_monster(u); + } + } +} + +faction *get_or_create_monsters(void) +{ + faction *f = findfaction(MONSTER_ID); + if (!f) { + const race *rc = rc_get_or_create("dragon"); + const char *email = config_get("monster.email"); + f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, default_locale, 0); + renumber_faction(f, MONSTER_ID); + faction_setname(f, "Monster"); + fset(f, FFL_NPC | FFL_NOIDLEOUT); + } + return f; +} + +faction *get_monsters(void) { + return get_or_create_monsters(); +} + +void make_zombie(unit * u) +{ + u_setfaction(u, get_monsters()); + scale_number(u, 1); + u->hp = unit_max_hp(u) * u->number; + u_setrace(u, get_race(RC_ZOMBIE)); + u->irace = NULL; +} diff --git a/src/monsters.h b/src/monsters.h index 02e41c0a4..52e9ebf37 100644 --- a/src/monsters.h +++ b/src/monsters.h @@ -1,8 +1,45 @@ -#pragma once +/* +Copyright (c) 1998-2015, Enno Rehling +Katja Zedel -struct unit; -struct region; -struct faction; +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. -struct unit *spawn_seaserpent(struct region *r, struct faction *f); -void spawn_dragons(void); +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#ifndef H_GC_MONSTER +#define H_GC_MONSTER +#ifdef __cplusplus +extern "C" { +#endif + + struct unit; + struct region; + struct faction; + + struct unit *spawn_seaserpent(struct region *r, struct faction *f); + void spawn_dragons(void); + void monsters_desert(struct faction *monsters); + + void monster_kills_peasants(struct unit *u); + bool monster_is_waiting(const struct unit *u); + struct faction *get_monsters(void); + struct faction *get_or_create_monsters(void); + void make_zombie(struct unit * u); + +#define MONSTER_ID 666 +#define is_monsters(f) ((f->flags & FFL_NPC) && f==get_monsters()) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/monsters.test.c b/src/monsters.test.c index ca793891c..e0eaa3ccc 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -10,7 +10,6 @@ #include #include -#include "monster.h" #include "monsters.h" #include "guard.h" #include "reports.h" diff --git a/src/move.c b/src/move.c index f1b2311f1..126557d58 100644 --- a/src/move.c +++ b/src/move.c @@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "travelthru.h" #include "vortex.h" -#include "monster.h" +#include "monsters.h" #include "lighthouse.h" #include "piracy.h" diff --git a/src/races/zombies.c b/src/races/zombies.c index d7f871dac..3e9303b38 100644 --- a/src/races/zombies.c +++ b/src/races/zombies.c @@ -24,7 +24,7 @@ /* util iclude */ #include -#include "monster.h" +#include "monsters.h" /* libc includes */ #include diff --git a/src/randenc.c b/src/randenc.c index a3c5ce303..536210b1f 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "volcano.h" #include "economy.h" -#include "monster.h" +#include "monsters.h" #include "move.h" #include "chaos.h" #include "study.h" @@ -826,22 +826,7 @@ void randomevents(void) /* monster-einheiten desertieren */ if (monsters) { - for (r = regions; r; r = r->next) { - unit *u; - - for (u = r->units; u; u = u->next) { - if (u->faction && !is_monsters(u->faction) - && (u_race(u)->flags & RCF_DESERT)) { - if (fval(u, UFL_ISNEW)) - continue; - if (rng_int() % 100 < 5) { - ADDMSG(&u->faction->msgs, msg_message("desertion", - "unit region", u, r)); - u_setfaction(u, monsters); - } - } - } - } + monsters_desert(monsters); } chaos_update(); diff --git a/src/report.c b/src/report.c index e754c3fb2..34da143de 100644 --- a/src/report.c +++ b/src/report.c @@ -26,7 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "guard.h" #include "laws.h" #include "market.h" -#include "monster.h" +#include "monsters.h" #include "travelthru.h" /* modules includes */ diff --git a/src/spells.c b/src/spells.c index 57b1da3a5..7e7b5669a 100644 --- a/src/spells.c +++ b/src/spells.c @@ -22,7 +22,7 @@ #include "spells.h" #include "direction.h" #include "randenc.h" -#include "monster.h" +#include "monsters.h" #include "teleport.h" #include diff --git a/src/study.c b/src/study.c index f3372334a..58cd068f2 100644 --- a/src/study.c +++ b/src/study.c @@ -24,7 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "study.h" #include "laws.h" #include "move.h" -#include "monster.h" +#include "monsters.h" #include "alchemy.h" #include "academy.h" diff --git a/src/summary.c b/src/summary.c index 2311b1994..8a3ee3c41 100644 --- a/src/summary.c +++ b/src/summary.c @@ -14,7 +14,7 @@ #include "summary.h" #include "laws.h" -#include "monster.h" +#include "monsters.h" #include "calendar.h" #include diff --git a/src/teleport.c b/src/teleport.c index 74176f6af..f81f2f9f0 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "skill.h" -#include "monster.h" +#include "monsters.h" /* libc includes */ #include diff --git a/src/upkeep.c b/src/upkeep.c index 198ce73df..1cf41011f 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -16,7 +16,7 @@ #include "alchemy.h" #include "economy.h" -#include "monster.h" +#include "monsters.h" #include "donations.h" #include From 8c045d7a78263394fff96c7f4bd9f181adad0aa3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 23 Dec 2016 23:58:24 +0100 Subject: [PATCH 080/271] fix flt/int compilation bug. --- src/monsters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monsters.c b/src/monsters.c index ea80b9740..829c1ed35 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -88,7 +88,7 @@ static double random_move_chance(void) { static int rule; static int config; if (config_changed(&config)) { - rule = config_get_flt("rules.monsters.random_move_percent", MOVE_PERCENT); + rule = config_get_int("rules.monsters.random_move_percent", MOVE_PERCENT); } return rule * 0.01; } From 0c865dca57337b18d141402a2e300e5cb863a245 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 19:56:55 +0100 Subject: [PATCH 081/271] failing test for name_unit. --- src/kernel/unit.test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index c4b1f46ed..752627144 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -468,6 +468,24 @@ static void test_renumber_unit(CuTest *tc) { test_cleanup(); } +static void gen_name(unit *u) +{ + unit_setname(u, "Hodor"); +} + +static void test_name_unit(CuTest *tc) { + race *rc; + unit * u; + + test_setup(); + rc = test_create_race("skeleton"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + rc->generate_name = gen_name; + name_unit(u); + CuAssertStrEquals(tc, "Hodor", unit_getname(u)); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -491,5 +509,6 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_inside_building); SUITE_ADD_TEST(suite, test_limited_skills); SUITE_ADD_TEST(suite, test_renumber_unit); + SUITE_ADD_TEST(suite, test_name_unit); return suite; } From 51bebfdb6b9592bd666d844f474084d171f85bc9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 20:03:50 +0100 Subject: [PATCH 082/271] fix undead name generation. --- src/kernel/race.c | 7 ------- src/kernel/race.h | 1 - src/kernel/unit.c | 12 +++--------- src/names.test.c | 2 +- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index f28c5ed2f..decc3b7bb 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -369,10 +369,3 @@ void register_race_description_function(race_desc_func func, const char *name) { void register_race_name_function(race_name_func func, const char *name) { register_function((pf_generic)func, name); } - -char * race_namegen(const struct race *rc, struct unit *u) { - if (rc->generate_name) { - rc->generate_name(u); - } - return NULL; -} diff --git a/src/kernel/race.h b/src/kernel/race.h index 022d09c86..6673676bd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -252,7 +252,6 @@ extern "C" { const char *raceprefix(const struct unit *u); void register_race_name_function(race_name_func, const char *); void register_race_description_function(race_desc_func, const char *); - char * race_namegen(const struct race *rc, struct unit *u); #ifdef __cplusplus } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 4aff7d118..f06c4c252 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1480,15 +1480,9 @@ void default_name(const unit *u, char name[], int len) { void name_unit(unit * u) { - if (u_race(u)->generate_name) { - char *gen_name = race_namegen(u_race(u), u); - if (gen_name) { - free(u->_name); - u->_name = gen_name; - } - else { - unit_setname(u, racename(u->faction->locale, u, u_race(u))); - } + const race *rc = u_race(u); + if (rc->generate_name) { + rc->generate_name(u); } else { char name[32]; diff --git a/src/names.test.c b/src/names.test.c index f50937f17..1fc41f340 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -24,7 +24,7 @@ static void test_names(CuTest * tc) locale_setstring(default_locale, "undead_postfix_0", "Kobolde"); CuAssertPtrNotNull(tc, foo = (race_name_func)get_function("nameundead")); rc->generate_name = foo; - race_namegen(rc, u); + rc->generate_name(u); CuAssertStrEquals(tc, "Graue Kobolde", u->_name); CuAssertPtrNotNull(tc, get_function("nameskeleton")); CuAssertPtrNotNull(tc, get_function("namezombie")); From e49d350348e754f24ba3a57bdde119829b56633c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 20:12:13 +0100 Subject: [PATCH 083/271] test that monsters with "namegeneric" hook get a NULL name (WIP) --- src/names.test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/names.test.c b/src/names.test.c index 1fc41f340..176a12a68 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -36,9 +36,25 @@ static void test_names(CuTest * tc) test_cleanup(); } +static void test_monster_names(CuTest *tc) { + unit *u; + race *rc; + + test_setup(); + register_names(); + rc = test_create_race("irongolem"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + CuAssertPtrNotNull(tc, u->_name); + rc->generate_name = (race_name_func)get_function("namegeneric"); + rc->generate_name(u); + CuAssertPtrEquals(tc, 0, u->_name); + test_cleanup(); +} + CuSuite *get_names_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_names); + SUITE_ADD_TEST(suite, test_monster_names); return suite; } From b8bccd723845ea0d55e670dbd9487ea861004e76 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 20:17:02 +0100 Subject: [PATCH 084/271] monster name pluralization changes with u->number. --- src/names.c | 6 +----- src/names.test.c | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/names.c b/src/names.c index 99c21a05e..cf1cdb910 100644 --- a/src/names.c +++ b/src/names.c @@ -221,11 +221,7 @@ const char *silbe3[SIL3] = { static void generic_name(unit * u) { - const char * name = rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL); - name = LOC(u->faction->locale, name); - if (name) { - unit_setname(u, name); - } + unit_setname(u, NULL); } static void dragon_name(unit * u) diff --git a/src/names.test.c b/src/names.test.c index 176a12a68..8109fc2d4 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -42,12 +42,18 @@ static void test_monster_names(CuTest *tc) { test_setup(); register_names(); + default_locale = test_create_locale(); + locale_setstring(default_locale, "race::irongolem", "Eisengolem"); + locale_setstring(default_locale, "race::irongolem_p", "Eisengolems"); rc = test_create_race("irongolem"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); CuAssertPtrNotNull(tc, u->_name); rc->generate_name = (race_name_func)get_function("namegeneric"); rc->generate_name(u); CuAssertPtrEquals(tc, 0, u->_name); + CuAssertStrEquals(tc, "Eisengolem", unit_getname(u)); + u->number = 2; + CuAssertStrEquals(tc, "Eisengolems", unit_getname(u)); test_cleanup(); } From d4dd9b4bc62147e5bc2aaf7d44704dec84beec98 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 21:21:23 +0100 Subject: [PATCH 085/271] enable PAY NOT in E2 --- conf/e2/config.json | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index 217cfffe9..ce823a33d 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -5,7 +5,6 @@ "e2/terrains.json" ], "disabled": [ - "pay", "jsreport" ], "settings": { From 47c8b20f680fd208b5dbe696f778ef7c562a158a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 20:54:57 +0100 Subject: [PATCH 086/271] add a happy test for mt_new. refactor to not use strncpy. --- src/test_eressea.c | 1 + src/util/CMakeLists.txt | 2 +- src/util/message.c | 20 +++++++++++--------- src/util/message.test.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/util/message.test.c diff --git a/src/test_eressea.c b/src/test_eressea.c index 71cf008f2..6d2dead3f 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -65,6 +65,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(direction); ADD_SUITE(skill); ADD_SUITE(keyword); + ADD_SUITE(message); ADD_SUITE(order); ADD_SUITE(race); /* util */ diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 7eda87132..842bcf58c 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -14,7 +14,7 @@ gamedata.test.c language.test.c # lists.test.c # log.test.c -# message.test.c +message.test.c # nrmessage.test.c parser.test.c password.test.c diff --git a/src/util/message.c b/src/util/message.c index f76409e53..23f81e095 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -87,19 +87,21 @@ message_type *mt_new(const char *name, const char *args[]) for (i = 0; args[i]; ++i) { const char *x = args[i]; const char *spos = strchr(x, ':'); - if (spos == NULL) { - mtype->pnames[i] = _strdup(x); - mtype->types[i] = NULL; + struct arg_type *atype = NULL; + if (spos != NULL) { + atype = find_argtype(spos + 1); + } + if (!atype) { + log_error("unknown argument type %s for message type %s\n", spos + 1, mtype->name); + assert(atype); } else { - char *cp = strncpy((char *)malloc(spos - x + 1), x, spos - x); + char *cp; + cp = malloc(spos - x + 1); + memcpy(cp, x, spos - x); cp[spos - x] = '\0'; mtype->pnames[i] = cp; - mtype->types[i] = find_argtype(spos + 1); - if (mtype->types[i] == NULL) { - log_error("unknown argument type %s for message type %s\n", spos + 1, mtype->name); - } - assert(mtype->types[i]); + mtype->types[i] = atype; } } } diff --git a/src/util/message.test.c b/src/util/message.test.c new file mode 100644 index 000000000..d114e33f2 --- /dev/null +++ b/src/util/message.test.c @@ -0,0 +1,29 @@ +#include +#include "message.h" + +#include +#include + +static void test_mt_new(CuTest *tc) +{ + message_type *mt; + test_setup(); + mt = mt_new_va("test", "name:string", "number:int", NULL); + CuAssertPtrNotNull(tc, mt); + CuAssertStrEquals(tc, "test", mt->name); + CuAssertIntEquals(tc, 2, mt->nparameters); + CuAssertPtrNotNull(tc, mt->pnames); + CuAssertStrEquals(tc, "name", mt->pnames[0]); + CuAssertStrEquals(tc, "number", mt->pnames[1]); + CuAssertPtrNotNull(tc, mt->types); + CuAssertStrEquals(tc, "string", mt->types[0]->name); + CuAssertStrEquals(tc, "int", mt->types[1]->name); + test_cleanup(); +} + +CuSuite *get_message_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_mt_new); + return suite; +} From d71d5e413a1eeba0e509397a1ba97969fd233fc9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:08:49 +0100 Subject: [PATCH 087/271] eliminate unnecessary strncpy use. --- src/report.c | 3 ++- src/reports.c | 6 +----- src/util/language.c | 25 ++++++++++++++++--------- src/util/language.test.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/report.c b/src/report.c index 34da143de..4e12f1261 100644 --- a/src/report.c +++ b/src/report.c @@ -413,7 +413,8 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } else { char substr[32]; - strncpy(substr, syntaxp, cstr - syntaxp); + assert(sizeof(substr) > (cstr - syntaxp)); + memcpy(substr, syntaxp, cstr - syntaxp); substr[cstr - syntaxp] = 0; locp = LOC(lang, mkname("spellpar", substr)); syntaxp = substr + 1; diff --git a/src/reports.c b/src/reports.c index 8ffb823a5..fa8a722d9 100644 --- a/src/reports.c +++ b/src/reports.c @@ -849,10 +849,6 @@ const struct unit * u, struct skill * sv, int *dh, int days) void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark) { - - /* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer - * mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf. - * Vgl. spunit (). */ bool firstline; static char buf[REPORTWIDTH + 1]; // FIXME: static buffer, artificial limit size_t len = strlen(s); @@ -883,7 +879,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned if (!cut) { cut = s + _min(len, REPORTWIDTH); } - strncpy(buf + indent, s, cut - s); + memcpy(buf + indent, s, cut - s); buf[indent + (cut - s)] = 0; addstrlist(SP, buf); // TODO: too much string copying, cut out this function while (*cut == ' ') { diff --git a/src/util/language.c b/src/util/language.c index d8b899742..cb91d7419 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -101,16 +101,23 @@ locale *get_or_create_locale(const char *name) void make_locales(const char *str) { const char *tok = str; - while (*tok) { - char zText[32]; - while (*tok && *tok != ',') - ++tok; - strncpy(zText, str, tok - str); - zText[tok - str] = 0; - get_or_create_locale(zText); - if (*tok) { - str = ++tok; + while (tok) { + char zText[16]; + size_t len; + + tok = strchr(str, ','); + if (tok) { + len = tok - str; + assert(sizeof(zText) > len); + memcpy(zText, str, len); + str = tok + 1; } + else { + len = strlen(str); + memcpy(zText, str, len); + } + zText[len] = 0; + get_or_create_locale(zText); } } diff --git a/src/util/language.test.c b/src/util/language.test.c index 236eac497..40a6775fa 100644 --- a/src/util/language.test.c +++ b/src/util/language.test.c @@ -16,9 +16,20 @@ static void test_language(CuTest *tc) test_cleanup(); } +static void test_make_locales(CuTest *tc) +{ + test_setup(); + make_locales("aa,bb,cc"); + CuAssertPtrNotNull(tc, get_locale("aa")); + CuAssertPtrNotNull(tc, get_locale("bb")); + CuAssertPtrNotNull(tc, get_locale("cc")); + test_cleanup(); +} + CuSuite *get_language_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_language); + SUITE_ADD_TEST(suite, test_make_locales); return suite; } From 2422e63af21aa44cb4d27f9119365bdbb08cc860 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:24:31 +0100 Subject: [PATCH 088/271] never use strncpy, anywhere. --- src/bind_config.c | 3 ++- src/helpers.c | 2 +- src/util/log.test.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index 3959cc22c..929e4cca0 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ int config_parse(const char *json) if (xp >= ep) break; } xp = (ep > json + 10) ? ep - 10 : json; - strncpy(buffer, xp, sizeof(buffer)); + strlcpy(buffer, xp, sizeof(buffer)); buffer[9] = 0; log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer); } diff --git a/src/helpers.c b/src/helpers.c index aa9bc12eb..e9502e075 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -167,7 +167,7 @@ static int lua_callspell(castorder * co) if (hashpos != NULL) { ptrdiff_t len = hashpos - fname; assert(len < (ptrdiff_t) sizeof(fbuf)); - strncpy(fbuf, fname, len); + memcpy(fbuf, fname, len); fbuf[len] = '\0'; fname = fbuf; } diff --git a/src/util/log.test.c b/src/util/log.test.c index 95cbefa96..55616c026 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -12,7 +12,7 @@ void log_string(void *data, int level, const char *module, const char *format, v unused_arg(format); unused_arg(module); unused_arg(level); - strncpy(str, arg, 32); + strcpy(str, arg); } static void test_logging(CuTest * tc) From 9351a1960e973ce414dd1a25fec897dcb2875805 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Jan 2017 21:37:52 +0100 Subject: [PATCH 089/271] gcc warning eliminated --- src/report.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/report.c b/src/report.c index 4e12f1261..553e6cb94 100644 --- a/src/report.c +++ b/src/report.c @@ -413,9 +413,10 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } else { char substr[32]; - assert(sizeof(substr) > (cstr - syntaxp)); - memcpy(substr, syntaxp, cstr - syntaxp); - substr[cstr - syntaxp] = 0; + size_t len = cstr - syntaxp; + assert(sizeof(substr) > len); + memcpy(substr, syntaxp, len); + substr[len] = 0; locp = LOC(lang, mkname("spellpar", substr)); syntaxp = substr + 1; } From fd759e7ff69e06b32e67fe4e103ebd21e56e4ed1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Jan 2017 20:20:13 +0100 Subject: [PATCH 090/271] remove old & unused fix_famililar repair code. --- src/bind_monsters.c | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 53a569311..4ac15aa24 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -56,34 +56,6 @@ static int tolua_spawn_undead(lua_State * L) return 0; } -static int fix_familiars(struct lua_State *L) -{ - faction *f; - for (f = factions; f; f = f->next) { - unit *u; - for (u = f->units; u; u = u->nextF) { - struct sc_mage *mage = get_mage(u); - if (mage && is_familiar(u)) { - if (mage->spellbook && mage->magietyp == M_GRAY) { - equipment *eq; - char buffer[64]; - - spellbook_clear(mage->spellbook); - free(mage->spellbook); - mage->spellbook = 0; - - _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name); - eq = get_equipment(buffer); - if (eq) { - equip_unit_mask(u, eq, EQUIP_SPELLS); - } - } - } - } - } - return 0; -} - void bind_monsters(struct lua_State *L) { tolua_module(L, NULL, 0); @@ -93,7 +65,6 @@ void bind_monsters(struct lua_State *L) tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters); tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead); tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons); - tolua_function(L, TOLUA_CAST "fix_familiars", fix_familiars); tolua_function(L, TOLUA_CAST "get_monsters", tolua_get_monsters); } tolua_endmodule(L); From 03def6ae5e552278ed5619ec7d74f81db3bb264a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Jan 2017 21:09:39 +0100 Subject: [PATCH 091/271] replace snprintf and the like. you cannot trust _snprintf in MSVC (no zero-termination). --- src/bind_storage.c | 4 +++- src/gmtool.c | 2 +- src/json.c | 6 +++--- src/kernel/item.c | 5 ++++- src/kernel/jsonconf.c | 7 ++++++- src/util/bsdstring.c | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bind_storage.c b/src/bind_storage.c index a81a3baeb..6b582e815 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -100,7 +100,9 @@ static int tolua_storage_tostring(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); char name[64]; - _snprintf(name, sizeof(name), "", (void *)data, data->version); + // safe to use sprintf here, because: + // %p is at most 16 characters, %d 20, text is 16, comes to 53 with \0 + sprintf(name, "", (void *)data, data->version); lua_pushstring(L, name); return 1; } diff --git a/src/gmtool.c b/src/gmtool.c index 7aab2fea7..b1b9a1bc1 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -1167,7 +1167,7 @@ static void handlekey(state * st, int c) region *first = (mr && mr->r && mr->r->next) ? mr->r->next : regions; if (findmode == 'f') { - snprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", locate); + slprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", locate); statusline(st->wnd_status->handle, sbuffer); f = findfaction(atoi36(locate)); if (f == NULL) { diff --git a/src/json.c b/src/json.c index 10322fe3f..2c27b9947 100644 --- a/src/json.c +++ b/src/json.c @@ -67,13 +67,13 @@ int json_export(stream * out, int flags) { cJSON *json, *root = cJSON_CreateObject(); assert(out && out->api); if (regions && (flags & EXPORT_REGIONS)) { - char id[32]; + char id[32]; // TODO: static_assert(INT_MAX < 10^32) region * r; plane * p; cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject()); for (p = planes; p; p = p->next) { cJSON *data; - _snprintf(id, sizeof(id), "%d", p->id); + sprintf(id, "%d", p->id); // safe, unless int is bigger than 64 bit cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", p->minx); cJSON_AddNumberToObject(data, "y", p->miny); @@ -85,7 +85,7 @@ int json_export(stream * out, int flags) { cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject()); for (r = regions; r; r = r->next) { cJSON *data; - _snprintf(id, sizeof(id), "%d", r->uid); + sprintf(id, "%d", r->uid); // safe, unless int is bigger than 64 bit cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "y", r->y); diff --git a/src/kernel/item.c b/src/kernel/item.c index 53fff79ab..9956f2a4a 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -156,7 +156,10 @@ const char *resourcename(const resource_type * rtype, int flags) } if (flags & NMF_PLURAL) { static char name[64]; // FIXME: static return value - _snprintf(name, sizeof(name), "%s_p", rtype->_name); + size_t len = strlen(rtype->_name); + assert(len <= sizeof(name) - 3); + memcpy(name, rtype->_name, len); + strcpy(name + len, "_p"); return name; } return rtype->_name; diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index d12238566..dccfbb68a 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -523,6 +523,8 @@ static void disable_feature(const char *str) { char name[32]; int k; skill_t sk; + size_t len; + sk = findskill(str); if (sk != NOSKILL) { enable_skill(sk, false); @@ -534,7 +536,10 @@ static void disable_feature(const char *str) { enable_keyword(k, false); return; } - _snprintf(name, sizeof(name), "%s.enabled", str); + len = strlen(str); + assert(len <= sizeof(name) - 9); + memcpy(name, str, len); + strcpy(name+len, ".enabled"); log_info("disable feature %s\n", name); config_set(name, "0"); } diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index 98d2d00f5..4fc56ce4e 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -13,7 +13,7 @@ int wrptr(char **ptr, size_t * size, int result) { size_t bytes = (size_t)result; if (result < 0) { - // _snprintf buffer was too small + // buffer was too small if (*size > 0) { **ptr = 0; *size = 0; From ae3bfc952b06f3d538d5f1cc7539cf64bb847e42 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Jan 2017 21:19:58 +0100 Subject: [PATCH 092/271] create_order takes variable arguments! more snprintf removal. --- src/give.test.c | 12 +++--------- src/kernel/jsonconf.c | 4 ++-- src/kernel/unit.test.c | 13 +++++-------- src/laws.test.c | 4 +--- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/give.test.c b/src/give.test.c index f2b0d60a9..029ee7c44 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -233,7 +233,6 @@ static void test_give_men_requires_contact(CuTest * tc) { struct give env = { 0 }; message * msg; order *ord; - char cmd[32]; test_setup_ex(tc); env.f1 = test_create_faction(0); @@ -244,8 +243,7 @@ static void test_give_men_requires_contact(CuTest * tc) { CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); - _snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no)); - ord = create_order(K_GIVE, env.f1->locale, cmd); + ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no)); test_clear_messages(env.f1); give_cmd(env.src, ord); CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person")); @@ -307,7 +305,6 @@ static void test_give(CuTest * tc) { static void test_give_cmd(CuTest * tc) { struct give env = { 0 }; struct order *ord; - char cmd[32]; test_setup_ex(tc); env.lang = test_create_locale(); @@ -316,8 +313,7 @@ static void test_give_cmd(CuTest * tc) { i_change(&env.src->items, env.itype, 10); - _snprintf(cmd, sizeof(cmd), "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); - ord = create_order(K_GIVE, env.f1->locale, cmd); + ord = create_order(K_GIVE, env.f1->locale, "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); assert(ord); give_cmd(env.src, ord); CuAssertIntEquals(tc, 5, i_get(env.src->items, env.itype)); @@ -330,7 +326,6 @@ static void test_give_cmd(CuTest * tc) { static void test_give_herbs(CuTest * tc) { struct give env = { 0 }; struct order *ord; - char cmd[32]; test_setup_ex(tc); test_create_world(); @@ -338,8 +333,7 @@ static void test_give_herbs(CuTest * tc) { setup_give(&env); i_change(&env.src->items, env.itype, 10); - _snprintf(cmd, sizeof(cmd), "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); - ord = create_order(K_GIVE, env.f1->locale, cmd); + ord = create_order(K_GIVE, env.f1->locale, "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); assert(ord); give_cmd(env.src, ord); diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index dccfbb68a..69e02c3a0 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -801,10 +801,10 @@ static void json_settings(cJSON *json) { else { char value[32]; if (child->type == cJSON_Number && child->valuedouble && child->valueintvaluedouble) { - _snprintf(value, sizeof(value), "%f", child->valuedouble); + sprintf(value, "%f", child->valuedouble); } else { - _snprintf(value, sizeof(value), "%d", child->valueint); + sprintf(value, "%d", child->valueint); } config_set(child->string, value); } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 752627144..1a481960d 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -140,37 +140,34 @@ static void test_scale_number(CuTest *tc) { static void test_unit_name(CuTest *tc) { unit *u; - char name[32]; test_cleanup(); test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); + renumber_unit(u, 666); unit_setname(u, "Hodor"); - _snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no)); - CuAssertStrEquals(tc, name, unitname(u)); + CuAssertStrEquals(tc, "Hodor (ii)", unitname(u)); test_cleanup(); } static void test_unit_name_from_race(CuTest *tc) { unit *u; - char name[32]; struct locale *lang; test_cleanup(); test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); + renumber_unit(u, 666); unit_setname(u, NULL); lang = get_or_create_locale("de"); locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch"); locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen"); - _snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no)); - CuAssertStrEquals(tc, name, unitname(u)); + CuAssertStrEquals(tc, "Mensch (ii)", unitname(u)); CuAssertStrEquals(tc, "Mensch", unit_getname(u)); u->number = 2; - _snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no)); - CuAssertStrEquals(tc, name, unitname(u)); + CuAssertStrEquals(tc, "Menschen (ii)", unitname(u)); CuAssertStrEquals(tc, "Menschen", unit_getname(u)); test_cleanup(); diff --git a/src/laws.test.c b/src/laws.test.c index 1bec0e6b4..d4753ec19 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -521,7 +521,6 @@ static void test_pay_cmd_other_building(CuTest *tc) { order *ord; faction *f; building *b; - char cmd[32]; test_setup(); setup_pay_cmd(&fix); @@ -531,8 +530,7 @@ static void test_pay_cmd_other_building(CuTest *tc) { config_set("rules.region_owner_pay_building", "lighthouse"); update_owners(b->region); - _snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no)); - ord = create_order(K_PAY, f->locale, cmd); + ord = create_order(K_PAY, f->locale, "NOT %s", itoa36(b->no)); assert(ord); CuAssertPtrEquals(tc, fix.u1, building_owner(b)); CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord)); From d94cde67a4e3ca32fc65c3f1832a74280354b8c2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 16:31:05 +0100 Subject: [PATCH 093/271] kill autoconf.h, replace platform.h for C99 compatibility work --- CMakeLists.txt | 50 ---------- autoconf.h.in | 36 ------- src/academy.c | 2 +- src/alchemy.c | 10 +- src/attributes/dict.c | 8 +- src/attributes/hate.c | 2 +- src/attributes/moved.c | 2 +- src/attributes/movement.c | 2 +- src/attributes/racename.c | 4 +- src/attributes/raceprefix.c | 4 +- src/battle.c | 66 ++++++------- src/battle.h | 1 + src/bind_building.c | 2 +- src/bind_dict.c | 2 +- src/bind_gmtool.c | 6 +- src/bind_region.c | 2 +- src/bind_ship.c | 2 +- src/building_action.c | 10 +- src/creport.c | 8 +- src/economy.c | 64 ++++++------- src/give.c | 4 +- src/gmtool.c | 4 +- src/guard.h | 3 + src/items.c | 2 +- src/items/artrewards.c | 2 +- src/items/demonseye.c | 4 +- src/items/speedsail.c | 4 +- src/items/weapons.c | 2 +- src/items/xerewards.c | 2 +- src/kernel/alliance.c | 4 +- src/kernel/ally.c | 6 +- src/kernel/build.c | 34 +++---- src/kernel/building.c | 10 +- src/kernel/building.h | 2 + src/kernel/building.test.c | 2 +- src/kernel/config.c | 13 +-- src/kernel/config.h | 1 + src/kernel/connection.c | 68 ++++++------- src/kernel/connection.h | 2 +- src/kernel/curse.c | 20 ++-- src/kernel/curse.h | 2 + src/kernel/equipment.c | 8 +- src/kernel/faction.c | 10 +- src/kernel/faction.h | 2 + src/kernel/group.c | 4 +- src/kernel/item.c | 22 ++--- src/kernel/jsonconf.c | 6 +- src/kernel/messages.c | 4 +- src/kernel/order.c | 2 +- src/kernel/plane.c | 2 +- src/kernel/pool.c | 10 +- src/kernel/race.c | 4 +- src/kernel/region.c | 16 ++-- src/kernel/region.h | 1 + src/kernel/resources.c | 4 +- src/kernel/save.c | 24 ++--- src/kernel/save.test.c | 8 +- src/kernel/ship.c | 10 +- src/kernel/spell.c | 2 +- src/kernel/spellbook.c | 2 +- src/kernel/terrain.c | 2 +- src/kernel/unit.c | 18 ++-- src/kernel/unit.test.c | 8 +- src/kernel/xmlreader.c | 24 ++--- src/laws.c | 86 ++++++++--------- src/laws.h | 1 + src/lighthouse.c | 4 +- src/lighthouse.h | 2 + src/listbox.c | 2 +- src/magic.c | 42 ++++---- src/magic.h | 1 + src/market.test.c | 2 +- src/modules/arena.c | 14 +-- src/modules/autoseed.c | 10 +- src/modules/museum.c | 8 +- src/modules/score.c | 2 +- src/monsters.c | 16 ++-- src/morale.c | 2 +- src/move.c | 24 ++--- src/move.h | 5 +- src/names.c | 6 +- src/platform.h | 180 ++--------------------------------- src/prefix.c | 2 +- src/races/dragons.c | 2 +- src/races/races.c | 2 +- src/races/zombies.c | 8 +- src/randenc.c | 4 +- src/report.c | 80 ++++++++-------- src/report.test.c | 6 +- src/reports.c | 44 ++++----- src/skill.h | 2 +- src/spells.c | 103 ++++++++++---------- src/spells/borders.c | 8 +- src/spells/borders.h | 3 + src/spells/buildingcurse.c | 2 +- src/spells/combatspells.c | 30 +++--- src/spells/flyingship.h | 2 + src/spells/regioncurse.c | 28 +++--- src/spells/shipcurse.c | 6 +- src/spells/unitcurse.c | 16 ++-- src/spy.c | 6 +- src/sqlite.c | 4 +- src/study.c | 18 ++-- src/summary.c | 8 +- src/test_eressea.c | 2 +- src/travelthru.test.c | 2 +- src/triggers/changefaction.c | 2 +- src/triggers/changerace.c | 2 +- src/triggers/clonedied.c | 2 +- src/triggers/createcurse.c | 2 +- src/triggers/createunit.c | 2 +- src/triggers/gate.c | 2 +- src/triggers/giveitem.c | 2 +- src/triggers/killunit.c | 2 +- src/triggers/shock.c | 6 +- src/triggers/timeout.c | 2 +- src/triggers/unitmessage.c | 6 +- src/upkeep.c | 12 +-- src/util/attrib.c | 2 +- src/util/attrib.h | 2 + src/util/attrib.test.c | 2 +- src/util/crmessage.c | 10 +- src/util/event.c | 4 +- src/util/goodies.c | 2 +- src/util/language.c | 8 +- src/util/language.h | 2 +- src/util/lists.c | 2 +- src/util/log.test.c | 6 +- src/util/message.c | 2 +- src/util/nrmessage.c | 6 +- src/util/translation.c | 12 +-- src/vortex.c | 14 +-- src/vortex.h | 5 + src/wormhole.c | 2 +- 134 files changed, 683 insertions(+), 902 deletions(-) delete mode 100644 autoconf.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f6b931e61..c08e16c20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,56 +14,6 @@ find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) -INCLUDE (CheckIncludeFiles) -INCLUDE (CheckSymbolExists) -CHECK_INCLUDE_FILES (stdbool.h HAVE_STDBOOL_H) -CHECK_INCLUDE_FILES (windows.h HAVE_WINDOWS_H) -CHECK_INCLUDE_FILES (io.h HAVE_IO_H) -CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H) -CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) -IF (HAVE_IO_H) -CHECK_SYMBOL_EXISTS (_access "io.h" HAVE__ACCESS) -ENDIF (HAVE_IO_H) -IF (HAVE_WINDOWS_H) -CHECK_SYMBOL_EXISTS (_sleep "windows.h" HAVE__SLEEP) -ENDIF(HAVE_WINDOWS_H) -IF(HAVE_STDBOOL_H) -CHECK_SYMBOL_EXISTS (_Bool "stdbool.h" HAVE__BOOL) -ENDIF(HAVE_STDBOOL_H) -IF(HAVE_UNISTD_H) -CHECK_SYMBOL_EXISTS (sleep "unistd.h" HAVE_SLEEP) -CHECK_SYMBOL_EXISTS (usleep "unistd.h" HAVE_USLEEP) -CHECK_SYMBOL_EXISTS (access "unistd.h" HAVE_ACCESS) -ENDIF(HAVE_UNISTD_H) -CHECK_SYMBOL_EXISTS (strlcpy "string.h" HAVE_STRLCPY) -CHECK_SYMBOL_EXISTS (strlcat "string.h" HAVE_STRLCAT) -CHECK_SYMBOL_EXISTS (slprintf "string.h" HAVE_SLPRINTF) -CHECK_SYMBOL_EXISTS (strcasecmp "string.h" HAVE_STRCASECMP) -CHECK_SYMBOL_EXISTS (strncasecmp "string.h" HAVE_STRNCASECMP) -CHECK_SYMBOL_EXISTS (_strlwr "string.h" HAVE__STRLWR) -CHECK_SYMBOL_EXISTS (_strcmpl "string.h" HAVE__STRCMPL) -CHECK_SYMBOL_EXISTS (_strdup "string.h" HAVE__STRDUP) -CHECK_SYMBOL_EXISTS (_stricmp "string.h" HAVE__STRICMP) -CHECK_SYMBOL_EXISTS (_memicmp "string.h" HAVE__MEMICMP) -CHECK_SYMBOL_EXISTS (strcmpl "string.h" HAVE_STRCMPL) -CHECK_SYMBOL_EXISTS (strdup "string.h" HAVE_STRDUP) -CHECK_SYMBOL_EXISTS (stricmp "string.h" HAVE_STRICMP) -CHECK_SYMBOL_EXISTS (memicmp "string.h" HAVE_MEMICMP) -CHECK_SYMBOL_EXISTS (strlwr "string.h" HAVE_STRLWR) -CHECK_SYMBOL_EXISTS (snprintf "stdio.h" HAVE_SNPRINTF) -CHECK_SYMBOL_EXISTS (_snprintf "stdio.h" HAVE__SNPRINTF) -CHECK_SYMBOL_EXISTS (mkdir "sys/stat.h" HAVE_SYS_STAT_MKDIR) -CHECK_SYMBOL_EXISTS (mkdir "direct.h" HAVE_DIRECT_MKDIR) -CHECK_SYMBOL_EXISTS (_mkdir "direct.h" HAVE_DIRECT__MKDIR) - -CONFIGURE_FILE ( - ${CMAKE_CURRENT_SOURCE_DIR}/autoconf.h.in - ${CMAKE_BINARY_DIR}/include/autoconf.h) -INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include) - -## skip compiler/libc detection and force cmake autoconf: -#add_definitions(-DUSE_AUTOCONF) - add_subdirectory (cJSON) add_subdirectory (storage) add_subdirectory (iniparser) diff --git a/autoconf.h.in b/autoconf.h.in deleted file mode 100644 index f3f197db1..000000000 --- a/autoconf.h.in +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#ifndef CMAKE_AUTOCONF_H -#define CMAKE_AUTOCONF_H -#cmakedefine HAVE_STDBOOL_H 1 -#cmakedefine HAVE_STRINGS_H 1 -#cmakedefine HAVE_WINDOWS_H 1 -#cmakedefine HAVE_IO_H 1 -#cmakedefine HAVE_UNISTD_H 1 -#cmakedefine HAVE__BOOL 1 -#cmakedefine HAVE_STRCASECMP 1 -#cmakedefine HAVE_STRNCASECMP 1 -#cmakedefine HAVE__STRICMP 1 -#cmakedefine HAVE_SNPRINTF 1 -#cmakedefine HAVE__SNPRINTF 1 -#cmakedefine HAVE_ACCESS 1 -#cmakedefine HAVE__ACCESS 1 -#cmakedefine HAVE_SLEEP 1 -#cmakedefine HAVE_USLEEP 1 -#cmakedefine HAVE__SLEEP 1 -#cmakedefine HAVE_STRDUP 1 -#cmakedefine HAVE__STRDUP 1 -#cmakedefine HAVE_STRICMP 1 -#cmakedefine HAVE__STRCMPL 1 -#cmakedefine HAVE_STRCMPL 1 -#cmakedefine HAVE__MEMICMP 1 -#cmakedefine HAVE_MEMICMP 1 -#cmakedefine HAVE__STRLWR 1 -#cmakedefine HAVE_STRLWR 1 -#cmakedefine HAVE_STRLCPY 1 -#cmakedefine HAVE_STRLCAT 1 -#cmakedefine HAVE_SLPRINTF 1 -#cmakedefine HAVE_SYS_STAT_MKDIR 1 -#cmakedefine HAVE_DIRECT_MKDIR 1 -#cmakedefine HAVE_DIRECT__MKDIR 1 - -#endif diff --git a/src/academy.c b/src/academy.c index f6b70873e..496c1ef8e 100644 --- a/src/academy.c +++ b/src/academy.c @@ -35,7 +35,7 @@ bool academy_can_teach(unit *teacher, unit *student, skill_t sk) { const struct building_type *btype = bt_find("academy"); if (active_building(teacher, btype) && active_building(student, btype)) { int j = study_cost(student, sk); - j = _max(50, j * 2); + j = MAX(50, j * 2); /* kann Einheit das zahlen? */ return get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j; /* sonst nehmen sie nicht am Unterricht teil */ diff --git a/src/alchemy.c b/src/alchemy.c index 9bc180700..ddbe46b8e 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -73,12 +73,12 @@ void herbsearch(unit * u, int max) } if (max) - max = _min(max, rherbs(r)); + max = MIN(max, rherbs(r)); else max = rherbs(r); herbsfound = ntimespprob(effsk * u->number, (double)rherbs(r) / 100.0F, -0.01F); - herbsfound = _min(herbsfound, max); + herbsfound = MIN(herbsfound, max); rsetherbs(r, (short) (rherbs(r) - herbsfound)); if (herbsfound) { @@ -156,7 +156,7 @@ static int potion_water_of_life(unit * u, region *r, int amount) { } static int potion_healing(unit * u, int amount) { - u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount); + u->hp = MIN(unit_max_hp(u) * u->number, u->hp + 400 * amount); return amount; } @@ -182,7 +182,7 @@ static int potion_power(unit *u, int amount) { amount = use; } /* Verf�nffacht die HP von max. 10 Personen in der Einheit */ - u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4; + u->hp += MIN(u->number, 10 * amount) * unit_max_hp(u) * 4; return amount; } @@ -248,7 +248,7 @@ static void free_potiondelay(attrib * a) { static int age_potiondelay(attrib * a, void *owner) { potiondelay *pd = (potiondelay *)a->data.v; - unused_arg(owner); + UNUSED_ARG(owner); pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount); return AT_AGE_REMOVE; } diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 2bba9ea7b..a3f034145 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -103,7 +103,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data) float flt; READ_STR(store, name, sizeof(name)); - dd->name = _strdup(name); + dd->name = strdup(name); READ_INT(store, &n); dd->type = (dict_type)n; switch (dd->type) { @@ -122,7 +122,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data) break; case TSTRING: READ_STR(store, name, sizeof(name)); - dd->data.str = _strdup(name); + dd->data.str = strdup(name); break; case TBUILDING: result = @@ -199,7 +199,7 @@ struct attrib *dict_create(const char *name, dict_type type, variant value) { attrib *a = a_new(&at_dict); dict_data *data = (dict_data *)a->data.v; - data->name = _strdup(name); + data->name = strdup(name); dict_set(a, type, value); return a; @@ -214,7 +214,7 @@ void dict_set(attrib * a, dict_type type, variant value) data->type = type; switch (type) { case TSTRING: - data->data.str = value.v ? _strdup(value.v) : NULL; + data->data.str = value.v ? strdup(value.v) : NULL; break; case TINTEGER: data->data.i = value.i; diff --git a/src/attributes/hate.c b/src/attributes/hate.c index 98a36a029..17155fc71 100644 --- a/src/attributes/hate.c +++ b/src/attributes/hate.c @@ -30,7 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int verify_hate(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); if (a->data.v == NULL) { return 0; } diff --git a/src/attributes/moved.c b/src/attributes/moved.c index 3da2a4c3b..c66a5489c 100644 --- a/src/attributes/moved.c +++ b/src/attributes/moved.c @@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int age_moved(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); --a->data.i; return a->data.i > 0; } diff --git a/src/attributes/movement.c b/src/attributes/movement.c index 874da5eb3..4d79039ef 100644 --- a/src/attributes/movement.c +++ b/src/attributes/movement.c @@ -67,7 +67,7 @@ void set_movement(attrib ** alist, int type) static int age_speedup(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); if (a->data.sa[0] > 0) { assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN); assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX); diff --git a/src/attributes/racename.c b/src/attributes/racename.c index b408cbf6a..c45fa3815 100644 --- a/src/attributes/racename.c +++ b/src/attributes/racename.c @@ -43,7 +43,7 @@ void set_racename(attrib ** palist, const char *name) attrib *a = a_find(*palist, &at_racename); if (!a && name) { a = a_add(palist, a_new(&at_racename)); - a->data.v = _strdup(name); + a->data.v = strdup(name); } else if (a && !name) { a_remove(palist, a); @@ -51,7 +51,7 @@ void set_racename(attrib ** palist, const char *name) else if (a) { if (strcmp(a->data.v, name) != 0) { free(a->data.v); - a->data.v = _strdup(name); + a->data.v = strdup(name); } } } diff --git a/src/attributes/raceprefix.c b/src/attributes/raceprefix.c index 15f0036c1..a87edfb80 100644 --- a/src/attributes/raceprefix.c +++ b/src/attributes/raceprefix.c @@ -41,7 +41,7 @@ void set_prefix(attrib ** ap, const char *str) free(a->data.v); } assert(a->type == &at_raceprefix); - a->data.v = _strdup(str); + a->data.v = strdup(str); } const char *get_prefix(attrib * a) @@ -53,7 +53,7 @@ const char *get_prefix(attrib * a) str = (char *)a->data.v; /* conversion of old prefixes */ if (strncmp(str, "prefix_", 7) == 0) { - ((attrib *)a)->data.v = _strdup(str + 7); + ((attrib *)a)->data.v = strdup(str + 7); free(str); str = (char *)a->data.v; } diff --git a/src/battle.c b/src/battle.c index 9d2d09cc0..550449ddd 100644 --- a/src/battle.c +++ b/src/battle.c @@ -440,7 +440,7 @@ static int get_row(const side * s, int row, const side * vs) /* every entry in the size[] array means someone trying to defend us. * 'retreat' is the number of rows falling. */ - result = _max(FIRST_ROW, row - retreat); + result = MAX(FIRST_ROW, row - retreat); return result; } @@ -600,12 +600,12 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking) if (u_race(u) == get_race(RC_ORC)) { int sword = effskill(u, SK_MELEE, 0); int spear = effskill(u, SK_SPEAR, 0); - skill = _max(sword, spear) - 3; + skill = MAX(sword, spear) - 3; if (attacking) { - skill = _max(skill, u_race(u)->at_default); + skill = MAX(skill, u_race(u)->at_default); } else { - skill = _max(skill, u_race(u)->df_default); + skill = MAX(skill, u_race(u)->df_default); } } else { @@ -685,7 +685,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type) /* only half against trolls */ if (skl > 0) { if (type == BONUS_SKILL) { - int dmg = _min(skl, 8); + int dmg = MIN(skl, 8); if (u_race(enemy.fighter->unit) == get_race(RC_TROLL)) { dmg = dmg / 4; } @@ -696,7 +696,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type) } else { skl = skl / 2; - return _min(skl, 4); + return MIN(skl, 4); } } } @@ -1008,7 +1008,7 @@ static void vampirism(troop at, int damage) if (gain > 0) { int maxhp = unit_max_hp(at.fighter->unit); at.fighter->person[at.index].hp = - _min(gain + at.fighter->person[at.index].hp, maxhp); + MIN(gain + at.fighter->person[at.index].hp, maxhp); } } } @@ -1203,15 +1203,15 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* TODO not sure if res could be > 1 here */ if (magic) { - da = (int)(_max(da * res, 0)); + da = (int)(MAX(da * res, 0)); } if (type != AT_COMBATSPELL && type != AT_SPELL) { if (rule_damage & DAMAGE_CRITICAL) { double kritchance = (sk * 3 - sd) / 200.0; - kritchance = _max(kritchance, 0.005); - kritchance = _min(0.9, kritchance); + kritchance = MAX(kritchance, 0.005); + kritchance = MIN(0.9, kritchance); while (chance(kritchance)) { if (bdebug) { @@ -1238,11 +1238,11 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* Skilldifferenzbonus */ if (rule_damage & DAMAGE_SKILL_BONUS) { - da += _max(0, (sk - sd) / DAMAGE_QUOTIENT); + da += MAX(0, (sk - sd) / DAMAGE_QUOTIENT); } } - rda = _max(da - ar, 0); + rda = MAX(da - ar, 0); if ((u_race(du)->battle_flags & BF_INV_NONMAGIC) && !magic) rda = 0; @@ -1275,7 +1275,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) } /* gibt R�stung +effect f�r duration Treffer */ if (me->typ == SHIELD_ARMOR) { - rda = _max(rda - me->effect, 0); + rda = MAX(rda - me->effect, 0); me->duration--; } } @@ -1474,7 +1474,7 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select) minrow = FIGHT_ROW; maxrow = BEHIND_ROW; } - minrow = _max(minrow, FIGHT_ROW); + minrow = MAX(minrow, FIGHT_ROW); enemies = count_enemies(b, af, minrow, maxrow, select); @@ -1574,7 +1574,7 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist) dt = select_enemy(at.fighter, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); } else { - mindist = _max(mindist, FIGHT_ROW); + mindist = MAX(mindist, FIGHT_ROW); dt = select_enemy(at.fighter, mindist, maxdist, SELECT_ADVANCE); } @@ -1735,7 +1735,7 @@ void do_combatmagic(battle * b, combatmagic_t was) level = eff_spelllevel(mage, sp, level, 1); if (sl > 0) - level = _min(sl, level); + level = MIN(sl, level); if (level < 0) { report_failed_spell(b, mage, sp); free_order(ord); @@ -1822,7 +1822,7 @@ static void do_combatspell(troop at) level = eff_spelllevel(caster, sp, fi->magic, 1); if ((sl = get_combatspelllevel(caster, 1)) > 0) - level = _min(level, sl); + level = MIN(level, sl); if (fumble(r, caster, sp, level)) { report_failed_spell(b, caster, sp); @@ -2056,7 +2056,7 @@ void dazzle(battle * b, troop * td) void damage_building(battle * b, building * bldg, int damage_abs) { - bldg->size = _max(1, bldg->size - damage_abs); + bldg->size = MAX(1, bldg->size - damage_abs); /* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb�ude passen. */ @@ -2332,7 +2332,7 @@ void do_regenerate(fighter * af) while (ta.index--) { struct person *p = af->person + ta.index; p->hp += effskill(au, SK_STAMINA, 0); - p->hp = _min(unit_max_hp(au), p->hp); + p->hp = MIN(unit_max_hp(au), p->hp); } } @@ -2391,10 +2391,10 @@ double fleechance(unit * u) if (u_race(u) == get_race(RC_HALFLING)) { c += 0.20; - c = _min(c, 0.90); + c = MIN(c, 0.90); } else { - c = _min(c, 0.75); + c = MIN(c, 0.75); } if (a != NULL) @@ -2518,7 +2518,7 @@ static void loot_items(fighter * corpse) float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */ int maxloot = (int)((float)itm->number * lootfactor); if (maxloot > 0) { - int i = _min(10, maxloot); + int i = MIN(10, maxloot); for (; i != 0; --i) { int loot = maxloot / i; @@ -2599,7 +2599,7 @@ static void battle_effects(battle * b, int dead_players) { region *r = b->region; int dead_peasants = - _min(rpeasants(r), (int)(dead_players * PopulationDamage())); + MIN(rpeasants(r), (int)(dead_players * PopulationDamage())); if (dead_peasants) { deathcounts(r, dead_peasants + dead_players); add_chaoscount(r, dead_peasants / 2); @@ -3092,7 +3092,7 @@ static void print_stats(battle * b) for (s = b->sides; s != b->sides + b->nsides; ++s) { if (!selist_empty(s->leader.fighters)) { - b->max_tactics = _max(b->max_tactics, s->leader.value); + b->max_tactics = MAX(b->max_tactics, s->leader.value); } } @@ -3258,7 +3258,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) /* change_effect wird in ageing gemacht */ /* Effekte von Artefakten */ - strongmen = _min(fig->unit->number, trollbelts(u)); + strongmen = MIN(fig->unit->number, trollbelts(u)); /* Hitpoints, Attack- und Defence-Boni f�r alle Personen */ for (i = 0; i < fig->alive; i++) { @@ -3448,7 +3448,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) else p_bonus += 3; } while (rnd >= 97); - bonus = _max(p_bonus, bonus); + bonus = MAX(p_bonus, bonus); } tactics += bonus; } @@ -3519,11 +3519,11 @@ static const char *simplename(region * r) const char *cp = rname(r, default_locale); for (i = 0; *cp && i != 16; ++i, ++cp) { int c = *(unsigned char *)cp; - while (c && !isalpha(c) && !isxspace(c)) { + while (c && !isalpha(c) && !isspace(c)) { ++cp; c = *(unsigned char *)cp; } - if (isxspace(c)) + if (isspace(c)) name[i] = '_'; else name[i] = *cp; @@ -3546,10 +3546,10 @@ battle *make_battle(region * r) bld->sizeleft = bld->size; if (battledebug) { - char zText[MAX_PATH]; - char zFilename[MAX_PATH]; + char zText[4096]; + char zFilename[4096]; join_path(basepath(), "battles", zText, sizeof(zText)); - if (_mkdir(zText) != 0) { + if (mkdir(zText, 0777) != 0) { log_error("could not create subdirectory for battle logs: %s", zText); battledebug = false; } @@ -4104,7 +4104,7 @@ static void battle_flee(battle * b) troop dt; int runners = 0; /* Flucht nicht bei mehr als 600 HP. Damit Wyrme t�tbar bleiben. */ - int runhp = _min(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status))); + int runhp = MIN(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status))); if (u->ship && fval(u->region->terrain, SEA_REGION)) { /* keine Flucht von Schiffen auf hoher See */ @@ -4147,7 +4147,7 @@ static void battle_flee(battle * b) if (fig->person[dt.index].flags & FL_PANICED) { ispaniced = EFFECT_PANIC_SPELL; } - if (chance(_min(fleechance(u) + ispaniced, 0.90))) { + if (chance(MIN(fleechance(u) + ispaniced, 0.90))) { ++runners; flee(dt); } diff --git a/src/battle.h b/src/battle.h index cee894b6c..dbdc7e1cb 100644 --- a/src/battle.h +++ b/src/battle.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_BATTLE #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/bind_building.c b/src/bind_building.c index 3724d4db5..f8cf4e6df 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -92,7 +92,7 @@ static int tolua_building_set_info(lua_State * L) const char *info = tolua_tostring(L, 2, 0); free(self->display); if (info) - self->display = _strdup(info); + self->display = strdup(info); else self->display = NULL; return 0; diff --git a/src/bind_dict.c b/src/bind_dict.c index 32d3c498d..40f73690f 100644 --- a/src/bind_dict.c +++ b/src/bind_dict.c @@ -106,7 +106,7 @@ static int tolua_dict_set_string(lua_State * L) attrib *a = a_find(*self, &at_dict); variant val; - val.v = _strdup(value); + val.v = strdup(value); for (; a && a->type == &at_dict; a = a->next) { if (strcmp(dict_name(a), name) == 0) { diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index 3c07bb3b7..e4ae939f9 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -133,14 +133,14 @@ static int tolua_selected_regions(lua_State * L) static int tolua_state_open(lua_State * L) { - unused_arg(L); + UNUSED_ARG(L); state_open(); return 0; } static int tolua_state_close(lua_State * L) { - unused_arg(L); + UNUSED_ARG(L); state_close(current_state); return 0; } @@ -188,7 +188,7 @@ static void lua_paint_info(struct window *wnd, const struct state *st) break; else { size_t len = end - str; - int bytes = _min((int)len, size); + int bytes = MIN((int)len, size); mvwaddnstr(win, line++, 1, str, bytes); wclrtoeol(win); str = end + 1; diff --git a/src/bind_region.c b/src/bind_region.c index 1296e4a65..2e328dc96 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -615,7 +615,7 @@ static int tolua_plane_set_name(lua_State * L) const char *str = tolua_tostring(L, 2, 0); free(self->name); if (str) - self->name = _strdup(str); + self->name = strdup(str); else self->name = 0; return 0; diff --git a/src/bind_ship.c b/src/bind_ship.c index f1c1c412a..95006cf5f 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -94,7 +94,7 @@ static int tolua_ship_set_display(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); free(self->display); - self->display = _strdup(tolua_tostring(L, 2, 0)); + self->display = strdup(tolua_tostring(L, 2, 0)); return 0; } diff --git a/src/building_action.c b/src/building_action.c index 5c533f4d0..f72af4412 100644 --- a/src/building_action.c +++ b/src/building_action.c @@ -93,7 +93,7 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store) const char *fname = data->fname; const char *fparam = data->param; - unused_arg(owner); + UNUSED_ARG(owner); WRITE_TOK(store, fname); WRITE_TOK(store, fparam ? fparam : NULLSTRING); } @@ -116,7 +116,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data) b = 0; } else { - bd->fname = _strdup(name); + bd->fname = strdup(name); } READ_TOK(store, name, sizeof(name)); if (strcmp(name, "tnnL") == 0) { @@ -127,7 +127,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data) if (strcmp(name, NULLSTRING) == 0) bd->param = 0; else { - bd->param = _strdup(name); + bd->param = strdup(name); } if (result == 0 && !b) { return AT_READ_FAIL; @@ -146,8 +146,8 @@ void building_addaction(building * b, const char *fname, const char *param) { attrib *a = a_add(&b->attribs, a_new(&at_building_action)); building_action *data = (building_action *)a->data.v; - data->fname = _strdup(fname); + data->fname = strdup(fname); if (param) { - data->param = _strdup(param); + data->param = strdup(param); } } diff --git a/src/creport.c b/src/creport.c index 6cd9b7a27..5e01433d4 100644 --- a/src/creport.c +++ b/src/creport.c @@ -125,7 +125,7 @@ static const char *translate(const char *key, const char *value) } else t = malloc(sizeof(translation)); - t->key = _strdup(key); + t->key = strdup(key); t->value = value; t->next = translation_table[kk]; translation_table[kk] = t; @@ -361,7 +361,7 @@ static int cr_race(variant var, char *buffer, const void *userdata) static int cr_alliance(variant var, char *buffer, const void *userdata) { const alliance *al = (const alliance *)var.v; - unused_arg(userdata); + UNUSED_ARG(userdata); if (al != NULL) { sprintf(buffer, "%d", al->id); } @@ -372,7 +372,7 @@ static int cr_skill(variant var, char *buffer, const void *userdata) { const faction *report = (const faction *)userdata; skill_t sk = (skill_t)var.i; - unused_arg(userdata); + UNUSED_ARG(userdata); if (sk != NOSKILL) sprintf(buffer, "\"%s\"", translate(mkname("skill", skillnames[sk]), skillname(sk, @@ -385,7 +385,7 @@ static int cr_skill(variant var, char *buffer, const void *userdata) static int cr_order(variant var, char *buffer, const void *userdata) { order *ord = (order *)var.v; - unused_arg(userdata); + UNUSED_ARG(userdata); if (ord != NULL) { char cmd[ORDERSIZE]; char *wp = buffer; diff --git a/src/economy.c b/src/economy.c index 01954ff54..7edbbcb12 100644 --- a/src/economy.c +++ b/src/economy.c @@ -337,11 +337,11 @@ static int do_recruiting(recruitment * recruits, int available) int number, dec; double multi = 2.0 * rc->recruit_multi; - number = _min(req->qty, (int)(get / multi)); + number = MIN(req->qty, (int)(get / multi)); if (rc->recruitcost) { int afford = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, number * rc->recruitcost) / rc->recruitcost; - number = _min(number, afford); + number = MIN(number, afford); } if (u->number + number > UNIT_MAXSIZE) { ADDMSG(&u->faction->msgs, msg_feedback(u, req->ord, "error_unit_size", @@ -551,7 +551,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) if (recruitcost > 0) { int pooled = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, recruitcost * n); - n = _min(n, pooled / recruitcost); + n = MIN(n, pooled / recruitcost); } u->wants = n; @@ -990,12 +990,12 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) rring = get_resourcetype(R_RING_OF_NIMBLEFINGER); if (rring) { int dm = i_get(u->items, rring->itype); - amount += skill * _min(u->number, dm) * (roqf_factor() - 1); + amount += skill * MIN(u->number, dm) * (roqf_factor() - 1); } /* Schaffenstrunk: */ if ((dm = get_effect(u, oldpotiontype[P_DOMORE])) != 0) { - dm = _min(dm, u->number); + dm = MIN(dm, u->number); change_effect(u, oldpotiontype[P_DOMORE], -dm); amount += dm * skill; /* dm Personen produzieren doppelt */ } @@ -1091,7 +1091,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) } need = norders; - avail = _min(avail, norders); + avail = MIN(avail, norders); if (need > 0) { int use = 0; for (al = alist; al; al = al->next) @@ -1106,7 +1106,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) use += x; norders -= want; need -= x; - al->get = _min(al->want, al->get + (int)(x / al->save)); + al->get = MIN(al->want, al->get + (int)(x / al->save)); } } if (use) { @@ -1139,7 +1139,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) avail = 0; } - avail = _min(avail, norders); + avail = MIN(avail, norders); for (al = alist; al; al = al->next) { if (avail > 0) { int want = required(al->want, al->save); @@ -1149,7 +1149,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) ++x; avail -= x; norders -= want; - al->get = _min(al->want, (int)(x / al->save)); + al->get = MIN(al->want, (int)(x / al->save)); if (rdata->produce) { int use = required(al->get, al->save); if (use) @@ -1625,7 +1625,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) k -= a->data.i; } - n = _min(n, k); + n = MIN(n, k); if (!n) { cmistake(u, ord, 102, MSG_COMMERCE); @@ -1936,7 +1936,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) /* Ein Händler kann nur 10 Güter pro Talentpunkt verkaufen. */ - n = _min(n, u->number * 10 * effskill(u, SK_TRADE, 0)); + n = MIN(n, u->number * 10 * effskill(u, SK_TRADE, 0)); if (!n) { cmistake(u, ord, 54, MSG_COMMERCE); @@ -1966,11 +1966,11 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) if (o->type.ltype == ltype && o->unit->faction == u->faction) { int fpool = o->qty - get_pooled(o->unit, itype->rtype, GET_RESERVE, INT_MAX); - available -= _max(0, fpool); + available -= MAX(0, fpool); } } - n = _min(n, available); + n = MIN(n, available); if (n <= 0) { cmistake(u, ord, 264, MSG_COMMERCE); @@ -1995,7 +1995,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) k -= a->data.i; } - n = _min(n, k); + n = MIN(n, k); assert(n >= 0); /* die Menge der verkauften Güter merken */ a->data.i += n; @@ -2052,7 +2052,7 @@ static void expandstealing(region * r, request * stealorders) n = 10; } if (n > 0) { - n = _min(n, g_requests[j].unit->wants); + n = MIN(n, g_requests[j].unit->wants); use_pooled(u, rsilver, GET_ALL, n); g_requests[j].unit->n = n; change_money(g_requests[j].unit, n); @@ -2106,8 +2106,8 @@ static void plant(unit * u, int raw) return; } - n = _min(skill * u->number, n); - n = _min(raw, n); + n = MIN(skill * u->number, n); + n = MIN(raw, n); /* Für jedes Kraut Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) @@ -2152,14 +2152,14 @@ static void planttrees(unit * u, int raw) } /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ - raw = _min(raw, skill * u->number); + raw = MIN(raw, skill * u->number); n = get_pooled(u, rtype, GET_DEFAULT, raw); if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } - n = _min(raw, n); + n = MIN(raw, n); /* Für jeden Samen Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { @@ -2209,7 +2209,7 @@ static void breedtrees(unit * u, int raw) } /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ - raw = _min(skill * u->number, raw); + raw = MIN(skill * u->number, raw); n = get_pooled(u, rtype, GET_DEFAULT, raw); /* Samen prüfen */ if (n == 0) { @@ -2217,7 +2217,7 @@ static void breedtrees(unit * u, int raw) msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } - n = _min(raw, n); + n = MIN(raw, n); /* Für jeden Samen Talent*5% Erfolgschance. */ for (i = n; i > 0; i--) { @@ -2259,7 +2259,7 @@ static void breedhorses(unit * u) } effsk = effskill(u, SK_HORSE_TRAINING, 0); n = u->number * effsk; - n = _min(n, horses); + n = MIN(n, horses); for (c = 0; c < n; c++) { if (rng_int() % 100 < effsk) { @@ -2508,7 +2508,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) } } - i = _min(u->number, i_get(u->items, rring->itype)); + i = MIN(u->number, i_get(u->items, rring->itype)); if (i > 0) { n *= STEALINCOME * (u->number + i * (roqf_factor() - 1)); } @@ -2530,7 +2530,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - produceexp(u, SK_STEALTH, _min(n, u->number)); + produceexp(u, SK_STEALTH, MIN(n, u->number)); } /* ------------------------------------------------------------- */ @@ -2554,7 +2554,7 @@ static void expandentertainment(region * r) entertaining -= o->qty; /* Nur soviel PRODUCEEXP wie auch tatsächlich gemacht wurde */ - produceexp(u, SK_ENTERTAINMENT, _min(u->n, u->number)); + produceexp(u, SK_ENTERTAINMENT, MIN(u->n, u->number)); add_income(u, IC_ENTERTAIN, o->qty, u->n); fset(u, UFL_LONGACTION | UFL_NOTMOVING); } @@ -2605,7 +2605,7 @@ void entertain_cmd(unit * u, struct order *ord) max_e = getuint(); if (max_e != 0) { - u->wants = _min(u->wants, max_e); + u->wants = MIN(u->wants, max_e); } o = nextentertainer++; o->unit = u; @@ -2665,7 +2665,7 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork) if (blessedharvest_ct) { int happy = (int)curse_geteffect(get_curse(r->attribs, blessedharvest_ct)); - happy = _min(happy, jobs); + happy = MIN(happy, jobs); earnings += happy; } } @@ -2819,10 +2819,10 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) max = INT_MAX; } if (!playerrace(u_race(u))) { - u->wants = _min(income(u), max); + u->wants = MIN(income(u), max); } else { - u->wants = _min(n * effskill(u, SK_TAXING, 0) * taxperlevel, max); + u->wants = MIN(n * effskill(u, SK_TAXING, 0) * taxperlevel, max); } u2 = is_guarded(r, u); @@ -2893,12 +2893,12 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders) max = INT_MAX; } if (!playerrace(u_race(u))) { - u->wants = _min(income(u), max); + u->wants = MIN(income(u), max); } else { /* For player start with 20 Silver +10 every 5 level of close combat skill*/ - int skbonus = (_max(effskill(u, SK_MELEE, 0), effskill(u, SK_SPEAR, 0)) * 2 / 10) + 2; - u->wants = _min(n * skbonus * 10, max); + int skbonus = (MAX(effskill(u, SK_MELEE, 0), effskill(u, SK_SPEAR, 0)) * 2 / 10) + 2; + u->wants = MIN(n * skbonus * 10, max); } o = (request *)calloc(1, sizeof(request)); diff --git a/src/give.c b/src/give.c index 524a27017..4f8417bf2 100644 --- a/src/give.c +++ b/src/give.c @@ -156,7 +156,7 @@ struct order *ord) assert(itype != NULL); n = get_pooled(src, item2resource(itype), GET_SLACK | GET_POOLED_SLACK, want); - n = _min(want, n); + n = MIN(want, n); r = n; if (dest && src->faction != dest->faction && src->faction->age < GiveRestriction()) { @@ -772,7 +772,7 @@ void give_cmd(unit * u, order * ord) msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); return; } - n = _min(u->number, n); + n = MIN(u->number, n); msg = u2 ? give_men(n, u, u2, ord) : disband_men(n, u, ord); if (msg) { ADDMSG(&u->faction->msgs, msg); diff --git a/src/gmtool.c b/src/gmtool.c index b1b9a1bc1..3db673731 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -427,7 +427,7 @@ static void paint_info_region(window * wnd, const state * st) int line = 0, maxline = getmaxy(win) - 2; map_region *mr = cursor_region(&st->display, &st->cursor); - unused_arg(st); + UNUSED_ARG(st); werase(win); wxborder(win); if (mr && mr->r) { @@ -1398,7 +1398,7 @@ int curses_readline(struct lua_State *L, char *buffer, size_t size, const char *prompt) { - unused_arg(L); + UNUSED_ARG(L); askstring(hstatus, prompt, buffer, size); return buffer[0] != 0; } diff --git a/src/guard.h b/src/guard.h index 4fb6cbf56..101369f40 100644 --- a/src/guard.h +++ b/src/guard.h @@ -2,6 +2,9 @@ #ifndef H_GUARD #define H_GUARD + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/items.c b/src/items.c index 6fbf957b3..6e995edaa 100644 --- a/src/items.c +++ b/src/items.c @@ -122,7 +122,7 @@ struct order *ord) double force; spell *sp = find_spell("antimagiczone"); attrib **ap = &r->attribs; - unused_arg(ord); + UNUSED_ARG(ord); assert(sp); /* Reduziert die Stärke jedes Spruchs um effect */ diff --git a/src/items/artrewards.c b/src/items/artrewards.c index 602841d23..23ab2119e 100644 --- a/src/items/artrewards.c +++ b/src/items/artrewards.c @@ -45,7 +45,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int age_peaceimmune(attrib * a, void *owner) { - unused_arg(owner); + UNUSED_ARG(owner); return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } diff --git a/src/items/demonseye.c b/src/items/demonseye.c index ffc1c5179..563a16047 100644 --- a/src/items/demonseye.c +++ b/src/items/demonseye.c @@ -38,8 +38,8 @@ summon_igjarjuk(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { struct plane *p = rplane(u->region); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(amount); + UNUSED_ARG(itype); if (p != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", "")); return EUNUSABLE; diff --git a/src/items/speedsail.c b/src/items/speedsail.c index 8bdaa41ab..cb40e9a8c 100644 --- a/src/items/speedsail.c +++ b/src/items/speedsail.c @@ -42,8 +42,8 @@ use_speedsail(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { struct plane *p = rplane(u->region); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(amount); + UNUSED_ARG(itype); if (p != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", "")); } diff --git a/src/items/weapons.c b/src/items/weapons.c index 1806e61a0..a23110a81 100644 --- a/src/items/weapons.c +++ b/src/items/weapons.c @@ -106,7 +106,7 @@ int *casualties) } enemies = count_enemies(b, af, FIGHT_ROW, FIGHT_ROW, SELECT_ADVANCE); - enemies = _min(enemies, CATAPULT_ATTACKS); + enemies = MIN(enemies, CATAPULT_ATTACKS); if (enemies == 0) { return true; /* allow further attacks */ } diff --git a/src/items/xerewards.c b/src/items/xerewards.c index ab5226a32..a6d1ad2ea 100644 --- a/src/items/xerewards.c +++ b/src/items/xerewards.c @@ -72,7 +72,7 @@ struct order *ord) } for (i = 0; i != amount; ++i) { - sp += _max(25, max_spellpoints(u->region, u) / 2); + sp += MAX(25, max_spellpoints(u->region, u) / 2); change_spellpoints(u, sp); } diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 32c58e246..0feb8407d 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -83,7 +83,7 @@ alliance *new_alliance(int id, const char *name) { al = calloc(1, sizeof(alliance)); al->id = id; if (name) { - al->name = _strdup(name); + al->name = strdup(name); } else { al->flags |= ALF_NON_ALLIED; @@ -447,7 +447,7 @@ void alliance_setname(alliance * self, const char *name) { free(self->name); if (name) - self->name = _strdup(name); + self->name = strdup(name); else self->name = NULL; } diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 5a5a5b1c3..759d556f4 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -76,7 +76,7 @@ int AllianceAuto(void) const char *str = config_get("alliance.auto"); value = 0; if (str != NULL) { - char *sstr = _strdup(str); + char *sstr = strdup(str); char *tok = strtok(sstr, " "); while (tok) { value |= ally_flag(tok, -1); @@ -136,7 +136,7 @@ int HelpMask(void) if (config_changed(&config)) { const char *str = config_get("rules.help.mask"); if (str != NULL) { - char *sstr = _strdup(str); + char *sstr = strdup(str); char *tok = strtok(sstr, " "); while (tok) { rule |= ally_flag(tok, -1); @@ -156,7 +156,7 @@ static int AllianceRestricted(void) const char *str = config_get("alliance.restricted"); int rule = 0; if (str != NULL) { - char *sstr = _strdup(str); + char *sstr = strdup(str); char *tok = strtok(sstr, " "); while (tok) { rule |= ally_flag(tok, -1); diff --git a/src/kernel/build.c b/src/kernel/build.c index b5a1b3417..dff51cf6c 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -123,11 +123,11 @@ static void destroy_road(unit * u, int nmax, struct order *ord) } road = rroad(r, d); - n = _min(n, road); + n = MIN(n, road); if (n != 0) { region *r2 = rconnect(r, d); int willdo = effskill(u, SK_ROAD_BUILDING, 0) * u->number; - willdo = _min(willdo, n); + willdo = MIN(willdo, n); if (willdo == 0) { /* TODO: error message */ } @@ -327,7 +327,7 @@ void build_road(unit * u, int size, direction_t d) } if (size > 0) - left = _min(size, left); + left = MIN(size, left); /* baumaximum anhand der rohstoffe */ if (u_race(u) == get_race(RC_STONEGOLEM)) { n = u->number * GOLEM_STONE; @@ -339,7 +339,7 @@ void build_road(unit * u, int size, direction_t d) return; } } - left = _min(n, left); + left = MIN(n, left); /* n = maximum by skill. try to maximize it */ n = u->number * effsk; @@ -347,7 +347,7 @@ void build_road(unit * u, int size, direction_t d) const resource_type *ring = get_resourcetype(R_RING_OF_NIMBLEFINGER); item *itm = ring ? *i_find(&u->items, ring->itype) : 0; if (itm != NULL && itm->number > 0) { - int rings = _min(u->number, itm->number); + int rings = MIN(u->number, itm->number); n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; } } @@ -355,15 +355,15 @@ void build_road(unit * u, int size, direction_t d) int dm = get_effect(u, oldpotiontype[P_DOMORE]); if (dm != 0) { int todo = (left - n + effsk - 1) / effsk; - todo = _min(todo, u->number); - dm = _min(dm, todo); + todo = MIN(todo, u->number); + dm = MIN(dm, todo); change_effect(u, oldpotiontype[P_DOMORE], -dm); n += dm * effsk; } /* Auswirkung Schaffenstrunk */ } /* make minimum of possible and available: */ - n = _min(left, n); + n = MIN(left, n); /* n is now modified by several special effects, so we have to * minimize it again to make sure the road will not grow beyond @@ -380,7 +380,7 @@ void build_road(unit * u, int size, direction_t d) else { use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n); /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - produceexp(u, SK_ROAD_BUILDING, _min(n, u->number)); + produceexp(u, SK_ROAD_BUILDING, MIN(n, u->number)); } ADDMSG(&u->faction->msgs, msg_message("buildroad", "region unit size", r, u, n)); @@ -486,7 +486,7 @@ int build(unit * u, const construction * ctype, int completed, int want) if (dm != 0) { /* Auswirkung Schaffenstrunk */ - dm = _min(dm, u->number); + dm = MIN(dm, u->number); change_effect(u, oldpotiontype[P_DOMORE], -dm); skills += dm * effsk; } @@ -545,7 +545,7 @@ int build(unit * u, const construction * ctype, int completed, int want) item *itm = ring ? *i_find(&u->items, ring->itype) : 0; int i = itm ? itm->number : 0; if (i > 0) { - int rings = _min(u->number, i); + int rings = MIN(u->number, i); n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; } } @@ -553,7 +553,7 @@ int build(unit * u, const construction * ctype, int completed, int want) if (want < n) n = want; if (type->maxsize > 0) { - n = _min(type->maxsize - completed, n); + n = MIN(type->maxsize - completed, n); if (type->improvement == NULL) { want = n; } @@ -626,7 +626,7 @@ int build(unit * u, const construction * ctype, int completed, int want) completed = completed + n; } /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - produceexp(u, ctype->skill, _min(made, u->number)); + produceexp(u, ctype->skill, MIN(made, u->number)); return made; } @@ -671,7 +671,7 @@ int maxbuild(const unit * u, const construction * cons) return 0; } else - maximum = _min(maximum, have / need); + maximum = MIN(maximum, have / need); } return maximum; } @@ -879,7 +879,7 @@ static void build_ship(unit * u, ship * sh, int want) } if (sh->damage && can) { - int repair = _min(sh->damage, can * DAMAGE_SCALE); + int repair = MIN(sh->damage, can * DAMAGE_SCALE); n += repair / DAMAGE_SCALE; if (repair % DAMAGE_SCALE) ++n; @@ -923,7 +923,7 @@ order * ord) return; } if (want > 0) - want = _min(want, msize); + want = MIN(want, msize); else want = msize; @@ -982,7 +982,7 @@ void continue_ship(unit * u, int want) return; } if (want > 0) - want = _min(want, msize); + want = MIN(want, msize); else want = msize; diff --git a/src/kernel/building.c b/src/kernel/building.c index b445019de..f2c9c9fd2 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -127,7 +127,7 @@ building_type *bt_get_or_create(const char *name) building_type *btype = bt_find_i(name); if (btype == NULL) { btype = calloc(sizeof(building_type), 1); - btype->_name = _strdup(name); + btype->_name = strdup(name); btype->auraregen = 1.0; btype->maxsize = -1; btype->capacity = 1; @@ -143,7 +143,7 @@ int buildingcapacity(const building * b) { if (b->type->capacity >= 0) { if (b->type->maxcapacity >= 0) { - return _min(b->type->maxcapacity, b->size * b->type->capacity); + return MIN(b->type->maxcapacity, b->size * b->type->capacity); } return b->size * b->type->capacity; } @@ -420,7 +420,7 @@ building *new_building(const struct building_type * btype, region * r, } assert(bname); slprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no)); - b->name = _strdup(bname); + b->name = strdup(bname); return b; } @@ -619,7 +619,7 @@ void building_setname(building * self, const char *name) { free(self->name); if (name) - self->name = _strdup(name); + self->name = strdup(name); else self->name = NULL; } @@ -779,7 +779,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) /* Godcurse: Income -10 */ ctype = ct_find("godcursezone"); if (ctype && curse_active(get_curse(r->attribs, ctype))) { - wage = _max(0, wage - 10); + wage = MAX(0, wage - 10); } /* Bei einer D�rre verdient man nur noch ein Viertel */ diff --git a/src/kernel/building.h b/src/kernel/building.h index 754f38f07..a6936d90d 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -23,6 +23,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index d15c82c8e..3b296a6fe 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -22,7 +22,7 @@ static void test_register_building(CuTest * tc) test_cleanup(); btype = (building_type *)calloc(sizeof(building_type), 1); - btype->_name = _strdup("herp"); + btype->_name = strdup("herp"); CuAssertIntEquals(tc, true, bt_changed(&cache)); CuAssertIntEquals(tc, false, bt_changed(&cache)); bt_register(btype); diff --git a/src/kernel/config.c b/src/kernel/config.c index 2b1ae678d..d369d0ecd 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -91,6 +91,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include struct settings global = { "Eressea", /* gamename */ @@ -361,7 +362,7 @@ void init_locale(struct locale *lang) str = "gwyrrd illaun draig cerddor tybied"; } - sstr = _strdup(str); + sstr = strdup(str); tok = strtok(sstr, " "); while (tok) { const char *name; @@ -472,7 +473,7 @@ int check_param(const struct param *p, const char *key, const char *searchvalue) if (!value) { return 0; } - char *p_value = _strdup(value); + char *p_value = strdup(value); const char *delimiter = " ,;"; char *v = strtok(p_value, delimiter); @@ -535,7 +536,7 @@ static const char * relpath(char *buf, size_t sz, const char *path) { static const char *g_datadir; const char *datapath(void) { - static char zText[MAX_PATH]; + static char zText[4096]; if (g_datadir) return g_datadir; return relpath(zText, sizeof(zText), "data"); @@ -549,7 +550,7 @@ void set_datapath(const char *path) static const char *g_reportdir; const char *reportpath(void) { - static char zText[MAX_PATH]; + static char zText[4096]; if (g_reportdir) return g_reportdir; return relpath(zText, sizeof(zText), "reports"); @@ -562,12 +563,12 @@ void set_reportpath(const char *path) int create_directories(void) { int err; - err = _mkdir(datapath()); + err = mkdir(datapath(), 0777); if (err) { if (errno == EEXIST) errno = 0; else return err; } - err = _mkdir(reportpath()); + err = mkdir(reportpath(), 0777); if (err && errno == EEXIST) { errno = 0; } diff --git a/src/kernel/config.h b/src/kernel/config.h index 91d5d576f..096d54da4 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -25,6 +25,7 @@ extern "C" { /* this should always be the first thing included after platform.h */ #include +#include #include "types.h" struct param; diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 082039f1b..5b2615bcc 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -131,7 +131,7 @@ static connection **get_borders_i(const region * r1, const region * r2) int key = reg_hashkey(r1); int k2 = reg_hashkey(r2); - key = _min(k2, key) % BORDER_MAXHASH; + key = MIN(k2, key) % BORDER_MAXHASH; bp = &borders[key]; while (*bp) { connection *b = *bp; @@ -258,31 +258,31 @@ void b_write(const connection * b, storage * store) bool b_transparent(const connection * b, const struct faction *f) { - unused_arg(b); - unused_arg(f); + UNUSED_ARG(b); + UNUSED_ARG(f); return true; } bool b_opaque(const connection * b, const struct faction * f) { - unused_arg(b); - unused_arg(f); + UNUSED_ARG(b); + UNUSED_ARG(f); return false; } bool b_blockall(const connection * b, const unit * u, const region * r) { - unused_arg(u); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(r); + UNUSED_ARG(b); return true; } bool b_blocknone(const connection * b, const unit * u, const region * r) { - unused_arg(u); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(r); + UNUSED_ARG(b); return false; } @@ -294,39 +294,39 @@ bool b_rvisible(const connection * b, const region * r) bool b_fvisible(const connection * b, const struct faction * f, const region * r) { - unused_arg(r); - unused_arg(f); - unused_arg(b); + UNUSED_ARG(r); + UNUSED_ARG(f); + UNUSED_ARG(b); return true; } bool b_uvisible(const connection * b, const unit * u) { - unused_arg(u); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(b); return true; } bool b_rinvisible(const connection * b, const region * r) { - unused_arg(r); - unused_arg(b); + UNUSED_ARG(r); + UNUSED_ARG(b); return false; } bool b_finvisible(const connection * b, const struct faction * f, const region * r) { - unused_arg(r); - unused_arg(f); - unused_arg(b); + UNUSED_ARG(r); + UNUSED_ARG(f); + UNUSED_ARG(b); return false; } bool b_uinvisible(const connection * b, const unit * u) { - unused_arg(u); - unused_arg(b); + UNUSED_ARG(u); + UNUSED_ARG(b); return false; } @@ -380,9 +380,9 @@ static const char *b_namewall(const connection * b, const region * r, { const char *bname = "wall"; - unused_arg(f); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(f); + UNUSED_ARG(r); + UNUSED_ARG(b); if (gflags & GF_ARTICLE) bname = "a_wall"; if (gflags & GF_PURE) @@ -421,9 +421,9 @@ border_type bt_noway = { static const char *b_namefogwall(const connection * b, const region * r, const struct faction *f, int gflags) { - unused_arg(f); - unused_arg(b); - unused_arg(r); + UNUSED_ARG(f); + UNUSED_ARG(b); + UNUSED_ARG(r); if (gflags & GF_PURE) return "fogwall"; if (gflags & GF_ARTICLE) @@ -434,7 +434,7 @@ static const char *b_namefogwall(const connection * b, const region * r, static bool b_blockfogwall(const connection * b, const unit * u, const region * r) { - unused_arg(b); + UNUSED_ARG(b); if (!u) return true; return (bool)(effskill(u, SK_PERCEPTION, r) > 4); /* Das ist die alte Nebelwand */ @@ -459,8 +459,8 @@ static const char *b_nameillusionwall(const connection * b, const region * r, const struct faction *f, int gflags) { int fno = b->data.i; - unused_arg(b); - unused_arg(r); + UNUSED_ARG(b); + UNUSED_ARG(r); if (gflags & GF_PURE) return (f && fno == f->no) ? "illusionwall" : "wall"; if (gflags & GF_ARTICLE) { @@ -496,7 +496,7 @@ static const char *b_nameroad(const connection * b, const region * r, int local = (r == b->from) ? b->data.sa[0] : b->data.sa[1]; static char buffer[64]; - unused_arg(f); + UNUSED_ARG(f); if (gflags & GF_PURE) return "road"; if (gflags & GF_ARTICLE) { @@ -512,7 +512,7 @@ static const char *b_nameroad(const connection * b, const region * r, } } else { - int percent = _max(1, 100 * local / r->terrain->max_road); + int percent = MAX(1, 100 * local / r->terrain->max_road); if (local) { slprintf(buffer, sizeof(buffer), LOC(f->locale, mkname("border", "a_road_percent")), percent); diff --git a/src/kernel/connection.h b/src/kernel/connection.h index 7eef0f52a..80177c638 100644 --- a/src/kernel/connection.h +++ b/src/kernel/connection.h @@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_BORDER #include - +#include #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/curse.c b/src/kernel/curse.c index c0e353b4f..7df567940 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -109,7 +109,7 @@ int curse_age(attrib * a, void *owner) curse *c = (curse *)a->data.v; int result = 0; - unused_arg(owner); + UNUSED_ARG(owner); c_clearflag(c, CURSE_ISNEW); if (c_flags(c) & CURSE_NOAGE) { @@ -122,7 +122,7 @@ int curse_age(attrib * a, void *owner) c->duration = 0; } else if (c->duration != INT_MAX) { - c->duration = _max(0, c->duration - 1); + c->duration = MAX(0, c->duration - 1); } return (c->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -348,7 +348,7 @@ const curse_type *ct_find(const char *c) return type; } else { - size_t k = _min(c_len, strlen(type->cname)); + size_t k = MIN(c_len, strlen(type->cname)); if (!memcmp(c, type->cname, k)) { return type; } @@ -507,7 +507,7 @@ int get_cursedmen(unit * u, const curse * c) cursedmen = c->data.i; } - return _min(u->number, cursedmen); + return MIN(u->number, cursedmen); } /* setzt die Anzahl der betroffenen Personen auf cursedmen */ @@ -596,7 +596,7 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, /* es gibt schon eins diese Typs */ if (c && ct->mergeflags != NO_MERGE) { if (ct->mergeflags & M_DURATION) { - c->duration = _max(c->duration, duration); + c->duration = MAX(c->duration, duration); } if (ct->mergeflags & M_SUMDURATION) { c->duration += duration; @@ -605,10 +605,10 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, c->effect += effect; } if (ct->mergeflags & M_MAXEFFECT) { - c->effect = _max(c->effect, effect); + c->effect = MAX(c->effect, effect); } if (ct->mergeflags & M_VIGOUR) { - c->vigour = _max(vigour, c->vigour); + c->vigour = MAX(vigour, c->vigour); } if (ct->mergeflags & M_VIGOUR_ADD) { c->vigour = vigour + c->vigour; @@ -792,9 +792,9 @@ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, { struct message *msg; - unused_arg(typ); - unused_arg(self); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(self); + UNUSED_ARG(obj); msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no); if (msg == NULL) { diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 29498f4d2..4cff4f9a1 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "objtypes.h" +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index de539223f..349a87448 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -47,7 +47,7 @@ equipment *create_equipment(const char *eqname) int i = eq ? strcmp(eq->name, eqname) : 1; if (i > 0) { eq = (equipment *)calloc(1, sizeof(equipment)); - eq->name = _strdup(eqname); + eq->name = strdup(eqname); eq->next = *eqp; memset(eq->skills, 0, sizeof(eq->skills)); *eqp = eq; @@ -78,7 +78,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value) { if (eq != NULL) { if (value != NULL) { - eq->skills[sk] = _strdup(value); + eq->skills[sk] = strdup(value); } else if (eq->skills[sk]) { free(eq->skills[sk]); @@ -98,7 +98,7 @@ void equipment_addspell(equipment * eq, const char * name, int level) lazy_spell *ls = malloc(sizeof(lazy_spell)); ls->sp = NULL; ls->level = level; - ls->name = _strdup(name); + ls->name = strdup(name); selist_push(&eq->spells, ls); } } @@ -115,7 +115,7 @@ equipment_setitem(equipment * eq, const item_type * itype, const char *value) if (idata == NULL) { idata = (itemdata *)malloc(sizeof(itemdata)); idata->itype = itype; - idata->value = _strdup(value); + idata->value = strdup(value); idata->next = eq->items; eq->items = idata; } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 4d2e6ae7b..811321f14 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -274,7 +274,7 @@ faction *addfaction(const char *email, const char *password, fhash(f); slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no)); - f->name = _strdup(buf); + f->name = strdup(buf); if (!f->race) { log_warning("creating a faction that has no race", itoa36(f->no)); @@ -523,7 +523,7 @@ void faction_setname(faction * self, const char *name) { free(self->name); if (name) - self->name = _strdup(name); + self->name = strdup(name); } const char *faction_getemail(const faction * self) @@ -535,7 +535,7 @@ void faction_setemail(faction * self, const char *email) { free(self->email); if (email) - self->email = _strdup(email); + self->email = strdup(email); } const char *faction_getbanner(const faction * self) @@ -547,7 +547,7 @@ void faction_setbanner(faction * self, const char *banner) { free(self->banner); if (banner) - self->banner = _strdup(banner); + self->banner = strdup(banner); } void faction_setpassword(faction * f, const char *pwhash) @@ -555,7 +555,7 @@ void faction_setpassword(faction * f, const char *pwhash) assert(pwhash); // && pwhash[0] == '$'); free(f->_password); - f->_password = _strdup(pwhash); + f->_password = strdup(pwhash); } bool valid_race(const struct faction *f, const struct race *rc) diff --git a/src/kernel/faction.h b/src/kernel/faction.h index d6419dd2f..757449bd8 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "skill.h" #include "types.h" #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/group.c b/src/kernel/group.c index 8753531a3..06f2f9f49 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -57,8 +57,8 @@ group *new_group(faction * f, const char *name, int gid) gp = &(*gp)->next; *gp = g; - maxgid = _max(gid, maxgid); - g->name = _strdup(name); + maxgid = MAX(gid, maxgid); + g->name = strdup(name); g->gid = gid; g->nexthash = ghash[index]; diff --git a/src/kernel/item.c b/src/kernel/item.c index 9956f2a4a..34a0e1875 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -189,7 +189,7 @@ resource_type *rt_get_or_create(const char *name) { perror("resource_type allocation failed"); } else { - rtype->_name = _strdup(name); + rtype->_name = strdup(name); rt_register(rtype); return rt_find(name); } @@ -285,8 +285,8 @@ weapon_type *new_weapontype(item_type * itype, wtype = calloc(sizeof(weapon_type), 1); if (damage) { - wtype->damage[0] = _strdup(damage[0]); - wtype->damage[1] = _strdup(damage[1]); + wtype->damage[0] = strdup(damage[0]); + wtype->damage[1] = strdup(damage[1]); } wtype->defmod = defmod; wtype->flags |= wflags; @@ -345,7 +345,7 @@ void it_set_appearance(item_type *itype, const char *appearance) { assert(itype); assert(itype->rtype); if (appearance) { - itype->_appearance[0] = _strdup(appearance); + itype->_appearance[0] = strdup(appearance); itype->_appearance[1] = strcat(strcpy((char *)malloc(strlen((char *)appearance) + 3), (char *)appearance), "_p"); } else { itype->_appearance[0] = 0; @@ -679,9 +679,9 @@ struct order *ord) direction_t d; message *msg = msg_message("meow", ""); - unused_arg(ord); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(ord); + UNUSED_ARG(amount); + UNUSED_ARG(itype); add_message(&u->region->msgs, msg); for (d = 0; d < MAXDIRECTIONS; d++) { @@ -720,7 +720,7 @@ struct order *ord) c = create_curse(u, &u->attribs, ct_find("skillmod"), power, duration, effect, u->number); c->data.i = SK_TACTICS; - unused_arg(ord); + UNUSED_ARG(ord); } use_pooled(u, itype->rtype, GET_DEFAULT, amount); ADDMSG(&u->faction->msgs, msg_message("use_tacticcrystal", @@ -749,14 +749,14 @@ mod_elves_only(const unit * u, const region * r, skill_t sk, int value) { if (u_race(u) == get_race(RC_ELF)) return value; - unused_arg(r); + UNUSED_ARG(r); return -118; } static int mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value) { - unused_arg(r); + UNUSED_ARG(r); if (u_race(u) == get_race(RC_DWARF) || (u_race(u)->flags & RCF_IRONGOLEM)) { return value; } @@ -767,7 +767,7 @@ static int heal(unit * user, int effect) { int req = unit_max_hp(user) * user->number - user->hp; if (req > 0) { - req = _min(req, effect); + req = MIN(req, effect); effect -= req; user->hp += req; } diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 69e02c3a0..414704309 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -224,7 +224,7 @@ static void json_terrain_production(cJSON *json, terrain_production *prod) { if (dst) { free(*dst); assert(child->type == cJSON_String); - *dst = _strdup(child->valuestring); + *dst = strdup(child->valuestring); } } } @@ -453,7 +453,7 @@ static void json_race(cJSON *json, race *rc) { switch (child->type) { case cJSON_String: if (strcmp(child->string, "damage") == 0) { - rc->def_damage = _strdup(child->valuestring); + rc->def_damage = strdup(child->valuestring); } break; case cJSON_Number: @@ -599,7 +599,7 @@ static void json_spells(cJSON *json) { sp->fumble = (fumble_f)get_function(item->valuestring); } else if (strcmp(item->string, "syntax") == 0) { - sp->syntax = _strdup(item->valuestring); + sp->syntax = strdup(item->valuestring); } } } diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 566e9bdef..89278624f 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -212,7 +212,7 @@ caddmessage(region * r, faction * f, const char *s, msg_t mtype, int level) { message *m = NULL; - unused_arg(level); + UNUSED_ARG(level); switch (mtype) { case MSG_INCOME: assert(f); @@ -275,7 +275,7 @@ message * msg_error(const unit * u, struct order *ord, int mno) { message * cmistake(const unit * u, struct order *ord, int mno, int mtype) { message * result; - unused_arg(mtype); + UNUSED_ARG(mtype); result = msg_error(u, ord, mno); ADDMSG(&u->faction->msgs, result); return result; diff --git a/src/kernel/order.c b/src/kernel/order.c index 3fd1dc92f..776190b67 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -405,7 +405,7 @@ order *parse_order(const char *s, const struct locale * lang) } } if (kwd != NOKEYWORD) { - while (isxspace(*(unsigned char *)sptr)) ++sptr; + while (isspace(*(unsigned char *)sptr)) ++sptr; s = sptr; return create_order_i(kwd, s, persistent, lang); } diff --git a/src/kernel/plane.c b/src/kernel/plane.c index 7e9650d13..0b2fdc0d3 100644 --- a/src/kernel/plane.c +++ b/src/kernel/plane.c @@ -234,7 +234,7 @@ plane *create_new_plane(int id, const char *name, int minx, int maxx, int miny, pl->next = NULL; pl->id = id; if (name) - pl->name = _strdup(name); + pl->name = strdup(name); pl->minx = minx; pl->maxx = maxx; pl->miny = miny; diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 5609d211f..702f86e0f 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -168,7 +168,7 @@ int count) use = have; else if (rtype->itype && mode & (GET_SLACK | GET_RESERVE)) { int reserve = get_reservation(u, rtype->itype); - int slack = _max(0, have - reserve); + int slack = MAX(0, have - reserve); if (mode & GET_RESERVE) use = have - slack; else if (mode & GET_SLACK) @@ -209,18 +209,18 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) } if ((mode & GET_SLACK) && (mode & GET_RESERVE)) { - n = _min(use, have); + n = MIN(use, have); } else if (rtype->itype) { int reserve = get_reservation(u, rtype->itype); - int slack = _max(0, have - reserve); + int slack = MAX(0, have - reserve); if (mode & GET_RESERVE) { n = have - slack; - n = _min(use, n); + n = MIN(use, n); change_reservation(u, rtype->itype, -n); } else if (mode & GET_SLACK) { - n = _min(use, slack); + n = MIN(use, slack); } } if (n > 0) { diff --git a/src/kernel/race.c b/src/kernel/race.c index decc3b7bb..a78a9e340 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -241,7 +241,7 @@ race *rc_create(const char *zName) log_error("race '%s' has an invalid name. remove spaces\n", zName); assert(strchr(zName, ' ') == NULL); } - rc->_name = _strdup(zName); + rc->_name = strdup(zName); rc->precombatspell = NULL; rc->attack[0].type = AT_COMBATSPELL; @@ -288,7 +288,7 @@ const char* rc_name(const race * rc, name_t n, char *name, size_t size) { default: assert(!"invalid name_t enum in rc_name_s"); } if (postfix) { - _snprintf(name, size, "race::%s%s", rc->_name, postfix); + snprintf(name, size, "race::%s%s", rc->_name, postfix); return name; } return NULL; diff --git a/src/kernel/region.c b/src/kernel/region.c index d937f8b68..cade135c7 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -138,7 +138,7 @@ int region_maxworkers(const region *r) { int size = production(r); int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE; - return _max(size - treespace, _min(size / 10, 200)); + return MAX(size - treespace, MIN(size / 10, 200)); } int deathcount(const region * r) @@ -403,7 +403,7 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height) int dx = x1 - x2; int dy = y1 - y2; int result, dist; - int mindist = _min(width, height) >> 1; + int mindist = MIN(width, height) >> 1; /* Bei negativem dy am Ursprung spiegeln, das veraendert * den Abstand nicht @@ -426,13 +426,13 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height) if (result <= mindist) return result; } - dist = _max(dx, height - dy); + dist = MAX(dx, height - dy); if (dist >= 0 && dist < result) { result = dist; if (result <= mindist) return result; } - dist = _max(width - dx, dy); + dist = MAX(width - dx, dy); if (dist >= 0 && dist < result) result = dist; return result; @@ -1215,7 +1215,7 @@ void terraform_region(region * r, const terrain_type * terrain) if (!fval(r, RF_CHAOTIC)) { int peasants; peasants = (region_maxworkers(r) * (20 + dice_rand("6d10"))) / 100; - rsetpeasants(r, _max(100, peasants)); + rsetpeasants(r, MAX(100, peasants)); rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL, INT_MAX) + 1) + rng_int() % 5)); } @@ -1395,7 +1395,7 @@ faction *update_owners(region * r) else if (f || new_owner->faction != region_get_last_owner(r)) { alliance *al = region_get_alliance(r); if (al && new_owner->faction->alliance == al) { - int morale = _max(0, region_get_morale(r) - MORALE_TRANSFER); + int morale = MAX(0, region_get_morale(r) - MORALE_TRANSFER); region_set_morale(r, morale, turn); } else { @@ -1418,7 +1418,7 @@ faction *update_owners(region * r) void region_setinfo(struct region *r, const char *info) { free(r->display); - r->display = info ? _strdup(info) : 0; + r->display = info ? strdup(info) : 0; } const char *region_getinfo(const region * r) @@ -1430,7 +1430,7 @@ void region_setname(struct region *r, const char *name) { if (r->land) { free(r->land->name); - r->land->name = name ? _strdup(name) : 0; + r->land->name = name ? strdup(name) : 0; } } diff --git a/src/kernel/region.h b/src/kernel/region.h index fcc5f08b0..9fa1a2daa 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_REGION #include +#include #include "types.h" #include "direction.h" diff --git a/src/kernel/resources.c b/src/kernel/resources.c index e064150e6..e32c7ad55 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -111,7 +111,7 @@ static void terraform_default(struct rawmaterial *res, const region * r) res->amount = (int)(res->amount * modifier); /* random adjustment, +/- 91% */ if (res->amount < 1) res->amount = 1; - unused_arg(r); + UNUSED_ARG(r); } #ifdef RANDOM_CHANGE @@ -205,7 +205,7 @@ struct rawmaterial_type *rmt_create(const struct resource_type *rtype, const char *name) { rawmaterial_type *rmtype = malloc(sizeof(rawmaterial_type)); - rmtype->name = _strdup(name); + rmtype->name = strdup(name); rmtype->rtype = rtype; rmtype->terraform = terraform_default; rmtype->update = NULL; diff --git a/src/kernel/save.c b/src/kernel/save.c index 68c89070c..1139b5f1f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -436,7 +436,7 @@ void read_planes(gamedata *data) { } pl->id = id; READ_STR(store, name, sizeof(name)); - pl->name = _strdup(name); + pl->name = strdup(name); READ_INT(store, &pl->minx); READ_INT(store, &pl->maxx); READ_INT(store, &pl->miny); @@ -668,7 +668,7 @@ unit *read_unit(struct gamedata *data) if (unicode_utf8_trim(obuf)!=0) { log_warning("trim unit %s name to '%s'", itoa36(u->no), obuf); } - u->_name = obuf[0] ? _strdup(obuf) : 0; + u->_name = obuf[0] ? strdup(obuf) : 0; if (lomem) { READ_STR(data->store, NULL, 0); } @@ -677,7 +677,7 @@ unit *read_unit(struct gamedata *data) if (unicode_utf8_trim(obuf)!=0) { log_warning("trim unit %s info to '%s'", itoa36(u->no), obuf); } - u->display = obuf[0] ? _strdup(obuf) : 0; + u->display = obuf[0] ? strdup(obuf) : 0; } READ_INT(data->store, &number); set_number(u, number); @@ -933,7 +933,7 @@ static region *readregion(struct gamedata *data, int x, int y) if (unicode_utf8_trim(name)!=0) { log_warning("trim region %d name to '%s'", uid, name); }; - r->land->name = _strdup(name); + r->land->name = strdup(name); } if (r->land) { int i; @@ -1034,7 +1034,7 @@ static region *readregion(struct gamedata *data, int x, int y) read_items(data->store, &r->land->items); if (data->version >= REGIONOWNER_VERSION) { READ_INT(data->store, &n); - region_set_morale(r, _max(0, (short)n), -1); + region_set_morale(r, MAX(0, (short)n), -1); read_owner(data, &r->land->ownership); } } @@ -1192,7 +1192,7 @@ static char * getpasswd(int fno) { assert(line[slen] == '\n'); line[slen] = 0; fclose(F); - return _strdup(line + len + 1); + return strdup(line + len + 1); } } fclose(F); @@ -1285,12 +1285,12 @@ faction *read_faction(struct gamedata * data) if (unicode_utf8_trim(name)!=0) { log_warning("trim faction %s name to '%s'", itoa36(f->no), name); }; - f->name = _strdup(name); + f->name = strdup(name); READ_STR(data->store, name, sizeof(name)); if (unicode_utf8_trim(name)!=0) { log_warning("trim faction %s banner to '%s'", itoa36(f->no), name); }; - f->banner = _strdup(name); + f->banner = strdup(name); log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no)); @@ -1528,7 +1528,7 @@ struct building *read_building(gamedata *data) { if (unicode_utf8_trim(name)!=0) { log_warning("trim building %s name to '%s'", itoa36(b->no), name); } - b->name = _strdup(name); + b->name = strdup(name); if (lomem) { READ_STR(store, NULL, 0); } @@ -1537,7 +1537,7 @@ struct building *read_building(gamedata *data) { if (unicode_utf8_trim(name)!=0) { log_warning("trim building %s info to '%s'", itoa36(b->no), name); } - b->display = _strdup(name); + b->display = strdup(name); } READ_INT(store, &b->size); READ_STR(store, name, sizeof(name)); @@ -1581,7 +1581,7 @@ ship *read_ship(struct gamedata *data) if (unicode_utf8_trim(name)!=0) { log_warning("trim ship %s name to '%s'", itoa36(sh->no), name); } - sh->name = _strdup(name); + sh->name = strdup(name); if (lomem) { READ_STR(store, NULL, 0); } @@ -1590,7 +1590,7 @@ ship *read_ship(struct gamedata *data) if (unicode_utf8_trim(name)!=0) { log_warning("trim ship %s info to '%s'", itoa36(sh->no), name); } - sh->display = _strdup(name); + sh->display = strdup(name); } READ_STR(store, name, sizeof(name)); sh->type = st_find(name); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 6a2758a1d..c05ce4455 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -91,7 +91,7 @@ static void test_readwrite_faction(CuTest * tc) test_setup(); f = test_create_faction(0); free(f->name); - f->name = _strdup(" Hodor "); + f->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", f->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); @@ -120,7 +120,7 @@ static void test_readwrite_region(CuTest * tc) test_setup(); r = test_create_region(0, 0, 0); free(r->land->name); - r->land->name = _strdup(" Hodor "); + r->land->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", r->land->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); @@ -150,7 +150,7 @@ static void test_readwrite_building(CuTest * tc) r = test_create_region(0, 0, 0); b = test_create_building(r, 0); free(b->name); - b->name = _strdup(" Hodor "); + b->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", b->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); @@ -183,7 +183,7 @@ static void test_readwrite_ship(CuTest * tc) r = test_create_region(0, 0, 0); sh = test_create_ship(r, 0); free(sh->name); - sh->name = _strdup(" Hodor "); + sh->name = strdup(" Hodor "); CuAssertStrEquals(tc, " Hodor ", sh->name); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 1790afb5d..b9ac0b170 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -109,7 +109,7 @@ ship_type *st_get_or_create(const char * name) { ship_type * st = st_find_i(name); if (!st) { st = (ship_type *)calloc(sizeof(ship_type), 1); - st->_name = _strdup(name); + st->_name = strdup(name); st->storm = 1.0; selist_push(&shiptypes, (void *)st); } @@ -202,7 +202,7 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang) } assert(sname); slprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no)); - sh->name = _strdup(buffer); + sh->name = strdup(buffer); shash(sh); if (r) { addlist(&r->ships, sh); @@ -333,8 +333,8 @@ int shipspeed(const ship * sh, const unit * u) int crew = crew_skill(sh); int crew_bonus = (crew / sh->type->sumskill / 2) - 1; if (crew_bonus > 0) { - bonus = _min(bonus, crew_bonus); - bonus = _min(bonus, sh->type->range_max - sh->type->range); + bonus = MIN(bonus, crew_bonus); + bonus = MIN(bonus, sh->type->range_max - sh->type->range); } else { bonus = 0; @@ -458,7 +458,7 @@ void write_ship_reference(const struct ship *sh, struct storage *store) void ship_setname(ship * self, const char *name) { free(self->name); - self->name = name ? _strdup(name) : 0; + self->name = name ? strdup(name) : 0; } const char *ship_getname(const ship * self) diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 4540029e2..5415c4a0e 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -78,7 +78,7 @@ spell * create_spell(const char * name, unsigned int id) len = cb_new_kv(name, len, &sp, sizeof(sp), buffer); if (cb_insert(&cb_spells, buffer, len) == CB_SUCCESS) { sp->id = id ? id : hashstring(name); - sp->sname = _strdup(name); + sp->sname = strdup(name); add_spell(&spells, sp); return sp; } diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index 7673324f8..bb060eaee 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -16,7 +16,7 @@ spellbook * create_spellbook(const char * name) { spellbook *result = (spellbook *)malloc(sizeof(spellbook)); - result->name = name ? _strdup(name) : 0; + result->name = name ? strdup(name) : 0; result->spells = 0; return result; } diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index ac4a49fe9..ca72e3060 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -110,7 +110,7 @@ terrain_type * get_or_create_terrain(const char *name) { if (!terrain) { terrain = (terrain_type *)calloc(sizeof(terrain_type), 1); if (terrain) { - terrain->_name = _strdup(name); + terrain->_name = strdup(name); terrain->next = registered_terrains; registered_terrains = terrain; if (strcmp("plain", name) == 0) { diff --git a/src/kernel/unit.c b/src/kernel/unit.c index f06c4c252..29766d4ef 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -123,7 +123,7 @@ unit *findunitr(const region * r, int n) // TODO: deprecated, replace with findunit(n) unit *findunitg(int n, const region * hint) { - unused_arg(hint); + UNUSED_ARG(hint); /* Abfangen von Syntaxfehlern. */ if (n <= 0) return NULL; @@ -511,7 +511,7 @@ int a_readprivate(attrib * a, void *owner, gamedata *data) struct storage *store = data->store; char lbuf[DISPLAYSIZE]; READ_STR(store, lbuf, sizeof(lbuf)); - a->data.v = _strdup(lbuf); + a->data.v = strdup(lbuf); return (a->data.v) ? AT_READ_OK : AT_READ_FAIL; } @@ -562,7 +562,7 @@ void usetprivate(unit * u, const char *str) if (a->data.v) { free(a->data.v); } - a->data.v = _strdup(str); + a->data.v = strdup(str); } /*********************/ @@ -809,8 +809,8 @@ void set_level(unit * u, skill_t sk, int value) static int leftship_age(struct attrib *a, void *owner) { /* must be aged, so it doesn't affect report generation (cansee) */ - unused_arg(a); - unused_arg(owner); + UNUSED_ARG(a); + UNUSED_ARG(owner); return AT_AGE_REMOVE; /* remove me */ } @@ -1390,7 +1390,7 @@ int invisible(const unit * target, const unit * viewer) else { int hidden = item_invis(target); if (hidden) { - hidden = _min(hidden, target->number); + hidden = MIN(hidden, target->number); if (viewer) { const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); hidden -= i_get(viewer->items, rtype->itype); @@ -1533,7 +1533,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, u->hp = unit_max_hp(u) * number; if (dname) { - u->_name = _strdup(dname); + u->_name = strdup(dname); } else if (urace->generate_name || playerrace(urace)) { name_unit(u); @@ -1640,7 +1640,7 @@ void unit_setname(unit * u, const char *name) { free(u->_name); if (name && name[0]) - u->_name = _strdup(name); + u->_name = strdup(name); else u->_name = NULL; } @@ -1654,7 +1654,7 @@ void unit_setinfo(unit * u, const char *info) { free(u->display); if (info) - u->display = _strdup(info); + u->display = strdup(info); else u->display = NULL; } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 1a481960d..b0a2891c5 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -240,9 +240,9 @@ static void test_default_name(CuTest *tc) { } static int cb_skillmod(const unit *u, const region *r, skill_t sk, int level) { - unused_arg(u); - unused_arg(r); - unused_arg(sk); + UNUSED_ARG(u); + UNUSED_ARG(r); + UNUSED_ARG(sk); return level + 3; } @@ -395,7 +395,7 @@ static void test_unit_description(CuTest *tc) { u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0)); CuAssertPtrEquals(tc, 0, u->display); CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale)); - u->display = _strdup("Hodor"); + u->display = strdup("Hodor"); CuAssertStrEquals(tc, "Hodor", u_description(u, NULL)); CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale)); test_cleanup(); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 640a28940..2f38cdab3 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -94,8 +94,8 @@ static xmlChar *xml_cleanup_string(xmlChar * str) while (*read) { /* eat leading whitespace */ - if (*read && isxspace(*read)) { - while (*read && isxspace(*read)) { + if (*read && isspace(*read)) { + while (*read && isspace(*read)) { ++read; } *write++ = ' '; @@ -379,7 +379,7 @@ static int parse_calendar(xmlDocPtr doc) first_turn = xml_ivalue(calendar, "start", first_turn); if (propValue) { free(agename); - agename = _strdup(mkname("calendar", (const char *)propValue)); + agename = strdup(mkname("calendar", (const char *)propValue)); xmlFree(propValue); } @@ -398,7 +398,7 @@ static int parse_calendar(xmlDocPtr doc) xmlNodePtr week = nsetWeeks->nodeTab[i]; xmlChar *propValue = xmlGetProp(week, BAD_CAST "name"); if (propValue) { - weeknames[i] = _strdup(mkname("calendar", (const char *)propValue)); + weeknames[i] = strdup(mkname("calendar", (const char *)propValue)); weeknames2[i] = malloc(strlen(weeknames[i]) + 3); sprintf(weeknames2[i], "%s_d", weeknames[i]); xmlFree(propValue); @@ -421,7 +421,7 @@ static int parse_calendar(xmlDocPtr doc) xmlChar *propValue = xmlGetProp(season, BAD_CAST "name"); if (propValue) { seasonnames[i] = - _strdup(mkname("calendar", (const char *)propValue)); + strdup(mkname("calendar", (const char *)propValue)); xmlFree(propValue); } } @@ -451,7 +451,7 @@ static int parse_calendar(xmlDocPtr doc) xmlFree(newyear); newyear = NULL; } - monthnames[i] = _strdup(mkname("calendar", (const char *)propValue)); + monthnames[i] = strdup(mkname("calendar", (const char *)propValue)); xmlFree(propValue); } if (nsetSeasons) { @@ -663,7 +663,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) xmlFree(propValue); propValue = xmlGetProp(node, BAD_CAST "value"); - wtype->damage[pos] = _strdup((const char *)propValue); // TODO: this is a memory leak + wtype->damage[pos] = strdup((const char *)propValue); // TODO: this is a memory leak if (k == 0) wtype->damage[1 - pos] = wtype->damage[pos]; xmlFree(propValue); @@ -1426,13 +1426,13 @@ static int parse_spells(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "parameters"); if (propValue) { - sp->parameter = _strdup((const char *)propValue); + sp->parameter = strdup((const char *)propValue); xmlFree(propValue); } propValue = xmlGetProp(node, BAD_CAST "syntax"); if (propValue) { - sp->syntax = _strdup((const char *)propValue); + sp->syntax = strdup((const char *)propValue); xmlFree(propValue); } #ifdef TODO /* no longer need it, spellbooks! */ @@ -1628,7 +1628,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "damage"); assert(propValue != NULL); - rc->def_damage = _strdup((const char *)propValue); + rc->def_damage = strdup((const char *)propValue); xmlFree(propValue); rc->magres = (float)xml_fvalue(node, "magres", rc->magres); @@ -1869,7 +1869,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "damage"); if (propValue != NULL) { - attack->data.dice = _strdup((const char *)propValue); + attack->data.dice = strdup((const char *)propValue); xmlFree(propValue); } else { @@ -1932,7 +1932,7 @@ static int parse_messages(xmlDocPtr doc) (const char *)propType); xmlFree(propName); xmlFree(propType); - argv[k] = _strdup(zBuffer); + argv[k] = strdup(zBuffer); } argv[result->nodesetval->nodeNr] = NULL; } diff --git a/src/laws.c b/src/laws.c index d311f698e..bbf1a200b 100644 --- a/src/laws.c +++ b/src/laws.c @@ -209,7 +209,7 @@ static void live(region * r) } /* bestes Talent raussuchen */ if (sb != NULL) { - int weeks = _min(effect, u->number); + int weeks = MIN(effect, u->number); reduce_skill(u, sb, weeks); ADDMSG(&u->faction->msgs, msg_message("dumbeffect", "unit weeks skill", u, weeks, (skill_t)sb->id)); @@ -267,7 +267,7 @@ static void calculate_emigration(region * r) int max_emigration = MAX_EMIGRATION(rp2 - maxp2); if (max_emigration > 0) { - max_emigration = _min(max_emigration, max_immigrants); + max_emigration = MIN(max_emigration, max_immigrants); r->land->newpeasants += max_emigration; rc->land->newpeasants -= max_emigration; max_immigrants -= max_emigration; @@ -318,7 +318,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance) double mean; if (luck == 0) return 0; - mean = peasant_luck_factor() * peasant_growth_factor() * _min(luck, peasants); + mean = peasant_luck_factor() * peasant_growth_factor() * MIN(luck, peasants); mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE); births = RAND_ROUND(normalvariate(mean, variance * mean)); @@ -357,7 +357,7 @@ static void peasants(region * r) /* Alle werden satt, oder halt soviele für die es auch Geld gibt */ - satiated = _min(peasants, money / maintenance_cost(NULL)); + satiated = MIN(peasants, money / maintenance_cost(NULL)); rsetmoney(r, money - satiated * maintenance_cost(NULL)); /* Von denjenigen, die nicht satt geworden sind, verhungert der @@ -366,7 +366,7 @@ static void peasants(region * r) /* Es verhungert maximal die unterernährten Bevölkerung. */ - n = _min(peasants - satiated, rpeasants(r)); + n = MIN(peasants - satiated, rpeasants(r)); dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE); if (dead > 0) { @@ -447,7 +447,7 @@ static void horses(region * r) /* Logistisches Wachstum, Optimum bei halbem Maximalbesatz. */ maxhorses = region_maxworkers(r) / 10; - maxhorses = _max(0, maxhorses); + maxhorses = MAX(0, maxhorses); horses = rhorses(r); if (horses > 0) { if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) { @@ -481,7 +481,7 @@ static void horses(region * r) if (r2 && fval(r2->terrain, WALK_INTO)) { int pt = (rhorses(r) * HORSEMOVE) / 100; pt = (int)normalvariate(pt, pt / 4.0); - pt = _max(0, pt); + pt = MAX(0, pt); if (fval(r2, RF_MIGRATION)) rsethorses(r2, rhorses(r2) + pt); else { @@ -594,7 +594,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) a = a_find(r->attribs, &at_germs); if (a && last_weeks_season == SEASON_SPRING) { /* ungekeimte Samen bleiben erhalten, Sprößlinge wachsen */ - sprout = _min(a->data.sa[1], rtrees(r, 1)); + sprout = MIN(a->data.sa[1], rtrees(r, 1)); /* aus dem gesamt Sprößlingepool abziehen */ rsettrees(r, 1, rtrees(r, 1) - sprout); /* zu den Bäumen hinzufügen */ @@ -614,7 +614,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) /* Grundchance 1.0% */ /* Jeder Elf in der Region erhöht die Chance marginal */ - elves = _min(elves, production(r) / 8); + elves = MIN(elves, production(r) / 8); if (elves) { seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY); } @@ -680,7 +680,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) /* Raubbau abfangen, es dürfen nie mehr Samen wachsen, als aktuell * in der Region sind */ - seeds = _min(a->data.sa[0], rtrees(r, 0)); + seeds = MIN(a->data.sa[0], rtrees(r, 0)); sprout = 0; for (i = 0; i < seeds; i++) { @@ -700,7 +700,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) * der Region entfernt werden können, da Jungbäume in der gleichen * Runde nachwachsen, wir also nicht mehr zwischen diesjährigen und * 'alten' Jungbäumen unterscheiden könnten */ - sprout = _min(a->data.sa[1], rtrees(r, 1)); + sprout = MIN(a->data.sa[1], rtrees(r, 1)); grownup_trees = 0; for (i = 0; i < sprout; i++) { @@ -740,7 +740,7 @@ void immigration(void) for (r = regions; r; r = r->next) { if (r->land && r->land->newpeasants) { int rp = rpeasants(r) + r->land->newpeasants; - rsetpeasants(r, _max(0, rp)); + rsetpeasants(r, MAX(0, rp)); } /* Genereate some (0-6 depending on the income) peasants out of nothing */ /* if less than 50 are in the region and there is space and no monster or demon units in the region */ @@ -843,7 +843,7 @@ void demographics(void) calculate_emigration(r); peasants(r); if (r->age > 20) { - double mwp = _max(region_maxworkers(r), 1); + double mwp = MAX(region_maxworkers(r), 1); double prob = pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0) * PLAGUE_CHANCE; @@ -1280,7 +1280,7 @@ static void remove_idle_players(void) } log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben..."); - age = calloc(_max(4, turn + 1), sizeof(int)); + age = calloc(MAX(4, turn + 1), sizeof(int)); for (fp = &factions; *fp;) { faction *f = *fp; if (!is_monsters(f)) { @@ -1621,7 +1621,7 @@ int display_cmd(unit * u, struct order *ord) free(*s); if (s2) { - *s = _strdup(s2); + *s = strdup(s2); if (strlen(s2) >= DISPLAYSIZE) { (*s)[DISPLAYSIZE] = 0; } @@ -1665,7 +1665,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2) unicode_utf8_trim(name); free(*s); - *s = _strdup(name); + *s = strdup(name); return 0; } @@ -2154,7 +2154,7 @@ int banner_cmd(unit * u, struct order *ord) const char * s = getstrtoken(); free(u->faction->banner); - u->faction->banner = s ? _strdup(s) : 0; + u->faction->banner = s ? strdup(s) : 0; add_message(&u->faction->msgs, msg_message("changebanner", "value", u->faction->banner)); @@ -2356,23 +2356,23 @@ static void display_race(unit * u, const race * rc) } } if (rc->battle_flags & BF_EQUIPMENT) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"))) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_PIERCE) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"))) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_CUT) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"))) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_BASH) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"))) != 0) WARN_STATIC_BUFFER(); } - if (wrptr(&bufp, &size, _snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks"))) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks"))) != 0) WARN_STATIC_BUFFER(); for (a = 0; a < RACE_ATTACKS; a++) { @@ -2385,12 +2385,12 @@ static void display_race(unit * u, const race * rc) switch (rc->attack[a].type) { case AT_STANDARD: bytes = - (size_t)_snprintf(bufp, size, "%s (%s)", + (size_t)snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_standard"), rc->def_damage); break; case AT_NATURAL: bytes = - (size_t)_snprintf(bufp, size, "%s (%s)", + (size_t)snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); break; case AT_SPELL: @@ -2398,11 +2398,11 @@ static void display_race(unit * u, const race * rc) case AT_DRAIN_ST: case AT_DRAIN_EXP: case AT_DAZZLE: - bytes = (size_t)_snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); + bytes = (size_t)snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); break; case AT_STRUCTURAL: bytes = - (size_t)_snprintf(bufp, size, "%s (%s)", + (size_t)snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); break; default: @@ -2670,7 +2670,7 @@ int combatspell_cmd(unit * u, struct order *ord) if (findparam(s, u->faction->locale) == P_LEVEL) { /* Merken, setzen kommt erst später */ level = getint(); - level = _max(0, level); + level = MAX(0, level); s = gettoken(token, sizeof(token)); } @@ -2903,14 +2903,14 @@ static void age_stonecircle(building *b) { float effect = 100; /* the mage reactivates the circle */ c = create_curse(mage, &rt->attribs, ct_astralblock, - (float)_max(1, sk), _max(1, sk / 2), effect, 0); + (float)MAX(1, sk), MAX(1, sk / 2), effect, 0); ADDMSG(&r->msgs, msg_message("astralshield_activate", "region unit", r, mage)); } else { int sk = effskill(mage, SK_MAGIC, 0); - c->duration = _max(c->duration, sk / 2); - c->vigour = _max(c->vigour, (float)sk); + c->duration = MAX(c->duration, sk / 2); + c->vigour = MAX(c->vigour, (float)sk); } } } @@ -2955,12 +2955,12 @@ static void ageing(void) /* Goliathwasser */ int i = get_effect(u, oldpotiontype[P_STRONG]); if (i > 0) { - change_effect(u, oldpotiontype[P_STRONG], -1 * _min(u->number, i)); + change_effect(u, oldpotiontype[P_STRONG], -1 * MIN(u->number, i)); } /* Berserkerblut */ i = get_effect(u, oldpotiontype[P_BERSERK]); if (i > 0) { - change_effect(u, oldpotiontype[P_BERSERK], -1 * _min(u->number, i)); + change_effect(u, oldpotiontype[P_BERSERK], -1 * MIN(u->number, i)); } if (is_cursed(u->attribs, C_OLDRACE, 0)) { @@ -3034,7 +3034,7 @@ static int maxunits(const faction * f) if (flimit == 0) { return alimit; } - return _min(alimit, flimit); + return MIN(alimit, flimit); } int checkunitnumber(const faction * f, int add) @@ -3130,7 +3130,7 @@ void new_units(void) s = gettoken(token, sizeof(token)); if (s && s[0]) { - name = _strdup(s); + name = strdup(s); } u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u); if (name != NULL) @@ -3361,7 +3361,7 @@ void monthly_healing(void) p *= heal_factor(u); if (u->hp < umhp) { - double maxheal = _max(u->number, umhp / 20.0); + double maxheal = MAX(u->number, umhp / 20.0); int addhp; if (active_building(u, bt_find("inn"))) { p *= 1.5; @@ -3376,7 +3376,7 @@ void monthly_healing(void) ++addhp; /* Aufaddieren der geheilten HP. */ - u->hp = _min(u->hp + addhp, umhp); + u->hp = MIN(u->hp + addhp, umhp); /* soll man an negativer regeneration sterben können? */ assert(u->hp > 0); @@ -3701,7 +3701,7 @@ int claim_cmd(unit * u, struct order *ord) if (itype) { item **iclaim = i_find(&u->faction->items, itype); if (iclaim && *iclaim) { - n = _min(n, (*iclaim)->number); + n = MIN(n, (*iclaim)->number); i_change(iclaim, itype, -n); i_change(&u->items, itype, n); } @@ -3962,7 +3962,7 @@ int armedmen(const unit * u, bool siege_weapons) if (n >= u->number) break; } - n = _min(n, u->number); + n = MIN(n, u->number); } } return n; @@ -3998,9 +3998,9 @@ int siege_cmd(unit * u, order * ord) rt_catapult = rt_find("catapult"); d = i_get(u->items, rt_catapult->itype); - d = _min(u->number, d); + d = MIN(u->number, d); pooled = get_pooled(u, rt_catapultammo, GET_DEFAULT, d); - d = _min(pooled, d); + d = MIN(pooled, d); if (effskill(u, SK_CATAPULT, 0) >= 1) { katapultiere = d; d *= effskill(u, SK_CATAPULT, 0); @@ -4027,11 +4027,11 @@ int siege_cmd(unit * u, order * ord) * einheiten wieder abgesucht werden muessen! */ usetsiege(u, b); - b->besieged += _max(bewaffnete, katapultiere); + b->besieged += MAX(bewaffnete, katapultiere); /* definitiver schaden eingeschraenkt */ - d = _min(d, b->size - 1); + d = MIN(d, b->size - 1); /* meldung, schaden anrichten */ if (d && !curse_active(get_curse(b->attribs, magicwalls_ct))) { @@ -4270,7 +4270,7 @@ void processorders(void) void update_subscriptions(void) { FILE *F; - char zText[MAX_PATH]; + char zText[4096]; join_path(basepath(), "subscriptions", zText, sizeof(zText)); F = fopen(zText, "r"); diff --git a/src/laws.h b/src/laws.h index 0adb010d2..f05c11ab4 100755 --- a/src/laws.h +++ b/src/laws.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_GC_LAWS #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/lighthouse.c b/src/lighthouse.c index 09c9b7d11..d29d58b71 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -83,8 +83,8 @@ int lighthouse_range(const building * b, const faction * f) } else if (f == NULL || u->faction == f) { int sk = effskill(u, SK_PERCEPTION, 0) / 3; - d = _max(d, sk); - d = _min(maxd, d); + d = MAX(d, sk); + d = MIN(maxd, d); if (d == maxd) break; } diff --git a/src/lighthouse.h b/src/lighthouse.h index 3bf970bf1..f2974ddf1 100644 --- a/src/lighthouse.h +++ b/src/lighthouse.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef LIGHTHOUSE_H #define LIGHTHOUSE_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/listbox.c b/src/listbox.c index 332041454..057240fad 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -27,7 +27,7 @@ insert_selection(list_selection ** p_sel, list_selection * prev, const char *str, void *payload) { list_selection *sel = calloc(sizeof(list_selection), 1); - sel->str = _strdup(str); + sel->str = strdup(str); sel->data = payload; if (*p_sel) { list_selection *s; diff --git a/src/magic.c b/src/magic.c index dbdc1abe8..f2992538c 100644 --- a/src/magic.c +++ b/src/magic.c @@ -118,7 +118,7 @@ static double MagicPower(double force) if (force > 0) { const char *str = config_get("magic.power"); double value = str ? atof(str) : 1.0; - return _max(value * force, 1.0f); + return MAX(value * force, 1.0f); } return 0; } @@ -146,7 +146,7 @@ static void a_writeicastle(const attrib * a, const void *owner, struct storage *store) { icastle_data *data = (icastle_data *)a->data.v; - unused_arg(owner); + UNUSED_ARG(owner); WRITE_TOK(store, data->type->_name); WRITE_INT(store, data->time); } @@ -543,7 +543,7 @@ int get_combatspelllevel(const unit * u, int nr) assert(nr < MAXCOMBATSPELLS); if (m) { int level = effskill(u, SK_MAGIC, 0); - return _min(m->combatspells[nr].level, level); + return MIN(m->combatspells[nr].level, level); } return -1; } @@ -679,7 +679,7 @@ int change_spellpoints(unit * u, int mp) } /* verhindere negative Magiepunkte */ - sp = _max(m->spellpoints + mp, 0); + sp = MAX(m->spellpoints + mp, 0); m->spellpoints = sp; return sp; @@ -739,7 +739,7 @@ int max_spellpoints(const region * r, const unit * u) if (n > 0) { msp = (msp * n) / 100; } - return _max((int)msp, 0); + return MAX((int)msp, 0); } int change_maxspellpoints(unit * u, int csp) @@ -774,7 +774,7 @@ int countspells(unit * u, int step) count = m->spellcount + step; /* negative Werte abfangen. */ - m->spellcount = _max(0, count); + m->spellcount = MAX(0, count); return m->spellcount; } @@ -867,7 +867,7 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range) } else if (sp->components[k].cost == SPC_LEVEL) { costtyp = SPC_LEVEL; - cast_level = _min(cast_level, maxlevel); + cast_level = MIN(cast_level, maxlevel); /* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden * sein, ansonsten schlägt der Spruch fehl */ } @@ -885,7 +885,7 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range) if (sb) { spellbook_entry * sbe = spellbook_get(sb, sp); if (sbe) { - return _min(cast_level, sbe->level); + return MIN(cast_level, sbe->level); } } log_error("spell %s is not in the spellbook for %s\n", sp->sname, unitname(u)); @@ -1103,7 +1103,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order } } } - return _max(force, 0); + return MAX(force, 0); } /* ------------------------------------------------------------- */ @@ -1278,8 +1278,8 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) break; } - probability = _max(0.02, probability + t_bonus * 0.01); - probability = _min(0.98, probability); + probability = MAX(0.02, probability + t_bonus * 0.01); + probability = MIN(0.98, probability); /* gibt true, wenn die Zufallszahl kleiner als die chance ist und * false, wenn sie gleich oder größer ist, dh je größer die @@ -1421,7 +1421,7 @@ static void do_fumble(castorder * co) case 2: /* temporary skill loss */ - duration = _max(rng_int() % level / 2, 2); + duration = MAX(rng_int() % level / 2, 2); effect = level / -2.0; c = create_curse(u, &u->attribs, ct_find("skillmod"), level, duration, effect, 1); @@ -1529,14 +1529,14 @@ void regenerate_aura(void) reg_aura -= regen; if (chance(reg_aura)) ++regen; - regen = _max(1, regen); - regen = _min((auramax - aura), regen); + regen = MAX(1, regen); + regen = MIN((auramax - aura), regen); aura += regen; ADDMSG(&u->faction->msgs, msg_message("regenaura", "unit region amount", u, r, regen)); } - set_spellpoints(u, _min(aura, auramax)); + set_spellpoints(u, MIN(aura, auramax)); } } } @@ -1853,7 +1853,7 @@ static int addparam_string(const char *const param[], spllprm ** spobjp) spobj->flag = 0; spobj->typ = SPP_STRING; - spobj->data.xs = _strdup(param[0]); + spobj->data.xs = strdup(param[0]); return 1; } @@ -2428,7 +2428,7 @@ static int age_unit(attrib * a, void *owner) /* if unit is gone or dead, remove the attribute */ { unit *u = (unit *)a->data.v; - unused_arg(owner); + UNUSED_ARG(owner); return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -2567,7 +2567,7 @@ static castorder *cast_cmd(unit * u, order * ord) /* für Syntax ' STUFE x REGION y z ' */ if (param == P_LEVEL) { int p = getint(); - level = _min(p, level); + level = MIN(p, level); if (level < 1) { /* Fehler "Das macht wenig Sinn" */ syntax_error(u, ord); @@ -2597,7 +2597,7 @@ static castorder *cast_cmd(unit * u, order * ord) * hier nach REGION nochmal auf STUFE prüfen */ if (param == P_LEVEL) { int p = getint(); - level = _min(p, level); + level = MIN(p, level); if (level < 1) { /* Fehler "Das macht wenig Sinn" */ syntax_error(u, ord); @@ -2728,7 +2728,7 @@ static castorder *cast_cmd(unit * u, order * ord) * löschen, zaubern kann er noch */ range *= 2; set_order(&caster->thisorder, NULL); - level = _min(level, effskill(caster, SK_MAGIC, 0) / 2); + level = MIN(level, effskill(caster, SK_MAGIC, 0) / 2); } } /* Weitere Argumente zusammenbasteln */ @@ -2751,7 +2751,7 @@ static castorder *cast_cmd(unit * u, order * ord) break; } } - params[p++] = _strdup(s); + params[p++] = strdup(s); } params[p] = 0; args = diff --git a/src/magic.h b/src/magic.h index d1ae286d0..f62c533bd 100644 --- a/src/magic.h +++ b/src/magic.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_MAGIC #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/market.test.c b/src/market.test.c index 43e070b5e..6f1d74b88 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -46,7 +46,7 @@ static void test_market_curse(CuTest * tc) config_set("rules.region_owners", "1"); btype = (building_type *)calloc(1, sizeof(building_type)); - btype->_name = _strdup("market"); + btype->_name = strdup("market"); bt_register(btype); terrain = get_terrain("plain"); diff --git a/src/modules/arena.c b/src/modules/arena.c index a912d273a..fbc3f0673 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -99,9 +99,9 @@ order * ord) if (u->building != arena_tower(u->faction->magiegebiet) && leave_fail(u)) { return -1; } - unused_arg(amount); - unused_arg(ord); - unused_arg(itype); + UNUSED_ARG(amount); + UNUSED_ARG(ord); + UNUSED_ARG(itype); assert(!"not implemented"); return 0; } @@ -120,9 +120,9 @@ enter_arena(unit * u, const item_type * itype, int amount, order * ord) region *r = u->region; unit *u2; int fee = 2000; - unused_arg(ord); - unused_arg(amount); - unused_arg(itype); + UNUSED_ARG(ord); + UNUSED_ARG(amount); + UNUSED_ARG(itype); if (u->faction->score > fee * 5) { score_t score = u->faction->score / 5; if (score < INT_MAX) { @@ -212,7 +212,7 @@ static int caldera_handle(trigger * t, void *data) else { log_error("could not perform caldera::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 925fae349..1e2d2d23f 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -199,7 +199,7 @@ newfaction *read_newfactions(const char *filename) free(nf); continue; } - nf->password = _strdup(password); + nf->password = strdup(password); nf->race = rc_find(race); nf->subscription = subscription; if (alliances != NULL) { @@ -962,8 +962,8 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi q = region_quality(r, rn); if (q >= MIN_QUALITY && nfactions < numfactions && *players) { starting_region(players, r, rn); - minq = _min(minq, q); - maxq = _max(maxq, q); + minq = MIN(minq, q); + maxq = MAX(maxq, q); ++nfactions; } } @@ -977,8 +977,8 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi q = region_quality(r, rn); if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) { starting_region(players, r, rn); - minq = _min(minq, q); - maxq = _max(maxq, q); + minq = MIN(minq, q); + maxq = MAX(maxq, q); ++nfactions; } } diff --git a/src/modules/museum.c b/src/modules/museum.c index e934a71a4..af37019d0 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -310,7 +310,7 @@ order * ord) unit *warden = findunit(atoi36("mwar")); int unit_cookie; - unused_arg(amount); + UNUSED_ARG(amount); /* Prüfen ob in Eingangshalle */ if (u->region->x != 9525 || u->region->y != 9525) { @@ -365,7 +365,7 @@ order * ord) region *r = u->region; plane *pl = rplane(r); - unused_arg(amount); + UNUSED_ARG(amount); /* Pruefen ob in normaler Plane und nur eine Person */ if (pl != get_homeplane()) { @@ -417,8 +417,8 @@ static const char *b_namequestportal(const connection * b, const region * r, { const char *bname; int lock = b->data.i; - unused_arg(b); - unused_arg(r); + UNUSED_ARG(b); + UNUSED_ARG(r); if (gflags & GF_ARTICLE) { if (lock > 0) { diff --git a/src/modules/score.c b/src/modules/score.c index 8213b8985..0776d6507 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -67,7 +67,7 @@ void score(void) region *r; faction *fc; score_t allscores = 0; - char path[MAX_PATH]; + char path[4096]; for (fc = factions; fc; fc = fc->next) fc->score = 0; diff --git a/src/monsters.c b/src/monsters.c index 829c1ed35..bba1cbd50 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -100,7 +100,7 @@ static void reduce_weight(unit * u) int horses = get_resource(u, get_resourcetype(R_HORSE)); if (horses > 0) { - horses = _min(horses, (u->number * 2)); + horses = MIN(horses, (u->number * 2)); change_resource(u, get_resourcetype(R_HORSE), -horses); } @@ -129,7 +129,7 @@ static void reduce_weight(unit * u) if (itype->weight >= 10 && itype->rtype->wtype == 0 && itype->rtype->atype == 0) { if (itype->capacity < itype->weight) { - int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); + int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } @@ -144,7 +144,7 @@ static void reduce_weight(unit * u) const item_type *itype = itm->type; weight += itm->number * itype->weight; if (itype->capacity < itype->weight) { - int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); + int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } @@ -1027,7 +1027,7 @@ static void eaten_by_monster(unit * u) n = (int)(n * multi); if (n > 0) { n = lovar(n); - n = _min(rpeasants(u->region), n); + n = MIN(rpeasants(u->region), n); if (n > 0) { deathcounts(u->region, n); @@ -1047,7 +1047,7 @@ static void absorbed_by_monster(unit * u) if (n > 0) { n = lovar(n); - n = _min(rpeasants(u->region), n); + n = MIN(rpeasants(u->region), n); if (n > 0) { rsetpeasants(u->region, rpeasants(u->region) - n); scale_number(u, u->number + n); @@ -1062,7 +1062,7 @@ static int scareaway(region * r, int anzahl) int n, p, diff = 0, emigrants[MAXDIRECTIONS]; direction_t d; - anzahl = _min(_max(1, anzahl), rpeasants(r)); + anzahl = MIN(MAX(1, anzahl), rpeasants(r)); /* Wandern am Ende der Woche (normal) oder wegen Monster. Die * Wanderung wird erst am Ende von demographics () ausgefuehrt. @@ -1074,7 +1074,7 @@ static int scareaway(region * r, int anzahl) p = rpeasants(r); assert(p >= 0 && anzahl >= 0); - for (n = _min(p, anzahl); n; n--) { + for (n = MIN(p, anzahl); n; n--) { direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); region *rc = rconnect(r, dir); @@ -1102,7 +1102,7 @@ static void scared_by_monster(unit * u) } if (n > 0) { n = lovar(n); - n = _min(rpeasants(u->region), n); + n = MIN(rpeasants(u->region), n); if (n > 0) { n = scareaway(u->region, n); if (n > 0) { diff --git a/src/morale.c b/src/morale.c index 8dc22ccb5..1bdf2363d 100644 --- a/src/morale.c +++ b/src/morale.c @@ -73,7 +73,7 @@ void morale_update(region *r) { void morale_change(region *r, int value) { int morale = region_get_morale(r); if (morale > 0) { - morale = _max(0, morale - value); + morale = MAX(0, morale - value); region_set_morale(r, morale, turn); } } diff --git a/src/move.c b/src/move.c index 126557d58..62300beb1 100644 --- a/src/move.c +++ b/src/move.c @@ -151,8 +151,8 @@ static void shiptrail_finalize(attrib * a) static int shiptrail_age(attrib * a, void *owner) { traveldir *t = (traveldir *)(a->data.v); - unused_arg(owner); + (void)owner; t->age--; return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -267,12 +267,12 @@ static int ridingcapacity(unit * u) ** tragen nichts (siehe walkingcapacity). Ein Wagen zählt nur, wenn er ** von zwei Pferden gezogen wird */ - animals = _min(animals, effskill(u, SK_RIDING, 0) * u->number * 2); + animals = MIN(animals, effskill(u, SK_RIDING, 0) * u->number * 2); if (fval(u_race(u), RCF_HORSE)) animals += u->number; /* maximal diese Pferde können zum Ziehen benutzt werden */ - vehicles = _min(animals / HORSESNEEDED, vehicles); + vehicles = MIN(animals / HORSESNEEDED, vehicles); return vehicles * vcap + animals * acap; } @@ -291,7 +291,7 @@ int walkingcapacity(const struct unit *u) /* Das Gewicht, welches die Pferde tragen, plus das Gewicht, welches * die Leute tragen */ - pferde_fuer_wagen = _min(animals, effskill(u, SK_RIDING, 0) * u->number * 4); + pferde_fuer_wagen = MIN(animals, effskill(u, SK_RIDING, 0) * u->number * 4); if (fval(u_race(u), RCF_HORSE)) { animals += u->number; people = 0; @@ -301,7 +301,7 @@ int walkingcapacity(const struct unit *u) } /* maximal diese Pferde können zum Ziehen benutzt werden */ - wagen_mit_pferden = _min(vehicles, pferde_fuer_wagen / HORSESNEEDED); + wagen_mit_pferden = MIN(vehicles, pferde_fuer_wagen / HORSESNEEDED); n = wagen_mit_pferden * vcap; @@ -311,7 +311,7 @@ int walkingcapacity(const struct unit *u) wagen_ohne_pferde = vehicles - wagen_mit_pferden; /* Genug Trolle, um die Restwagen zu ziehen? */ - wagen_mit_trollen = _min(u->number / 4, wagen_ohne_pferde); + wagen_mit_trollen = MIN(u->number / 4, wagen_ohne_pferde); /* Wagenkapazität hinzuzählen */ n += wagen_mit_trollen * vcap; @@ -335,7 +335,7 @@ int walkingcapacity(const struct unit *u) int belts = i_get(u->items, rbelt->itype); if (belts) { int multi = config_get_int("rules.trollbelt.multiplier", STRENGTHMULTIPLIER); - n += _min(people, belts) * (multi - 1) * u_race(u)->capacity; + n += MIN(people, belts) * (multi - 1) * u_race(u)->capacity; } } @@ -366,7 +366,7 @@ static int canwalk(unit * u) effsk = effskill(u, SK_RIDING, 0); maxwagen = effsk * u->number * 2; if (u_race(u) == get_race(RC_TROLL)) { - maxwagen = _max(maxwagen, u->number / 4); + maxwagen = MAX(maxwagen, u->number / 4); } maxpferde = effsk * u->number * 4 + u->number; @@ -505,7 +505,7 @@ static double overload(const region * r, ship * sh) double ovl = n / (double)sh->type->cargo; if (mcabins) - ovl = _max(ovl, p / (double)mcabins); + ovl = MAX(ovl, p / (double)mcabins); return ovl; } } @@ -752,7 +752,7 @@ double damage_overload(double overload) badness = overload - overload_worse(); if (badness >= 0) { assert(overload_worst() > overload_worse() || !"overload.worst must be > overload.worse"); - damage += _min(badness, overload_worst() - overload_worse()) * + damage += MIN(badness, overload_worst() - overload_worse()) * (overload_max_damage() - damage) / (overload_worst() - overload_worse()); } @@ -946,7 +946,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) guard_count += u->number; double prob_u = (sk - stealth) * skill_prob; /* amulet counts at most once */ - prob_u += _min(1, _min(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; + prob_u += MIN(1, MIN(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; if (u->building && (u->building->type == castle_bt) && u == building_owner(u->building)) prob_u += castle_prob*buildingeffsize(u->building, 0); if (prob_u >= prob) { @@ -1985,7 +1985,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) const luxury_type *ltype = resource2luxury(itm->type->rtype); if (ltype != NULL && itm->number > 0) { int st = itm->number * effskill(harbourmaster, SK_TRADE, 0) / 50; - st = _min(itm->number, st); + st = MIN(itm->number, st); if (st > 0) { i_change(&u2->items, itm->type, -st); diff --git a/src/move.h b/src/move.h index 14c040493..4d0b4e9f2 100644 --- a/src/move.h +++ b/src/move.h @@ -16,11 +16,12 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#include "direction.h" +#include + #ifndef H_KRNL_MOVEMENT #define H_KRNL_MOVEMENT -#include "direction.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/src/names.c b/src/names.c index cf1cdb910..248084828 100644 --- a/src/names.c +++ b/src/names.c @@ -365,7 +365,7 @@ static void dracoid_name(unit * u) size_t sz; /* ignore u */ - unused_arg(u); + UNUSED_ARG(u); /* Wieviele Mittelteile? */ mid_syllabels = rng_int() % 4; @@ -425,8 +425,8 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) } } - /* Buchstaben pro Teilkürzel = _max(1,max/AnzWort) */ - bpt = (c > 0) ? _max(1, maxchars / c) : 1; + /* Buchstaben pro Teilkürzel = MAX(1,max/AnzWort) */ + bpt = (c > 0) ? MAX(1, maxchars / c) : 1; /* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */ diff --git a/src/platform.h b/src/platform.h index c781021ae..2f114cec5 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,179 +1,15 @@ -/* -Copyright (c) 1998-2015, Enno Rehling - Katja Zedel +#pragma once -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. +#ifndef UNILIB_H +#define UNILIB_H -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef PLATFORM_H -#define PLATFORM_H - -#ifdef NDEBUG -#define LOMEM +#ifndef MAX_PATH +# define MAX_PATH 4096 #endif -// enable X/Open 7 extensions (like strdup): -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 700 -#endif +#define UNUSED_ARG(a) (void)(a) -// enable bsd string extensions, since glibc 2.12 (_BSD_SOURCE is dead): -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L -#endif - -#ifndef USE_AUTOCONF -#define USE_AUTOCONF - -#ifdef _MSC_VER -#undef USE_AUTOCONF -#define HAVE_STDBOOL_H -#define HAVE_DIRECT__MKDIR -#define HAVE__ACCESS - -#define VC_EXTRALEAN -#define WIN32_LEAN_AND_MEAN -#pragma warning(push) -#pragma warning(disable:4820 4255 4668) -# include -# include -#pragma warning(pop) -# undef MOUSE_MOVED -# define STDIO_CP 1252 /* log.c, convert to console character set */ -# pragma warning (disable: 4201 4214 4514 4115 4711) -#if _MSC_VER >= 1900 -# pragma warning(disable: 4710) -/* warning C4710: function not inlined */ -# pragma warning(disable: 4456) -/* warning C4456 : declaration of hides previous local declaration */ -# pragma warning(disable: 4457) -/* warning C4457: declaration of hides function parameter */ -# pragma warning(disable: 4459) -/* warning C4459: declaration of hides global declaration */ -#endif -# pragma warning(disable: 4056) -/* warning C4056: overflow in floating point constant arithmetic */ -# pragma warning(disable: 4201) -/* warning C4201: nonstandard extension used : nameless struct/union */ -# pragma warning(disable: 4214) -/* warning C4214: nonstandard extension used : bit field types other than int */ -# pragma warning(disable: 4100) -/* warning C4100: : unreferenced formal parameter */ -# pragma warning(disable: 4996) -/* is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */ -# pragma warning(disable: 4668) -/* : bytes padding after data member */ -# pragma warning(disable: 4820) - -/* warning C4100: was declared deprecated */ -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE -#endif - -/* - * http://msdn2.microsoft.com/en-us/library/ms235505(VS.80).aspx - * Defining _CRT_DISABLE_PERFCRIT_LOCKS forces all I/O operations to assume a - * single-threaded I/O model and use the _nolock forms of the functions. - */ -#ifndef _CRT_DISABLE_PERFCRIT_LOCKS -#define _CRT_DISABLE_PERFCRIT_LOCKS -#endif - -#elif __GNUC__ -#undef USE_AUTOCONF -#define HAVE_SNPRINTF -#define HAVE_SYS_STAT_MKDIR -#define HAVE_STRDUP -#define HAVE_UNISTD_H -#endif -#endif - -#ifdef USE_AUTOCONF -// unknown toolchain, using autoconf -#include -#endif - -#define unused_arg (void) - -#define iswxspace(c) (c==160 || iswspace(c)) -#define isxspace(c) (c==160 || isspace(c)) - -#define TOLUA_CAST (char*) - -#if !defined(MAX_PATH) -#if defined(PATH_MAX) -# define MAX_PATH PATH_MAX -#else -# define MAX_PATH 256 -#endif -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -#if defined(HAVE_STDBOOL_H) -# include -#else -# ifndef HAVE__BOOL -# ifdef __cplusplus -typedef bool _Bool; -# else -typedef unsigned char _Bool; -# endif -# endif -# define bool _Bool -# define false 0 -# define true 1 -# define __bool_true_false_are_defined 1 -#endif - -#ifndef HAVE__ACCESS -#ifdef HAVE_ACCESS -#define _access(path, mode) access(path, mode) -#endif -#endif - -#if defined(HAVE_DIRECT__MKDIR) -#include -#elif defined(HAVE_DIRECT_MKDIR) -#include -#define _mkdir(a) mkdir(a) -#elif defined(HAVE_SYS_STAT_MKDIR) -#include -#define _mkdir(a) mkdir(a, 0777) -#endif - -#ifndef _min -#define _min(a,b) ((a) < (b) ? (a) : (b)) -#endif -#ifndef _max -#define _max(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#if !defined(HAVE__STRDUP) -#if defined(HAVE_STRDUP) -#undef _strdup -#define _strdup strdup -#endif -#endif - -#if !defined(HAVE__SNPRINTF) -#if defined(HAVE_SNPRINTF) -#define _snprintf snprintf -#endif -#endif +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif - diff --git a/src/prefix.c b/src/prefix.c index a6564b6e8..1a22e6982 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -30,7 +30,7 @@ int add_raceprefix(const char *prefix) race_prefixes = tmp; size *= 2; } - race_prefixes[next++] = _strdup(prefix); + race_prefixes[next++] = strdup(prefix); race_prefixes[next] = NULL; return 0; } diff --git a/src/races/dragons.c b/src/races/dragons.c index 222d63c89..aa79a783a 100644 --- a/src/races/dragons.c +++ b/src/races/dragons.c @@ -22,7 +22,7 @@ /* util includes */ #include -#define age_chance(a,b,p) (_max(0,a-b)*p) +#define age_chance(a,b,p) (MAX(0,a-b)*p) #define DRAGONAGE 27 #define WYRMAGE 68 diff --git a/src/races/races.c b/src/races/races.c index 2c6cfffa9..8af9cf2ed 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -42,7 +42,7 @@ static void oldfamiliars(unit * u) char fname[64]; /* these familiars have no special skills. */ - _snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); + snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); create_mage(u, M_GRAY); equip_unit(u, get_equipment(fname)); } diff --git a/src/races/zombies.c b/src/races/zombies.c index 3e9303b38..ea26298b2 100644 --- a/src/races/zombies.c +++ b/src/races/zombies.c @@ -33,7 +33,7 @@ #define UNDEAD_BREAKUP 25 /* chance dafuer */ #define UNDEAD_BREAKUP_FRACTION (25+rng_int()%70) /* anteil der weg geht */ -#define age_chance(a,b,p) (_max(0,a-b)*p) +#define age_chance(a,b,p) (MAX(0,a-b)*p) void make_undead_unit(unit * u) { @@ -70,7 +70,7 @@ void age_undead(unit * u) void age_skeleton(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = _max(1, u->number / 2); + int n = MAX(1, u->number / 2); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_SKELETON_LORD)); u->irace = NULL; @@ -82,7 +82,7 @@ void age_skeleton(unit * u) void age_zombie(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = _max(1, u->number / 2); + int n = MAX(1, u->number / 2); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_ZOMBIE_LORD)); u->irace = NULL; @@ -94,7 +94,7 @@ void age_zombie(unit * u) void age_ghoul(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = _max(1, u->number / 2); + int n = MAX(1, u->number / 2); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_GHOUL_LORD)); u->irace = NULL; diff --git a/src/randenc.c b/src/randenc.c index 536210b1f..ab51d64b1 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -785,7 +785,7 @@ static void rotting_herbs(void) if (fval(itm->type, ITF_HERB)) { double nv = normalvariate(k, k / 4); int inv = (int)nv; - int delta = _min(n, inv); + int delta = MIN(n, inv); if (!i_change(itmp, itm->type, -delta)) { continue; } @@ -814,7 +814,7 @@ void randomevents(void) while (*blist) { building *b = *blist; if (fval(b->type, BTF_DECAY) && !building_owner(b)) { - b->size -= _max(1, (b->size * 20) / 100); + b->size -= MAX(1, (b->size * 20) / 100); if (b->size == 0) { remove_building(blist, r->buildings); } diff --git a/src/report.c b/src/report.c index 553e6cb94..503f12732 100644 --- a/src/report.c +++ b/src/report.c @@ -269,17 +269,17 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc /* Reihenfolge beachten: Erst REGION, dann STUFE! */ if (sp->sptyp & FARCASTING) { - bytes = _snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION])); + bytes = snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION])); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (sp->sptyp & SPELLLEVEL) { - bytes = _snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL])); + bytes = snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL])); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)_snprintf(bufp, size, " \"%s\"", spell_name(sp, lang)); + bytes = (int)snprintf(bufp, size, " \"%s\"", spell_name(sp, lang)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -305,12 +305,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc if (cp == 'u') { targetp = targets + 1; locp = LOC(lang, targetp->vars); - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -318,12 +318,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc else if (cp == 's') { targetp = targets + 2; locp = LOC(lang, targetp->vars); - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -342,12 +342,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc else if (cp == 'b') { targetp = targets + 3; locp = LOC(lang, targetp->vars); - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -382,17 +382,17 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc if (targetp->param && targetp->vars) { locp = LOC(lang, targetp->vars); bytes = - (int)_snprintf(bufp, size, " %s <%s>", parameters[targetp->param], + (int)snprintf(bufp, size, " %s <%s>", parameters[targetp->param], locp); if (multi) { if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); } } else { bytes = - (int)_snprintf(bufp, size, " %s", parameters[targetp->param]); + (int)snprintf(bufp, size, " %s", parameters[targetp->param]); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -422,10 +422,10 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } if (*params == '?') { ++params; - bytes = (int)_snprintf(bufp, size, " [<%s>]", locp); + bytes = (int)snprintf(bufp, size, " [<%s>]", locp); } else { - bytes = (int)_snprintf(bufp, size, " <%s>", locp); + bytes = (int)snprintf(bufp, size, " <%s>", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -494,18 +494,18 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la bufp = buf; if (sp->sptyp & SPELLLEVEL) { bytes = - _snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, + snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR) { - bytes = _snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); + bytes = snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } } else { - bytes = _snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); + bytes = snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); if (wrptr(&bufp, &size, bytes) != 0) { WARN_STATIC_BUFFER(); } @@ -929,7 +929,7 @@ static void describe(struct stream *out, const region * r, faction * f) } if (!e) { e = calloc(sizeof(struct edge), 1); - e->name = _strdup(name); + e->name = strdup(name); e->transparent = transparent; e->next = edges; edges = e; @@ -945,13 +945,13 @@ static void describe(struct stream *out, const region * r, faction * f) WARN_STATIC_BUFFER(); if (r->seen.mode == seen_travel) { - bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); } else if (r->seen.mode == seen_neighbour) { - bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); } else if (r->seen.mode == seen_lighthouse) { - bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); } else { bytes = 0; @@ -974,7 +974,7 @@ static void describe(struct stream *out, const region * r, faction * f) saplings = rtrees(r, 1); if (production(r)) { if (trees > 0 || saplings > 0) { - bytes = _snprintf(bufp, size, ", %d/%d ", trees, saplings); + bytes = snprintf(bufp, size, ", %d/%d ", trees, saplings); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1004,7 +1004,7 @@ static void describe(struct stream *out, const region * r, faction * f) for (n = 0; n < numresults; ++n) { if (result[n].number >= 0 && result[n].level >= 0) { - bytes = _snprintf(bufp, size, ", %d %s/%d", result[n].number, + bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number, LOC(f->locale, result[n].name), result[n].level); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1015,14 +1015,14 @@ static void describe(struct stream *out, const region * r, faction * f) /* peasants & silver */ if (rpeasants(r)) { int n = rpeasants(r); - bytes = _snprintf(bufp, size, ", %d", n); + bytes = snprintf(bufp, size, ", %d", n); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (r->land->ownership) { const char *str = LOC(f->locale, mkname("morale", itoa10(region_get_morale(r)))); - bytes = _snprintf(bufp, size, " %s", str); + bytes = snprintf(bufp, size, " %s", str); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1041,7 +1041,7 @@ static void describe(struct stream *out, const region * r, faction * f) } } if (rmoney(r) && r->seen.mode >= seen_travel) { - bytes = _snprintf(bufp, size, ", %d ", rmoney(r)); + bytes = snprintf(bufp, size, ", %d ", rmoney(r)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = @@ -1053,7 +1053,7 @@ static void describe(struct stream *out, const region * r, faction * f) /* Pferde */ if (rhorses(r)) { - bytes = _snprintf(bufp, size, ", %d ", rhorses(r)); + bytes = snprintf(bufp, size, ", %d ", rhorses(r)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = @@ -1141,7 +1141,7 @@ static void describe(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); f_regionid(r2, f, regname, sizeof(regname)); - bytes = _snprintf(bufp, size, trailinto(r2, f->locale), regname); + bytes = snprintf(bufp, size, trailinto(r2, f->locale), regname); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1453,7 +1453,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) bufp = buf; size = sizeof(buf) - 1; - bytes = _snprintf(bufp, size, "%s %s; %s [%d,%d$", + bytes = snprintf(bufp, size, "%s %s; %s [%d,%d$", LOC(u->faction->locale, parameters[P_UNIT]), itoa36(u->no), unit_getname(u), u->number, get_money(u)); if (wrptr(&bufp, &size, bytes) != 0) @@ -1631,7 +1631,7 @@ static void allies(struct stream *out, const faction * f) if (f->allies) { int bytes; size_t size = sizeof(buf); - bytes = _snprintf(buf, size, "%s ", LOC(f->locale, "faction_help")); + bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help")); size -= bytes; show_allies(f, f->allies, buf + bytes, size); paragraph(out, buf, 0, 0, 0); @@ -1642,7 +1642,7 @@ static void allies(struct stream *out, const faction * f) if (g->allies) { int bytes; size_t size = sizeof(buf); - bytes = _snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help")); + bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help")); size -= bytes; show_allies(f, g->allies, buf + bytes, size); paragraph(out, buf, 0, 0, 0); @@ -1781,12 +1781,12 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, getshipweight(sh, &n, &p); n = (n + 99) / 100; /* 1 Silber = 1 GE */ - bytes = _snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), + bytes = snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), LOC(f->locale, sh->type->_name), n, shipcapacity(sh) / 100); } else { bytes = - _snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, + snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, sh->type->_name)); } if (wrptr(&bufp, &size, bytes) != 0) @@ -1794,7 +1794,7 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */ if (sh->size != sh->type->construction->maxsize) { - bytes = _snprintf(bufp, size, ", %s (%d/%d)", + bytes = snprintf(bufp, size, ", %s (%d/%d)", LOC(f->locale, "nr_undercons"), sh->size, sh->type->construction->maxsize); if (wrptr(&bufp, &size, bytes) != 0) @@ -1803,7 +1803,7 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, if (sh->damage) { int percent = ship_damage_percent(sh); bytes = - _snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); + snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1852,7 +1852,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio lang = f->locale; newline(out); bytes = - _snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang, + snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang, "nr_size"), b->size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1867,7 +1867,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio if (owner && owner->faction == f) { /* illusion. report real type */ name = LOC(lang, bname); - bytes = _snprintf(bufp, size, " (%s)", name); + bytes = snprintf(bufp, size, " (%s)", name); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -2168,7 +2168,7 @@ report_plaintext(const char *filename, report_context * ctx, bufp = buf; size = sizeof(buf) - 1; - bytes = _snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); + bytes = snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); for (op = 0; op != MAXOPTIONS; op++) { @@ -2220,14 +2220,14 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); centre(out, LOC(f->locale, pname), true); - _snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), + snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), ptype->level); centre(out, buf, true); newline(out); bufp = buf; size = sizeof(buf) - 1; - bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); + bytes = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); diff --git a/src/report.test.c b/src/report.test.c index 555d39408..aa3c52695 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -139,7 +139,7 @@ static void cleanup_spell_fixture(spell_fixture *spf) { static void set_parameter(spell_fixture spell, char *value) { free(spell.sp->parameter); - spell.sp->parameter = _strdup(value); + spell.sp->parameter = strdup(value); } static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) { @@ -210,14 +210,14 @@ static void test_write_spell_syntax(CuTest *tc) { set_parameter(spell, "bc"); free(spell.sp->syntax); - spell.sp->syntax = _strdup("hodor"); + spell.sp->syntax = strdup("hodor"); check_spell_syntax(tc, "bc hodor", &spell, " ZAUBERE \"Testzauber\" "); free(spell.sp->syntax); spell.sp->syntax = 0; set_parameter(spell, "c?"); free(spell.sp->syntax); - spell.sp->syntax = _strdup("hodor"); + spell.sp->syntax = strdup("hodor"); check_spell_syntax(tc, "c?", &spell, " ZAUBERE \"Testzauber\" []"); free(spell.sp->syntax); spell.sp->syntax = 0; diff --git a/src/reports.c b/src/reports.c index fa8a722d9..a9695145b 100644 --- a/src/reports.c +++ b/src/reports.c @@ -529,7 +529,7 @@ size_t size) if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) { faction *f = get_otherfaction(a_otherfaction); int result = - _snprintf(bufp, size, ", %s (%s)", factionname(f), + snprintf(bufp, size, ", %s (%s)", factionname(f), factionname(u->faction)); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); @@ -544,7 +544,7 @@ size_t size) bufp = STRLCPY(bufp, ", ", size); - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d ", u->number))) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d ", u->number))) WARN_STATIC_BUFFER(); pzTmp = get_racename(u->attribs); @@ -641,7 +641,7 @@ size_t size) bufp = STRLCPY(bufp, ", ", size); if (!dh) { - result = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); + result = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); dh = 1; @@ -650,7 +650,7 @@ size_t size) bufp = STRLCPY(bufp, ic, size); } else { - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d %s", in, ic))) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d %s", in, ic))) WARN_STATIC_BUFFER(); } } @@ -661,7 +661,7 @@ size_t size) if (book) { selist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC, 0); - int result = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); + int result = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); if (wrptr(&bufp, &size, result) != 0) { WARN_STATIC_BUFFER(); } @@ -671,7 +671,7 @@ size_t size) if (sbe->level <= maxlevel) { int result = 0; if (!header) { - result = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); + result = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); header = 1; } else { @@ -690,7 +690,7 @@ size_t size) } if (i != MAXCOMBATSPELLS) { int result = - _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); + snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); @@ -708,7 +708,7 @@ size_t size) int sl = get_combatspelllevel(u, i); bufp = STRLCPY(bufp, spell_name(sp, u->faction->locale), size); if (sl > 0) { - result = _snprintf(bufp, size, " (%d)", sl); + result = snprintf(bufp, size, " (%d)", sl); if (wrptr(&bufp, &size, result) != 0) WARN_STATIC_BUFFER(); } @@ -819,13 +819,13 @@ const struct unit * u, struct skill * sv, int *dh, int days) if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) { i = u_geteffstealth(u); if (i >= 0) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d/", i)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0) WARN_STATIC_BUFFER(); } } effsk = eff_skill(u, sv, 0); - if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d", effsk)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d", effsk)) != 0) WARN_STATIC_BUFFER(); if (u->faction->options & want(O_SHOWSKCHANGE)) { @@ -836,11 +836,11 @@ const struct unit * u, struct skill * sv, int *dh, int days) oldeff = sv->old + get_modifier(u, sv->id, sv->old, u->region, false); } - oldeff = _max(0, oldeff); + oldeff = MAX(0, oldeff); diff = effsk - oldeff; if (diff != 0) { - if (wrptr(&bufp, &size, _snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0) WARN_STATIC_BUFFER(); } } @@ -877,7 +877,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned firstline = false; } if (!cut) { - cut = s + _min(len, REPORTWIDTH); + cut = s + MIN(len, REPORTWIDTH); } memcpy(buf + indent, s, cut - s); buf[indent + (cut - s)] = 0; @@ -1411,7 +1411,7 @@ int write_reports(faction * f, time_t ltime) int error = 0; do { char filename[32]; - char path[MAX_PATH]; + char path[4096]; sprintf(filename, "%d-%s.%s", turn, itoa36(f->no), rtype->extension); join_path(reportpath(), filename, path, sizeof(path)); @@ -1481,7 +1481,7 @@ int reports(void) FILE *mailit; time_t ltime = time(NULL); int retval = 0; - char path[MAX_PATH]; + char path[4096]; const char * rpath = reportpath(); log_info("Writing reports for turn %d:", turn); @@ -1508,7 +1508,7 @@ int reports(void) static variant var_copy_string(variant x) { - x.v = x.v ? _strdup((const char *)x.v) : 0; + x.v = x.v ? strdup((const char *)x.v) : 0; return x; } @@ -1612,7 +1612,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size) pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl); len = strlcpy(buffer, rname(r, f ? f->locale : 0), size); - _snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); + snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); buffer[size - 1] = 0; len = strlen(buffer); } @@ -1863,7 +1863,7 @@ static void eval_order(struct opstack **stack, const void *userdata) size_t len; variant var; - unused_arg(userdata); + UNUSED_ARG(userdata); write_order(ord, buf, sizeof(buf)); len = strlen(buf); var.v = strcpy(balloc(len + 1), buf); @@ -1883,7 +1883,7 @@ static void eval_resources(struct opstack **stack, const void *userdata) while (res != NULL && size > 4) { const char *rname = resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0); - int result = _snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname)); + int result = snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname)); if (wrptr(&bufp, &size, result) != 0 || size < sizeof(buf) / 2) { WARN_STATIC_BUFFER(); break; @@ -1947,7 +1947,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) variant var; char *bufp = buf; #ifdef _SECURECRT_ERRCODE_VALUES_DEFINED - /* stupid MS broke _snprintf */ + /* stupid MS broke snprintf */ int eold = errno; #endif @@ -1958,7 +1958,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) const char *trail = trailinto(r, lang); const char *rn = f_regionid_s(r, report); - if (wrptr(&bufp, &size, _snprintf(bufp, size, trail, rn)) != 0) + if (wrptr(&bufp, &size, snprintf(bufp, size, trail, rn)) != 0) WARN_STATIC_BUFFER(); if (i + 2 < end) { @@ -2014,7 +2014,7 @@ static void eval_int36(struct opstack **stack, const void *userdata) var.v = strcpy(balloc(len + 1), c); opush(stack, var); - unused_arg(userdata); + UNUSED_ARG(userdata); } /*** END MESSAGE RENDERING ***/ diff --git a/src/skill.h b/src/skill.h index 8b0c0c155..24f96a844 100644 --- a/src/skill.h +++ b/src/skill.h @@ -3,7 +3,7 @@ #ifndef H_SKILL_H #define H_SKILL_H -#include +#include struct locale; typedef enum { diff --git a/src/spells.c b/src/spells.c index 7e7b5669a..6ed38d022 100644 --- a/src/spells.c +++ b/src/spells.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -149,7 +150,7 @@ static void magicanalyse_region(region * r, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); found = true; if (chance(probability)) { /* Analyse geglueckt */ @@ -190,7 +191,7 @@ static void magicanalyse_unit(unit * u, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -231,7 +232,7 @@ static void magicanalyse_building(building * b, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -272,7 +273,7 @@ static void magicanalyse_ship(ship * sh, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = _max(1, mon); + mon = MAX(1, mon); if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -704,7 +705,7 @@ static int sp_destroy_magic(castorder * co) "unit region command", mage, mage->region, co->order)); } - return _max(succ, 1); + return MAX(succ, 1); } /* ------------------------------------------------------------- */ @@ -773,7 +774,7 @@ static int sp_transferaura(castorder * co) return 0; } - gain = _min(aura, scm_src->spellpoints) / multi; + gain = MIN(aura, scm_src->spellpoints) / multi; scm_src->spellpoints -= gain * multi; scm_dst->spellpoints += gain; @@ -912,7 +913,7 @@ static int sp_summonent(castorder * co) return 0; } - ents = _min((int)(power * power), rtrees(r, 2)); + ents = MIN((int)(power * power), rtrees(r, 2)); u = create_unit(r, mage->faction, ents, get_race(RC_TREEMAN), 0, NULL, mage); @@ -1304,7 +1305,7 @@ static int sp_rosthauch(castorder * co) for (; iweapon != NULL; iweapon = iweapon->next) { item **ip = i_find(&u->items, iweapon->type); if (*ip) { - float chance = (float)_min((*ip)->number, force); + float chance = (float)MIN((*ip)->number, force); if (iweapon->chance < 1.0) { chance *= iweapon->chance; } @@ -1343,7 +1344,7 @@ static int sp_rosthauch(castorder * co) * unguenstigsten Fall kann pro Stufe nur eine Waffe verzaubert werden, * darum wird hier nur fuer alle Faelle in denen noch weniger Waffen * betroffen wurden ein Kostennachlass gegeben */ - return _min(success, cast_level); + return MIN(success, cast_level); } /* ------------------------------------------------------------- */ @@ -1373,7 +1374,7 @@ static int sp_kaelteschutz(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; double force = co->force; - int duration = _max(cast_level, (int)force) + 1; + int duration = MAX(cast_level, (int)force) + 1; spellparameter *pa = co->par; double effect; @@ -2137,8 +2138,8 @@ static int sp_drought(castorder * co) */ c = get_curse(r->attribs, ct_find("drought")); if (c) { - c->vigour = _max(c->vigour, power); - c->duration = _max(c->duration, (int)power); + c->vigour = MAX(c->vigour, power); + c->duration = MAX(c->duration, (int)power); } else { double effect = 4.0; @@ -2335,8 +2336,8 @@ static int sp_earthquake(castorder * co) if (burg->size != 0 && !is_cursed(burg->attribs, C_MAGICWALLS, 0)) { /* Magieresistenz */ if (!target_resists_magic(mage, burg, TYP_BUILDING, 0)) { - kaputt = _min(10 * cast_level, burg->size / 4); - kaputt = _max(kaputt, 1); + kaputt = MIN(10 * cast_level, burg->size / 4); + kaputt = MAX(kaputt, 1); burg->size -= kaputt; if (burg->size == 0) { /* TODO: sollten die Insassen nicht Schaden nehmen? */ @@ -2501,7 +2502,7 @@ static int sp_forest_fire(castorder * co) * das Zaubern. Patzer werden warscheinlicher. * Jeder Zauber muss erst gegen den Wiederstand des Fluchs gezaubert * werden und schwaecht dessen Antimagiewiederstand um 1. - * Wirkt _max(Stufe(Magier) - Stufe(Ziel), rand(3)) Wochen + * Wirkt MAX(Stufe(Magier) - Stufe(Ziel), rand(3)) Wochen * Patzer: * Magier wird selbst betroffen * @@ -2529,7 +2530,7 @@ static int sp_fumblecurse(castorder * co) rx = rng_int() % 3; sx = cast_level - effskill(target, SK_MAGIC, 0); - duration = _max(sx, rx) + 1; + duration = MAX(sx, rx) + 1; effect = force / 2; c = create_curse(mage, &target->attribs, ct_find("fumble"), @@ -2695,8 +2696,8 @@ static int sp_firewall(castorder * co) } else { fd = (wall_data *)b->data.v; - fd->force = (int)_max(fd->force, force / 2 + 0.5); - fd->countdown = _max(fd->countdown, cast_level + 1); + fd->force = (int)MAX(fd->force, force / 2 + 0.5); + fd->countdown = MAX(fd->countdown, cast_level + 1); } /* melden, 1x pro Partei */ @@ -2938,7 +2939,7 @@ attrib_type at_deathcloud_compat = { * Ruestung wirkt nicht * Patzer: * Magier geraet in den Staub und verliert zufaellige Zahl von HP bis -* auf _max(hp,2) +* auf MAX(hp,2) * Besonderheiten: * Nicht als curse implementiert, was schlecht ist - man kann dadurch * kein dispell machen. Wegen fix unter Zeitdruck erstmal nicht zu @@ -3361,7 +3362,7 @@ static int sp_summonundead(castorder * co) return 0; } - undead = _min(deathcount(r), 2 + lovar(force)); + undead = MIN(deathcount(r), 2 + lovar(force)); if (cast_level <= 8) { race = get_race(RC_SKELETON); @@ -3409,7 +3410,7 @@ static int sp_auraleak(castorder * co) int cast_level = co->level; message *msg; - lost = _min(0.95, cast_level * 0.05); + lost = MIN(0.95, cast_level * 0.05); for (u = r->units; u; u = u->next) { if (is_mage(u)) { @@ -3792,8 +3793,8 @@ static int sp_raisepeasantmob(castorder * co) anteil = 6 + (rng_int() % 4); n = rpeasants(r) * anteil / 10; - n = _max(0, n); - n = _min(n, rpeasants(r)); + n = MAX(0, n); + n = MIN(n, rpeasants(r)); if (n <= 0) { report_failure(mage, co->order); @@ -4032,13 +4033,13 @@ static int sp_recruit(castorder * co) n = (pow(force, 1.6) * 100) / f->race->recruitcost; if (rc->recruit_multi > 0) { double multp = (double)maxp / rc->recruit_multi; - n = _min(multp, n); - n = _max(n, 1); + n = MIN(multp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - (int)(n * rc->recruit_multi)); } else { - n = _min(maxp, n); - n = _max(n, 1); + n = MIN(maxp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - (int)n); } @@ -4083,13 +4084,13 @@ static int sp_bigrecruit(castorder * co) n = (int)force + lovar((force * force * 1000) / (float)f->race->recruitcost); if (f->race == get_race(RC_ORC)) { - n = _min(2 * maxp, n); - n = _max(n, 1); + n = MIN(2 * maxp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - (n + 1) / 2); } else { - n = _min(maxp, n); - n = _max(n, 1); + n = MIN(maxp, n); + n = MAX(n, 1); rsetpeasants(r, maxp - n); } @@ -4178,7 +4179,7 @@ static int sp_pump(castorder * co) * Betoert eine Einheit, so das sie ihm den groe�ten Teil ihres Bargelds * und 50% ihres Besitzes schenkt. Sie behaelt jedoch immer soviel, wie * sie zum ueberleben braucht. Wirkt gegen Magieresistenz. - * _min(Stufe*1000$, u->money - maintenace) + * MIN(Stufe*1000$, u->money - maintenace) * Von jedem Item wird 50% abgerundet ermittelt und uebergeben. Dazu * kommt Itemzahl%2 mit 50% chance * @@ -4215,8 +4216,8 @@ static int sp_seduce(castorder * co) int loot; if (itm->type->rtype == rsilver) { loot = - _min(cast_level * 1000, get_money(target) - (maintenance_cost(target))); - loot = _max(loot, 0); + MIN(cast_level * 1000, get_money(target) - (maintenance_cost(target))); + loot = MAX(loot, 0); } else { loot = itm->number / 2; @@ -4224,7 +4225,7 @@ static int sp_seduce(castorder * co) loot += rng_int() % 2; } if (loot > 0) { - loot = _min(loot, (int)(force * 5)); + loot = MIN(loot, (int)(force * 5)); } } if (loot > 0) { @@ -4341,7 +4342,7 @@ static int sp_headache(castorder * co) } if (smax != NULL) { /* wirkt auf maximal 10 Personen */ - unsigned int change = _min(10, target->number) * (rng_uint() % 2 + 1) / target->number; + unsigned int change = MIN(10, target->number) * (rng_uint() % 2 + 1) / target->number; reduce_skill(target, smax, change); } set_order(&target->thisorder, NULL); @@ -4385,7 +4386,7 @@ static int sp_raisepeasants(castorder * co) "error_nopeasants", "")); return 0; } - bauern = _min(rpeasants(r), (int)(power * 250)); + bauern = MIN(rpeasants(r), (int)(power * 250)); rsetpeasants(r, rpeasants(r) - bauern); u2 = @@ -4468,7 +4469,7 @@ int sp_puttorest(castorder * co) message *seen = msg_message("puttorest", "mage", mage); message *unseen = msg_message("puttorest", "mage", NULL); - laid_to_rest = _max(laid_to_rest, dead); + laid_to_rest = MAX(laid_to_rest, dead); deathcounts(r, -laid_to_rest); @@ -4713,7 +4714,7 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) /* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken, * also duration+2 */ - duration = (int)_max(1, power / 2); /* Stufe 1 macht sonst mist */ + duration = (int)MAX(1, power / 2); /* Stufe 1 macht sonst mist */ duration = 2 + rng_int() % duration; /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ @@ -4752,7 +4753,7 @@ int sp_clonecopy(castorder * co) return 0; } - _snprintf(name, sizeof(name), (const char *)LOC(mage->faction->locale, + slprintf(name, sizeof(name), (const char *)LOC(mage->faction->locale, "clone_of"), unitname(mage)); clone = create_unit(target_region, mage->faction, 1, get_race(RC_CLONE), 0, name, @@ -4855,7 +4856,7 @@ int sp_sweetdreams(castorder * co) cmistake(mage, co->order, 40, MSG_EVENT); continue; } - men = _min(opfer, u->number); + men = MIN(opfer, u->number); opfer -= men; /* Nichts machen als ein entsprechendes Attribut an die Einheit legen. */ @@ -4969,7 +4970,7 @@ int sp_itemcloak(castorder * co) spellparameter *pa = co->par; int cast_level = co->level; double power = co->force; - int duration = (int)_max(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ + int duration = (int)MAX(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ /* wenn kein Ziel gefunden, Zauber abbrechen */ if (pa->param[0]->flag == TARGET_NOTFOUND) @@ -5027,7 +5028,7 @@ int sp_resist_magic_bonus(castorder * co) u = pa->param[n]->data.u; - m = _min(u->number, victims); + m = MIN(u->number, victims); victims -= m; create_curse(mage, &u->attribs, ct_find("magicresistance"), @@ -5043,8 +5044,8 @@ int sp_resist_magic_bonus(castorder * co) msg_release(msg); } - cast_level = _min(cast_level, (int)(cast_level * (victims + 4) / maxvictims)); - return _max(cast_level, 1); + cast_level = MIN(cast_level, (int)(cast_level * (victims + 4) / maxvictims)); + return MAX(cast_level, 1); } /** spell 'Astraler Weg'. @@ -5656,7 +5657,7 @@ int sp_showastral(castorder * co) free_regionlist(rl); return cast_level; - unused_arg(co); + UNUSED_ARG(co); return 0; } #endif @@ -5907,7 +5908,7 @@ int sp_permtransfer(castorder * co) return 0; } - aura = _min(get_spellpoints(mage) - spellcost(mage, sp), aura); + aura = MIN(get_spellpoints(mage) - spellcost(mage, sp), aura); change_maxspellpoints(mage, -aura); change_spellpoints(mage, -aura); @@ -6216,7 +6217,7 @@ int sp_speed2(castorder * co) spellparameter *pa = co->par; maxmen = 2 * cast_level * cast_level; - dur = _max(1, cast_level / 2); + dur = MAX(1, cast_level / 2); for (n = 0; n < pa->length; n++) { double effect; @@ -6230,7 +6231,7 @@ int sp_speed2(castorder * co) u = pa->param[n]->data.u; - men = _min(maxmen, u->number); + men = MIN(maxmen, u->number); effect = 2; create_curse(mage, &u->attribs, ct_find("speed"), force, dur, effect, men); maxmen -= men; @@ -6241,7 +6242,7 @@ int sp_speed2(castorder * co) "unit region amount", mage, mage->region, used)); /* Effektiv benoetigten cast_level (mindestens 1) zurueckgeben */ used = (int)sqrt(used / 2); - return _max(1, used); + return MAX(1, used); } /* ------------------------------------------------------------- */ @@ -6324,7 +6325,7 @@ int sp_q_antimagie(castorder * co) ADDMSG(&mage->faction->msgs, msg_message("destroy_magic_noeffect", "unit region command", mage, mage->region, co->order)); } - return _max(succ, 1); + return MAX(succ, 1); } /* ------------------------------------------------------------- */ diff --git a/src/spells/borders.c b/src/spells/borders.c index 04f7e15f4..00019e92c 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -206,7 +206,7 @@ struct region *from, struct region *to, bool routing) wall_data *fd = (wall_data *)b->data.v; if (!routing && fd->active) { int hp = dice(3, fd->force) * u->number; - hp = _min(u->hp, hp); + hp = MIN(u->hp, hp); u->hp -= hp; if (u->hp) { ADDMSG(&u->faction->msgs, msg_message("firewall_damage", @@ -227,9 +227,9 @@ static const char *b_namefirewall(const connection * b, const region * r, const faction * f, int gflags) { const char *bname; - unused_arg(f); - unused_arg(r); - unused_arg(b); + UNUSED_ARG(f); + UNUSED_ARG(r); + UNUSED_ARG(b); if (gflags & GF_ARTICLE) bname = "a_firewall"; else diff --git a/src/spells/borders.h b/src/spells/borders.h index 31823df94..b14661b9f 100644 --- a/src/spells/borders.h +++ b/src/spells/borders.h @@ -1,5 +1,8 @@ #ifndef H_KRNL_CURSES #define H_KRNL_CURSES + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/spells/buildingcurse.c b/src/spells/buildingcurse.c index 01b0435ab..158383fd2 100644 --- a/src/spells/buildingcurse.c +++ b/src/spells/buildingcurse.c @@ -36,7 +36,7 @@ message *cinfo_building(const void *obj, objtype_t typ, const curse * c, int self) { const building *b = (const building *)obj; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_BUILDING); assert(obj); assert(c); diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 10f1711ef..ccfc2346f 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -337,14 +337,14 @@ int sp_combatrosthauch(struct castorder * co) if (force <= 0) break; - /* da n _min(force, x), sollte force maximal auf 0 sinken */ + /* da n MIN(force, x), sollte force maximal auf 0 sinken */ assert(force >= 0); if (df->weapons) { int w; for (w = 0; df->weapons[w].type != NULL; ++w) { weapon *wp = df->weapons; - int n = _min(force, wp->used); + int n = MIN(force, wp->used); if (n) { requirement *mat = wp->type->itype->construction->materials; bool iron = false; @@ -921,7 +921,7 @@ int sp_shadowknights(struct castorder * co) region *r = b->region; unit *mage = fi->unit; attrib *a; - int force = _max(1, (int)get_force(power, 3)); + int force = MAX(1, (int)get_force(power, 3)); message *msg; u = @@ -1015,7 +1015,7 @@ int sp_chaosrow(struct castorder * co) continue; if (power <= 0.0) break; - /* force sollte wegen des _max(0,x) nicht unter 0 fallen k�nnen */ + /* force sollte wegen des MAX(0,x) nicht unter 0 fallen k�nnen */ if (is_magic_resistant(mage, df->unit, 0)) continue; @@ -1050,7 +1050,7 @@ int sp_chaosrow(struct castorder * co) } k += df->alive; } - power = _max(0, power - n); + power = MAX(0, power - n); } selist_free(fgs); @@ -1154,12 +1154,12 @@ int sp_hero(struct castorder * co) switch (sp->id) { case SPL_HERO: df_bonus = (int)(power / 5); - force = _max(1, lovar(get_force(power, 4))); + force = MAX(1, lovar(get_force(power, 4))); break; default: df_bonus = 1; - force = _max(1, (int)power); + force = MAX(1, (int)power); } allies = @@ -1208,7 +1208,7 @@ int sp_berserk(struct castorder * co) switch (sp->id) { case SPL_BERSERK: case SPL_BLOODTHIRST: - at_bonus = _max(1, level / 3); + at_bonus = MAX(1, level / 3); df_malus = 2; force = (int)get_force(power, 2); break; @@ -1264,7 +1264,7 @@ int sp_frighten(struct castorder * co) int targets = 0; message *m; - at_malus = _max(1, level - 4); + at_malus = MAX(1, level - 4); df_malus = 2; force = (int)get_force(power, 2); @@ -1545,7 +1545,7 @@ int sp_fumbleshield(struct castorder * co) case SPL_CERDDOR_FUMBLESHIELD: case SPL_TYBIED_FUMBLESHIELD: duration = 100; - effect = _max(1, 25 - level); + effect = MAX(1, 25 - level); break; default: @@ -1596,7 +1596,7 @@ int sp_reanimate(struct castorder * co) } healable = count_healable(b, fi); - healable = (int)_min(k, healable); + healable = (int)MIN(k, healable); while (healable--) { fighter *tf = select_corpse(b, fi); if (tf != NULL && tf->side->casualties > 0 @@ -1649,7 +1649,7 @@ int sp_keeploot(struct castorder * co) message_all(b, m); msg_release(m); - b->keeploot = (int)_max(25, b->keeploot + 5 * power); + b->keeploot = (int)MAX(25, b->keeploot + 5 * power); return level; } @@ -1680,10 +1680,10 @@ static int heal_fighters(selist * fgs, int *power, bool heal_monsters) ++wound; if (wound > 0 && wound < hp) { - int heal = _min(healhp, wound); + int heal = MIN(healhp, wound); assert(heal >= 0); df->person[n].hp += heal; - healhp = _max(0, healhp - heal); + healhp = MAX(0, healhp - heal); ++healed; if (healhp <= 0) break; @@ -1834,7 +1834,7 @@ int sp_undeadhero(struct castorder * co) } selist_free(fgs); - level = _min(level, undead); + level = MIN(level, undead); if (undead == 0) { msg = msg_message("summonundead_effect_0", "mage region", mage, mage->region); diff --git a/src/spells/flyingship.h b/src/spells/flyingship.h index 8b7bf0874..52013ac13 100644 --- a/src/spells/flyingship.h +++ b/src/spells/flyingship.h @@ -3,6 +3,8 @@ #ifndef FLYINGSHIP_H #define FLYINGSHIP_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 3d7593484..b10f3046f 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -45,8 +45,8 @@ static message *cinfo_cursed_by_the_gods(const void *obj, objtype_t typ, { region *r = (region *)obj; - unused_arg(typ); - unused_arg(self); + UNUSED_ARG(typ); + UNUSED_ARG(self); assert(typ == TYP_REGION); if (r->terrain->flags & SEA_REGION) { @@ -68,9 +68,9 @@ static struct curse_type ct_godcursezone = { static message *cinfo_dreamcurse(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(self); - unused_arg(typ); - unused_arg(obj); + UNUSED_ARG(self); + UNUSED_ARG(typ); + UNUSED_ARG(obj); assert(typ == TYP_REGION); if (c->effect > 0) { @@ -94,9 +94,9 @@ static struct curse_type ct_gbdream = { static message *cinfo_magicstreet(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); - unused_arg(self); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(self); + UNUSED_ARG(obj); assert(typ == TYP_REGION); /* Warnung vor Auflösung */ @@ -117,9 +117,9 @@ static struct curse_type ct_magicstreet = { static message *cinfo_antimagiczone(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); - unused_arg(self); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(self); + UNUSED_ARG(obj); assert(typ == TYP_REGION); /* Magier spüren eine Antimagiezone */ @@ -139,7 +139,7 @@ const curse * c, int self) unit *u = NULL; unit *mage = c->magician; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_REGION); r = (region *)obj; @@ -167,8 +167,8 @@ static struct curse_type ct_antimagiczone = { static message *cinfo_farvision(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(obj); assert(typ == TYP_REGION); diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index 59cc534d4..b6a722ad3 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -38,8 +38,8 @@ message *cinfo_ship(const void *obj, objtype_t typ, const curse * c, int self) { message *msg; - unused_arg(typ); - unused_arg(obj); + UNUSED_ARG(typ); + UNUSED_ARG(obj); assert(typ == TYP_SHIP); if (self != 0) { /* owner or inside */ @@ -62,7 +62,7 @@ static message *cinfo_shipnodrift(const void *obj, objtype_t typ, const curse * { ship *sh = (ship *)obj; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_SHIP); if (self != 0) { diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index 6e769145e..ded4a1676 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -46,7 +46,7 @@ static message *cinfo_auraboost(const void *obj, objtype_t typ, const curse * c, int self) { struct unit *u = (struct unit *)obj; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (self != 0) { @@ -80,7 +80,7 @@ static message *cinfo_slave(const void *obj, objtype_t typ, const curse * c, int self) { unit *u; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); u = (unit *)obj; @@ -104,7 +104,7 @@ cinfo_slave static message *cinfo_calm(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (c->magician && c->magician->faction) { @@ -133,7 +133,7 @@ static struct curse_type ct_calmmonster = { static message *cinfo_speed(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (self != 0) { @@ -156,7 +156,7 @@ static struct curse_type ct_speed = { */ message *cinfo_unit(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); assert(obj); @@ -181,7 +181,7 @@ static struct curse_type ct_orcish = { static message *cinfo_kaelteschutz(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); if (self != 0) { @@ -233,7 +233,7 @@ static message *cinfo_sparkle(const void *obj, objtype_t typ, const curse * c, }; int m, begin = 0, end = 0; unit *u; - unused_arg(typ); + UNUSED_ARG(typ); assert(typ == TYP_UNIT); u = (unit *)obj; @@ -324,7 +324,7 @@ write_skill(struct storage *store, const curse * c, const void *target) static message *cinfo_skillmod(const void *obj, objtype_t typ, const curse * c, int self) { - unused_arg(typ); + UNUSED_ARG(typ); if (self != 0) { unit *u = (unit *)obj; diff --git a/src/spy.c b/src/spy.c index 86476bec7..eb58f792a 100644 --- a/src/spy.c +++ b/src/spy.c @@ -146,7 +146,7 @@ int spy_cmd(unit * u, struct order *ord) * Fuer jeden Talentpunkt, den das Spionagetalent das Tarnungstalent * des Opfers uebersteigt, erhoeht sich dieses um 5%*/ spy = effskill(u, SK_SPY, 0) - effskill(target, SK_STEALTH, r); - spychance = 0.1 + _max(spy * 0.05, 0.0); + spychance = 0.1 + MAX(spy * 0.05, 0.0); if (chance(spychance)) { produceexp(u, SK_SPY, u->number); @@ -162,7 +162,7 @@ int spy_cmd(unit * u, struct order *ord) - (effskill(u, SK_STEALTH, 0) + effskill(u, SK_SPY, 0) / 2); if (invisible(u, target) >= u->number) { - observe = _min(observe, 0); + observe = MIN(observe, 0); } /* Anschliessend wird - unabhaengig vom Erfolg - gewuerfelt, ob der @@ -352,7 +352,7 @@ static int top_skill(region * r, faction * f, ship * sh, skill_t sk) for (u = r->units; u; u = u->next) { if (u->ship == sh && u->faction == f) { int s = effskill(u, sk, 0); - value = _max(s, value); + value = MAX(s, value); } } return value; diff --git a/src/sqlite.c b/src/sqlite.c index 6acaf4116..9379faa4f 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -94,9 +94,9 @@ read_factions(sqlite3 * db, int game_id) { text = (const char *)sqlite3_column_text(stmt, 1); if (text) dbf->no = atoi36(text); text = (const char *)sqlite3_column_text(stmt, 2); - if (text) dbf->name = _strdup(text); + if (text) dbf->name = strdup(text); text = (const char *)sqlite3_column_text(stmt, 3); - if (text) dbf->email = _strdup(text); + if (text) dbf->email = strdup(text); selist_push(&result, dbf); res = sqlite3_step(stmt); } diff --git a/src/study.c b/src/study.c index 58cd068f2..b69b4359f 100644 --- a/src/study.c +++ b/src/study.c @@ -201,7 +201,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, * steigen. * * n ist die Anzahl zusaetzlich gelernter Tage. n darf max. die Differenz - * von schon gelernten Tagen zum _max(30 Tage pro Mann) betragen. */ + * von schon gelernten Tagen zum MAX(30 Tage pro Mann) betragen. */ if (magic_lowskill(student)) { cmistake(teacher, teacher->thisorder, 292, MSG_EVENT); @@ -215,7 +215,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, n -= teach->value; } - n = _min(n, nteaching); + n = MIN(n, nteaching); if (n != 0) { if (teach == NULL) { @@ -267,7 +267,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, * die Talentaenderung (enno). */ - nteaching = _max(0, nteaching - student->number * 30); + nteaching = MAX(0, nteaching - student->number * 30); } return n; @@ -303,7 +303,7 @@ int teach_cmd(unit * u, struct order *ord) teaching = u->number * 30 * TEACHNUMBER; if ((i = get_effect(u, oldpotiontype[P_FOOL])) > 0) { /* Trank "Dumpfbackenbrot" */ - i = _min(i, u->number * TEACHNUMBER); + i = MIN(i, u->number * TEACHNUMBER); /* Trank wirkt pro Schueler, nicht pro Lehrer */ teaching -= i * 30; change_effect(u, oldpotiontype[P_FOOL], -i); @@ -604,7 +604,7 @@ int study_cmd(unit * u, order * ord) } /* Akademie: */ if (active_building(u, bt_find("academy"))) { - studycost = _max(50, studycost * 2); + studycost = MAX(50, studycost * 2); } if (sk == SK_MAGIC) { @@ -691,11 +691,11 @@ int study_cmd(unit * u, order * ord) if (studycost) { int cost = studycost * u->number; money = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, cost); - money = _min(money, cost); + money = MIN(money, cost); } if (money < studycost * u->number) { studycost = p; /* Ohne Univertreurung */ - money = _min(money, studycost); + money = MIN(money, studycost); if (p > 0 && money < studycost * u->number) { cmistake(u, ord, 65, MSG_EVENT); multi = money / (double)(studycost * u->number); @@ -715,12 +715,12 @@ int study_cmd(unit * u, order * ord) } if (get_effect(u, oldpotiontype[P_WISE])) { - l = _min(u->number, get_effect(u, oldpotiontype[P_WISE])); + l = MIN(u->number, get_effect(u, oldpotiontype[P_WISE])); teach->value += l * 10; change_effect(u, oldpotiontype[P_WISE], -l); } if (get_effect(u, oldpotiontype[P_FOOL])) { - l = _min(u->number, get_effect(u, oldpotiontype[P_FOOL])); + l = MIN(u->number, get_effect(u, oldpotiontype[P_FOOL])); teach->value -= l * 30; change_effect(u, oldpotiontype[P_FOOL], -l); } diff --git a/src/summary.c b/src/summary.c index 8a3ee3c41..32416a263 100644 --- a/src/summary.c +++ b/src/summary.c @@ -97,8 +97,8 @@ int update_nmrs(void) if (timeout>0) { if (nmr < 0 || nmr > timeout) { log_error("faction %s has %d NMR", itoa36(f->no), nmr); - nmr = _max(0, nmr); - nmr = _min(nmr, timeout); + nmr = MAX(0, nmr); + nmr = MIN(nmr, timeout); } if (nmr > 0) { log_debug("faction %s has %d NMR", itoa36(f->no), nmr); @@ -164,7 +164,7 @@ static char *gamedate2(const struct locale *lang) static void writeturn(void) { - char zText[MAX_PATH]; + char zText[4096]; FILE *f; join_path(basepath(), "datum", zText, sizeof(zText)); @@ -190,7 +190,7 @@ void report_summary(summary * s, summary * o, bool full) FILE *F = NULL; int i, newplayers = 0; faction *f; - char zText[MAX_PATH]; + char zText[4096]; int timeout = NMRTimeout(); if (full) { diff --git a/src/test_eressea.c b/src/test_eressea.c index 6d2dead3f..02d52c5ed 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -33,7 +33,7 @@ static void add_suite(CuSuite *(*csuite)(void), const char *name, int argc, char } if (s) { s->next = suites; - s->name = _strdup(name); + s->name = strdup(name); s->csuite = csuite(); suites = s; } diff --git a/src/travelthru.test.c b/src/travelthru.test.c index be87743d2..09d807674 100644 --- a/src/travelthru.test.c +++ b/src/travelthru.test.c @@ -15,7 +15,7 @@ struct attrib; static void count_travelers(region *r, unit *u, void *cbdata) { int *n = (int *)cbdata; - unused_arg(r); + UNUSED_ARG(r); *n += u->number; } diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index 37d993f4a..3de537c7b 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -70,7 +70,7 @@ static int changefaction_handle(trigger * t, void *data) else { log_error("could not perform changefaction::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/changerace.c b/src/triggers/changerace.c index f38b7f3d5..a9f282698 100644 --- a/src/triggers/changerace.c +++ b/src/triggers/changerace.c @@ -74,7 +74,7 @@ static int changerace_handle(trigger * t, void *data) else { log_error("could not perform changerace::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/clonedied.c b/src/triggers/clonedied.c index 642b50ab0..f3d1fc00b 100644 --- a/src/triggers/clonedied.c +++ b/src/triggers/clonedied.c @@ -58,7 +58,7 @@ static int clonedied_handle(trigger * t, void *data) } else log_error("could not perform clonedied::handle()\n"); - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index 040a4e7b7..3eb0891ca 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -76,7 +76,7 @@ static int createcurse_handle(trigger * t, void *data) else { log_error("could not perform createcurse::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 5952c88bc..41573d86b 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -74,7 +74,7 @@ static int createunit_handle(trigger * t, void *data) else { log_error("could not perform createunit::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/gate.c b/src/triggers/gate.c index e681efc04..c70163a14 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -57,7 +57,7 @@ static int gate_handle(trigger * t, void *data) log_error("could not perform gate::handle()\n"); return -1; } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/giveitem.c b/src/triggers/giveitem.c index 6b0e8f8c7..9bc2c56e1 100644 --- a/src/triggers/giveitem.c +++ b/src/triggers/giveitem.c @@ -70,7 +70,7 @@ static int giveitem_handle(trigger * t, void *data) else { log_error("could not perform giveitem::handle()\n"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/killunit.c b/src/triggers/killunit.c index 22ad27896..3e6c9defe 100644 --- a/src/triggers/killunit.c +++ b/src/triggers/killunit.c @@ -48,7 +48,7 @@ static int killunit_handle(trigger * t, void *data) /* we can't remove_unit() here, because that's what's calling us. */ set_number(u, 0); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 7c54676e0..31424e979 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -60,8 +60,8 @@ static void do_shock(unit * u, const char *reason) if (u->number > 0) { /* HP - Verlust */ int hp = (unit_max_hp(u) * u->number) / 10; - hp = _min(u->hp, hp); - u->hp = _max(1, hp); + hp = MIN(u->hp, hp); + u->hp = MAX(1, hp); } /* Aura - Verlust */ @@ -102,7 +102,7 @@ static int shock_handle(trigger * t, void *data) if (u && u->number) { do_shock(u, "trigger"); } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/timeout.c b/src/triggers/timeout.c index 10e4d08be..43bb061c8 100644 --- a/src/triggers/timeout.c +++ b/src/triggers/timeout.c @@ -61,7 +61,7 @@ static int timeout_handle(trigger * t, void *data) handle_triggers(&td->triggers, NULL); return -1; } - unused_arg(data); + UNUSED_ARG(data); return 0; } diff --git a/src/triggers/unitmessage.c b/src/triggers/unitmessage.c index 0c1e80124..7ba97d9bc 100644 --- a/src/triggers/unitmessage.c +++ b/src/triggers/unitmessage.c @@ -71,7 +71,7 @@ static int unitmessage_handle(trigger * t, void *data) td->level); } } - unused_arg(data); + UNUSED_ARG(data); return 0; } @@ -92,7 +92,7 @@ static int unitmessage_read(trigger * t, gamedata *data) int result = read_reference(&td->target, data, read_unit_reference, resolve_unit); READ_TOK(data->store, zText, sizeof(zText)); - td->string = _strdup(zText); + td->string = strdup(zText); READ_INT(data->store, &td->type); READ_INT(data->store, &td->level); @@ -117,7 +117,7 @@ trigger *trigger_unitmessage(unit * target, const char *string, int type, trigger *t = t_new(&tt_unitmessage); unitmessage_data *td = (unitmessage_data *)t->data.v; td->target = target; - td->string = _strdup(string); + td->string = strdup(string); td->type = type; td->level = level; return t; diff --git a/src/upkeep.c b/src/upkeep.c index 1cf41011f..94cbc341d 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -47,7 +47,7 @@ static void help_feed(unit * donor, unit * u, int *need_p) { int need = *need_p; int give = get_money(donor) - lifestyle(donor); - give = _min(need, give); + give = MIN(need, give); if (give > 0) { change_money(donor, -give); @@ -161,7 +161,7 @@ void get_food(region * r) * food from the peasants - should not be used with WORK */ if (owner != NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) { int rm = rmoney(r); - int use = _min(rm, need); + int use = MIN(rm, need); rsetmoney(r, rm - use); need -= use; } @@ -174,7 +174,7 @@ void get_food(region * r) for (v = r->units; need && v; v = v->next) { if (v->faction == u->faction && help_money(v)) { int give = get_money(v) - lifestyle(v); - give = _min(need, give); + give = MIN(need, give); if (give > 0) { change_money(v, -give); change_money(u, give); @@ -191,7 +191,7 @@ void get_food(region * r) int need = lifestyle(u); faction *f = u->faction; - need -= _max(0, get_money(u)); + need -= MAX(0, get_money(u)); if (need > 0) { unit *v; @@ -247,7 +247,7 @@ void get_food(region * r) unit *donor = u; while (donor != NULL && hungry > 0) { int blut = get_effect(donor, pt_blood); - blut = _min(blut, hungry); + blut = MIN(blut, hungry); if (blut) { change_effect(donor, pt_blood, -blut); hungry -= blut; @@ -295,7 +295,7 @@ void get_food(region * r) /* 3. Von den überlebenden das Geld abziehen: */ for (u = r->units; u; u = u->next) { - int need = _min(get_money(u), lifestyle(u)); + int need = MIN(get_money(u), lifestyle(u)); change_money(u, -need); } } diff --git a/src/util/attrib.c b/src/util/attrib.c index 4bdf35bfa..a99a70ba3 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -124,7 +124,7 @@ int a_readstring(attrib * a, void *owner, struct gamedata *data) len += DISPLAYSIZE - 1; } else { - result = _strdup(buf); + result = strdup(buf); } } while (e == ENOMEM); a->data.v = result; diff --git a/src/util/attrib.h b/src/util/attrib.h index d93ce1240..45dc9b942 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef ATTRIB_H #define ATTRIB_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/attrib.test.c b/src/util/attrib.test.c index 7fa2ef82c..b44afeec2 100644 --- a/src/util/attrib.test.c +++ b/src/util/attrib.test.c @@ -119,7 +119,7 @@ static void test_attrib_rwstring(CuTest *tc) { attrib a = { 0 }; test_setup(); - a.data.v = _strdup("Hello World"); + a.data.v = strdup("Hello World"); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); a_writestring(&a, NULL, &store); diff --git a/src/util/crmessage.c b/src/util/crmessage.c index 98afe0f05..47bb6bf7d 100644 --- a/src/util/crmessage.c +++ b/src/util/crmessage.c @@ -145,21 +145,21 @@ int cr_render(const message * msg, char *buffer, const void *userdata) int cr_string(variant var, char *buffer, const void *userdata) { sprintf(buffer, "\"%s\"", (const char *)var.v); - unused_arg(userdata); + UNUSED_ARG(userdata); return 0; } int cr_int(variant var, char *buffer, const void *userdata) { sprintf(buffer, "%d", var.i); - unused_arg(userdata); + UNUSED_ARG(userdata); return 0; } int cr_ignore(variant var, char *buffer, const void *userdata) { - unused_arg(var); - unused_arg(buffer); - unused_arg(userdata); + UNUSED_ARG(var); + UNUSED_ARG(buffer); + UNUSED_ARG(userdata); return -1; } diff --git a/src/util/event.c b/src/util/event.c index cdf178aec..78a6d6fbc 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -153,7 +153,7 @@ static int read_handler(attrib * a, void *owner, gamedata *data) handler_info *hi = (handler_info *)a->data.v; READ_TOK(store, zText, sizeof(zText)); - hi->event = _strdup(zText); + hi->event = strdup(zText); read_triggers(data, &hi->triggers); if (hi->triggers != NULL) { return AT_READ_OK; @@ -200,7 +200,7 @@ void add_trigger(struct attrib **ap, const char *eventname, struct trigger *t) if (a == NULL || a->type != &at_eventhandler) { a = a_add(ap, a_new(&at_eventhandler)); td = (handler_info *)a->data.v; - td->event = _strdup(eventname); + td->event = strdup(eventname); } tp = &td->triggers; while (*tp) diff --git a/src/util/goodies.c b/src/util/goodies.c index 2444d0f47..c478bcf83 100644 --- a/src/util/goodies.c +++ b/src/util/goodies.c @@ -113,7 +113,7 @@ int set_email(char **pemail, const char *newmail) free(*pemail); *pemail = 0; if (newmail) { - *pemail = _strdup(newmail); + *pemail = strdup(newmail); } return 0; } diff --git a/src/util/language.c b/src/util/language.c index cb91d7419..efd5cd5f7 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -86,7 +86,7 @@ locale *get_or_create_locale(const char *name) *lp = l = (locale *)calloc(sizeof(locale), 1); assert_alloc(l); l->hashkey = hkey; - l->name = _strdup(name); + l->name = strdup(name); l->index = nextlocaleindex++; assert(nextlocaleindex <= MAXLOCALES); if (default_locale == NULL) default_locale = l; @@ -209,15 +209,15 @@ void locale_setstring(locale * lang, const char *key, const char *value) find->nexthash = lang->strings[id]; lang->strings[id] = find; find->hashkey = hkey; - find->key = _strdup(key); - find->str = _strdup(value); + find->key = strdup(key); + find->str = strdup(value); } else { if (strcmp(find->str, value) != 0) { log_warning("multiple translations for key %s\n", key); } free(find->str); - find->str = _strdup(value); + find->str = strdup(value); } } diff --git a/src/util/language.h b/src/util/language.h index a90398cc0..36bc58378 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -19,7 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef MY_LOCALE_H #define MY_LOCALE_H -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/util/lists.c b/src/util/lists.c index d61327fa0..be3deeffd 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -127,7 +127,7 @@ void addstrlist(strlist ** SP, const char *s) { strlist *slist = malloc(sizeof(strlist)); slist->next = NULL; - slist->s = _strdup(s); + slist->s = strdup(s); addlist(SP, slist); } diff --git a/src/util/log.test.c b/src/util/log.test.c index 55616c026..1558ee3e3 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -9,9 +9,9 @@ void log_string(void *data, int level, const char *module, const char *format, va_list args) { char *str = (char *)data; const char *arg = va_arg(args, const char *); - unused_arg(format); - unused_arg(module); - unused_arg(level); + UNUSED_ARG(format); + UNUSED_ARG(module); + UNUSED_ARG(level); strcpy(str, arg); } diff --git a/src/util/message.c b/src/util/message.c index 23f81e095..c5285835e 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -73,7 +73,7 @@ message_type *mt_new(const char *name, const char *args[]) while (args[nparameters]) ++nparameters; } mtype->key = 0; - mtype->name = _strdup(name); + mtype->name = strdup(name); mtype->nparameters = nparameters; if (nparameters > 0) { mtype->pnames = (char **)malloc(sizeof(char *) * nparameters); diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index e3b0bcc0b..8156b9784 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -91,7 +91,7 @@ const nrsection *section_add(const char *name) } if (!*mcp) { nrsection *mc = calloc(sizeof(nrsection), 1); - mc->name = _strdup(name); + mc->name = strdup(name); *mcp = mc; } return *mcp; @@ -130,14 +130,14 @@ const char *string, int level, const char *section) nrt->section = NULL; nrtypes[hash] = nrt; assert(string && *string); - nrt->string = _strdup(string); + nrt->string = strdup(string); *c = '\0'; for (i = 0; i != mtype->nparameters; ++i) { if (i != 0) *c++ = ' '; c += strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames)); } - nrt->vars = _strdup(zNames); + nrt->vars = strdup(zNames); } } diff --git a/src/util/translation.c b/src/util/translation.c index 829a1fe05..b0933d322 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -414,7 +414,7 @@ static void eval_lt(opstack ** stack, const void *userdata) int b = opop_i(stack); int rval = (b < a) ? 1 : 0; opush_i(stack, rval); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_eq(opstack ** stack, const void *userdata) @@ -423,7 +423,7 @@ static void eval_eq(opstack ** stack, const void *userdata) int b = opop_i(stack); int rval = (a == b) ? 1 : 0; opush_i(stack, rval); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_add(opstack ** stack, const void *userdata) @@ -431,14 +431,14 @@ static void eval_add(opstack ** stack, const void *userdata) int a = opop_i(stack); int b = opop_i(stack); opush_i(stack, a + b); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_isnull(opstack ** stack, const void *userdata) { /* (int, int) -> int */ void *a = opop_v(stack); opush_i(stack, (a == NULL) ? 1 : 0); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_if(opstack ** stack, const void *userdata) @@ -447,14 +447,14 @@ static void eval_if(opstack ** stack, const void *userdata) void *b = opop_v(stack); int cond = opop_i(stack); opush_v(stack, cond ? b : a); - unused_arg(userdata); + UNUSED_ARG(userdata); } static void eval_strlen(opstack ** stack, const void *userdata) { /* string -> int */ const char *c = (const char *)opop_v(stack); opush_i(stack, c ? (int)strlen(c) : 0); - unused_arg(userdata); + UNUSED_ARG(userdata); } #include "base36.h" diff --git a/src/vortex.c b/src/vortex.c index 725460ce2..7b6206d03 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -70,7 +70,7 @@ static void a_freedirection(attrib * a) static int a_agedirection(attrib * a, void *owner) { spec_direction *d = (spec_direction *)(a->data.v); - unused_arg(owner); + (void)owner; --d->duration; return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } @@ -81,14 +81,14 @@ static int a_readdirection(attrib * a, void *owner, struct gamedata *data) spec_direction *d = (spec_direction *)(a->data.v); char lbuf[32]; - unused_arg(owner); + (void)owner; READ_INT(store, &d->x); READ_INT(store, &d->y); READ_INT(store, &d->duration); READ_TOK(store, lbuf, sizeof(lbuf)); - d->desc = _strdup(lbuf); + d->desc = strdup(lbuf); READ_TOK(store, lbuf, sizeof(lbuf)); - d->keyword = _strdup(lbuf); + d->keyword = strdup(lbuf); d->active = true; return AT_READ_OK; } @@ -98,7 +98,7 @@ a_writedirection(const attrib * a, const void *owner, struct storage *store) { spec_direction *d = (spec_direction *)(a->data.v); - unused_arg(owner); + (void)owner; WRITE_INT(store, d->x); WRITE_INT(store, d->y); WRITE_INT(store, d->duration); @@ -143,8 +143,8 @@ attrib *create_special_direction(region * r, region * rt, int duration, d->x = rt->x; d->y = rt->y; d->duration = duration; - d->desc = _strdup(desc); - d->keyword = _strdup(keyword); + d->desc = strdup(desc); + d->keyword = strdup(keyword); return a; } diff --git a/src/vortex.h b/src/vortex.h index af41b6111..993f5cdab 100644 --- a/src/vortex.h +++ b/src/vortex.h @@ -1,5 +1,10 @@ +#pragma once + #ifndef H_VORTEX #define H_VORTEX + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/wormhole.c b/src/wormhole.c index dd105b302..462f4e637 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -63,7 +63,7 @@ static int wormhole_age(struct attrib *a, void *owner) region *r = entry->region; unit *u = r->units; - unused_arg(owner); + UNUSED_ARG(owner); for (; u != NULL && maxtransport != 0; u = u->next) { if (u->building == entry) { message *m = NULL; From 5ddd511aa8701242a4c940e1bf60e545d12783a5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:05:48 +0100 Subject: [PATCH 094/271] continue fixing compilation (gcc/clang) --- src/bind_faction.c | 1 + src/kernel/alliance.h | 3 +++ src/kernel/order.h | 1 + src/keyword.h | 2 ++ src/platform.h | 3 +++ src/util/filereader.c | 15 ++++++++------- src/util/parser.c | 8 ++++---- src/util/parser.h | 1 + src/util/password.h | 1 + src/util/rand.h | 4 ++++ src/util/translation.c | 1 + 11 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/bind_faction.c b/src/bind_faction.c index 109814717..f5c393de6 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -34,6 +34,7 @@ without prior permission by the authors of Eressea. #include #include +#include typedef struct helpmode { const char *name; diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index fac2dfd38..8e112e8c9 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_ALLIANCE #define H_KRNL_ALLIANCE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/order.h b/src/kernel/order.h index 69cf1ea33..7f4b00a5e 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -15,6 +15,7 @@ #include "keyword.h" #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/keyword.h b/src/keyword.h index e60d0731f..1d8f04bb2 100644 --- a/src/keyword.h +++ b/src/keyword.h @@ -2,6 +2,8 @@ #define H_KEYWORD_H #include "kernel/types.h" +#include + #ifdef __cplusplus extern "C" { diff --git a/src/platform.h b/src/platform.h index 2f114cec5..7f82f46a8 100644 --- a/src/platform.h +++ b/src/platform.h @@ -3,6 +3,8 @@ #ifndef UNILIB_H #define UNILIB_H +#define _POSIX_C_SOURCE 200809L + #ifndef MAX_PATH # define MAX_PATH 4096 #endif @@ -12,4 +14,5 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define TOLUA_CAST (char*) #endif diff --git a/src/util/filereader.c b/src/util/filereader.c index 3223ca2ab..d36d3ca71 100644 --- a/src/util/filereader.c +++ b/src/util/filereader.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -30,7 +31,7 @@ static int eatwhite(const char *ptr, size_t * total_size) ret = unicode_utf8_to_ucs4(&ucs, ptr, &size); if (ret != 0) break; - if (!iswxspace((wint_t)ucs)) + if (!iswspace((wint_t)ucs)) break; *total_size += size; ptr += size; @@ -52,7 +53,7 @@ static const char *getbuf_latin1(FILE * F) if (bp == NULL) return NULL; - while (*bp && isxspace(*(unsigned char *)bp)) + while (*bp && isspace(*(unsigned char *)bp)) ++bp; /* eatwhite */ comment = (bool)(comment && cont); @@ -113,15 +114,15 @@ static const char *getbuf_latin1(FILE * F) if (iscntrl(c)) { if (!comment && cp < fbuf + MAXLINE) { - *cp++ = isxspace(c) ? ' ' : '?'; + *cp++ = isspace(c) ? ' ' : '?'; } ++bp; continue; } - else if (isxspace(c)) { + else if (isspace(c)) { if (!quote) { ++bp; - while (*bp && isxspace(*(unsigned char *)bp)) + while (*bp && isspace(*(unsigned char *)bp)) ++bp; /* eatwhite */ if (!comment && *bp && *bp != COMMENT_CHAR && cp < fbuf + MAXLINE) *(cp++) = ' '; @@ -136,7 +137,7 @@ static const char *getbuf_latin1(FILE * F) } else if (c == CONTINUE_CHAR) { const char *end = ++bp; - while (*end && isxspace(*(unsigned char *)end)) + while (*end && isspace(*(unsigned char *)end)) ++end; /* eatwhite */ if (*end == '\0') { bp = end; @@ -269,7 +270,7 @@ static const char *getbuf_utf8(FILE * F) break; } - if (iswxspace((wint_t)ucs)) { + if (iswspace((wint_t)ucs)) { if (!quote) { bp += size; ret = eatwhite(bp, &size); diff --git a/src/util/parser.c b/src/util/parser.c index 0fbde6769..bbdb5ac7e 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -32,7 +32,7 @@ static int eatwhitespace_c(const char **str_p) for (;;) { unsigned char utf8_character = (unsigned char)*str; if (~utf8_character & 0x80) { - if (!iswxspace(utf8_character)) + if (!iswspace(utf8_character)) break; ++str; } @@ -42,7 +42,7 @@ static int eatwhitespace_c(const char **str_p) log_warning("illegal character sequence in UTF8 string: %s\n", str); break; } - if (!iswxspace((wint_t)ucs)) + if (!iswspace((wint_t)ucs)) break; str += len; } @@ -106,7 +106,7 @@ void skip_token(void) log_warning("illegal character sequence in UTF8 string: %s\n", states->current_token); } } - if (iswxspace((wint_t)ucs) && quotechar == 0) { + if (iswspace((wint_t)ucs) && quotechar == 0) { return; } else { @@ -163,7 +163,7 @@ char *parse_token(const char **str, char *lbuf, size_t buflen) copy = true; escape = false; } - else if (iswxspace((wint_t)ucs)) { + else if (iswspace((wint_t)ucs)) { if (quotechar == 0) break; copy = true; diff --git a/src/util/parser.h b/src/util/parser.h index 802fc56cb..0c8306931 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -12,6 +12,7 @@ #define UTIL_PARSER_H #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/util/password.h b/src/util/password.h index e1d49fb6d..b83d544a6 100644 --- a/src/util/password.h +++ b/src/util/password.h @@ -1,5 +1,6 @@ #pragma once +#include #define PASSWORD_PLAINTEXT 0 #define PASSWORD_DEFAULT PASSWORD_PLAINTEXT diff --git a/src/util/rand.h b/src/util/rand.h index 9fb3f2f69..e9d9062b7 100644 --- a/src/util/rand.h +++ b/src/util/rand.h @@ -1,3 +1,4 @@ +#pragma once /* Copyright (c) 1998-2015, Enno Rehling Katja Zedel + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/translation.c b/src/util/translation.c index b0933d322..c733cc272 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -21,6 +21,7 @@ /* libc includes */ #include #include +#include #include #include From 774fa12a5a2a59b6cf42903842bae8d38c6a7211 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:07:36 +0100 Subject: [PATCH 095/271] continued work for MSVC compilation --- src/alchemy.c | 4 ++++ src/battle.c | 11 +++++++++-- src/donations.c | 1 + src/economy.c | 38 +++++++++++++++++++------------------- src/kernel/messages.h | 2 +- src/move.c | 11 +++++++++-- src/names.c | 2 +- src/platform.h | 23 +++++++++++++++++++++++ src/reports.c | 16 ++++++++-------- src/spells.c | 8 +++++++- src/spells/combatspells.c | 4 ++-- 11 files changed, 84 insertions(+), 36 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index ddbe46b8e..81244eba1 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -162,6 +162,7 @@ static int potion_healing(unit * u, int amount) { static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { attrib *a = (attrib *)a_find(r->attribs, atype); + UNUSED_ARG(u); if (!a) { a = a_add(&r->attribs, a_new(atype)); } @@ -170,6 +171,7 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { } static int potion_truth(unit *u) { + UNUSED_ARG(u); // TODO: this potion does nothing! // fset(u, UFL_DISBELIEVES); return 1; @@ -304,6 +306,7 @@ static void a_writeeffect(const attrib * a, const void *owner, struct storage *store) { effect_data *edata = (effect_data *)a->data.v; + UNUSED_ARG(owner); WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0)); WRITE_INT(store, edata->value); } @@ -316,6 +319,7 @@ static int a_readeffect(attrib * a, void *owner, struct gamedata *data) effect_data *edata = (effect_data *)a->data.v; char zText[32]; + UNUSED_ARG(owner); READ_TOK(store, zText, sizeof(zText)); rtype = rt_find(zText); diff --git a/src/battle.c b/src/battle.c index 550449ddd..402f61ed5 100644 --- a/src/battle.c +++ b/src/battle.c @@ -509,6 +509,9 @@ contest_new(int skilldiff, const troop dt, const armor_type * ar, const armor_type * sh) { double tohit = 0.5 + skilldiff * 0.1; + + UNUSED_ARG(sh); + UNUSED_ARG(ar); if (tohit < 0.5) tohit = 0.5; if (chance(tohit)) { @@ -839,6 +842,7 @@ int select_magicarmor(troop t) /* Sind side ds und Magier des meffect verb�ndet, dann return 1*/ bool meffect_protection(battle * b, meffect * s, side * ds) { + UNUSED_ARG(b); if (!s->magician->alive) return false; if (s->duration <= 0) @@ -853,6 +857,7 @@ bool meffect_protection(battle * b, meffect * s, side * ds) /* Sind side as und Magier des meffect verfeindet, dann return 1*/ bool meffect_blocked(battle * b, meffect * s, side * as) { + UNUSED_ARG(b); if (!s->magician->alive) return false; if (s->duration <= 0) @@ -1763,8 +1768,8 @@ void do_combatmagic(battle * b, combatmagic_t was) for (co = spellranks[rank].begin; co; co = co->next) { fighter *fig = co->magician.fig; const spell *sp = co->sp; - int level = co->level; + level = co->level; if (!sp->cast) { log_error("spell '%s' has no function.\n", sp->sname); } @@ -2040,6 +2045,7 @@ int hits(troop at, troop dt, weapon * awp) void dazzle(battle * b, troop * td) { + UNUSED_ARG(b); /* Nicht kumulativ ! */ #ifdef TODO_RUNESWORD if (td->fighter->weapon[WP_RUNESWORD].count > td->index) { @@ -2487,6 +2493,7 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype) static int loot_quota(const unit * src, const unit * dst, const item_type * type, int n) { + UNUSED_ARG(type); if (dst && src && src->faction != dst->faction) { double divisor = config_get_flt("rules.items.loot_divisor", 1); assert(divisor <= 0 || divisor >= 1); @@ -2636,7 +2643,6 @@ static void reorder_fleeing(region * r) static void aftermath(battle * b) { region *r = b->region; - ship *sh; side *s; int dead_players = 0; bfaction *bf; @@ -2833,6 +2839,7 @@ static void aftermath(battle * b) * dieses Schiff besch�digt. Andernfalls ein Schiff, welches * evt. zuvor verlassen wurde. */ if (ships_damaged) { + ship *sh; if (du->ship) sh = du->ship; else diff --git a/src/donations.c b/src/donations.c index 4dee36444..b923df73b 100644 --- a/src/donations.c +++ b/src/donations.c @@ -1,3 +1,4 @@ +#include #include #include "donations.h" diff --git a/src/economy.c b/src/economy.c index 7edbbcb12..16b201555 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1041,10 +1041,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) static int required(int want, double save) { - int norders = (int)(want * save); - if (norders < want * save) - ++norders; - return norders; + int req = (int)(want * save); + if (req < want * save) + ++req; + return req; } static void @@ -1058,7 +1058,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (rm != NULL) { do { int avail = rm->amount; - int norders = 0; + int nreq = 0; allocation *al; if (avail <= 0) { @@ -1077,7 +1077,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (effskill(al->unit, itype->construction->skill, 0) >= rm->level + itype->construction->minskill - 1) { if (req) { - norders += req; + nreq += req; } else { fset(al, AFL_DONE); @@ -1089,22 +1089,22 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) fset(al, AFL_LOWSKILL); } } - need = norders; + need = nreq; - avail = MIN(avail, norders); + avail = MIN(avail, nreq); if (need > 0) { int use = 0; for (al = alist; al; al = al->next) if (!fval(al, AFL_DONE)) { if (avail > 0) { int want = required(al->want - al->get, al->save); - int x = avail * want / norders; + int x = avail * want / nreq; /* Wenn Rest, dann würfeln, ob ich was bekomme: */ - if (rng_int() % norders < (avail * want) % norders) + if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; use += x; - norders -= want; + nreq -= want; need -= x; al->get = MIN(al->want, al->get + (int)(x / al->save)); } @@ -1113,7 +1113,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) assert(use <= rm->amount); rm->type->use(rm, r, use); } - assert(avail == 0 || norders == 0); + assert(avail == 0 || nreq == 0); } first = false; } while (need > 0); @@ -1124,13 +1124,13 @@ static void attrib_allocation(const resource_type * rtype, region * r, allocation * alist) { allocation *al; - int norders = 0; + int nreq = 0; attrib *a = a_find(rtype->attribs, &at_resourcelimit); resource_limit *rdata = (resource_limit *)a->data.v; int avail = rdata->value; for (al = alist; al; al = al->next) { - norders += required(al->want, al->save); + nreq += required(al->want, al->save); } if (rdata->limit) { @@ -1139,16 +1139,16 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) avail = 0; } - avail = MIN(avail, norders); + avail = MIN(avail, nreq); for (al = alist; al; al = al->next) { if (avail > 0) { int want = required(al->want, al->save); - int x = avail * want / norders; + int x = avail * want / nreq; /* Wenn Rest, dann würfeln, ob ich was bekomme: */ - if (rng_int() % norders < (avail * want) % norders) + if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; - norders -= want; + nreq -= want; al->get = MIN(al->want, (int)(x / al->save)); if (rdata->produce) { int use = required(al->get, al->save); @@ -1157,7 +1157,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) } } } - assert(avail == 0 || norders == 0); + assert(avail == 0 || nreq == 0); } typedef void(*allocate_function) (const resource_type *, struct region *, diff --git a/src/kernel/messages.h b/src/kernel/messages.h index 866eecba7..a42342153 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -57,7 +57,7 @@ extern "C" { struct mlist ** merge_messages(message_list *mlist, message_list *append); void split_messages(message_list *mlist, struct mlist **split); -#define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } } +#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { assert(mx->refcount>=1); add_message(msgs, mx); msg_release(mx); } } void syntax_error(const struct unit *u, struct order *ord); struct message * cmistake(const struct unit *u, struct order *ord, int mno, int mtype); diff --git a/src/move.c b/src/move.c index 62300beb1..0184d22ca 100644 --- a/src/move.c +++ b/src/move.c @@ -163,6 +163,7 @@ static int shiptrail_read(attrib * a, void *owner, struct gamedata *data) int n; traveldir *t = (traveldir *)(a->data.v); + UNUSED_ARG(owner); READ_INT(store, &t->no); READ_INT(store, &n); t->dir = (direction_t)n; @@ -174,6 +175,8 @@ static void shiptrail_write(const attrib * a, const void *owner, struct storage *store) { traveldir *t = (traveldir *)(a->data.v); + + UNUSED_ARG(owner); WRITE_INT(store, t->no); WRITE_INT(store, t->dir); WRITE_INT(store, t->age); @@ -204,6 +207,8 @@ static bool entrance_allowed(const struct unit *u, const struct region *r) return true; return false; #else + UNUSED_ARG(u); + UNUSED_ARG(r); return true; #endif } @@ -466,6 +471,8 @@ static int canride(unit * u) static bool cansail(const region * r, ship * sh) { + UNUSED_ARG(r); + /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction || sh->type->construction->improvement == NULL); @@ -490,6 +497,8 @@ static bool cansail(const region * r, ship * sh) static double overload(const region * r, ship * sh) { + UNUSED_ARG(r); + /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction || sh->type->construction->improvement == NULL); @@ -1761,8 +1770,6 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) * befahrene Region. */ while (next_point && current_point != next_point && step < k) { - const char *token; - int error; const terrain_type *tthis = current_point->terrain; /* these values need to be updated if next_point changes (due to storms): */ const terrain_type *tnext = next_point->terrain; diff --git a/src/names.c b/src/names.c index 248084828..969e278d8 100644 --- a/src/names.c +++ b/src/names.c @@ -394,8 +394,8 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) size_t size; int result; + UNUSED_ARG(buflen); /* Prüfen, ob Kurz genug */ - if (strlen(s) <= maxchars) { return s; } diff --git a/src/platform.h b/src/platform.h index 7f82f46a8..dca251b7e 100644 --- a/src/platform.h +++ b/src/platform.h @@ -4,6 +4,20 @@ #define UNILIB_H #define _POSIX_C_SOURCE 200809L +#ifdef _MSC_VER +#ifndef __STDC__ +#define __STDC__ 1 // equivalent to /Za +#endif +#define NO_STRDUP +#define NO_MKDIR +#define mkdir(d, a) _mkdir(d) +#define _CRT_SECURE_NO_WARNINGS +#pragma warning(disable: 4710 4820) +#pragma warning(disable: 4100) // unreferenced formal parameter +#pragma warning(disable: 4456) // declaration hides previous +#pragma warning(disable: 4457) // declaration hides function parameter +#pragma warning(disable: 4459) // declaration hides global +#endif #ifndef MAX_PATH # define MAX_PATH 4096 @@ -15,4 +29,13 @@ #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define TOLUA_CAST (char*) + +#ifdef NO_STRDUP +char * strdup(const char *s); +#endif + +#ifdef NO_MKDIR +int mkdir(const char *pathname, int mode); +#endif + #endif diff --git a/src/reports.c b/src/reports.c index a9695145b..395547734 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1906,23 +1906,23 @@ static void eval_regions(struct opstack **stack, const void *userdata) const faction *report = (const faction *)userdata; int i = opop(stack).i; int end, begin = opop(stack).i; - const arg_regions *regions = (const arg_regions *)opop(stack).v; + const arg_regions *aregs = (const arg_regions *)opop(stack).v; char buf[256]; size_t size = sizeof(buf) - 1; variant var; char *bufp = buf; - if (regions == NULL) { + if (aregs == NULL) { end = begin; } else { if (i >= 0) end = begin + i; else - end = regions->nregions + i; + end = aregs->nregions + i; } for (i = begin; i < end; ++i) { - const char *rname = (const char *)regionname(regions->regions[i], report); + const char *rname = (const char *)regionname(aregs->regions[i], report); bufp = STRLCPY(bufp, rname, size); if (i + 1 < end && size > 2) { @@ -1941,7 +1941,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) const faction *report = (const faction *)userdata; const struct locale *lang = report ? report->locale : default_locale; int i, end = 0, begin = 0; - const arg_regions *regions = (const arg_regions *)opop(stack).v; + const arg_regions *aregs = (const arg_regions *)opop(stack).v; char buf[512]; size_t size = sizeof(buf) - 1; variant var; @@ -1951,10 +1951,10 @@ static void eval_trail(struct opstack **stack, const void *userdata) int eold = errno; #endif - if (regions != NULL) { - end = regions->nregions; + if (aregs != NULL) { + end = aregs->nregions; for (i = begin; i < end; ++i) { - region *r = regions->regions[i]; + region *r = aregs->regions[i]; const char *trail = trailinto(r, lang); const char *rn = f_regionid_s(r, report); diff --git a/src/spells.c b/src/spells.c index 6ed38d022..0bb6df5af 100644 --- a/src/spells.c +++ b/src/spells.c @@ -398,6 +398,7 @@ static void report_effect(region * r, unit * mage, message * seen, message * unseen) { int err = report_action(r, mage, seen, ACTION_RESET | ACTION_CANSEE); + UNUSED_ARG(unseen); if (err) { report_action(r, mage, seen, ACTION_CANNOTSEE); } @@ -2895,6 +2896,8 @@ static int dc_read_compat(struct attrib *a, void *target, gamedata *data) float strength; int rx, ry; + UNUSED_ARG(a); + UNUSED_ARG(target); READ_INT(store, &duration); READ_FLT(store, &strength); READ_INT(store, &var.i); @@ -3119,8 +3122,10 @@ static bool chaosgate_valid(const connection * b) } static struct region *chaosgate_move(const connection * b, struct unit *u, -struct region *from, struct region *to, bool routing) + struct region *from, struct region *to, bool routing) { + UNUSED_ARG(from); + UNUSED_ARG(b); if (!routing) { int maxhp = u->hp / 4; if (maxhp < u->number) @@ -6438,6 +6443,7 @@ int sp_break_curse(castorder * co) /* ------------------------------------------------------------- */ int sp_becomewyrm(castorder * co) { + UNUSED_ARG(co); return 0; } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index ccfc2346f..76fd605ff 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -826,8 +826,8 @@ int sp_shadowcall(struct castorder * co) attrib *a; int force = (int)(get_force(power, 3) / 2); unit *u; - const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" }; - const race *rc = rc_find(races[rng_int() % 3]); + const char *rcnames[3] = { "shadowbat", "nightmare", "vampunicorn" }; + const race *rc = rc_find(rcnames[rng_int() % 3]); message *msg; u = create_unit(r, mage->faction, force, rc, 0, NULL, mage); From 7b25ed282df8878a4603c7c16426b6aa9d50b103 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:20:47 +0100 Subject: [PATCH 096/271] more stbool.h includes, MSVC has no unlink --- src/attributes/key.h | 3 +++ src/donations.test.c | 1 + src/give.h | 3 +++ src/kernel/command.test.c | 2 ++ src/market.h | 3 +++ src/monsters.h | 3 +++ src/platform.h | 5 ++++- src/renumber.test.c | 1 + src/reports.h | 2 +- src/summary.h | 2 ++ src/util/xml.h | 2 ++ 11 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/attributes/key.h b/src/attributes/key.h index 89292db1d..d2cea1ff0 100644 --- a/src/attributes/key.h +++ b/src/attributes/key.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_ATTRIBUTE_KEY #define H_ATTRIBUTE_KEY + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/donations.test.c b/src/donations.test.c index 068aba74a..09cd31977 100644 --- a/src/donations.test.c +++ b/src/donations.test.c @@ -1,3 +1,4 @@ +#include #include "donations.h" #include diff --git a/src/give.h b/src/give.h index 9c06e89ca..94eee729c 100644 --- a/src/give.h +++ b/src/give.h @@ -12,6 +12,9 @@ */ #ifndef H_GC_GIVE #define H_GC_GIVE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/command.test.c b/src/kernel/command.test.c index f38c7e443..25e75fdc3 100644 --- a/src/kernel/command.test.c +++ b/src/kernel/command.test.c @@ -10,7 +10,9 @@ without prior permission by the authors of Eressea. */ +#include #include "command.h" + #include "unit.h" #include "order.h" diff --git a/src/market.h b/src/market.h index a74c88391..74dc8db17 100644 --- a/src/market.h +++ b/src/market.h @@ -12,6 +12,9 @@ without prior permission by the authors of Eressea. */ #ifndef H_GC_MARKET #define H_GC_MARKET + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/monsters.h b/src/monsters.h index 52e9ebf37..a5a3ccd15 100644 --- a/src/monsters.h +++ b/src/monsters.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_GC_MONSTER #define H_GC_MONSTER + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/platform.h b/src/platform.h index dca251b7e..682bcc1c2 100644 --- a/src/platform.h +++ b/src/platform.h @@ -10,7 +10,7 @@ #endif #define NO_STRDUP #define NO_MKDIR -#define mkdir(d, a) _mkdir(d) +#define NO_UNLINK #define _CRT_SECURE_NO_WARNINGS #pragma warning(disable: 4710 4820) #pragma warning(disable: 4100) // unreferenced formal parameter @@ -38,4 +38,7 @@ char * strdup(const char *s); int mkdir(const char *pathname, int mode); #endif +#ifdef NO_UNLINK +int unlink(const char *pathname); +#endif #endif diff --git a/src/renumber.test.c b/src/renumber.test.c index 6c3f0f17b..8f6f91a59 100644 --- a/src/renumber.test.c +++ b/src/renumber.test.c @@ -1,3 +1,4 @@ +#include #include "renumber.h" #include diff --git a/src/reports.h b/src/reports.h index d69b9a88b..625048de9 100644 --- a/src/reports.h +++ b/src/reports.h @@ -20,10 +20,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_REPORTS #define H_KRNL_REPORTS -#include #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/summary.h b/src/summary.h index ea8daeee1..b12d74009 100644 --- a/src/summary.h +++ b/src/summary.h @@ -11,6 +11,8 @@ #ifndef H_GC_SUMMARY #define H_GC_SUMMARY +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/xml.h b/src/util/xml.h index 921cd3f53..bd22e3e0a 100644 --- a/src/util/xml.h +++ b/src/util/xml.h @@ -13,6 +13,8 @@ #ifndef H_UTIL_XML #define H_UTIL_XML +#include + #ifdef __cplusplus extern "C" { #endif From d1b5daf83341e59e3dee36031560fddfc5ce2cd1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:40:01 +0100 Subject: [PATCH 097/271] compiles with gcc on rpi --- src/kernel/jsonconf.test.c | 2 +- src/kernel/save.c | 2 +- src/platform.h | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 76784ed56..950868046 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -448,7 +448,7 @@ static void test_configs(CuTest * tc) CuAssertPtrEquals(tc, 0, buildingtypes); json_config(json); CuAssertPtrNotNull(tc, buildingtypes); - if (unlink("test.json")!=0 && errno==ENOENT) { + if (remove("test.json")!=0 && errno==ENOENT) { errno = 0; } cJSON_Delete(json); diff --git a/src/kernel/save.c b/src/kernel/save.c index 1139b5f1f..bbbd77fd1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1830,7 +1830,7 @@ int writegame(const char *filename) join_path(datapath(), filename, path, sizeof(path)); #ifdef HAVE_UNISTD_H /* make sure we don't overwrite an existing file (hard links) */ - if (unlink(path)!=0) { + if (remove(path)!=0) { if (errno==ENOENT) { errno = 0; } diff --git a/src/platform.h b/src/platform.h index 682bcc1c2..21c459a74 100644 --- a/src/platform.h +++ b/src/platform.h @@ -10,7 +10,6 @@ #endif #define NO_STRDUP #define NO_MKDIR -#define NO_UNLINK #define _CRT_SECURE_NO_WARNINGS #pragma warning(disable: 4710 4820) #pragma warning(disable: 4100) // unreferenced formal parameter @@ -38,7 +37,4 @@ char * strdup(const char *s); int mkdir(const char *pathname, int mode); #endif -#ifdef NO_UNLINK -int unlink(const char *pathname); -#endif #endif From c38cd41194e179d46e8fcfbf17bc1ef7629c1c15 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 10:57:42 +0100 Subject: [PATCH 098/271] fix the install script, issue #623 --- s/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/s/install b/s/install index 18cc2393f..416d07f9a 100755 --- a/s/install +++ b/s/install @@ -10,12 +10,11 @@ done DEST=$(dirname $ROOT)/server -MACHINE=`uname -m` [ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" [ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" [ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" -BIN_DIR="build-$MACHINE-$CC-Debug" +BIN_DIR="Debug" cd $ROOT/$BIN_DIR make install From 94737375f5b11d4f0471fa3ca74643d0705fe17b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 14:53:35 +0100 Subject: [PATCH 099/271] issue #621: delete battledebug code --- src/battle.c | 156 ++------------------------------------------------- src/battle.h | 1 - src/main.c | 3 - 3 files changed, 6 insertions(+), 154 deletions(-) diff --git a/src/battle.c b/src/battle.c index 402f61ed5..4105cf73f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -93,12 +93,6 @@ typedef enum combatmagic { DO_POSTCOMBATSPELL } combatmagic_t; -/* globals */ -bool battledebug = false; - -static int obs_count = 0; -static FILE *bdebug; - #define MINSPELLRANGE 1 #define MAXSPELLRANGE 7 @@ -1219,9 +1213,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) kritchance = MIN(0.9, kritchance); while (chance(kritchance)) { - if (bdebug) { - fprintf(bdebug, "%s/%d lands a critical hit\n", itoa36(au->no), at.index); - } da += dice_rand(damage); } } @@ -1302,10 +1293,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) } if (df->person[dt.index].hp > 0) { /* Hat �berlebt */ - if (bdebug) { - fprintf(bdebug, "Damage %d, armor %d: %d -> %d HP\n", - da, ar, df->person[dt.index].hp + rda, df->person[dt.index].hp); - } if (u_race(au) == get_race(RC_DAEMON)) { if (!(df->person[dt.index].flags & (FL_COURAGE | FL_DAZZLED))) { df->person[dt.index].flags |= FL_DAZZLED; @@ -1334,10 +1321,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) } ++at.fighter->kills; - if (bdebug) { - fprintf(bdebug, "Damage %d, armor %d, type %d: %d -> %d HP, tot.\n", - da, ar, type, df->person[dt.index].hp + rda, df->person[dt.index].hp); - } for (pitm = &du->items; *pitm;) { item *itm = *pitm; const item_type *itype = itm->type; @@ -1979,20 +1962,6 @@ int getreload(troop at) return at.fighter->person[at.index].reload; } -static void -debug_hit(troop at, const weapon * awp, troop dt, const weapon * dwp, -int skdiff, int dist, bool success) -{ - fprintf(bdebug, "%.4s/%d [%6s/%d] %s %.4s/%d [%6s/%d] with %d, distance %d\n", - itoa36(at.fighter->unit->no), at.index, - LOC(default_locale, awp ? resourcename(awp->type->itype->rtype, - 0) : "unarmed"), weapon_effskill(at, dt, awp, true, dist > 1), - success ? "hits" : "misses", itoa36(dt.fighter->unit->no), dt.index, - LOC(default_locale, dwp ? resourcename(dwp->type->itype->rtype, - 0) : "unarmed"), weapon_effskill(dt, at, dwp, false, dist > 1), skdiff, - dist); -} - int hits(troop at, troop dt, weapon * awp) { fighter *af = at.fighter, *df = dt.fighter; @@ -2032,14 +2001,8 @@ int hits(troop at, troop dt, weapon * awp) shield = select_armor(dt, false); } if (contest(skdiff, dt, armor, shield)) { - if (bdebug) { - debug_hit(at, awp, dt, dwp, skdiff, dist, true); - } return 1; } - if (bdebug) { - debug_hit(at, awp, dt, dwp, skdiff, dist, false); - } return 0; } @@ -2190,11 +2153,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) } } if (reload && wp && wp->type->reload && !getreload(ta)) { - int i = setreload(ta); - if (bdebug) { - fprintf(bdebug, "%s/%d reloading %d turns\n", itoa36(au->no), - ta.index, i); - } + setreload(ta); } } } @@ -2874,13 +2833,6 @@ static void aftermath(battle * b) } reorder_fleeing(r); - - if (bdebug) { - fprintf(bdebug, "The battle lasted %d turns, %s and %s.\n", - b->turn, - b->has_tactics_turn ? "had a tactic turn" : "had no tactic turn", - ships_damaged ? "was relevant" : "was not relevant."); - } } static void battle_punit(unit * u, battle * b) @@ -2894,10 +2846,6 @@ static void battle_punit(unit * u, battle * b) spunit(&S, f, u, 4, seen_battle); for (x = S; x; x = x->next) { fbattlerecord(b, f, x->s); - if (bdebug && u->faction == f) { - fputs(x->s, bdebug); - fputc('\n', bdebug); - } } if (S) freestrlist(S); @@ -3077,17 +3025,6 @@ static void print_stats(battle * b) fbattlerecord(b, f, buf); } - if (bdebug && s->faction) { - if (f_get_alliance(s->faction)) { - fprintf(bdebug, "##### %s (%s/%d)\n", s->faction->name, - itoa36(s->faction->no), - s->faction->alliance ? s->faction->alliance->id : 0); - } - else { - fprintf(bdebug, "##### %s (%s)\n", s->faction->name, - itoa36(s->faction->no)); - } - } print_fighters(b, s); } @@ -3519,28 +3456,6 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) return false; } -static const char *simplename(region * r) -{ - int i; - static char name[17]; - const char *cp = rname(r, default_locale); - for (i = 0; *cp && i != 16; ++i, ++cp) { - int c = *(unsigned char *)cp; - while (c && !isalpha(c) && !isspace(c)) { - ++cp; - c = *(unsigned char *)cp; - } - if (isspace(c)) - name[i] = '_'; - else - name[i] = *cp; - if (c == 0) - break; - } - name[i] = 0; - return name; -} - battle *make_battle(region * r) { battle *b = (battle *)calloc(1, sizeof(battle)); @@ -3552,29 +3467,6 @@ battle *make_battle(region * r) for (bld = r->buildings; bld != NULL; bld = bld->next) bld->sizeleft = bld->size; - if (battledebug) { - char zText[4096]; - char zFilename[4096]; - join_path(basepath(), "battles", zText, sizeof(zText)); - if (mkdir(zText, 0777) != 0) { - log_error("could not create subdirectory for battle logs: %s", zText); - battledebug = false; - } - else { - sprintf(zFilename, "battle-%d-%s.log", obs_count++, simplename(r)); - join_path(zText, zFilename, zText, sizeof(zText)); - bdebug = fopen(zText, "w"); - if (!bdebug) - log_error("battles cannot be debugged"); - else { - const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; - fwrite(utf8_bom, 1, 3, bdebug); - fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r, - default_locale)); - } - } - } - b->region = r; b->plane = getplane(r); /* Finde alle Parteien, die den Kampf beobachten k�nnen: */ @@ -3644,10 +3536,6 @@ static void battle_free(battle * b) { void free_battle(battle * b) { - if (bdebug) { - fclose(bdebug); - } - while (b->factions) { bfaction *bf = b->factions; b->factions = bf->next; @@ -3812,13 +3700,7 @@ static void join_allies(battle * b) } /* keine Einw�nde, also soll er mitmachen: */ if (c == NULL) { - if (join_battle(b, u, false, &c)) { - if (battledebug) { - fprintf(bdebug, "%s joins to help %s against %s.\n", - unitname(u), factionname(s->faction), factionname(se->faction)); - } - } - else if (c == NULL) { + if (!join_battle(b, u, false, &c)) { continue; } } @@ -3826,12 +3708,7 @@ static void join_allies(battle * b) /* the enemy of my friend is my enemy: */ for (se = b->sides; se != s_end; ++se) { if (se->faction != u->faction && enemy(s, se)) { - if (set_enemy(se, c->side, false) && battledebug) { - fprintf(bdebug, - "%u/%s hates %u/%s because they are enemies with %u/%s.\n", - c->side->index, sidename(c->side), se->index, sidename(se), - s->index, sidename(s)); - } + set_enemy(se, c->side, false); } } } @@ -4012,18 +3889,8 @@ static bool start_battle(region * r, battle ** bp) } b = make_battle(r); } - if (join_battle(b, u, true, &c1)) { - if (battledebug) { - fprintf(bdebug, "%s joins by attacking %s.\n", - unitname(u), unitname(u2)); - } - } - if (join_battle(b, u2, false, &c2)) { - if (battledebug) { - fprintf(bdebug, "%s joins because of an attack from %s.\n", - unitname(u2), unitname(u)); - } - } + join_battle(b, u, true, &c1); + join_battle(b, u2, false, &c2); /* Hat die attackierte Einheit keinen Noaid-Status, * wird das Flag von der Faction genommen, andere @@ -4036,11 +3903,7 @@ static bool start_battle(region * r, battle ** bp) * Pr�combataura bei kurzem Kampf. */ c1->side->bf->attacker = true; - if (set_enemy(c1->side, c2->side, true) && battledebug) { - fprintf(bdebug, "%u/%s hates %u/%s because they attacked them.\n", - c2->side->index, sidename(c2->side), - c1->side->index, sidename(c1->side)); - } + set_enemy(c1->side, c2->side, true); fighting = true; } } @@ -4159,10 +4022,6 @@ static void battle_flee(battle * b) flee(dt); } } - if (bdebug && runners > 0) { - fprintf(bdebug, "Fleeing: %d from %s\n", runners, - itoa36(fig->unit->no)); - } } } } @@ -4265,9 +4124,6 @@ void do_battle(region * r) log_debug("battle in %s (%d, %d) : ", regionname(r, 0), r->x, r->y); for (; battle_report(b) && b->turn <= max_turns; ++b->turn) { - if (bdebug) { - fprintf(bdebug, "*** Turn: %d\n", b->turn); - } battle_flee(b); battle_update(b); battle_attacks(b); diff --git a/src/battle.h b/src/battle.h index dbdc7e1cb..1b4cf2588 100644 --- a/src/battle.h +++ b/src/battle.h @@ -227,7 +227,6 @@ extern "C" { } meffect; extern const troop no_troop; - extern bool battledebug; /* BEGIN battle interface */ side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); diff --git a/src/main.c b/src/main.c index 44c1b9e2d..5e998f835 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "eressea.h" -#include "battle.h" #ifdef USE_CURSES #include "gmtool.h" #endif @@ -71,8 +70,6 @@ static void load_inifile(dictionary * d) lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; verbosity = iniparser_getint(d, "eressea:verbose", 2); - battledebug = iniparser_getint(d, "eressea:debug", battledebug) ? 1 : 0; - str = iniparser_getstring(d, "eressea:locales", "de,en"); make_locales(str); From 1921fa4ec1deb4e1242c90d253025000dbb0f770 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 14:55:03 +0100 Subject: [PATCH 100/271] issue #478: re-enable -Werror --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39d290560..1b9cc82dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ COMPILE_DEFINITIONS ERESSEA_VERSION="${ERESSEA_VERSION}") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=unused-but-set-variable") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") From 437d959d97b9b8222ade0bbcb5e022f691cbe0e8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 11 Jan 2017 15:09:02 +0100 Subject: [PATCH 101/271] do not set -Werror twice --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b9cc82dc..39d290560 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ COMPILE_DEFINITIONS ERESSEA_VERSION="${ERESSEA_VERSION}") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=unused-but-set-variable") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") From 5b78578939fdada743c1106ac5881a4afab3af11 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 14 Jan 2017 17:19:08 +0100 Subject: [PATCH 102/271] github issue #626: installing in non-standard paths --- s/cmake-init | 3 ++- s/install | 2 -- s/setup | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/s/cmake-init b/s/cmake-init index ea94afb7c..84a1d9cdb 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -35,12 +35,13 @@ if [ -d $HOME/usr ]; then PREFIX_PATH=$HOME/usr:$HOME/usr/local:$PREFIX_PATH fi +DEST=$(dirname $ROOT)/server ARGS=" -DCMAKE_MODULE_PATH=$ROOT/cmake/Modules \ -DCMAKE_BUILD_TYPE=$BUILD \ -DCMAKE_LIBRARY_PATH=$LIBRARY_PATH \ -DCMAKE_INCLUDE_PATH=$INCLUDE_PATH \ -DCMAKE_PREFIX_PATH=$PREFIX_PATH \ - -DCMAKE_INSTALL_PREFIX=$HOME/eressea/server" + -DCMAKE_INSTALL_PREFIX=$DEST" git submodule update --init diff --git a/s/install b/s/install index 416d07f9a..962961063 100755 --- a/s/install +++ b/s/install @@ -8,8 +8,6 @@ while [ ! -d $ROOT/.git ]; do fi done -DEST=$(dirname $ROOT)/server - [ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" [ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" [ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" diff --git a/s/setup b/s/setup index 0839d5b8f..fc5fb9874 100755 --- a/s/setup +++ b/s/setup @@ -1,5 +1,15 @@ #!/bin/bash +ROOT=$(pwd) +while [ ! -d $ROOT/.git ]; do + ROOT=$(dirname $ROOT) + if [ "/" = "$ROOT" ]; then + echo "could not find root, are you in the git repository?" + exit + fi +done +ERESSEA=$(dirname $ROOT) + function abort() { echo $1 [ -z $2 ] && exit -1 @@ -37,7 +47,6 @@ while getopts :d:g:r:s:hfn o; do done [ $game -gt 0 ] || abort "must use a positive integer for game id" -[ -d $ERESSEA ] || abort "invalid or missing env variable ERESSEA ($ERESSEA)" [ -z $SOURCE ] && SOURCE=$ERESSEA/$src [ -d $SOURCE ] || abort "invalid source directory $SOURCE" [ -z $rules ] && rules=e$game @@ -46,7 +55,8 @@ done [ -e $TOOLS ] || TOOLS=$SOURCE/bin [ -z $INIFILE ] && INIFILE=$TOOLS/inifile [ -e $INIFILE ] || INIFILE=$TOOLS/iniparser/inifile -#[ -e $INIFILE ] || abort "tool is not installed: $INIFILE" + +[ -e $SOURCE/conf/$rules/config.xml ] || abort "cannot find conf/$rules/config.xml" cd $ERESSEA if [ -d $dir ] ; then From d7dd281a6a0e9a99f09c93d087a7bfac3413d893 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 08:32:31 +0100 Subject: [PATCH 103/271] move orders-accept configuration to eressea.ini install lunit, too --- CMakeLists.txt | 1 + conf/eressea.ini | 3 ++ process/orders-accept | 111 ++++++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c08e16c20..8fd15f201 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,4 +23,5 @@ add_subdirectory (src eressea) install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.xml") install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.json") install(DIRECTORY scripts DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua") +install(DIRECTORY lunit DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua") install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/conf/eressea.ini b/conf/eressea.ini index e14d0af50..c2f7bbb7f 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -1,3 +1,6 @@ +[game] +email = Eressea Server +name = Eressea [eressea] base = . diff --git a/process/orders-accept b/process/orders-accept index 151f0b196..49bdc3cb0 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -3,22 +3,50 @@ from email.Utils import parseaddr from email.Parser import Parser -from os import mkdir, rename, stat, utime, unlink, symlink -from os.path import exists +import os +import os.path +import ConfigParser from re import compile, IGNORECASE from stat import ST_MTIME from string import upper, split, replace import logging -from sys import argv, stdin, exit +import sys +from sys import stdin from time import ctime, sleep, time from socket import gethostname from rfc822 import parsedate_tz, mktime_tz -LOG_FILENAME='/home/eressea/log/orders.log' +if 'ERESSEA' in os.environ: + dir = os.environ['ERESSEA'] +elif 'HOME' in os.environ: + dir = os.path.join(os.environ['HOME'], '/eressea') +else: # WTF? No HOME? + dir = "/home/eressea/eressea" +if not os.path.isdir(dir): + print "please set the ERESSEA environment variable to the install path" + sys.exit(1) +rootdir = dir + +try: + game = int(sys.argv[1]) +except: + game = sys.argv[1] +gamedir = os.path.join(rootdir, "game-%d" % (game, )) +frommail = 'Eressea Server ' +gamename = 'Eressea' +inifile = os.path.join(gamedir, 'eressea.ini') +if not os.path.exists(inifile): + print "no such file: " . inifile +else: + config = ConfigParser.ConfigParser() + config.read(inifile) + if config.has_option('game', 'email'): + frommail = config.get('game', 'email') + if config.has_option('game', 'name'): + gamename = config.get('game', 'name') + config = None prefix = 'turn-' hostname = gethostname() -# base directory for all your games: -rootdir = "/home/eressea" orderbase = "orders.dir" sendmail = True # maximum number of reports per sender: @@ -28,36 +56,21 @@ writeheaders = True # reject all html email? rejecthtml = True -games = [ - { - "from" : "Eressea Server ", - "prefix" : "Eressea" - }, - { - "from" : "Eressea Server ", - "prefix": "E3" - }, - { - "from" : "Eressea Server ", - "prefix": "E4" - }, -] - def unlock_file(filename): try: - unlink(filename+".lock") + os.unlink(filename+".lock") except: print "could not unlock %s.lock, file not found" % filename def lock_file(filename): i = 0 wait = 1 - if not exists(filename): + if not os.path.exists(filename): file=open(filename, "w") file.close() while True: try: - symlink(filename, filename+".lock") + os.symlink(filename, filename+".lock") return except: i = i+1 @@ -74,17 +87,17 @@ messages = { "software and re-send the orders.", "multipart-de" : - "FEHLER: Die von dir eingeschickte Mail enthält keinen " \ + "FEHLER: Die von dir eingeschickte Mail enth�lt keinen " \ "Text. Evtl. hast Du den Zug als HTML oder als anderweitig " \ - "ungültig formatierte Mail ingeschickt. Wir können ihn " \ - "deshalb nicht berücksichtigen. Schicke den Zug nochmals " \ + "ung�ltig formatierte Mail ingeschickt. Wir k�nnen ihn " \ + "deshalb nicht ber�cksichtigen. Schicke den Zug nochmals " \ "als reinen Text ohne Formatierungen ein.", "maildate-de": - "Es erreichte uns bereits ein Zug mit einem späteren " \ + "Es erreichte uns bereits ein Zug mit einem sp�teren " \ "Absendedatum (%s > %s). Entweder ist deine " \ "Systemzeit verstellt, oder ein Zug hat einen anderen Zug von " \ - "dir auf dem Transportweg überholt. Entscheidend für die " \ + "dir auf dem Transportweg �berholt. Entscheidend f�r die " \ "Auswertungsreihenfolge ist das Absendedatum, d.h. der Date:-Header " \ "deiner Mail.", @@ -173,8 +186,8 @@ def available_file(dirname, basename): ver = 0 maxdate = 0 filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver) - while exists(filename): - maxdate = max(stat(filename)[ST_MTIME], maxdate) + while os.path.exists(filename): + maxdate = max(os.stat(filename)[ST_MTIME], maxdate) ver = ver + 1 filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver) if ver >= maxfiles: @@ -234,7 +247,7 @@ def copy_orders(message, filename, sender): from os.path import split dirname, basename = split(filename) dirname = dirname + '/headers' - if not exists(dirname): mkdir(dirname) + if not os.path.exists(dirname): os.mkdir(dirname) outfile = open(dirname + '/' + basename, "w") for name, value in message.items(): outfile.write(name + ": " + value + "\n") @@ -265,16 +278,14 @@ def copy_orders(message, filename, sender): # create a file, containing: # game=0 locale=de file=/path/to/filename email=rcpt@domain.to def accept(game, locale, stream, extend=None): - global rootdir, orderbase + global rootdir, orderbase, gamedir, gamename, frommail if extend is not None: orderbase = orderbase + ".pre-" + extend - gamename = games[game-2]["prefix"] - gamedir = rootdir+"/eressea/game-%d" % (game, ) - savedir = gamedir+"/"+orderbase + savedir = os.path.join(gamedir, orderbase) # check if it's one of the pre-sent orders. # create the save-directories if they don't exist - if not exists(gamedir): mkdir(gamedir) - if not exists(savedir): mkdir(savedir) + if not os.path.exists(gamedir): os.mkdir(gamedir) + if not os.path.exists(savedir): os.mkdir(savedir) # parse message message = Parser().parse(stream) sender = get_sender(message) @@ -298,7 +309,7 @@ def accept(game, locale, stream, extend=None): maildate = message.get("Date") if maildate != None: turndate = mktime_tz(parsedate_tz(maildate)) - utime(filename, (turndate, turndate)) + os.utime(filename, (turndate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) if turndate < maxdate: logger.warning("inconsistent message date " + sender) @@ -313,9 +324,9 @@ def accept(game, locale, stream, extend=None): warning = " (" + messages["error-" + locale] + ")" msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n" logger.warning("rejected - no text/plain in orders from " + sender) - unlink(filename) + os.unlink(filename) savedir = savedir + "/rejected" - if not exists(savedir): mkdir(savedir) + if not os.path.exists(savedir): os.mkdir(savedir) lock_file(gamedir + "/orders.queue") maxdate, filename = available_file(savedir, prefix + sender) store_message(message, filename) @@ -323,7 +334,6 @@ def accept(game, locale, stream, extend=None): fail = True if sendmail and warning is not None: - frommail = games[key]["from"] subject = gamename + " " + messages["subject-"+locale] + warning mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg from smtplib import SMTP @@ -347,22 +357,15 @@ def accept(game, locale, stream, extend=None): return 0 # the main body of the script: +LOG_FILENAME=os.path.join(rootdir, 'log/orders.log') logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME) logger = logging delay=None # TODO: parse the turn delay -try: - game = int(argv[1]) -except: - game = argv[1] - if game[:3]=='e3a': - game = 3 - elif game[:7]=='eressea': - game = 2 -locale = argv[2] +locale = sys.argv[2] infile = stdin -if len(argv)>3: - infile = open(argv[3], "r") +if len(sys.argv)>3: + infile = open(sys.argv[3], "r") retval = accept(game, locale, infile, delay) if infile!=stdin: infile.close() -exit(retval) +sys.exit(retval) From 6d5749308dd3479077685588fe273a4b5ba01127 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 18:44:58 +0100 Subject: [PATCH 104/271] rename [eressea] section to [game] --- conf/eressea.ini | 5 +- process/orders-accept | 49 ++++++++++--------- process/orders-process | 107 +++++++++++++++++++++++++---------------- s/setup | 4 +- src/main.c | 14 +++--- 5 files changed, 102 insertions(+), 77 deletions(-) diff --git a/conf/eressea.ini b/conf/eressea.ini index c2f7bbb7f..b6db180ca 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -1,8 +1,7 @@ [game] -email = Eressea Server +email = eressea-server@kn-bremen.de +sender = Eressea Server name = Eressea - -[eressea] base = . report = reports verbose = 0 diff --git a/process/orders-accept b/process/orders-accept index 49bdc3cb0..78af0a056 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -27,13 +27,12 @@ if not os.path.isdir(dir): sys.exit(1) rootdir = dir -try: - game = int(sys.argv[1]) -except: - game = sys.argv[1] +game = int(sys.argv[1]) gamedir = os.path.join(rootdir, "game-%d" % (game, )) -frommail = 'Eressea Server ' +frommail = 'eressea-server@kn-bremen.de' gamename = 'Eressea' +sender = '%s Server <%s>' % (gamename, frommail) + inifile = os.path.join(gamedir, 'eressea.ini') if not os.path.exists(inifile): print "no such file: " . inifile @@ -44,6 +43,10 @@ else: frommail = config.get('game', 'email') if config.has_option('game', 'name'): gamename = config.get('game', 'name') + if config.has_option('game', 'sender'): + sender = config.get('game', 'sender') + else: + sender = "%s Server <%s>" % (gamename, frommail) config = None prefix = 'turn-' hostname = gethostname() @@ -278,7 +281,7 @@ def copy_orders(message, filename, sender): # create a file, containing: # game=0 locale=de file=/path/to/filename email=rcpt@domain.to def accept(game, locale, stream, extend=None): - global rootdir, orderbase, gamedir, gamename, frommail + global rootdir, orderbase, gamedir, gamename, sender if extend is not None: orderbase = orderbase + ".pre-" + extend savedir = os.path.join(gamedir, orderbase) @@ -288,21 +291,21 @@ def accept(game, locale, stream, extend=None): if not os.path.exists(savedir): os.mkdir(savedir) # parse message message = Parser().parse(stream) - sender = get_sender(message) - logger = logging.getLogger(sender) + email = get_sender(message) + logger = logging.getLogger(email) # write syslog - if sender is None or valid_email(sender)==0: - logger.warning("invalid email address: " + str(sender)) + if email is None or valid_email(email)==0: + logger.warning("invalid email address: " + str(email)) return -1 - logger.info("received orders from " + sender) + logger.info("received orders from " + email) # get an available filename lock_file(gamedir + "/orders.queue") - maxdate, filename = available_file(savedir, prefix + sender) + maxdate, filename = available_file(savedir, prefix + email) if filename is None: - logger.warning("more than " + str(maxfiles) + " orders from " + sender) + logger.warning("more than " + str(maxfiles) + " orders from " + email) return -1 # copy the orders to the file - text_ok = copy_orders(message, filename, sender) + text_ok = copy_orders(message, filename, email) unlock_file(gamedir + "/orders.queue") warning, msg, fail = None, "", False @@ -312,47 +315,47 @@ def accept(game, locale, stream, extend=None): os.utime(filename, (turndate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) if turndate < maxdate: - logger.warning("inconsistent message date " + sender) + logger.warning("inconsistent message date " + email) warning = " (" + messages["warning-" + locale] + ")" msg = msg + formatpar(messages["maildate-" + locale] % (ctime(maxdate),ctime(turndate)), 76, 2) + "\n" else: - logger.warning("missing message date " + sender) + logger.warning("missing message date " + email) warning = " (" + messages["warning-" + locale] + ")" msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n" if not text_ok: warning = " (" + messages["error-" + locale] + ")" msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n" - logger.warning("rejected - no text/plain in orders from " + sender) + logger.warning("rejected - no text/plain in orders from " + email) os.unlink(filename) savedir = savedir + "/rejected" if not os.path.exists(savedir): os.mkdir(savedir) lock_file(gamedir + "/orders.queue") - maxdate, filename = available_file(savedir, prefix + sender) + maxdate, filename = available_file(savedir, prefix + email) store_message(message, filename) unlock_file(gamedir + "/orders.queue") fail = True if sendmail and warning is not None: subject = gamename + " " + messages["subject-"+locale] + warning - mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg + mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, sender, email) + msg from smtplib import SMTP server = SMTP("localhost") - server.sendmail(frommail, sender, mail) + server.sendmail(sender, email, mail) server.close() if not sendmail: - print text_ok, fail, sender + print text_ok, fail, email print filename if not fail: lock_file(gamedir + "/orders.queue") queue = open(gamedir + "/orders.queue", "a") - queue.write("email=%s file=%s locale=%s game=%s\n" % (sender, filename, locale, game)) + queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game)) queue.close() unlock_file(gamedir + "/orders.queue") - logger.info("done - accepted orders from " + sender) + logger.info("done - accepted orders from " + email) return 0 diff --git a/process/orders-process b/process/orders-process index 753385e2e..b33cc05bf 100755 --- a/process/orders-process +++ b/process/orders-process @@ -2,7 +2,9 @@ # -*- coding: iso-8859-1 -*- from os import unlink, symlink, rename, popen, tmpfile -from os.path import exists +import os +import os.path +import ConfigParser from re import compile, IGNORECASE from string import split, join, upper, strip from sys import argv, exit @@ -14,9 +16,8 @@ from epasswd import EPasswd def pwd_get_email(faction, pwd, pwdfile=None): return None -def splitfilename(filename): - from os.path import split - return split(filename) +def split_filename(filename): + return os.path.split(filename) def unlock_file(filename): try: @@ -28,7 +29,7 @@ def unlock_file(filename): def lock_file(filename): i = 0 wait = 1 - if not exists(filename): + if not os.path.exists(filename): file=open(filename, "w") file.close() while True: @@ -62,17 +63,47 @@ messages = { "error-en": "Error", } +game = int(sys.argv[1]) +echeck_cmd = "/home/eressea/echeck/echeck.sh" +maxlines = 25 # base directory for all your games: -rootdir = "/home/eressea/eressea" -frommail = "Eressea Server " -orderbase = "orders.dir" -sendmail = True -maxlines = 25 -echeck_cmd = "/home/eressea/echeck/echeck.sh" +install_dir = "/home/eressea/eressea" +if 'ERESSEA' in os.environ: + install_dir = os.environ['ERESSEA'] +elif 'HOME' in os.environ: + install_dir = os.path.join(os.environ['HOME'], '/eressea') +if not os.path.isdir(install_dir): + print "please set the ERESSEA environment variable to the install path" + sys.exit(1) + +game_dir = os.path.join(install_dir, "game-%d" % (game, )) +frommail = 'eressea-server@kn-bremen.de' +gamename = 'Eressea' +sender = '%s Server <%s>' % (gamename, frommail) + +inifile = os.path.join(gamedir, 'eressea.ini') +if not os.path.exists(inifile): + print "no such file: " . inifile +else: + config = ConfigParser.ConfigParser() + config.read(inifile) + if config.has_option('game', 'email'): + frommail = config.get('game', 'email') + if config.has_option('game', 'name'): + gamename = config.get('game', 'name') + if config.has_option('game', 'sender'): + sender = config.get('game', 'sender') + else: + sender = "%s Server <%s>" % (gamename, frommail) + config = None + +queue_file = os.path.join(game_dir, "orders.queue") +if not os.path.exists(queue_file): + exit(0) # regular expression that finds the start of a faction -fact_re = compile("^\s*(eressea|vinyambar|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE) +fact_re = compile("^\s*(eressea|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE) def check_pwd(filename, email, pw_data): results = [] @@ -98,7 +129,7 @@ def check_pwd(filename, email, pw_data): return results def echeck(filename, locale, rules): - dirname, filename = splitfilename(filename) + dirname, filename = split_filename(filename) stream = popen("%s %s %s %s %s" % (echeck_cmd, locale, filename, dirname, rules), 'r') lines = stream.readlines() if len(lines)==0: @@ -111,14 +142,6 @@ def echeck(filename, locale, rules): stream.close() return mail -## the main body of the script -game = int(argv[1]) - -basedir = rootdir + "/game-%d" % (game, ) -queuename = basedir + "/orders.queue" -if not exists(queuename): - exit(0) - # parse the queue file - #print "connecting to SMTP..." from smtplib import SMTP @@ -127,16 +150,17 @@ try: except: print "could not connect to SMTP server" exit(0) + #print "reading password file..." -pw_data = EPasswd(basedir + "/passwd") +pw_data = EPasswd(os.path.join(game_dir,"passwd")) #print "reading orders.queue..." # move the queue file to a save space while locking it: try: - lock_file(queuename) + lock_file(queue_file) except: exit(0) -queuefile = open(queuename, "r") +queuefile = open(queue_file, "r") lines = queuefile.readlines() queuefile.close() @@ -154,9 +178,9 @@ tmpfile.close() openlog("orders") -unlink(queuename) +unlink(queue_file) try: - unlock_file(queuename) + unlock_file(queue_file) except: pass @@ -170,15 +194,15 @@ for line in lines: email = dict["email"] locale = dict["locale"] game = int(dict["game"]) - file = dict["file"] + infile = dict["file"] gamename='[E%d]' % game rules='e%d' % game warning = "" failed = True - results = check_pwd(file, email, pw_data) - logfile = open(basedir+"/zug.log", "a") - dirname, filename = splitfilename(file) - msg = messages["validate-"+locale] + " " + filename + "\n\n" + results = check_pwd(infile, email, pw_data) + logfile = open(os.path.join(game_dir, "zug.log"), "a") + dirname, filename = split_filename(infile) + msg = messages["validate-"+locale] + " " + infilename + "\n\n" for faction, game_email, success, pwd in results: msg = msg + messages["faction-"+locale] + " " + faction + "\n" if success: failed = False @@ -189,25 +213,24 @@ for line in lines: if failed: warning = " (" + messages["warning-" + locale] + ")" - syslog("failed - no valid password in " + file) + syslog("failed - no valid password in " + infile) else: - result = echeck(file, locale, rules) - if email=='eressea': - print result - continue - elif result is None: + result = None + if os.path.exists(echeck_cmd): + result = echeck(infile, locale, rules) + if result is None: # echeck did not finish - msg = msg + "Echeck was killed. Your turn was accepted, but could not be verified.\n" + msg = msg + "Echeck is broken. Your turn was accepted, but could not be verified.\n" warning = " (" + messages["warning-" + locale] + ")" - syslog("process - echeck got killed, " + file) + syslog("process - echeck broken, " + infile) else: msg = msg + result - syslog("process - checked orders in " + file) + syslog("process - checked orders in " + infile) subject = gamename + " " + messages["subject-" + locale] + warning - msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, frommail, email) + msg + msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, sender, email) + msg try: - server.sendmail(frommail, email, msg) + server.sendmail(sender, email, msg) except: syslog("failed - cannot send to " + email) diff --git a/s/setup b/s/setup index fc5fb9874..d8ffa74ad 100755 --- a/s/setup +++ b/s/setup @@ -94,8 +94,8 @@ touch eressea.ini } ini_start -ini_sec eressea -ini_add eressea locales de,en +ini_sec game +ini_add game locales de,en ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit diff --git a/src/main.c b/src/main.c index 5e998f835..2d81041ec 100644 --- a/src/main.c +++ b/src/main.c @@ -54,23 +54,23 @@ static void load_inifile(dictionary * d) assert(d); - str = iniparser_getstring(d, "eressea:base", basedir); + str = iniparser_getstring(d, "game:base", basedir); if (str != basedir) { set_basepath(str); } - str = iniparser_getstring(d, "eressea:report", reportdir); + str = iniparser_getstring(d, "game:report", reportdir); if (str != reportdir) { set_reportpath(str); } - str = iniparser_getstring(d, "eressea:data", datadir); + str = iniparser_getstring(d, "game:data", datadir); if (str != datadir) { set_datapath(str); } - lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; + lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0; - verbosity = iniparser_getint(d, "eressea:verbose", 2); - str = iniparser_getstring(d, "eressea:locales", "de,en"); + verbosity = iniparser_getint(d, "game:verbose", 2); + str = iniparser_getstring(d, "game:locales", "de,en"); make_locales(str); if (global.inifile) iniparser_freedict(global.inifile); @@ -84,7 +84,7 @@ static void parse_config(const char *filename) load_inifile(d); log_debug("reading from configuration file %s\n", filename); - memdebug = iniparser_getint(d, "eressea:memcheck", memdebug); + memdebug = iniparser_getint(d, "game:memcheck", memdebug); #ifdef USE_CURSES /* only one value in the [editor] section */ force_color = iniparser_getint(d, "editor:color", force_color); From e6f676c30c2a93924169d07ad9a4e1815c1b2895 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 20:05:33 +0100 Subject: [PATCH 105/271] we do not need eressea.conf --- process/send-bz2-report | 1 - process/sendreport.sh | 1 - process/sendreports.sh | 1 - 3 files changed, 3 deletions(-) diff --git a/process/send-bz2-report b/process/send-bz2-report index e9962d539..983564bea 100755 --- a/process/send-bz2-report +++ b/process/send-bz2-report @@ -8,7 +8,6 @@ if [ ! -f reports.txt ]; then exit -2 fi source $HOME/bin/functions.sh -source $ERESSEA/etc/eressea.conf TEMPLATE=report-mail.txt if [ "$1" == "-Lde" ] diff --git a/process/sendreport.sh b/process/sendreport.sh index 1b9af1d35..93d52f0b4 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -8,7 +8,6 @@ if [ -z $ERESSEA ]; then exit -2 fi source $HOME/bin/functions.sh -source $HOME/etc/eressea.conf GAME=$1 EMAIL=$2 diff --git a/process/sendreports.sh b/process/sendreports.sh index fc24200b6..c2bfa741c 100755 --- a/process/sendreports.sh +++ b/process/sendreports.sh @@ -8,7 +8,6 @@ if [ -z $ERESSEA ]; then exit -2 fi source $HOME/bin/functions.sh -source $ERESSEA/etc/eressea.conf if [ ! -z $1 ]; then GAME=$ERESSEA/game-$1 From b51349df6bc1afe7667dd33062abc15263b59464 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 Jan 2017 22:39:38 +0100 Subject: [PATCH 106/271] change error message categories. also removing some unused messages and code that supports them. https://bugs.eressea.de/view.php?id=2270 --- res/core/messages.xml | 117 +++++++--------------------------------- src/kernel/messages.c | 18 ------- src/kernel/types.h | 2 - src/util/unicode.test.c | 17 ++++++ 4 files changed, 36 insertions(+), 118 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 260f76c70..41569d9f3 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1804,7 +1804,7 @@ "$unit($unit) in $region($region): '$order($command)' - Der Magier erschafft ein Traumgebäude." "$unit($unit) in $region($region): '$order($command)' - The magician creates an illusionary building." - + @@ -2402,7 +2402,7 @@ "Eine Botschaft von $unit.dative($unit) in $region($region): 'Ups! Quack, Quack!'" "A message from $unit($unit) in $region($region): 'Oops! Croak, Croak!'" - + @@ -2412,7 +2412,7 @@ "$unit($unit) in $region($region): '$order($command)' - $unit($mage) kann Zauber, die durch $unit($unit) gewirkt werden, nicht zusätzlich in die Ferne richten." "$unit($unit) in $region($region): '$order($command)' - $unit($mage) cannot direct spells that are channeled through $unit($unit) into distant regions." - + @@ -2552,13 +2552,6 @@ "$unit($unit) in $region($region) regeneriert $int($amount) Aura." "$unit($unit) regenerates $int($amount) aura in $region($region)." - - - - - "$string" - "$string" - @@ -2596,13 +2589,6 @@ "$unit($teacher) lehrt $unit($student) $skill($skill)." "$unit($teacher) teaches $unit($student) $skill($skill)." - - - - - "$string" - "$string" - @@ -2834,13 +2820,6 @@ "$unit($unit) baut für $int($size) an $ship($ship) weiter." "$unit($unit) builds $int($size) more on $ship($ship)." - - - - - "$string" - "$string" - @@ -2878,15 +2857,7 @@ "$unit($unit) $if($eq($mode,1),"reitet", "wandert") von $region($start) nach $region($end).$if($isnull($regions),""," Dabei wurde $trail($regions) durchquert.")" "$unit($unit) $if($eq($mode,1),"rides", "walks") from $region($start) to $region($end)$if($isnull($regions),""," by way of $trail($regions)")." - - - - - - "$unit($unit) entdeckt dass im $direction($direction) $terrain($region) ist." - "$unit($unit) discovered that $terrain($region) lies in the $direction($direction)." - - + @@ -2895,7 +2866,7 @@ "$unit($unit) entdeckt, dass $region($region) $localize($terrain) ist." "$unit($unit) discovered that $region($region) is $localize($terrain)." - + @@ -2903,7 +2874,7 @@ "$unit($unit) ist in dieser Runde gelandet und kann nicht weiter ins Landesinnere nach $region($region) vorstossen." "$unit($unit) has just landed and cannot continue moving to $region($region)." - + @@ -2911,7 +2882,7 @@ "Die Mannschaft der $ship($ship) kann in letzter Sekunde verhindern, dass das Schiff in $region($region) auf Land aufläuft." "At the very last moment, the crew of the $ship($ship) saved the ship from running aground in $region($region)." - + @@ -2919,7 +2890,7 @@ "Die $ship($ship) konnte in $region($region) nicht einreisen, die Küste ist zu gefährlich für das Schiff." "The $ship($ship) could not berth in $region($region). The coast is too dangerous for the vessel." - + @@ -2927,7 +2898,7 @@ "Die Mannschaft der $ship($ship) weigert sich, nach $direction($direction) zu reisen." "The crew of the $ship($ship) refuses to travel to the $direction($direction)." - + @@ -2935,7 +2906,7 @@ "Die Mannschaft der $ship($ship) weigert sich, nach $region($region) zu reisen." "The crew of the $ship($ship) refuses to travel to $region($region)." - + @@ -2943,7 +2914,7 @@ "$unit($unit) weigert sich, nach $direction($direction) zu reisen." "$unit($unit) refuses to travel to the $direction($direction)." - + @@ -2951,7 +2922,7 @@ "$unit($unit) weigert sich, nach $region($region) zu reisen." "$unit($unit) refuses to travel to $region($region)." - + @@ -2959,7 +2930,7 @@ "Die $ship($ship) konnte $region($region) nicht verlassen." "The $ship($ship) could not leave $region($region)." - + @@ -2968,35 +2939,7 @@ "$unit($unit) wurde in $region($region) von $unit.dative($guard) aufgehalten." "$unit($unit) was kept in $region($region) by $unit($guard)." - - - - - "Wir haben den Krieg mit $faction($faction) beendet." - "We declared peace with $faction($faction)." - - - - - - "$faction($faction) hat den Krieg mit uns beendet." - "$faction($faction) has declared peace with us." - - - - - - "Wir haben $faction($faction) den Krieg erklärt." - "We declared war on $faction($faction)." - - - - - - "$faction($faction) hat uns den Krieg erklärt." - "$faction($faction) has declared war on us." - - + @@ -3005,7 +2948,7 @@ "$unit($unit) konnte nicht von $region($region) nach $region($target) reisen, da der Besitzer der Region es verhinderte." "$unit($unit) could not travel from $region($region) to $region($target) because the owner denied entrance." - + @@ -3029,7 +2972,7 @@ "$unit($follower) konnte $unit($unit) nicht folgen." "$unit($follower) could not follow $unit($unit)." - + @@ -3037,7 +2980,7 @@ "$unit($unit) entdeckt, dass es keinen Weg nach $direction($direction) gibt." "$unit($unit) discovers that there is no route going $direction($direction)." - + @@ -3046,13 +2989,6 @@ "$unit($unit) konnte von $region($region) nicht nach $direction($direction) ausreisen, der Nebel war zu dicht." "$unit($unit) could not travel $direction($direction) from $region($region), the fog was too dense." - - - - - "$string" - "$string" - @@ -6945,13 +6881,6 @@ "$unit($unit) in $region($region): '$order($command)' - Man benötigt mindestens $int($minskill) $skill($skill), um $resource($product,0) zu produzieren." "$unit($unit) in $region($region): '$order($command)' - You need at least $int($minskill) $skill($skill), to produce $resource($product,0)." - - - - - "$string" - "$string" - @@ -6959,13 +6888,6 @@ "$string" "$string" - - - - - "$string" - "$string" - @@ -6997,7 +6919,6 @@ "$unit($target) erhält $int($amount) $resource($resource,$amount) von $unit($unit)." "$unit($target) receives $int($amount) $resource($resource,$amount) from $unit($unit)." - @@ -7200,7 +7121,7 @@ "$unit($unit) in $region($region): '$order($command)' - No pyramids may be build in this region. The closest region to build a pyramid in is between $int($mindist) and $int($maxdist) regions away." - + @@ -7621,7 +7542,7 @@ "Heer $int($index)($abbrev): $int($dead) Tote, $int($fled) Geflohene, $int($survived) Ãœberlebende." "Army $int($index)($abbrev): $int($dead) dead, $int($fled) fled, $int($survived) survivors." - + diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 89278624f..cb859df96 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -214,29 +214,11 @@ caddmessage(region * r, faction * f, const char *s, msg_t mtype, int level) UNUSED_ARG(level); switch (mtype) { - case MSG_INCOME: - assert(f); - m = add_message(&f->msgs, msg_message("msg_economy", "string", s)); - break; case MSG_BATTLE: assert(0 || !"battle messages must not use addmessage"); break; - case MSG_MOVE: - assert(f); - m = add_message(&f->msgs, msg_message("msg_movement", "string", s)); - break; - case MSG_COMMERCE: - assert(f); - m = add_message(&f->msgs, msg_message("msg_economy", "string", s)); - break; - case MSG_PRODUCE: - assert(f); - m = add_message(&f->msgs, msg_message("msg_production", "string", s)); - break; case MSG_MAGIC: - case MSG_COMMENT: case MSG_MESSAGE: - case MSG_ORCVERMEHRUNG: case MSG_EVENT: /* Botschaften an REGION oder einzelne PARTEI */ m = msg_message("msg_event", "string", s); diff --git a/src/kernel/types.h b/src/kernel/types.h index 2b63f7e07..b9faefce7 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -146,9 +146,7 @@ typedef enum { /* Fehler und Meldungen im Report */ MSG_INCOME, MSG_COMMERCE, MSG_PRODUCE, - MSG_ORCVERMEHRUNG, MSG_MESSAGE, - MSG_COMMENT, MSG_MAGIC, MAX_MSG } msg_t; diff --git a/src/util/unicode.test.c b/src/util/unicode.test.c index ef07c944c..a6268186e 100644 --- a/src/util/unicode.test.c +++ b/src/util/unicode.test.c @@ -100,9 +100,26 @@ static void test_unicode_utf8_to_ucs(CuTest *tc) { CuAssertIntEquals(tc, 1, sz); } +static void test_unicode_bug2262(CuTest *tc) { + char name[7]; + ucs4_t ucs; + size_t sz; + + strcpy(name, "utende"); + CuAssertIntEquals(tc, 0, unicode_utf8_to_ucs4(&ucs, name, &sz)); + CuAssertIntEquals(tc, 1, sz); + CuAssertIntEquals(tc, 'u', ucs); + CuAssertIntEquals(tc, 0, unicode_utf8_trim(name)); + + name[0] = -4; // latin1: ü should fail to decode + CuAssertIntEquals(tc, EILSEQ, unicode_utf8_to_ucs4(&ucs, name, &sz)); + CuAssertIntEquals(tc, EILSEQ, unicode_utf8_trim(name)); +} + CuSuite *get_unicode_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_unicode_bug2262); SUITE_ADD_TEST(suite, test_unicode_tolower); SUITE_ADD_TEST(suite, test_unicode_trim); SUITE_ADD_TEST(suite, test_unicode_utf8_to_other); From e511bf76b57e164252d8a83fe13afe3666bf9aa1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 18:53:11 +0100 Subject: [PATCH 107/271] read game configuration data from .ini file --- src/kernel/config.c | 34 ++++++++++++++++++++++++++++++++++ src/kernel/config.h | 1 + src/main.c | 1 + 3 files changed, 36 insertions(+) diff --git a/src/kernel/config.c b/src/kernel/config.c index d369d0ecd..0e1f159eb 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -712,6 +712,40 @@ bool config_changed(int *cache_key) { return false; } +#define MAXKEYS 16 +void config_set_from(const dictionary *d) +{ + int s, nsec = iniparser_getnsec(d); + for (s=0;s!=nsec;++s) { + char key[128]; + const char *sec = iniparser_getsecname(d, s); + int k, nkeys = iniparser_getsecnkeys(d, sec); + const char *akeys[MAXKEYS]; + const char ** keys = akeys; + size_t slen = strlen(sec); + assert(slenMAXKEYS) { + keys = malloc(sizeof(const char *) * nkeys); + } + iniparser_getseckeys(d, sec, keys); + for (k=0;k!=nkeys;++k) { + const char *val; + size_t klen = strlen(keys[k]); + assert(klen+slen+1 Date: Sat, 21 Jan 2017 19:53:47 +0100 Subject: [PATCH 108/271] issue #629: fix eressea.ini config fixed reading of ini data into config (keys have a . here, not a :). added a test. removed obsolete global.inifile variable. --- src/bindings.c | 10 +++++----- src/bindings.h | 6 +++--- src/kernel/config.c | 10 +++++----- src/kernel/config.h | 5 +++-- src/kernel/config.test.c | 17 +++++++++++++++++ src/main.c | 17 ++++++++--------- 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 13b562af6..99155613a 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -978,7 +978,7 @@ static int tolua_report_unit(lua_State * L) return 1; } -static void parse_inifile(lua_State * L, dictionary * d, const char *section) +static void parse_inifile(lua_State * L, const dictionary * d, const char *section) { int i; const char *arg; @@ -1018,7 +1018,7 @@ static void parse_inifile(lua_State * L, dictionary * d, const char *section) void tolua_bind_open(lua_State * L); -int tolua_bindings_open(lua_State * L) +int tolua_bindings_open(lua_State * L, const dictionary *inifile) { tolua_open(L); @@ -1072,7 +1072,7 @@ int tolua_bindings_open(lua_State * L) tolua_module(L, TOLUA_CAST "config", 1); tolua_beginmodule(L, TOLUA_CAST "config"); { - parse_inifile(L, global.inifile, "lua"); + parse_inifile(L, inifile, "lua"); tolua_variable(L, TOLUA_CAST "locales", &config_get_locales, 0); tolua_function(L, TOLUA_CAST "get_resource", &config_get_resource); tolua_variable(L, TOLUA_CAST "buildings", &config_get_buildings, 0); @@ -1142,12 +1142,12 @@ void lua_done(lua_State * L) { lua_close(L); } -lua_State *lua_init(void) { +lua_State *lua_init(const dictionary *inifile) { lua_State *L = luaL_newstate(); openlibs(L); register_tolua_helpers(); - tolua_bindings_open(L); + tolua_bindings_open(L, inifile); tolua_eressea_open(L); #ifdef USE_SQLITE tolua_sqlite_open(L); diff --git a/src/bindings.h b/src/bindings.h index 8eda1178b..b4523e582 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -16,10 +16,10 @@ extern "C" { struct lua_State; struct selist; + struct _dictionary_; int tolua_sqlite_open(struct lua_State *L); - int tolua_bindings_open(struct lua_State *L); - int tolua_spelllist_next(struct lua_State *L); + int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); int tolua_selist_push(struct lua_State *L, const char *list_type, @@ -28,7 +28,7 @@ extern "C" { int log_lua_error(struct lua_State *L); void lua_done(struct lua_State *L); - struct lua_State *lua_init(void); + struct lua_State *lua_init(const struct _dictionary_ *d); int eressea_run(struct lua_State *L, const char *luafile); #ifdef __cplusplus diff --git a/src/kernel/config.c b/src/kernel/config.c index 0e1f159eb..d05c29d1b 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -720,12 +720,12 @@ void config_set_from(const dictionary *d) char key[128]; const char *sec = iniparser_getsecname(d, s); int k, nkeys = iniparser_getsecnkeys(d, sec); - const char *akeys[MAXKEYS]; - const char ** keys = akeys; + char *akeys[MAXKEYS]; + char ** keys = akeys; size_t slen = strlen(sec); assert(slenMAXKEYS) { keys = malloc(sizeof(const char *) * nkeys); } @@ -734,8 +734,8 @@ void config_set_from(const dictionary *d) const char *val; size_t klen = strlen(keys[k]); assert(klen+slen+1 #include #include "types.h" -struct param; + + struct param; + struct _dictionary_; #define DISPLAYSIZE 8192 /* max. L�nge einer Beschreibung, incl trailing 0 */ #define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */ @@ -108,7 +110,6 @@ struct param; struct attrib *attribs; unsigned int data_turn; void *vm_state; - struct _dictionary_ *inifile; struct global_functions { int(*wage) (const struct region * r, const struct faction * f, const struct race * rc, int in_turn); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index 405587443..719ff840e 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -233,9 +235,24 @@ static void test_rules(CuTest *tc) { CuAssertIntEquals(tc, 1000, rule_faction_limit()); } +static void test_config_inifile(CuTest *tc) { + dictionary *ini; + test_setup(); + ini = dictionary_new(0); + dictionary_set(ini, "game", NULL); + iniparser_set(ini, "game:id", "42"); + iniparser_set(ini, "game:name", "Eressea"); + config_set_from(ini); + CuAssertStrEquals(tc, "Eressea", config_get("game.name")); + CuAssertIntEquals(tc, 42, game_id()); + iniparser_freedict(ini); + test_cleanup(); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_config_inifile); SUITE_ADD_TEST(suite, test_config_cache); SUITE_ADD_TEST(suite, test_get_set_param); SUITE_ADD_TEST(suite, test_param_int); diff --git a/src/main.c b/src/main.c index 97c84dffe..777770f0a 100644 --- a/src/main.c +++ b/src/main.c @@ -72,12 +72,9 @@ static void load_inifile(dictionary * d) verbosity = iniparser_getint(d, "game:verbose", 2); str = iniparser_getstring(d, "game:locales", "de,en"); make_locales(str); - - if (global.inifile) iniparser_freedict(global.inifile); - global.inifile = d; } -static void parse_config(const char *filename) +static dictionary *parse_config(const char *filename) { dictionary *d = iniparser_load(filename); if (d) { @@ -92,6 +89,7 @@ static void parse_config(const char *filename) gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage); #endif } + return d; } static int usage(const char *prog, const char *arg) @@ -272,10 +270,11 @@ int main(int argc, char **argv) { int err = 0; lua_State *L; + dictionary *d; setup_signal_handler(); /* ini file sets defaults for arguments*/ - parse_config(inifile); - if (!global.inifile) { + d = parse_config(inifile); + if (!d) { log_error("could not open ini configuration %s\n", inifile); } /* parse arguments again, to override ini file */ @@ -283,7 +282,7 @@ int main(int argc, char **argv) locale_init(); - L = lua_init(); + L = lua_init(d); game_init(); bind_monsters(L); err = eressea_run(L, luafile); @@ -294,8 +293,8 @@ int main(int argc, char **argv) game_done(); lua_done(L); log_close(); - if (global.inifile) { - iniparser_freedict(global.inifile); + if (d) { + iniparser_freedict(d); } return 0; } From dbc6a17e66d38f11f8acce5d153ac054e603aec8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 20:39:46 +0100 Subject: [PATCH 109/271] fix gcc build, introduce a hard limit on ini section size --- src/kernel/config.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index d05c29d1b..57874f118 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -720,15 +720,12 @@ void config_set_from(const dictionary *d) char key[128]; const char *sec = iniparser_getsecname(d, s); int k, nkeys = iniparser_getsecnkeys(d, sec); - char *akeys[MAXKEYS]; - char ** keys = akeys; + const char *keys[MAXKEYS]; size_t slen = strlen(sec); + assert(nkeys <= MAXKEYS); assert(slenMAXKEYS) { - keys = malloc(sizeof(const char *) * nkeys); - } iniparser_getseckeys(d, sec, keys); for (k=0;k!=nkeys;++k) { const char *val; @@ -740,9 +737,6 @@ void config_set_from(const dictionary *d) config_set(key, val); } } - if (keys!=akeys) { - free(keys); - } } } From 82193864c54efbf31eadbc481e8590defb51ed12 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 20:51:08 +0100 Subject: [PATCH 110/271] fix valgrind error. I did not understand what keys look like, then effed up when fixing that. --- src/kernel/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 57874f118..a07c36aba 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -731,7 +731,7 @@ void config_set_from(const dictionary *d) const char *val; size_t klen = strlen(keys[k]); assert(klen+slen+1 Date: Sat, 21 Jan 2017 20:59:16 +0100 Subject: [PATCH 111/271] config.json settings shall not override eressea.ini --- src/kernel/jsonconf.c | 4 +++- src/kernel/jsonconf.test.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 414704309..03e210ce0 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -806,7 +806,9 @@ static void json_settings(cJSON *json) { else { sprintf(value, "%d", child->valueint); } - config_set(child->string, value); + if (config_get(child->string) == NULL) { + config_set(child->string, value); + } } } } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 950868046..93fcd8d10 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -69,12 +69,15 @@ static void test_settings(CuTest * tc) "\"string\" : \"1d4\"," "\"integer\" : 14," "\"true\": true," + "\"game.id\": 4," "\"false\": false," "\"float\" : 1.5 }}"; cJSON *json = cJSON_Parse(data); test_cleanup(); + config_set("game.id", "42"); // should not be replaced json_config(json); + CuAssertStrEquals(tc, "42", config_get("game.id")); CuAssertStrEquals(tc, "1", config_get("true")); CuAssertStrEquals(tc, "0", config_get("false")); CuAssertStrEquals(tc, "1d4", config_get("string")); From a6dd02c11198356b0b03f4a1ea2a21d8412d5b51 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 21 Jan 2017 21:03:48 +0100 Subject: [PATCH 112/271] add game id to eressea.ini --- s/setup | 1 + 1 file changed, 1 insertion(+) diff --git a/s/setup b/s/setup index d8ffa74ad..848175ddc 100755 --- a/s/setup +++ b/s/setup @@ -96,6 +96,7 @@ touch eressea.ini ini_start ini_sec game ini_add game locales de,en +ini_add id $game ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit From 39375e8d4a0dba73618144bf611539f774ab20dd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 04:46:36 +0100 Subject: [PATCH 113/271] use the email address from eressea.ini in CR mailto --- conf/e2/config.xml | 4 ---- conf/e3/config.xml | 4 ---- conf/e4/config.xml | 4 ---- src/creport.c | 7 +++++-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 0441a46f6..9e32218da 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -53,10 +53,6 @@ - - eressea-server@eressea.kn-bremen.de - eressea-server@eressea.kn-bremen.de - Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 2 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. diff --git a/conf/e3/config.xml b/conf/e3/config.xml index c8c5dbb06..6a5b18b84 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -45,10 +45,6 @@ - - eressea-server@eressea.kn-bremen.de - eressea-server@eressea.kn-bremen.de - Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 3 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. diff --git a/conf/e4/config.xml b/conf/e4/config.xml index b188f7d79..3209c8eed 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -46,10 +46,6 @@ - - eressea-server@eressea.kn-bremen.de - eressea-server@eressea.kn-bremen.de - Bitte denke daran, deine Befehle mit dem Betreff ERESSEA 4 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. diff --git a/src/creport.c b/src/creport.c index 5e01433d4..fc944779f 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1475,7 +1475,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) faction *f = ctx->f; const char *prefix; region *r; - const char *mailto = LOC(f->locale, "mailto"); + const char *mailto = config_get("game.email"); const attrib *a; FILE *F = fopen(filename, "w"); static const race *rc_human; @@ -1510,8 +1510,11 @@ report_computer(const char *filename, report_context * ctx, const char *bom) fprintf(F, "%d;Zeitalter\n", era); fprintf(F, "\"%s\";Build\n", eressea_version()); if (mailto != NULL) { + // char mailcmd[64]; + // snprintf(mailcmd, sizeof(mailcmd), "%s %d, %s", game_name(), game_id(), LOC(f->locale, "mailcmd")); + const char * mailcmd = LOC(f->locale, "mailcmd"); fprintf(F, "\"%s\";mailto\n", mailto); - fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd")); + fprintf(F, "\"%s\";mailcmd\n", mailcmd); } show_alliances_cr(F, f); From 0496c660287cb6a9bb3db80c4d70d084142012f4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 04:55:19 +0100 Subject: [PATCH 114/271] use FACTION in text template, not ERESSEA --- src/report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/report.c b/src/report.c index 503f12732..bbbdb2fb6 100644 --- a/src/report.c +++ b/src/report.c @@ -1408,7 +1408,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) newline(out); newline(out); - sprintf(buf, "%s %s \"password\"", LOC(f->locale, "ERESSEA"), itoa36(f->no)); + sprintf(buf, "%s %s \"password\"", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no)); rps_nowrap(out, buf); newline(out); newline(out); From 847cfb54258356f4f9cb778f7677173a1ff72db3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 05:13:44 +0100 Subject: [PATCH 115/271] game.start in eressea.ini overrides calendar --- s/setup | 3 ++- src/bindings.c | 2 +- src/calendar.c | 9 +++++++-- src/calendar.h | 6 +++--- src/kernel/xmlreader.c | 7 ++++++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/s/setup b/s/setup index 848175ddc..e3e8e113d 100755 --- a/s/setup +++ b/s/setup @@ -96,7 +96,8 @@ touch eressea.ini ini_start ini_sec game ini_add game locales de,en -ini_add id $game +ini_add game id $game +ini_add game start 1 ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit diff --git a/src/bindings.c b/src/bindings.c index 99155613a..576c54939 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -948,7 +948,7 @@ static int init_data(const char *filename, const char *catalog) return l; } if (turn < 0) { - turn = first_turn; + turn = first_turn(); } return 0; } diff --git a/src/calendar.c b/src/calendar.c index 7a27328a7..2099b6631 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1,10 +1,10 @@ #include #include "calendar.h" +#include #include #include -int first_turn = 0; int first_month = 0; int weeks_per_month = 4; int months_per_year = 12; @@ -16,10 +16,15 @@ int *month_season = NULL; char *agename = NULL; int seasons = 0; +int first_turn(void) +{ + return config_get_int("game.start", 1); +} + const gamedate *get_gamedate(int turn, gamedate * gd) { int weeks_per_year = months_per_year * weeks_per_month; - int t = turn - first_turn; + int t = turn - first_turn(); assert(gd); if (t < 0) diff --git a/src/calendar.h b/src/calendar.h index 86f665c1a..d398cd77c 100644 --- a/src/calendar.h +++ b/src/calendar.h @@ -13,7 +13,6 @@ extern "C" { }; extern char *agename; - extern int first_turn; extern int first_month; extern int seasons; @@ -35,8 +34,9 @@ extern "C" { int week; } gamedate; - extern const gamedate *get_gamedate(int turn, gamedate * gd); - extern void calendar_cleanup(void); +const gamedate *get_gamedate(int turn, gamedate * gd); +void calendar_cleanup(void); +int first_turn(void); #ifdef __cplusplus } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2f38cdab3..2ba9d785a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -375,8 +375,13 @@ static int parse_calendar(xmlDocPtr doc) xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons; xmlChar *propValue = xmlGetProp(calendar, BAD_CAST "name"); xmlChar *newyear = xmlGetProp(calendar, BAD_CAST "newyear"); + xmlChar *start; - first_turn = xml_ivalue(calendar, "start", first_turn); + start = xmlGetProp(calendar, BAD_CAST "start"); + if (start && config_get("game.start")==NULL) { + config_set("game.start", (const char *)start); + xmlFree(start); + } if (propValue) { free(agename); agename = strdup(mkname("calendar", (const char *)propValue)); From d3d72d17e8a708839b87af6a0d718d86ccf429f9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 08:03:12 +0100 Subject: [PATCH 116/271] no starting equipment. do not let the addplayer function give equipment. rename equipment for autoseed. --- conf/e2/config.xml | 2 +- conf/e3/config.xml | 8 -------- conf/e4/config.xml | 9 --------- res/eressea/equipment.xml | 22 +++++++++++----------- scripts/eressea/autoseed.lua | 6 +++--- src/kernel/faction.c | 6 ------ 6 files changed, 15 insertions(+), 38 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 9e32218da..5affea141 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -42,7 +42,7 @@ - + diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 6a5b18b84..35716f332 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -28,14 +28,6 @@ - - - - - - - - diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 3209c8eed..ac962202c 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -27,15 +27,6 @@ - - - - - - - - - diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml index bf7e38376..efd4f2a3b 100644 --- a/res/eressea/equipment.xml +++ b/res/eressea/equipment.xml @@ -2,18 +2,18 @@ - + - + - + @@ -21,30 +21,30 @@ - + - + - + - + - + - + @@ -58,12 +58,12 @@ - + - + diff --git a/scripts/eressea/autoseed.lua b/scripts/eressea/autoseed.lua index 562c39361..822725804 100644 --- a/scripts/eressea/autoseed.lua +++ b/scripts/eressea/autoseed.lua @@ -64,9 +64,9 @@ local function seed(r, email, race, lang) assert(f) local u = unit.create(f, r) assert(u) - equip_unit(u, "new_faction") - equip_unit(u, "first_unit") - equip_unit(u, "first_" .. race, 7) -- disable old callbacks + equip_unit(u, "autoseed_faction") + equip_unit(u, "autoseed_unit") + equip_unit(u, "autoseed_" .. race, 7) unit.create(f, r, 5):set_skill("mining", 30) unit.create(f, r, 5):set_skill("quarrying", 30) f:set_origin(r) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 811321f14..b0aa83efd 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alliance.h" #include "ally.h" #include "curse.h" -#include "equipment.h" #include "group.h" #include "item.h" #include "messages.h" @@ -286,15 +285,10 @@ faction *addfaction(const char *email, const char *password, unit *addplayer(region * r, faction * f) { unit *u; - char buffer[32]; assert(f->units == NULL); faction_setorigin(f, 0, r->x, r->y); u = create_unit(r, f, 1, f->race, 0, NULL, NULL); - equip_items(&u->faction->items, get_equipment("new_faction")); - equip_unit(u, get_equipment("first_unit")); - sprintf(buffer, "first_%s", u_race(u)->_name); - equip_unit(u, get_equipment(buffer)); u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { From d4a81ebd736c38fc7b6cf5ac7f99348e1b30b8dc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 11:38:01 +0100 Subject: [PATCH 117/271] make these modules optional --- scripts/eressea/autoseed.lua | 1 + scripts/eressea/embassy.lua | 8 +++++--- scripts/eressea/eternath.lua | 2 +- scripts/eressea/ponnuki.lua | 1 + scripts/eressea/wedding.lua | 1 + scripts/eressea/xmas.lua | 2 ++ 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/eressea/autoseed.lua b/scripts/eressea/autoseed.lua index 822725804..9e5060f85 100644 --- a/scripts/eressea/autoseed.lua +++ b/scripts/eressea/autoseed.lua @@ -1,3 +1,4 @@ +if not config.autoseed then return nil end local autoseed = {} -- minimum required resources in the 7-hex neighborhood: diff --git a/scripts/eressea/embassy.lua b/scripts/eressea/embassy.lua index efbe248b7..82bce62c2 100644 --- a/scripts/eressea/embassy.lua +++ b/scripts/eressea/embassy.lua @@ -1,8 +1,5 @@ -- Muschelplateau -local embassy = {} -local home = nil - -- global exports (use item) function use_seashell(u, amount) -- Muschelplateau... @@ -17,6 +14,11 @@ function use_seashell(u, amount) return -4 end +if not config.embassy then return nil end + +local embassy = {} +local home = nil + function embassy.init() home = get_region(165,30) if home==nil then diff --git a/scripts/eressea/eternath.lua b/scripts/eressea/eternath.lua index 858a8d462..063577b74 100644 --- a/scripts/eressea/eternath.lua +++ b/scripts/eressea/eternath.lua @@ -1,5 +1,5 @@ -- DEPRECATED - +if not config.eternath then return nil end -- implements parts of a quest in E2 -- this module is deprecated, because it puts functions in the global environment for at_building_action diff --git a/scripts/eressea/ponnuki.lua b/scripts/eressea/ponnuki.lua index 994a16ff0..96bb0b5f1 100644 --- a/scripts/eressea/ponnuki.lua +++ b/scripts/eressea/ponnuki.lua @@ -1,3 +1,4 @@ +if not config.ponnuki then return nil end local ponnuki = {} local directions = { "NW", "NO", "O", "SO", "SW", "W" } diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua index 812bd3269..2c06d9891 100644 --- a/scripts/eressea/wedding.lua +++ b/scripts/eressea/wedding.lua @@ -1,4 +1,5 @@ -- DEPRECATED +if not config.wedding then return nil end -- this script contains the action functions for the two portals -- used on the jadee/wildente wedding island. the two _action functions diff --git a/scripts/eressea/xmas.lua b/scripts/eressea/xmas.lua index 36e755f45..0316e6265 100644 --- a/scripts/eressea/xmas.lua +++ b/scripts/eressea/xmas.lua @@ -1,3 +1,5 @@ +if not config.xmas then return nil end + local gifts = { e2 = { { year = 2015, turn = 959, item = 'snowglobe', msg='santa_f' }, From 48ae12b629e42caffadd21a2cd88387d221b4feb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:38:41 +0100 Subject: [PATCH 118/271] emit a password message for newbie factions --- src/kernel/faction.c | 1 + src/kernel/faction.h | 5 +++-- src/laws.c | 1 + src/reports.c | 8 ++++++++ src/reports.test.c | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b0aa83efd..146ae06a4 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -249,6 +249,7 @@ faction *addfaction(const char *email, const char *password, if (!password) password = itoa36(rng_int()); faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); + f->flags |= FFL_PWMSG; f->alliance_joindate = turn; f->lastorders = turn; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 757449bd8..1bab9101c 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -38,10 +38,11 @@ extern "C" { extern struct attrib_type at_maxmagicians; /* faction flags */ -#define FFL_NEWID (1<<0) /* Die Partei hat bereits einmal ihre no gewechselt */ +#define FFL_NEWID (1<<0) // Die Partei hat bereits einmal ihre no gewechselt #define FFL_ISNEW (1<<1) +#define FFL_PWMSG (1<<2) // received a "new password" message #define FFL_QUIT (1<<3) -#define FFL_CURSED (1<<4) /* you're going to have a bad time */ +#define FFL_CURSED (1<<4) // you're going to have a bad time #define FFL_DEFENDER (1<<10) #define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */ #define FFL_NOAID (1<<21) /* Hilfsflag Kampf */ diff --git a/src/laws.c b/src/laws.c index bbf1a200b..d6e005ff8 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2214,6 +2214,7 @@ int password_cmd(unit * u, struct order *ord) faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT)); ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf)); + u->faction->flags |= FFL_PWMSG; return 0; } diff --git a/src/reports.c b/src/reports.c index 395547734..77682a23a 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1335,6 +1335,14 @@ void prepare_report(report_context *ctx, faction *f) rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name); } + if (f->age<=2) { + if ((f->flags&FFL_PWMSG)==0) { + // TODO: this assumes unencrypted passwords + f->flags |= FFL_PWMSG; + ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->_password)); + } + } + ctx->f = f; ctx->report_time = time(NULL); ctx->addresses = NULL; diff --git a/src/reports.test.c b/src/reports.test.c index 1794f1cff..18ce468bb 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -226,6 +226,23 @@ static void test_arg_resources(CuTest *tc) { test_cleanup(); } +static void test_newbie_password_message(CuTest *tc) { + report_context ctx; + faction *f; + test_setup(); + f = test_create_faction(0); + f->age = 5; + CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + prepare_report(&ctx, f); + CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd")); + f->age=2; + prepare_report(&ctx, f); + CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd")); + test_cleanup(); +} + static void test_prepare_travelthru(CuTest *tc) { report_context ctx; faction *f, *f2; @@ -465,6 +482,7 @@ static void test_seen_travelthru(CuTest *tc) { CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_newbie_password_message); SUITE_ADD_TEST(suite, test_prepare_report); SUITE_ADD_TEST(suite, test_seen_neighbours); SUITE_ADD_TEST(suite, test_seen_travelthru); From 6e515702296f60fc13a9888ff92d784ca0d98235 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:43:48 +0100 Subject: [PATCH 119/271] remove ERESSEA keyword from "bad password" message. --- res/core/messages.xml | 5 ++--- src/kernel/save.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 41569d9f3..130b58d03 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3306,11 +3306,10 @@ - - "ERESSEA $int36($faction) \"${password}\" - Deine Befehle hatten ein falsches Passwort." - "ERESSEA $int36($faction) \"${password}\" - Your orders had the wrong password." + "Deine Befehle hatten ein falsches Passwort (${password})." + "Your orders had the wrong password (${password})." diff --git a/src/kernel/save.c b/src/kernel/save.c index bbbd77fd1..84914127a 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -235,8 +235,7 @@ static faction *factionorders(void) if (!checkpasswd(f, (const char *)pass)) { log_debug("Invalid password for faction %s", itoa36(fid)); - ADDMSG(&f->msgs, msg_message("wrongpasswd", "faction password", - f->no, pass)); + ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", pass)); return 0; } /* Die Partei hat sich zumindest gemeldet, so dass sie noch From 59916d1d5c57c58f0ef53ca418a3720ea96c8bea Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:51:32 +0100 Subject: [PATCH 120/271] remove sqlite3 code and dependency --- CMakeLists.txt | 1 - process/sendreport.sh | 6 -- src/CMakeLists.txt | 12 --- src/bind_sqlite.c | 95 ------------------- src/bindings.c | 3 - src/bindings.h | 1 - src/sqlite.c | 207 ------------------------------------------ 7 files changed, 325 deletions(-) delete mode 100644 src/bind_sqlite.c delete mode 100644 src/sqlite.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fd15f201..5cf75771b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ project (eressea-server C) enable_testing() find_package (LibXml2) -find_package (SQLite3) find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) diff --git a/process/sendreport.sh b/process/sendreport.sh index 93d52f0b4..81d16813c 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -39,9 +39,3 @@ fi source ${FACTION}.sh $EMAIL || reply "Unbekannte Partei $FACTION" -if [ -e $ERESSEA/game-$GAME/eressea.db ]; then - SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)" - OWNER=$(sqlite3 $ERESSEA/game-$GAME/eressea.db "$SQL") - echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ - | mutt -s "Reportnachforderung Partei ${FACTION}" $OWNER -fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39d290560..2545115fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,13 +155,6 @@ set(SERVER_SRC bind_unit.c ) -if (SQLITE3_FOUND) -set (SERVER_SRC ${SERVER_SRC} - sqlite.c - bind_sqlite.c -) -endif (SQLITE3_FOUND) - if (CURSES_FOUND) set (SERVER_SRC ${SERVER_SRC} gmtool.c @@ -251,11 +244,6 @@ add_test(server test_eressea) install(TARGETS eressea DESTINATION "bin") -if (SQLITE3_FOUND) -target_link_libraries(eressea ${SQLITE3_LIBRARIES}) -add_definitions(-DUSE_SQLITE) -endif(SQLITE3_FOUND) - if (CURSES_FOUND) include_directories (${CURSES_INCLUDE_DIR}) target_link_libraries(eressea ${CURSES_LIBRARIES}) diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c deleted file mode 100644 index e8c9b7565..000000000 --- a/src/bind_sqlite.c +++ /dev/null @@ -1,95 +0,0 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ - -#include - -#include "bind_unit.h" -#include "bindings.h" - -#include -#include -#include - -#define LTYPE_DB TOLUA_CAST "db" - -extern int db_update_factions(sqlite3 * db, bool force, int game); -static int tolua_db_update_factions(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - db_update_factions(db, tolua_toboolean(L, 2, 0), game_id()); - return 0; -} - -extern int db_update_scores(sqlite3 * db, bool force); -static int tolua_db_update_scores(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - db_update_scores(db, tolua_toboolean(L, 2, 0)); - return 0; -} - -static int tolua_db_execute(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - const char *sql = tolua_tostring(L, 2, 0); - - int res = sqlite3_exec(db, sql, 0, 0, 0); - - lua_pushinteger(L, res); - return 1; -} - -static int tolua_db_close(lua_State * L) -{ - sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); - sqlite3_close(db); - return 0; -} - -static int tolua_db_create(lua_State * L) -{ - sqlite3 *db; - const char *dbname = tolua_tostring(L, 1, 0); - int result = sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE, 0); - if (result == SQLITE_OK) { - tolua_pushusertype(L, (void *)db, LTYPE_DB); - return 1; - } - return 0; -} - -int tolua_sqlite_open(lua_State * L) -{ - /* register user types */ - - tolua_usertype(L, LTYPE_DB); - - tolua_module(L, NULL, 0); - tolua_beginmodule(L, NULL); - { - tolua_cclass(L, LTYPE_DB, LTYPE_DB, TOLUA_CAST "", NULL); - tolua_beginmodule(L, LTYPE_DB); - { - tolua_function(L, TOLUA_CAST "open", &tolua_db_create); - tolua_function(L, TOLUA_CAST "close", &tolua_db_close); - - tolua_function(L, TOLUA_CAST "update_factions", - &tolua_db_update_factions); - tolua_function(L, TOLUA_CAST "update_scores", &tolua_db_update_scores); - tolua_function(L, TOLUA_CAST "execute", &tolua_db_execute); - } - tolua_endmodule(L); - - } - tolua_endmodule(L); - return 0; -} diff --git a/src/bindings.c b/src/bindings.c index 576c54939..936d588e5 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1149,9 +1149,6 @@ lua_State *lua_init(const dictionary *inifile) { register_tolua_helpers(); tolua_bindings_open(L, inifile); tolua_eressea_open(L); -#ifdef USE_SQLITE - tolua_sqlite_open(L); -#endif tolua_unit_open(L); tolua_building_open(L); tolua_ship_open(L); diff --git a/src/bindings.h b/src/bindings.h index b4523e582..6fa91741b 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -18,7 +18,6 @@ extern "C" { struct selist; struct _dictionary_; - int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); diff --git a/src/sqlite.c b/src/sqlite.c deleted file mode 100644 index 9379faa4f..000000000 --- a/src/sqlite.c +++ /dev/null @@ -1,207 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -faction *get_faction_by_id(int uid) -{ - faction *f; - for (f = factions; f; f = f->next) { - if (f->subscription == uid) { - return f; - } - } - return NULL; -} - -/* -typedef struct stmt_cache { -sqlite3 *db; -sqlite3_stmt *stmt; -const char *sql; -int inuse; -} stmt_cache; - -#define MAX_STMT_CACHE 64 -static stmt_cache cache[MAX_STMT_CACHE]; -static int cache_insert; - -static sqlite3_stmt *stmt_cache_get(sqlite3 * db, const char *sql) -{ -int i; -sqlite3_stmt *stmt; - -for (i = 0; i != MAX_STMT_CACHE && cache[i].db; ++i) { -if (cache[i].sql == sql && cache[i].db == db) { -cache[i].inuse = 1; -stmt = cache[i].stmt; -sqlite3_reset(stmt); -sqlite3_clear_bindings(stmt); -return stmt; -} -} -if (i == MAX_STMT_CACHE) { -while (cache[cache_insert].inuse) { -cache[cache_insert].inuse = 0; -cache_insert = (cache_insert + 1) & (MAX_STMT_CACHE - 1); -} -i = cache_insert; -stmt = cache[i].stmt; -sqlite3_finalize(stmt); -} -cache[i].inuse = 1; -cache[i].db = db; -cache[i].sql = sql; -sqlite3_prepare_v2(db, sql, -1, &cache[i].stmt, NULL); -return cache[i].stmt; -} -*/ -typedef struct db_faction { - int uid; - int no; - char *email; - char *name; -} db_faction; - -static struct selist * -read_factions(sqlite3 * db, int game_id) { - int res; - selist *result = 0; - const char * sql = - "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" - " LEFT OUTER JOIN faction_data fd" - " WHERE f.id=fd.faction_id AND f.game_id=? AND" - " fd.turn=(SELECT MAX(turn) FROM faction_data fx WHERE fx.faction_id=f.id)" - " ORDER BY f.id"; - sqlite3_stmt *stmt = 0; - sqlite3_prepare_v2(db, sql, -1, &stmt, 0); - sqlite3_bind_int(stmt, 1, game_id); - - res = sqlite3_step(stmt); - while (res == SQLITE_ROW) { - const char * text; - db_faction * dbf = (db_faction*)calloc(1, sizeof(db_faction)); - dbf->uid = (int)sqlite3_column_int64(stmt, 0); - text = (const char *)sqlite3_column_text(stmt, 1); - if (text) dbf->no = atoi36(text); - text = (const char *)sqlite3_column_text(stmt, 2); - if (text) dbf->name = strdup(text); - text = (const char *)sqlite3_column_text(stmt, 3); - if (text) dbf->email = strdup(text); - selist_push(&result, dbf); - res = sqlite3_step(stmt); - } - sqlite3_finalize(stmt); - return result; -} - -static int insert_faction(sqlite3 *db, int game_id, faction *f) { - const char *sql = "INSERT INTO faction (game_id, race) VALUES (?, ?)"; - sqlite3_stmt *stmt = 0; - sqlite3_prepare_v2(db, sql, -1, &stmt, 0); - sqlite3_bind_int(stmt, 1, game_id); - sqlite3_bind_text(stmt, 2, f->race->_name, -1, SQLITE_STATIC); - sqlite3_step(stmt); - sqlite3_finalize(stmt); - return (int)sqlite3_last_insert_rowid(db); -} - -static void update_faction(sqlite3 *db, const faction *f) { - char code[5]; - const char *sql = - "INSERT INTO faction_data (faction_id, code, name, email, lang, turn)" - " VALUES (?, ?, ?, ?, ?, ?)"; - sqlite3_stmt *stmt = 0; - strcpy(code, itoa36(f->no)); - sqlite3_prepare_v2(db, sql, -1, &stmt, 0); - sqlite3_bind_int(stmt, 1, f->subscription); - sqlite3_bind_text(stmt, 2, code, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 3, f->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 4, f->email, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 5, locale_name(f->locale), -1, SQLITE_STATIC); - sqlite3_bind_int(stmt, 6, turn); - sqlite3_step(stmt); - sqlite3_finalize(stmt); -} - -int db_update_factions(sqlite3 * db, bool force, int game_id) { - selist *ql = read_factions(db, game_id); - faction *f; - if (!ql) return SQLITE_OK; - sqlite3_exec(db, "BEGIN", 0, 0, 0); - for (f = factions; f; f = f->next) { - bool update = force; - db_faction *dbf = 0; -#ifdef SELIST_TODO - selist_iter it = qli_init(&ql); - while (qli_more(it)) { - db_faction *df = (db_faction*)qli_next(&it); - if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { - dbf = df; - } - if (f->subscription == df->uid) { - dbf = df; - break; - } - } -#endif - if (dbf) { - if (dbf->uid != f->subscription) { - log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); - f->subscription = dbf->uid; - } - update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); - } - else { - f->subscription = insert_faction(db, game_id, f); - log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); - update = true; - } - if (update) { - update_faction(db, f); - log_debug("faction %s updated\n", itoa36(f->no)); - } - } - sqlite3_exec(db, "COMMIT", 0, 0, 0); - return SQLITE_OK; -} - -int db_update_scores(sqlite3 * db, bool force) -{ - /* - const char *sselist_ins = - "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; - sqlite3_stmt *stmt_ins = stmt_cache_get(db, sselist_ins); - const char *sselist_upd = - "UPDATE score set value=? WHERE faction_id=? AND turn=?"; - sqlite3_stmt *stmt_upd = stmt_cache_get(db, sselist_upd); - faction *f; - sqlite3_exec(db, "BEGIN", 0, 0, 0); - for (f = factions; f; f = f->next) { - int res; - sqlite3_bind_int(stmt_ins, 1, f->score); - sqlite3_bind_int64(stmt_ins, 2, f->subscription); - sqlite3_bind_int(stmt_ins, 3, turn); - res = sqlite3_step(stmt_ins); - if (res == SQLITE_CONSTRAINT) { - sqlite3_bind_int(stmt_upd, 1, f->score); - sqlite3_bind_int64(stmt_upd, 2, f->subscription); - sqlite3_bind_int(stmt_upd, 3, turn); - res = sqlite3_step(stmt_upd); - sqlite3_reset(stmt_upd); - } - sqlite3_reset(stmt_ins); - } - sqlite3_exec(db, "COMMIT", 0, 0, 0); - */ - return SQLITE_OK; -} From f86d86d4c6758cec983cb3cf187c773396a97000 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:57:25 +0100 Subject: [PATCH 121/271] Revert "remove sqlite3 code and dependency" This reverts commit 7b55a57610b3e8d54ad2b1a6d6f8642ca9ae391f. --- CMakeLists.txt | 1 + process/sendreport.sh | 6 ++ src/CMakeLists.txt | 12 +++ src/bind_sqlite.c | 95 ++++++++++++++++++++ src/bindings.c | 3 + src/bindings.h | 1 + src/sqlite.c | 204 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 322 insertions(+) create mode 100644 src/bind_sqlite.c create mode 100644 src/sqlite.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cf75771b..8fd15f201 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ project (eressea-server C) enable_testing() find_package (LibXml2) +find_package (SQLite3) find_package (Curses) find_package (Lua REQUIRED) find_package (ToLua REQUIRED) diff --git a/process/sendreport.sh b/process/sendreport.sh index 81d16813c..93d52f0b4 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -39,3 +39,9 @@ fi source ${FACTION}.sh $EMAIL || reply "Unbekannte Partei $FACTION" +if [ -e $ERESSEA/game-$GAME/eressea.db ]; then + SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)" + OWNER=$(sqlite3 $ERESSEA/game-$GAME/eressea.db "$SQL") + echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ + | mutt -s "Reportnachforderung Partei ${FACTION}" $OWNER +fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2545115fc..39d290560 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,6 +155,13 @@ set(SERVER_SRC bind_unit.c ) +if (SQLITE3_FOUND) +set (SERVER_SRC ${SERVER_SRC} + sqlite.c + bind_sqlite.c +) +endif (SQLITE3_FOUND) + if (CURSES_FOUND) set (SERVER_SRC ${SERVER_SRC} gmtool.c @@ -244,6 +251,11 @@ add_test(server test_eressea) install(TARGETS eressea DESTINATION "bin") +if (SQLITE3_FOUND) +target_link_libraries(eressea ${SQLITE3_LIBRARIES}) +add_definitions(-DUSE_SQLITE) +endif(SQLITE3_FOUND) + if (CURSES_FOUND) include_directories (${CURSES_INCLUDE_DIR}) target_link_libraries(eressea ${CURSES_LIBRARIES}) diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c new file mode 100644 index 000000000..e8c9b7565 --- /dev/null +++ b/src/bind_sqlite.c @@ -0,0 +1,95 @@ +/* ++-------------------+ +| | Enno Rehling +| Eressea PBEM host | Christian Schlittchen +| (c) 1998 - 2008 | Katja Zedel +| | Henning Peters ++-------------------+ + +This program may not be used, modified or distributed +without prior permission by the authors of Eressea. +*/ + +#include + +#include "bind_unit.h" +#include "bindings.h" + +#include +#include +#include + +#define LTYPE_DB TOLUA_CAST "db" + +extern int db_update_factions(sqlite3 * db, bool force, int game); +static int tolua_db_update_factions(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + db_update_factions(db, tolua_toboolean(L, 2, 0), game_id()); + return 0; +} + +extern int db_update_scores(sqlite3 * db, bool force); +static int tolua_db_update_scores(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + db_update_scores(db, tolua_toboolean(L, 2, 0)); + return 0; +} + +static int tolua_db_execute(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + const char *sql = tolua_tostring(L, 2, 0); + + int res = sqlite3_exec(db, sql, 0, 0, 0); + + lua_pushinteger(L, res); + return 1; +} + +static int tolua_db_close(lua_State * L) +{ + sqlite3 *db = (sqlite3 *)tolua_tousertype(L, 1, 0); + sqlite3_close(db); + return 0; +} + +static int tolua_db_create(lua_State * L) +{ + sqlite3 *db; + const char *dbname = tolua_tostring(L, 1, 0); + int result = sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE, 0); + if (result == SQLITE_OK) { + tolua_pushusertype(L, (void *)db, LTYPE_DB); + return 1; + } + return 0; +} + +int tolua_sqlite_open(lua_State * L) +{ + /* register user types */ + + tolua_usertype(L, LTYPE_DB); + + tolua_module(L, NULL, 0); + tolua_beginmodule(L, NULL); + { + tolua_cclass(L, LTYPE_DB, LTYPE_DB, TOLUA_CAST "", NULL); + tolua_beginmodule(L, LTYPE_DB); + { + tolua_function(L, TOLUA_CAST "open", &tolua_db_create); + tolua_function(L, TOLUA_CAST "close", &tolua_db_close); + + tolua_function(L, TOLUA_CAST "update_factions", + &tolua_db_update_factions); + tolua_function(L, TOLUA_CAST "update_scores", &tolua_db_update_scores); + tolua_function(L, TOLUA_CAST "execute", &tolua_db_execute); + } + tolua_endmodule(L); + + } + tolua_endmodule(L); + return 0; +} diff --git a/src/bindings.c b/src/bindings.c index 936d588e5..576c54939 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1149,6 +1149,9 @@ lua_State *lua_init(const dictionary *inifile) { register_tolua_helpers(); tolua_bindings_open(L, inifile); tolua_eressea_open(L); +#ifdef USE_SQLITE + tolua_sqlite_open(L); +#endif tolua_unit_open(L); tolua_building_open(L); tolua_ship_open(L); diff --git a/src/bindings.h b/src/bindings.h index 6fa91741b..b4523e582 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -18,6 +18,7 @@ extern "C" { struct selist; struct _dictionary_; + int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); diff --git a/src/sqlite.c b/src/sqlite.c new file mode 100644 index 000000000..aea0f5d20 --- /dev/null +++ b/src/sqlite.c @@ -0,0 +1,204 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +faction *get_faction_by_id(int uid) +{ + faction *f; + for (f = factions; f; f = f->next) { + if (f->subscription == uid) { + return f; + } + } + return NULL; +} + +/* +typedef struct stmt_cache { +sqlite3 *db; +sqlite3_stmt *stmt; +const char *sql; +int inuse; +} stmt_cache; + +#define MAX_STMT_CACHE 64 +static stmt_cache cache[MAX_STMT_CACHE]; +static int cache_insert; + +static sqlite3_stmt *stmt_cache_get(sqlite3 * db, const char *sql) +{ +int i; +sqlite3_stmt *stmt; + +for (i = 0; i != MAX_STMT_CACHE && cache[i].db; ++i) { +if (cache[i].sql == sql && cache[i].db == db) { +cache[i].inuse = 1; +stmt = cache[i].stmt; +sqlite3_reset(stmt); +sqlite3_clear_bindings(stmt); +return stmt; +} +} +if (i == MAX_STMT_CACHE) { +while (cache[cache_insert].inuse) { +cache[cache_insert].inuse = 0; +cache_insert = (cache_insert + 1) & (MAX_STMT_CACHE - 1); +} +i = cache_insert; +stmt = cache[i].stmt; +sqlite3_finalize(stmt); +} +cache[i].inuse = 1; +cache[i].db = db; +cache[i].sql = sql; +sqlite3_prepare_v2(db, sql, -1, &cache[i].stmt, NULL); +return cache[i].stmt; +} +*/ +typedef struct db_faction { + int uid; + int no; + char *email; + char *name; +} db_faction; + +static struct quicklist * +read_factions(sqlite3 * db, int game_id) { + int res; + quicklist *result = 0; + const char * sql = + "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" + " LEFT OUTER JOIN faction_data fd" + " WHERE f.id=fd.faction_id AND f.game_id=? AND" + " fd.turn=(SELECT MAX(turn) FROM faction_data fx WHERE fx.faction_id=f.id)" + " ORDER BY f.id"; + sqlite3_stmt *stmt = 0; + sqlite3_prepare_v2(db, sql, -1, &stmt, 0); + sqlite3_bind_int(stmt, 1, game_id); + + res = sqlite3_step(stmt); + while (res == SQLITE_ROW) { + const char * text; + db_faction * dbf = (db_faction*)calloc(1, sizeof(db_faction)); + dbf->uid = (int)sqlite3_column_int64(stmt, 0); + text = (const char *)sqlite3_column_text(stmt, 1); + if (text) dbf->no = atoi36(text); + text = (const char *)sqlite3_column_text(stmt, 2); + if (text) dbf->name = strdup(text); + text = (const char *)sqlite3_column_text(stmt, 3); + if (text) dbf->email = strdup(text); + ql_push(&result, dbf); + res = sqlite3_step(stmt); + } + sqlite3_finalize(stmt); + return result; +} + +static int insert_faction(sqlite3 *db, int game_id, faction *f) { + const char *sql = "INSERT INTO faction (game_id, race) VALUES (?, ?)"; + sqlite3_stmt *stmt = 0; + sqlite3_prepare_v2(db, sql, -1, &stmt, 0); + sqlite3_bind_int(stmt, 1, game_id); + sqlite3_bind_text(stmt, 2, f->race->_name, -1, SQLITE_STATIC); + sqlite3_step(stmt); + sqlite3_finalize(stmt); + return (int)sqlite3_last_insert_rowid(db); +} + +static void update_faction(sqlite3 *db, const faction *f) { + char code[5]; + const char *sql = + "INSERT INTO faction_data (faction_id, code, name, email, lang, turn)" + " VALUES (?, ?, ?, ?, ?, ?)"; + sqlite3_stmt *stmt = 0; + strcpy(code, itoa36(f->no)); + sqlite3_prepare_v2(db, sql, -1, &stmt, 0); + sqlite3_bind_int(stmt, 1, f->subscription); + sqlite3_bind_text(stmt, 2, code, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 3, f->name, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 4, f->email, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 5, locale_name(f->locale), -1, SQLITE_STATIC); + sqlite3_bind_int(stmt, 6, turn); + sqlite3_step(stmt); + sqlite3_finalize(stmt); +} + +int db_update_factions(sqlite3 * db, bool force, int game_id) { + quicklist *ql = read_factions(db, game_id); + faction *f; + sqlite3_exec(db, "BEGIN", 0, 0, 0); + for (f = factions; f; f = f->next) { + bool update = force; + db_faction *dbf = 0; + ql_iter it = qli_init(&ql); + while (qli_more(it)) { + db_faction *df = (db_faction*)qli_next(&it); + if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { + dbf = df; + } + if (f->subscription == df->uid) { + dbf = df; + break; + } + } + if (dbf) { + if (dbf->uid != f->subscription) { + log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); + f->subscription = dbf->uid; + } + update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); + } + else { + f->subscription = insert_faction(db, game_id, f); + log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); + update = true; + } + if (update) { + update_faction(db, f); + log_debug("faction %s updated\n", itoa36(f->no)); + } + } + sqlite3_exec(db, "COMMIT", 0, 0, 0); + return SQLITE_OK; +} + +int db_update_scores(sqlite3 * db, bool force) +{ + /* + const char *sql_ins = + "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; + sqlite3_stmt *stmt_ins = stmt_cache_get(db, sql_ins); + const char *sql_upd = + "UPDATE score set value=? WHERE faction_id=? AND turn=?"; + sqlite3_stmt *stmt_upd = stmt_cache_get(db, sql_upd); + faction *f; + sqlite3_exec(db, "BEGIN", 0, 0, 0); + for (f = factions; f; f = f->next) { + int res; + sqlite3_bind_int(stmt_ins, 1, f->score); + sqlite3_bind_int64(stmt_ins, 2, f->subscription); + sqlite3_bind_int(stmt_ins, 3, turn); + res = sqlite3_step(stmt_ins); + if (res == SQLITE_CONSTRAINT) { + sqlite3_bind_int(stmt_upd, 1, f->score); + sqlite3_bind_int64(stmt_upd, 2, f->subscription); + sqlite3_bind_int(stmt_upd, 3, turn); + res = sqlite3_step(stmt_upd); + sqlite3_reset(stmt_upd); + } + sqlite3_reset(stmt_ins); + } + sqlite3_exec(db, "COMMIT", 0, 0, 0); + */ + return SQLITE_OK; +} From abeb7e344e122a5f9f2a3c2ac4611db69ad560e7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 13:09:32 +0100 Subject: [PATCH 122/271] configure dbname in eressea.ini (or don't use DB if not --- scripts/run-turn.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 7ee9165ca..92efa8a14 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -26,15 +26,17 @@ function callbacks(rules, name, ...) end local function dbupdate() - update_scores() - dbname = config.dbname or 'eressea.db' - edb = db.open(config.basepath..'/'..dbname) - if edb~=nil then - edb:update_factions() - edb:update_scores() - else - eressea.log.error("could not open "..config.basepath..'/'..dbname) - end + update_scores() + if config.dbname then + dbname = config.basepath..'/'..config.dbname + edb = db.open(dbame) + if edb~=nil then + edb:update_factions() + edb:update_scores() + else + eressea.log.error("could not open "..dbname) + end + end end local function write_emails(locales) From f4e25fe20e625dc6b8cbf71b4e8ae8a7246785c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:01:09 +0100 Subject: [PATCH 123/271] try loading config.lua and custom.lua files, if they exist. --- src/bindings.c | 68 ++++++++++++++++++++++++++++++++--------------- src/kernel/save.h | 1 - 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 576c54939..e7c4859b4 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1168,32 +1168,56 @@ lua_State *lua_init(const dictionary *inifile) { return L; } +static int run_script(lua_State *L, const char *luafile) { + int err; + FILE *F; + + F = fopen(luafile, "r"); + if (!F) { + log_debug("dofile('%s'): %s", luafile, strerror(errno)); + return errno; + } + fclose(F); + + log_debug("executing script %s", luafile); + lua_getglobal(L, "dofile"); + lua_pushstring(L, luafile); + err = lua_pcall(L, 1, 1, -3); /* error handler (debug.traceback) is now at stack -3 */ + if (err != 0) { + log_lua_error(L); + assert(!"Lua syntax error? check log."); + } + else { + if (lua_isnumber(L, -1)) { + err = (int)lua_tonumber(L, -1); + } + lua_pop(L, 1); + } + return err; +} + int eressea_run(lua_State *L, const char *luafile) { - int err = 0; - + int err; global.vm_state = L; + + /* push an error handling function on the stack: */ + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + lua_remove(L, -2); + + /* try to run configuration scripts: */ + err = run_script(L, "config.lua"); + err = run_script(L, "custom.lua"); + /* run the main script */ if (luafile) { - log_debug("executing script %s\n", luafile); - - lua_getglobal(L, "debug"); - lua_getfield(L, -1, "traceback"); - lua_remove(L, -2); - lua_getglobal(L, "dofile"); - lua_pushstring(L, luafile); - err = lua_pcall(L, 1, 1, -3); - if (err != 0) { - log_lua_error(L); - assert(!"Lua syntax error? check log."); - } - else { - if (lua_isnumber(L, -1)) { - err = (int)lua_tonumber(L, -1); - } - lua_pop(L, 1); - } - return err; + err = run_script(L, luafile); } - return lua_console(L); + else { + err = lua_console(L); + } + /* pop error handler off the stack: */ + lua_pop(L, 1); + return err; } diff --git a/src/kernel/save.h b/src/kernel/save.h index be78b9c68..4ead34efe 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -44,7 +44,6 @@ extern "C" { extern int enc_gamedata; int readorders(const char *filename); - int creategame(void); int readgame(const char *filename); int writegame(const char *filename); From e7a41a20178831aed58a12841179b2d7ea6a49fd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:03:46 +0100 Subject: [PATCH 124/271] missing includE --- src/bindings.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bindings.c b/src/bindings.c index e7c4859b4..62d9064b4 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -80,6 +80,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #define TOLUA_PKG(NAME) extern void tolua_##NAME##_open(lua_State * L) From 64e45248dcb7ebac4b832a1a1dbec5a2ae7bd100 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:28:04 +0100 Subject: [PATCH 125/271] rename create_equipment function --- src/bindings.c | 6 +++--- src/kernel/equipment.c | 2 +- src/kernel/equipment.h | 2 +- src/kernel/equipment.test.c | 2 +- src/kernel/xmlreader.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 62d9064b4..7fb894ebb 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -83,7 +83,7 @@ without prior permission by the authors of Eressea. #include #include -#define TOLUA_PKG(NAME) extern void tolua_##NAME##_open(lua_State * L) +#define TOLUA_PKG(NAME) void tolua_##NAME##_open(lua_State * L) TOLUA_PKG(eressea); TOLUA_PKG(process); @@ -328,7 +328,7 @@ static int tolua_addequipment(lua_State * L) if (iname != NULL) { const struct item_type *itype = it_find(iname); if (itype != NULL) { - equipment_setitem(create_equipment(eqname), itype, value); + equipment_setitem(get_or_create_equipment(eqname), itype, value); result = 0; } } @@ -461,7 +461,7 @@ static int tolua_equipment_setitem(lua_State * L) if (iname != NULL) { const struct item_type *itype = it_find(iname); if (itype != NULL) { - equipment_setitem(create_equipment(eqname), itype, value); + equipment_setitem(get_or_create_equipment(eqname), itype, value); result = 0; } } diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 349a87448..00f8c2f95 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -39,7 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static equipment *equipment_sets; -equipment *create_equipment(const char *eqname) +equipment *get_or_create_equipment(const char *eqname) { equipment **eqp = &equipment_sets; for (;;) { diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 4081ab748..53475b510 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -56,7 +56,7 @@ extern "C" { void equipment_done(void); - struct equipment *create_equipment(const char *eqname); + struct equipment *get_or_create_equipment(const char *eqname); struct equipment *get_equipment(const char *eqname); void equipment_setitem(struct equipment *eq, diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index a82f86674..afd53849e 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -27,7 +27,7 @@ void test_equipment(CuTest * tc) CuAssertPtrNotNull(tc, sp); CuAssertPtrEquals(tc, 0, get_equipment("herpderp")); - eq = create_equipment("herpderp"); + eq = get_or_create_equipment("herpderp"); CuAssertPtrEquals(tc, eq, get_equipment("herpderp")); equipment_setitem(eq, it_horses, "1"); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2ba9d785a..cba01bc7b 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1266,7 +1266,7 @@ add_subsets(xmlDocPtr doc, equipment * eq, xmlNodeSetPtr nsetSubsets) assert(propValue != NULL); eq->subsets[i].sets[set].chance = chance; eq->subsets[i].sets[set].set = - create_equipment((const char *)propValue); + get_or_create_equipment((const char *)propValue); xmlFree(propValue); } } @@ -1296,7 +1296,7 @@ static int parse_equipment(xmlDocPtr doc) xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); if (propName != NULL) { - equipment *eq = create_equipment((const char *)propName); + equipment *eq = get_or_create_equipment((const char *)propName); xmlXPathObjectPtr xpathResult; xpath->node = node; From 76af048fed26d039c41f9794c91b0e3ecd429849 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:35:54 +0100 Subject: [PATCH 126/271] clean the quipment interface for lua a little bit. --- conf/e2/config.xml | 2 +- src/bindings.c | 18 ------------------ src/kernel/faction.c | 6 ++++++ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 5affea141..8389ba470 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -29,7 +29,7 @@ - + diff --git a/src/bindings.c b/src/bindings.c index 7fb894ebb..0986ffb37 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -319,23 +319,6 @@ static int tolua_dice_rand(lua_State * L) return 1; } -static int tolua_addequipment(lua_State * L) -{ - const char *eqname = tolua_tostring(L, 1, 0); - const char *iname = tolua_tostring(L, 2, 0); - const char *value = tolua_tostring(L, 3, 0); - int result = -1; - if (iname != NULL) { - const struct item_type *itype = it_find(iname); - if (itype != NULL) { - equipment_setitem(get_or_create_equipment(eqname), itype, value); - result = 0; - } - } - lua_pushinteger(L, result); - return 1; -} - static int tolua_get_season(lua_State * L) { int turnno = (int)tolua_tonumber(L, 1, 0); @@ -1112,7 +1095,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "get_season", tolua_get_season); tolua_function(L, TOLUA_CAST "equipment_setitem", tolua_equipment_setitem); tolua_function(L, TOLUA_CAST "equip_unit", tolua_equipunit); - tolua_function(L, TOLUA_CAST "add_equipment", tolua_addequipment); tolua_function(L, TOLUA_CAST "atoi36", tolua_atoi36); tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36); tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 146ae06a4..040cd5fb0 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alliance.h" #include "ally.h" #include "curse.h" +#include "equipment.h" #include "group.h" #include "item.h" #include "messages.h" @@ -286,10 +287,15 @@ faction *addfaction(const char *email, const char *password, unit *addplayer(region * r, faction * f) { unit *u; + const struct equipment* eq; assert(f->units == NULL); faction_setorigin(f, 0, r->x, r->y); u = create_unit(r, f, 1, f->race, 0, NULL, NULL); + eq = get_equipment("first_unit"); + if (eq) { + equip_items(&u->items, eq); + } u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { From 98be6bb8aeb5db1f7e63e524add0d491eb787ec8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:51:20 +0100 Subject: [PATCH 127/271] eliminate duplicate password message --- scripts/tests/faction.lua | 2 +- src/kernel/faction.c | 11 +++++------ src/kernel/faction.test.c | 2 +- src/reports.test.c | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index 38fdc4eb7..87a6b5100 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -17,7 +17,7 @@ function setup() end function test_faction_flags() - assert_equal(2, f.flags) -- FFL_ISNEW + assert_equal(6, f.flags) -- FFL_ISNEW|FFL_PWMSG f.flags = 42 assert_equal(42, f.flags) end diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 040cd5fb0..b7115c62f 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -247,11 +247,6 @@ faction *addfaction(const char *email, const char *password, log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email); } - if (!password) password = itoa36(rng_int()); - faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); - ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); - f->flags |= FFL_PWMSG; - f->alliance_joindate = turn; f->lastorders = turn; f->_alive = true; @@ -260,7 +255,11 @@ faction *addfaction(const char *email, const char *password, f->magiegebiet = 0; f->locale = loc; f->subscription = subscription; - f->flags = FFL_ISNEW; + f->flags = FFL_ISNEW|FFL_PWMSG; + + if (!password) password = itoa36(rng_int()); + faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); + ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); f->options = want(O_REPORT) | want(O_ZUGVORLAGE) | want(O_COMPUTER) | want(O_COMPRESS) | diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 3bfc36ca8..b18121e2d 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) { CuAssertTrue(tc, checkpasswd(f, "hurrdurr")); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); CuAssertIntEquals(tc, 1234, f->subscription); - CuAssertIntEquals(tc, FFL_ISNEW, f->flags); + CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags); CuAssertIntEquals(tc, 0, f->age); CuAssertTrue(tc, faction_alive(f)); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); diff --git a/src/reports.test.c b/src/reports.test.c index 18ce468bb..e3ca5c89b 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -232,7 +232,7 @@ static void test_newbie_password_message(CuTest *tc) { test_setup(); f = test_create_faction(0); f->age = 5; - CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + f->flags = 0; prepare_report(&ctx, f); CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd")); From 963713b1894049637979e61ac4563b96353561a8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 19:06:37 +0100 Subject: [PATCH 128/271] remove unused equipment sets (from an unrealized feature). --- res/e3a/equipment.xml | 69 ------------------------------------------- 1 file changed, 69 deletions(-) diff --git a/res/e3a/equipment.xml b/res/e3a/equipment.xml index bbd2ac5b7..9fe133f48 100644 --- a/res/e3a/equipment.xml +++ b/res/e3a/equipment.xml @@ -1,78 +1,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From ef10c607145d0494994d1495498cf85739d38b28 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 19:32:03 +0100 Subject: [PATCH 129/271] the locales module is deprecated. let's do this in custom.lua from now on. --- scripts/eressea/e2/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/eressea/e2/init.lua b/scripts/eressea/e2/init.lua index ed996c395..722078741 100644 --- a/scripts/eressea/e2/init.lua +++ b/scripts/eressea/e2/init.lua @@ -11,7 +11,7 @@ return { require('eressea.tunnels'), require('eressea.ponnuki'), require('eressea.astral'), - require('eressea.locales'), +-- require('eressea.locales'), require('eressea.jsreport'), require('eressea.ents'), require('eressea.cursed') From ee88c13732ddec3a3c9cb6beeecb0cf26698658a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 20:19:32 +0100 Subject: [PATCH 130/271] Korrekte Email-Subject und Adresse, auch im NR. Eliminate crufty per-game strings. --- conf/e2/config.xml | 12 ------------ conf/e3/config.xml | 12 ------------ conf/e4/config.xml | 12 ------------ res/core/de/strings.xml | 6 ++++++ res/core/messages.xml | 10 ++++++++++ src/creport.c | 4 +--- src/kernel/config.c | 17 +++++++++++++++-- src/kernel/config.h | 1 + src/kernel/config.test.c | 2 ++ src/report.c | 17 +++++++++++------ src/reports.c | 7 +++++++ src/reports.h | 1 + 12 files changed, 54 insertions(+), 47 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 8389ba470..56c622d04 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -52,16 +52,4 @@ - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA 2 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. - Remember to send your orders to - eressea-server@eressea.kn-bremen.de with the subject ERESSEA 2 ORDERS. - - - ERESSEA 2 BEFEHLE - ERESSEA 2 ORDERS - - diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 35716f332..ac05d5a5a 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -36,16 +36,4 @@ - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA 3 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. - Remember to send your orders to - eressea-server@eressea.kn-bremen.de with the subject E3 ORDERS. - - - ERESSEA 3 BEFEHLE - ERESSEA 3 ORDERS - - diff --git a/conf/e4/config.xml b/conf/e4/config.xml index ac962202c..f9ede1a27 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -36,16 +36,4 @@ - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA 4 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden. - Remember to send your orders to - eressea-server@eressea.kn-bremen.de with the subject ERESSEA 4 ORDERS. - - - ERESSEA 4 BEFEHLE - ERESSEA 4 ORDERS - - diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index b23d44ffb..7d31fc678 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -6,6 +6,12 @@ _x: preposition (15 /Schlumpf/schwerter) _a: including article (ein Schlumpf, a smurf) --> + + + BEFEHLE + ORDERS + + Wirbel vortex diff --git a/res/core/messages.xml b/res/core/messages.xml index 130b58d03..6892ec4e5 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1,5 +1,15 @@ + + + + + + Bitte denke daran, deine Befehle mit dem Betreff + $subject an $email zu senden. + Remember to send your orders to + $email with the subject ${subject}. + diff --git a/src/creport.c b/src/creport.c index fc944779f..106f34545 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1510,9 +1510,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) fprintf(F, "%d;Zeitalter\n", era); fprintf(F, "\"%s\";Build\n", eressea_version()); if (mailto != NULL) { - // char mailcmd[64]; - // snprintf(mailcmd, sizeof(mailcmd), "%s %d, %s", game_name(), game_id(), LOC(f->locale, "mailcmd")); - const char * mailcmd = LOC(f->locale, "mailcmd"); + const char * mailcmd = get_mailcmd(f->locale); fprintf(F, "\"%s\";mailto\n", mailto); fprintf(F, "\"%s\";mailcmd\n", mailcmd); } diff --git a/src/kernel/config.c b/src/kernel/config.c index a07c36aba..c7bc71cdf 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -802,12 +802,25 @@ void free_gamedata(void) } } -const char * game_name(void) { +const char * game_name(void) +{ const char * param = config_get("game.name"); return param ? param : global.gamename; } +const char * game_name_upper(void) +{ + static char result[32]; // FIXME: static result + char *r = result; + const char *param = game_name(); + const char *c = param; + while (*c && (r-result)age <= 2) { - const char *s; - s = locale_getstring(f->locale, "newbie_info_game"); - if (s) { - newline(out); - centre(out, s, true); + const char *email; + const char *subject; + email = config_get("game.email"); + subject = get_mailcmd(f->locale); + m = msg_message("newbie_info_game", "email subject", email, subject); + if (m) { + nr_render(m, f->locale, buf, sizeof(buf), f); + msg_release(m); + centre(out, buf, true); } if ((f->options & want(O_COMPUTER)) == 0) { - f->options |= want(O_COMPUTER); + const char *s; s = locale_getstring(f->locale, "newbie_info_cr"); if (s) { newline(out); centre(out, s, true); } + f->options |= want(O_COMPUTER); } } newline(out); diff --git a/src/reports.c b/src/reports.c index 77682a23a..5a47acfed 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1944,6 +1944,13 @@ static void eval_regions(struct opstack **stack, const void *userdata) opush(stack, var); } +const char *get_mailcmd(const struct locale *loc) +{ + static char result[64]; // FIXME: static return buffer + snprintf(result, sizeof(result), "%s %d %s", game_name_upper(), game_id(), LOC(loc, "mailcmd")); + return result; +} + static void eval_trail(struct opstack **stack, const void *userdata) { /* order -> string */ const faction *report = (const faction *)userdata; diff --git a/src/reports.h b/src/reports.h index 625048de9..4fab104ef 100644 --- a/src/reports.h +++ b/src/reports.h @@ -131,6 +131,7 @@ extern "C" { int stream_printf(struct stream * out, const char *format, ...); int count_travelthru(struct region *r, const struct faction *f); + const char *get_mailcmd(const struct locale *loc); #define GR_PLURAL 0x01 /* grammar: plural */ #define MAX_INVENTORY 128 /* maimum number of different items in an inventory */ From 21b617c973d59184e70c3a44c8d78d5b8da5a4e8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 20:32:54 +0100 Subject: [PATCH 131/271] fix game_name, remove it from rules --- conf/e2/config.json | 2 -- conf/e3/config.json | 2 -- conf/e4/config.json | 2 -- res/core/de/strings.xml | 2 -- src/kernel/config.c | 2 +- 5 files changed, 1 insertion(+), 9 deletions(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index ce823a33d..ca157f501 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -8,8 +8,6 @@ "jsreport" ], "settings": { - "game.id": 2, - "game.name": "Eressea", "orders.default": "work", "NewbieImmunity": 8, "modules.wormholes": true, diff --git a/conf/e3/config.json b/conf/e3/config.json index 30bc7e599..fd533070e 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -25,8 +25,6 @@ "jsreport" ], "settings": { - "game.id": 3, - "game.name": "E3", "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, diff --git a/conf/e4/config.json b/conf/e4/config.json index cbe273af6..91961258a 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -25,8 +25,6 @@ "jsreport" ], "settings": { - "game.id": 4, - "game.name": "Deveron", "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 7d31fc678..bccfdd165 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -6,12 +6,10 @@ _x: preposition (15 /Schlumpf/schwerter) _a: including article (ein Schlumpf, a smurf) --> - BEFEHLE ORDERS - Wirbel vortex diff --git a/src/kernel/config.c b/src/kernel/config.c index c7bc71cdf..c2db29f22 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -814,7 +814,7 @@ const char * game_name_upper(void) char *r = result; const char *param = game_name(); const char *c = param; - while (*c && (r-result)r) { *r++ = (char)toupper(*c++); } *r = '\0'; From b2e6c481863308f912b50a58e9025502c5b1d0cc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 21:02:15 +0100 Subject: [PATCH 132/271] specify a game id, because there is one in the data --- tests/eressea.ini | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/eressea.ini b/tests/eressea.ini index e84171d45..faf4b1b9e 100644 --- a/tests/eressea.ini +++ b/tests/eressea.ini @@ -1,10 +1,8 @@ -[eressea] -base = . -report = reports +[game] +name = Eressea +id = 2 +email = eressea-server@kn-bremen.de verbose = 0 -lomem = 0 -debug = 0 -memcheck = 0 locales = de,en [lua] From 1bd6ab11ea2617f38f38036737e5a12985ab4c74 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 09:22:29 +0100 Subject: [PATCH 133/271] FACTION and PARTEI should both start orders. --- src/kernel/save.c | 24 ++++++++++++++++++++++-- tests/orders.184 | 5 +++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 84914127a..be461e27c 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -252,6 +252,26 @@ static faction *factionorders(void) return f; } +static param_t next_param(const char *s, const struct locale *lang) { + param_t p; + if (!s || s[0] == '@') { + return NOPARAM; + } + p = findparam(s, lang); + if (p==NOPARAM) { + const struct locale *loc; + for (loc=locales;loc;loc=nextlocale(loc)) { + if (loc!=lang) { + p = findparam(s, lang); + if (p==P_FACTION || p==P_GAMENAME) { + break; + } + } + } + } + return p; +} + int readorders(const char *filename) { FILE *F = NULL; @@ -279,7 +299,7 @@ int readorders(const char *filename) const char *s; init_tokens_str(b); s = gettoken(token, sizeof(token)); - p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM; + p = next_param(s, lang); switch (p) { case P_GAMENAME: case P_FACTION: @@ -308,7 +328,7 @@ int readorders(const char *filename) p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM; } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); - } + } break; /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue diff --git a/tests/orders.184 b/tests/orders.184 index 980993481..315c180d5 100644 --- a/tests/orders.184 +++ b/tests/orders.184 @@ -1,4 +1,4 @@ -ERESSEA 6rLo "6rLo" +PARTEI 6rLo "6rLo" EINHEIT 7Lgf NACH NW NW NAECHSTER @@ -6,7 +6,8 @@ ERESSEA w86y "w86y" EINHEIT uc3u STIRB "mrqa" NAECHSTER -ERESSEA ngij "ngij" + +FACTION ngij "ngij" EINHEIT iwbz HELFE w86y ALLES EINHEIT j536 From af1ce9b84e6e47d1c6ea060032b14f4acf9c63e4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 10:47:49 +0100 Subject: [PATCH 134/271] issue #633: parse FACTION/PARTEI in any language. added a test since the first fix did not work. --- src/kernel/config.c | 21 +++++++++++++++++++++ src/kernel/config.h | 1 + src/kernel/config.test.c | 24 ++++++++++++++++++++++++ src/kernel/save.c | 22 +--------------------- src/util/language.c | 7 ++++--- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index c2db29f22..109913560 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -213,6 +213,27 @@ param_t findparam(const char *s, const struct locale * lang) return result; } +param_t findparam_block(const char *s, const struct locale *lang, bool any_locale) +{ + param_t p; + if (!s || s[0] == '@') { + return NOPARAM; + } + p = findparam(s, lang); + if (any_locale && p==NOPARAM) { + const struct locale *loc; + for (loc=locales;loc;loc=nextlocale(loc)) { + if (loc!=lang) { + p = findparam(s, loc); + if (p==P_FACTION || p==P_GAMENAME) { + break; + } + } + } + } + return p; +} + param_t findparam_ex(const char *s, const struct locale * lang) { param_t result = findparam(s, lang); diff --git a/src/kernel/config.h b/src/kernel/config.h index 43189400c..b51ba2725 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -45,6 +45,7 @@ extern "C" { int findoption(const char *s, const struct locale *lang); param_t findparam(const char *s, const struct locale *lang); + param_t findparam_block(const char *s, const struct locale *lang, bool any_locale); param_t findparam_ex(const char *s, const struct locale * lang); bool isparam(const char *s, const struct locale * lang, param_t param); param_t getparam(const struct locale *lang); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index ca362d6a1..72b2387ac 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -251,9 +251,33 @@ static void test_config_inifile(CuTest *tc) { test_cleanup(); } +static void test_findparam(CuTest *tc) { + struct locale *en, *de; + test_setup(); + en = get_or_create_locale("en"); + locale_setstring(en, parameters[P_FACTION], "FACTION"); + CuAssertIntEquals(tc, NOPARAM, findparam("FACTION", en)); + init_parameters(en); + CuAssertIntEquals(tc, P_FACTION, findparam("FACTION", en)); + de = get_or_create_locale("de"); + locale_setstring(de, parameters[P_FACTION], "PARTEI"); + CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", de)); + init_parameters(de); + CuAssertIntEquals(tc, P_FACTION, findparam("PARTEI", de)); + CuAssertIntEquals(tc, NOPARAM, findparam("HODOR", de)); + + CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", en)); + CuAssertIntEquals(tc, NOPARAM, findparam_block("HODOR", de, false)); + CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", de, true)); + CuAssertIntEquals(tc, NOPARAM, findparam_block("PARTEI", en, false)); + CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", en, true)); + test_cleanup(); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_findparam); SUITE_ADD_TEST(suite, test_config_inifile); SUITE_ADD_TEST(suite, test_config_cache); SUITE_ADD_TEST(suite, test_get_set_param); diff --git a/src/kernel/save.c b/src/kernel/save.c index be461e27c..ac236d5bf 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -252,26 +252,6 @@ static faction *factionorders(void) return f; } -static param_t next_param(const char *s, const struct locale *lang) { - param_t p; - if (!s || s[0] == '@') { - return NOPARAM; - } - p = findparam(s, lang); - if (p==NOPARAM) { - const struct locale *loc; - for (loc=locales;loc;loc=nextlocale(loc)) { - if (loc!=lang) { - p = findparam(s, lang); - if (p==P_FACTION || p==P_GAMENAME) { - break; - } - } - } - } - return p; -} - int readorders(const char *filename) { FILE *F = NULL; @@ -299,7 +279,7 @@ int readorders(const char *filename) const char *s; init_tokens_str(b); s = gettoken(token, sizeof(token)); - p = next_param(s, lang); + p = findparam_block(s, lang, true); switch (p) { case P_GAMENAME: case P_FACTION: diff --git a/src/util/language.c b/src/util/language.c index efd5cd5f7..300e69103 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -295,10 +295,11 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ // TODO: swap the name of s and key const char * s = string_cb(i); if (s) { - struct critbit_tree ** cb = (struct critbit_tree **)tokens; const char * key = locale_string(lang, s, false); - if (!key) key = s; - add_translation(cb, key, i); + if (key) { + struct critbit_tree ** cb = (struct critbit_tree **)tokens; + add_translation(cb, key, i); + } } } } From a79e5ef2a5ef25d7df3b81b6af57724d6f75dadd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 11:13:01 +0100 Subject: [PATCH 135/271] refactor and annotate volcano outbreaks. add configuration options to control volcano behavior. --- src/volcano.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/volcano.c b/src/volcano.c index 60beeaed7..a9a4f0ba7 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -55,7 +55,7 @@ static int nb_armor(const unit * u, int index) if (!(u_race(u)->battle_flags & BF_EQUIPMENT)) return 0; - /* Normale Rüstung */ + /* Normale R�stung */ for (itm = u->items; itm; itm = itm->next) { const armor_type *atype = itm->type->rtype->atype; @@ -169,11 +169,11 @@ static region *rrandneighbour(region * r) for (i = 0; i != MAXDIRECTIONS; i++) { c++; } - /* Zufällig eine auswählen */ + /* Zuf�llig eine ausw�hlen */ rr = rng_int() % c; - /* Durchzählen */ + /* Durchz�hlen */ c = -1; for (i = 0; i != MAXDIRECTIONS; i++) { @@ -204,7 +204,7 @@ volcano_destruction(region * volcano, region * r, const char *damage) else { /* Produktion vierteln ... */ a->data.sa[0] = (short)percent; - /* Für 6-17 Runden */ + /* F�r 6-17 Runden */ a->data.sa[1] = (short)(a->data.sa[1] + time); } @@ -255,6 +255,14 @@ void volcano_outbreak(region * r, region *rn) } } +static bool stop_smoke_chance(void) { + return rng_int() % 100 < 12; +} + +static bool outbreak_chance(void) { + return rng_int() % 100 < 8; +} + void volcano_update(void) { region *r; @@ -270,13 +278,16 @@ void volcano_update(void) r->terrain = t_volcano; } else { - if (rng_int() % 100 < 12) { + if (stop_smoke_chance()) { ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r)); r->terrain = t_volcano; } - else if (r->uid == 1246051340 || (r->age > 20 && rng_int() % 100 < 8)) { + else if (r->uid == 1246051340 || outbreak_chance()) { + // HACK: a fixed E4-only region-uid in Code. + // FIXME: In E4 gibt es eine Ebene #1246051340, die Smalland heisst. + // da das kein aktiver Vulkan ist, ist dieser Test da nicht idiotisch? + // das sollte bestimmt rn betreffen? region *rn; - /* Zufällige Nachbarregion verwüsten */ rn = rrandneighbour(r); volcano_outbreak(r, rn); r->terrain = t_volcano; From d8770932f01fc99341380f23c73d2f22a0b3807c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 11:44:34 +0100 Subject: [PATCH 136/271] fix issue #477 (intermittent volcano) --- scripts/tests/xmas.lua | 2 ++ src/volcano.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 7ac4ce731..5477e08ab 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -8,6 +8,8 @@ function setup() eressea.settings.set("rules.grow.formula", "0") eressea.settings.set("rules.peasants.growth.factor", "0") eressea.settings.set("volcano.active.percent", "0") + eressea.settings.set("volcano.outbreak.percent", "0") + eressea.settings.set("volcano.stop.percent", "0") end function test_snowglobe_fail() diff --git a/src/volcano.c b/src/volcano.c index a9a4f0ba7..89a865017 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -256,11 +256,19 @@ void volcano_outbreak(region * r, region *rn) } static bool stop_smoke_chance(void) { - return rng_int() % 100 < 12; + static int cache, percent = 0; + if (config_changed(&cache)) { + percent = config_get_int("volcano.stop.percent", 12); + } + return percent!=0 && (rng_int() % 100) < percent; } static bool outbreak_chance(void) { - return rng_int() % 100 < 8; + static int cache, percent = 0; + if (config_changed(&cache)) { + percent = config_get_int("volcano.outbreak.percent", 8); + } + return percent!=0 && (rng_int() % 100) < percent; } void volcano_update(void) From c0692986b27236912a8646f692a4c6e4f16da87b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Jan 2017 21:35:01 +0100 Subject: [PATCH 137/271] make runtests.bat not crash. disable auto-load of config.lua (sob). free messages and config in config.reset(). --- scripts/tests/laws.lua | 2 ++ src/bind_config.c | 3 +++ src/bindings.c | 2 +- src/laws.c | 3 ++- src/util/nrmessage.c | 13 +++++++++++++ src/util/nrmessage.h | 16 +++++++++------- src/util/nrmessage_struct.h | 4 ++-- 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index f0fef15a9..6f41fc54b 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -95,6 +95,7 @@ function test_force_leave_postcombat() u1.building = b1 u2.building = b1 eressea.settings.set("rules.owners.force_leave", "1") + eressea.settings.set("NewbieImmunity", "0") u1:clear_orders() u1:add_order("ATTACKIERE " .. itoa36(u2.id)) u2:clear_orders() @@ -109,6 +110,7 @@ function test_force_leave_postcombat() end end assert_not_equal(nil, u3) + assert_equal(nil, u2.building) assert_equal(nil, u3.building) assert_equal(1, u3.number) end diff --git a/src/bind_config.c b/src/bind_config.c index 929e4cca0..faf543f47 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,9 @@ void config_reset(void) { default_locale = 0; + free_config(); free_locales(); + free_nrmesssages(); free_spells(); free_buildingtypes(); free_shiptypes(); diff --git a/src/bindings.c b/src/bindings.c index 0986ffb37..7bf30202a 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1190,7 +1190,7 @@ int eressea_run(lua_State *L, const char *luafile) lua_remove(L, -2); /* try to run configuration scripts: */ - err = run_script(L, "config.lua"); + // err = run_script(L, "config.lua"); err = run_script(L, "custom.lua"); /* run the main script */ diff --git a/src/laws.c b/src/laws.c index d6e005ff8..74e572a78 100644 --- a/src/laws.c +++ b/src/laws.c @@ -119,7 +119,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. int NewbieImmunity(void) { - return config_get_int("NewbieImmunity", 0); + int result = config_get_int("NewbieImmunity", 0); + return result; } bool IsImmune(const faction * f) diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index 8156b9784..717c4dc1f 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -178,3 +178,16 @@ const char *nrt_section(const nrmessage_type * nrt) { return nrt ? nrt->section : NULL; } + +void free_nrmesssages(void) { + int i; + for (i = 0; i != NRT_MAXHASH; ++i) { + while (nrtypes[i]) { + nrmessage_type *nr = nrtypes[i]; + nrtypes[i] = nr->next; + free(nr->string); + free(nr->vars); + free(nr); + } + } +} diff --git a/src/util/nrmessage.h b/src/util/nrmessage.h index 122b1f1a8..6cc02bfe2 100644 --- a/src/util/nrmessage.h +++ b/src/util/nrmessage.h @@ -31,18 +31,20 @@ extern "C" { extern nrsection *sections; - extern void nrt_register(const struct message_type *mtype, + void free_nrmesssages(void); + + void nrt_register(const struct message_type *mtype, const struct locale *lang, const char *script, int level, const char *section); - extern struct nrmessage_type *nrt_find(const struct locale *, + struct nrmessage_type *nrt_find(const struct locale *, const struct message_type *); - extern const char *nrt_string(const struct nrmessage_type *type); - extern const char *nrt_section(const struct nrmessage_type *mt); + const char *nrt_string(const struct nrmessage_type *type); + const char *nrt_section(const struct nrmessage_type *mt); - extern size_t nr_render(const struct message *msg, const struct locale *lang, + size_t nr_render(const struct message *msg, const struct locale *lang, char *buffer, size_t size, const void *userdata); - extern int nr_level(const struct message *msg); - extern const char *nr_section(const struct message *msg); + int nr_level(const struct message *msg); + const char *nr_section(const struct message *msg); /* before: * fogblock;movement:0;de;{unit} konnte von {region} nicht nach {$dir direction} ausreisen, der Nebel war zu dicht. diff --git a/src/util/nrmessage_struct.h b/src/util/nrmessage_struct.h index 6a3a1d9b0..57f8e644d 100644 --- a/src/util/nrmessage_struct.h +++ b/src/util/nrmessage_struct.h @@ -8,8 +8,8 @@ typedef struct nrmessage_type { const struct message_type *mtype; const struct locale *lang; - const char *string; - const char *vars; + char *string; + char *vars; struct nrmessage_type *next; int level; const char *section; From dcdb5354d9b99d0711f3ddbf6bc5ad0cd86ec89d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 24 Jan 2017 10:36:27 +0100 Subject: [PATCH 138/271] BUG 2273: runtests.bat fails when config is auto-loaded. run rules tests with the correct configuration, ignore .ini file setting. still not enabling auto-load again, use custom.lua instead. --- scripts/tests/e3/castles.lua | 2 +- tests/runtests.bat | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index 1fd4e13e9..df395ed3d 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -46,7 +46,7 @@ end function test_build_packice() local r = region.create(0, 0, "packice") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("packice@eressea.de", "human", "de") local u = unit.create(f, r, 1) u:clear_orders() u:add_item("stone", 10) diff --git a/tests/runtests.bat b/tests/runtests.bat index e79d27baa..996fb47b7 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -6,9 +6,9 @@ IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug SET SERVER=%BUILD%\eressea.exe %BUILD%\test_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 +%SERVER% -re2 ..\scripts\run-tests-e2.lua +%SERVER% -re3 ..\scripts\run-tests-e3.lua +%SERVER% -re4 ..\scripts\run-tests-e4.lua PAUSE RMDIR /s /q reports DEL score score.alliances datum turn From 044953e4ab2a462fe6d1434201aa88f60d4aa00e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 18:17:19 +0100 Subject: [PATCH 139/271] add a function to compare size of occupied castles --- src/kernel/building.c | 13 ++++++++++++- src/kernel/building.h | 2 ++ src/kernel/building.test.c | 26 ++++++++++++++++++++++++++ src/kernel/region.c | 14 +++++++++++--- src/kernel/region.test.c | 25 +++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index f2c9c9fd2..98caad07a 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -335,7 +335,18 @@ const building_type *findbuildingtype(const char *name, return (const building_type *)type.v; } -static int building_protection(const building * b, const unit * u, building_bonus bonus) +int cmp_castle_size(const building * b, const building * a) +{ + if (!b || !b->type->protection || !building_owner(b)) { + return -1; + } + if (!a || !a->type->protection || !building_owner(a)) { + return 1; + } + return b->size - a->size; +} + +int building_protection(const building * b, const unit * u, building_bonus bonus) { int i = 0; int bsize = buildingeffsize(b, false); diff --git a/src/kernel/building.h b/src/kernel/building.h index a6936d90d..8b1a5b05b 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -85,6 +85,8 @@ extern "C" { extern struct selist *buildingtypes; extern struct attrib_type at_building_action; + int cmp_castle_size(const struct building * b, const struct building * a); + int building_protection(const struct building * b, const struct unit * u, building_bonus bonus); building_type *bt_get_or_create(const char *name); bool bt_changed(int *cache); const building_type *bt_find(const char *name); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 3b296a6fe..89e2b978c 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -493,9 +493,35 @@ static void test_building_type(CuTest *tc) { test_cleanup(); } +static void test_cmp_castle_size(CuTest *tc) { + region *r; + building *b1, *b2; + building_type *bt_castle; + unit *u1, *u2; + + test_setup(); + bt_castle = test_create_buildingtype("castle"); + bt_castle->protection = building_protection; + r = test_create_region(0, 0, 0); + b1 = test_create_building(r, bt_castle); + b2 = test_create_building(r, bt_castle); + u1 = test_create_unit(test_create_faction(0), r); + u_set_building(u1, b1); + u2 = test_create_unit(test_create_faction(0), r); + u_set_building(u2, b2); + b1->size = 5; + b2->size = 10; + CuAssertTrue(tc, cmp_castle_size(b1, b2)<0); + CuAssertTrue(tc, cmp_castle_size(b2, b1)>0); + CuAssertTrue(tc, cmp_castle_size(b1, NULL)>0); + CuAssertTrue(tc, cmp_castle_size(NULL, b1)<0); + test_cleanup(); +} + CuSuite *get_building_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_cmp_castle_size); SUITE_ADD_TEST(suite, test_register_building); SUITE_ADD_TEST(suite, test_btype_defaults); SUITE_ADD_TEST(suite, test_building_set_owner); diff --git a/src/kernel/region.c b/src/kernel/region.c index cade135c7..06d2d9d7c 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1324,9 +1324,17 @@ struct message *msg) struct faction *region_get_owner(const struct region *r) { - assert(rule_region_owners()); - if (r->land && r->land->ownership) { - return r->land->ownership->owner; + if (r->land) { + if (rule_region_owners()) { + if (r->land->ownership) { + return r->land->ownership->owner; + } + } + else { + building *b = largestbuilding(r, cmp_castle_size, false); + unit * u = b ? building_owner(b) : NULL; + return u ? u->faction : NULL; + } } return NULL; } diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c index 01ecae2a8..8cf08a62c 100644 --- a/src/kernel/region.test.c +++ b/src/kernel/region.test.c @@ -1,6 +1,8 @@ #include #include "region.h" +#include "building.h" +#include "unit.h" #include "terrain.h" #include "item.h" @@ -31,9 +33,32 @@ void test_terraform(CuTest *tc) { test_cleanup(); } +static void test_region_get_owner(CuTest *tc) { + region *r; + building *b1, *b2; + building_type *bt_castle; + unit *u1, *u2; + + test_setup(); + bt_castle = test_create_buildingtype("castle"); + bt_castle->protection = building_protection; + r = test_create_region(0, 0, 0); + b1 = test_create_building(r, bt_castle); + b2 = test_create_building(r, bt_castle); + b1->size = 5; + b2->size = 10; + u1 = test_create_unit(test_create_faction(0), r); + u_set_building(u1, b1); + u2 = test_create_unit(test_create_faction(0), r); + u_set_building(u2, b2); + CuAssertPtrEquals(tc, u2->faction, region_get_owner(r)); + test_cleanup(); +} + CuSuite *get_region_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_terraform); + SUITE_ADD_TEST(suite, test_region_get_owner); return suite; } From 2a1ead6506e7d0cb6033adefbbde727580716b5e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 20:57:54 +0100 Subject: [PATCH 140/271] BENENNE REGION ist jeder Einheit des Regionsbesitzers erlaubt --- src/kernel/building.test.c | 7 ++----- src/kernel/config.c | 2 +- src/kernel/region.test.c | 7 ++----- src/laws.c | 11 +---------- src/laws.test.c | 39 +++++++++++++++++++++++++++++++++----- src/tests.c | 9 +++++++-- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 89e2b978c..e02d16556 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -496,15 +496,12 @@ static void test_building_type(CuTest *tc) { static void test_cmp_castle_size(CuTest *tc) { region *r; building *b1, *b2; - building_type *bt_castle; unit *u1, *u2; test_setup(); - bt_castle = test_create_buildingtype("castle"); - bt_castle->protection = building_protection; r = test_create_region(0, 0, 0); - b1 = test_create_building(r, bt_castle); - b2 = test_create_building(r, bt_castle); + b1 = test_create_building(r, NULL); + b2 = test_create_building(r, NULL); u1 = test_create_unit(test_create_faction(0), r); u_set_building(u1, b1); u2 = test_create_unit(test_create_faction(0), r); diff --git a/src/kernel/config.c b/src/kernel/config.c index 109913560..83d0808da 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -203,7 +203,7 @@ param_t findparam(const char *s, const struct locale * lang) void **tokens = get_translations(lang, UT_PARAMS); critbit_tree *cb = (critbit_tree *)*tokens; if (!cb) { - log_error("no parameters defined in locale %s", locale_name(lang)); + log_warning("no parameters defined in locale %s", locale_name(lang)); } else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { cb_get_kv(match, &i, sizeof(int)); diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c index 8cf08a62c..892b37a8e 100644 --- a/src/kernel/region.test.c +++ b/src/kernel/region.test.c @@ -36,15 +36,12 @@ void test_terraform(CuTest *tc) { static void test_region_get_owner(CuTest *tc) { region *r; building *b1, *b2; - building_type *bt_castle; unit *u1, *u2; test_setup(); - bt_castle = test_create_buildingtype("castle"); - bt_castle->protection = building_protection; r = test_create_region(0, 0, 0); - b1 = test_create_building(r, bt_castle); - b2 = test_create_building(r, bt_castle); + b1 = test_create_building(r, NULL); + b2 = test_create_building(r, NULL); b1->size = 5; b2->size = 10; u1 = test_create_unit(test_create_faction(0), r); diff --git a/src/laws.c b/src/laws.c index 74e572a78..769bfc9d3 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1892,16 +1892,7 @@ int name_cmd(struct unit *u, struct order *ord) break; case P_REGION: - if (!b) { - cmistake(u, ord, 145, MSG_EVENT); - break; - } - if (building_owner(b) != u) { - cmistake(u, ord, 148, MSG_EVENT); - break; - } - - if (b != largestbuilding(r, get_cmp_region_owner(), false)) { + if (u->faction != region_get_owner(r)) { cmistake(u, ord, 147, MSG_EVENT); break; } diff --git a/src/laws.test.c b/src/laws.test.c index d4753ec19..67a9bb810 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -812,10 +812,7 @@ static void test_name_region(CuTest *tc) { f = u->faction; ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); - name_cmd(u, ord); - CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error145")); - - u->building = test_create_building(u->region, 0); + u_set_building(u, test_create_building(u->region, 0)); name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->region->land->name); free_order(ord); @@ -1060,7 +1057,7 @@ static void test_name_cmd(CuTest *tc) { free_order(ord); ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_BUILDING])); - u->building = test_create_building(u->region, 0); + u_set_building(u, test_create_building(u->region, 0)); name_cmd(u, ord); CuAssertStrEquals(tc, "Hodor", u->building->name); free_order(ord); @@ -1073,6 +1070,37 @@ static void test_name_cmd(CuTest *tc) { test_cleanup(); } +static void test_name_cmd_2274(CuTest *tc) { + unit *u1, *u2, *u3; + faction *f; + region *r; + + test_setup(); + r = test_create_region(0, 0, 0); + u1 = test_create_unit(test_create_faction(0), r); + u2 = test_create_unit(test_create_faction(0), r); + u3 = test_create_unit(u2->faction, r); + u_set_building(u1, test_create_building(r, NULL)); + u1->building->size = 10; + u_set_building(u2, test_create_building(r, NULL)); + u2->building->size = 20; + + f = u2->faction; + u2->thisorder = create_order(K_NAME, f->locale, "%s Heimat", LOC(f->locale, parameters[P_REGION])); + name_cmd(u2, u2->thisorder); + CuAssertStrEquals(tc, "Heimat", r->land->name); + f = u3->faction; + u3->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); + name_cmd(u3, u3->thisorder); + CuAssertStrEquals(tc, "Hodor", r->land->name); + f = u1->faction; + u1->thisorder = create_order(K_NAME, f->locale, "%s notallowed", LOC(f->locale, parameters[P_REGION])); + name_cmd(u1, u1->thisorder); + CuAssertStrEquals(tc, "Hodor", r->land->name); + + test_cleanup(); +} + static void test_ally_cmd(CuTest *tc) { unit *u; faction * f; @@ -1481,6 +1509,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_name_cmd); + SUITE_ADD_TEST(suite, test_name_cmd_2274); SUITE_ADD_TEST(suite, test_ally_cmd_errors); SUITE_ADD_TEST(suite, test_long_order_normal); SUITE_ADD_TEST(suite, test_long_order_none); diff --git a/src/tests.c b/src/tests.c index 15ae677fe..eb2631afe 100644 --- a/src/tests.c +++ b/src/tests.c @@ -225,8 +225,13 @@ building * test_create_building(region * r, const building_type * btype) { building * b; assert(r); - b = new_building(btype ? btype : test_create_buildingtype("castle"), r, default_locale); - b->size = b->type->maxsize > 0 ? b->type->maxsize : 1; + if (!btype) { + building_type *bt_castle = test_create_buildingtype("castle"); + bt_castle->protection = building_protection; + btype = bt_castle; + } + b = new_building(btype, r, default_locale); + b->size = btype->maxsize > 0 ? btype->maxsize : 1; return b; } From 21514f3bfe6e177906807d5bc090979a79342718 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 21:03:08 +0100 Subject: [PATCH 141/271] BESCHREIBE REGION ist jeder Einheit des Regionsbesitzers erlaubt --- src/laws.c | 20 +------------------- src/laws.test.c | 5 +++++ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/laws.c b/src/laws.c index 769bfc9d3..6b0bfda8d 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1538,16 +1538,6 @@ int prefix_cmd(unit * u, struct order *ord) return 0; } -static cmp_building_cb get_cmp_region_owner(void) -{ - if (rule_region_owners()) { - return &cmp_current_owner; - } - else { - return &cmp_wage; - } -} - int display_cmd(unit * u, struct order *ord) { char token[128]; @@ -1597,15 +1587,7 @@ int display_cmd(unit * u, struct order *ord) break; case P_REGION: - if (!u->building) { - cmistake(u, ord, 145, MSG_EVENT); - break; - } - if (building_owner(u->building) != u) { - cmistake(u, ord, 148, MSG_EVENT); - break; - } - if (u->building != largestbuilding(r, get_cmp_region_owner(), false)) { + if (u->faction != region_get_owner(r)) { cmistake(u, ord, 147, MSG_EVENT); break; } diff --git a/src/laws.test.c b/src/laws.test.c index 67a9bb810..5eb742809 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -229,6 +229,11 @@ static void test_display_cmd(CuTest *tc) { CuAssertPtrEquals(tc, NULL, u->display); free_order(ord); + ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); + CuAssertIntEquals(tc, 0, display_cmd(u, ord)); + CuAssertPtrEquals(tc, NULL, r->display); + free_order(ord); + test_cleanup(); } From e4a58b2e62763926b46fec4e54807f0070932cdc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 25 Jan 2017 21:26:30 +0100 Subject: [PATCH 142/271] hack compress to not use /home/enno/bin script --- process/compress.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/compress.sh b/process/compress.sh index ff152b9f1..e50cf1940 100755 --- a/process/compress.sh +++ b/process/compress.sh @@ -20,5 +20,5 @@ if [ ! -d $GAME/reports ]; then fi cd $GAME/reports -$HOME/bin/compress.py $TURN "$GAME_NAME" +$ERESSEA/server/bin/compress.py $TURN "$GAME_NAME" cd - From 350357120adc3d7014ce97f0a1d66cf9209a9854 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 16:05:44 +0100 Subject: [PATCH 143/271] fix duplicate cutest library conflict and crash --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fd15f201..405b86a03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ endif(WIN32) project (eressea-server C) - enable_testing() find_package (LibXml2) find_package (SQLite3) From 57f6c56e890fdd857d1acb9f313f35581c47d700 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 17:41:21 +0100 Subject: [PATCH 144/271] remove quicklist shim, use selist everywhere --- src/bindings.h | 2 +- src/sqlite.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/bindings.h b/src/bindings.h index b4523e582..354bb199a 100755 --- a/src/bindings.h +++ b/src/bindings.h @@ -15,8 +15,8 @@ extern "C" { #endif struct lua_State; - struct selist; struct _dictionary_; + struct selist; int tolua_sqlite_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d); diff --git a/src/sqlite.c b/src/sqlite.c index aea0f5d20..2f23d41d5 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,10 +72,10 @@ typedef struct db_faction { char *name; } db_faction; -static struct quicklist * +static struct selist * read_factions(sqlite3 * db, int game_id) { int res; - quicklist *result = 0; + selist *result = 0; const char * sql = "SELECT f.id, fd.code, fd.name, fd.email FROM faction f" " LEFT OUTER JOIN faction_data fd" @@ -97,7 +97,7 @@ read_factions(sqlite3 * db, int game_id) { if (text) dbf->name = strdup(text); text = (const char *)sqlite3_column_text(stmt, 3); if (text) dbf->email = strdup(text); - ql_push(&result, dbf); + selist_push(&result, dbf); res = sqlite3_step(stmt); } sqlite3_finalize(stmt); @@ -134,13 +134,18 @@ static void update_faction(sqlite3 *db, const faction *f) { } int db_update_factions(sqlite3 * db, bool force, int game_id) { - quicklist *ql = read_factions(db, game_id); + selist *ql = read_factions(db, game_id); faction *f; sqlite3_exec(db, "BEGIN", 0, 0, 0); for (f = factions; f; f = f->next) { bool update = force; db_faction *dbf = 0; +<<<<<<< HEAD ql_iter it = qli_init(&ql); +======= +#ifdef SELIST_TODO + selist_iter it = qli_init(&ql); +>>>>>>> remove quicklist shim, use selist everywhere while (qli_more(it)) { db_faction *df = (db_faction*)qli_next(&it); if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { @@ -175,12 +180,12 @@ int db_update_factions(sqlite3 * db, bool force, int game_id) { int db_update_scores(sqlite3 * db, bool force) { /* - const char *sql_ins = + const char *sselist_ins = "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; - sqlite3_stmt *stmt_ins = stmt_cache_get(db, sql_ins); - const char *sql_upd = + sqlite3_stmt *stmt_ins = stmt_cache_get(db, sselist_ins); + const char *sselist_upd = "UPDATE score set value=? WHERE faction_id=? AND turn=?"; - sqlite3_stmt *stmt_upd = stmt_cache_get(db, sql_upd); + sqlite3_stmt *stmt_upd = stmt_cache_get(db, sselist_upd); faction *f; sqlite3_exec(db, "BEGIN", 0, 0, 0); for (f = factions; f; f = f->next) { From 23b211d9e483243a50ec6fd16826b9362f57e1ee Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 18:58:29 +0100 Subject: [PATCH 145/271] fix study.c teacher messaging --- clibs | 2 +- src/sqlite.c | 82 +++++++++++++++++++++++++++--------------------- src/study.c | 50 +++++++++++++++++++---------- src/study.h | 4 +-- src/study.test.c | 8 ++--- src/travelthru.c | 3 +- 6 files changed, 90 insertions(+), 59 deletions(-) diff --git a/clibs b/clibs index 1052905e0..f91ef37f0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 1052905e08314de8778750d7585474182723111e +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/src/sqlite.c b/src/sqlite.c index 2f23d41d5..edb5bfc62 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -133,47 +133,59 @@ static void update_faction(sqlite3 *db, const faction *f) { sqlite3_finalize(stmt); } +struct cb_data { + const faction *f; + sqlite3 *db; + db_faction *dbf; +}; + +static bool db_faction_cb(void *el, void *arg) { + db_faction *df = (db_faction *)el; + struct cb_data *cb = (struct cb_data *)arg; + const faction *f = cb->f; + + if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { + cb->dbf = df; + } + if (f->subscription == df->uid) { + cb->dbf = df; + return false; + } + return true; +} + int db_update_factions(sqlite3 * db, bool force, int game_id) { selist *ql = read_factions(db, game_id); - faction *f; - sqlite3_exec(db, "BEGIN", 0, 0, 0); - for (f = factions; f; f = f->next) { - bool update = force; - db_faction *dbf = 0; -<<<<<<< HEAD - ql_iter it = qli_init(&ql); -======= -#ifdef SELIST_TODO - selist_iter it = qli_init(&ql); ->>>>>>> remove quicklist shim, use selist everywhere - while (qli_more(it)) { - db_faction *df = (db_faction*)qli_next(&it); - if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { - dbf = df; + if (ql) { + faction *f; + struct cb_data cbdata; + cbdata.db = db; + cbdata.dbf = NULL; + sqlite3_exec(db, "BEGIN", 0, 0, 0); + for (f = factions; f; f = f->next) { + bool update = force; + cbdata.f = f; + selist_foreach_ex(ql, db_faction_cb, &cbdata); + if (cbdata.dbf) { + const db_faction *dbf = cbdata.dbf; + if (dbf->uid != f->subscription) { + log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); + f->subscription = dbf->uid; + } + update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); } - if (f->subscription == df->uid) { - dbf = df; - break; + else { + f->subscription = insert_faction(db, game_id, f); + log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); + update = true; + } + if (update) { + update_faction(db, f); + log_debug("faction %s updated\n", itoa36(f->no)); } } - if (dbf) { - if (dbf->uid != f->subscription) { - log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); - f->subscription = dbf->uid; - } - update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); - } - else { - f->subscription = insert_faction(db, game_id, f); - log_warning("faction %s not found in database, created as %d\n", itoa36(f->no), f->subscription); - update = true; - } - if (update) { - update_faction(db, f); - log_debug("faction %s updated\n", itoa36(f->no)); - } + sqlite3_exec(db, "COMMIT", 0, 0, 0); } - sqlite3_exec(db, "COMMIT", 0, 0, 0); return SQLITE_OK; } diff --git a/src/study.c b/src/study.c index b69b4359f..c6dc3b260 100644 --- a/src/study.c +++ b/src/study.c @@ -52,8 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include - -#include +#include /* libc includes */ #include @@ -222,7 +221,7 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, a = a_add(&student->attribs, a_new(&at_learning)); teach = (teaching_info *)a->data.v; } - ql_push(&teach->teachers, teacher); + selist_push(&teach->teachers, teacher); teach->value += n; if (student->building && teacher->building == student->building) { @@ -531,6 +530,36 @@ static bool ExpensiveMigrants(void) return rule; } +struct teach_data { + unit *u; + skill_t sk; +}; + +static bool cb_msg_teach(void *el, void *arg) { + struct teach_data *td = (struct teach_data *)arg; + unit *ut = (unit *)el; + unit * u = td->u; + skill_t sk = td->sk; + if (ut->faction != u->faction) { + bool feedback = alliedunit(u, ut->faction, HELP_GUARD); + if (feedback) { + ADDMSG(&ut->faction->msgs, msg_message("teach_teacher", + "teacher student skill level", ut, u, sk, + effskill(u, sk, 0))); + } + ADDMSG(&u->faction->msgs, msg_message("teach_student", + "teacher student skill", ut, u, sk)); + } + return true; +} + +static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) { + struct teach_data cbdata; + cbdata.sk = sk; + cbdata.u = u; + selist_foreach_ex(teachers, cb_msg_teach, &cbdata); +} + int study_cmd(unit * u, order * ord) { region *r = u->region; @@ -755,19 +784,8 @@ int study_cmd(unit * u, order * ord) learn_skill(u, sk, days); if (a != NULL) { - ql_iter qli = qli_init(&teach->teachers); - while (qli_more(qli)) { - unit *teacher = (unit *)qli_next(&qli); - if (teacher->faction != u->faction) { - bool feedback = alliedunit(u, teacher->faction, HELP_GUARD); - if (feedback) { - ADDMSG(&teacher->faction->msgs, msg_message("teach_teacher", - "teacher student skill level", teacher, u, sk, - effskill(u, sk, 0))); - } - ADDMSG(&u->faction->msgs, msg_message("teach_student", - "teacher student skill", teacher, u, sk)); - } + if (teach->teachers) { + msg_teachers(teach->teachers, u, sk); } a_remove(&u->attribs, a); a = NULL; diff --git a/src/study.h b/src/study.h index 8067bc9bd..0f8ae70f5 100644 --- a/src/study.h +++ b/src/study.h @@ -27,7 +27,7 @@ extern "C" { #endif struct unit; - struct quicklist; + struct selist; int teach_cmd(struct unit *u, struct order *ord); int study_cmd(struct unit *u, struct order *ord); @@ -48,7 +48,7 @@ extern "C" { #define TEACHNUMBER 10 typedef struct teaching_info { - struct quicklist *teachers; + struct selist *teachers; int value; } teaching_info; diff --git a/src/study.test.c b/src/study.test.c index 4c1e5f171..594ca600c 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include @@ -539,9 +539,9 @@ static void test_teach_message(CuTest *tc) { teach = (teaching_info *)a->data.v; CuAssertPtrNotNull(tc, teach->teachers); CuAssertIntEquals(tc, 600, teach->value); - CuAssertIntEquals(tc, 2, ql_length(teach->teachers)); - CuAssertPtrEquals(tc, u1, ql_get(teach->teachers, 0)); - CuAssertPtrEquals(tc, u2, ql_get(teach->teachers, 1)); + CuAssertIntEquals(tc, 2, selist_length(teach->teachers)); + CuAssertPtrEquals(tc, u1, selist_get(teach->teachers, 0)); + CuAssertPtrEquals(tc, u2, selist_get(teach->teachers, 1)); study_cmd(u, u->thisorder); CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher")); CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher")); diff --git a/src/travelthru.c b/src/travelthru.c index a546c976c..73aa97757 100644 --- a/src/travelthru.c +++ b/src/travelthru.c @@ -105,10 +105,11 @@ struct cb_data { struct region *r; }; -void cb_map(void *data, void *ex) { +static bool cb_map(void *data, void *ex) { struct cb_data *cb = (struct cb_data *)ex; struct unit *u = (struct unit *)data; cb->call(cb->r, u, cb->data); + return true; } void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *data) From 146cb9b00d3f5ca9320eb4f0725e65ea1eef7b2f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 19:19:40 +0100 Subject: [PATCH 146/271] fix merge conflict --- src/study.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/study.c b/src/study.c index fb87987fa..c6dc3b260 100644 --- a/src/study.c +++ b/src/study.c @@ -54,8 +54,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include - /* libc includes */ #include #include From f941fceed4df187e69e7f6d7bc26d36eb483332a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 21:34:45 +0100 Subject: [PATCH 147/271] new cmake modules (expat) --- cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake b/cmake index f1fb3943a..d88983c7f 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit f1fb3943ace59994d90d71a891b80033dc2700a2 +Subproject commit d88983c7ff4bc3a4884a7c3f74e8190bac5eab23 From 0913336ef8dfc6ea0a0ee321e7cad26bd4ed1064 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jan 2017 21:47:59 +0100 Subject: [PATCH 148/271] Use MSVC fixes for clibs compilation. --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index f91ef37f0..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 From d4e5e5f478f1c90589b86b0a6e18eb62f0446367 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 27 Jan 2017 20:20:20 +0100 Subject: [PATCH 149/271] add a simple upgrade script for non-developers. --- s/upgrade | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 s/upgrade diff --git a/s/upgrade b/s/upgrade new file mode 100755 index 000000000..9d9d5a313 --- /dev/null +++ b/s/upgrade @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +ROOT=`pwd` +while [ ! -d $ROOT/.git ]; do + ROOT=`dirname $ROOT` +done + +cd $ROOT +git pull +git submodule update +s/build +s/runtests +s/install From 6d15767a1896bc2f03f4b9c4b6b1dd1a2fc7cb61 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 28 Jan 2017 19:42:20 +0100 Subject: [PATCH 150/271] create a spellref structure. use this when referring to spells that may not (yet) exist. use it for race::precombatspell (rare use case). --- clibs | 2 +- src/kernel/race.c | 2 ++ src/kernel/race.h | 3 ++- src/kernel/spell.c | 29 +++++++++++++++++++++++++++++ src/kernel/spell.h | 9 +++++++++ src/kernel/spell.test.c | 17 +++++++++++++++++ src/kernel/xmlreader.c | 15 +++++++++++++-- src/magic.c | 7 +++++-- 8 files changed, 78 insertions(+), 6 deletions(-) diff --git a/clibs b/clibs index 27c8b3202..f91ef37f0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/src/kernel/race.c b/src/kernel/race.c index a78a9e340..c18761dcd 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -32,6 +32,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "region.h" #include "ship.h" #include "skill.h" +#include "spell.h" #include "terrain.h" #include "unit.h" @@ -182,6 +183,7 @@ void racelist_insert(struct race_list **rl, const struct race *r) void free_races(void) { while (races) { race * rc = races->next; + spellref_free(races->precombatspell); free_params(&races->parameters); free(xrefs); xrefs = 0; diff --git a/src/kernel/race.h b/src/kernel/race.h index 6673676bd..496dfa763 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -45,6 +45,7 @@ extern "C" { struct param; struct spell; + struct spellref; struct locale; extern int num_races; @@ -137,7 +138,7 @@ extern "C" { int at_bonus; /* Ver�ndert den Angriffsskill (default: 0) */ int df_bonus; /* Ver�ndert den Verteidigungskill (default: 0) */ struct param *parameters; // additional properties, for an example see natural_armor - const struct spell *precombatspell; + struct spellref *precombatspell; signed char *study_speed; /* study-speed-bonus in points/turn (0=30 Tage) */ int flags; int battle_flags; diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 5415c4a0e..5e4a57e86 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -145,3 +145,32 @@ spell *find_spellbyid(unsigned int id) log_warning("cannot find spell by id: %u\n", id); return NULL; } + +struct spellref *spellref_create(const char *name) +{ + spellref *spref = malloc(sizeof(spellref)); + + spref->name = strdup(name); + spref->sp = NULL; + return spref; +} + +void spellref_free(spellref *spref) +{ + if (spref) { + free(spref->name); + free(spref); + } +} + +struct spell *spellref_get(struct spellref *spref) +{ + if (!spref->sp) { + spref->sp = find_spell(spref->name); + if (spref->sp) { + free(spref->name); + spref->name = NULL; + } + } + return spref->sp; +} diff --git a/src/kernel/spell.h b/src/kernel/spell.h index f74fda6e2..b5b227b50 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -45,6 +45,15 @@ extern "C" { fumble_f fumble; } spell; + typedef struct spellref { + char * name; + struct spell *sp; + } spellref; + + struct spellref *spellref_create(const char *name); + void spellref_free(struct spellref *spref); + struct spell *spellref_get(struct spellref *spref); + int sp_antimagiczone(struct castorder *co); struct spell * create_spell(const char * name, unsigned int id); diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index 6bb2ac449..4a8cd617a 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -69,9 +69,26 @@ static void test_create_spell_with_id(CuTest * tc) test_cleanup(); } +static void test_spellref(CuTest *tc) +{ + spellref *ref; + spell *sp; + test_setup(); + ref = spellref_create("hodor"); + CuAssertPtrNotNull(tc, ref); + CuAssertPtrEquals(tc, NULL, spellref_get(ref)); + sp = create_spell("hodor", 0); + CuAssertPtrNotNull(tc, sp); + CuAssertPtrEquals(tc, sp, spellref_get(ref)); + CuAssertPtrEquals(tc, NULL, ref->name); + spellref_free(ref); + test_cleanup(); +} + CuSuite *get_spell_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_spellref); SUITE_ADD_TEST(suite, test_create_a_spell); SUITE_ADD_TEST(suite, test_create_duplicate_spell); SUITE_ADD_TEST(suite, test_create_spell_with_id); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index cba01bc7b..238b04227 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -87,6 +87,17 @@ static const spell *xml_spell(xmlNode * node, const char *name) return sp; } +static spellref *xml_spellref(xmlNode * node, const char *name) +{ + xmlChar *propValue = xmlGetProp(node, BAD_CAST name); + if (propValue != NULL) { + spellref *ref = spellref_create((const char *)propValue); + xmlFree(propValue); + return ref; + } + return NULL; +} + static xmlChar *xml_cleanup_string(xmlChar * str) { xmlChar *read = str; @@ -1853,7 +1864,7 @@ static int parse_races(xmlDocPtr doc) || !"precombatspell is already initialized"); for (k = 0; k != result->nodesetval->nodeNr; ++k) { xmlNodePtr node = result->nodesetval->nodeTab[k]; - rc->precombatspell = xml_spell(node, "spell"); + rc->precombatspell = xml_spellref(node, "spell"); } xmlXPathFreeObject(result); @@ -2076,10 +2087,10 @@ void register_xmlreader(void) xml_register_callback(parse_buildings); /* requires resources */ xml_register_callback(parse_ships); /* requires terrains */ + xml_register_callback(parse_races); /* requires spells */ xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_spellbooks); /* requires spells */ xml_register_callback(parse_equipment); /* requires spells */ - xml_register_callback(parse_races); /* requires spells */ xml_register_callback(parse_calendar); } #endif diff --git a/src/magic.c b/src/magic.c index f2992538c..7969253e0 100644 --- a/src/magic.c +++ b/src/magic.c @@ -560,8 +560,11 @@ const spell *get_combatspell(const unit * u, int nr) if (m) { return m->combatspells[nr].sp; } - else if (u_race(u)->precombatspell != NULL) { - return u_race(u)->precombatspell; + else { + const race * rc = u_race(u); + if (rc->precombatspell) { + return spellref_get(rc->precombatspell); + } } return NULL; From 11c0330de1fe4f8b9efd58aaa6a59e5bff7252f7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 28 Jan 2017 19:52:28 +0100 Subject: [PATCH 151/271] make race::attack use spellref, too. --- src/battle.c | 9 ++++++--- src/kernel/race.c | 5 +++++ src/kernel/race.h | 2 +- src/kernel/xmlreader.c | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/battle.c b/src/battle.c index 4105cf73f..ad613a69f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1858,10 +1858,13 @@ static void do_combatspell(troop at) static void do_extra_spell(troop at, const att * a) { - const spell *sp = a->data.sp; + const spell *sp = spellref_get(a->data.sp); - if (sp->cast == NULL) { - log_error("spell '%s' has no function.\n", sp->sname); + if (!sp) { + log_error("no such spell: '%s'", a->data.sp->name); + } + else if (sp->cast == NULL) { + log_error("spell '%s' has no function.", sp->sname); } else { assert(a->level > 0); diff --git a/src/kernel/race.c b/src/kernel/race.c index c18761dcd..1bdba8a1b 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -182,7 +182,12 @@ void racelist_insert(struct race_list **rl, const struct race *r) void free_races(void) { while (races) { + int i; race * rc = races->next; + + for (i = 0; races->attack[i].type!=AT_NONE; ++i) { + spellref_free(races->attack[i].data.sp); + } spellref_free(races->precombatspell); free_params(&races->parameters); free(xrefs); diff --git a/src/kernel/race.h b/src/kernel/race.h index 496dfa763..19b7b7ad3 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -105,7 +105,7 @@ extern "C" { int type; union { const char *dice; - const struct spell *sp; + struct spellref *sp; } data; int flags; int level; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 238b04227..36fe2d7f8 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1889,11 +1889,11 @@ static int parse_races(xmlDocPtr doc) xmlFree(propValue); } else { - attack->data.sp = xml_spell(node, "spell"); + attack->data.sp = xml_spellref(node, "spell"); if (attack->data.sp) { attack->level = xml_ivalue(node, "level", 0); if (attack->level <= 0) { - log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->sname, rc->_name, attack->level); + log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->name, rc->_name, attack->level); } } } From d794ad4433f0c58fe3240a1eb417af71ec89f513 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 28 Jan 2017 20:02:15 +0100 Subject: [PATCH 152/271] Eressea config requires game.id At home, I am running all games from the same directory for testing, and cannot use eressea.ini for setting game.id Override it in eressea.ini for other games. --- conf/e2/config.json | 2 ++ conf/e3/config.json | 2 ++ conf/e4/config.json | 2 ++ 3 files changed, 6 insertions(+) diff --git a/conf/e2/config.json b/conf/e2/config.json index ca157f501..f9f9b2df0 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -8,6 +8,8 @@ "jsreport" ], "settings": { + "game.name" : "Eressea", + "game.id" : 2, "orders.default": "work", "NewbieImmunity": 8, "modules.wormholes": true, diff --git a/conf/e3/config.json b/conf/e3/config.json index fd533070e..8783055b8 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -25,6 +25,8 @@ "jsreport" ], "settings": { + "game.name" : "Eressea", + "game.id" : 3, "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, diff --git a/conf/e4/config.json b/conf/e4/config.json index 91961258a..e11b13a1c 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -25,6 +25,8 @@ "jsreport" ], "settings": { + "game.name" : "Eressea", + "game.id" : 4, "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, From 2016a9ef20a6762dfd1df867ebc352c1f631d58d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 28 Jan 2017 20:07:31 +0100 Subject: [PATCH 153/271] unused function --- cmake | 2 +- src/kernel/xmlreader.c | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/cmake b/cmake index d88983c7f..f1fb3943a 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit d88983c7ff4bc3a4884a7c3f74e8190bac5eab23 +Subproject commit f1fb3943ace59994d90d71a891b80033dc2700a2 diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 36fe2d7f8..959872920 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -75,18 +75,6 @@ static void xml_readtext(xmlNodePtr node, struct locale **lang, xmlChar ** text) *text = xmlNodeListGetString(node->doc, node->children, 1); } -static const spell *xml_spell(xmlNode * node, const char *name) -{ - const spell *sp = NULL; - xmlChar *propValue = xmlGetProp(node, BAD_CAST name); - if (propValue != NULL) { - sp = find_spell((const char *)propValue); - assert(sp); - xmlFree(propValue); - } - return sp; -} - static spellref *xml_spellref(xmlNode * node, const char *name) { xmlChar *propValue = xmlGetProp(node, BAD_CAST name); From 7437ebb36a5eb2c7a13ba911884b629163e5470d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 29 Jan 2017 10:45:22 +0100 Subject: [PATCH 154/271] WIP: make all spell configuration use spellref. does not pass tests. --- src/kernel/xmlreader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 36fe2d7f8..cad8780c7 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -2088,9 +2088,9 @@ void register_xmlreader(void) xml_register_callback(parse_buildings); /* requires resources */ xml_register_callback(parse_ships); /* requires terrains */ xml_register_callback(parse_races); /* requires spells */ - xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_spellbooks); /* requires spells */ xml_register_callback(parse_equipment); /* requires spells */ + xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_calendar); } #endif From ae83448e4aea90dc0913155adb1aaa92703f97d8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 10:10:21 +0100 Subject: [PATCH 155/271] Deveron is now just E3 with a different name. remove a lot of duplication. add a -c option to specify a path for eressea.ini --- conf/e4/catalog.xml | 16 ------- conf/e4/config.json | 95 ------------------------------------- conf/e4/config.xml | 39 --------------- s/runtests | 1 - scripts/eressea/e4/init.lua | 11 ----- scripts/run-tests-e4.lua | 23 --------- src/kernel/config.c | 13 +++-- src/kernel/save.c | 7 --- src/main.c | 26 +++++++--- tests/runtests.bat | 1 - 10 files changed, 29 insertions(+), 203 deletions(-) delete mode 100644 conf/e4/catalog.xml delete mode 100644 conf/e4/config.json delete mode 100644 conf/e4/config.xml delete mode 100644 scripts/eressea/e4/init.lua delete mode 100644 scripts/run-tests-e4.lua diff --git a/conf/e4/catalog.xml b/conf/e4/catalog.xml deleted file mode 100644 index 9987e72c8..000000000 --- a/conf/e4/catalog.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - diff --git a/conf/e4/config.json b/conf/e4/config.json deleted file mode 100644 index e11b13a1c..000000000 --- a/conf/e4/config.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "include": [ - "keywords.json", - "prefixes.json", - "e3/terrains.json" - ], - "disabled": [ - "herbalism", - "alchemy", - "entertainment", - "espionage", - "perception", - "stealth", - "taxation", - "trade", - "besiege", - "steal", - "buy", - "teach", - "sabotage", - "spy", - "tax", - "entertain", - "sell", - "jsreport" - ], - "settings": { - "game.name" : "Eressea", - "game.id" : 4, - "orders.default": "work", - "database.gameid": 7, - "NewbieImmunity": 4, - "modules.astralspace": false, - "modules.wormholes": false, - "modules.markets": true, - "magic.regeneration": 0.75, - "magic.power": 0.5, - "resource.factor": 0.25, - "skills.cost.tactics": 500, - "entertain.base": 0, - "entertain.perlevel": 20, - "nmr.timeout": 5, - "nmr.removenewbie": 0, - "GiveRestriction": 3, - "hunger.long": false, - "hunger.damage": "1d9+9", - "hunger.demons.skill": true, - "hunger.demons.peasant_tolerance": true, - "init_spells": 0, - "recruit.allow_merge": true, - "study.expensivemigrants": true, - "study.speedup": 2, - "study.produceexp": 12, - "world.era": 3, - "rules.reserve.twophase": true, - "rules.owners.force_leave": false, - "rules.transfermen": false, - "stealth.faction.other": false, - "rules.stealth.anon_battle": false, - "rules.check_overload": false, - "rules.combat.goblinbonus": 3, - "rules.alliances": true, - "rules.combat.herospeed": 3, - "rules.combat.demon_vampire": 5, - "rules.combat.skill_bonus": 0, - "rules.combat.nat_armor": 1, - "rules.items.loot_divisor": 2, - "rules.items.give_divisor": 2, - "rules.move.owner_leave": true, - "rules.region_owners": true, - "rules.cavalry.skill": 2, - "rules.cavalry.mode": 1, - "rules.magic.multipotion": true, - "rules.magic.wol_effect": 5, - "rules.magic.factionlist": true, - "rules.magic.wol_type": 2, - "rules.blessed_harvest.flags": 1, - "rules.magic.elfpower": true, - "rules.magic.playerschools": "gwyrrd illaun draig cerddor", - "rules.build.other_buildings": true, - "rules.economy.taxation": 1, - "rules.food.flags": 2, - "rules.economy.roqf": 5, - "rules.economy.herbrot": 0, - "rules.region_owner_pay_building": "market harbour lighthouse", - "rules.dwarf_castles": true, - "rules.limit.faction": 250, - "rules.grow.formula": 1, - "rules.tactics.formula": 1, - "rules.help.mask": "fight guard money give", - "movement.shipspeed.skillbonus": 6, - "alliance.auto": "fight", - "alliance.restricted": "fight" - } -} diff --git a/conf/e4/config.xml b/conf/e4/config.xml deleted file mode 100644 index f9ede1a27..000000000 --- a/conf/e4/config.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/s/runtests b/s/runtests index 58498436f..e42640de1 100755 --- a/s/runtests +++ b/s/runtests @@ -15,7 +15,6 @@ cd $ROOT $ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests.lua $ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests-e2.lua $ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests-e3.lua -$ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests-e4.lua rm -rf data reports orders.txt score score.alliances datum turn cd $OLDWPD diff --git a/scripts/eressea/e4/init.lua b/scripts/eressea/e4/init.lua deleted file mode 100644 index 32c0b8498..000000000 --- a/scripts/eressea/e4/init.lua +++ /dev/null @@ -1,11 +0,0 @@ -require 'eressea.e3.rules' -require 'eressea.spells' - -eressea.log.debug("rules for game E4") - -return { - require('eressea'), - -- require('eressea.markets'), - require('eressea.frost'), - require('eressea.ents') -} diff --git a/scripts/run-tests-e4.lua b/scripts/run-tests-e4.lua deleted file mode 100644 index f827baec0..000000000 --- a/scripts/run-tests-e4.lua +++ /dev/null @@ -1,23 +0,0 @@ --- 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/src/kernel/config.c b/src/kernel/config.c index 83d0808da..b1894cdff 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -749,13 +749,18 @@ void config_set_from(const dictionary *d) key[slen] = '.'; iniparser_getseckeys(d, sec, keys); for (k=0;k!=nkeys;++k) { - const char *val; + const char *val, *orig; size_t klen = strlen(keys[k]); assert(klen+slen+1 Date: Thu, 2 Feb 2017 10:19:39 +0100 Subject: [PATCH 156/271] uninitialized variable. --- src/kernel/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index b1894cdff..ca23a5bc9 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -754,8 +754,8 @@ void config_set_from(const dictionary *d) assert(klen+slen+1 Date: Thu, 2 Feb 2017 16:52:32 +0100 Subject: [PATCH 157/271] WIP: spellref everywhere --- src/creport.c | 5 +++-- src/kernel/spell.c | 13 +++++++++---- src/kernel/spell.h | 41 +++++++++++++++++++++-------------------- src/kernel/spellbook.c | 32 +++++++++++++++++++++++++------- src/kernel/spellbook.h | 5 +++-- src/kernel/xmlreader.c | 2 +- src/laws.c | 4 ++-- src/magic.c | 28 ++++++++++++++++------------ src/report.c | 6 +++--- src/reports.c | 3 ++- 10 files changed, 85 insertions(+), 54 deletions(-) diff --git a/src/creport.c b/src/creport.c index 106f34545..53c542470 100644 --- a/src/creport.c +++ b/src/creport.c @@ -718,7 +718,8 @@ static void cr_output_spells(stream *out, const unit * u, int maxlevel) for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { - spell * sp = sbe->sp; + // TODO: no need to deref spref here, spref->name == sp->sname + spell * sp = spellref_get(sbe->spref); const char *name = translate(mkname("spell", sp->sname), spell_name(sp, f->locale)); if (!header) { stream_printf(out, "SPRUECHE\n"); @@ -1621,7 +1622,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) a = a_find(f->attribs, &at_reportspell); while (a && a->type == &at_reportspell) { spellbook_entry *sbe = (spellbook_entry *)a->data.v; - cr_reportspell(F, sbe->sp, sbe->level, f->locale); + cr_reportspell(F, spellref_get(sbe->spref), sbe->level, f->locale); a = a->next; } for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 5e4a57e86..f950918e0 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -167,10 +167,15 @@ struct spell *spellref_get(struct spellref *spref) { if (!spref->sp) { spref->sp = find_spell(spref->name); - if (spref->sp) { - free(spref->name); - spref->name = NULL; - } } return spref->sp; } + +spellref *spellref_copy(spellref *spref) +{ + spellref *result = spellref_create(spref->name); + if (spref->sp) { + result->sp = spref->sp; + } + return result; +} diff --git a/src/kernel/spell.h b/src/kernel/spell.h index b5b227b50..116816e26 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -52,6 +52,7 @@ extern "C" { struct spellref *spellref_create(const char *name); void spellref_free(struct spellref *spref); + struct spellref *spellref_copy(struct spellref *spref); struct spell *spellref_get(struct spellref *spref); int sp_antimagiczone(struct castorder *co); @@ -70,7 +71,7 @@ extern "C" { } #endif #endif -/* ------------------------------------------------------------- *//* Erläuterungen zu den Spruchdefinitionen +/* ------------------------------------------------------------- *//* Erl�uterungen zu den Spruchdefinitionen * * Spruchstukturdefinition: * spell{ @@ -88,35 +89,35 @@ extern "C" { * id: * SPL_NOSPELL muss der letzte Spruch in der Liste spelldaten sein, * denn nicht auf die Reihenfolge in der Liste sondern auf die id wird - * geprüft + * gepr�ft * * sptyp: * besondere Spruchtypen und Flags * (Regionszauber, Kampfzauber, Farcastbar, Stufe variable, ..) * * rank: - * gibt die Priorität und damit die Reihenfolge an, in der der Spruch + * gibt die Priorit�t und damit die Reihenfolge an, in der der Spruch * gezaubert wird. - * 1: Aura übertragen + * 1: Aura �bertragen * 2: Antimagie - * 3: Magierverändernde Sprüche (Magic Boost, ..) + * 3: Magierver�ndernde Spr�che (Magic Boost, ..) * 4: Monster erschaffen * 5: Standartlevel * 7: Teleport * - * Komponenten[Anzahl mögl. Items][Art:Anzahl:Kostentyp] + * Komponenten[Anzahl m�gl. Items][Art:Anzahl:Kostentyp] * * R_AURA: - * Grundkosten für einen Zauber. Soviel Mp müssen mindestens investiert - * werden, um den Spruch zu wirken. Zusätzliche Mp können unterschiedliche + * Grundkosten f�r einen Zauber. Soviel Mp m�ssen mindestens investiert + * werden, um den Spruch zu wirken. Zus�tzliche Mp k�nnen unterschiedliche * Auswirkungen haben, die in der Spruchfunktionsroutine definiert werden. * * R_PERMAURA: * Kosten an permantenter Aura * * Komponenten Kostentyp: - * SPC_LEVEL == Spruch mit Levelabhängigen Magiekosten. Die angegeben - * Kosten müssen für Stufe 1 berechnet sein. + * SPC_LEVEL == Spruch mit Levelabh�ngigen Magiekosten. Die angegeben + * Kosten m�ssen f�r Stufe 1 berechnet sein. * SPC_FIX == Feste Kosten * * Wenn keine spezielle Syntax angegeben ist, wird die @@ -137,34 +138,34 @@ extern "C" { * * u : eine Einheitennummer * r : hier kommen zwei Regionskoordinaten x y - * b : Gebäude- oder Burgnummer + * b : Geb�ude- oder Burgnummer * s : Schiffsnummer - * c : String, wird ohne Weiterverarbeitung übergeben - * i : Zahl (int), wird ohne Weiterverarbeitung übergeben + * c : String, wird ohne Weiterverarbeitung �bergeben + * i : Zahl (int), wird ohne Weiterverarbeitung �bergeben * k : Keywort - dieser String gibt den Paramter an, der folgt. Der * Parameter wird mit findparam() identifiziert. - * k muss immer von einem c als Platzhalter für das Objekt gefolgt + * k muss immer von einem c als Platzhalter f�r das Objekt gefolgt * werden. - * Ein gutes Beispiel sind hierfür die Sprüche zur Magieanalyse. + * Ein gutes Beispiel sind hierf�r die Spr�che zur Magieanalyse. * + : gibt an, das der vorherige Parameter mehrfach vorkommen kann. Da * ein Ende nicht definiert werden kann, muss dies immer am Schluss * kommen. * - * Flags für das Parsing: + * Flags f�r das Parsing: * TESTRESISTANCE : alle Zielobjekte, also alle Parameter vom Typ Unit, * Burg, Schiff oder Region, werden auf ihre - * Magieresistenz überprüft + * Magieresistenz �berpr�ft * TESTCANSEE : jedes Objekt vom Typ Einheit wird auf seine - * Sichtbarkeit überprüft + * Sichtbarkeit �berpr�ft * SEARCHLOCAL : die Zielobjekte werden nur regional gesucht * REGIONSPELL : Ziel ist die Region, auch wenn kein Zielobjekt * angegeben wird. Ist TESTRESISTANCE gesetzt, so wird - * die Magieresistenz der Region überprüft + * die Magieresistenz der Region �berpr�ft * * Bei fehlendem Ziel oder wenn dieses dem Zauber widersteht, wird die * Spruchfunktion nicht aufgerufen. * Sind zu wenig Parameter vorhanden, wird der Zauber ebenfalls nicht - * ausgeführt. + * ausgef�hrt. * Ist eins von mehreren Zielobjekten resistent, so wird das Flag * pa->param[n]->flag == TARGET_RESISTS * Ist eins von mehreren Zielobjekten nicht gefunden worden, so ist diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index bb060eaee..919142585 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -50,7 +50,7 @@ void read_spellbook(spellbook **bookp, gamedata *data, int(*get_level)(const spe sb = *bookp; } if (level > 0 && (data->version >= SPELLBOOK_VERSION || !spellbook_get(sb, sp))) { - spellbook_add(sb, sp, level); + spellbook_add_spell(sb, sp, level); } } } @@ -64,25 +64,43 @@ void write_spellbook(const struct spellbook *book, struct storage *store) if (book) { for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - WRITE_TOK(store, sbe->sp->sname); + WRITE_TOK(store, sbe->spref->name); WRITE_INT(store, sbe->level); } } WRITE_TOK(store, "end"); } -void spellbook_add(spellbook *sb, struct spell * sp, int level) +void spellbook_add(spellbook *sb, spellref *spref, int level) { spellbook_entry * sbe; - assert(sb && sp && level > 0); + assert(sb && spref && level > 0); +#ifndef NDEBUG + if (spellbook_get(sb, spellref_get(spref))) { + log_error("duplicate spell in spellbook '%s': '%s'\n", sb->name, spref->name); + } +#endif + sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); + sbe->spref = spellref_copy(spref); + sbe->level = level; + selist_push(&sb->spells, sbe); +} + +void spellbook_add_spell(spellbook *sb, spell *sp, int level) +{ + spellbook_entry * sbe; + + assert(sb && sp->sname && level > 0); #ifndef NDEBUG if (spellbook_get(sb, sp)) { log_error("duplicate spell in spellbook '%s': '%s'\n", sb->name, sp->sname); } #endif sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); - sbe->sp = sp; + // FIXME: create a better API to create spellref from spell + sbe->spref = spellref_create(sp->sname); + sbe->spref->sp = sp; sbe->level = level; selist_push(&sb->spells, sbe); } @@ -95,6 +113,7 @@ void spellbook_clear(spellbook *sb) assert(sb); for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); + spellref_free(sbe->spref); free(sbe); } selist_free(sb->spells); @@ -124,11 +143,10 @@ spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp) for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - if (sp == sbe->sp) { + if (sp == spellref_get(sbe->spref)) { return sbe; } } } return 0; } - diff --git a/src/kernel/spellbook.h b/src/kernel/spellbook.h index 75a420c06..858240f54 100644 --- a/src/kernel/spellbook.h +++ b/src/kernel/spellbook.h @@ -29,7 +29,7 @@ extern "C" { struct selist; typedef struct spellbook_entry { - struct spell * sp; + struct spellref * spref; int level; } spellbook_entry; @@ -44,7 +44,8 @@ extern "C" { void read_spellbook(struct spellbook **bookp, struct gamedata *data, int(*get_level)(const struct spell * sp, void *), void * cbdata); void write_spellbook(const struct spellbook *book, struct storage *store); - void spellbook_add(spellbook *sbp, struct spell * sp, int level); + void spellbook_add(spellbook *sbp, struct spellref *spref, int level); + void spellbook_add_spell(spellbook *sb, struct spell *sp, int level); int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), void * data); void spellbook_clear(spellbook *sb); spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 959872920..f9d0912da 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -2076,9 +2076,9 @@ void register_xmlreader(void) xml_register_callback(parse_buildings); /* requires resources */ xml_register_callback(parse_ships); /* requires terrains */ xml_register_callback(parse_races); /* requires spells */ - xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_spellbooks); /* requires spells */ xml_register_callback(parse_equipment); /* requires spells */ + xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_calendar); } #endif diff --git a/src/laws.c b/src/laws.c index 6b0bfda8d..f543fc78f 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3458,8 +3458,8 @@ static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel) for (qi = 0, ql = src->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { - if (!spellbook_get(dst, sbe->sp)) { - spellbook_add(dst, sbe->sp, sbe->level); + if (!spellbook_get(dst, spellref_get(sbe->spref))) { + spellbook_add(dst, sbe->spref, sbe->level); } } } diff --git a/src/magic.c b/src/magic.c index 7969253e0..bdac11df8 100644 --- a/src/magic.c +++ b/src/magic.c @@ -430,14 +430,14 @@ void show_new_spells(faction * f, int level, const spellbook *book) for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= level) { - - if (!already_seen(f, sbe->sp)) { + spell *sp = spellref_get(sbe->spref); + if (!already_seen(f, sp)) { attrib * a = a_new(&at_reportspell); spellbook_entry * entry = (spellbook_entry *)a->data.v; entry->level = sbe->level; - entry->sp = sbe->sp; + entry->spref = spellref_copy(sbe->spref); a_add(&f->attribs, a); - a_add(&f->attribs, a_new(&at_seenspell))->data.v = sbe->sp; + a_add(&f->attribs, a_new(&at_seenspell))->data.v = sp; } } } @@ -481,13 +481,16 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells commonspells[maxspell] = sbe; sbe = 0; } - else if (f->spellbook && spellbook_get(f->spellbook, sbe->sp)) { - // already have this spell, remove it from the list of candidates - commonspells[spellno] = commonspells[--numspells]; - if (maxspell > numspells) { - maxspell = numspells; + else { + spell *sp = spellref_get(sbe->spref); + if (f->spellbook && spellbook_get(f->spellbook, sp)) { + // already have this spell, remove it from the list of candidates + commonspells[spellno] = commonspells[--numspells]; + if (maxspell > numspells) { + maxspell = numspells; + } + sbe = 0; } - sbe = 0; } } @@ -495,7 +498,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells if (!f->spellbook) { f->spellbook = create_spellbook(0); } - spellbook_add(f->spellbook, sbe->sp, sbe->level); + spellbook_add(f->spellbook, sbe->spref, sbe->level); commonspells[spellno] = commonspells[--numspells]; } } @@ -2948,6 +2951,7 @@ const char *spell_info(const spell * sp, const struct locale *lang) return LOC(lang, mkname("spellinfo", sp->sname)); } +// TODO: should take the name, not the spell (spellref optimizations) const char *spell_name(const spell * sp, const struct locale *lang) { return LOC(lang, mkname("spell", sp->sname)); @@ -2967,7 +2971,7 @@ static void select_spellbook(void **tokens, spellbook *sb, const struct locale * for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - spell *sp = sbe->sp; + spell *sp = spellref_get(sbe->spref); const char *n = spell_name(sp, lang); if (!n) { diff --git a/src/report.c b/src/report.c index 1282789fa..fa1222f90 100644 --- a/src/report.c +++ b/src/report.c @@ -234,7 +234,7 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind } while (*begin); } -static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool cont, char * bufp, size_t size) { +static size_t write_spell_modifier(const spell * sp, int flag, const char * str, bool cont, char * bufp, size_t size) { if (sp->sptyp & flag) { size_t bytes = 0; if (cont) { @@ -255,7 +255,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc char buf[4096]; char *bufp = buf; size_t size = sizeof(buf) - 1; - spell * sp = sbe->sp; + const spell * sp = spellref_get(sbe->spref); const char *params = sp->parameter; if (sp->sptyp & ISCOMBATSPELL) { @@ -445,7 +445,7 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la char buf[4096]; char *startp, *bufp = buf; size_t size = sizeof(buf) - 1; - spell * sp = sbe->sp; + const spell * sp = spellref_get(sbe->spref); newline(out); centre(out, spell_name(sp, lang), true); diff --git a/src/reports.c b/src/reports.c index 5a47acfed..bb727083e 100644 --- a/src/reports.c +++ b/src/reports.c @@ -680,7 +680,8 @@ size_t size) if (wrptr(&bufp, &size, result) != 0) { WARN_STATIC_BUFFER(); } - bufp = STRLCPY(bufp, spell_name(sbe->sp, f->locale), size); + // TODO: no need to deref the spellref here (spref->name is good) + bufp = STRLCPY(bufp, spell_name(spellref_get(sbe->spref), f->locale), size); } } From b08b1544f4a4c89e851df41eee1025036b5ce0af Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 16:55:07 +0100 Subject: [PATCH 158/271] snotling is not a player race --- res/eressea/races.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 7c3a5ab0c..e31283fc3 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1150,7 +1150,7 @@ - + From 0c08a644950fbead4a917798e6237cf20776efb4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 17:10:53 +0100 Subject: [PATCH 159/271] new clibs module, fixed MSVC settings --- clibs | 2 +- cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clibs b/clibs index f91ef37f0..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 diff --git a/cmake b/cmake index f1fb3943a..d88983c7f 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit f1fb3943ace59994d90d71a891b80033dc2700a2 +Subproject commit d88983c7ff4bc3a4884a7c3f74e8190bac5eab23 From 784a934c47c8c9c47f671fb69c736e5d24f8b44b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 19:17:01 +0100 Subject: [PATCH 160/271] Fix snotling XML (no recruiting). --- clibs | 2 +- res/eressea/races.xml | 5 +++-- src/kernel/xmlreader.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clibs b/clibs index f91ef37f0..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 diff --git a/res/eressea/races.xml b/res/eressea/races.xml index e31283fc3..2ef5950c9 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1150,7 +1150,9 @@ - + + @@ -1180,7 +1182,6 @@ - diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index f9d0912da..35a682649 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -2074,11 +2074,11 @@ void register_xmlreader(void) xml_register_callback(parse_rules); xml_register_callback(parse_buildings); /* requires resources */ + xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_ships); /* requires terrains */ xml_register_callback(parse_races); /* requires spells */ xml_register_callback(parse_spellbooks); /* requires spells */ xml_register_callback(parse_equipment); /* requires spells */ - xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_calendar); } #endif From e9a5a79c652aa7f63584c1f77b5ab0c525216670 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 19:28:46 +0100 Subject: [PATCH 161/271] make my visual studio debugging experience the same as before (-r is like -c) --- src/main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index a3bcdb866..9bfd1448f 100644 --- a/src/main.c +++ b/src/main.c @@ -186,14 +186,11 @@ static int parse_args(int argc, char **argv, int *exitcode) else { const char *arg; switch (argi[1]) { + case 'r': case 'c': i = get_arg(argc, argv, 2, i, &arg, 0); config_set("config.path", arg); break; - case 'r': - i = get_arg(argc, argv, 2, i, &arg, 0); - config_set("config.rules", arg); - break; case 'f': i = get_arg(argc, argv, 2, i, &luafile, 0); break; From 9f3f1bf41df000a24621404fca3513fd2ccf2357 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 19:30:29 +0100 Subject: [PATCH 162/271] fix runtests.bat experience (doh!) --- src/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 9bfd1448f..a3bcdb866 100644 --- a/src/main.c +++ b/src/main.c @@ -186,11 +186,14 @@ static int parse_args(int argc, char **argv, int *exitcode) else { const char *arg; switch (argi[1]) { - case 'r': case 'c': i = get_arg(argc, argv, 2, i, &arg, 0); config_set("config.path", arg); break; + case 'r': + i = get_arg(argc, argv, 2, i, &arg, 0); + config_set("config.rules", arg); + break; case 'f': i = get_arg(argc, argv, 2, i, &luafile, 0); break; From 456d1bd1967fb66d0e354d45df57019489501461 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 20:08:04 +0100 Subject: [PATCH 163/271] spellbooks should not use spellref, it's unnecessary. --- src/creport.c | 4 ++-- src/kernel/spell.c | 26 ++++++++++++++------------ src/kernel/spell.h | 3 +-- src/kernel/spell.test.c | 5 +++-- src/kernel/spellbook.c | 33 +++++++-------------------------- src/kernel/spellbook.h | 7 +++---- src/kernel/xmlreader.c | 10 +++++----- src/laws.c | 4 ++-- src/magic.c | 19 ++++++++----------- src/report.c | 4 ++-- src/reports.c | 2 +- 11 files changed, 48 insertions(+), 69 deletions(-) diff --git a/src/creport.c b/src/creport.c index 53c542470..345aaf0bc 100644 --- a/src/creport.c +++ b/src/creport.c @@ -719,7 +719,7 @@ static void cr_output_spells(stream *out, const unit * u, int maxlevel) spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { // TODO: no need to deref spref here, spref->name == sp->sname - spell * sp = spellref_get(sbe->spref); + spell * sp = sbe->sp; const char *name = translate(mkname("spell", sp->sname), spell_name(sp, f->locale)); if (!header) { stream_printf(out, "SPRUECHE\n"); @@ -1622,7 +1622,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) a = a_find(f->attribs, &at_reportspell); while (a && a->type == &at_reportspell) { spellbook_entry *sbe = (spellbook_entry *)a->data.v; - cr_reportspell(F, spellref_get(sbe->spref), sbe->level, f->locale); + cr_reportspell(F, sbe->sp, sbe->level, f->locale); a = a->next; } for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; diff --git a/src/kernel/spell.c b/src/kernel/spell.c index f950918e0..212b0a7d2 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -146,12 +146,18 @@ spell *find_spellbyid(unsigned int id) return NULL; } -struct spellref *spellref_create(const char *name) +struct spellref *spellref_create(spell *sp, const char *name) { spellref *spref = malloc(sizeof(spellref)); - spref->name = strdup(name); - spref->sp = NULL; + if (sp) { + spref->sp = sp; + spref->name = strdup(sp->sname); + } + else if (name) { + spref->name = strdup(name); + spref->sp = NULL; + } return spref; } @@ -166,16 +172,12 @@ void spellref_free(spellref *spref) struct spell *spellref_get(struct spellref *spref) { if (!spref->sp) { + assert(spref->name); spref->sp = find_spell(spref->name); + if (spref->sp) { + free(spref->name); + spref->name = NULL; + } } return spref->sp; } - -spellref *spellref_copy(spellref *spref) -{ - spellref *result = spellref_create(spref->name); - if (spref->sp) { - result->sp = spref->sp; - } - return result; -} diff --git a/src/kernel/spell.h b/src/kernel/spell.h index 116816e26..e7592f082 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -50,9 +50,8 @@ extern "C" { struct spell *sp; } spellref; - struct spellref *spellref_create(const char *name); + struct spellref *spellref_create(struct spell *sp, const char *name); void spellref_free(struct spellref *spref); - struct spellref *spellref_copy(struct spellref *spref); struct spell *spellref_get(struct spellref *spref); int sp_antimagiczone(struct castorder *co); diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index 4a8cd617a..b500f94cc 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -74,13 +74,14 @@ static void test_spellref(CuTest *tc) spellref *ref; spell *sp; test_setup(); - ref = spellref_create("hodor"); + ref = spellref_create(NULL, "hodor"); CuAssertPtrNotNull(tc, ref); + CuAssertPtrEquals(tc, NULL, ref->sp); + CuAssertStrEquals(tc, "hodor", ref->name); CuAssertPtrEquals(tc, NULL, spellref_get(ref)); sp = create_spell("hodor", 0); CuAssertPtrNotNull(tc, sp); CuAssertPtrEquals(tc, sp, spellref_get(ref)); - CuAssertPtrEquals(tc, NULL, ref->name); spellref_free(ref); test_cleanup(); } diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index 919142585..b7f65420c 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -50,7 +50,7 @@ void read_spellbook(spellbook **bookp, gamedata *data, int(*get_level)(const spe sb = *bookp; } if (level > 0 && (data->version >= SPELLBOOK_VERSION || !spellbook_get(sb, sp))) { - spellbook_add_spell(sb, sp, level); + spellbook_add(sb, sp, level); } } } @@ -64,43 +64,25 @@ void write_spellbook(const struct spellbook *book, struct storage *store) if (book) { for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - WRITE_TOK(store, sbe->spref->name); + WRITE_TOK(store, sbe->sp->sname); WRITE_INT(store, sbe->level); } } WRITE_TOK(store, "end"); } -void spellbook_add(spellbook *sb, spellref *spref, int level) +void spellbook_add(spellbook *sb, spell *sp, int level) { spellbook_entry * sbe; - assert(sb && spref && level > 0); -#ifndef NDEBUG - if (spellbook_get(sb, spellref_get(spref))) { - log_error("duplicate spell in spellbook '%s': '%s'\n", sb->name, spref->name); - } -#endif - sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); - sbe->spref = spellref_copy(spref); - sbe->level = level; - selist_push(&sb->spells, sbe); -} - -void spellbook_add_spell(spellbook *sb, spell *sp, int level) -{ - spellbook_entry * sbe; - - assert(sb && sp->sname && level > 0); + assert(sb && sp && level > 0); #ifndef NDEBUG if (spellbook_get(sb, sp)) { log_error("duplicate spell in spellbook '%s': '%s'\n", sb->name, sp->sname); } #endif sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); - // FIXME: create a better API to create spellref from spell - sbe->spref = spellref_create(sp->sname); - sbe->spref->sp = sp; + sbe->sp = sp; sbe->level = level; selist_push(&sb->spells, sbe); } @@ -113,7 +95,6 @@ void spellbook_clear(spellbook *sb) assert(sb); for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - spellref_free(sbe->spref); free(sbe); } selist_free(sb->spells); @@ -135,7 +116,7 @@ int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), return 0; } -spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp) +spellbook_entry * spellbook_get(spellbook *sb, const struct spell *sp) { if (sb) { selist *ql; @@ -143,7 +124,7 @@ spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp) for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - if (sp == spellref_get(sbe->spref)) { + if (sbe->sp==sp) { return sbe; } } diff --git a/src/kernel/spellbook.h b/src/kernel/spellbook.h index 858240f54..fb3438a8b 100644 --- a/src/kernel/spellbook.h +++ b/src/kernel/spellbook.h @@ -29,7 +29,7 @@ extern "C" { struct selist; typedef struct spellbook_entry { - struct spellref * spref; + struct spell *sp; int level; } spellbook_entry; @@ -44,11 +44,10 @@ extern "C" { void read_spellbook(struct spellbook **bookp, struct gamedata *data, int(*get_level)(const struct spell * sp, void *), void * cbdata); void write_spellbook(const struct spellbook *book, struct storage *store); - void spellbook_add(spellbook *sbp, struct spellref *spref, int level); - void spellbook_add_spell(spellbook *sb, struct spell *sp, int level); + void spellbook_add(spellbook *sbp, struct spell *sp, int level); int spellbook_foreach(spellbook *sb, int(*callback)(spellbook_entry *, void *), void * data); void spellbook_clear(spellbook *sb); - spellbook_entry * spellbook_get(spellbook *sb, const struct spell * sp); + spellbook_entry * spellbook_get(spellbook *sb, const struct spell *sp); #ifdef __cplusplus } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index f9d0912da..4225858ee 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -79,7 +79,7 @@ static spellref *xml_spellref(xmlNode * node, const char *name) { xmlChar *propValue = xmlGetProp(node, BAD_CAST name); if (propValue != NULL) { - spellref *ref = spellref_create((const char *)propValue); + spellref *ref = spellref_create(NULL, (const char *)propValue); xmlFree(propValue); return ref; } @@ -2075,10 +2075,10 @@ void register_xmlreader(void) xml_register_callback(parse_buildings); /* requires resources */ xml_register_callback(parse_ships); /* requires terrains */ - xml_register_callback(parse_races); /* requires spells */ - xml_register_callback(parse_spellbooks); /* requires spells */ - xml_register_callback(parse_equipment); /* requires spells */ - xml_register_callback(parse_spells); /* requires resources */ + xml_register_callback(parse_races); xml_register_callback(parse_calendar); + xml_register_callback(parse_spells); /* requires resources */ + xml_register_callback(parse_equipment); /* requires spells */ + xml_register_callback(parse_spellbooks); /* requires spells */ } #endif diff --git a/src/laws.c b/src/laws.c index f543fc78f..6b0bfda8d 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3458,8 +3458,8 @@ static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel) for (qi = 0, ql = src->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { - if (!spellbook_get(dst, spellref_get(sbe->spref))) { - spellbook_add(dst, sbe->spref, sbe->level); + if (!spellbook_get(dst, sbe->sp)) { + spellbook_add(dst, sbe->sp, sbe->level); } } } diff --git a/src/magic.c b/src/magic.c index bdac11df8..7e820f9c3 100644 --- a/src/magic.c +++ b/src/magic.c @@ -430,14 +430,13 @@ void show_new_spells(faction * f, int level, const spellbook *book) for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= level) { - spell *sp = spellref_get(sbe->spref); - if (!already_seen(f, sp)) { + if (!already_seen(f, sbe->sp)) { attrib * a = a_new(&at_reportspell); spellbook_entry * entry = (spellbook_entry *)a->data.v; entry->level = sbe->level; - entry->spref = spellref_copy(sbe->spref); + entry->sp = sbe->sp; a_add(&f->attribs, a); - a_add(&f->attribs, a_new(&at_seenspell))->data.v = sp; + a_add(&f->attribs, a_new(&at_seenspell))->data.v = sbe->sp; } } } @@ -482,8 +481,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells sbe = 0; } else { - spell *sp = spellref_get(sbe->spref); - if (f->spellbook && spellbook_get(f->spellbook, sp)) { + if (f->spellbook && spellbook_get(f->spellbook, sbe->sp)) { // already have this spell, remove it from the list of candidates commonspells[spellno] = commonspells[--numspells]; if (maxspell > numspells) { @@ -498,7 +496,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells if (!f->spellbook) { f->spellbook = create_spellbook(0); } - spellbook_add(f->spellbook, sbe->spref, sbe->level); + spellbook_add(f->spellbook, sbe->sp, sbe->level); commonspells[spellno] = commonspells[--numspells]; } } @@ -2971,15 +2969,14 @@ static void select_spellbook(void **tokens, spellbook *sb, const struct locale * for (qi = 0, ql = sb->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry *sbe = (spellbook_entry *)selist_get(ql, qi); - spell *sp = spellref_get(sbe->spref); - const char *n = spell_name(sp, lang); + const char *n = spell_name(sbe->sp, lang); if (!n) { - log_error("no translation in locale %s for spell %s\n", locale_name(lang), sp->sname); + log_error("no translation in locale %s for spell %s\n", locale_name(lang), sbe->sp->sname); } else { variant token; - token.v = sp; + token.v = sbe->sp; addtoken((struct tnode **)tokens, n, token); } } diff --git a/src/report.c b/src/report.c index fa1222f90..06244c70c 100644 --- a/src/report.c +++ b/src/report.c @@ -255,7 +255,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc char buf[4096]; char *bufp = buf; size_t size = sizeof(buf) - 1; - const spell * sp = spellref_get(sbe->spref); + const spell * sp = sbe->sp; const char *params = sp->parameter; if (sp->sptyp & ISCOMBATSPELL) { @@ -445,7 +445,7 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la char buf[4096]; char *startp, *bufp = buf; size_t size = sizeof(buf) - 1; - const spell * sp = spellref_get(sbe->spref); + const spell * sp = sbe->sp; newline(out); centre(out, spell_name(sp, lang), true); diff --git a/src/reports.c b/src/reports.c index bb727083e..318660024 100644 --- a/src/reports.c +++ b/src/reports.c @@ -681,7 +681,7 @@ size_t size) WARN_STATIC_BUFFER(); } // TODO: no need to deref the spellref here (spref->name is good) - bufp = STRLCPY(bufp, spell_name(spellref_get(sbe->spref), f->locale), size); + bufp = STRLCPY(bufp, spell_name(sbe->sp, f->locale), size); } } From 0224620ca332048a11d05c3d12197bdcb7efb822 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 20:12:52 +0100 Subject: [PATCH 164/271] code duplication, lazy_spell was almost the same as spellref. --- src/kernel/equipment.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 00f8c2f95..6b74121ff 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -87,8 +87,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value) } typedef struct lazy_spell { - char *name; - struct spell *sp; + struct spellref *spref; int level; } lazy_spell; @@ -96,9 +95,8 @@ void equipment_addspell(equipment * eq, const char * name, int level) { if (eq) { lazy_spell *ls = malloc(sizeof(lazy_spell)); - ls->sp = NULL; + ls->spref = spellref_create(NULL, name); ls->level = level; - ls->name = strdup(name); selist_push(&eq->spells, ls); } } @@ -162,12 +160,8 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { lazy_spell *sbe = (lazy_spell *)selist_get(ql, qi); - if (!sbe->sp) { - sbe->sp = find_spell(sbe->name); - free(sbe->name); - sbe->name = NULL; - } - unit_add_spell(u, mage, sbe->sp, sbe->level); + spell *sp = spellref_get(sbe->spref); + unit_add_spell(u, mage, sp, sbe->level); } } } @@ -238,7 +232,7 @@ void equip_items(struct item **items, const struct equipment *eq) void free_ls(void *arg) { lazy_spell *ls = (lazy_spell*)arg; - free(ls->name); + spellref_free(ls->spref); free(ls); } From 7009f26ee51652eb352574d7455162a68d8554e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Feb 2017 20:12:52 +0100 Subject: [PATCH 165/271] code duplication, lazy_spell was almost the same as spellref. --- src/kernel/equipment.c | 16 +++++----------- src/kernel/xmlreader.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 00f8c2f95..6b74121ff 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -87,8 +87,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value) } typedef struct lazy_spell { - char *name; - struct spell *sp; + struct spellref *spref; int level; } lazy_spell; @@ -96,9 +95,8 @@ void equipment_addspell(equipment * eq, const char * name, int level) { if (eq) { lazy_spell *ls = malloc(sizeof(lazy_spell)); - ls->sp = NULL; + ls->spref = spellref_create(NULL, name); ls->level = level; - ls->name = strdup(name); selist_push(&eq->spells, ls); } } @@ -162,12 +160,8 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { lazy_spell *sbe = (lazy_spell *)selist_get(ql, qi); - if (!sbe->sp) { - sbe->sp = find_spell(sbe->name); - free(sbe->name); - sbe->name = NULL; - } - unit_add_spell(u, mage, sbe->sp, sbe->level); + spell *sp = spellref_get(sbe->spref); + unit_add_spell(u, mage, sp, sbe->level); } } } @@ -238,7 +232,7 @@ void equip_items(struct item **items, const struct equipment *eq) void free_ls(void *arg) { lazy_spell *ls = (lazy_spell*)arg; - free(ls->name); + spellref_free(ls->spref); free(ls); } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 4225858ee..854a6dd4c 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -2068,17 +2068,20 @@ static int parse_strings(xmlDocPtr doc) void register_xmlreader(void) { - xml_register_callback(parse_strings); - xml_register_callback(parse_messages); - xml_register_callback(parse_resources); xml_register_callback(parse_rules); - xml_register_callback(parse_buildings); /* requires resources */ - xml_register_callback(parse_ships); /* requires terrains */ xml_register_callback(parse_races); xml_register_callback(parse_calendar); - xml_register_callback(parse_spells); /* requires resources */ - xml_register_callback(parse_equipment); /* requires spells */ + xml_register_callback(parse_resources); + + xml_register_callback(parse_buildings); /* requires resources */ + xml_register_callback(parse_ships); /* requires resources, terrains */ + xml_register_callback(parse_equipment); /* requires resources */ + + xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_spellbooks); /* requires spells */ + + xml_register_callback(parse_strings); + xml_register_callback(parse_messages); } #endif From 7750297dc2a340a256bf773a39697f0cfacb1ef1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 10:57:32 +0100 Subject: [PATCH 166/271] express race.magres as percentage, not probability (double->int) --- res/e3a/races.xml | 102 ++++++++++++++--------------- res/eressea/races.xml | 130 ++++++++++++++++++------------------- res/races/aquarian.xml | 2 +- res/races/cat.xml | 2 +- res/races/demon.xml | 2 +- res/races/dragon.xml | 2 +- res/races/dwarf.xml | 2 +- res/races/elf.xml | 2 +- res/races/goblin-2.xml | 2 +- res/races/goblin-3.xml | 2 +- res/races/goblin.xml | 2 +- res/races/halfling.xml | 2 +- res/races/human.xml | 2 +- res/races/insect.xml | 2 +- res/races/orc.xml | 2 +- res/races/troll.xml | 2 +- res/races/wyrm.xml | 2 +- res/races/youngdragon.xml | 2 +- res/races/zombie.xml | 2 +- src/battle.test.c | 4 +- src/kernel/jsonconf.c | 2 +- src/kernel/jsonconf.test.c | 5 +- src/kernel/race.c | 4 ++ src/kernel/race.h | 3 +- src/kernel/race.test.c | 3 +- src/kernel/xmlreader.c | 2 +- src/magic.c | 2 +- src/magic.test.c | 6 +- 28 files changed, 152 insertions(+), 145 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 2b0f68b9d..3402fdb73 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -8,7 +8,7 @@ - + @@ -32,7 +32,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -124,7 +124,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -192,7 +192,7 @@ - + @@ -219,7 +219,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -263,7 +263,7 @@ - + @@ -287,7 +287,7 @@ - + @@ -311,7 +311,7 @@ - + @@ -334,7 +334,7 @@ - + @@ -361,7 +361,7 @@ - + @@ -384,7 +384,7 @@ - + @@ -409,7 +409,7 @@ - + @@ -435,7 +435,7 @@ - + @@ -460,7 +460,7 @@ - + @@ -484,7 +484,7 @@ - + @@ -507,7 +507,7 @@ - + @@ -535,7 +535,7 @@ - + @@ -559,7 +559,7 @@ - + @@ -582,7 +582,7 @@ - + @@ -607,16 +607,16 @@ - + - + - + @@ -624,7 +624,7 @@ - + @@ -672,47 +672,47 @@ - + - + - + - + - + - + - + - + @@ -720,21 +720,21 @@ - + - + - + @@ -742,7 +742,7 @@ - + @@ -768,7 +768,7 @@ - + @@ -787,7 +787,7 @@ - + @@ -806,7 +806,7 @@ - + @@ -823,7 +823,7 @@ - + @@ -839,7 +839,7 @@ - + @@ -855,7 +855,7 @@ - + @@ -871,13 +871,13 @@ - + - + @@ -890,7 +890,7 @@ - + @@ -898,7 +898,7 @@ - + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 2ef5950c9..e4e22d0c3 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1,7 +1,7 @@ - - + @@ -27,7 +27,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -118,7 +118,7 @@ - + @@ -148,7 +148,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -209,7 +209,7 @@ - + @@ -244,7 +244,7 @@ - + @@ -275,7 +275,7 @@ - + @@ -308,7 +308,7 @@ - + @@ -339,7 +339,7 @@ - + @@ -370,7 +370,7 @@ - + @@ -401,7 +401,7 @@ - + @@ -431,7 +431,7 @@ - + @@ -463,7 +463,7 @@ - + @@ -495,7 +495,7 @@ - + @@ -525,7 +525,7 @@ - + @@ -558,7 +558,7 @@ - + @@ -589,16 +589,16 @@ - + - + - @@ -607,7 +607,7 @@ - + @@ -671,66 +671,66 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -742,7 +742,7 @@ - + @@ -755,7 +755,7 @@ - + @@ -769,20 +769,20 @@ - + - + - + @@ -801,7 +801,7 @@ - + @@ -827,7 +827,7 @@ - + @@ -860,7 +860,7 @@ - + @@ -889,7 +889,7 @@ - + @@ -921,7 +921,7 @@ - + @@ -978,7 +978,7 @@ - + @@ -1011,11 +1011,11 @@ - + - + @@ -1023,7 +1023,7 @@ - + @@ -1037,7 +1037,7 @@ - + @@ -1055,7 +1055,7 @@ - + @@ -1073,7 +1073,7 @@ - + @@ -1089,7 +1089,7 @@ - + @@ -1104,7 +1104,7 @@ - + @@ -1119,7 +1119,7 @@ - + @@ -1134,12 +1134,12 @@ - + - + @@ -1151,7 +1151,7 @@ - @@ -1182,7 +1182,7 @@ - + @@ -1209,7 +1209,7 @@ - + @@ -1241,7 +1241,7 @@ - + @@ -1271,7 +1271,7 @@ - + @@ -1285,13 +1285,13 @@ - + - + @@ -1300,7 +1300,7 @@ - + diff --git a/res/races/aquarian.xml b/res/races/aquarian.xml index 776f17e93..a0e1189b7 100644 --- a/res/races/aquarian.xml +++ b/res/races/aquarian.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/cat.xml b/res/races/cat.xml index 818b24b36..75bc8019a 100644 --- a/res/races/cat.xml +++ b/res/races/cat.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/demon.xml b/res/races/demon.xml index a350fef4a..0ce4c86ff 100644 --- a/res/races/demon.xml +++ b/res/races/demon.xml @@ -1,5 +1,5 @@ - - + diff --git a/res/races/elf.xml b/res/races/elf.xml index dfbd2f2ec..ee1278a26 100644 --- a/res/races/elf.xml +++ b/res/races/elf.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/goblin-2.xml b/res/races/goblin-2.xml index 9a9c265be..ae90c1918 100644 --- a/res/races/goblin-2.xml +++ b/res/races/goblin-2.xml @@ -1,5 +1,5 @@ - - - - + diff --git a/res/races/human.xml b/res/races/human.xml index 2e4b94af2..8f1ad5cb4 100644 --- a/res/races/human.xml +++ b/res/races/human.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/insect.xml b/res/races/insect.xml index cecbf0193..dc9faa06d 100644 --- a/res/races/insect.xml +++ b/res/races/insect.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/orc.xml b/res/races/orc.xml index d9d26ab25..4f4d96ed5 100644 --- a/res/races/orc.xml +++ b/res/races/orc.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/troll.xml b/res/races/troll.xml index a2341851b..c70020fa2 100644 --- a/res/races/troll.xml +++ b/res/races/troll.xml @@ -1,5 +1,5 @@ - -magres = 0.5; /* gets added to skill bonus */ + rc->_magres = 50; /* percentage, gets added to skill bonus */ calculate_armor(dt, 0, 0, &magres); CuAssertDblEquals_Msg(tc, "race bonus", 0.6, magic_resistance(du), 0.01); CuAssertDblEquals_Msg(tc, "race reduction", 0.4, magres, 0.01); - rc->magres = 1.5; /* should not cause negative damage multiplier */ + rc->_magres = 150; /* should not cause negative damage multiplier */ CuAssertDblEquals_Msg(tc, "magic resistance is never > 0.9", 0.9, magic_resistance(du), 0.01); calculate_armor(dt, 0, 0, &magres); CuAssertDblEquals_Msg(tc, "damage reduction is never < 0.1", 0.1, magres, 0.01); diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 03e210ce0..0cfba4e34 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -458,7 +458,7 @@ static void json_race(cJSON *json, race *rc) { break; case cJSON_Number: if (strcmp(child->string, "magres") == 0) { - rc->magres = (float)child->valuedouble; + rc->_magres = child->valueint; } else if (strcmp(child->string, "maxaura") == 0) { rc->maxaura = (float)child->valuedouble; diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 93fcd8d10..7ac6a93cc 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -136,7 +136,7 @@ static void test_races(CuTest * tc) { const char * data = "{\"races\": { \"orc\" : { " "\"damage\" : \"1d4\"," - "\"magres\" : 1.0," + "\"magres\" : 100," "\"maxaura\" : 2.0," "\"regaura\" : 3.0," "\"speed\" : 4.0," @@ -163,7 +163,8 @@ static void test_races(CuTest * tc) CuAssertPtrNotNull(tc, rc); CuAssertIntEquals(tc, RCF_NPC | RCF_WALK | RCF_UNDEAD, rc->flags); CuAssertStrEquals(tc, "1d4", rc->def_damage); - CuAssertDblEquals(tc, 1.0, rc->magres, 0.0); + CuAssertIntEquals(tc, 100, rc->_magres); + CuAssertDblEquals(tc, 1.0, rc_magres(rc), 0.0); CuAssertDblEquals(tc, 2.0, rc->maxaura, 0.0); CuAssertDblEquals(tc, 3.0, rc->regaura, 0.0); CuAssertDblEquals(tc, 4.0, rc->speed, 0.0); diff --git a/src/kernel/race.c b/src/kernel/race.c index 1bdba8a1b..3dc708ed1 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -282,6 +282,10 @@ bool r_insectstalled(const region * r) return fval(r->terrain, ARCTIC_REGION); } +double rc_magres(const struct race *rc) { + return rc->_magres / 100.0; +} + const char* rc_name(const race * rc, name_t n, char *name, size_t size) { const char * postfix = 0; if (!rc) { diff --git a/src/kernel/race.h b/src/kernel/race.h index 19b7b7ad3..72e1269c9 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -116,7 +116,7 @@ extern "C" { typedef struct race { char *_name; - float magres; + int _magres; float healing; double maxaura; /* Faktor auf Maximale Aura */ double regaura; /* Faktor auf Regeneration */ @@ -184,6 +184,7 @@ extern "C" { const char * rc_name_s(const race *rc, name_t n); const char * rc_name(const race *rc, name_t n, char *name, size_t size); + double rc_magres(const struct race *rc); /* Flags. Do not reorder these without changing json_race() in jsonconf.c */ #define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */ #define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */ diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index 663a538ee..d40f252bc 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -23,7 +23,8 @@ static void test_rc_defaults(CuTest *tc) { test_setup(); rc = rc_get_or_create("human"); CuAssertStrEquals(tc, "human", rc->_name); - CuAssertDblEquals(tc, 0.0, rc->magres, 0.0); + CuAssertIntEquals(tc, 0, rc->_magres); + CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0); CuAssertDblEquals(tc, 0.0, rc->maxaura, 0.0); CuAssertDblEquals(tc, 1.0, rc->recruit_multi, 0.0); CuAssertDblEquals(tc, 1.0, rc->regaura, 0.0); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 854a6dd4c..3d7276bf3 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1635,7 +1635,7 @@ static int parse_races(xmlDocPtr doc) rc->def_damage = strdup((const char *)propValue); xmlFree(propValue); - rc->magres = (float)xml_fvalue(node, "magres", rc->magres); + rc->_magres = xml_ivalue(node, "magres", rc->_magres); rc->healing = (float)xml_fvalue(node, "healing", rc->healing); rc->maxaura = (float)xml_fvalue(node, "maxaura", rc->maxaura); rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura); diff --git a/src/magic.c b/src/magic.c index 7e820f9c3..e48ec6d5d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1149,7 +1149,7 @@ double magic_resistance(unit * target) const curse_type * ct_goodresist = 0, *ct_badresist = 0; const resource_type *rtype; const race *rc = u_race(target); - double probability = rc->magres; + double probability = rc_magres(rc); const plane *pl = rplane(target->region); if (rc == get_race(RC_HIRNTOETER) && !pl) { diff --git a/src/magic.test.c b/src/magic.test.c index befd1986d..29534b33b 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -413,11 +413,11 @@ static void test_magic_resistance(CuTest *tc) { test_setup(); rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); - CuAssertDblEquals(tc, rc->magres, magic_resistance(u), 0.01); - rc->magres = 1.0; + CuAssertDblEquals(tc, rc->_magres/100.0, magic_resistance(u), 0.01); + rc->_magres = 100; CuAssertDblEquals_Msg(tc, "magic resistance is capped at 0.9", 0.9, magic_resistance(u), 0.01); rc = test_create_race("braineater"); - rc->magres = 1.0; + rc->_magres = 100; u_setrace(u, rc); CuAssertDblEquals_Msg(tc, "brain eaters outside astral space have 50% magres", 0.5, magic_resistance(u), 0.01); u->region->_plane = get_astralplane(); From fd9583df3d5b72715344fd80fa732c6a9368ce13 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 17:43:40 +0100 Subject: [PATCH 167/271] fix healing for elves in a forest. rename _magres back to magres. rc->parameters is not linked to config_changed invalidation. add tests. --- src/battle.test.c | 4 ++-- src/kernel/jsonconf.c | 2 +- src/kernel/jsonconf.test.c | 2 +- src/kernel/race.c | 2 +- src/kernel/race.h | 2 +- src/kernel/race.test.c | 3 ++- src/kernel/unit.c | 22 ++++++++++++++++++++++ src/kernel/unit.h | 1 + src/kernel/unit.test.c | 28 ++++++++++++++++++++++++++++ src/kernel/xmlreader.c | 2 +- src/laws.c | 26 +------------------------- src/magic.test.c | 6 +++--- src/tests.c | 3 +++ 13 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/battle.test.c b/src/battle.test.c index 155b3ae0c..03535e16e 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -352,12 +352,12 @@ static void test_magic_resistance(CuTest *tc) calculate_armor(dt, 0, 0, &magres); CuAssertDblEquals_Msg(tc, "skill bonus", 0.1, magic_resistance(du), 0.01); CuAssertDblEquals_Msg(tc, "skill reduction", 0.9, magres, 0.01); - rc->_magres = 50; /* percentage, gets added to skill bonus */ + rc->magres = 50; /* percentage, gets added to skill bonus */ calculate_armor(dt, 0, 0, &magres); CuAssertDblEquals_Msg(tc, "race bonus", 0.6, magic_resistance(du), 0.01); CuAssertDblEquals_Msg(tc, "race reduction", 0.4, magres, 0.01); - rc->_magres = 150; /* should not cause negative damage multiplier */ + rc->magres = 150; /* should not cause negative damage multiplier */ CuAssertDblEquals_Msg(tc, "magic resistance is never > 0.9", 0.9, magic_resistance(du), 0.01); calculate_armor(dt, 0, 0, &magres); CuAssertDblEquals_Msg(tc, "damage reduction is never < 0.1", 0.1, magres, 0.01); diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 0cfba4e34..dcc4c9c0c 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -458,7 +458,7 @@ static void json_race(cJSON *json, race *rc) { break; case cJSON_Number: if (strcmp(child->string, "magres") == 0) { - rc->_magres = child->valueint; + rc->magres = child->valueint; } else if (strcmp(child->string, "maxaura") == 0) { rc->maxaura = (float)child->valuedouble; diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 7ac6a93cc..5b0590bf8 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -163,7 +163,7 @@ static void test_races(CuTest * tc) CuAssertPtrNotNull(tc, rc); CuAssertIntEquals(tc, RCF_NPC | RCF_WALK | RCF_UNDEAD, rc->flags); CuAssertStrEquals(tc, "1d4", rc->def_damage); - CuAssertIntEquals(tc, 100, rc->_magres); + CuAssertIntEquals(tc, 100, rc->magres); CuAssertDblEquals(tc, 1.0, rc_magres(rc), 0.0); CuAssertDblEquals(tc, 2.0, rc->maxaura, 0.0); CuAssertDblEquals(tc, 3.0, rc->regaura, 0.0); diff --git a/src/kernel/race.c b/src/kernel/race.c index 3dc708ed1..16eff8695 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -283,7 +283,7 @@ bool r_insectstalled(const region * r) } double rc_magres(const struct race *rc) { - return rc->_magres / 100.0; + return rc->magres / 100.0; } const char* rc_name(const race * rc, name_t n, char *name, size_t size) { diff --git a/src/kernel/race.h b/src/kernel/race.h index 72e1269c9..853e1041f 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -116,7 +116,7 @@ extern "C" { typedef struct race { char *_name; - int _magres; + int magres; float healing; double maxaura; /* Faktor auf Maximale Aura */ double regaura; /* Faktor auf Regeneration */ diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index d40f252bc..c07808099 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -23,8 +23,9 @@ static void test_rc_defaults(CuTest *tc) { test_setup(); rc = rc_get_or_create("human"); CuAssertStrEquals(tc, "human", rc->_name); - CuAssertIntEquals(tc, 0, rc->_magres); + CuAssertIntEquals(tc, 0, rc->magres); CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0); + CuAssertDblEquals(tc, 0.0, rc->healing, 0.0); CuAssertDblEquals(tc, 0.0, rc->maxaura, 0.0); CuAssertDblEquals(tc, 1.0, rc->recruit_multi, 0.0); CuAssertDblEquals(tc, 1.0, rc->regaura, 0.0); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 29766d4ef..354a52a06 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -2047,3 +2047,25 @@ bool has_limited_skills(const struct unit * u) return false; } +double u_heal_factor(const unit * u) +{ + const race * rc = u_race(u); + if (rc->healing>0) { + return rc->healing; + } + if (r_isforest(u->region)) { + static int rc_cache; + static const race *rc_elf; + if (rc_changed(&rc_cache)) { + rc_elf = get_race(RC_ELF); + } + if (rc == rc_elf) { + double elf_regen = 1.0; + if (rc->parameters) { + elf_regen = get_param_flt(rc->parameters, "regen.forest", elf_regen); + } + return elf_regen; + } + } + return 1.0; +} diff --git a/src/kernel/unit.h b/src/kernel/unit.h index e846ca1f4..14096c872 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -190,6 +190,7 @@ extern "C" { bool leave(struct unit *u, bool force); bool can_leave(struct unit *u); + double u_heal_factor(const struct unit * u); void u_set_building(struct unit * u, struct building * b); void u_set_ship(struct unit * u, struct ship * sh); void leave_ship(struct unit * u); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index b0a2891c5..ad4e1761a 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -483,6 +484,32 @@ static void test_name_unit(CuTest *tc) { test_cleanup(); } +static void test_heal_factor(CuTest *tc) { + unit * u; + region *r; + race *rc; + terrain_type *t_plain; + + test_setup(); + t_plain = test_create_terrain("plain", LAND_REGION|FOREST_REGION); + rc = rc_get_or_create("human"); + u = test_create_unit(test_create_faction(rc), r = test_create_region(0, 0, t_plain)); + rsettrees(r, 1, r->terrain->size / TREESIZE); + rsettrees(r, 2, 0); + CuAssertTrue(tc, r_isforest(r)); + CuAssertDblEquals(tc, 1.0, u_heal_factor(u), 0.0); + rc->healing = 2.0; + CuAssertDblEquals(tc, 2.0, u_heal_factor(u), 0.0); + rc->healing = 0.0; + rc = rc_get_or_create("elf"); + CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_ELF)); + u_setrace(u, get_race(RC_ELF)); + CuAssertDblEquals(tc, 1.0, u_heal_factor(u), 0.0); + set_param(&rc->parameters, "regen.forest", "1.5"); + CuAssertDblEquals(tc, 1.5, u_heal_factor(u), 0.0); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -507,5 +534,6 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_limited_skills); SUITE_ADD_TEST(suite, test_renumber_unit); SUITE_ADD_TEST(suite, test_name_unit); + SUITE_ADD_TEST(suite, test_heal_factor); return suite; } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 3d7276bf3..87771ba6b 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1635,7 +1635,7 @@ static int parse_races(xmlDocPtr doc) rc->def_damage = strdup((const char *)propValue); xmlFree(propValue); - rc->_magres = xml_ivalue(node, "magres", rc->_magres); + rc->magres = xml_ivalue(node, "magres", rc->magres); rc->healing = (float)xml_fvalue(node, "healing", rc->healing); rc->maxaura = (float)xml_fvalue(node, "maxaura", rc->maxaura); rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura); diff --git a/src/laws.c b/src/laws.c index 6b0bfda8d..98ff5d9f6 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3271,30 +3271,6 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order } } -static double heal_factor(const unit * u) -{ - const race * rc = u_race(u); - if (rc->healing>0) { - return rc->healing; - } - if (r_isforest(u->region)) { - static int rc_cache; - static const race *rc_elf; - if (rc_changed(&rc_cache)) { - rc_elf = get_race(RC_ELF); - } - if (rc==rc_elf) { - static int config; - static double elf_regen = 1.0; - if (config_changed(&config)) { - elf_regen = get_param_flt(u_race(u)->parameters, "regen.forest", 1.0F); - } - return elf_regen; - } - } - return 1.0; -} - void monthly_healing(void) { region *r; @@ -3334,7 +3310,7 @@ void monthly_healing(void) continue; } - p *= heal_factor(u); + p *= u_heal_factor(u); if (u->hp < umhp) { double maxheal = MAX(u->number, umhp / 20.0); int addhp; diff --git a/src/magic.test.c b/src/magic.test.c index 29534b33b..b32211fd4 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -413,11 +413,11 @@ static void test_magic_resistance(CuTest *tc) { test_setup(); rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); - CuAssertDblEquals(tc, rc->_magres/100.0, magic_resistance(u), 0.01); - rc->_magres = 100; + CuAssertDblEquals(tc, rc->magres/100.0, magic_resistance(u), 0.01); + rc->magres = 100; CuAssertDblEquals_Msg(tc, "magic resistance is capped at 0.9", 0.9, magic_resistance(u), 0.01); rc = test_create_race("braineater"); - rc->_magres = 100; + rc->magres = 100; u_setrace(u, rc); CuAssertDblEquals_Msg(tc, "brain eaters outside astral space have 50% magres", 0.5, magic_resistance(u), 0.01); u->region->_plane = get_astralplane(); diff --git a/src/tests.c b/src/tests.c index eb2631afe..5c9ce821d 100644 --- a/src/tests.c +++ b/src/tests.c @@ -217,6 +217,9 @@ terrain_type * test_create_terrain(const char * name, unsigned int flags) { terrain_type * t = get_or_create_terrain(name); + if (flags & LAND_REGION) { + t->size = 1000; + } t->flags = flags; return t; } From 1c347ca5ba8e765246435d361e44f9451ddbc94b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 18:18:55 +0100 Subject: [PATCH 168/271] race.healing is now an int percentage, not a float multiplier --- src/kernel/race.h | 2 +- src/kernel/race.test.c | 2 +- src/kernel/unit.c | 2 +- src/kernel/unit.test.c | 4 ++-- src/kernel/xmlreader.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kernel/race.h b/src/kernel/race.h index 853e1041f..a7d495f6b 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -117,7 +117,7 @@ extern "C" { typedef struct race { char *_name; int magres; - float healing; + int healing; double maxaura; /* Faktor auf Maximale Aura */ double regaura; /* Faktor auf Regeneration */ double recruit_multi; /* Faktor f�r Bauernverbrauch */ diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index c07808099..01ce41443 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -25,7 +25,7 @@ static void test_rc_defaults(CuTest *tc) { CuAssertStrEquals(tc, "human", rc->_name); CuAssertIntEquals(tc, 0, rc->magres); CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0); - CuAssertDblEquals(tc, 0.0, rc->healing, 0.0); + CuAssertIntEquals(tc, 0, rc->healing); CuAssertDblEquals(tc, 0.0, rc->maxaura, 0.0); CuAssertDblEquals(tc, 1.0, rc->recruit_multi, 0.0); CuAssertDblEquals(tc, 1.0, rc->regaura, 0.0); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 354a52a06..329a523c6 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -2051,7 +2051,7 @@ double u_heal_factor(const unit * u) { const race * rc = u_race(u); if (rc->healing>0) { - return rc->healing; + return rc->healing / 100.0; } if (r_isforest(u->region)) { static int rc_cache; diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index ad4e1761a..bf4e9a389 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -498,9 +498,9 @@ static void test_heal_factor(CuTest *tc) { rsettrees(r, 2, 0); CuAssertTrue(tc, r_isforest(r)); CuAssertDblEquals(tc, 1.0, u_heal_factor(u), 0.0); - rc->healing = 2.0; + rc->healing = 200; CuAssertDblEquals(tc, 2.0, u_heal_factor(u), 0.0); - rc->healing = 0.0; + rc->healing = 0; rc = rc_get_or_create("elf"); CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_ELF)); u_setrace(u, get_race(RC_ELF)); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 87771ba6b..638dae189 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1636,7 +1636,7 @@ static int parse_races(xmlDocPtr doc) xmlFree(propValue); rc->magres = xml_ivalue(node, "magres", rc->magres); - rc->healing = (float)xml_fvalue(node, "healing", rc->healing); + rc->healing = (int)(xml_fvalue(node, "healing", rc->healing) * 100); // TODO: store as int in XML rc->maxaura = (float)xml_fvalue(node, "maxaura", rc->maxaura); rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura); rc->recruitcost = xml_ivalue(node, "recruitcost", rc->recruitcost); From f22cc3b419bb1349f46eedd9e35a85e138842c6f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 19:47:30 +0100 Subject: [PATCH 169/271] add a test for max_spellpoints --- src/magic.test.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/magic.test.c b/src/magic.test.c index b32211fd4..e2c25bf81 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -425,6 +425,29 @@ static void test_magic_resistance(CuTest *tc) { test_cleanup(); } +static void test_max_spellpoints(CuTest *tc) { + unit *u; + race *rc; + + test_setup(); + rc = test_create_race("human"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + CuAssertIntEquals(tc, 1, max_spellpoints(u->region, u)); + rc->maxaura = 1.0; + CuAssertIntEquals(tc, 1, max_spellpoints(u->region, u)); + rc->maxaura = 2.0; + CuAssertIntEquals(tc, 2, max_spellpoints(u->region, u)); + create_mage(u, M_GRAY); + set_level(u, SK_MAGIC, 1); + CuAssertIntEquals(tc, 3, max_spellpoints(u->region, u)); + set_level(u, SK_MAGIC, 2); + CuAssertIntEquals(tc, 9, max_spellpoints(u->region, u)); + // permanent aura loss: + CuAssertIntEquals(tc, 7, change_maxspellpoints(u, -2)); + CuAssertIntEquals(tc, 7, max_spellpoints(u->region, u)); + test_cleanup(); +} + CuSuite *get_magic_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -441,5 +464,6 @@ CuSuite *get_magic_suite(void) SUITE_ADD_TEST(suite, test_set_post_combatspell); SUITE_ADD_TEST(suite, test_hasspell); SUITE_ADD_TEST(suite, test_magic_resistance); + SUITE_ADD_TEST(suite, test_max_spellpoints); return suite; } From e51742da9052b018c0fb0020d4652b4045c69940 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 19:50:48 +0100 Subject: [PATCH 170/271] use rc_maxaura wrapper everywhere. --- src/kernel/race.c | 6 +++++- src/kernel/race.h | 1 + src/kernel/race.test.c | 2 +- src/magic.c | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index 16eff8695..75ff16436 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -282,10 +282,14 @@ bool r_insectstalled(const region * r) return fval(r->terrain, ARCTIC_REGION); } -double rc_magres(const struct race *rc) { +double rc_magres(const race *rc) { return rc->magres / 100.0; } +double rc_maxaura(const race *rc) { + return rc->maxaura; +} + const char* rc_name(const race * rc, name_t n, char *name, size_t size) { const char * postfix = 0; if (!rc) { diff --git a/src/kernel/race.h b/src/kernel/race.h index a7d495f6b..7acc7fea5 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -185,6 +185,7 @@ extern "C" { const char * rc_name(const race *rc, name_t n, char *name, size_t size); double rc_magres(const struct race *rc); + double rc_maxaura(const struct race *rc); /* Flags. Do not reorder these without changing json_race() in jsonconf.c */ #define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */ #define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */ diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index 01ce41443..eaf497168 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -26,7 +26,7 @@ static void test_rc_defaults(CuTest *tc) { CuAssertIntEquals(tc, 0, rc->magres); CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0); CuAssertIntEquals(tc, 0, rc->healing); - CuAssertDblEquals(tc, 0.0, rc->maxaura, 0.0); + CuAssertDblEquals(tc, 0.0, rc_maxaura(rc), 0.0); CuAssertDblEquals(tc, 1.0, rc->recruit_multi, 0.0); CuAssertDblEquals(tc, 1.0, rc->regaura, 0.0); CuAssertDblEquals(tc, 1.0, rc->speed, 0.0); diff --git a/src/magic.c b/src/magic.c index e48ec6d5d..89774e96a 100644 --- a/src/magic.c +++ b/src/magic.c @@ -719,7 +719,7 @@ static int use_item_aura(const region * r, const unit * u) int sk, n; sk = effskill(u, SK_MAGIC, r); - n = (int)(sk * sk * u_race(u)->maxaura / 4); + n = (int)(sk * sk * rc_maxaura(u_race(u)) / 4); return n; } @@ -727,13 +727,13 @@ static int use_item_aura(const region * r, const unit * u) int max_spellpoints(const region * r, const unit * u) { int sk; - double n, msp; + double n, msp = 0; double potenz = 2.1; double divisor = 1.2; const struct resource_type *rtype; sk = effskill(u, SK_MAGIC, r); - msp = u_race(u)->maxaura * (pow(sk, potenz) / divisor + 1) + get_spchange(u); + msp = rc_maxaura(u_race(u)) * (pow(sk, potenz) / divisor + 1) + get_spchange(u); rtype = rt_find("aurafocus"); if (rtype && i_get(u->items, rtype->itype) > 0) { From 250227cad245707c8ed17857eabb9143c6b6ca07 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 20:06:01 +0100 Subject: [PATCH 171/271] store maxaura as an integer, not a float. --- src/kernel/jsonconf.c | 2 +- src/kernel/jsonconf.test.c | 5 +++-- src/kernel/race.c | 2 +- src/kernel/race.h | 2 +- src/kernel/xmlreader.c | 2 +- src/magic.test.c | 4 ++-- src/tests.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index dcc4c9c0c..7a074a410 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -461,7 +461,7 @@ static void json_race(cJSON *json, race *rc) { rc->magres = child->valueint; } else if (strcmp(child->string, "maxaura") == 0) { - rc->maxaura = (float)child->valuedouble; + rc->maxaura = child->valueint; } else if (strcmp(child->string, "regaura") == 0) { rc->regaura = (float)child->valuedouble; diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 5b0590bf8..7c591f075 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -137,7 +137,7 @@ static void test_races(CuTest * tc) const char * data = "{\"races\": { \"orc\" : { " "\"damage\" : \"1d4\"," "\"magres\" : 100," - "\"maxaura\" : 2.0," + "\"maxaura\" : 200," "\"regaura\" : 3.0," "\"speed\" : 4.0," "\"recruitcost\" : 1," @@ -165,7 +165,8 @@ static void test_races(CuTest * tc) CuAssertStrEquals(tc, "1d4", rc->def_damage); CuAssertIntEquals(tc, 100, rc->magres); CuAssertDblEquals(tc, 1.0, rc_magres(rc), 0.0); - CuAssertDblEquals(tc, 2.0, rc->maxaura, 0.0); + CuAssertIntEquals(tc, 200, rc->maxaura); + CuAssertDblEquals(tc, 2.0, rc_maxaura(rc), 0.0); CuAssertDblEquals(tc, 3.0, rc->regaura, 0.0); CuAssertDblEquals(tc, 4.0, rc->speed, 0.0); CuAssertIntEquals(tc, 1, rc->recruitcost); diff --git a/src/kernel/race.c b/src/kernel/race.c index 75ff16436..59d263108 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -287,7 +287,7 @@ double rc_magres(const race *rc) { } double rc_maxaura(const race *rc) { - return rc->maxaura; + return rc->maxaura / 100.0; } const char* rc_name(const race * rc, name_t n, char *name, size_t size) { diff --git a/src/kernel/race.h b/src/kernel/race.h index 7acc7fea5..82d8cdf69 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -118,7 +118,7 @@ extern "C" { char *_name; int magres; int healing; - double maxaura; /* Faktor auf Maximale Aura */ + int maxaura; /* Faktor auf Maximale Aura */ double regaura; /* Faktor auf Regeneration */ double recruit_multi; /* Faktor f�r Bauernverbrauch */ int index; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 638dae189..d75a6583f 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1637,7 +1637,7 @@ static int parse_races(xmlDocPtr doc) rc->magres = xml_ivalue(node, "magres", rc->magres); rc->healing = (int)(xml_fvalue(node, "healing", rc->healing) * 100); // TODO: store as int in XML - rc->maxaura = (float)xml_fvalue(node, "maxaura", rc->maxaura); + rc->maxaura = (int)(xml_fvalue(node, "maxaura", rc->maxaura) * 100); // TODO: store as int in XML rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura); rc->recruitcost = xml_ivalue(node, "recruitcost", rc->recruitcost); rc->maintenance = xml_ivalue(node, "maintenance", rc->maintenance); diff --git a/src/magic.test.c b/src/magic.test.c index e2c25bf81..4a6078589 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -433,9 +433,9 @@ static void test_max_spellpoints(CuTest *tc) { rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); CuAssertIntEquals(tc, 1, max_spellpoints(u->region, u)); - rc->maxaura = 1.0; + rc->maxaura = 100; CuAssertIntEquals(tc, 1, max_spellpoints(u->region, u)); - rc->maxaura = 2.0; + rc->maxaura = 200; CuAssertIntEquals(tc, 2, max_spellpoints(u->region, u)); create_mage(u, M_GRAY); set_level(u, SK_MAGIC, 1); diff --git a/src/tests.c b/src/tests.c index 5c9ce821d..6a43e6e79 100644 --- a/src/tests.c +++ b/src/tests.c @@ -40,7 +40,7 @@ struct race *test_create_race(const char *name) race *rc = rc_get_or_create(name); rc->maintenance = 10; rc->hitpoints = 20; - rc->maxaura = 1.0; + rc->maxaura = 100; rc->ec_flags |= GETITEM; rc->battle_flags = BF_EQUIPMENT; return rc; From 70b12ae6ca9fc34ed124db53d8e1b41a78736e16 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 20:16:44 +0100 Subject: [PATCH 172/271] refactor handling of race.param in XML --- src/kernel/faction.c | 2 +- src/kernel/xmlreader.c | 23 +++++++++++------------ src/upkeep.c | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b7115c62f..e3cb4508a 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -758,7 +758,7 @@ int count_migrants(const faction * f) int count_maxmigrants(const faction * f) { - int formula = get_param_int(f->race->parameters, "migrants.formula", 0); + int formula = f->race->parameters ? get_param_int(f->race->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE; if (formula == MIGRANTS_LOG10) { int nsize = count_all(f); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index d75a6583f..9b1f5532c 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1573,17 +1573,6 @@ static int parse_spells(xmlDocPtr doc) return 0; } -static void parse_param(struct param **params, xmlNodePtr node) -{ - xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - xmlChar *propValue = xmlGetProp(node, BAD_CAST "value"); - - set_param(params, (const char *)propName, (const char *)propValue); - - xmlFree(propName); - xmlFree(propValue); -} - static void parse_ai(race * rc, xmlNodePtr node) { int n; @@ -1737,12 +1726,22 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "noattack", false)) rc->battle_flags |= BF_NO_ATTACK; + rc->recruit_multi = 1.0; for (child = node->children; child; child = child->next) { if (strcmp((const char *)child->name, "ai") == 0) { parse_ai(rc, child); } else if (strcmp((const char *)child->name, "param") == 0) { - parse_param(&rc->parameters, child); + xmlChar *propName = xmlGetProp(child, BAD_CAST "name"); + xmlChar *propValue = xmlGetProp(child, BAD_CAST "value"); + if (strcmp((const char *)propName, "recruit_multi")==0) { + rc->recruit_multi = atof((const char *)propValue); + } + else { + set_param(&rc->parameters, (const char *)propName, (const char *)propValue); + } + xmlFree(propName); + xmlFree(propValue); } } rc->recruit_multi = get_param_flt(rc->parameters, "recruit_multi", 1.0); diff --git a/src/upkeep.c b/src/upkeep.c index 94cbc341d..c53c321d0 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -59,7 +59,7 @@ static void help_feed(unit * donor, unit * u, int *need_p) } static const char *hunger_damage(const race *rc) { - const char * damage = get_param(rc->parameters, "hunger.damage"); + const char * damage = rc->parameters ? get_param(rc->parameters, "hunger.damage") : NULL; if (!damage) { damage = config_get("hunger.damage"); } From bb37e423e1f434d2b8c707d9e4b5f16d8cc7c0de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 20:35:15 +0100 Subject: [PATCH 173/271] use UFL_FOLLOWED for optimization. --- src/move.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/move.c b/src/move.c index 0184d22ca..f06a0b901 100644 --- a/src/move.c +++ b/src/move.c @@ -2061,7 +2061,9 @@ static const region_list *travel_i(unit * u, const region_list * route_begin, route_end = cap_route(r, route_begin, route_end, movement_speed(u)); route_end = travel_route(u, route_begin, route_end, ord, mode); - get_followers(u, r, route_end, followers); + if (u->flags&UFL_FOLLOWED) { + get_followers(u, r, route_end, followers); + } /* transportation */ for (ord = u->orders; ord; ord = ord->next) { From 644a6019a62382246aee125c15f8d702acf0f094 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 21:19:39 +0100 Subject: [PATCH 174/271] do not call isdigit with a negative value. http://bugs.eressea.de/view.php?id=1987#c6941 --- src/spy.c | 2 +- src/util/base36.c | 4 ++-- src/util/dice.c | 2 +- src/util/parser.c | 4 ++-- src/util/translation.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/spy.c b/src/spy.c index eb58f792a..0ca3050c2 100644 --- a/src/spy.c +++ b/src/spy.c @@ -229,7 +229,7 @@ int setstealth_cmd(unit * u, struct order *ord) return 0; } - if (isdigit(s[0])) { + if (isdigit(*(const unsigned char *)s)) { /* Tarnungslevel setzen */ level = atoi((const char *)s); if (level > effskill(u, SK_STEALTH, 0)) { diff --git a/src/util/base36.c b/src/util/base36.c index 7edb46027..285e9760e 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -39,9 +39,9 @@ int atoi36(const char *str) while (isalnum(*(unsigned char *)s)) { if (isupper(*(unsigned char *)s)) i = i * 36 + (*s) - 'A' + 10; - else if (islower(*(unsigned char *)s)) + else if (islower(*s)) i = i * 36 + (*s) - 'a' + 10; - else if (isdigit(*(unsigned char *)s)) + else if (isdigit(*s)) i = i * 36 + (*s) - '0'; else break; diff --git a/src/util/dice.c b/src/util/dice.c index e28a4bccd..6fa50261d 100644 --- a/src/util/dice.c +++ b/src/util/dice.c @@ -49,7 +49,7 @@ static int term_eval(const char **sptr) int state = 1; for (;;) { - if (isdigit(*(unsigned char *)c)) { + if (isdigit(*(const unsigned char *)c)) { k = k * 10 + (*c - '0'); } else if (*c == '+' || *c == '-' || *c == 0 || *c == '*' || *c == ')' diff --git a/src/util/parser.c b/src/util/parser.c index bbdb5ac7e..fca066cb1 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -251,7 +250,8 @@ unsigned int atoip(const char *s) int n; assert(s); - n = isdigit(s[0]) ? atoi(s) : 0; + n = (s[0] >='0' && s[0]<='9'); + n = n ? atoi(s) : 0; if (n < 0) n = 0; diff --git a/src/util/translation.c b/src/util/translation.c index c733cc272..fb89a5af9 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -354,7 +354,7 @@ static const char *parse(opstack ** stack, const char *inn, return parse_symbol(stack, ++b, userdata); break; default: - if (isdigit(*(unsigned char *)b) || *b == '-' || *b == '+') { + if (isdigit(*(const unsigned char *)b) || *b == '-' || *b == '+') { return parse_int(stack, b); } else From 2be1868ff0471a9278abf510f6ac02756178286a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Feb 2017 21:48:03 +0100 Subject: [PATCH 175/271] Antiemagiekristall Meldung geht an die Region. Nicht nur an die Partei, die es zaubert. http://bugs.eressea.de/view.php?id=1987 --- res/core/messages.xml | 5 ++--- src/items.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 6892ec4e5..c28670d65 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1910,10 +1910,9 @@ - - "$unit($unit) benutzt in $region($region) einen Antimagiekristall." - "$unit($unit) uses an antimagic crystal in $region($region)." + "$unit($unit) benutzt einen Antimagiekristall." + "$unit($unit) uses an antimagic crystal." diff --git a/src/items.c b/src/items.c index 6e995edaa..bb5009038 100644 --- a/src/items.c +++ b/src/items.c @@ -167,8 +167,7 @@ struct order *ord) } } use_pooled(u, rt_crystal, GET_DEFAULT, amount); - ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal", - "unit region", u, r)); + ADDMSG(&u->region->msgs, msg_message("use_antimagiccrystal", "unit", u)); return 0; } From 2ecbf89f1a6e4145956e416007a8d22e771aaed3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Feb 2017 23:16:16 +0100 Subject: [PATCH 176/271] clean up and test various race.parameters --- src/battle.c | 6 +----- src/battle.test.c | 3 +++ src/kernel/faction.c | 5 +---- src/kernel/faction.test.c | 21 ++++++++++++++++++++- src/kernel/race.c | 9 +++++++++ src/kernel/race.h | 6 ++++++ src/kernel/race.test.c | 1 + src/market.c | 4 ++-- src/market.h | 4 ++++ src/market.test.c | 14 ++++++++++++++ 10 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/battle.c b/src/battle.c index ad613a69f..9316d35dd 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1014,17 +1014,13 @@ static void vampirism(troop at, int damage) #define MAXRACES 128 -static int armor_bonus(const race *rc) { - return get_param_int(rc->parameters, "armor.stamina", -1); -} - int natural_armor(unit * du) { const race *rc = u_race(du); int an; assert(rc); - an = armor_bonus(rc); + an = rc_armor_bonus(rc); if (an > 0) { int sk = effskill(du, SK_STAMINA, 0); return rc->armor + sk / an; diff --git a/src/battle.test.c b/src/battle.test.c index 03535e16e..e8187c772 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -223,10 +223,13 @@ static void test_natural_armor(CuTest * tc) rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); set_level(u, SK_STAMINA, 2); + CuAssertIntEquals(tc, 0, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 0, natural_armor(u)); set_param(&rc->parameters, "armor.stamina", "1"); + CuAssertIntEquals(tc, 1, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 2, natural_armor(u)); set_param(&rc->parameters, "armor.stamina", "2"); + CuAssertIntEquals(tc, 2, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 1, natural_armor(u)); test_cleanup(); } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index e3cb4508a..1c8ff4cb8 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -753,12 +753,9 @@ int count_migrants(const faction * f) return count_faction(f, COUNT_MIGRANTS); } -#define MIGRANTS_NONE 0 -#define MIGRANTS_LOG10 1 - int count_maxmigrants(const faction * f) { - int formula = f->race->parameters ? get_param_int(f->race->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE; + int formula = rc_migrants_formula(f->race); if (formula == MIGRANTS_LOG10) { int nsize = count_all(f); diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index b18121e2d..43956df59 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -3,9 +3,10 @@ #include #include #include +#include #include #include -#include +#include #include #include #include @@ -191,9 +192,27 @@ static void test_set_origin_bug(CuTest *tc) { test_cleanup(); } +static void test_max_migrants(CuTest *tc) { + faction *f; + unit *u; + race *rc; + + test_setup(); + rc = test_create_race("human"); + f = test_create_faction(rc); + u = test_create_unit(f, test_create_region(0, 0, 0)); + CuAssertIntEquals(tc, 0, count_maxmigrants(f)); + set_param(&rc->parameters, "migrants.formula", "1"); + CuAssertIntEquals(tc, 0, count_maxmigrants(f)); + scale_number(u, 250); + CuAssertIntEquals(tc, 13, count_maxmigrants(f)); + test_cleanup(); +} + CuSuite *get_faction_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_max_migrants); SUITE_ADD_TEST(suite, test_addfaction); SUITE_ADD_TEST(suite, test_remove_empty_factions); SUITE_ADD_TEST(suite, test_destroyfaction_allies); diff --git a/src/kernel/race.c b/src/kernel/race.c index 59d263108..123d64022 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -290,6 +290,15 @@ double rc_maxaura(const race *rc) { return rc->maxaura / 100.0; } +int rc_armor_bonus(const race *rc) { + return get_param_int(rc->parameters, "armor.stamina", 0); +} + +int rc_migrants_formula(const race *rc) +{ + return rc->parameters ? get_param_int(rc->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE; +} + const char* rc_name(const race * rc, name_t n, char *name, size_t size) { const char * postfix = 0; if (!rc) { diff --git a/src/kernel/race.h b/src/kernel/race.h index 82d8cdf69..7c4600ae5 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -186,6 +186,12 @@ extern "C" { double rc_magres(const struct race *rc); double rc_maxaura(const struct race *rc); + int rc_armor_bonus(const struct race *rc); + +#define MIGRANTS_NONE 0 +#define MIGRANTS_LOG10 1 + int rc_migrants_formula(const race *rc); + /* Flags. Do not reorder these without changing json_race() in jsonconf.c */ #define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */ #define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */ diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index eaf497168..b730676a4 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -23,6 +23,7 @@ static void test_rc_defaults(CuTest *tc) { test_setup(); rc = rc_get_or_create("human"); CuAssertStrEquals(tc, "human", rc->_name); + CuAssertIntEquals(tc, 0, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 0, rc->magres); CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0); CuAssertIntEquals(tc, 0, rc->healing); diff --git a/src/market.c b/src/market.c index 42819325f..254d3a483 100644 --- a/src/market.c +++ b/src/market.c @@ -66,7 +66,7 @@ attrib_type at_market = { NULL, NULL, NULL, ATF_UNIQUE }; -static int rc_luxury_trade(const struct race *rc) +int rc_luxury_trade(const struct race *rc) { if (rc) { return get_param_int(rc->parameters, "luxury_trade", 1000); @@ -74,7 +74,7 @@ static int rc_luxury_trade(const struct race *rc) return 1000; } -static int rc_herb_trade(const struct race *rc) +int rc_herb_trade(const struct race *rc) { if (rc) { return get_param_int(rc->parameters, "herb_trade", 500); diff --git a/src/market.h b/src/market.h index 74dc8db17..8f1d39eb4 100644 --- a/src/market.h +++ b/src/market.h @@ -19,10 +19,14 @@ without prior permission by the authors of Eressea. extern "C" { #endif struct building; + struct race; bool markets_module(void); void do_markets(void); + int rc_luxury_trade(const struct race *rc); + int rc_herb_trade(const struct race *rc); + #ifdef __cplusplus } #endif diff --git a/src/market.test.c b/src/market.test.c index 6f1d74b88..1e0195a57 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -80,9 +80,23 @@ static void test_market_curse(CuTest * tc) CuAssertIntEquals(tc, 35, i_get(u->items, ltype)); } +static void test_rc_trade(CuTest *tc) { + race *rc; + test_setup(); + rc = test_create_race("human"); + CuAssertIntEquals(tc, 1000, rc_luxury_trade(rc)); + CuAssertIntEquals(tc, 500, rc_herb_trade(rc)); + set_param(&rc->parameters, "luxury_trade", "100"); + set_param(&rc->parameters, "herb_trade", "50"); + CuAssertIntEquals(tc, 100, rc_luxury_trade(rc)); + CuAssertIntEquals(tc, 50, rc_herb_trade(rc)); + test_cleanup(); +} + CuSuite *get_market_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_market_curse); + SUITE_ADD_TEST(suite, test_rc_trade); return suite; } From 3b3e39a3192953e63281b5c7ce00972d20a6930f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Feb 2017 23:21:36 +0100 Subject: [PATCH 177/271] optimization: elf-special "regen.forest" is now a config. this is an E3 feature eliminates rc.parameters for elves allows use of a local cached static --- conf/e3/config.json | 1 + res/e3a/races.xml | 1 - src/kernel/unit.c | 7 ++++--- src/kernel/unit.test.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/conf/e3/config.json b/conf/e3/config.json index 8783055b8..1cecc89d2 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -42,6 +42,7 @@ "nmr.timeout": 5, "nmr.removenewbie": 0, "GiveRestriction": 3, + "healing.forest": 2.0, "hunger.long": false, "hunger.damage": "1d9+9", "hunger.demons.skill": true, diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 3402fdb73..4fcc76e4f 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -127,7 +127,6 @@ - diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 329a523c6..27a296a15 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -2060,9 +2060,10 @@ double u_heal_factor(const unit * u) rc_elf = get_race(RC_ELF); } if (rc == rc_elf) { - double elf_regen = 1.0; - if (rc->parameters) { - elf_regen = get_param_flt(rc->parameters, "regen.forest", elf_regen); + static int cache; + static double elf_regen; + if (config_changed(&cache)) { + elf_regen = config_get_flt("healing.forest", 1.0); } return elf_regen; } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index bf4e9a389..1ddf6282e 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -505,7 +505,7 @@ static void test_heal_factor(CuTest *tc) { CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_ELF)); u_setrace(u, get_race(RC_ELF)); CuAssertDblEquals(tc, 1.0, u_heal_factor(u), 0.0); - set_param(&rc->parameters, "regen.forest", "1.5"); + config_set("healing.forest", "1.5"); CuAssertDblEquals(tc, 1.5, u_heal_factor(u), 0.0); test_cleanup(); } From bdb50eab7545e76c686416ed8579ad8b391f809c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Feb 2017 23:42:50 +0100 Subject: [PATCH 178/271] make migrants.formula a flag. lookup in race.parameters was slow. there is only one formula, anyhow. --- src/kernel/faction.c | 2 +- src/kernel/faction.test.c | 2 +- src/kernel/race.c | 2 +- src/kernel/race.h | 1 + src/kernel/xmlreader.c | 5 +++++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 1c8ff4cb8..28ac2e203 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -565,7 +565,7 @@ bool valid_race(const struct faction *f, const struct race *rc) else { const char *str = get_param(f->race->parameters, "other_race"); if (str) - return (bool)(rc_find(str) == rc); + return rc_find(str) == rc; return false; } } diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 43956df59..1b1a0236b 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -202,7 +202,7 @@ static void test_max_migrants(CuTest *tc) { f = test_create_faction(rc); u = test_create_unit(f, test_create_region(0, 0, 0)); CuAssertIntEquals(tc, 0, count_maxmigrants(f)); - set_param(&rc->parameters, "migrants.formula", "1"); + rc->flags |= RCF_MIGRANTS; CuAssertIntEquals(tc, 0, count_maxmigrants(f)); scale_number(u, 250); CuAssertIntEquals(tc, 13, count_maxmigrants(f)); diff --git a/src/kernel/race.c b/src/kernel/race.c index 123d64022..7f6fe15c2 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -296,7 +296,7 @@ int rc_armor_bonus(const race *rc) { int rc_migrants_formula(const race *rc) { - return rc->parameters ? get_param_int(rc->parameters, "migrants.formula", MIGRANTS_NONE) : MIGRANTS_NONE; + return (rc->flags&RCF_MIGRANTS) ? MIGRANTS_LOG10 : MIGRANTS_NONE; } const char* rc_name(const race * rc, name_t n, char *name, size_t size) { diff --git a/src/kernel/race.h b/src/kernel/race.h index 7c4600ae5..67eea00f4 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -223,6 +223,7 @@ extern "C" { #define RCF_STONEGOLEM (1<<27) /* race gets stonegolem properties */ #define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ #define RCF_ATTACK_MOVED (1<<29) /* may attack if it has moved */ +#define RCF_MIGRANTS (1<<30) /* may have migrant units (human bonus) */ /* Economic flags */ #define ECF_KEEP_ITEM (1<<1) /* gibt Gegenst�nde weg */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 9b1f5532c..a0172313a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1737,6 +1737,11 @@ static int parse_races(xmlDocPtr doc) if (strcmp((const char *)propName, "recruit_multi")==0) { rc->recruit_multi = atof((const char *)propValue); } + else if (strcmp((const char *)propName, "migrants.formula") == 0) { + if (propValue[0] == '1') { + rc->flags |= RCF_MIGRANTS; + } + } else { set_param(&rc->parameters, (const char *)propName, (const char *)propValue); } From 0b3d15f4b3deb5f6d62df40ef9176eb28359f5fa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Feb 2017 23:46:26 +0100 Subject: [PATCH 179/271] eliminate unused other_cost parameter. cost of other races is defined by their recruitcost. --- res/e3a/races.xml | 3 --- res/races/goblin-2.xml | 1 - res/races/goblin-3.xml | 1 - src/economy.c | 1 - 4 files changed, 6 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 4fcc76e4f..7e75f3fd4 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -36,7 +36,6 @@ - @@ -51,7 +50,6 @@ - @@ -80,7 +78,6 @@ - diff --git a/res/races/goblin-2.xml b/res/races/goblin-2.xml index ae90c1918..f8964d7c0 100644 --- a/res/races/goblin-2.xml +++ b/res/races/goblin-2.xml @@ -8,7 +8,6 @@ getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/goblin-3.xml b/res/races/goblin-3.xml index aa0c8fddb..4ad83967d 100644 --- a/res/races/goblin-3.xml +++ b/res/races/goblin-3.xml @@ -8,7 +8,6 @@ getitem="yes" equipment="yes" healing="2.0"> - diff --git a/src/economy.c b/src/economy.c index 16b201555..2d9fe6666 100644 --- a/src/economy.c +++ b/src/economy.c @@ -427,7 +427,6 @@ static int recruit_cost(const faction * f, const race * rc) } else if (valid_race(f, rc)) { return rc->recruitcost; - /* return get_param_int(f->race->parameters, "other_cost", -1); */ } return -1; } From 117d37e2ea61040f63d6766b73952c522d7c59ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 14:48:43 +0100 Subject: [PATCH 180/271] do not specify rules at command line. it is in eressea.ini --- s/preview | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/preview b/s/preview index 1e5d0db48..0c1467627 100755 --- a/s/preview +++ b/s/preview @@ -81,7 +81,7 @@ VALGRIND=$(which valgrind) if [ ! -z $VALGRIND ]; then SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER" fi -$SERVER -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua +$SERVER -v$verbose -t$turn $SOURCE/scripts/run-turn.lua let turn=$turn+1 [ -e data/$turn.dat ] || abort "no data file created" } From bd836b76e10f2e4dbd8d913d4129b94c32026866 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 16:55:51 +0100 Subject: [PATCH 181/271] channel XML race.parameters through a single, tested, function --- src/battle.test.c | 4 ++-- src/economy.c | 5 +---- src/kernel/faction.c | 13 +++++++++---- src/kernel/faction.test.c | 17 +++++++++++++++++ src/kernel/race.c | 14 ++++++++++++++ src/kernel/race.h | 2 ++ src/kernel/race.test.c | 16 ++++++++++++++++ src/kernel/xmlreader.c | 12 +----------- src/market.test.c | 4 ++-- 9 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/battle.test.c b/src/battle.test.c index e8187c772..946d5fcee 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -225,10 +225,10 @@ static void test_natural_armor(CuTest * tc) set_level(u, SK_STAMINA, 2); CuAssertIntEquals(tc, 0, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 0, natural_armor(u)); - set_param(&rc->parameters, "armor.stamina", "1"); + rc_set_param(rc, "armor.stamina", "1"); CuAssertIntEquals(tc, 1, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 2, natural_armor(u)); - set_param(&rc->parameters, "armor.stamina", "2"); + rc_set_param(rc, "armor.stamina", "2"); CuAssertIntEquals(tc, 2, rc_armor_bonus(rc)); CuAssertIntEquals(tc, 1, natural_armor(u)); test_cleanup(); diff --git a/src/economy.c b/src/economy.c index 2d9fe6666..dcbc7431e 100644 --- a/src/economy.c +++ b/src/economy.c @@ -422,10 +422,7 @@ static void expandrecruit(region * r, request * recruitorders) static int recruit_cost(const faction * f, const race * rc) { - if (is_monsters(f) || f->race == rc) { - return rc->recruitcost; - } - else if (valid_race(f, rc)) { + if (is_monsters(f) || valid_race(f, rc)) { return rc->recruitcost; } return -1; diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 28ac2e203..30a623e44 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -558,15 +558,20 @@ void faction_setpassword(faction * f, const char *pwhash) f->_password = strdup(pwhash); } +const race *other_race(const race *rc) { + if (rc->parameters) { + const char *str = get_param(rc->parameters, "other_race"); + return str ? rc_find(str) : NULL; + } + return NULL; +} + bool valid_race(const struct faction *f, const struct race *rc) { if (f->race == rc) return true; else { - const char *str = get_param(f->race->parameters, "other_race"); - if (str) - return rc_find(str) == rc; - return false; + return other_race(f->race) == rc; } } diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 1b1a0236b..c01731964 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -209,6 +209,22 @@ static void test_max_migrants(CuTest *tc) { test_cleanup(); } +static void test_valid_race(CuTest *tc) { + race * rc1, *rc2; + faction *f; + + test_setup(); + rc1 = test_create_race("human"); + rc2 = test_create_race("elf"); + f = test_create_faction(rc1); + CuAssertTrue(tc, valid_race(f, rc1)); + CuAssertTrue(tc, !valid_race(f, rc2)); + rc_set_param(rc1, "other_race", "elf"); + CuAssertTrue(tc, valid_race(f, rc1)); + CuAssertTrue(tc, valid_race(f, rc2)); + test_cleanup(); +} + CuSuite *get_faction_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -222,5 +238,6 @@ CuSuite *get_faction_suite(void) SUITE_ADD_TEST(suite, test_set_origin); SUITE_ADD_TEST(suite, test_set_origin_bug); SUITE_ADD_TEST(suite, test_check_passwd); + SUITE_ADD_TEST(suite, test_valid_race); return suite; } diff --git a/src/kernel/race.c b/src/kernel/race.c index 7f6fe15c2..0e9371e39 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -299,6 +299,20 @@ int rc_migrants_formula(const race *rc) return (rc->flags&RCF_MIGRANTS) ? MIGRANTS_LOG10 : MIGRANTS_NONE; } +void rc_set_param(struct race *rc, const char *key, const char *value) { + if (strcmp(key, "recruit_multi") == 0) { + rc->recruit_multi = atof(value); + } + else if (strcmp(key, "migrants.formula") == 0) { + if (value[0] == '1') { + rc->flags |= RCF_MIGRANTS; + } + } + else { + set_param(&rc->parameters, key, value); + } +} + const char* rc_name(const race * rc, name_t n, char *name, size_t size) { const char * postfix = 0; if (!rc) { diff --git a/src/kernel/race.h b/src/kernel/race.h index 67eea00f4..b500ed6a1 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -184,6 +184,8 @@ extern "C" { const char * rc_name_s(const race *rc, name_t n); const char * rc_name(const race *rc, name_t n, char *name, size_t size); + void rc_set_param(struct race *rc, const char *key, const char *value); + double rc_magres(const struct race *rc); double rc_maxaura(const struct race *rc); int rc_armor_bonus(const struct race *rc); diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index b730676a4..132457cb4 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -84,6 +84,21 @@ static void test_old_race(CuTest *tc) test_cleanup(); } +static void test_rc_set_param(CuTest *tc) { + race *rc; + test_setup(); + rc = test_create_race("human"); + CuAssertPtrEquals(tc, NULL, rc->parameters); + rc_set_param(rc, "hodor", "HODOR"); + CuAssertStrEquals(tc, "HODOR", get_param(rc->parameters, "hodor")); + rc_set_param(rc, "recruit_multi", "0.5"); + CuAssertDblEquals(tc, 0.5, rc->recruit_multi, 0.0); + rc_set_param(rc, "migrants.formula", "1"); + CuAssertIntEquals(tc, RCF_MIGRANTS, rc->flags&RCF_MIGRANTS); + CuAssertIntEquals(tc, MIGRANTS_LOG10, rc_migrants_formula(rc)); + test_cleanup(); +} + CuSuite *get_race_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -92,6 +107,7 @@ CuSuite *get_race_suite(void) SUITE_ADD_TEST(suite, test_rc_name); SUITE_ADD_TEST(suite, test_rc_defaults); SUITE_ADD_TEST(suite, test_rc_find); + SUITE_ADD_TEST(suite, test_rc_set_param); return suite; } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index a0172313a..c07e19809 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1734,17 +1734,7 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)child->name, "param") == 0) { xmlChar *propName = xmlGetProp(child, BAD_CAST "name"); xmlChar *propValue = xmlGetProp(child, BAD_CAST "value"); - if (strcmp((const char *)propName, "recruit_multi")==0) { - rc->recruit_multi = atof((const char *)propValue); - } - else if (strcmp((const char *)propName, "migrants.formula") == 0) { - if (propValue[0] == '1') { - rc->flags |= RCF_MIGRANTS; - } - } - else { - set_param(&rc->parameters, (const char *)propName, (const char *)propValue); - } + rc_set_param(rc, (const char *)propName, (const char *)propValue); xmlFree(propName); xmlFree(propValue); } diff --git a/src/market.test.c b/src/market.test.c index 1e0195a57..b4d5f05f5 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -86,8 +86,8 @@ static void test_rc_trade(CuTest *tc) { rc = test_create_race("human"); CuAssertIntEquals(tc, 1000, rc_luxury_trade(rc)); CuAssertIntEquals(tc, 500, rc_herb_trade(rc)); - set_param(&rc->parameters, "luxury_trade", "100"); - set_param(&rc->parameters, "herb_trade", "50"); + rc_set_param(rc, "luxury_trade", "100"); + rc_set_param(rc, "herb_trade", "50"); CuAssertIntEquals(tc, 100, rc_luxury_trade(rc)); CuAssertIntEquals(tc, 50, rc_herb_trade(rc)); test_cleanup(); From f2ed2c892ab535b2567a39009d3825cbd0a1a0e6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 18:38:53 +0100 Subject: [PATCH 182/271] bugfix: Drachen "scare" attribut muss mit MOD, nicht AND angewendet werden. rng_int() & 400 ist eine bekloppte Rechnung. --- src/kernel/race.c | 10 +++++++++- src/kernel/race.h | 1 + src/monsters.c | 18 +++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index 0e9371e39..4dc347751 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -48,6 +48,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* attrib includes */ +#include #include /* libc includes */ @@ -290,10 +291,17 @@ double rc_maxaura(const race *rc) { return rc->maxaura / 100.0; } -int rc_armor_bonus(const race *rc) { +int rc_armor_bonus(const race *rc) +{ return get_param_int(rc->parameters, "armor.stamina", 0); } +int rc_scare(const struct race *rc) +{ + attrib *a = a_find(rc->attribs, &at_scare); + return a ? a->data.i : 0; +} + int rc_migrants_formula(const race *rc) { return (rc->flags&RCF_MIGRANTS) ? MIGRANTS_LOG10 : MIGRANTS_NONE; diff --git a/src/kernel/race.h b/src/kernel/race.h index b500ed6a1..6a4feb269 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -189,6 +189,7 @@ extern "C" { double rc_magres(const struct race *rc); double rc_maxaura(const struct race *rc); int rc_armor_bonus(const struct race *rc); + int rc_scare(const struct race *rc); #define MIGRANTS_NONE 0 #define MIGRANTS_LOG10 1 diff --git a/src/monsters.c b/src/monsters.c index bba1cbd50..a7678c701 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -31,7 +31,6 @@ #include "study.h" /* attributes includes */ -#include #include #include @@ -1013,11 +1012,11 @@ static void eaten_by_monster(unit * u) int horse = -1; const resource_type *rhorse = get_resourcetype(R_HORSE); const race *rc = u_race(u); - attrib *a; + int scare; - a = a_find(rc->attribs, &at_scare); - if (a) { - n = rng_int() & a->data.i * u->number; + scare = rc_scare(rc); + if (scare>0) { + n = rng_int() % scare * u->number; } else { n = rng_int() % (u->number / 20 + 1); horse = 0; @@ -1093,10 +1092,11 @@ static void scared_by_monster(unit * u) { int n; const race *rc = u_race(u); - attrib *a; - a = a_find(rc->attribs, &at_scare); - if (a) { - n = rng_int() & a->data.i * u->number; + int scare; + + scare = rc_scare(rc); + if (scare>0) { + n = rng_int() % scare * u->number; } else { n = rng_int() % (u->number / 4 + 1); } From 67414f29ebf6af99a084e315d086bf429cd646cd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 19:26:07 +0100 Subject: [PATCH 183/271] wrap ai.scare and at_scare in rc_set_param --- src/kernel/race.c | 5 +++++ src/kernel/race.test.c | 2 ++ src/kernel/xmlreader.c | 13 ++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index 4dc347751..b7c52d169 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -311,6 +311,11 @@ void rc_set_param(struct race *rc, const char *key, const char *value) { if (strcmp(key, "recruit_multi") == 0) { rc->recruit_multi = atof(value); } + else if (strcmp(key, "ai.scare") == 0) { + attrib *a = a_new(&at_scare); + a->data.i = atoi(value); + a_add(&rc->attribs, a); + } else if (strcmp(key, "migrants.formula") == 0) { if (value[0] == '1') { rc->flags |= RCF_MIGRANTS; diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index 132457cb4..857e8696a 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -96,6 +96,8 @@ static void test_rc_set_param(CuTest *tc) { rc_set_param(rc, "migrants.formula", "1"); CuAssertIntEquals(tc, RCF_MIGRANTS, rc->flags&RCF_MIGRANTS); CuAssertIntEquals(tc, MIGRANTS_LOG10, rc_migrants_formula(rc)); + rc_set_param(rc, "ai.scare", "400"); + CuAssertIntEquals(tc, 400, rc_scare(rc)); test_cleanup(); } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index c07e19809..0864df9a6 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1575,13 +1575,12 @@ static int parse_spells(xmlDocPtr doc) static void parse_ai(race * rc, xmlNodePtr node) { - int n; - - n = xml_ivalue(node, "scare", 0); - if (n>0) { - attrib *a = a_new(&at_scare); - a->data.i = n; - a_add(&rc->attribs, a); + xmlChar *propValue; + + propValue = xmlGetProp(node, BAD_CAST "scare"); + if (propValue) { + rc_set_param(rc, "ai.scare", (const char *)propValue); + xmlFree(propValue); } rc->splitsize = xml_ivalue(node, "splitsize", 0); rc->aggression = (float)xml_fvalue(node, "aggression", 0.04); From 492aba543bb79847268d54c7d4247d9a4a8d0a8e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 19:30:09 +0100 Subject: [PATCH 184/271] delete at_scare delete dead code (race.attribs has no at_skillmod) delete race.attribs --- src/attributes/attributes.c | 5 ----- src/attributes/attributes.h | 1 - src/battle.c | 4 ---- src/kernel/race.c | 9 +-------- src/kernel/race.h | 1 - 5 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c index 8e9b22139..42f5247fe 100644 --- a/src/attributes/attributes.c +++ b/src/attributes/attributes.c @@ -58,10 +58,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -attrib_type at_scare = { // monster scares peasants - "scare", NULL, NULL, NULL, a_writeint, a_readint -}; - attrib_type at_unitdissolve = { "unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars }; @@ -78,7 +74,6 @@ static int read_ext(attrib * a, void *owner, gamedata *data) void register_attributes(void) { /* Alle speicherbaren Attribute müssen hier registriert werden */ - at_register(&at_scare); at_register(&at_shiptrail); at_register(&at_familiar); at_register(&at_familiarmage); diff --git a/src/attributes/attributes.h b/src/attributes/attributes.h index 91184ad98..4ec3150ec 100644 --- a/src/attributes/attributes.h +++ b/src/attributes/attributes.h @@ -23,7 +23,6 @@ extern "C" { #endif struct attrib_type; - extern struct attrib_type at_scare; extern void register_attributes(void); #ifdef __cplusplus diff --git a/src/battle.c b/src/battle.c index 9316d35dd..04e72d92c 100644 --- a/src/battle.c +++ b/src/battle.c @@ -760,10 +760,6 @@ bool missile) if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS) && !fval(wtype, WTF_MISSILE)))) { skill += CavalryBonus(tu, enemy, BONUS_SKILL); - if (wtype) - skill = - skillmod(u_race(tu)->attribs, tu, tu->region, wtype->skill, skill, - SMF_RIDING); } if (t.index < tf->elvenhorses) { diff --git a/src/kernel/race.c b/src/kernel/race.c index b7c52d169..9a5ce84c2 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -48,7 +48,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* attrib includes */ -#include #include /* libc includes */ @@ -298,8 +297,7 @@ int rc_armor_bonus(const race *rc) int rc_scare(const struct race *rc) { - attrib *a = a_find(rc->attribs, &at_scare); - return a ? a->data.i : 0; + return get_param_int(rc->parameters, "ai.scare", 0); } int rc_migrants_formula(const race *rc) @@ -311,11 +309,6 @@ void rc_set_param(struct race *rc, const char *key, const char *value) { if (strcmp(key, "recruit_multi") == 0) { rc->recruit_multi = atof(value); } - else if (strcmp(key, "ai.scare") == 0) { - attrib *a = a_new(&at_scare); - a->data.i = atoi(value); - a_add(&rc->attribs, a); - } else if (strcmp(key, "migrants.formula") == 0) { if (value[0] == '1') { rc->flags |= RCF_MIGRANTS; diff --git a/src/kernel/race.h b/src/kernel/race.h index 6a4feb269..906b56808 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -154,7 +154,6 @@ extern "C" { void(*init_familiar) (struct unit *); const struct race *familiars[MAXMAGIETYP]; - struct attrib *attribs; struct race *next; } race; From de10a8ad65a3fcafccd9e34de3938dc4172a350a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 5 Feb 2017 20:48:44 +0100 Subject: [PATCH 185/271] reduce side-effects in snowglobe tests. should no longer be intermittent. --- clibs | 2 +- cmake | 2 +- scripts/tests/xmas.lua | 12 +++--------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/clibs b/clibs index 27c8b3202..f91ef37f0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/cmake b/cmake index d88983c7f..f1fb3943a 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit d88983c7ff4bc3a4884a7c3f74e8190bac5eab23 +Subproject commit f1fb3943ace59994d90d71a891b80033dc2700a2 diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 5477e08ab..459984901 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -46,23 +46,17 @@ function test_snowglobe() local r2 = region.create(1, 0, "ocean") local f = faction.create("snowglobe2@eressea.de", "human", "de") local u = unit.create(f, r1, 1) - local have = 6 local fail = 0 u:add_item("snowglobe", have) - local xform = { ocean = "glacier", glacier = "glacier", firewall = "volcano", volcano = "mountain", desert = "plain", plain = "plain" } - u:clear_orders() - u:add_order("BENUTZEN 1 Schneekugel Ost") + local xform = { ocean = "glacier", glacier = "glacier", firewall = "volcano", desert = "plain", volcano = "mountain", plain = "plain" } for k, v in pairs(xform) do r2.terrain = k - process_orders() + use_snowglobe(u, 1, "Ost", nil) assert_equal(v, r2.terrain) - if k~=v then - have=have - 1 - else + if k==v then fail = fail + 1 assert_equal(fail, f:count_msg_type('target_region_invalid')) end - assert_equal(have, u:get_item("snowglobe")) end end From 998dcffab2f29f81b3a64c595275ed01ac78a372 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Feb 2017 09:03:08 +0100 Subject: [PATCH 186/271] introduce an rcoption struct. used for pretty rare options that have no property in the race struct. --- clibs | 2 +- cmake | 2 +- src/kernel/faction.c | 10 +------ src/kernel/race.c | 69 +++++++++++++++++++++++++++++++++++++++++++- src/kernel/race.h | 4 +++ 5 files changed, 75 insertions(+), 12 deletions(-) diff --git a/clibs b/clibs index f91ef37f0..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 diff --git a/cmake b/cmake index f1fb3943a..d88983c7f 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit f1fb3943ace59994d90d71a891b80033dc2700a2 +Subproject commit d88983c7ff4bc3a4884a7c3f74e8190bac5eab23 diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 30a623e44..a5373d44d 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -558,20 +558,12 @@ void faction_setpassword(faction * f, const char *pwhash) f->_password = strdup(pwhash); } -const race *other_race(const race *rc) { - if (rc->parameters) { - const char *str = get_param(rc->parameters, "other_race"); - return str ? rc_find(str) : NULL; - } - return NULL; -} - bool valid_race(const struct faction *f, const struct race *rc) { if (f->race == rc) return true; else { - return other_race(f->race) == rc; + return rc_otherrace(f->race) == rc; } } diff --git a/src/kernel/race.c b/src/kernel/race.c index 9a5ce84c2..bc4bdd1e4 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -44,6 +44,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include @@ -77,6 +78,59 @@ static const char *racenames[MAXRACES] = { "clone" }; +#define MAXOPTIONS 4 +typedef struct rcoption { + unsigned char key[MAXOPTIONS]; + variant value[MAXOPTIONS]; +} rcoption; + +enum { + RCO_NONE, + RCO_SCARE, + RCO_OTHER +}; + +static void rc_setoption(race *rc, int key, const char *value) { + int i; + variant *v = NULL; + if (!rc->options) { + rc->options = malloc(sizeof(rcoption)); + rc->options->key[0] = key; + rc->options->key[1] = RCO_NONE; + v = rc->options->value; + } else { + for (i=0;!v && i < MAXOPTIONS && rc->options->key[i]!=RCO_NONE;++i) { + if (rc->options->key[i]==key) { + v = rc->options->value+i; + } + } + if (!v) { + assert(ioptions->value+i; + rc->options->key[i] = key; + } + } + assert(v); + if (key == RCO_SCARE) { + v->i = atoi(value); + } + else if (key == RCO_OTHER) { + v->v = rc_get_or_create(value); + } +} + +static variant *rc_getoption(const race *rc, int key) { + if (rc->options) { + int i; + for (i=0;i!=MAXOPTIONS && rc->options->key[i]!=RCO_NONE;++i) { + if (rc->options->key[i]==key) { + return rc->options->value+i; + } + } + } + return NULL; +} + const struct race *findrace(const char *s, const struct locale *lang) { void **tokens = get_translations(lang, UT_RACES); @@ -297,7 +351,14 @@ int rc_armor_bonus(const race *rc) int rc_scare(const struct race *rc) { - return get_param_int(rc->parameters, "ai.scare", 0); + variant *v = rc_getoption(rc, RCO_SCARE); + return v ? v->i : 0; +} + +const race *rc_otherrace(const race *rc) +{ + variant *v = rc_getoption(rc, RCO_OTHER); + return v ? (const race *)v->v : NULL; } int rc_migrants_formula(const race *rc) @@ -314,6 +375,12 @@ void rc_set_param(struct race *rc, const char *key, const char *value) { rc->flags |= RCF_MIGRANTS; } } + else if (strcmp(key, "other_race")==0) { + rc_setoption(rc, RCO_OTHER, value); + } + else if (strcmp(key, "ai.scare")==0) { + rc_setoption(rc, RCO_SCARE, value); + } else { set_param(&rc->parameters, key, value); } diff --git a/src/kernel/race.h b/src/kernel/race.h index 906b56808..f4afb04de 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -47,6 +47,7 @@ extern "C" { struct spell; struct spellref; struct locale; + struct rcoption; extern int num_races; @@ -153,6 +154,8 @@ extern "C" { struct item *(*itemdrop) (const struct race *, int size); void(*init_familiar) (struct unit *); + struct rcoption *options; // rarely used properties + const struct race *familiars[MAXMAGIETYP]; struct race *next; } race; @@ -189,6 +192,7 @@ extern "C" { double rc_maxaura(const struct race *rc); int rc_armor_bonus(const struct race *rc); int rc_scare(const struct race *rc); + const race *rc_otherrace(const race *rc); #define MIGRANTS_NONE 0 #define MIGRANTS_LOG10 1 From 28c951bdfd423aaa381324665369ffaff4fd5549 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Feb 2017 09:46:36 +0100 Subject: [PATCH 187/271] eliminate race.parameters. move all special properties to race.options --- src/kernel/race.c | 71 +++++++++++++++++++++++++++++++++++++++--- src/kernel/race.h | 4 ++- src/kernel/race.test.c | 6 ++-- src/kernel/xmlreader.c | 1 - src/market.c | 16 ---------- src/morale.c | 7 ++--- src/upkeep.c | 18 +++++------ 7 files changed, 84 insertions(+), 39 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index bc4bdd1e4..8b2632753 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -86,8 +86,12 @@ typedef struct rcoption { enum { RCO_NONE, - RCO_SCARE, - RCO_OTHER + RCO_SCARE, // races that scare and eat peasants + RCO_OTHER, // may recruit from another race + RCO_STAMINA, // every n levels of stamina add +1 RC + RCO_HUNGER, // custom hunger.damage override (char *) + RCO_TRADELUX, + RCO_TRADEHERB, }; static void rc_setoption(race *rc, int key, const char *value) { @@ -114,9 +118,21 @@ static void rc_setoption(race *rc, int key, const char *value) { if (key == RCO_SCARE) { v->i = atoi(value); } + else if (key == RCO_STAMINA) { + v->i = atoi(value); + } else if (key == RCO_OTHER) { v->v = rc_get_or_create(value); } + else if (key == RCO_HUNGER) { + v->v = strdup(value); + } + else if (key == RCO_TRADEHERB) { + v->i = atoi(value); + } + else if (key == RCO_TRADELUX) { + v->i = atoi(value); + } } static variant *rc_getoption(const race *rc, int key) { @@ -238,12 +254,20 @@ void free_races(void) { while (races) { int i; race * rc = races->next; + rcoption * opt = races->options; + if (opt) { + for (i=0;i!=MAXOPTIONS && opt->key[i]!=RCO_NONE;++i) { + if (opt->key[i]==RCO_HUNGER) { + free(opt->value[i].v); + } + } + free(opt); + } for (i = 0; races->attack[i].type!=AT_NONE; ++i) { spellref_free(races->attack[i].data.sp); } spellref_free(races->precombatspell); - free_params(&races->parameters); free(xrefs); xrefs = 0; free(races->_name); @@ -344,9 +368,16 @@ double rc_maxaura(const race *rc) { return rc->maxaura / 100.0; } +const char * rc_hungerdamage(const race *rc) +{ + variant *v = rc_getoption(rc, RCO_HUNGER); + return v ? (const char *)v->v : NULL; +} + int rc_armor_bonus(const race *rc) { - return get_param_int(rc->parameters, "armor.stamina", 0); + variant *v = rc_getoption(rc, RCO_STAMINA); + return v ? v->i : 0; } int rc_scare(const struct race *rc) @@ -355,6 +386,24 @@ int rc_scare(const struct race *rc) return v ? v->i : 0; } +int rc_luxury_trade(const struct race *rc) +{ + if (rc) { + variant *v = rc_getoption(rc, RCO_TRADELUX); + if (v) return v->i; + } + return 1000; +} + +int rc_herb_trade(const struct race *rc) +{ + if (rc) { + variant *v = rc_getoption(rc, RCO_TRADEHERB); + if (v) return v->i; + } + return 500; +} + const race *rc_otherrace(const race *rc) { variant *v = rc_getoption(rc, RCO_OTHER); @@ -381,8 +430,20 @@ void rc_set_param(struct race *rc, const char *key, const char *value) { else if (strcmp(key, "ai.scare")==0) { rc_setoption(rc, RCO_SCARE, value); } + else if (strcmp(key, "hunger.damage")==0) { + rc_setoption(rc, RCO_HUNGER, value); + } + else if (strcmp(key, "armor.stamina")==0) { + rc_setoption(rc, RCO_STAMINA, value); + } + else if (strcmp(key, "luxury_trade")==0) { + rc_setoption(rc, RCO_TRADELUX, value); + } + else if (strcmp(key, "herb_trade")==0) { + rc_setoption(rc, RCO_TRADEHERB, value); + } else { - set_param(&rc->parameters, key, value); + log_error("unknown property for race %s: %s=%s", rc->_name, key, value); } } diff --git a/src/kernel/race.h b/src/kernel/race.h index f4afb04de..6321d4f22 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -138,7 +138,6 @@ extern "C" { int df_default; /* Verteidigungsskill Unbewaffnet (default: -2) */ int at_bonus; /* Ver�ndert den Angriffsskill (default: 0) */ int df_bonus; /* Ver�ndert den Verteidigungskill (default: 0) */ - struct param *parameters; // additional properties, for an example see natural_armor struct spellref *precombatspell; signed char *study_speed; /* study-speed-bonus in points/turn (0=30 Tage) */ int flags; @@ -188,10 +187,13 @@ extern "C" { void rc_set_param(struct race *rc, const char *key, const char *value); + int rc_luxury_trade(const struct race *rc); + int rc_herb_trade(const struct race *rc); double rc_magres(const struct race *rc); double rc_maxaura(const struct race *rc); int rc_armor_bonus(const struct race *rc); int rc_scare(const struct race *rc); + const char * rc_hungerdamage(const race *rc); const race *rc_otherrace(const race *rc); #define MIGRANTS_NONE 0 diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index 857e8696a..8363d8b72 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -88,9 +88,7 @@ static void test_rc_set_param(CuTest *tc) { race *rc; test_setup(); rc = test_create_race("human"); - CuAssertPtrEquals(tc, NULL, rc->parameters); - rc_set_param(rc, "hodor", "HODOR"); - CuAssertStrEquals(tc, "HODOR", get_param(rc->parameters, "hodor")); + CuAssertPtrEquals(tc, NULL, rc->options); rc_set_param(rc, "recruit_multi", "0.5"); CuAssertDblEquals(tc, 0.5, rc->recruit_multi, 0.0); rc_set_param(rc, "migrants.formula", "1"); @@ -98,6 +96,8 @@ static void test_rc_set_param(CuTest *tc) { CuAssertIntEquals(tc, MIGRANTS_LOG10, rc_migrants_formula(rc)); rc_set_param(rc, "ai.scare", "400"); CuAssertIntEquals(tc, 400, rc_scare(rc)); + rc_set_param(rc, "hunger.damage", "1d10+12"); + CuAssertStrEquals(tc, "1d10+12", rc_hungerdamage(rc)); test_cleanup(); } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 0864df9a6..00bb9f848 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1738,7 +1738,6 @@ static int parse_races(xmlDocPtr doc) xmlFree(propValue); } } - rc->recruit_multi = get_param_flt(rc->parameters, "recruit_multi", 1.0); /* reading eressea/races/race/skill */ xpath->node = node; diff --git a/src/market.c b/src/market.c index 254d3a483..8fd4e3f0d 100644 --- a/src/market.c +++ b/src/market.c @@ -66,22 +66,6 @@ attrib_type at_market = { NULL, NULL, NULL, ATF_UNIQUE }; -int rc_luxury_trade(const struct race *rc) -{ - if (rc) { - return get_param_int(rc->parameters, "luxury_trade", 1000); - } - return 1000; -} - -int rc_herb_trade(const struct race *rc) -{ - if (rc) { - return get_param_int(rc->parameters, "herb_trade", 500); - } - return 500; -} - #define MAX_MARKETS 128 #define MIN_PEASANTS 50 /* if there are at least this many peasants, you will get 1 good */ diff --git a/src/morale.c b/src/morale.c index 1bdf2363d..580af899f 100644 --- a/src/morale.c +++ b/src/morale.c @@ -31,10 +31,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -static double rc_popularity(const struct race *rc) +static double popularity() { - int pop = get_param_int(rc->parameters, "morale", MORALE_AVERAGE); - return 1.0 / (pop - MORALE_COOLDOWN); /* 10 turns average */ + return 1.0 / (MORALE_AVERAGE - MORALE_COOLDOWN); /* 10 turns average */ } void morale_update(region *r) { @@ -52,7 +51,7 @@ void morale_update(region *r) { if (morale < maxmorale) { if (stability > MORALE_COOLDOWN && r->land->ownership->owner && morale < MORALE_MAX) { - double ch = rc_popularity(r->land->ownership->owner->race); + double ch = popularity(); if (is_cursed(r->attribs, C_GENEROUS, 0)) { ch *= 1.2; /* 20% improvement */ } diff --git a/src/upkeep.c b/src/upkeep.c index c53c321d0..8494d7f25 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -59,7 +59,7 @@ static void help_feed(unit * donor, unit * u, int *need_p) } static const char *hunger_damage(const race *rc) { - const char * damage = rc->parameters ? get_param(rc->parameters, "hunger.damage") : NULL; + const char * damage = rc_hungerdamage(rc); if (!damage) { damage = config_get("hunger.damage"); } @@ -98,11 +98,11 @@ static bool hunger(int number, unit * u) deathcounts(r, dead); } if (hpsub > 0) { - /* Jetzt die Schäden der nicht gestorbenen abziehen. */ + /* Jetzt die Sch�den der nicht gestorbenen abziehen. */ u->hp -= hpsub; - /* Meldung nur, wenn noch keine für Tote generiert. */ + /* Meldung nur, wenn noch keine f�r Tote generiert. */ if (dead == 0) { - /* Durch unzureichende Ernährung wird %s geschwächt */ + /* Durch unzureichende Ern�hrung wird %s geschw�cht */ ADDMSG(&u->faction->msgs, msg_message("malnourish", "unit region", u, r)); } } @@ -125,13 +125,13 @@ void get_food(region * r) return; } /* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber - * wird zunächst so auf die Einheiten aufgeteilt, dass idealerweise - * jede Einheit genug Silber für ihren Unterhalt hat. */ + * wird zun�chst so auf die Einheiten aufgeteilt, dass idealerweise + * jede Einheit genug Silber f�r ihren Unterhalt hat. */ for (u = r->units; u; u = u->next) { int need = lifestyle(u); - /* Erstmal zurücksetzen */ + /* Erstmal zur�cksetzen */ freset(u, UFL_HUNGER); if (u->ship && (u->ship->flags & SF_FISHING)) { @@ -230,7 +230,7 @@ void get_food(region * r) } /* 3. bestimmen, wie viele Bauern gefressen werden. - * bei fehlenden Bauern den Dämon hungern lassen + * bei fehlenden Bauern den D�mon hungern lassen */ for (u = r->units; u; u = u->next) { if (u_race(u) == rc_demon) { @@ -293,7 +293,7 @@ void get_food(region * r) } rsetpeasants(r, peasantfood / 10); - /* 3. Von den überlebenden das Geld abziehen: */ + /* 3. Von den �berlebenden das Geld abziehen: */ for (u = r->units; u; u = u->next) { int need = MIN(get_money(u), lifestyle(u)); change_money(u, -need); From 2267373b2e40409f75f485c1155dd69e9dbf7cba Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Feb 2017 10:44:11 +0100 Subject: [PATCH 188/271] gcc warning --- clibs | 2 +- cmake | 2 +- src/morale.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clibs b/clibs index 27c8b3202..f91ef37f0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/cmake b/cmake index d88983c7f..f1fb3943a 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit d88983c7ff4bc3a4884a7c3f74e8190bac5eab23 +Subproject commit f1fb3943ace59994d90d71a891b80033dc2700a2 diff --git a/src/morale.c b/src/morale.c index 580af899f..67108333e 100644 --- a/src/morale.c +++ b/src/morale.c @@ -31,7 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -static double popularity() +static double popularity(void) { return 1.0 / (MORALE_AVERAGE - MORALE_COOLDOWN); /* 10 turns average */ } From baf3275ebac67b3d01e1040bd644c9f3cb984bd2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Feb 2017 11:52:07 +0100 Subject: [PATCH 189/271] valgrind: always terminate options --- src/kernel/race.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kernel/race.c b/src/kernel/race.c index 8b2632753..c57d98a24 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -112,6 +112,9 @@ static void rc_setoption(race *rc, int key, const char *value) { assert(ioptions->value+i; rc->options->key[i] = key; + if (i+1options->key[i+1]=RCO_NONE; + } } } assert(v); From d851554ebe68abc540a45796767fc016a786b0c0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Feb 2017 18:16:34 +0100 Subject: [PATCH 190/271] MSVC doesn't like to do integer->char conversions. --- src/kernel/race.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index c57d98a24..c7c2e8165 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -94,7 +94,8 @@ enum { RCO_TRADEHERB, }; -static void rc_setoption(race *rc, int key, const char *value) { +static void rc_setoption(race *rc, int k, const char *value) { + unsigned char key = (unsigned char)k; int i; variant *v = NULL; if (!rc->options) { From 8ffa0919366a631e9189ee9a84c562de3b8a5d4f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Feb 2017 20:34:11 +0100 Subject: [PATCH 191/271] do not abort xml parsing when there is no calendar --- src/kernel/xmlreader.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 00bb9f848..cd3331517 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -358,16 +358,13 @@ static int parse_calendar(xmlDocPtr doc) xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathObjectPtr xpathCalendars; xmlNodeSetPtr nsetCalendars; - int c, rv = 0; /* reading eressea/buildings/building */ xpathCalendars = xmlXPathEvalExpression(BAD_CAST "/eressea/calendar", xpath); nsetCalendars = xpathCalendars->nodesetval; months_per_year = 0; - if (nsetCalendars == NULL || nsetCalendars->nodeNr == 0) { - rv = -1; - } - else + if (nsetCalendars != NULL && nsetCalendars->nodeNr != 0) { + int c; for (c = 0; c != nsetCalendars->nodeNr; ++c) { xmlNodePtr calendar = nsetCalendars->nodeTab[c]; xmlXPathObjectPtr xpathWeeks, xpathMonths, xpathSeasons; @@ -477,10 +474,11 @@ static int parse_calendar(xmlDocPtr doc) xmlFree(newyear); newyear = NULL; } + } xmlXPathFreeObject(xpathCalendars); xmlXPathFreeContext(xpath); - return rv; + return 0; } static int parse_ships(xmlDocPtr doc) From 60497da87b74c4228523e63d927c741abafa2d67 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 Feb 2017 20:50:07 +0100 Subject: [PATCH 192/271] print error message when missing parameter translation. --- src/kernel/xmlreader.c | 3 +-- src/util/language.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index cd3331517..6491daf20 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -359,7 +359,6 @@ static int parse_calendar(xmlDocPtr doc) xmlXPathObjectPtr xpathCalendars; xmlNodeSetPtr nsetCalendars; - /* reading eressea/buildings/building */ xpathCalendars = xmlXPathEvalExpression(BAD_CAST "/eressea/calendar", xpath); nsetCalendars = xpathCalendars->nodesetval; months_per_year = 0; @@ -374,7 +373,7 @@ static int parse_calendar(xmlDocPtr doc) xmlChar *start; start = xmlGetProp(calendar, BAD_CAST "start"); - if (start && config_get("game.start")==NULL) { + if (start && config_get("game.start") == NULL) { config_set("game.start", (const char *)start); xmlFree(start); } diff --git a/src/util/language.c b/src/util/language.c index 300e69103..0de04be71 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -300,6 +300,9 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ struct critbit_tree ** cb = (struct critbit_tree **)tokens; add_translation(cb, key, i); } + else { + log_error("no translation for %s in locale %s", s, lang->name); + } } } } From f48dd415380b82b509447650bd96221b9a4b37c8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 Feb 2017 21:37:38 +0100 Subject: [PATCH 193/271] fix a segfault in free_Races --- src/kernel/config.c | 2 +- src/kernel/race.c | 8 +++++++- src/kernel/race.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index ca23a5bc9..b2734d43a 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -203,7 +203,7 @@ param_t findparam(const char *s, const struct locale * lang) void **tokens = get_translations(lang, UT_PARAMS); critbit_tree *cb = (critbit_tree *)*tokens; if (!cb) { - log_warning("no parameters defined in locale %s", locale_name(lang)); + log_error("no parameters defined in locale %s", locale_name(lang)); } else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { cb_get_kv(match, &i, sizeof(int)); diff --git a/src/kernel/race.c b/src/kernel/race.c index c7c2e8165..a4a11c15d 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -269,7 +269,13 @@ void free_races(void) { free(opt); } for (i = 0; races->attack[i].type!=AT_NONE; ++i) { - spellref_free(races->attack[i].data.sp); + att *at = races->attack + i; + if (at->type == AT_SPELL) { + spellref_free(at->data.sp); + } + else { + free(at->data.dice); + } } spellref_free(races->precombatspell); free(xrefs); diff --git a/src/kernel/race.h b/src/kernel/race.h index 6321d4f22..c58bad701 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -105,7 +105,7 @@ extern "C" { typedef struct att { int type; union { - const char *dice; + char *dice; struct spellref *sp; } data; int flags; From b504899b07fbcc48f9c96cec85da3c2e4d066561 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 9 Feb 2017 23:28:50 +0100 Subject: [PATCH 194/271] fix locale initialization --- src/bind_config.c | 2 -- src/bindings.c | 2 +- src/kernel/config.c | 2 +- src/laws.c | 1 + src/util/language.c | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index faf543f47..c603800ed 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -22,7 +22,6 @@ void config_reset(void) { default_locale = 0; free_config(); - free_locales(); free_nrmesssages(); free_spells(); free_buildingtypes(); @@ -37,7 +36,6 @@ int config_parse(const char *json) if (conf) { json_config(conf); cJSON_Delete(conf); - init_locales(); return 0; } else { diff --git a/src/bindings.c b/src/bindings.c index 7bf30202a..1515c74e0 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -517,7 +517,7 @@ static void reset_game(void) for (f = factions; f; f = f->next) { f->flags &= FFL_SAVEMASK; } - init_locales(); +// init_locales(); } static int tolua_process_orders(lua_State * L) diff --git a/src/kernel/config.c b/src/kernel/config.c index b2734d43a..ca23a5bc9 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -203,7 +203,7 @@ param_t findparam(const char *s, const struct locale * lang) void **tokens = get_translations(lang, UT_PARAMS); critbit_tree *cb = (critbit_tree *)*tokens; if (!cb) { - log_error("no parameters defined in locale %s", locale_name(lang)); + log_warning("no parameters defined in locale %s", locale_name(lang)); } else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { cb_get_kv(match, &i, sizeof(int)); diff --git a/src/laws.c b/src/laws.c index 98ff5d9f6..78ca6fba9 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4196,6 +4196,7 @@ void init_processor(void) void processorders(void) { + init_locales(); init_processor(); process(); /*************************************************/ diff --git a/src/util/language.c b/src/util/language.c index 0de04be71..86a6895be 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -301,7 +301,7 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ add_translation(cb, key, i); } else { - log_error("no translation for %s in locale %s", s, lang->name); + log_warning("no translation for %s in locale %s", s, lang->name); } } } From 2ee0e599b173295f45fabf58124e2063047ce3b1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 17:38:39 +0100 Subject: [PATCH 195/271] initialize game after loading config --- scripts/eressea/xmlconf.lua | 1 + src/bind_eressea.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 9d87f3f3e..584f8d3e2 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -7,3 +7,4 @@ if config.rules then assert(0 == read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data") end +eressea.game.reset() diff --git a/src/bind_eressea.c b/src/bind_eressea.c index 279ce8f4e..de8751306 100755 --- a/src/bind_eressea.c +++ b/src/bind_eressea.c @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -16,6 +18,7 @@ void eressea_free_game(void) { free_gamedata(); init_resources(); + init_locales(); } int eressea_read_game(const char * filename) { From 853f63b50129f1d0d7ab0013f7e330c760f69daf Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 20:27:13 +0100 Subject: [PATCH 196/271] delete unitmessage trigger, it is unused --- src/spells.c | 1 - src/triggers/CMakeLists.txt | 1 - src/triggers/triggers.c | 2 - src/triggers/unitmessage.c | 124 ------------------------------------ src/triggers/unitmessage.h | 37 ----------- 5 files changed, 165 deletions(-) delete mode 100644 src/triggers/unitmessage.c delete mode 100644 src/triggers/unitmessage.h diff --git a/src/spells.c b/src/spells.c index 0bb6df5af..e936a46a2 100644 --- a/src/spells.c +++ b/src/spells.c @@ -95,7 +95,6 @@ #include #include #include -#include /* attributes includes */ #include diff --git a/src/triggers/CMakeLists.txt b/src/triggers/CMakeLists.txt index d6670a95b..e123698d6 100644 --- a/src/triggers/CMakeLists.txt +++ b/src/triggers/CMakeLists.txt @@ -11,7 +11,6 @@ killunit.c shock.c timeout.c triggers.c -unitmessage.c ) FOREACH(_FILE ${_FILES}) LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE}) diff --git a/src/triggers/triggers.c b/src/triggers/triggers.c index 433201abd..8826fcba2 100644 --- a/src/triggers/triggers.c +++ b/src/triggers/triggers.c @@ -28,7 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include /* util includes */ @@ -47,7 +46,6 @@ void register_triggers(void) tt_register(&tt_giveitem); tt_register(&tt_killunit); tt_register(&tt_shock); - tt_register(&tt_unitmessage); tt_register(&tt_timeout); tt_register(&tt_clonedied); } diff --git a/src/triggers/unitmessage.c b/src/triggers/unitmessage.c deleted file mode 100644 index 7ba97d9bc..000000000 --- a/src/triggers/unitmessage.c +++ /dev/null @@ -1,124 +0,0 @@ -/* -+-------------------+ Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -+-------------------+ -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ - -#include -#include "unitmessage.h" - -/* kernel includes */ -#include -#include -#include - -/* util includes */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* ansi includes */ -#include -#include -#include -#include - -/*** -** give an item to someone -**/ - -typedef struct unitmessage_data { - struct unit *target; - char *string; - int type; - int level; -} unitmessage_data; - -static void unitmessage_init(trigger * t) -{ - t->data.v = calloc(sizeof(unitmessage_data), 1); -} - -static void unitmessage_free(trigger * t) -{ - unitmessage_data *sd = (unitmessage_data *)t->data.v; - free(sd->string); - free(t->data.v); -} - -static int unitmessage_handle(trigger * t, void *data) -{ - /* call an event handler on unitmessage. - * data.v -> ( variant event, int timer ) - */ - unitmessage_data *td = (unitmessage_data *)t->data.v; - if (td->target && td->target->no) { - struct faction *f = td->target->faction; - const char * str = LOC(f->locale, td->string); - /* bug found in turn 733: sometimes, alps have f*cked up messages */ - if (td->string && td->string[0]) { - addmessage(td->target->region, f, str, td->type, - td->level); - } - } - UNUSED_ARG(data); - return 0; -} - -static void unitmessage_write(const trigger * t, struct storage *store) -{ - unitmessage_data *td = (unitmessage_data *)t->data.v; - write_unit_reference(td->target, store); - WRITE_TOK(store, td->string); - WRITE_INT(store, td->type); - WRITE_INT(store, td->level); -} - -static int unitmessage_read(trigger * t, gamedata *data) -{ - unitmessage_data *td = (unitmessage_data *)t->data.v; - char zText[256]; - - int result = read_reference(&td->target, data, read_unit_reference, - resolve_unit); - READ_TOK(data->store, zText, sizeof(zText)); - td->string = strdup(zText); - READ_INT(data->store, &td->type); - READ_INT(data->store, &td->level); - - if (result == 0 && td->target == NULL) { - return AT_READ_FAIL; - } - return AT_READ_OK; -} - -trigger_type tt_unitmessage = { - "unitmessage", - unitmessage_init, - unitmessage_free, - unitmessage_handle, - unitmessage_write, - unitmessage_read -}; - -trigger *trigger_unitmessage(unit * target, const char *string, int type, - int level) -{ - trigger *t = t_new(&tt_unitmessage); - unitmessage_data *td = (unitmessage_data *)t->data.v; - td->target = target; - td->string = strdup(string); - td->type = type; - td->level = level; - return t; -} diff --git a/src/triggers/unitmessage.h b/src/triggers/unitmessage.h deleted file mode 100644 index 5b5b0793b..000000000 --- a/src/triggers/unitmessage.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef UNITMESSAGE_H -#define UNITMESSAGE_H -#ifdef __cplusplus -extern "C" { -#endif - - /* all types we use are defined here to reduce dependencies */ - struct trigger_type; - struct trigger; - struct unit; - - extern struct trigger_type tt_unitmessage; - extern struct trigger *trigger_unitmessage(struct unit *target, - const char *string, int type, int level); - -#ifdef __cplusplus -} -#endif -#endif From c897108a2cf29a0f562d44da294d91b2a749db9c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 20:58:34 +0100 Subject: [PATCH 197/271] clibs latest --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index f91ef37f0..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 From 10e78b1455147442a4334a3f6c845545ba2c0244 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 22:15:21 +0100 Subject: [PATCH 198/271] remove code for dict and lua .objects properties. rewrite muschelplateau code to use keys. --- scripts/eressea/embassy.lua | 18 +--- src/CMakeLists.txt | 1 - src/attributes/dict.c | 179 +++++++++------------------------- src/attributes/dict.h | 7 -- src/attributes/key.c | 2 +- src/bind_dict.c | 185 ------------------------------------ src/bind_dict.h | 26 ----- src/bind_faction.c | 40 ++++++-- src/bind_region.c | 13 +-- src/bind_unit.c | 8 -- src/bindings.c | 2 - 11 files changed, 79 insertions(+), 402 deletions(-) delete mode 100644 src/bind_dict.c delete mode 100644 src/bind_dict.h diff --git a/scripts/eressea/embassy.lua b/scripts/eressea/embassy.lua index 82bce62c2..704581c6f 100644 --- a/scripts/eressea/embassy.lua +++ b/scripts/eressea/embassy.lua @@ -1,19 +1,5 @@ -- Muschelplateau --- global exports (use item) -function use_seashell(u, amount) --- Muschelplateau... - local visit = u.faction.objects:get("embassy_muschel") - if visit and u.region~= home then - local turns = get_turn() - visit - local msg = message.create('msg_event') - msg:set_string("string", u.name .. "(" .. itoa36(u.id) .. ") erzählt den Bewohnern von " .. u.region.name .. " von Muschelplateau, das die Partei " .. u.faction.name .. " vor " .. turns .. " Wochen besucht hat." ) - msg:send_region(u.region) - return 0 - end - return -4 -end - if not config.embassy then return nil end local embassy = {} @@ -34,10 +20,10 @@ function embassy.update() eressea.log.debug("updating embassies in " .. tostring(home)) local u for u in home.units do - if u.faction.objects:get('embassy_muschel')==nil then + if not u.faction:get_key('mupL') then if (u.faction:add_item('seashell', 1)>0) then eressea.log.debug("new seashell for " .. tostring(u.faction)) - u.faction.objects:set('embassy_muschel', get_turn()) + u.faction:set_key('mupL', get_turn()) end end end diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a65cb8912..b4d3614e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,7 +148,6 @@ set(SERVER_SRC bind_locale.c bind_eressea.c bind_faction.c - bind_dict.c bind_order.c bindings.c bind_message.c diff --git a/src/attributes/dict.c b/src/attributes/dict.c index a3f034145..6d4b3ed3c 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "dict.h" +#include "key.h" /* kernel includes */ #include @@ -29,6 +30,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include +#include +#include #include #include @@ -54,46 +57,6 @@ typedef struct dict_data { } data; } dict_data; -static void -dict_write(const attrib * a, const void *owner, struct storage *store) -{ - const dict_data *data = (dict_data *)a->data.v; - int type = (int)data->type; - WRITE_TOK(store, data->name); - WRITE_INT(store, type); - switch (data->type) { - case TINTEGER: - WRITE_INT(store, data->data.i); - break; - case TREAL: - WRITE_FLT(store, (float)data->data.real); - break; - case TSTRING: - WRITE_STR(store, data->data.str); - break; - case TUNIT: - write_unit_reference(data->data.u, store); - break; - case TFACTION: - write_faction_reference(data->data.f, store); - break; - case TBUILDING: - write_building_reference(data->data.b, store); - break; - case TSHIP: - /* write_ship_reference(data->data.sh, store); */ - assert(!"not implemented"); - break; - case TREGION: - write_region_reference(data->data.r, store); - break; - case TNONE: - break; - default: - assert(!"illegal type in object-attribute"); - } -} - static int dict_read(attrib * a, void *owner, gamedata *data) { storage *store = data->store; @@ -164,7 +127,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data) default: return AT_READ_FAIL; } - return AT_READ_OK; + return AT_READ_DEPR; } static void dict_init(attrib * a) @@ -184,100 +147,46 @@ static void dict_done(attrib * a) free(a->data.v); } +static void dict_upgrade(attrib **alist, attrib *abegin) { + int n = 0, *keys = 0; + int i = 0, val[4]; + attrib *a, *ak = a_find(*alist, &at_keys); + if (ak) { + keys = (int *)ak->data.v; + if (keys) n = keys[0]; + } + for (a = abegin; a && a->type == abegin->type; a = a->next) { + dict_data *dd = (dict_data *)a->data.v; + if (dd->type != TINTEGER) { + log_error("dict conversion, bad type %d for %s", dd->type, dd->name); + } + else { + if (strcmp(dd->name, "embassy_muschel")==0) { + val[i++] = atoi36("mupL"); + } + else { + log_error("dict conversion, bad entry %s", dd->name); + } + } + if (i == 4) { + keys = realloc(keys, sizeof(int) * (n + i + 1)); + memcpy(keys + n + 1, val, sizeof(int)*i); + n += i; + i = 0; + } + } + if (i > 0) { + keys = realloc(keys, sizeof(int) * (n + i + 1)); + memcpy(keys + n + 1, val, sizeof(int)*i); + if (!ak) { + ak = a_add(alist, a_new(&at_keys)); + } + } + ak->data.v = keys; + keys[0] = n + i; +} + attrib_type at_dict = { "object", dict_init, dict_done, NULL, - dict_write, dict_read + NULL, dict_read, dict_upgrade }; - -const char *dict_name(const attrib * a) -{ - dict_data *data = (dict_data *)a->data.v; - return data->name; -} - -struct attrib *dict_create(const char *name, dict_type type, variant value) -{ - attrib *a = a_new(&at_dict); - dict_data *data = (dict_data *)a->data.v; - data->name = strdup(name); - - dict_set(a, type, value); - return a; -} - -void dict_set(attrib * a, dict_type type, variant value) -{ - dict_data *data = (dict_data *)a->data.v; - - if (data->type == TSTRING) - free(data->data.str); - data->type = type; - switch (type) { - case TSTRING: - data->data.str = value.v ? strdup(value.v) : NULL; - break; - case TINTEGER: - data->data.i = value.i; - break; - case TREAL: - data->data.real = value.f; - break; - case TREGION: - data->data.r = (region *)value.v; - break; - case TBUILDING: - data->data.b = (building *)value.v; - break; - case TFACTION: - data->data.f = (faction *)value.v; - break; - case TUNIT: - data->data.u = (unit *)value.v; - break; - case TSHIP: - data->data.sh = (ship *)value.v; - break; - case TNONE: - break; - default: - assert(!"invalid object-type"); - break; - } -} - -void dict_get(const struct attrib *a, dict_type * type, variant * value) -{ - dict_data *data = (dict_data *)a->data.v; - *type = data->type; - switch (data->type) { - case TSTRING: - value->v = data->data.str; - break; - case TINTEGER: - value->i = data->data.i; - break; - case TREAL: - value->f = (float)data->data.real; - break; - case TREGION: - value->v = data->data.r; - break; - case TBUILDING: - value->v = data->data.b; - break; - case TFACTION: - value->v = data->data.f; - break; - case TUNIT: - value->v = data->data.u; - break; - case TSHIP: - value->v = data->data.sh; - break; - case TNONE: - break; - default: - assert(!"invalid object-type"); - break; - } -} diff --git a/src/attributes/dict.h b/src/attributes/dict.h index 5b282779e..7b028fa00 100644 --- a/src/attributes/dict.h +++ b/src/attributes/dict.h @@ -26,13 +26,6 @@ extern "C" { extern struct attrib_type at_dict; - struct attrib *dict_create(const char *name, dict_type type, - variant value); - void dict_get(const struct attrib *a, dict_type * type, - variant * value); - void dict_set(struct attrib *a, dict_type type, variant value); - const char *dict_name(const struct attrib *a); - #ifdef __cplusplus } #endif diff --git a/src/attributes/key.c b/src/attributes/key.c index 0b252e0c0..ef4b79ad5 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -66,7 +66,7 @@ attrib_type at_keys = { NULL }; -void a_upgradekeys(attrib **alist, attrib *abegin) { +static void a_upgradekeys(attrib **alist, attrib *abegin) { int n = 0, *keys = 0; int i = 0, val[4]; attrib *a, *ak = a_find(*alist, &at_keys); diff --git a/src/bind_dict.c b/src/bind_dict.c deleted file mode 100644 index 40f73690f..000000000 --- a/src/bind_dict.c +++ /dev/null @@ -1,185 +0,0 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ - -#include -#include "bind_dict.h" - -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include -#include - -static int tolua_dict_get(lua_State * L) -{ - dict self = (dict)tolua_tousertype(L, 1, 0); - const char *name = tolua_tostring(L, 2, 0); - attrib *a = a_find(*self, &at_dict); - - for (; a && a->type == &at_dict; a = a->next) { - const char *obj_name = dict_name(a); - if (obj_name && name && strcmp(obj_name, name) == 0) { - variant val; - dict_type type; - - dict_get(a, &type, &val); - switch (type) { - case TNONE: - lua_pushnil(L); - break; - case TINTEGER: - lua_pushinteger(L, val.i); - break; - case TREAL: - lua_pushnumber(L, (lua_Number)val.f); - break; - case TREGION: - tolua_pushusertype(L, val.v, TOLUA_CAST "region"); - break; - case TBUILDING: - tolua_pushusertype(L, val.v, TOLUA_CAST "building"); - break; - case TUNIT: - tolua_pushusertype(L, val.v, TOLUA_CAST "unit"); - break; - case TSHIP: - tolua_pushusertype(L, val.v, TOLUA_CAST "ship"); - break; - case TSTRING: - tolua_pushstring(L, (const char *)val.v); - break; - default: - assert(!"not implemented"); - } - return 1; - } - } - lua_pushnil(L); - return 1; -} - -static int tolua_dict_set_number(lua_State * L) -{ - dict self = (dict)tolua_tousertype(L, 1, 0); - const char *name = tolua_tostring(L, 2, 0); - lua_Number value = tolua_tonumber(L, 3, 0); - attrib *a = a_find(*self, &at_dict); - variant val; - - val.f = (float)value; - - for (; a && a->type == &at_dict; a = a->next) { - if (strcmp(dict_name(a), name) == 0) { - dict_set(a, TREAL, val); - return 0; - } - } - - a = a_add(self, dict_create(name, TREAL, val)); - return 0; -} - -static int tolua_dict_set_string(lua_State * L) -{ - dict self = (dict)tolua_tousertype(L, 1, 0); - const char *name = tolua_tostring(L, 2, 0); - const char *value = tolua_tostring(L, 3, 0); - attrib *a = a_find(*self, &at_dict); - variant val; - - val.v = strdup(value); - - for (; a && a->type == &at_dict; a = a->next) { - if (strcmp(dict_name(a), name) == 0) { - dict_set(a, TSTRING, val); - return 0; - } - } - - a = a_add(self, dict_create(name, TSTRING, val)); - return 0; -} - -static int tolua_dict_set_usertype(lua_State * L, int type) -{ - dict self = (dict)tolua_tousertype(L, 1, 0); - const char *name = tolua_tostring(L, 2, 0); - unit *value = tolua_tousertype(L, 3, 0); - attrib *a = a_find(*self, &at_dict); - variant val; - - val.v = value; - - for (; a && a->type == &at_dict; a = a->next) { - if (strcmp(dict_name(a), name) == 0) { - dict_set(a, type, val); - return 0; - } - } - - a = a_add(self, dict_create(name, type, val)); - return 0; -} - -static int tolua_dict_set(lua_State * L) -{ - tolua_Error tolua_err; - if (tolua_isnumber(L, 3, 0, &tolua_err)) { - return tolua_dict_set_number(L); - } - else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &tolua_err)) { - return tolua_dict_set_usertype(L, TUNIT); - } - else if (tolua_isusertype(L, 3, TOLUA_CAST "faction", 0, &tolua_err)) { - return tolua_dict_set_usertype(L, TFACTION); - } - else if (tolua_isusertype(L, 3, TOLUA_CAST "ship", 0, &tolua_err)) { - return tolua_dict_set_usertype(L, TSHIP); - } - else if (tolua_isusertype(L, 3, TOLUA_CAST "building", 0, &tolua_err)) { - return tolua_dict_set_usertype(L, TBUILDING); - } - else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &tolua_err)) { - return tolua_dict_set_usertype(L, TREGION); - } - return tolua_dict_set_string(L); -} - -void tolua_dict_open(lua_State * L) -{ - /* register user types */ - tolua_usertype(L, USERTYPE_DICT); - - tolua_module(L, NULL, 0); - tolua_beginmodule(L, NULL); - { - tolua_cclass(L, USERTYPE_DICT, USERTYPE_DICT, - TOLUA_CAST "", NULL); - tolua_beginmodule(L, USERTYPE_DICT); - { - tolua_function(L, TOLUA_CAST "get", tolua_dict_get); - tolua_function(L, TOLUA_CAST "set", tolua_dict_set); - } - tolua_endmodule(L); - } - tolua_endmodule(L); -} diff --git a/src/bind_dict.h b/src/bind_dict.h deleted file mode 100644 index 83ca1efbf..000000000 --- a/src/bind_dict.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#define USERTYPE_DICT ((char *)"dict") - - struct lua_State; - void tolua_dict_open(struct lua_State *L); - - typedef struct attrib **dict; - -#ifdef __cplusplus -} -#endif diff --git a/src/bind_faction.c b/src/bind_faction.c index f5c393de6..749bb65f6 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -13,7 +13,6 @@ without prior permission by the authors of Eressea. #include #include "bind_faction.h" #include "bind_unit.h" -#include "bind_dict.h" #include "bindings.h" #include "helpers.h" @@ -27,7 +26,9 @@ without prior permission by the authors of Eressea. #include #include #include +#include +#include #include #include #include @@ -241,6 +242,32 @@ static int tolua_faction_addnotice(lua_State * L) return 0; } +static int tolua_faction_getkey(lua_State * L) +{ + faction *self = (faction *)tolua_tousertype(L, 1, 0); + const char *name = tolua_tostring(L, 2, 0); + int flag = atoi36(name); + + lua_pushboolean(L, key_get(self->attribs, flag)); + return 1; +} + +static int tolua_faction_setkey(lua_State * L) +{ + faction *self = (faction *)tolua_tousertype(L, 1, 0); + const char *name = tolua_tostring(L, 2, 0); + int value = tolua_toboolean(L, 3, 0); + int flag = atoi36(name); + + if (value) { + key_set(&self->attribs, flag); + } + else { + key_unset(&self->attribs, flag); + } + return 0; +} + static int tolua_faction_count_msg_type(lua_State *L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); const char *str = tolua_tostring(L, 2, 0); @@ -258,13 +285,6 @@ static int tolua_faction_count_msg_type(lua_State *L) { return 1; } -static int tolua_faction_get_objects(lua_State * L) -{ - faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT); - return 1; -} - static int tolua_faction_get_policy(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); @@ -618,8 +638,8 @@ void tolua_faction_open(lua_State * L) /* tech debt hack, siehe https://paper.dropbox.com/doc/Weihnachten-2015-5tOx5r1xsgGDBpb0gILrv#:h=Probleme-mit-Tests-(Nachtrag-0 */ tolua_function(L, TOLUA_CAST "count_msg_type", tolua_faction_count_msg_type); - tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects, - NULL); + tolua_function(L, TOLUA_CAST "get_key", tolua_faction_getkey); + tolua_function(L, TOLUA_CAST "set_key", tolua_faction_setkey); } tolua_endmodule(L); } diff --git a/src/bind_region.c b/src/bind_region.c index 2e328dc96..d9956c8b6 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -14,7 +14,6 @@ without prior permission by the authors of Eressea. #include "bind_region.h" #include "bind_unit.h" #include "bind_ship.h" -#include "bind_dict.h" #include "bind_building.h" #include "chaos.h" @@ -36,10 +35,11 @@ without prior permission by the authors of Eressea. #include #include -#include #include #include +#include + #include #include @@ -434,13 +434,6 @@ static int tolua_region_set_resource(lua_State * L) return 0; } -static int tolua_region_get_objects(lua_State * L) -{ - region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT); - return 1; -} - static int tolua_region_destroy(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); @@ -733,8 +726,6 @@ void tolua_region_open(lua_State * L) tolua_function(L, TOLUA_CAST "get_key", tolua_region_getkey); tolua_function(L, TOLUA_CAST "set_key", tolua_region_setkey); - - tolua_variable(L, TOLUA_CAST "objects", tolua_region_get_objects, 0); } tolua_endmodule(L); diff --git a/src/bind_unit.c b/src/bind_unit.c index 1983e0f62..c0939b5cf 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -13,7 +13,6 @@ without prior permission by the authors of Eressea. #include #include "bind_unit.h" -#include "bind_dict.h" #include "alchemy.h" #include "bindings.h" #include "move.h" @@ -67,12 +66,6 @@ static int tolua_bufunit(lua_State * L) { return 1; } -static int tolua_unit_get_objects(lua_State * L) -{ - unit *self = (unit *)tolua_tousertype(L, 1, 0); - tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT); - return 1; -} int tolua_unitlist_nextf(lua_State * L) { @@ -1013,7 +1006,6 @@ void tolua_unit_open(lua_State * L) tolua_unit_set_race); tolua_variable(L, TOLUA_CAST "hp_max", &tolua_unit_get_hpmax, 0); - tolua_variable(L, TOLUA_CAST "objects", &tolua_unit_get_objects, 0); tolua_function(L, TOLUA_CAST "show", &tolua_bufunit); } tolua_endmodule(L); diff --git a/src/bindings.c b/src/bindings.c index 1515c74e0..2e4ed3dc6 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -15,7 +15,6 @@ without prior permission by the authors of Eressea. #include "bind_unit.h" #include "bind_storage.h" #include "bind_building.h" -#include "bind_dict.h" #include "bind_message.h" #include "bind_building.h" #include "bind_faction.h" @@ -1143,7 +1142,6 @@ lua_State *lua_init(const dictionary *inifile) { tolua_unit_open(L); tolua_message_open(L); tolua_order_open(L); - tolua_dict_open(L); #ifdef USE_CURSES tolua_gmtool_open(L); #endif From 40de740a0aa06e6b036ca9fe03b1f0a4fee3dc74 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 22:24:36 +0100 Subject: [PATCH 199/271] remove dict from ships and buildings, too --- src/bind_building.c | 9 --------- src/bind_ship.c | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/src/bind_building.c b/src/bind_building.c index f8cf4e6df..ea689bfb5 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -13,7 +13,6 @@ without prior permission by the authors of Eressea. #include #include "bind_building.h" #include "bind_unit.h" -#include "bind_dict.h" #include #include @@ -41,13 +40,6 @@ int tolua_buildinglist_next(lua_State * L) return 0; /* no more values to return */ } -static int tolua_building_get_objects(lua_State * L) -{ - building *self = (building *)tolua_tousertype(L, 1, 0); - tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT); - return 1; -} - static int tolua_building_set_working(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); @@ -258,7 +250,6 @@ void tolua_building_open(lua_State * L) tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size, tolua_building_set_size); tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename); - tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0); tolua_variable(L, TOLUA_CAST "working", tolua_building_get_working, tolua_building_set_working); } diff --git a/src/bind_ship.c b/src/bind_ship.c index 95006cf5f..515fa8de3 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -13,7 +13,6 @@ without prior permission by the authors of Eressea. #include #include "bind_ship.h" #include "bind_unit.h" -#include "bind_dict.h" #include "move.h" @@ -115,13 +114,6 @@ static int tolua_ship_get_units(lua_State * L) return 1; } -static int tolua_ship_get_objects(lua_State * L) -{ - ship *self = (ship *)tolua_tousertype(L, 1, 0); - tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT); - return 1; -} - static int tolua_ship_create(lua_State * L) { region *r = (region *)tolua_tousertype(L, 1, 0); @@ -233,8 +225,6 @@ void tolua_ship_open(lua_State * L) tolua_variable(L, TOLUA_CAST "type", tolua_ship_get_type, 0); tolua_variable(L, TOLUA_CAST "damage", tolua_ship_get_damage, tolua_ship_set_damage); - tolua_variable(L, TOLUA_CAST "objects", tolua_ship_get_objects, 0); - tolua_function(L, TOLUA_CAST "create", tolua_ship_create); } tolua_endmodule(L); From f6fcd392934fbaa90d2edb72421114da09d6f564 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 22:28:57 +0100 Subject: [PATCH 200/271] add a failing test for familiars (disabled). remove superfluous init_locales calls. --- src/bind_config.c | 1 - src/kernel/save.c | 1 - src/laws.c | 1 - src/magic.test.c | 20 ++++++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index c603800ed..b4aa68d58 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -20,7 +20,6 @@ #include "kernel/terrain.h" void config_reset(void) { - default_locale = 0; free_config(); free_nrmesssages(); free_spells(); diff --git a/src/kernel/save.c b/src/kernel/save.c index 8ec797e68..67ed7e125 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1470,7 +1470,6 @@ int readgame(const char *filename) FILE *F; size_t sz; - init_locales(); log_debug("- reading game data from %s", filename); join_path(datapath(), filename, path, sizeof(path)); diff --git a/src/laws.c b/src/laws.c index 78ca6fba9..98ff5d9f6 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4196,7 +4196,6 @@ void init_processor(void) void processorders(void) { - init_locales(); init_processor(); process(); /*************************************************/ diff --git a/src/magic.test.c b/src/magic.test.c index 4a6078589..07a6d5257 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -2,6 +2,7 @@ #include "magic.h" #include "teleport.h" +#include "give.h" #include #include @@ -448,6 +449,24 @@ static void test_max_spellpoints(CuTest *tc) { test_cleanup(); } +static void test_familiar_mage(CuTest *tc) { + unit *um, *uf, *ut; + test_setup(); + um = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + uf = test_create_unit(um->faction, um->region); + ut = test_create_unit(um->faction, um->region); + set_number(ut, 0); + CuAssertTrue(tc, create_newfamiliar(um, uf)); + CuAssertTrue(tc, is_familiar(uf)); + CuAssertTrue(tc, !is_familiar(um)); + CuAssertPtrEquals(tc, um, get_familiar_mage(uf)); + CuAssertPtrEquals(tc, uf, get_familiar(um)); + + CuAssertPtrEquals(tc, NULL, give_men(1, um, ut, NULL)); + CuAssertPtrEquals(tc, ut, get_familiar_mage(uf)); + test_cleanup(); +} + CuSuite *get_magic_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -465,5 +484,6 @@ CuSuite *get_magic_suite(void) SUITE_ADD_TEST(suite, test_hasspell); SUITE_ADD_TEST(suite, test_magic_resistance); SUITE_ADD_TEST(suite, test_max_spellpoints); + DISABLE_TEST(suite, test_familiar_mage); return suite; } From b56538e0923475992d62e0e875c252f21d67bc53 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Feb 2017 22:37:15 +0100 Subject: [PATCH 201/271] remove test for dicts --- scripts/tests/common.lua | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 670060816..96673bfd3 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -330,17 +330,6 @@ function test_message() return msg end -function test_hashtable() - local f = faction.create("noreply1@eressea.de", "human", "de") - f.objects:set("enno", "smart guy") - f.objects:set("age", 10) - assert(f.objects:get("jesus") == nil) - assert(f.objects:get("enno") == "smart guy") - assert(f.objects:get("age") == 10) - f.objects:set("age", nil) - assert(f.objects:get("age") == nil) -end - function test_events() local fail = 1 local function msg_handler(u, evt) From e5c95f1501a7800eed9ac1f113058715671b7221 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 Feb 2017 10:39:54 +0100 Subject: [PATCH 202/271] avoid division by zero when no calendar is configured --- src/kernel/xmlreader.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 6491daf20..d89259317 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -361,7 +361,6 @@ static int parse_calendar(xmlDocPtr doc) xpathCalendars = xmlXPathEvalExpression(BAD_CAST "/eressea/calendar", xpath); nsetCalendars = xpathCalendars->nodesetval; - months_per_year = 0; if (nsetCalendars != NULL && nsetCalendars->nodeNr != 0) { int c; for (c = 0; c != nsetCalendars->nodeNr; ++c) { From 17ff2ead416576937212d7ccb140a2d41e389a64 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 05:52:46 +0100 Subject: [PATCH 203/271] make_locales from config_get --- clibs | 2 +- src/kernel/xmlreader.c | 4 ---- src/main.c | 6 +++--- src/util/language.c | 6 +++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/clibs b/clibs index 27c8b3202..f91ef37f0 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 +Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index d89259317..5ce6800ef 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -66,10 +66,6 @@ static void xml_readtext(xmlNodePtr node, struct locale **lang, xmlChar ** text) xmlChar *propValue = xmlGetProp(node, BAD_CAST "locale"); assert(propValue != NULL); *lang = get_locale((const char *)propValue); -#ifdef MAKE_LOCALES - if (*lang == NULL) - *lang = get_or_create_locale((const char *)propValue); -#endif xmlFree(propValue); *text = xmlNodeListGetString(node->doc, node->children, 1); diff --git a/src/main.c b/src/main.c index a3bcdb866..875a33bf9 100644 --- a/src/main.c +++ b/src/main.c @@ -70,15 +70,13 @@ static void load_inifile(dictionary * d) lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0; verbosity = iniparser_getint(d, "game:verbose", 2); - str = iniparser_getstring(d, "game:locales", "de,en"); - make_locales(str); } static dictionary *parse_config(const char *filename) { char path[MAX_PATH]; dictionary *d; - const char *cfgpath = config_get("config.path"); + const char *str, *cfgpath = config_get("config.path"); if (cfgpath) { join_path(cfgpath, filename, path, sizeof(path)); @@ -99,6 +97,8 @@ static dictionary *parse_config(const char *filename) gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage); #endif } + str = config_get("game.locales"); + make_locales(str ? str : "de,en"); return d; } diff --git a/src/util/language.c b/src/util/language.c index 86a6895be..3f628036d 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -327,10 +327,10 @@ static int locale_init = 0; void init_locales(void) { - int l; + locale * lang; if (locale_init) return; - for (l = 0; localenames[l]; ++l) { - struct locale *lang = get_or_create_locale(localenames[l]); + assert(locales); + for (lang = locales; lang; lang = lang->next) { init_locale(lang); } locale_init = 1; From 6893248473d740557197b2f4d5405c5197f84c6f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:06:33 +0100 Subject: [PATCH 204/271] jsonconf should not need to create locales --- src/kernel/jsonconf.c | 8 ++++---- src/kernel/jsonconf.test.c | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 7a074a410..89219665e 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -654,7 +654,7 @@ static void json_strings(cJSON *json) { } for (child = json->child; child; child = child->next) { if (child->type == cJSON_Object) { - struct locale *lang = get_or_create_locale(child->string); + struct locale *lang = get_locale(child->string); json_locale(child, lang); } else { @@ -695,7 +695,7 @@ static void json_directions(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - struct locale * lang = get_or_create_locale(child->string); + struct locale * lang = get_locale(child->string); json_direction(child, lang); } } @@ -771,7 +771,7 @@ static void json_skills(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - struct locale * lang = get_or_create_locale(child->string); + struct locale * lang = get_locale(child->string); json_skill(child, lang); } } @@ -783,7 +783,7 @@ static void json_keywords(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - struct locale * lang = get_or_create_locale(child->string); + struct locale * lang = get_locale(child->string); json_keyword(child, lang); } } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 7c591f075..abf64e7d5 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -600,9 +600,10 @@ static void test_infinitive_from_config(CuTest *tc) { cJSON *json = cJSON_Parse(data); CuAssertPtrNotNull(tc, json); + test_setup(); + lang = get_or_create_locale("de"); json_config(json); - lang = get_or_create_locale("de"); CuAssertIntEquals(tc, K_STUDY, get_keyword("LERN", lang)); CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNE", lang)); CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang)); From ac8250ecd85b1cb31c2164b236abf867a542975e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:14:29 +0100 Subject: [PATCH 205/271] remove global read_orders binding --- src/bindings.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 2e4ed3dc6..21f2aad58 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -223,14 +223,6 @@ static int tolua_rng_int(lua_State * L) return 1; } -static int tolua_read_orders(lua_State * L) -{ - const char *filename = tolua_tostring(L, 1, 0); - int result = readorders(filename); - lua_pushinteger(L, result); - return 1; -} - static int tolua_message_unit(lua_State * L) { unit *sender = (unit *)tolua_tousertype(L, 1, 0); @@ -1072,8 +1064,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "factions", tolua_get_factions); tolua_function(L, TOLUA_CAST "regions", tolua_get_regions); tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn); -// tolua_function(L, TOLUA_CAST "write_map", &tolua_write_map); - tolua_function(L, TOLUA_CAST "read_orders", tolua_read_orders); tolua_function(L, TOLUA_CAST "process_orders", tolua_process_orders); tolua_function(L, TOLUA_CAST "init_reports", tolua_init_reports); tolua_function(L, TOLUA_CAST "write_reports", tolua_write_reports); From 75514014bc7769963d82cb7e8368118b6cbcf654 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:20:37 +0100 Subject: [PATCH 206/271] no need to create locale here --- src/reports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reports.c b/src/reports.c index 318660024..f904f5799 100644 --- a/src/reports.c +++ b/src/reports.c @@ -157,7 +157,7 @@ size_t report_status(const unit * u, const struct locale *lang, char *fsbuf, siz if (!status) { const char *lname = locale_name(lang); - struct locale *wloc = get_or_create_locale(lname); + struct locale *wloc = get_locale(lname); log_warning("no translation for combat status %s in %s", combatstatus[u->status], lname); locale_setstring(wloc, combatstatus[u->status], combatstatus[u->status]+7); len = strlcpy(fsbuf, combatstatus[u->status]+7, buflen); From a4bd4320e538db848d2e523ebc110e0ad84fc007 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 06:24:25 +0100 Subject: [PATCH 207/271] fix bad read_orders call --- scripts/run-turn.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 92efa8a14..9118ed8ee 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -146,7 +146,7 @@ function process(rules, orders) init_summary() -- run the turn: - if read_orders(orders) ~= 0 then + if eressea.read_orders(orders) ~= 0 then print("could not read " .. orders) return -1 end From b05c2564e52e212076d62568b36eba9c24d67c5f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 13:22:44 +0100 Subject: [PATCH 208/271] make att_modification not crash when a good/bad dream curse has no magician. --- clibs | 2 +- conf/e2/locales.xml | 12 ++++++++++++ src/kernel/curse.h | 2 +- src/kernel/unit.c | 2 +- src/spells.c | 6 +++--- 5 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 conf/e2/locales.xml diff --git a/clibs b/clibs index f91ef37f0..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f91ef37f08c5244bf616f1836c0aa9caaf36805c +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 diff --git a/conf/e2/locales.xml b/conf/e2/locales.xml new file mode 100644 index 000000000..f71525343 --- /dev/null +++ b/conf/e2/locales.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 4cff4f9a1..543755c2b 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -210,7 +210,7 @@ extern "C" { typedef struct curse { variant data; /* pointer auf spezielle curse-unterstructs */ struct curse *nexthash; - const curse_type *type; /* Zeiger auf ein curse_type-struct */ + const curse_type *type; /* Zeiger auf ein curse_type-struct */ struct unit *magician; /* Pointer auf den Magier, der den Spruch gewirkt hat */ double vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */ double effect; diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 27a296a15..f92916b2f 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1301,7 +1301,7 @@ static int att_modification(const unit * u, skill_t sk) while (a && a->type == &at_curse) { curse *c = (curse *)a->data.v; - if (curse_active(c) && c->type == gbdream_ct) { + if (c->magician && curse_active(c) && c->type == gbdream_ct) { int effect = curse_geteffect_int(c); bool allied = alliedunit(c->magician, u->faction, HELP_GUARD); if (allied) { diff --git a/src/spells.c b/src/spells.c index e936a46a2..19c1e81f8 100644 --- a/src/spells.c +++ b/src/spells.c @@ -4726,7 +4726,7 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) /* Erfolg melden */ ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect", - "unit region command", c->magician, mage->region, co->order)); + "unit region command", mage, mage->region, co->order)); return cast_level; } @@ -4867,7 +4867,7 @@ int sp_sweetdreams(castorder * co) effect = 0.05f; c = create_curse(mage, &u->attribs, ct_find("orcish"), power, duration, effect, men); - msg = msg_message("sp_sweetdreams_effect", "mage unit region", c->magician, u, r); + msg = msg_message("sp_sweetdreams_effect", "mage unit region", mage, u, r); r_addmessage(r, mage->faction, msg); if (u->faction != mage->faction) { r_addmessage(r, u->faction, msg); @@ -4892,7 +4892,7 @@ int sp_disturbingdreams(castorder * co) c = create_curse(mage, &r->attribs, ct_find("badlearn"), power, duration, effect, 0); ADDMSG(&mage->faction->msgs, msg_message("sp_disturbingdreams_effect", - "mage region", c->magician, r)); + "mage region", mage, r)); return cast_level; } From 4828045fd7edc52ffba69ca1081be2047f7cd0f2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 18:52:41 +0100 Subject: [PATCH 209/271] there is no NEWATSROI, remove dead code --- src/give.c | 2 +- src/kernel/unit.c | 27 --------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/src/give.c b/src/give.c index 4f8417bf2..d1a9d75f4 100644 --- a/src/give.c +++ b/src/give.c @@ -227,7 +227,7 @@ static bool can_give_men(const unit *u, const unit *dst, order *ord, message **m if (unit_has_cursed_item(u)) { if (msg) *msg = msg_error(u, ord, 78); } - else if (dst && (has_skill(u, SK_MAGIC) && dst->number > 0)) { + else if (has_skill(u, SK_MAGIC)) { /* cannot give units to and from magicians */ if (msg) *msg = msg_error(u, ord, 158); } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index f92916b2f..2f38a0836 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1245,24 +1245,6 @@ static int item_invis(const unit *u) { + (rsphere ? i_get(u->items, rsphere->itype) * 100 : 0); } -#ifdef NEWATSROI -static int item_modification(const unit * u, skill_t sk, int val) -{ - if (sk == SK_STEALTH) { - if (item_invis(u) >= u->number) { - val += ROIBONUS; - } - } - if (sk == SK_PERCEPTION) { - const struct resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); - if (i_get(u->items, rtype->itype) >= u->number) { - val += ATSBONUS; - } - } - return val; -} -#endif - static int att_modification(const unit * u, skill_t sk) { double result = 0; @@ -1335,11 +1317,6 @@ int get_modifier(const unit * u, skill_t sk, int level, const region * r, bool n skill += rc_skillmod(u_race(u), r, sk); skill += att_modification(u, sk); -#ifdef NEWATSROI - if (!noitem) { - skill = item_modification(u, sk, skill); - } -#endif skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS); if (fval(u, UFL_HUNGER)) { @@ -1382,9 +1359,6 @@ int effskill_study(const unit * u, skill_t sk, const region * r) int invisible(const unit * target, const unit * viewer) { -#ifdef NEWATSROI - return 0; -#else if (viewer && viewer->faction == target->faction) return 0; else { @@ -1398,7 +1372,6 @@ int invisible(const unit * target, const unit * viewer) } return hidden; } -#endif } /** remove the unit from memory. From 182fc3fa3c2f574685600498586972bfde848ece Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Feb 2017 19:32:27 +0100 Subject: [PATCH 210/271] remove test for bug 2253 --- src/give.test.c | 6 ------ src/spells.c | 11 ++++------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/give.test.c b/src/give.test.c index 029ee7c44..7da787c87 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -124,12 +124,6 @@ static void test_give_men_magicians(CuTest * tc) { CuAssertIntEquals(tc, 1, env.src->number); msg_release(msg); - - set_number(env.dst, 0); - CuAssertPtrEquals(tc, NULL, give_men(1, env.src, env.dst, NULL)); - CuAssertIntEquals(tc, 1, env.dst->number); - CuAssertIntEquals(tc, 0, env.src->number); - p = rpeasants(env.r); CuAssertPtrNotNull(tc, msg = disband_men(1, env.dst, NULL)); CuAssertStrEquals(tc, "give_person_peasants", (const char *)msg->parameters[0].v); diff --git a/src/spells.c b/src/spells.c index 19c1e81f8..b40192016 100644 --- a/src/spells.c +++ b/src/spells.c @@ -4714,7 +4714,6 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) int cast_level = co->level; double power = co->force; region *r = co_get_region(co); - curse *c; /* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken, * also duration+2 */ @@ -4722,8 +4721,8 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) duration = 2 + rng_int() % duration; /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ - c = create_curse(mage, &r->attribs, ct_find(curse_name), power, duration, effect, 0); - + create_curse(mage, &r->attribs, ct_find(curse_name), power, duration, effect, 0); + /* Erfolg melden */ ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect", "unit region command", mage, mage->region, co->order)); @@ -4841,7 +4840,6 @@ int sp_sweetdreams(castorder * co) /* Schleife ueber alle angegebenen Einheiten */ for (n = 0; n < pa->length; n++) { - curse *c; unit *u; double effect; message *msg; @@ -4865,7 +4863,7 @@ int sp_sweetdreams(castorder * co) /* Nichts machen als ein entsprechendes Attribut an die Einheit legen. */ effect = 0.05f; - c = create_curse(mage, &u->attribs, ct_find("orcish"), power, duration, effect, men); + create_curse(mage, &u->attribs, ct_find("orcish"), power, duration, effect, men); msg = msg_message("sp_sweetdreams_effect", "mage unit region", mage, u, r); r_addmessage(r, mage->faction, msg); @@ -4886,10 +4884,9 @@ int sp_disturbingdreams(castorder * co) double power = co->force; int duration = 1 + (int)(power / 6); double effect; - curse *c; effect = 10; - c = create_curse(mage, &r->attribs, ct_find("badlearn"), power, duration, effect, 0); + create_curse(mage, &r->attribs, ct_find("badlearn"), power, duration, effect, 0); ADDMSG(&mage->faction->msgs, msg_message("sp_disturbingdreams_effect", "mage region", mage, r)); From 3ea12be5642c130fd40a13c7e765e0c66927e14d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 13 Feb 2017 18:48:38 +0100 Subject: [PATCH 211/271] BENUTZE Muschel repariert. at_keys hat jetzt auch zu jedem key ein value, und Funktionen zum Update altee Daten. --- scripts/eressea/embassy.lua | 16 +++++- src/attributes/dict.c | 98 +++++++++++-------------------------- src/attributes/dict.h | 10 ++-- src/attributes/key.c | 62 +++++++++++++---------- src/attributes/key.h | 6 +-- src/attributes/key.test.c | 47 ++++++++++++------ src/bind_faction.c | 6 +-- src/bind_region.c | 4 +- src/bind_unit.c | 2 +- src/bindings.c | 4 +- src/kernel/group.test.c | 4 +- src/kernel/item.c | 2 +- src/kernel/save.test.c | 8 +-- src/util/gamedata.h | 3 +- 14 files changed, 135 insertions(+), 137 deletions(-) diff --git a/scripts/eressea/embassy.lua b/scripts/eressea/embassy.lua index 704581c6f..93ff66d7c 100644 --- a/scripts/eressea/embassy.lua +++ b/scripts/eressea/embassy.lua @@ -5,6 +5,20 @@ if not config.embassy then return nil end local embassy = {} local home = nil +-- global exports (use item) +function use_seashell(u, amount) +-- Muschelplateau... + local visit = u.faction:get_key('mupL') + if visit and u.region~= home then + local turns = get_turn() - visit + local msg = message.create('msg_event') + msg:set_string("string", u.name .. "(" .. itoa36(u.id) .. ") erzählt den Bewohnern von " .. u.region.name .. " von Muschelplateau, das die Partei " .. u.faction.name .. " vor " .. turns .. " Wochen besucht hat." ) + msg:send_region(u.region) + return 0 + end + return -4 +end + function embassy.init() home = get_region(165,30) if home==nil then @@ -20,7 +34,7 @@ function embassy.update() eressea.log.debug("updating embassies in " .. tostring(home)) local u for u in home.units do - if not u.faction:get_key('mupL') then + if u.faction:get_key('mupL')==0 then if (u.faction:add_item('seashell', 1)>0) then eressea.log.debug("new seashell for " .. tostring(u.faction)) u.faction:set_key('mupL', get_turn()) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 6d4b3ed3c..ad66e3676 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -42,6 +42,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +typedef enum { + TNONE = 0, TINTEGER = 1 +} dict_type; + typedef struct dict_data { dict_type type; char *name; @@ -62,94 +66,38 @@ static int dict_read(attrib * a, void *owner, gamedata *data) storage *store = data->store; char name[NAMESIZE]; dict_data *dd = (dict_data *)a->data.v; - int result, n; - float flt; + int n; READ_STR(store, name, sizeof(name)); dd->name = strdup(name); READ_INT(store, &n); dd->type = (dict_type)n; - switch (dd->type) { - case TINTEGER: - READ_INT(store, &dd->data.i); - break; - case TREAL: - READ_FLT(store, &flt); - if ((int)flt == flt) { - dd->type = TINTEGER; - dd->data.i = (int)flt; - } - else { - dd->data.real = flt; - } - break; - case TSTRING: - READ_STR(store, name, sizeof(name)); - dd->data.str = strdup(name); - break; - case TBUILDING: - result = - read_reference(&dd->data.b, data, read_building_reference, - resolve_building); - if (result == 0 && !dd->data.b) { - return AT_READ_FAIL; - } - break; - case TUNIT: - result = - read_reference(&dd->data.u, data, read_unit_reference, resolve_unit); - if (result == 0 && !dd->data.u) { - return AT_READ_FAIL; - } - break; - case TFACTION: - result = - read_reference(&dd->data.f, data, read_faction_reference, - resolve_faction); - if (result == 0 && !dd->data.f) { - return AT_READ_FAIL; - } - break; - case TREGION: - result = - read_reference(&dd->data.r, data, read_region_reference, - RESOLVE_REGION(data->version)); - if (result == 0 && !dd->data.r) { - return AT_READ_FAIL; - } - break; - case TSHIP: - /* return read_ship_reference(&data->data.sh, store); */ - assert(!"not implemented"); - break; - case TNONE: - break; - default: + if (dd->type != TINTEGER) { + log_error("read dict, invalid type %d", n); return AT_READ_FAIL; } + READ_INT(store, &dd->data.i); return AT_READ_DEPR; } static void dict_init(attrib * a) { - dict_data *data; + dict_data *dd; a->data.v = malloc(sizeof(dict_data)); - data = (dict_data *)a->data.v; - data->type = TNONE; + dd = (dict_data *)a->data.v; + dd->type = TNONE; } static void dict_done(attrib * a) { - dict_data *data = (dict_data *)a->data.v; - if (data->type == TSTRING) - free(data->data.str); - free(data->name); + dict_data *dd = (dict_data *)a->data.v; + free(dd->name); free(a->data.v); } static void dict_upgrade(attrib **alist, attrib *abegin) { int n = 0, *keys = 0; - int i = 0, val[4]; + int i = 0, val[8]; attrib *a, *ak = a_find(*alist, &at_keys); if (ak) { keys = (int *)ak->data.v; @@ -162,7 +110,9 @@ static void dict_upgrade(attrib **alist, attrib *abegin) { } else { if (strcmp(dd->name, "embassy_muschel")==0) { - val[i++] = atoi36("mupL"); + val[i * 2] = atoi36("mupL"); + val[i * 2 + 1] = dd->data.i; + ++i; } else { log_error("dict conversion, bad entry %s", dd->name); @@ -170,14 +120,14 @@ static void dict_upgrade(attrib **alist, attrib *abegin) { } if (i == 4) { keys = realloc(keys, sizeof(int) * (n + i + 1)); - memcpy(keys + n + 1, val, sizeof(int)*i); + memcpy(keys + n + 1, val, sizeof(val)); n += i; i = 0; } } if (i > 0) { - keys = realloc(keys, sizeof(int) * (n + i + 1)); - memcpy(keys + n + 1, val, sizeof(int)*i); + keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1)); + memcpy(keys + n*2 + 1, val, sizeof(int)*i*2); if (!ak) { ak = a_add(alist, a_new(&at_keys)); } @@ -190,3 +140,11 @@ attrib_type at_dict = { "object", dict_init, dict_done, NULL, NULL, dict_read, dict_upgrade }; + +void dict_set(attrib * a, const char * name, int value) +{ + dict_data *dd = (dict_data *)a->data.v; + dd->name = strdup(name); + dd->type = TINTEGER; + dd->data.i = value; +} diff --git a/src/attributes/dict.h b/src/attributes/dict.h index 7b028fa00..cc700bb9f 100644 --- a/src/attributes/dict.h +++ b/src/attributes/dict.h @@ -13,18 +13,16 @@ #ifndef H_ATTRIBUTE_OBJECT #define H_ATTRIBUTE_OBJECT -#include +struct attrib_type; +struct attrib; #ifdef __cplusplus extern "C" { #endif - typedef enum { - TNONE = 0, TINTEGER = 1, TREAL = 2, TSTRING = 3, - TUNIT = 10, TFACTION = 11, TREGION = 12, TBUILDING = 13, TSHIP = 14 - } dict_type; + extern struct attrib_type at_dict; // DEPRECATED: at_dict has been replaced with at_keys - extern struct attrib_type at_dict; + void dict_set(struct attrib * a, const char * name, int value); #ifdef __cplusplus } diff --git a/src/attributes/key.c b/src/attributes/key.c index 84bbf7c04..904df32be 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -30,8 +30,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static void a_writekeys(const attrib *a, const void *o, storage *store) { int i, *keys = (int *)a->data.v; - for (i = 0; i <= keys[0]; ++i) { - WRITE_INT(store, keys[i]); + WRITE_INT(store, keys[0]); + for (i = 0; i < keys[0]; ++i) { + WRITE_INT(store, keys[i * 2 + 1]); + WRITE_INT(store, keys[i * 2 + 2]); } } @@ -42,10 +44,16 @@ static int a_readkeys(attrib * a, void *owner, gamedata *data) { if (i == 0) { return AT_READ_FAIL; } - a->data.v = p = malloc(sizeof(int)*(i + 1)); + a->data.v = p = malloc(sizeof(int)*(i*2 + 1)); *p++ = i; while (i--) { READ_INT(data->store, p++); + if (data->version >= KEYVAL_VERSION) { + READ_INT(data->store, p++); + } + else { + *p++ = 1; + } } return AT_READ_OK; } @@ -71,24 +79,25 @@ attrib_type at_keys = { static void a_upgradekeys(attrib **alist, attrib *abegin) { int n = 0, *keys = 0; - int i = 0, val[4]; + int i = 0, val[8]; attrib *a, *ak = a_find(*alist, &at_keys); if (ak) { keys = (int *)ak->data.v; if (keys) n = keys[0]; } for (a = abegin; a && a->type == abegin->type; a = a->next) { - val[i++] = a->data.i; - if (i == 4) { - keys = realloc(keys, sizeof(int) * (n + i + 1)); - memcpy(keys + n + 1, val, sizeof(int)*i); + val[i * 2] = a->data.i; + val[i * 2 + 1] = 1; + if (++i == 4) { + keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1)); + memcpy(keys + 2 * n + 1, val, sizeof(val)); n += i; i = 0; } } if (i > 0) { - keys = realloc(keys, sizeof(int) * (n + i + 1)); - memcpy(keys + n + 1, val, sizeof(int)*i); + keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1)); + memcpy(keys + 2 * n + 1, val, sizeof(int)*i*2); if (!ak) { ak = a_add(alist, a_new(&at_keys)); } @@ -107,9 +116,9 @@ attrib_type at_key = { a_upgradekeys }; -void key_set(attrib ** alist, int key) +void key_set(attrib ** alist, int key, int val) { - int *keys, n = 1; + int *keys, n = 0; attrib *a; assert(key != 0); a = a_find(*alist, &at_keys); @@ -118,12 +127,13 @@ void key_set(attrib ** alist, int key) } keys = (int *)a->data.v; if (keys) { - n = keys[0] + 1; + n = keys[0]; } - keys = realloc(keys, sizeof(int) *(n + 1)); - // TODO: does insertion sort pay off here? - keys[0] = n; - keys[n] = key; + keys = realloc(keys, sizeof(int) *(2 * n + 3)); + // TODO: does insertion sort pay off here? prob. not. + keys[0] = n + 1; + keys[2 * n + 1] = key; + keys[2 * n + 2] = val; a->data.v = keys; } @@ -135,29 +145,31 @@ void key_unset(attrib ** alist, int key) if (a) { int i, *keys = (int *)a->data.v; if (keys) { - for (i = 1; i <= keys[0]; ++i) { - if (keys[i] == key) { - keys[i] = keys[keys[0]]; + int n = keys[0]; + for (i = 0; i != n; ++i) { + if (keys[2 * i + 1] == key) { + memmove(keys + 2 * i + 1, keys + 2 * n - 1, 2 * sizeof(int)); keys[0]--; + break; } } } } } -bool key_get(attrib *alist, int key) { +int key_get(attrib *alist, int key) { attrib *a; assert(key != 0); a = a_find(alist, &at_keys); if (a) { int i, *keys = (int *)a->data.v; if (keys) { - for (i = 1; i <= keys[0]; ++i) { - if (keys[i] == key) { - return true; + for (i = 0; i != keys[0]; ++i) { + if (keys[i*2+1] == key) { + return keys[i * 2 + 2]; } } } } - return false; + return 0; } diff --git a/src/attributes/key.h b/src/attributes/key.h index d2cea1ff0..81511d248 100644 --- a/src/attributes/key.h +++ b/src/attributes/key.h @@ -26,12 +26,12 @@ extern "C" { #endif struct attrib; struct attrib_type; - extern struct attrib_type at_key; + extern struct attrib_type at_key; // DEPRECATED: at_key has been replaced with at_keys extern struct attrib_type at_keys; - void key_set(struct attrib **alist, int key); + void key_set(struct attrib **alist, int key, int value); void key_unset(struct attrib **alist, int key); - bool key_get(struct attrib *alist, int key); + int key_get(struct attrib *alist, int key); #ifdef __cplusplus } diff --git a/src/attributes/key.test.c b/src/attributes/key.test.c index 2b7632917..b816e1d86 100644 --- a/src/attributes/key.test.c +++ b/src/attributes/key.test.c @@ -1,22 +1,24 @@ #include #include "key.h" +#include "dict.h" #include +#include #include #include static void test_get_set_keys(CuTest *tc) { attrib *a = 0; - key_set(&a, 42); - key_set(&a, 43); - key_set(&a, 44); - CuAssertTrue(tc, key_get(a, 42)); - CuAssertTrue(tc, key_get(a, 43)); - CuAssertTrue(tc, key_get(a, 44)); + key_set(&a, 42, 1); + key_set(&a, 43, 2); + key_set(&a, 44, 3); + CuAssertIntEquals(tc, 1, key_get(a, 42)); + CuAssertIntEquals(tc, 2, key_get(a, 43)); + CuAssertIntEquals(tc, 3, key_get(a, 44)); key_unset(&a, 42); - CuAssertTrue(tc, !key_get(a, 42)); - CuAssertTrue(tc, key_get(a, 43)); - CuAssertTrue(tc, key_get(a, 44)); + CuAssertIntEquals(tc, 0, key_get(a, 42)); + CuAssertIntEquals(tc, 2, key_get(a, 43)); + CuAssertIntEquals(tc, 3, key_get(a, 44)); a_removeall(&a, NULL); } @@ -26,7 +28,7 @@ static attrib *key_set_orig(attrib **alist, int key) { return a; } -static void test_upgrade(CuTest *tc) { +static void test_upgrade_key(CuTest *tc) { attrib *alist = 0; key_set_orig(&alist, 40); key_set_orig(&alist, 41); @@ -35,18 +37,31 @@ static void test_upgrade(CuTest *tc) { key_set_orig(&alist, 44); CuAssertPtrNotNull(tc, alist->type->upgrade); alist->type->upgrade(&alist, alist); - CuAssertTrue(tc, key_get(alist, 40)); - CuAssertTrue(tc, key_get(alist, 41)); - CuAssertTrue(tc, key_get(alist, 42)); - CuAssertTrue(tc, key_get(alist, 43)); - CuAssertTrue(tc, key_get(alist, 44)); + CuAssertIntEquals(tc, 1, key_get(alist, 40)); + CuAssertIntEquals(tc, 1, key_get(alist, 41)); + CuAssertIntEquals(tc, 1, key_get(alist, 42)); + CuAssertIntEquals(tc, 1, key_get(alist, 43)); + CuAssertIntEquals(tc, 1, key_get(alist, 44)); a_removeall(&alist, NULL); } +static void test_upgrade_dict(CuTest *tc) { + attrib *a; + + a = a_new(&at_dict); + + dict_set(a, "embassy_muschel", 42); + CuAssertPtrNotNull(tc, a->type->upgrade); + a->type->upgrade(&a, a); + CuAssertIntEquals(tc, 42, key_get(a, atoi36("mupL"))); + a_removeall(&a, NULL); +} + CuSuite *get_key_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_get_set_keys); - SUITE_ADD_TEST(suite, test_upgrade); + SUITE_ADD_TEST(suite, test_upgrade_key); + SUITE_ADD_TEST(suite, test_upgrade_dict); return suite; } diff --git a/src/bind_faction.c b/src/bind_faction.c index 749bb65f6..371481fcb 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -248,7 +248,7 @@ static int tolua_faction_getkey(lua_State * L) const char *name = tolua_tostring(L, 2, 0); int flag = atoi36(name); - lua_pushboolean(L, key_get(self->attribs, flag)); + lua_pushinteger(L, key_get(self->attribs, flag)); return 1; } @@ -256,11 +256,11 @@ static int tolua_faction_setkey(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); - int value = tolua_toboolean(L, 3, 0); + int value = (int)tolua_tonumber(L, 3, 0); int flag = atoi36(name); if (value) { - key_set(&self->attribs, flag); + key_set(&self->attribs, flag, value); } else { key_unset(&self->attribs, flag); diff --git a/src/bind_region.c b/src/bind_region.c index d9956c8b6..51a5bedd4 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -544,11 +544,11 @@ static int tolua_region_setkey(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); - int value = tolua_toboolean(L, 3, 0); + int value = (int)tolua_tonumber(L, 3, 0); int flag = atoi36(name); if (value) { - key_set(&self->attribs, flag); + key_set(&self->attribs, flag, value); } else { key_unset(&self->attribs, flag); diff --git a/src/bind_unit.c b/src/bind_unit.c index c0939b5cf..a9d413bf0 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -786,7 +786,7 @@ static int tolua_unit_set_flag(lua_State * L) int value = (int)tolua_tonumber(L, 3, 0); int flag = atoi36(name); if (value) { - key_set(&self->attribs, flag); + key_set(&self->attribs, flag, value); } else { key_unset(&self->attribs, flag); diff --git a/src/bindings.c b/src/bindings.c index 21f2aad58..531b68618 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -206,10 +206,10 @@ static int tolua_translate(lua_State * L) static int tolua_setkey(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); - int value = tolua_toboolean(L, 2, 0); + int value = (int)tolua_tonumber(L, 3, 0); int flag = atoi36(name); if (value) { - key_set(&global.attribs, flag); + key_set(&global.attribs, flag, value); } else { key_unset(&global.attribs, flag); diff --git a/src/kernel/group.test.c b/src/kernel/group.test.c index 78ee6b24f..e95458114 100644 --- a/src/kernel/group.test.c +++ b/src/kernel/group.test.c @@ -84,7 +84,7 @@ static void test_group_readwrite(CuTest * tc) f = test_create_faction(0); new_group(f, "NW", 42); g = new_group(f, "Egoisten", 43); - key_set(&g->attribs, 44); + key_set(&g->attribs, 44, 44); al = ally_add(&g->allies, f); al->status = HELP_GIVE; write_groups(&store, f); @@ -108,7 +108,7 @@ static void test_group_readwrite(CuTest * tc) CuAssertStrEquals(tc, "Egoisten", f->groups->next->name); CuAssertPtrEquals(tc, 0, f->groups->allies); g = f->groups->next; - CuAssertTrue(tc, key_get(g->attribs, 44)); + CuAssertIntEquals(tc, 44, key_get(g->attribs, 44)); CuAssertPtrNotNull(tc, g->allies); CuAssertPtrEquals(tc, 0, g->allies->next); CuAssertPtrEquals(tc, f, g->allies->faction); diff --git a/src/kernel/item.c b/src/kernel/item.c index 34a0e1875..9327700cd 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -939,7 +939,7 @@ struct order *ord) use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, user->number); - key_set(&f->attribs, atoi36("mbst")); + key_set(&f->attribs, atoi36("mbst"), turn); set_level(user, SK_MAGIC, 3); ADDMSG(&user->faction->msgs, msg_message("use_item", diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index c05ce4455..70bcb2e65 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -211,8 +211,8 @@ static void test_readwrite_attrib(CuTest *tc) { attrib *a = NULL; test_setup(); - key_set(&a, 41); - key_set(&a, 42); + key_set(&a, 41, 42); + key_set(&a, 42, 43); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); write_attribs(data.store, a, NULL); @@ -223,8 +223,8 @@ static void test_readwrite_attrib(CuTest *tc) { read_attribs(&data, &a, NULL); mstream_done(&data.strm); gamedata_done(&data); - CuAssertTrue(tc, key_get(a, 41)); - CuAssertTrue(tc, key_get(a, 42)); + CuAssertIntEquals(tc, 42, key_get(a, 41)); + CuAssertIntEquals(tc, 43, key_get(a, 42)); a_removeall(&a, NULL); test_cleanup(); diff --git a/src/util/gamedata.h b/src/util/gamedata.h index bb1632838..75a750452 100644 --- a/src/util/gamedata.h +++ b/src/util/gamedata.h @@ -32,10 +32,11 @@ #define NOCRYPT_VERSION 352 /* passwords are plaintext again */ #define ATHASH_VERSION 353 /* attribute-type hash, not name */ #define NOWATCH_VERSION 354 /* plane->watchers is gone */ +#define KEYVAL_VERSION 355 /* at_keys has values */ /* unfinished: */ #define CRYPT_VERSION 400 /* passwords are encrypted */ -#define RELEASE_VERSION NOWATCH_VERSION /* current datafile */ +#define RELEASE_VERSION KEYVAL_VERSION /* current datafile */ #define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ From aa230cc191b85dbcf40051bb0093e09046b5b6f4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Feb 2017 12:15:36 +0100 Subject: [PATCH 212/271] fix coverity warnings --- src/attributes/key.c | 8 ++++++-- src/kernel/version.c | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/attributes/key.c b/src/attributes/key.c index 904df32be..8b09fdd1c 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -102,8 +102,12 @@ static void a_upgradekeys(attrib **alist, attrib *abegin) { ak = a_add(alist, a_new(&at_keys)); } } - ak->data.v = keys; - keys[0] = n + i; + if (ak) { + ak->data.v = keys; + if (keys) { + keys[0] = n + i; + } + } } attrib_type at_key = { diff --git a/src/kernel/version.c b/src/kernel/version.c index 7e8ed01d7..8cf6a372e 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -11,8 +11,9 @@ const char *eressea_version(void) { #ifdef ERESSEA_BUILDNO return ERESSEA_VERSION "-" ERESSEA_BUILDNO; -#endif +#else return ERESSEA_VERSION; +#endif } int version_no(const char *str) { From 08e14f3095c6feb62821dd3101d4b13bf6f503c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Feb 2017 16:23:40 +0100 Subject: [PATCH 213/271] coverity warnings --- src/attributes/dict.c | 8 ++++++-- src/economy.c | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index ad66e3676..36d017b2c 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -132,8 +132,12 @@ static void dict_upgrade(attrib **alist, attrib *abegin) { ak = a_add(alist, a_new(&at_keys)); } } - ak->data.v = keys; - keys[0] = n + i; + if (ak) { + ak->data.v = keys; + if (keys) { + keys[0] = n + i; + } + } } attrib_type at_dict = { diff --git a/src/economy.c b/src/economy.c index dcbc7431e..dec4517a4 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2707,7 +2707,7 @@ static void expandloot(region * r, request * lootorders) { unit *u; unsigned int i; - int looted = 0; + int m, looted = 0; int startmoney = rmoney(r); expandorders(r, lootorders); @@ -2724,9 +2724,9 @@ static void expandloot(region * r, request * lootorders) free(g_requests); /* Lowering morale by 1 depending on the looted money (+20%) */ - if (rng_int() % 100 < 20 + (looted * 80) / startmoney) { - int m = region_get_morale(r); - if (m) { + m = region_get_morale(r); + if (m && startmoney>0) { + if (rng_int() % 100 < 20 + (looted * 80) / startmoney) { /*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/ region_set_morale(r, m - 1, -1); } From 623137e872f3bec0f824ff40cdb51914681074bd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Feb 2017 19:57:31 +0100 Subject: [PATCH 214/271] test guardhouse level limits. --- scripts/tests/e3/castles.lua | 52 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index df395ed3d..eafc58b51 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -11,30 +11,40 @@ function teardown() eressea.settings.set("rules.food.flags", "0") end +function test_watch() + local r = region.create(0, 0, "plain") + local b = building.create(r, "watch") + + assert_equal("scaffolding", b:get_typename(1)) + assert_equal("scaffolding", b:get_typename(4)) + assert_equal("guardhouse", b:get_typename(5)) + assert_equal("guardhouse", b:get_typename(9)) + assert_equal("guardtower", b:get_typename(10)) +end + function test_small_castles() - local r = region.create(0, 0, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f1, r, 1) - local f2 = faction.create("noreply@eressea.de", "halfling", "de") - local u2 = unit.create(f2, r, 1) - u1:add_item("money", 10000) + local r = region.create(0, 0, "plain") + local f1 = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f1, r, 1) + local f2 = faction.create("noreply@eressea.de", "halfling", "de") + local u2 = unit.create(f2, r, 1) - local b = building.create(r, "castle") - u2.building = b - u1.building = b + local b = building.create(r, "castle") + u2.building = b + u1.building = b - b.owner = u2 - assert_equal("site", b:get_typename(7)) - assert_equal("fortification", b:get_typename(8)) - b.owner = u1 - assert_equal("site", b:get_typename(9)) - assert_equal("fortification", b:get_typename(10)) + b.owner = u2 + assert_equal("site", b:get_typename(7)) + assert_equal("fortification", b:get_typename(8)) + b.owner = u1 + assert_equal("site", b:get_typename(9)) + assert_equal("fortification", b:get_typename(10)) end function test_build_normal() - local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") - local u = unit.create(f, r, 1) + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) u:clear_orders() u:add_item("stone", 10) u:set_skill("building", 10) @@ -45,9 +55,9 @@ function test_build_normal() end function test_build_packice() - local r = region.create(0, 0, "packice") - local f = faction.create("packice@eressea.de", "human", "de") - local u = unit.create(f, r, 1) + local r = region.create(0, 0, "packice") + local f = faction.create("packice@eressea.de", "human", "de") + local u = unit.create(f, r, 1) u:clear_orders() u:add_item("stone", 10) u:set_skill("building", 10) From 1dcb21b08cffe1be5170c0ac4fa77747dfaa686e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Feb 2017 20:30:24 +0100 Subject: [PATCH 215/271] bug 2281: add a failing test https://bugs.eressea.de/view.php?id=2281 --- scripts/tests/e3/castles.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index eafc58b51..b16019159 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -11,6 +11,28 @@ function teardown() eressea.settings.set("rules.food.flags", "0") end +function test_build_watch() + local r = region.create(0, 0, "plain") + local f = faction.create("e3build@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + + u.number = 20 + u:add_item("log", 20) + u.id = 42 + + u:set_skill("building", 1) + u:add_order("MACHE Wache") + process_orders() + assert_not_nil(u.building) + assert_equal(5, u.building.size) + + u:set_skill("building", 2) + u:add_order("MACHE Wache " .. itoa36(u.building.id)) + process_orders() + assert_not_nil(u.building) + assert_equal(10, u.building.size) +end + function test_watch() local r = region.create(0, 0, "plain") local b = building.create(r, "watch") From 4ce415be5099ef93f20c9634d1c396a7effa8e5e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Feb 2017 20:51:03 +0100 Subject: [PATCH 216/271] BUG 2281: fix maxsize of guard towers. --- res/e3a/buildings.xml | 2 +- src/kernel/build.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml index c1edbcc0b..f65654e2f 100644 --- a/res/e3a/buildings.xml +++ b/res/e3a/buildings.xml @@ -3,7 +3,7 @@ - + diff --git a/src/kernel/build.c b/src/kernel/build.c index dff51cf6c..6b23723e8 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -595,7 +595,7 @@ int build(unit * u, const construction * ctype, int completed, int want) else break; } - if (type->materials) + if (type->materials) { for (c = 0; type->materials[c].number; c++) { const struct resource_type *rtype = type->materials[c].rtype; int prebuilt = @@ -620,6 +620,7 @@ int build(unit * u, const construction * ctype, int completed, int want) use_pooled(u, rtype, GET_DEFAULT, (need - prebuilt + multi - 1) / multi); } + } made += n; skills -= n * type->minskill; want -= n; From 794710189940fec22b1a02ccef5a36681f56cdfd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Feb 2017 21:01:22 +0100 Subject: [PATCH 217/271] factor out some function to make future debugging easier. --- src/kernel/build.c | 131 ++++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 56 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 6b23723e8..78bcd6b8f 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -428,6 +428,76 @@ int roqf_factor(void) return value; } +static int use_materials(unit *u, const construction *type, int n, int completed) { + if (type->materials) { + int c; + for (c = 0; type->materials[c].number; c++) { + const struct resource_type *rtype = type->materials[c].rtype; + int prebuilt = + required(completed, type->reqsize, type->materials[c].number); + int need = + required(completed + n, type->reqsize, type->materials[c].number); + int multi = 1; + int canuse = 100; /* normalization */ + if (building_is_active(u->building) && inside_building(u)) { + canuse = matmod(u->building->type->attribs, u, rtype, canuse); + } + if (canuse < 0) { + return canuse; /* pass errors to caller */ + } + canuse = matmod(type->attribs, u, rtype, canuse); + + assert(canuse % 100 == 0 + || !"only constant multipliers are implemented in build()"); + multi = canuse / 100; + if (canuse < 0) { + return canuse; /* pass errors to caller */ + } + use_pooled(u, rtype, GET_DEFAULT, + (need - prebuilt + multi - 1) / multi); + } + } + return 0; +} + +static int count_materials(unit *u, const construction *type, int n, int completed) +{ + if (type->materials) { + int c; + for (c = 0; n > 0 && type->materials[c].number; c++) { + const struct resource_type *rtype = type->materials[c].rtype; + int need, prebuilt; + int canuse = get_pooled(u, rtype, GET_DEFAULT, INT_MAX); + + if (building_is_active(u->building) && inside_building(u)) { + canuse = matmod(u->building->type->attribs, u, rtype, canuse); + } + + if (canuse < 0) + return canuse; /* pass errors to caller */ + canuse = matmod(type->attribs, u, rtype, canuse); + if (type->reqsize > 1) { + prebuilt = + required(completed, type->reqsize, type->materials[c].number); + for (; n;) { + need = + required(completed + n, type->reqsize, type->materials[c].number); + if (need - prebuilt <= canuse) + break; + --n; /* TODO: optimieren? */ + } + } + else { + int maxn = canuse / type->materials[c].number; + if (maxn < n) { + n = maxn; + } + } + } + } + return n; +} + /** Use up resources for building an object. * Build up to 'size' points of 'type', where 'completed' * of the first object have already been finished. return the @@ -492,7 +562,7 @@ int build(unit * u, const construction * ctype, int completed, int want) } } for (; want > 0 && skills > 0;) { - int c, n; + int err, n; /* skip over everything that's already been done: * type->improvement==NULL means no more improvements, but no size limits @@ -559,67 +629,16 @@ int build(unit * u, const construction * ctype, int completed, int want) } } - if (type->materials) - for (c = 0; n > 0 && type->materials[c].number; c++) { - const struct resource_type *rtype = type->materials[c].rtype; - int need, prebuilt; - int canuse = get_pooled(u, rtype, GET_DEFAULT, INT_MAX); - - if (building_is_active(u->building) && inside_building(u)) { - canuse = matmod(u->building->type->attribs, u, rtype, canuse); - } - - if (canuse < 0) - return canuse; /* pass errors to caller */ - canuse = matmod(type->attribs, u, rtype, canuse); - if (type->reqsize > 1) { - prebuilt = - required(completed, type->reqsize, type->materials[c].number); - for (; n;) { - need = - required(completed + n, type->reqsize, type->materials[c].number); - if (need - prebuilt <= canuse) - break; - --n; /* TODO: optimieren? */ - } - } - else { - int maxn = canuse / type->materials[c].number; - if (maxn < n) - n = maxn; - } - } + n = count_materials(u, type, n, completed); if (n <= 0) { if (made == 0) return ENOMATERIALS; else break; } - if (type->materials) { - for (c = 0; type->materials[c].number; c++) { - const struct resource_type *rtype = type->materials[c].rtype; - int prebuilt = - required(completed, type->reqsize, type->materials[c].number); - int need = - required(completed + n, type->reqsize, type->materials[c].number); - int multi = 1; - int canuse = 100; /* normalization */ - if (building_is_active(u->building) && inside_building(u)) { - canuse = matmod(u->building->type->attribs, u, rtype, canuse); - } - if (canuse < 0) - return canuse; /* pass errors to caller */ - canuse = matmod(type->attribs, u, rtype, canuse); - - assert(canuse % 100 == 0 - || !"only constant multipliers are implemented in build()"); - multi = canuse / 100; - if (canuse < 0) - return canuse; /* pass errors to caller */ - - use_pooled(u, rtype, GET_DEFAULT, - (need - prebuilt + multi - 1) / multi); - } + err = use_materials(u, type, n, completed); + if (err < 0) { + return err; } made += n; skills -= n * type->minskill; From 5680057e7f0c27cf90eeb81588bd5659d5be8874 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 15 Feb 2017 17:09:23 +0100 Subject: [PATCH 218/271] adding simple test for MAKE --- src/economy.c | 140 ++++++++++++++++++++++----------------------- src/economy.h | 1 + src/economy.test.c | 31 ++++++++++ src/kernel/build.c | 2 +- src/kernel/item.h | 6 +- 5 files changed, 107 insertions(+), 73 deletions(-) diff --git a/src/economy.c b/src/economy.c index dec4517a4..711a80d82 100644 --- a/src/economy.c +++ b/src/economy.c @@ -534,7 +534,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) } if (has_skill(u, SK_MAGIC)) { /* error158;de;{unit} in {region}: '{command}' - Magier arbeiten - * grundsätzlich nur alleine! */ + * grunds�tzlich nur alleine! */ cmistake(u, ord, 158, MSG_EVENT); return; } @@ -895,7 +895,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) const resource_type *rring; int amount, skill; - /* momentan kann man keine ressourcen abbauen, wenn man dafür + /* momentan kann man keine ressourcen abbauen, wenn man daf�r * Materialverbrauch hat: */ assert(itype != NULL && (itype->construction == NULL || itype->construction->materials == NULL)); @@ -928,8 +928,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) } } - /* Bergwächter können Abbau von Eisen/Laen durch Bewachen verhindern. - * Als magische Wesen 'sehen' Bergwächter alles und werden durch + /* Bergw�chter k�nnen Abbau von Eisen/Laen durch Bewachen verhindern. + * Als magische Wesen 'sehen' Bergw�chter alles und werden durch * Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen). */ if (itype->rtype && (itype->rtype == get_resourcetype(R_IRON) || itype->rtype == rt_find("laen"))) { @@ -1095,7 +1095,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (avail > 0) { int want = required(al->want - al->get, al->save); int x = avail * want / nreq; - /* Wenn Rest, dann würfeln, ob ich was bekomme: */ + /* Wenn Rest, dann w�rfeln, ob ich was bekomme: */ if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; @@ -1140,7 +1140,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) if (avail > 0) { int want = required(al->want, al->save); int x = avail * want / nreq; - /* Wenn Rest, dann würfeln, ob ich was bekomme: */ + /* Wenn Rest, dann w�rfeln, ob ich was bekomme: */ if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; @@ -1248,7 +1248,7 @@ static void create_potion(unit * u, const potion_type * ptype, int want) } } -static void create_item(unit * u, const item_type * itype, int want) +void make_item(unit * u, const item_type * itype, int want) { if (itype->construction && fval(itype->rtype, RTF_LIMITED)) { #if GUARD_DISABLES_PRODUCTION == 1 @@ -1402,7 +1402,7 @@ int make_cmd(unit * u, struct order *ord) } } else if (itype != NULL) { - create_item(u, itype, m); + make_item(u, itype, m); } else { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", "")); @@ -1453,15 +1453,15 @@ static void expandbuying(region * r, request * buyorders) return; /* Initialisation. multiplier ist der Multiplikator auf den - * Verkaufspreis. Für max_products Produkte kauft man das Produkt zum - * einfachen Verkaufspreis, danach erhöht sich der Multiplikator um 1. - * counter ist ein Zähler, der die gekauften Produkte zählt. money - * wird für die debug message gebraucht. */ + * Verkaufspreis. F�r max_products Produkte kauft man das Produkt zum + * einfachen Verkaufspreis, danach erh�ht sich der Multiplikator um 1. + * counter ist ein Z�hler, der die gekauften Produkte z�hlt. money + * wird f�r die debug message gebraucht. */ max_products = rpeasants(r) / TRADE_FRACTION; - /* Kauf - auch so programmiert, daß er leicht erweiterbar auf mehrere - * Güter pro Monat ist. j sind die Befehle, i der Index des + /* Kauf - auch so programmiert, da� er leicht erweiterbar auf mehrere + * G�ter pro Monat ist. j sind die Befehle, i der Index des * gehandelten Produktes. */ if (max_products > 0) { unsigned int j; @@ -1483,10 +1483,10 @@ static void expandbuying(region * r, request * buyorders) unit *u = g_requests[j].unit; item *items; - /* litems zählt die Güter, die verkauft wurden, u->n das Geld, das - * verdient wurde. Dies muß gemacht werden, weil der Preis ständig sinkt, + /* litems z�hlt die G�ter, die verkauft wurden, u->n das Geld, das + * verdient wurde. Dies mu� gemacht werden, weil der Preis st�ndig sinkt, * man sich also das verdiente Geld und die verkauften Produkte separat - * merken muß. */ + * merken mu�. */ attrib *a = a_find(u->attribs, &at_luxuries); if (a == NULL) a = a_add(&u->attribs, a_new(&at_luxuries)); @@ -1503,7 +1503,7 @@ static void expandbuying(region * r, request * buyorders) rsetmoney(r, rmoney(r) + price); /* Falls mehr als max_products Bauern ein Produkt verkauft haben, steigt - * der Preis Multiplikator für das Produkt um den Faktor 1. Der Zähler + * der Preis Multiplikator f�r das Produkt um den Faktor 1. Der Z�hler * wird wieder auf 0 gesetzt. */ if (++trade->number == max_products) { trade->number = 0; @@ -1563,7 +1563,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) return; } /* Im Augenblick kann man nur 1 Produkt kaufen. expandbuying ist aber - * schon dafür ausgerüstet, mehrere Produkte zu kaufen. */ + * schon daf�r ausger�stet, mehrere Produkte zu kaufen. */ kwd = init_order(ord); assert(kwd == K_BUY); @@ -1573,7 +1573,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) return; } if (besieged(u)) { - /* Belagerte Einheiten können nichts kaufen. */ + /* Belagerte Einheiten k�nnen nichts kaufen. */ cmistake(u, ord, 60, MSG_COMMERCE); return; } @@ -1587,7 +1587,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) } } else { - /* ...oder in der Region muß es eine Burg geben. */ + /* ...oder in der Region mu� es eine Burg geben. */ building *b = 0; if (r->buildings) { static int cache; @@ -1608,11 +1608,11 @@ static void buy(unit * u, request ** buyorders, struct order *ord) } } - /* Ein Händler kann nur 10 Güter pro Talentpunkt handeln. */ + /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt handeln. */ k = u->number * 10 * effskill(u, SK_TRADE, 0); - /* hat der Händler bereits gehandelt, muss die Menge der bereits - * verkauften/gekauften Güter abgezogen werden */ + /* hat der H�ndler bereits gehandelt, muss die Menge der bereits + * verkauften/gekauften G�ter abgezogen werden */ a = a_find(u->attribs, &at_trades); if (!a) { a = a_add(&u->attribs, a_new(&at_trades)); @@ -1629,7 +1629,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) } assert(n >= 0); - /* die Menge der verkauften Güter merken */ + /* die Menge der verkauften G�ter merken */ a->data.i += n; s = gettoken(token, sizeof(token)); @@ -1662,7 +1662,7 @@ static void add_income(unit * u, int type, int want, int qty) "unit region mode wanted amount", u, u->region, type, want, qty)); } -/* Steuersätze in % bei Burggröße */ +/* Steuers�tze in % bei Burggr��e */ static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 }; static void expandselling(region * r, request * sellorders, int limit) @@ -1697,11 +1697,11 @@ static void expandselling(region * r, request * sellorders, int limit) } memset(counter, 0, sizeof(int) * ncounter); - if (!sellorders) { /* NEIN, denn Insekten können in || !r->buildings) */ - return; /* Sümpfen und Wüsten auch so handeln */ + if (!sellorders) { /* NEIN, denn Insekten k�nnen in || !r->buildings) */ + return; /* S�mpfen und W�sten auch so handeln */ } - /* Stelle Eigentümer der größten Burg fest. Bekommt Steuern aus jedem - * Verkauf. Wenn zwei Burgen gleicher Größe bekommt gar keiner etwas. */ + /* Stelle Eigent�mer der gr��ten Burg fest. Bekommt Steuern aus jedem + * Verkauf. Wenn zwei Burgen gleicher Gr��e bekommt gar keiner etwas. */ for (b = rbuildings(r); b; b = b->next) { if (b->size > maxsize && building_owner(b) != NULL && b->type == castle_bt) { @@ -1724,13 +1724,13 @@ static void expandselling(region * r, request * sellorders, int limit) maxowner = (unit *)NULL; } } - /* Die Region muss genug Geld haben, um die Produkte kaufen zu können. */ + /* Die Region muss genug Geld haben, um die Produkte kaufen zu k�nnen. */ money = rmoney(r); - /* max_products sind 1/100 der Bevölkerung, falls soviele Produkte + /* max_products sind 1/100 der Bev�lkerung, falls soviele Produkte * verkauft werden - counter[] - sinkt die Nachfrage um 1 Punkt. - * multiplier speichert r->demand für die debug message ab. */ + * multiplier speichert r->demand f�r die debug message ab. */ max_products = rpeasants(r) / TRADE_FRACTION; if (max_products <= 0) @@ -1798,11 +1798,11 @@ static void expandselling(region * r, request * sellorders, int limit) change_money(u, price); fset(u, UFL_LONGACTION | UFL_NOTMOVING); - /* r->money -= price; --- dies wird eben nicht ausgeführt, denn die - * Produkte können auch als Steuern eingetrieben werden. In der Region - * wurden Silberstücke gegen Luxusgüter des selben Wertes eingetauscht! + /* r->money -= price; --- dies wird eben nicht ausgef�hrt, denn die + * Produkte k�nnen auch als Steuern eingetrieben werden. In der Region + * wurden Silberst�cke gegen Luxusg�ter des selben Wertes eingetauscht! * Falls mehr als max_products Kunden ein Produkt gekauft haben, sinkt - * die Nachfrage für das Produkt um 1. Der Zähler wird wieder auf 0 + * die Nachfrage f�r das Produkt um 1. Der Z�hler wird wieder auf 0 * gesetzt. */ if (++counter[i] > max_products) { @@ -1819,7 +1819,7 @@ static void expandselling(region * r, request * sellorders, int limit) } free(g_requests); - /* Steuern. Hier werden die Steuern dem Besitzer der größten Burg gegeben. */ + /* Steuern. Hier werden die Steuern dem Besitzer der gr��ten Burg gegeben. */ if (maxowner) { if (taxcollected > 0) { change_money(maxowner, (int)taxcollected); @@ -1876,7 +1876,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) cmistake(u, ord, 69, MSG_INCOME); return false; } - /* sellorders sind KEIN array, weil für alle items DIE SELBE resource + /* sellorders sind KEIN array, weil f�r alle items DIE SELBE resource * (das geld der region) aufgebraucht wird. */ kwd = init_order(ord); @@ -1901,13 +1901,13 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) return false; } } - /* Belagerte Einheiten können nichts verkaufen. */ + /* Belagerte Einheiten k�nnen nichts verkaufen. */ if (besieged(u)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error60", "")); return false; } - /* In der Region muß es eine Burg geben. */ + /* In der Region mu� es eine Burg geben. */ if (u_race(u) == get_race(RC_INSECT)) { if (r->terrain != newterrain(T_SWAMP) && r->terrain != newterrain(T_DESERT) @@ -1917,7 +1917,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) } } else { - /* ...oder in der Region muß es eine Burg geben. */ + /* ...oder in der Region mu� es eine Burg geben. */ building *b = 0; if (r->buildings) { for (b = r->buildings; b; b = b->next) { @@ -1930,7 +1930,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) } } - /* Ein Händler kann nur 10 Güter pro Talentpunkt verkaufen. */ + /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt verkaufen. */ n = MIN(n, u->number * 10 * effskill(u, SK_TRADE, 0)); @@ -1956,7 +1956,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) } available = get_pooled(u, itype->rtype, GET_DEFAULT, INT_MAX); - /* Wenn andere Einheiten das selbe verkaufen, muß ihr Zeug abgezogen + /* Wenn andere Einheiten das selbe verkaufen, mu� ihr Zeug abgezogen * werden damit es nicht zweimal verkauft wird: */ for (o = *sellorders; o; o = o->next) { if (o->type.ltype == ltype && o->unit->faction == u->faction) { @@ -1973,16 +1973,16 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) return false; } /* Hier wird request->type verwendet, weil die obere limit durch - * das silber gegeben wird (region->money), welches für alle + * das silber gegeben wird (region->money), welches f�r alle * (!) produkte als summe gilt, als nicht wie bei der - * produktion, wo für jedes produkt einzeln eine obere limite + * produktion, wo f�r jedes produkt einzeln eine obere limite * existiert, so dass man arrays von orders machen kann. */ - /* Ein Händler kann nur 10 Güter pro Talentpunkt handeln. */ + /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt handeln. */ k = u->number * 10 * effskill(u, SK_TRADE, 0); - /* hat der Händler bereits gehandelt, muss die Menge der bereits - * verkauften/gekauften Güter abgezogen werden */ + /* hat der H�ndler bereits gehandelt, muss die Menge der bereits + * verkauften/gekauften G�ter abgezogen werden */ a = a_find(u->attribs, &at_trades); if (!a) { a = a_add(&u->attribs, a_new(&at_trades)); @@ -1993,7 +1993,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) n = MIN(n, k); assert(n >= 0); - /* die Menge der verkauften Güter merken */ + /* die Menge der verkauften G�ter merken */ a->data.i += n; o = (request *)calloc(1, sizeof(request)); o->unit = u; @@ -2017,8 +2017,8 @@ static void expandstealing(region * r, request * stealorders) expandorders(r, stealorders); if (!norders) return; - /* Für jede unit in der Region wird Geld geklaut, wenn sie Opfer eines - * Beklauen-Orders ist. Jedes Opfer muß einzeln behandelt werden. + /* F�r jede unit in der Region wird Geld geklaut, wenn sie Opfer eines + * Beklauen-Orders ist. Jedes Opfer mu� einzeln behandelt werden. * * u ist die beklaute unit. oa.unit ist die klauende unit. */ @@ -2079,7 +2079,7 @@ static void plant(unit * u, int raw) return; } - /* Skill prüfen */ + /* Skill pr�fen */ skill = effskill(u, SK_HERBALISM, 0); if (skill < 6) { ADDMSG(&u->faction->msgs, @@ -2087,14 +2087,14 @@ static void plant(unit * u, int raw) "skill minskill product", SK_HERBALISM, 6, itype->rtype, 1)); return; } - /* Wasser des Lebens prüfen */ + /* Wasser des Lebens pr�fen */ if (get_pooled(u, rt_water, GET_DEFAULT, 1) == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rt_water)); return; } n = get_pooled(u, itype->rtype, GET_DEFAULT, skill * u->number); - /* Kräuter prüfen */ + /* Kr�uter pr�fen */ if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", @@ -2104,7 +2104,7 @@ static void plant(unit * u, int raw) n = MIN(skill * u->number, n); n = MIN(raw, n); - /* Für jedes Kraut Talent*10% Erfolgschance. */ + /* F�r jedes Kraut Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) planted++; @@ -2129,10 +2129,10 @@ static void planttrees(unit * u, int raw) return; } - /* Mallornbäume kann man nur in Mallornregionen züchten */ + /* Mallornb�ume kann man nur in Mallornregionen z�chten */ rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORNSEED : R_SEED); - /* Skill prüfen */ + /* Skill pr�fen */ skill = effskill(u, SK_HERBALISM, 0); if (skill < 6) { ADDMSG(&u->faction->msgs, @@ -2157,7 +2157,7 @@ static void planttrees(unit * u, int raw) } n = MIN(raw, n); - /* Für jeden Samen Talent*10% Erfolgschance. */ + /* F�r jeden Samen Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) planted++; @@ -2172,7 +2172,7 @@ static void planttrees(unit * u, int raw) "unit region amount herb", u, r, planted, rtype)); } -/* züchte bäume */ +/* z�chte b�ume */ static void breedtrees(unit * u, int raw) { int n, i, skill, planted = 0; @@ -2184,7 +2184,7 @@ static void breedtrees(unit * u, int raw) get_gamedate(turn, &date); current_season = date.season; - /* Bäume züchten geht nur im Frühling */ + /* B�ume z�chten geht nur im Fr�hling */ if (current_season != SEASON_SPRING) { planttrees(u, raw); return; @@ -2194,10 +2194,10 @@ static void breedtrees(unit * u, int raw) return; } - /* Mallornbäume kann man nur in Mallornregionen züchten */ + /* Mallornb�ume kann man nur in Mallornregionen z�chten */ rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORNSEED : R_SEED); - /* Skill prüfen */ + /* Skill pr�fen */ skill = effskill(u, SK_HERBALISM, 0); if (skill < 12) { planttrees(u, raw); @@ -2207,7 +2207,7 @@ static void breedtrees(unit * u, int raw) /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ raw = MIN(skill * u->number, raw); n = get_pooled(u, rtype, GET_DEFAULT, raw); - /* Samen prüfen */ + /* Samen pr�fen */ if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); @@ -2215,7 +2215,7 @@ static void breedtrees(unit * u, int raw) } n = MIN(raw, n); - /* Für jeden Samen Talent*5% Erfolgschance. */ + /* F�r jeden Samen Talent*5% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 100 < skill * 5) planted++; @@ -2230,7 +2230,7 @@ static void breedtrees(unit * u, int raw) "unit region amount herb", u, r, planted, rtype)); } -/* züchte pferde */ +/* z�chte pferde */ static void breedhorses(unit * u) { int n, c, breed = 0; @@ -2283,7 +2283,7 @@ static void breed_cmd(unit * u, struct order *ord) return; } - /* züchte [] */ + /* z�chte [] */ (void)init_order(ord); s = gettoken(token, sizeof(token)); @@ -2549,7 +2549,7 @@ static void expandentertainment(region * r) m -= u->n; entertaining -= o->qty; - /* Nur soviel PRODUCEEXP wie auch tatsächlich gemacht wurde */ + /* Nur soviel PRODUCEEXP wie auch tats�chlich gemacht wurde */ produceexp(u, SK_ENTERTAINMENT, MIN(u->n, u->number)); add_income(u, IC_ENTERTAIN, o->qty, u->n); fset(u, UFL_LONGACTION | UFL_NOTMOVING); @@ -3121,7 +3121,7 @@ void produce(struct region *r) /* Entertainment (expandentertainment) und Besteuerung (expandtax) vor den * Befehlen, die den Bauern mehr Geld geben, damit man aus den Zahlen der - * letzten Runde berechnen kann, wieviel die Bauern für Unterhaltung + * letzten Runde berechnen kann, wieviel die Bauern f�r Unterhaltung * auszugeben bereit sind. */ if (entertaining) expandentertainment(r); @@ -3136,7 +3136,7 @@ void produce(struct region *r) /* An erster Stelle Kaufen (expandbuying), die Bauern so Geld bekommen, um * nachher zu beim Verkaufen (expandselling) den Spielern abkaufen zu - * können. */ + * k�nnen. */ if (buyorders) expandbuying(r, buyorders); diff --git a/src/economy.h b/src/economy.h index 5549e13cb..7b0eed8c9 100644 --- a/src/economy.h +++ b/src/economy.h @@ -56,6 +56,7 @@ extern "C" { enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT }; void maintain_buildings(struct region *r); + void make_item(struct unit * u, const struct item_type * itype, int want); int make_cmd(struct unit *u, struct order *ord); void split_allocations(struct region *r); int give_control_cmd(struct unit *u, struct order *ord); diff --git a/src/economy.test.c b/src/economy.test.c index 3c4a5f257..bee074714 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -341,12 +341,43 @@ static void test_income(CuTest *tc) test_cleanup(); } +static void test_make_item(CuTest *tc) { + unit *u; + struct item_type *itype; + const struct resource_type *rt_silver; + + test_setup(); + init_resources(); + rt_silver = get_resourcetype(R_SILVER); + itype = test_create_itemtype("log"); + u = test_create_unit(test_create_faction(0), test_create_region(0,0,0)); + make_item(u, itype, 1); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_cannotmake")); + CuAssertIntEquals(tc, 0, get_item(u, itype)); + test_clear_messages(u->faction); + itype->construction = calloc(1, sizeof(construction)); + itype->construction->skill = SK_ALCHEMY; + itype->construction->minskill = 1; + itype->construction->maxsize = 1; + itype->construction->reqsize = 1; + itype->construction->materials = calloc(2, sizeof(requirement)); + itype->construction->materials[0].rtype = rt_silver; + itype->construction->materials[0].number = 1; + set_level(u, SK_ALCHEMY, 1); + set_item(u, rt_silver->itype, 1); + make_item(u, itype, 1); + CuAssertIntEquals(tc, 1, get_item(u, itype)); + CuAssertIntEquals(tc, 0, get_item(u, rt_silver->itype)); + test_cleanup(); +} + CuSuite *get_economy_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_give_control_building); SUITE_ADD_TEST(suite, test_give_control_ship); SUITE_ADD_TEST(suite, test_income); + SUITE_ADD_TEST(suite, test_make_item); SUITE_ADD_TEST(suite, test_steal_okay); SUITE_ADD_TEST(suite, test_steal_ocean); SUITE_ADD_TEST(suite, test_steal_nosteal); diff --git a/src/kernel/build.c b/src/kernel/build.c index 78bcd6b8f..88ab35fd2 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -397,7 +397,7 @@ static int required(int size, int msize, int maxneed) * braucht man required von maxneed resourcen */ { int used; - + assert(msize > 0); used = size * maxneed / msize; if (size * maxneed % msize) ++used; diff --git a/src/kernel/item.h b/src/kernel/item.h index c32f38057..39a2d0687 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -70,7 +70,7 @@ extern "C" { typedef char *(*rtype_name) (const struct resource_type * rtype, int flags); typedef struct resource_type { /* --- constants --- */ - char *_name; /* wie es heißt */ + char *_name; /* wie es hei�t */ unsigned int flags; /* --- functions --- */ rtype_uchange uchange; @@ -136,7 +136,7 @@ extern "C" { int weight; int capacity; struct construction *construction; - char *_appearance[2]; /* wie es für andere aussieht */ + char *_appearance[2]; /* wie es f�r andere aussieht */ /* --- functions --- */ bool(*canuse) (const struct unit * user, const struct item_type * itype); @@ -311,6 +311,8 @@ extern "C" { extern const struct potion_type *oldpotiontype[]; const struct resource_type *get_resourcetype(resource_t rt); + int get_item(const struct unit * u, const struct item_type *itype); + int set_item(struct unit * u, const struct item_type *itype, int value); int get_money(const struct unit *); int set_money(struct unit *, int); int change_money(struct unit *, int); From 5902a6922f06eae2d42591a71ff76b670cd146de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 15 Feb 2017 20:50:45 +0100 Subject: [PATCH 219/271] BUG 2279: add a failing unit test. --- src/economy.test.c | 36 +++++++++++++++++++++++++++++++++++- src/kernel/resources.h | 16 +++++++--------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/economy.test.c b/src/economy.test.c index bee074714..ddb0cafbc 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -11,10 +11,12 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -345,11 +347,17 @@ static void test_make_item(CuTest *tc) { unit *u; struct item_type *itype; const struct resource_type *rt_silver; + resource_type *rtype; + attrib *a; + resource_limit *rdata; test_setup(); init_resources(); + + /* make items from other items (turn silver to stone) */ rt_silver = get_resourcetype(R_SILVER); - itype = test_create_itemtype("log"); + itype = test_create_itemtype("stone"); + rtype = itype->rtype; u = test_create_unit(test_create_faction(0), test_create_region(0,0,0)); make_item(u, itype, 1); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_cannotmake")); @@ -368,6 +376,32 @@ static void test_make_item(CuTest *tc) { make_item(u, itype, 1); CuAssertIntEquals(tc, 1, get_item(u, itype)); CuAssertIntEquals(tc, 0, get_item(u, rt_silver->itype)); + + /* make level-based raw materials, no materials used in construction */ + free(itype->construction->materials); + itype->construction->materials = 0; + rtype->flags |= RTF_LIMITED; + a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); + rdata = (resource_limit *)a->data.v; + rdata->value = 0; + rmt_create(rtype, "stone"); + add_resource(u->region, 1, 300, 150, rtype); + u->region->resources->amount = 300; /* there are 300 stones at level 1 */ + set_level(u, SK_ALCHEMY, 10); + + make_item(u, itype, 10); + split_allocations(u->region); + CuAssertIntEquals(tc, 11, get_item(u, itype)); + CuAssertIntEquals(tc, 290, u->region->resources->amount); /* used 10 stones to make 10 stones */ + + rdata->modifiers = calloc(2, sizeof(resource_mod)); + rdata->modifiers[0].flags = RMF_SAVEMATERIAL; + rdata->modifiers[0].race = u->_race; + rdata->modifiers[0].value.f = (float)0.6; + make_item(u, itype, 10); + split_allocations(u->region); + CuAssertIntEquals(tc, 21, get_item(u, itype)); + CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */ test_cleanup(); } diff --git a/src/kernel/resources.h b/src/kernel/resources.h index 32c69036c..a1a7abd40 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -55,18 +55,16 @@ extern "C" { extern struct rawmaterial_type *rawmaterialtypes; - extern void update_resources(struct region *r); - extern void terraform_resources(struct region *r); - extern void read_resources(struct region *r); - extern void write_resources(struct region *r); - extern struct rawmaterial *rm_get(struct region *, + void update_resources(struct region *r); + void terraform_resources(struct region *r); + struct rawmaterial *rm_get(struct region *, const struct resource_type *); - extern struct rawmaterial_type *rmt_find(const char *str); - extern struct rawmaterial_type *rmt_get(const struct resource_type *); + struct rawmaterial_type *rmt_find(const char *str); + struct rawmaterial_type *rmt_get(const struct resource_type *); - extern void add_resource(struct region *r, int level, int base, int divisor, + void add_resource(struct region *r, int level, int base, int divisor, const struct resource_type *rtype); - extern struct rawmaterial_type *rmt_create(const struct resource_type *rtype, + struct rawmaterial_type *rmt_create(const struct resource_type *rtype, const char *name); #ifdef __cplusplus From 50083fc668641d6c232ce6b3958e16240c91a31d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 15 Feb 2017 21:16:54 +0100 Subject: [PATCH 220/271] BUG 2279: too many resources used. diddling the resource-save formula until test passes. --- src/economy.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/economy.c b/src/economy.c index 711a80d82..b38244ca8 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1038,8 +1038,6 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) static int required(int want, double save) { int req = (int)(want * save); - if (req < want * save) - ++req; return req; } @@ -1095,14 +1093,14 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (avail > 0) { int want = required(al->want - al->get, al->save); int x = avail * want / nreq; - /* Wenn Rest, dann w�rfeln, ob ich was bekomme: */ - if (rng_int() % nreq < (avail * want) % nreq) - ++x; + int r = (avail * want) % nreq; + /* Wenn Rest, dann wuerfeln, ob ich etwas bekomme: */ + if (r > 0 && rng_int() % nreq < r) ++x; avail -= x; use += x; nreq -= want; need -= x; - al->get = MIN(al->want, al->get + (int)(x / al->save)); + al->get = MIN(al->want, al->get + (int)(1 + x / al->save)); } } if (use) { From 20ff8981df584330e1cc9d3f29811903dcba961b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 15 Feb 2017 09:30:36 +0100 Subject: [PATCH 221/271] trying to extract allocation modifiers into a separate function --- src/economy.c | 80 ++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/src/economy.c b/src/economy.c index b38244ca8..abbf28a02 100644 --- a/src/economy.c +++ b/src/economy.c @@ -883,6 +883,32 @@ enum { AFL_LOWSKILL = 1 << 1 }; +struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, int *skillp) { + struct building *b = inside_building(u); + const struct building_type *btype = building_is_active(b) ? b->type : NULL; + double save = 1.0; + int skill = 0; + + for (; mod->flags != 0; ++mod) { + if (mod->btype == NULL || mod->btype == btype) { + if (mod->flags & RMF_REQUIREDBUILDING) { + return msg_error(u, u->thisorder, 104);; + } + if (mod->race == NULL || mod->race == u_race(u)) { + if (mod->flags & RMF_SAVEMATERIAL) { + save *= mod->value.f; + } + if (mod->flags & RMF_SKILL) { + skill += mod->value.i; + } + } + } + } + *skillp = skill; + *savep = save; + return NULL; +} + static void allocate_resource(unit * u, const resource_type * rtype, int want) { const item_type *itype = resource2item(rtype); @@ -893,7 +919,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) attrib *a = a_find(rtype->attribs, &at_resourcelimit); resource_limit *rdata = (resource_limit *)a->data.v; const resource_type *rring; - int amount, skill; + int amount, skill, skill_mod; + double save_mod; /* momentan kann man keine ressourcen abbauen, wenn man daf�r * Materialverbrauch hat: */ @@ -915,16 +942,11 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) } if (rdata->modifiers) { - resource_mod *mod = rdata->modifiers; - for (; mod->flags != 0; ++mod) { - if (mod->flags & RMF_REQUIREDBUILDING) { - struct building *b = inside_building(u); - const struct building_type *btype = building_is_active(b) ? b->type : NULL; - if (mod->btype && mod->btype != btype) { - cmistake(u, u->thisorder, 104, MSG_PRODUCE); - return; - } - } + message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod); + if (msg) { + ADDMSG(&u->faction->msgs, msg); + msg_release(msg); + return; } } @@ -962,23 +984,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) itype->rtype)); return; } - else { - struct building *b = inside_building(u); - const struct building_type *btype = building_is_active(b) ? b->type : NULL; - - if (rdata->modifiers) { - resource_mod *mod = rdata->modifiers; - for (; mod->flags != 0; ++mod) { - if (mod->flags & RMF_SKILL) { - if (mod->btype == NULL || mod->btype == btype) { - if (mod->race == NULL || mod->race == u_race(u)) { - skill += mod->value.i; - } - } - } - } - } - } + skill += skill_mod; amount = skill * u->number; /* nun ist amount die Gesamtproduktion der Einheit (in punkten) */ @@ -1013,26 +1019,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) } al = new_allocation(); al->want = amount; - al->save = 1.0; + al->save = save_mod; al->next = alist->data; al->unit = u; alist->data = al; - - if (rdata->modifiers) { - struct building *b = inside_building(u); - const struct building_type *btype = building_is_active(b) ? b->type : NULL; - - resource_mod *mod = rdata->modifiers; - for (; mod->flags != 0; ++mod) { - if (mod->flags & RMF_SAVEMATERIAL) { - if (mod->btype == NULL || mod->btype == btype) { - if (mod->race == NULL || mod->race == u_race(u)) { - al->save *= mod->value.f; - } - } - } - } - } } static int required(int want, double save) From a5dfe12d48cc147f8ecbbc6e7087c231581fd6dd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 16 Feb 2017 19:38:09 +0100 Subject: [PATCH 222/271] initialize variable --- src/economy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/economy.c b/src/economy.c index abbf28a02..df01f3b45 100644 --- a/src/economy.c +++ b/src/economy.c @@ -919,8 +919,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) attrib *a = a_find(rtype->attribs, &at_resourcelimit); resource_limit *rdata = (resource_limit *)a->data.v; const resource_type *rring; - int amount, skill, skill_mod; - double save_mod; + int amount, skill, skill_mod = 0; + double save_mod = 1.0; /* momentan kann man keine ressourcen abbauen, wenn man daf�r * Materialverbrauch hat: */ From a624915a0634ef1ac731c6c12e99242e25609a3d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 16 Feb 2017 20:26:34 +0100 Subject: [PATCH 223/271] error message if building is required. was broken in recent commit. also fix reference counts. --- src/economy.c | 6 ++---- src/economy.test.c | 7 +++++++ src/kernel/messages.c | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/economy.c b/src/economy.c index df01f3b45..4c54cb5da 100644 --- a/src/economy.c +++ b/src/economy.c @@ -891,9 +891,6 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, for (; mod->flags != 0; ++mod) { if (mod->btype == NULL || mod->btype == btype) { - if (mod->flags & RMF_REQUIREDBUILDING) { - return msg_error(u, u->thisorder, 104);; - } if (mod->race == NULL || mod->race == u_race(u)) { if (mod->flags & RMF_SAVEMATERIAL) { save *= mod->value.f; @@ -902,6 +899,8 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, skill += mod->value.i; } } + } else if (mod->flags & RMF_REQUIREDBUILDING) { + return msg_error(u, u->thisorder, 104); } } *skillp = skill; @@ -945,7 +944,6 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod); if (msg) { ADDMSG(&u->faction->msgs, msg); - msg_release(msg); return; } } diff --git a/src/economy.test.c b/src/economy.test.c index ddb0cafbc..7101d859a 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -402,6 +402,13 @@ static void test_make_item(CuTest *tc) { split_allocations(u->region); CuAssertIntEquals(tc, 21, get_item(u, itype)); CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */ + + rdata->modifiers[0].flags = RMF_REQUIREDBUILDING; + rdata->modifiers[0].race = NULL; + rdata->modifiers[0].btype = bt_get_or_create("mine"); + make_item(u, itype, 10); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error104")); + test_cleanup(); } diff --git a/src/kernel/messages.c b/src/kernel/messages.c index cb859df96..f74e9c0d7 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -270,8 +270,6 @@ void syntax_error(const struct unit *u, struct order *ord) ADDMSG(&u->faction->msgs, result); } -extern unsigned int new_hashstring(const char *s); - void free_messagelist(mlist *msgs) { struct mlist **mlistptr; From 2328975dc226c735f5652918482e8e995345c52b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 17 Feb 2017 21:45:10 +0100 Subject: [PATCH 224/271] do not use floats for material-save. abusing variants for storing short fractions. remove unused RMF_SAVERESOURCE. --- src/economy.c | 40 ++++++++++++++++++++++++++-------------- src/economy.test.c | 4 +++- src/kernel/item.h | 3 +-- src/kernel/xmlreader.c | 7 ++----- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/economy.c b/src/economy.c index 4c54cb5da..70b48e9ce 100644 --- a/src/economy.c +++ b/src/economy.c @@ -863,7 +863,7 @@ static void manufacture(unit * u, const item_type * itype, int want) typedef struct allocation { struct allocation *next; int want, get; - double save; + variant save; unsigned int flags; unit *unit; } allocation; @@ -883,17 +883,18 @@ enum { AFL_LOWSKILL = 1 << 1 }; -struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, int *skillp) { +struct message * get_modifiers(unit *u, const resource_mod *mod, variant *savep, int *skillp) { struct building *b = inside_building(u); const struct building_type *btype = building_is_active(b) ? b->type : NULL; - double save = 1.0; + int save_n = 1, save_d = 1; int skill = 0; for (; mod->flags != 0; ++mod) { if (mod->btype == NULL || mod->btype == btype) { if (mod->race == NULL || mod->race == u_race(u)) { if (mod->flags & RMF_SAVEMATERIAL) { - save *= mod->value.f; + save_n *= mod->value.sa[0]; + save_d *= mod->value.sa[1]; } if (mod->flags & RMF_SKILL) { skill += mod->value.i; @@ -904,7 +905,12 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, } } *skillp = skill; - *savep = save; + assert(save_n < SHRT_MAX); + assert(save_n > SHRT_MIN); + assert(save_d < SHRT_MAX); + assert(save_d > SHRT_MIN); + savep->sa[0] = (short)save_n; + savep->sa[1] = (short)save_d; return NULL; } @@ -919,7 +925,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) resource_limit *rdata = (resource_limit *)a->data.v; const resource_type *rring; int amount, skill, skill_mod = 0; - double save_mod = 1.0; + variant save_mod; /* momentan kann man keine ressourcen abbauen, wenn man daf�r * Materialverbrauch hat: */ @@ -947,6 +953,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) return; } } + else { + save_mod.sa[0] = 1; + save_mod.sa[1] = 1; + } /* Bergw�chter k�nnen Abbau von Eisen/Laen durch Bewachen verhindern. * Als magische Wesen 'sehen' Bergw�chter alles und werden durch @@ -1023,9 +1033,9 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) alist->data = al; } -static int required(int want, double save) +static int required(int want, variant save) { - int req = (int)(want * save); + int req = (int)(want * save.sa[0] / save.sa[1]); return req; } @@ -1088,7 +1098,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) use += x; nreq -= want; need -= x; - al->get = MIN(al->want, al->get + (int)(1 + x / al->save)); + al->get = MIN(al->want, al->get + x * al->save.sa[1] / al->save.sa[0]); } } if (use) { @@ -1126,12 +1136,13 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) if (avail > 0) { int want = required(al->want, al->save); int x = avail * want / nreq; - /* Wenn Rest, dann w�rfeln, ob ich was bekomme: */ - if (rng_int() % nreq < (avail * want) % nreq) - ++x; + int rx = (avail * want) % nreq; + /* Wenn Rest, dann wuerfeln, ob ich was bekomme: */ + if (rx>0 && rng_int() % nreq < rx) ++x; avail -= x; nreq -= want; - al->get = MIN(al->want, (int)(x / al->save)); + al->get = x * al->save.sa[0] / al->save.sa[1]; + al->get = MIN(al->want, al->get); if (rdata->produce) { int use = required(al->get, al->save); if (use) @@ -2619,8 +2630,9 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork) if (jobs >= working) workers = u->number; else { + int r = (u->number * jobs) % working; workers = u->number * jobs / working; - if (rng_int() % working < (u->number * jobs) % working) + if (r > 0 && rng_int() % working < r) workers++; } diff --git a/src/economy.test.c b/src/economy.test.c index 7101d859a..d9f9b82e8 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -350,6 +350,7 @@ static void test_make_item(CuTest *tc) { resource_type *rtype; attrib *a; resource_limit *rdata; + double d = 0.6; test_setup(); init_resources(); @@ -397,7 +398,8 @@ static void test_make_item(CuTest *tc) { rdata->modifiers = calloc(2, sizeof(resource_mod)); rdata->modifiers[0].flags = RMF_SAVEMATERIAL; rdata->modifiers[0].race = u->_race; - rdata->modifiers[0].value.f = (float)0.6; + rdata->modifiers[0].value.sa[0] = (short)(0.5+100*d); + rdata->modifiers[0].value.sa[1] = 100; make_item(u, itype, 10); split_allocations(u->region); CuAssertIntEquals(tc, 21, get_item(u, itype)); diff --git a/src/kernel/item.h b/src/kernel/item.h index 39a2d0687..e6301c314 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -91,8 +91,7 @@ extern "C" { /* resource-limits for regions */ #define RMF_SKILL 0x01 /* int, bonus on resource production skill */ -#define RMF_SAVEMATERIAL 0x02 /* float, multiplier on resource usage */ -#define RMF_SAVERESOURCE 0x03 /* int, bonus on resource production skill */ +#define RMF_SAVEMATERIAL 0x02 /* fraction (sa[0]/sa[1]), multiplier on resource usage */ #define RMF_REQUIREDBUILDING 0x04 /* building, required to build */ typedef struct resource_mod { diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 5ce6800ef..5cecc4fdb 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1025,13 +1025,10 @@ static int parse_resources(xmlDocPtr doc) rdata->modifiers[k].flags = RMF_SKILL; } else if (strcmp((const char *)propValue, "material") == 0) { - rdata->modifiers[k].value.f = (float)xml_fvalue(node, "value", 0); + rdata->modifiers[k].value.sa[0] = (short)(0.5+100*xml_fvalue(node, "value", 0)); + rdata->modifiers[k].value.sa[1] = 100; rdata->modifiers[k].flags = RMF_SAVEMATERIAL; } - else if (strcmp((const char *)propValue, "resource") == 0) { - rdata->modifiers[k].value.f = (float)xml_fvalue(node, "value", 0); - rdata->modifiers[k].flags = RMF_SAVERESOURCE; - } else if (strcmp((const char *)propValue, "require") == 0) { xmlChar *propBldg = xmlGetProp(node, BAD_CAST "building"); if (propBldg != NULL) { From 0a3e3de5a33405b0de1e93e5734266c48a94e126 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 17 Feb 2017 22:01:51 +0100 Subject: [PATCH 225/271] refactor fractions a little bit. --- src/kernel/xmlreader.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 5cecc4fdb..36f003e80 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1025,8 +1025,17 @@ static int parse_resources(xmlDocPtr doc) rdata->modifiers[k].flags = RMF_SKILL; } else if (strcmp((const char *)propValue, "material") == 0) { - rdata->modifiers[k].value.sa[0] = (short)(0.5+100*xml_fvalue(node, "value", 0)); - rdata->modifiers[k].value.sa[1] = 100; + int num, den = 100; + double fval = xml_fvalue(node, "value", 0); + // TODO: extract into a function for reading fractions? + num = (int)(fval * den + 0.5); + if (num % 10 == 0) { + // TODO: calculating a GCD would be better than this + num /= 10; + den /= 10; + } + rdata->modifiers[k].value.sa[0] = (short)num; + rdata->modifiers[k].value.sa[1] = (short)den; rdata->modifiers[k].flags = RMF_SAVEMATERIAL; } else if (strcmp((const char *)propValue, "require") == 0) { From aee68fbd0fb0bc5ec2c159ce4812ef7749dd1fc2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 11:19:42 +0100 Subject: [PATCH 226/271] github issue #658 MACHE 1 EISEN use 1 iron even with savings. --- src/economy.c | 2 ++ src/economy.test.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/economy.c b/src/economy.c index 70b48e9ce..ab1875eed 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1036,6 +1036,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) static int required(int want, variant save) { int req = (int)(want * save.sa[0] / save.sa[1]); + int r = want * save.sa[0] % save.sa[1]; + if (r>0) ++req; return req; } diff --git a/src/economy.test.c b/src/economy.test.c index d9f9b82e8..fdc218844 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -405,6 +405,11 @@ static void test_make_item(CuTest *tc) { CuAssertIntEquals(tc, 21, get_item(u, itype)); CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */ + make_item(u, itype, 1); + split_allocations(u->region); + CuAssertIntEquals(tc, 22, get_item(u, itype)); + CuAssertIntEquals(tc, 283, u->region->resources->amount); /* no free lunches */ + rdata->modifiers[0].flags = RMF_REQUIREDBUILDING; rdata->modifiers[0].race = NULL; rdata->modifiers[0].btype = bt_get_or_create("mine"); From 9682d6b48c751a236844d7a3c3d8dff2bf0be74e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 15:45:57 +0100 Subject: [PATCH 227/271] implement quick-and-dirty gcd --- src/kernel/xmlreader.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 36f003e80..3a4b351dd 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -905,6 +905,22 @@ static int parse_rules(xmlDocPtr doc) return 0; } +static int gcd(int num, int den) { + const int primes[] = { 3, 5, 7, 11, 0 }; + int i=0, g = 1, p = 2; + while (p && p<=den && p<=num) { + if (num % p == 0 && den % p == 0) { + num /= p; + den /= p; + g *= p; + } + else { + p = primes[i++]; + } + } + return g; +} + static int parse_resources(xmlDocPtr doc) { xmlXPathContextPtr xpath = xmlXPathNewContext(doc); @@ -1025,15 +1041,13 @@ static int parse_resources(xmlDocPtr doc) rdata->modifiers[k].flags = RMF_SKILL; } else if (strcmp((const char *)propValue, "material") == 0) { - int num, den = 100; + int g, num, den = 100; double fval = xml_fvalue(node, "value", 0); // TODO: extract into a function for reading fractions? num = (int)(fval * den + 0.5); - if (num % 10 == 0) { - // TODO: calculating a GCD would be better than this - num /= 10; - den /= 10; - } + g = gcd(num, den); + num /= g; + den /= g; rdata->modifiers[k].value.sa[0] = (short)num; rdata->modifiers[k].value.sa[1] = (short)den; rdata->modifiers[k].flags = RMF_SAVEMATERIAL; From a754975ef9d957b79f7e142244ff27301081f7ec Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 17:52:25 +0100 Subject: [PATCH 228/271] fix loading data where embassy uses floats. --- src/attributes/dict.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 36d017b2c..f95555734 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -43,7 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include typedef enum { - TNONE = 0, TINTEGER = 1 + TNONE = 0, TINTEGER = 1, TREAL = 2 } dict_type; typedef struct dict_data { @@ -72,11 +72,18 @@ static int dict_read(attrib * a, void *owner, gamedata *data) dd->name = strdup(name); READ_INT(store, &n); dd->type = (dict_type)n; - if (dd->type != TINTEGER) { + if (dd->type == TINTEGER) { + READ_INT(store, &dd->data.i); + } + else if (dd->type == TREAL) { + float flt; + READ_FLT(store, &flt); + dd->data.real = flt; + } + else { log_error("read dict, invalid type %d", n); return AT_READ_FAIL; } - READ_INT(store, &dd->data.i); return AT_READ_DEPR; } @@ -95,6 +102,16 @@ static void dict_done(attrib * a) free(a->data.v); } +static void upgrade_keyval(const dict_data *dd, int keyval[], int v) { + if (strcmp(dd->name, "embassy_muschel") == 0) { + keyval[0] = atoi36("mupL"); + keyval[1] = v; + } + else { + log_error("dict conversion, bad entry %s", dd->name); + } +} + static void dict_upgrade(attrib **alist, attrib *abegin) { int n = 0, *keys = 0; int i = 0, val[8]; @@ -105,18 +122,17 @@ static void dict_upgrade(attrib **alist, attrib *abegin) { } for (a = abegin; a && a->type == abegin->type; a = a->next) { dict_data *dd = (dict_data *)a->data.v; - if (dd->type != TINTEGER) { - log_error("dict conversion, bad type %d for %s", dd->type, dd->name); + if (dd->type == TINTEGER) { + upgrade_keyval(dd, val + i * 2, dd->data.i); + ++i; + } + else if (dd->type == TREAL) { + upgrade_keyval(dd, val + i * 2, (int)dd->data.real); + ++i; } else { - if (strcmp(dd->name, "embassy_muschel")==0) { - val[i * 2] = atoi36("mupL"); - val[i * 2 + 1] = dd->data.i; - ++i; - } - else { - log_error("dict conversion, bad entry %s", dd->name); - } + log_error("dict conversion, bad type %d for %s", dd->type, dd->name); + assert(!"invalid input"); } if (i == 4) { keys = realloc(keys, sizeof(int) * (n + i + 1)); From daa75543610ea410b3ade74d670224a86001ff12 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 18:14:18 +0100 Subject: [PATCH 229/271] remove race.precombatspell --- res/eressea/races.xml | 1 - src/kernel/race.c | 2 -- src/kernel/race.h | 1 - src/kernel/xmlreader.c | 11 ----------- src/magic.c | 7 ------- 5 files changed, 22 deletions(-) diff --git a/res/eressea/races.xml b/res/eressea/races.xml index e4e22d0c3..de5a26325 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1283,7 +1283,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index a4a11c15d..683d37d63 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -277,7 +277,6 @@ void free_races(void) { free(at->data.dice); } } - spellref_free(races->precombatspell); free(xrefs); xrefs = 0; free(races->_name); @@ -337,7 +336,6 @@ race *rc_create(const char *zName) assert(strchr(zName, ' ') == NULL); } rc->_name = strdup(zName); - rc->precombatspell = NULL; rc->attack[0].type = AT_COMBATSPELL; for (i = 1; i < RACE_ATTACKS; ++i) diff --git a/src/kernel/race.h b/src/kernel/race.h index c58bad701..8fc6d5989 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -138,7 +138,6 @@ extern "C" { int df_default; /* Verteidigungsskill Unbewaffnet (default: -2) */ int at_bonus; /* Ver�ndert den Angriffsskill (default: 0) */ int df_bonus; /* Ver�ndert den Verteidigungskill (default: 0) */ - struct spellref *precombatspell; signed char *study_speed; /* study-speed-bonus in points/turn (0=30 Tage) */ int flags; int battle_flags; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 3a4b351dd..1ac5583ec 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1849,17 +1849,6 @@ static int parse_races(xmlDocPtr doc) } xmlXPathFreeObject(result); - /* reading eressea/races/race/precombatspell */ - xpath->node = node; - result = xmlXPathEvalExpression(BAD_CAST "precombatspell", xpath); - assert(rc->precombatspell == NULL - || !"precombatspell is already initialized"); - for (k = 0; k != result->nodesetval->nodeNr; ++k) { - xmlNodePtr node = result->nodesetval->nodeTab[k]; - rc->precombatspell = xml_spellref(node, "spell"); - } - xmlXPathFreeObject(result); - /* reading eressea/races/race/attack */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "attack", xpath); diff --git a/src/magic.c b/src/magic.c index 89774e96a..19890ec0e 100644 --- a/src/magic.c +++ b/src/magic.c @@ -561,13 +561,6 @@ const spell *get_combatspell(const unit * u, int nr) if (m) { return m->combatspells[nr].sp; } - else { - const race * rc = u_race(u); - if (rc->precombatspell) { - return spellref_get(rc->precombatspell); - } - } - return NULL; } From 7d5586635ea4523a056def5656a81867b1660d8a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 18:24:44 +0100 Subject: [PATCH 230/271] remove shadowcall spell --- res/core/de/strings.xml | 8 -------- res/core/messages.xml | 10 ---------- res/e3a/races.xml | 31 ------------------------------- res/e3a/spellbooks/gray.xml | 1 - res/e3a/spells.xml | 3 --- res/eressea/races.xml | 25 ------------------------- res/eressea/spellbooks/gray.xml | 1 - res/eressea/spells.xml | 3 --- 8 files changed, 82 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index bccfdd165..3aa71393d 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -3819,10 +3819,6 @@ Meteorregen Meteor Shower - - Schattenruf - Shadow Call - Erschaffe einen Ring der Regeneration Create A Ring of Regeneration @@ -4503,10 +4499,6 @@ Verletzt alle Gegner. Injures all enemies. - - Ruft Schattenwesen. - Calls beings from shadow. - Panik. Panic. diff --git a/res/core/messages.xml b/res/core/messages.xml index c28670d65..3fae49eb3 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -7521,16 +7521,6 @@ "$unit($mage) casts $spell($spell). $int($amount) fighters are temporarily losing some of their memories." - - - - - - - "$unit($mage) ruft $int($amount) $race($race, 0) zu Hilfe." - "$unit($mage) calls upon the help of $int($amount) $race($race, 0)." - - diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 7e75f3fd4..5060604a3 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -885,35 +885,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/e3a/spellbooks/gray.xml b/res/e3a/spellbooks/gray.xml index 5967d6265..9c0035e78 100644 --- a/res/e3a/spellbooks/gray.xml +++ b/res/e3a/spellbooks/gray.xml @@ -107,7 +107,6 @@ - diff --git a/res/e3a/spells.xml b/res/e3a/spells.xml index ec656c18f..74eb89146 100644 --- a/res/e3a/spells.xml +++ b/res/e3a/spells.xml @@ -665,9 +665,6 @@ - - - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index de5a26325..26607a297 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1284,29 +1284,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/eressea/spellbooks/gray.xml b/res/eressea/spellbooks/gray.xml index a7f718f2a..ae7a1f611 100644 --- a/res/eressea/spellbooks/gray.xml +++ b/res/eressea/spellbooks/gray.xml @@ -123,7 +123,6 @@ - diff --git a/res/eressea/spells.xml b/res/eressea/spells.xml index 5af11913e..1d762f4bd 100644 --- a/res/eressea/spells.xml +++ b/res/eressea/spells.xml @@ -471,9 +471,6 @@ - - - From a553b2258a0509bd7fa04e10262f8ef7a074246f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 18:25:58 +0100 Subject: [PATCH 231/271] remove code for shadowcall, too --- src/spells.c | 1 - src/spells/combatspells.c | 36 ------------------------------------ src/spells/combatspells.h | 1 - 3 files changed, 38 deletions(-) diff --git a/src/spells.c b/src/spells.c index b40192016..66f5325c9 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6596,7 +6596,6 @@ static spelldata spell_functions[] = { { "powerful_dragonbreath", sp_dragonodem, 0 }, { "drain_skills", sp_dragonodem, 0 }, { "aura_of_fear", sp_flee, 0 }, - { "shadowcall", sp_shadowcall, 0 }, { "immolation", sp_immolation, 0 }, { "firestorm", sp_immolation, 0 }, { "coldfront", sp_immolation, 0 }, diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 76fd605ff..939433617 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -815,42 +815,6 @@ int sp_drainodem(fighter * fi, int level, double power, spell * sp) /* ------------------------------------------------------------- */ /* PRECOMBAT */ -int sp_shadowcall(struct castorder * co) -{ - fighter * fi = co->magician.fig; - int level = co->level; - double power = co->force; - battle *b = fi->side->battle; - region *r = b->region; - unit *mage = fi->unit; - attrib *a; - int force = (int)(get_force(power, 3) / 2); - unit *u; - const char *rcnames[3] = { "shadowbat", "nightmare", "vampunicorn" }; - const race *rc = rc_find(rcnames[rng_int() % 3]); - message *msg; - - u = create_unit(r, mage->faction, force, rc, 0, NULL, mage); - setstatus(u, ST_FIGHT); - - set_level(u, SK_WEAPONLESS, (int)(power / 2)); - set_level(u, SK_STAMINA, (int)(power / 2)); - u->hp = u->number * unit_max_hp(u); - - a = a_new(&at_unitdissolve); - a->data.ca[0] = 0; - a->data.ca[1] = 100; - a_add(&u->attribs, a); - - make_fighter(b, u, fi->side, is_attacker(fi)); - msg = - msg_message("sp_shadowcall_effect", "mage amount race", mage, u->number, - u_race(u)); - message_all(b, msg); - msg_release(msg); - return level; -} - static fighter *summon_allies(const fighter *fi, const race *rc, int number) { attrib *a; unit *mage = fi->unit; diff --git a/src/spells/combatspells.h b/src/spells/combatspells.h index 4e3173a66..cf07c2a89 100644 --- a/src/spells/combatspells.h +++ b/src/spells/combatspells.h @@ -49,7 +49,6 @@ extern "C" { int sp_armorshield(struct castorder * co); int sp_stun(struct castorder * co); int sp_undeadhero(struct castorder * co); - int sp_shadowcall(struct castorder * co); int sp_immolation(struct castorder * co); #ifdef __cplusplus From 5b52451d9dc749de1b22d3b5fa3ea5571bce9d7d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 19:21:54 +0100 Subject: [PATCH 232/271] remove unused ai.aggression atribute --- res/e3a/races.xml | 6 +++--- res/eressea/races.xml | 6 +++--- src/kernel/race.h | 1 - src/kernel/xmlreader.c | 1 - src/monsters.c | 2 +- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 5060604a3..ccc118877 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -765,7 +765,7 @@ - + @@ -803,7 +803,7 @@ - + @@ -836,7 +836,7 @@ - + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 26607a297..3cf5136a4 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1038,7 +1038,7 @@ - + @@ -1074,7 +1074,7 @@ - + @@ -1105,7 +1105,7 @@ - + diff --git a/src/kernel/race.h b/src/kernel/race.h index 8fc6d5989..05e9ffdec 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -130,7 +130,6 @@ extern "C" { int capacity; int income; float speed; - float aggression; /* chance that a monster will attack */ int hitpoints; char *def_damage; int armor; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 1ac5583ec..9faf92ef8 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1595,7 +1595,6 @@ static void parse_ai(race * rc, xmlNodePtr node) xmlFree(propValue); } rc->splitsize = xml_ivalue(node, "splitsize", 0); - rc->aggression = (float)xml_fvalue(node, "aggression", 0.04); if (xml_bvalue(node, "killpeasants", false)) rc->flags |= RCF_KILLPEASANTS; if (xml_bvalue(node, "moverandom", false)) diff --git a/src/monsters.c b/src/monsters.c index a7678c701..3c9ee1eb8 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -216,7 +216,7 @@ static order *get_money_for_dragon(region * r, unit * udragon, int wanted) /* falls genug geld in der region ist, treiben wir steuern ein. */ if (rmoney(r) >= wanted) { /* 5% chance, dass der drache aus einer laune raus attackiert */ - if (!attacks || chance(1.0 - u_race(udragon)->aggression)) { + if (!attacks) { /* Drachen haben in E3 und E4 keine Einnahmen. Neuer Befehl Pluendern erstmal nur fuer Monster?*/ return create_order(K_LOOT, default_locale, NULL); } From 4e5f1d05ce228219a0e8b9865569d16499c79fa8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 21:15:14 +0100 Subject: [PATCH 233/271] Be very strict about C standards. Compile with -std=c89 in gcc. remove all // comments (they are nice, but unnecessary). variables only declared at start of block. various pedantery. backwards compatible va_copy for pre-C99 gcc. --- src/CMakeLists.txt | 4 +-- src/alchemy.c | 7 ++--- src/attributes/dict.h | 2 +- src/attributes/key.c | 2 +- src/attributes/key.h | 2 +- src/battle.c | 4 +-- src/battle.test.c | 6 ++-- src/bind_faction.c | 2 +- src/bind_storage.c | 5 +-- src/bind_unit.c | 4 ++- src/bindings.c | 2 -- src/creport.c | 8 ++--- src/economy.c | 6 ++-- src/economy.test.c | 8 ++--- src/give.c | 6 ++-- src/give.test.c | 2 +- src/gmtool.c | 4 +-- src/guard.test.c | 2 +- src/json.c | 6 ++-- src/json.test.c | 2 +- src/kernel/build.test.c | 2 +- src/kernel/building.c | 7 +++-- src/kernel/building.h | 4 +-- src/kernel/config.c | 11 +++---- src/kernel/config.h | 4 +-- src/kernel/config.test.c | 6 ++-- src/kernel/connection.c | 2 +- src/kernel/curse.c | 2 +- src/kernel/curse.test.c | 1 - src/kernel/equipment.c | 2 +- src/kernel/faction.c | 3 +- src/kernel/faction.h | 6 ++-- src/kernel/item.c | 13 ++++---- src/kernel/item.test.c | 2 +- src/kernel/jsonconf.c | 8 +++-- src/kernel/jsonconf.test.c | 4 +-- src/kernel/messages.test.c | 2 +- src/kernel/race.c | 14 ++++----- src/kernel/race.h | 2 +- src/kernel/region.c | 2 +- src/kernel/save.c | 8 ++--- src/kernel/save.h | 2 +- src/kernel/save.test.c | 2 +- src/kernel/terrain.c | 2 +- src/kernel/unit.c | 5 ++- src/kernel/unit.test.c | 23 +++++++------- src/kernel/version.c | 2 +- src/kernel/xmlreader.c | 10 +++--- src/keyword.c | 2 +- src/keyword.h | 1 - src/laws.c | 61 ++++++++++++++++++------------------ src/laws.test.c | 25 ++++++++------- src/magic.c | 10 +++--- src/magic.h | 2 +- src/magic.test.c | 2 +- src/main.c | 4 +-- src/monsters.c | 2 +- src/monsters.test.c | 6 ++-- src/move.c | 16 +++++----- src/move.test.c | 7 +++-- src/names.c | 2 +- src/piracy.c | 11 ++++--- src/piracy.test.c | 6 ++-- src/platform.h | 5 +++ src/prefix.h | 2 +- src/report.c | 15 +++++---- src/reports.c | 40 +++++++++++------------ src/spells.c | 2 +- src/spells.test.c | 14 +++++---- src/spells/combatspells.c | 5 +-- src/spy.c | 2 +- src/spy.test.c | 2 +- src/study.test.c | 2 +- src/test_eressea.c | 9 ++++-- src/triggers/changefaction.c | 1 - src/triggers/createunit.c | 1 - src/upkeep.test.c | 6 ++-- src/util/attrib.c | 6 ++-- src/util/attrib.h | 6 ++-- src/util/bsdstring.c | 2 +- src/util/bsdstring.test.c | 2 +- src/util/language.c | 10 +++--- src/util/log.c | 12 +++---- src/util/parser.test.c | 4 +-- src/util/password.h | 6 ++-- src/util/umlaut.c | 2 +- src/util/unicode.test.c | 4 +-- src/util/variant.h | 4 +-- src/volcano.c | 8 ++--- 89 files changed, 285 insertions(+), 279 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4d3614e9..3fc1e62a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,8 +25,8 @@ IF (CMAKE_COMPILER_IS_GNUCC) ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -ansi -pedantic") add_definitions(-DHAVE__BOOL) ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP") diff --git a/src/alchemy.c b/src/alchemy.c index 81244eba1..aff3485ef 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -172,8 +172,7 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { static int potion_truth(unit *u) { UNUSED_ARG(u); - // TODO: this potion does nothing! - // fset(u, UFL_DISBELIEVES); + /* TODO: this potion does nothing! */ return 1; } @@ -297,7 +296,7 @@ static void a_initeffect(attrib * a) a->data.v = calloc(sizeof(effect_data), 1); } -static void a_finalizeeffect(attrib * a) //-V524 +static void a_finalizeeffect(attrib * a) /*-V524 */ { free(a->data.v); } @@ -328,7 +327,7 @@ static int a_readeffect(attrib * a, void *owner, struct gamedata *data) return AT_READ_FAIL; } if (rtype->ptype==oldpotiontype[P_HEAL]) { - // healing potions used to have long-term effects + /* healing potions used to have long-term effects */ return AT_READ_FAIL; } edata->type = rtype->ptype; diff --git a/src/attributes/dict.h b/src/attributes/dict.h index cc700bb9f..aa6b4566a 100644 --- a/src/attributes/dict.h +++ b/src/attributes/dict.h @@ -20,7 +20,7 @@ struct attrib; extern "C" { #endif - extern struct attrib_type at_dict; // DEPRECATED: at_dict has been replaced with at_keys + extern struct attrib_type at_dict; /* DEPRECATED: at_dict has been replaced with at_keys */ void dict_set(struct attrib * a, const char * name, int value); diff --git a/src/attributes/key.c b/src/attributes/key.c index 8b09fdd1c..31580bccf 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -134,7 +134,7 @@ void key_set(attrib ** alist, int key, int val) n = keys[0]; } keys = realloc(keys, sizeof(int) *(2 * n + 3)); - // TODO: does insertion sort pay off here? prob. not. + /* TODO: does insertion sort pay off here? prob. not. */ keys[0] = n + 1; keys[2 * n + 1] = key; keys[2 * n + 2] = val; diff --git a/src/attributes/key.h b/src/attributes/key.h index 81511d248..0b3ab748f 100644 --- a/src/attributes/key.h +++ b/src/attributes/key.h @@ -26,7 +26,7 @@ extern "C" { #endif struct attrib; struct attrib_type; - extern struct attrib_type at_key; // DEPRECATED: at_key has been replaced with at_keys + extern struct attrib_type at_key; /* DEPRECATED: at_key has been replaced with at_keys */ extern struct attrib_type at_keys; void key_set(struct attrib **alist, int key, int value); diff --git a/src/battle.c b/src/battle.c index 04e72d92c..9ce22918a 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1111,7 +1111,7 @@ int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awty ar += am; if (magres) { - // calculate damage multiplier for magical damage + /* calculate damage multiplier for magical damage */ double res = 1.0 - magic_resistance(du); if (u_race(du)->battle_flags & BF_EQUIPMENT) { @@ -1302,10 +1302,10 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) if (oldpotiontype[P_HEAL] && !fval(&df->person[dt.index], FL_HEALING_USED)) { if (i_get(du->items, oldpotiontype[P_HEAL]->itype) > 0) { - i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1); message *m = msg_message("battle::potionsave", "unit", du); message_faction(b, du->faction, m); msg_release(m); + i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1); fset(&df->person[dt.index], FL_HEALING_USED); df->person[dt.index].hp = u_race(du)->hitpoints * 5; /* give the person a buffer */ return false; diff --git a/src/battle.test.c b/src/battle.test.c index 946d5fcee..5d34766db 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -433,9 +433,9 @@ static void test_battle_skilldiff(CuTest *tc) td.fighter->person[0].flags |= FL_SLEEPING; CuAssertIntEquals(tc, 3, skilldiff(ta, td, 0)); - // TODO: unarmed halfling vs. dragon: +5 - // TODO: rule_goblin_bonus - // TODO: weapon modifiers, missiles, skill_formula + /* TODO: unarmed halfling vs. dragon: +5 */ + /* TODO: rule_goblin_bonus */ + /* TODO: weapon modifiers, missiles, skill_formula */ free_battle(b); test_cleanup(); diff --git a/src/bind_faction.c b/src/bind_faction.c index 371481fcb..518ccccac 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -381,7 +381,7 @@ static int tolua_faction_get_origin(lua_State * L) static int tolua_faction_destroy(lua_State * L) { faction **fp, *f = (faction *)tolua_tousertype(L, 1, 0); - // TODO: this loop is slow af, but what can we do? + /* TODO: this loop is slow af, but what can we do? */ for (fp = &factions; *fp; fp = &(*fp)->next) { if (*fp == f) { destroyfaction(fp); diff --git a/src/bind_storage.c b/src/bind_storage.c index 6b582e815..68ac36179 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -100,8 +100,9 @@ static int tolua_storage_tostring(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); char name[64]; - // safe to use sprintf here, because: - // %p is at most 16 characters, %d 20, text is 16, comes to 53 with \0 + /* safe to use sprintf here, because: + * %p is at most 16 characters, %d 20, text is 16, + * comes to 53 with \0 */ sprintf(name, "", (void *)data, data->version); lua_pushstring(L, name); return 1; diff --git a/src/bind_unit.c b/src/bind_unit.c index a9d413bf0..c8ac2b362 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -857,13 +857,15 @@ static int tolua_unit_create(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 2, 0); + unit *u; const char *rcname = tolua_tostring(L, 4, NULL); int num = (int)tolua_tonumber(L, 3, 1); const race *rc; + assert(f && r); rc = rcname ? rc_find(rcname) : f->race; assert(rc); - unit *u = create_unit(r, f, num, rc, 0, NULL, NULL); + u = create_unit(r, f, num, rc, 0, NULL, NULL); tolua_pushusertype(L, u, TOLUA_CAST "unit"); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 531b68618..18261a507 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -508,7 +508,6 @@ static void reset_game(void) for (f = factions; f; f = f->next) { f->flags &= FFL_SAVEMASK; } -// init_locales(); } static int tolua_process_orders(lua_State * L) @@ -1178,7 +1177,6 @@ int eressea_run(lua_State *L, const char *luafile) lua_remove(L, -2); /* try to run configuration scripts: */ - // err = run_script(L, "config.lua"); err = run_script(L, "custom.lua"); /* run the main script */ diff --git a/src/creport.c b/src/creport.c index 345aaf0bc..c2d10d1c0 100644 --- a/src/creport.c +++ b/src/creport.c @@ -286,7 +286,7 @@ cr_output_curses(struct stream *out, const faction * viewer, const void *obj, ob } static void cr_output_curses_compat(FILE *F, const faction * viewer, const void *obj, objtype_t typ) { - // TODO: eliminate this function + /* TODO: eliminate this function */ stream strm; fstream_init(&strm, F); cr_output_curses(&strm, viewer, obj, typ); @@ -718,7 +718,7 @@ static void cr_output_spells(stream *out, const unit * u, int maxlevel) for (ql = book->spells, qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { - // TODO: no need to deref spref here, spref->name == sp->sname + /* TODO: no need to deref spref here, spref->name == sp->sname */ spell * sp = sbe->sp; const char *name = translate(mkname("spell", sp->sname), spell_name(sp, f->locale)); if (!header) { @@ -752,7 +752,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f, const char *prefix; assert(u && u->number); - assert(u->region == r); // TODO: if this holds true, then why did we pass in r? + assert(u->region == r); /* TODO: if this holds true, then why did we pass in r? */ if (fval(u_race(u), RCF_INVISIBLE)) return; @@ -990,7 +990,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f, static void cr_output_unit_compat(FILE * F, const region * r, const faction * f, const unit * u, int mode) { - // TODO: eliminate this function + /* TODO: eliminate this function */ stream strm; fstream_init(&strm, F); cr_output_unit(&strm, r, f, u, mode); diff --git a/src/economy.c b/src/economy.c index ab1875eed..94a1a90fa 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1753,7 +1753,7 @@ static void expandselling(region * r, request * sellorders, int limit) int i; int use = 0; for (i = 0, search = luxurytypes; search != ltype; search = search->next) { - // TODO: this is slow and lame! + /* TODO: this is slow and lame! */ ++i; } if (counter[i] >= limit) @@ -2444,8 +2444,8 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) f = u2->faction; } else { - // TODO: is this really necessary? it's the only time we use faction.c/deadhash - // it allows stealing from a unit in a dead faction, but why? + /* TODO: is this really necessary? it's the only time we use faction.c/deadhash + * it allows stealing from a unit in a dead faction, but why? */ f = dfindhash(id); } diff --git a/src/economy.test.c b/src/economy.test.c index fdc218844..766fb4302 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -266,7 +266,7 @@ static void test_maintain_buildings(CuTest *tc) { b->size = btype->maxsize; u_set_building(u, b); - // this building has no upkeep, it just works: + /* this building has no upkeep, it just works: */ b->flags = 0; maintain_buildings(r); CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED)); @@ -278,7 +278,7 @@ static void test_maintain_buildings(CuTest *tc) { req[0].rtype = itype->rtype; btype->maintenance = req; - // we cannot afford to pay: + /* we cannot afford to pay: */ b->flags = 0; maintain_buildings(r); CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED)); @@ -287,7 +287,7 @@ static void test_maintain_buildings(CuTest *tc) { test_clear_messagelist(&f->msgs); test_clear_messagelist(&r->msgs); - // we can afford to pay: + /* we can afford to pay: */ i_change(&u->items, itype, 100); b->flags = 0; maintain_buildings(r); @@ -298,7 +298,7 @@ static void test_maintain_buildings(CuTest *tc) { CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "maintenance")); test_clear_messagelist(&f->msgs); - // this building has no owner, it doesn't work: + /* this building has no owner, it doesn't work: */ u_set_building(u, NULL); b->flags = 0; maintain_buildings(r); diff --git a/src/give.c b/src/give.c index d1a9d75f4..5abb950a6 100644 --- a/src/give.c +++ b/src/give.c @@ -70,8 +70,8 @@ static bool can_give(const unit * u, const unit * u2, const item_type * itype, i { if (u2) { if (u2->number==0 && !fval(u2, UFL_ISNEW)) { - // https://bugs.eressea.de/view.php?id=2230 - // cannot give anything to dead units + /* https://bugs.eressea.de/view.php?id=2230 + * cannot give anything to dead units */ return false; } else if (u->faction != u2->faction) { int rule = rule_give(); @@ -258,7 +258,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) message * msg; int maxt = max_transfers(); - assert(u2); // use disband_men for GIVE 0 + assert(u2); /* use disband_men for GIVE 0 */ if (!can_give_men(u, u2, ord, &msg)) { return msg; diff --git a/src/give.test.c b/src/give.test.c index 7da787c87..fbb71cf3c 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -393,7 +393,7 @@ static void test_give_new_unit(CuTest * tc) { } static void test_give_invalid_target(CuTest *tc) { - // bug https://bugs.eressea.de/view.php?id=1685 + /* bug https://bugs.eressea.de/view.php?id=1685 */ struct give env = { 0 }; order *ord; diff --git a/src/gmtool.c b/src/gmtool.c index 3db673731..5a0cd576c 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -184,7 +184,7 @@ map_region *mr_get(const view * vi, int xofs, int yofs) static point *coor2point(const coordinate * c, point * p) { assert(c && p); - p->x = c->x * TWIDTH + c->y * TWIDTH / 2; //-V537 + p->x = c->x * TWIDTH + c->y * TWIDTH / 2; /*-V537 */ p->y = c->y * THEIGHT; return p; } @@ -262,7 +262,7 @@ static chtype mr_tile(const map_region * mr, int highlight) const region *r = mr->r; switch (r->terrain->_name[0]) { case 'o': - return '.' | COLOR_PAIR(hl + COLOR_CYAN) | A_BOLD; //-V525 + return '.' | COLOR_PAIR(hl + COLOR_CYAN) | A_BOLD; /*-V525 */ case 'd': return 'D' | COLOR_PAIR(hl + COLOR_YELLOW) | A_BOLD; case 't': diff --git a/src/guard.test.c b/src/guard.test.c index c5bffeab5..fb55129ee 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -34,7 +34,7 @@ static void test_is_guarded(CuTest *tc) { } static void test_guard_unskilled(CuTest * tc) -// TODO: it would be better to test armedmen() +/* TODO: it would be better to test armedmen() */ { unit *u, *ug; region *r; diff --git a/src/json.c b/src/json.c index 2c27b9947..e6eacced9 100644 --- a/src/json.c +++ b/src/json.c @@ -67,13 +67,13 @@ int json_export(stream * out, int flags) { cJSON *json, *root = cJSON_CreateObject(); assert(out && out->api); if (regions && (flags & EXPORT_REGIONS)) { - char id[32]; // TODO: static_assert(INT_MAX < 10^32) + char id[32]; /* TODO: static_assert(INT_MAX < 10^32) */ region * r; plane * p; cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject()); for (p = planes; p; p = p->next) { cJSON *data; - sprintf(id, "%d", p->id); // safe, unless int is bigger than 64 bit + sprintf(id, "%d", p->id); /* safe, unless int is bigger than 64 bit */ cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", p->minx); cJSON_AddNumberToObject(data, "y", p->miny); @@ -85,7 +85,7 @@ int json_export(stream * out, int flags) { cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject()); for (r = regions; r; r = r->next) { cJSON *data; - sprintf(id, "%d", r->uid); // safe, unless int is bigger than 64 bit + sprintf(id, "%d", r->uid); /* safe, unless int is bigger than 64 bit */ cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "y", r->y); diff --git a/src/json.test.c b/src/json.test.c index 528b734a4..57cb6e136 100644 --- a/src/json.test.c +++ b/src/json.test.c @@ -16,7 +16,7 @@ static char *strip(char *str) { char *s = str, *b = str, *e = str; - // b is where text begins, e where it ends, s where we insert it. + /* b is where text begins, e where it ends, s where we insert it. */ for (; *b && isspace(*b); ++b) {}; for (e = b; *e && !isspace(*e); ++e) {}; while (*b) { diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index b714f58f0..77efcfd73 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -200,7 +200,7 @@ static void test_build_with_potion(CuTest *tc) { CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20)); CuAssertIntEquals(tc, 2, get_effect(u, ptype)); set_level(u, SK_ARMORER, bf.cons.minskill); - scale_number(u, 2); // OBS: this scales the effects, too: + scale_number(u, 2); /* OBS: this scales the effects, too: */ CuAssertIntEquals(tc, 4, get_effect(u, ptype)); CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20)); CuAssertIntEquals(tc, 2, get_effect(u, ptype)); diff --git a/src/kernel/building.c b/src/kernel/building.c index 98caad07a..06078aaba 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -461,8 +461,8 @@ void remove_building(building ** blist, building * b) bunhash(b); /* Falls Karawanserei, Damm oder Tunnel einst�rzen, wird die schon - * gebaute Stra�e zur H�lfte vernichtet */ - // TODO: caravan, tunnel, dam modularization ? is_building_type ? + * gebaute Strasse zur Haelfte vernichtet */ + /* TODO: caravan, tunnel, dam modularization ? is_building_type ? */ if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) { region *r = b->region; int d; @@ -605,10 +605,11 @@ static unit *building_owner_ex(const building * bld, const struct faction * last unit *building_owner(const building * bld) { + unit *owner; if (!bld) { return NULL; } - unit *owner = bld->_owner; + owner = bld->_owner; if (!owner || (owner->building != bld || owner->number <= 0)) { unit * heir = building_owner_ex(bld, owner ? owner->faction : 0); return (heir && heir->number > 0) ? heir : 0; diff --git a/src/kernel/building.h b/src/kernel/building.h index 8b1a5b05b..1adce7e09 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -55,8 +55,8 @@ extern "C" { typedef enum { DEFENSE_BONUS, - CLOSE_COMBAT_ATTACK_BONUS, // TODO: only DEFENSE_BONUS is in use? - RANGED_ATTACK_BONUS, + CLOSE_COMBAT_ATTACK_BONUS, /* TODO: only DEFENSE_BONUS is in use? */ + RANGED_ATTACK_BONUS } building_bonus; typedef struct building_type { diff --git a/src/kernel/config.c b/src/kernel/config.c index ca23a5bc9..3f04b03b3 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -275,7 +275,6 @@ unit *getnewunit(const region * r, const faction * f) /* -- Erschaffung neuer Einheiten ------------------------------ */ static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; -// PEASANT: "b", "ba", "bau", "baue", "p", "pe", "pea", "peas" static int *forbidden_ids; int forbiddenid(int id) @@ -491,19 +490,19 @@ int check_param(const struct param *p, const char *key, const char *searchvalue) { int result = 0; const char *value = get_param(p, key); + char *v, *p_value; if (!value) { return 0; } - char *p_value = strdup(value); - const char *delimiter = " ,;"; - char *v = strtok(p_value, delimiter); + p_value = strdup(value); + v = strtok(p_value, " ,;"); while (v != NULL) { if (strcmp(v, searchvalue) == 0) { result = 1; break; } - v = strtok(NULL, delimiter); + v = strtok(NULL, " ,;"); } free(p_value); return result; @@ -836,7 +835,7 @@ const char * game_name(void) const char * game_name_upper(void) { - static char result[32]; // FIXME: static result + static char result[32]; /* FIXME: static result */ char *r = result; const char *param = game_name(); const char *c = param; diff --git a/src/kernel/config.h b/src/kernel/config.h index b51ba2725..e38d1dd56 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -61,8 +61,8 @@ extern "C" { int newcontainerid(void); bool rule_region_owners(void); - bool rule_stealth_other(void); // units can pretend to be another faction, TARNE PARTEI - bool rule_stealth_anon(void); // units can anonymize their faction, TARNE PARTEI [NICHT] + bool rule_stealth_other(void); /* units can pretend to be another faction, TARNE PARTEI */ + bool rule_stealth_anon(void); /* units can anonymize their faction, TARNE PARTEI [NICHT] */ int rule_alliance_limit(void); int rule_faction_limit(void); #define HARVEST_WORK 0x00 diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index 72b2387ac..9a10a4c56 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -51,7 +51,7 @@ static void test_read_unitid(CuTest *tc) { CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region)); free_order(ord); - // bug https://bugs.eressea.de/view.php?id=1685 + /* bug https://bugs.eressea.de/view.php?id=1685 */ ord = create_order(K_GIVE, lang, "##"); init_order(ord); CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region)); @@ -98,14 +98,14 @@ static void test_getunit(CuTest *tc) { CuAssertPtrEquals(tc, NULL, u2); free_order(ord); - // bug https://bugs.eressea.de/view.php?id=1685 + /* bug https://bugs.eressea.de/view.php?id=1685 */ ord = create_order(K_GIVE, lang, "TEMP ##"); init_order(ord); CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, NULL, u2); free_order(ord); - // bug https://bugs.eressea.de/view.php?id=1685 + /* bug https://bugs.eressea.de/view.php?id=1685 */ ord = create_order(K_GIVE, lang, "##"); init_order(ord); CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2)); diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 5b2615bcc..43caee729 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -640,7 +640,7 @@ int read_borders(gamedata *data) if (!to || !from) { log_error("%s connection %d has missing regions", zText, bid); if (type->read) { - // skip ahead + /* skip ahead */ connection dummy; type->read(&dummy, data); } diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 7df567940..25f89ec1f 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -696,7 +696,7 @@ void transfer_curse(unit * u, unit * u2, int n) int curse_cansee(const curse *c, const faction *viewer, objtype_t typ, const void *obj, int self) { if (self < 3 && c->magician && c->magician->faction == viewer) { - // magicians can see their own curses better than anybody, no exceptions + /* magicians can see their own curses better than anybody, no exceptions */ self = 3; } else if (c->type->cansee) { diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 0ca4510d9..56c3288f8 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -55,7 +55,6 @@ static void setup_curse(curse_fixture *fix, const char *name) { } static void cleanup_curse(curse_fixture *fix) { - // destroy_curse(fix->c); test_cleanup(); } diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 6b74121ff..d9a971455 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -253,7 +253,7 @@ void equipment_done(void) { free(eq->items); eq->items = next; } - // TODO: subsets, skills + /* TODO: subsets, skills */ for (i=0;i!=MAXSKILLS;++i) { free(eq->skills[i]); } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index a5373d44d..57cd5d3af 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -449,7 +449,7 @@ void destroyfaction(faction ** fp) /* units of other factions that were disguised as this faction * have their disguise replaced by ordinary faction hiding. */ if (rule_stealth_other()) { - // TODO: f.alive should be tested for in get_otherfaction + /* TODO: f.alive should be tested for in get_otherfaction */ region *rc; for (rc = regions; rc; rc = rc->next) { for (u = rc->units; u; u = u->next) { @@ -553,7 +553,6 @@ void faction_setbanner(faction * self, const char *banner) void faction_setpassword(faction * f, const char *pwhash) { assert(pwhash); - // && pwhash[0] == '$'); free(f->_password); f->_password = strdup(pwhash); } diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 1bab9101c..0a0ac39d6 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -38,11 +38,11 @@ extern "C" { extern struct attrib_type at_maxmagicians; /* faction flags */ -#define FFL_NEWID (1<<0) // Die Partei hat bereits einmal ihre no gewechselt +#define FFL_NEWID (1<<0) /* Die Partei hat bereits einmal ihre no gewechselt */ #define FFL_ISNEW (1<<1) -#define FFL_PWMSG (1<<2) // received a "new password" message +#define FFL_PWMSG (1<<2) /* received a "new password" message */ #define FFL_QUIT (1<<3) -#define FFL_CURSED (1<<4) // you're going to have a bad time +#define FFL_CURSED (1<<4) /* you're going to have a bad time */ #define FFL_DEFENDER (1<<10) #define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */ #define FFL_NOAID (1<<21) /* Hilfsflag Kampf */ diff --git a/src/kernel/item.c b/src/kernel/item.c index 9327700cd..177e44831 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -155,7 +155,7 @@ const char *resourcename(const resource_type * rtype, int flags) } } if (flags & NMF_PLURAL) { - static char name[64]; // FIXME: static return value + static char name[64]; /* FIXME: static return value */ size_t len = strlen(rtype->_name); assert(len <= sizeof(name) - 3); memcpy(name, rtype->_name, len); @@ -638,11 +638,14 @@ static const char *resourcenames[MAX_RESOURCES] = { const resource_type *get_resourcetype(resource_t type) { static int update; static struct resource_type * rtypes[MAX_RESOURCES]; + const resource_type *rtype = NULL; if (update != num_resources) { memset(rtypes, 0, sizeof(rtypes)); update = num_resources; } - const resource_type *rtype = rtypes[type]; + else { + rtype = rtypes[type]; + } if (!rtype) { rtype = rtypes[type] = rt_find(resourcenames[type]); } @@ -975,27 +978,23 @@ void init_resources(void) { resource_type *rtype; - rt_get_or_create(resourcenames[R_PERSON]); // lousy hack + rt_get_or_create(resourcenames[R_PERSON]); /* lousy hack */ rtype = rt_get_or_create(resourcenames[R_PEASANT]); rtype->uchange = res_changepeasants; - // R_SILVER rtype = rt_get_or_create(resourcenames[R_SILVER]); rtype->flags |= RTF_ITEM | RTF_POOLED; rtype->uchange = res_changeitem; rtype->itype = it_get_or_create(rtype); rtype->itype->give = give_money; - // R_PERMAURA rtype = rt_get_or_create(resourcenames[R_PERMAURA]); rtype->uchange = res_changepermaura; - // R_LIFE rtype = rt_get_or_create(resourcenames[R_LIFE]); rtype->uchange = res_changehp; - // R_AURA rtype = rt_get_or_create(resourcenames[R_AURA]); rtype->uchange = res_changeaura; diff --git a/src/kernel/item.test.c b/src/kernel/item.test.c index 231b45d00..52e7d9917 100644 --- a/src/kernel/item.test.c +++ b/src/kernel/item.test.c @@ -19,7 +19,7 @@ static void test_resourcename_no_appearance(CuTest *tc) { const resource_type *rtype; test_cleanup(); - init_resources(); // creates R_SILVER + init_resources(); /* creates R_SILVER */ rtype = get_resourcetype(R_SILVER); assert(rtype && rtype->itype); assert(rtype->itype->_appearance[0] == 0); diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 89219665e..2478c838f 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -146,6 +146,8 @@ static void json_maintenance(cJSON *json, maintenance **mtp) { static void json_construction(cJSON *json, construction **consp) { cJSON *child; + construction * cons; + if (json->type == cJSON_Array) { int size = 0; for (child = json->child; child; child = child->next) { @@ -164,7 +166,7 @@ static void json_construction(cJSON *json, construction **consp) { log_error("construction %s is not a json object: %d", json->string, json->type); return; } - construction * cons = (construction *)calloc(sizeof(construction), 1); + cons = (construction *)calloc(sizeof(construction), 1); for (child = json->child; child; child = child->next) { switch (child->type) { case cJSON_Object: @@ -191,8 +193,8 @@ static void json_construction(cJSON *json, construction **consp) { } static void json_terrain_production(cJSON *json, terrain_production *prod) { - assert(json->type == cJSON_Object); cJSON *child; + assert(json->type == cJSON_Object); for (child = json->child; child; child = child->next) { char **dst = 0; switch (child->type) { @@ -490,7 +492,7 @@ static void json_race(cJSON *json, race *rc) { else if (strcmp(child->string, "ac") == 0) { rc->armor = child->valueint; } - // TODO: studyspeed (orcs only) + /* TODO: studyspeed (orcs only) */ break; case cJSON_Array: if (strcmp(child->string, "flags") == 0) { diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index abf64e7d5..dcf748d00 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -75,7 +75,7 @@ static void test_settings(CuTest * tc) cJSON *json = cJSON_Parse(data); test_cleanup(); - config_set("game.id", "42"); // should not be replaced + config_set("game.id", "42"); /* should not be replaced */ json_config(json); CuAssertStrEquals(tc, "42", config_get("game.id")); CuAssertStrEquals(tc, "1", config_get("true")); @@ -488,7 +488,7 @@ static void test_terrains(CuTest * tc) CuAssertPtrEquals(tc, rt_get_or_create("h0"), ter->herbs[0]->rtype); CuAssertPtrEquals(tc, rt_get_or_create("h1"), ter->herbs[1]->rtype); CuAssertPtrEquals(tc, 0, (void *)ter->herbs[2]); - CuAssertPtrNotNull(tc, ter->name); // anything named "plain" uses plain_name() + CuAssertPtrNotNull(tc, ter->name); /* anything named "plain" uses plain_name() */ CuAssertPtrNotNull(tc, ter->production); CuAssertPtrEquals(tc, rt_get_or_create("stone"), (resource_type *)ter->production[0].type); CuAssertDblEquals(tc, 0.1, ter->production[0].chance, 0.01); diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index c391c8720..7b0f2dd5e 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -39,7 +39,7 @@ void test_message(CuTest *tc) { static void test_merge_split(CuTest *tc) { message_list *mlist = 0, *append = 0; - struct mlist **split; // TODO: why is this a double asterisk? + struct mlist **split; /* TODO: why is this a double asterisk? */ message_type *mtype = mt_new("custom", NULL); message *msg; diff --git a/src/kernel/race.c b/src/kernel/race.c index 683d37d63..2ede414c7 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -86,12 +86,12 @@ typedef struct rcoption { enum { RCO_NONE, - RCO_SCARE, // races that scare and eat peasants - RCO_OTHER, // may recruit from another race - RCO_STAMINA, // every n levels of stamina add +1 RC - RCO_HUNGER, // custom hunger.damage override (char *) + RCO_SCARE, /* races that scare and eat peasants */ + RCO_OTHER, /* may recruit from another race */ + RCO_STAMINA, /* every n levels of stamina add +1 RC */ + RCO_HUNGER, /* custom hunger.damage override (char *) */ RCO_TRADELUX, - RCO_TRADEHERB, + RCO_TRADEHERB }; static void rc_setoption(race *rc, int k, const char *value) { @@ -476,7 +476,7 @@ const char* rc_name(const race * rc, name_t n, char *name, size_t size) { const char *rc_name_s(const race * rc, name_t n) { - static char name[64]; // FIXME: static return value + static char name[64]; /* FIXME: static return value */ return rc_name(rc, n, name, sizeof(name)); } @@ -497,7 +497,7 @@ const char *racename(const struct locale *loc, const unit * u, const race * rc) const char *str, *prefix = raceprefix(u); if (prefix != NULL) { - static char lbuf[80]; // FIXME: static return value + static char lbuf[80]; /* FIXME: static return value */ char *bufp = lbuf; size_t size = sizeof(lbuf) - 1; int ch, bytes; diff --git a/src/kernel/race.h b/src/kernel/race.h index 05e9ffdec..ceb5e59d9 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -151,7 +151,7 @@ extern "C" { struct item *(*itemdrop) (const struct race *, int size); void(*init_familiar) (struct unit *); - struct rcoption *options; // rarely used properties + struct rcoption *options; /* rarely used properties */ const struct race *familiars[MAXMAGIETYP]; struct race *next; diff --git a/src/kernel/region.c b/src/kernel/region.c index 06d2d9d7c..aefffa875 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1132,7 +1132,7 @@ void terraform_region(region * r, const terrain_type * terrain) } } if (!nb) { - // TODO: this is really lame + /* TODO: this is really lame */ int i = get_maxluxuries(); if (i > 0) { i = rng_int() % i; diff --git a/src/kernel/save.c b/src/kernel/save.c index 67ed7e125..3ddaf7a7c 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -94,7 +94,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* exported symbols symbols */ int firstx = 0, firsty = 0; -// TODO: is this still important? +/* TODO: is this still important? */ int enc_gamedata = ENCODING_UTF8; /* local symbols */ @@ -467,7 +467,7 @@ void read_planes(gamedata *data) { } } read_attribs(data, &pl->attribs, pl); - if (pl->id != 1094969858) { // Regatta + if (pl->id != 1094969858) { /* Regatta */ addlist(&planes, pl); } } @@ -1206,7 +1206,7 @@ static void read_password(gamedata *data, faction *f) { char * pass = getpasswd(f->no); if (pass) { faction_setpassword(f, password_encode(pass, PASSWORD_DEFAULT)); - free(pass); // TODO: remove this allocation! + free(pass); /* TODO: remove this allocation! */ } else { log_error("data version is BADCRYPT but %s not in password.txt", itoa36(f->no)); @@ -1542,7 +1542,7 @@ struct building *read_building(gamedata *data) { b->type = bt_find(name); read_attribs(data, &b->attribs, b); - // repairs, bug 2221: + /* repairs, bug 2221: */ if (b->type->maxsize>0 && b->size>b->type->maxsize) { log_error("building too big: %s (%s size %d of %d), fixing.", buildingname(b), b->type->_name, b->size, b->type->maxsize); b->size = b->type->maxsize; diff --git a/src/kernel/save.h b/src/kernel/save.h index 4ead34efe..763ff66b6 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -40,7 +40,7 @@ extern "C" { /* Nach MAX_INPUT_SIZE brechen wir das Einlesen der Zeile ab und nehmen an, * dass hier ein Fehler (fehlende ") vorliegt */ - // TODO: is this *really* still in use? + /* TODO: is this *really* still in use? */ extern int enc_gamedata; int readorders(const char *filename); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 70bcb2e65..9501df896 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -78,7 +78,7 @@ static void test_readwrite_unit(CuTest * tc) mstream_done(&data.strm); gamedata_done(&data); - move_unit(u, r, NULL); // this makes sure that u doesn't leak + move_unit(u, r, NULL); /* this makes sure that u doesn't leak */ test_cleanup(); } diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index ca72e3060..3d6f4c313 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -114,7 +114,7 @@ terrain_type * get_or_create_terrain(const char *name) { terrain->next = registered_terrains; registered_terrains = terrain; if (strcmp("plain", name) == 0) { - // TODO: this is awful, it belongs in config + /* TODO: this is awful, it belongs in config */ terrain->name = &plain_name; } } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 2f38a0836..1acebac6d 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -120,7 +120,7 @@ unit *findunitr(const region * r, int n) return (u && u->region == r) ? u : 0; } -// TODO: deprecated, replace with findunit(n) +/* TODO: deprecated, replace with findunit(n) */ unit *findunitg(int n, const region * hint) { UNUSED_ARG(hint); @@ -366,7 +366,7 @@ int gift_items(unit * u, int flags) static unit *deleted_units = NULL; #define DMAXHASH 7919 -#undef DMAXHASH // TODO: makes dfindhash slow! +#undef DMAXHASH /* TODO: makes dfindhash slow! */ #ifdef DMAXHASH typedef struct dead { struct dead *nexthash; @@ -455,7 +455,6 @@ int remove_unit(unit ** ulist, unit * u) #ifdef DMAXHASH dhash(u->no, u->faction); #endif - // u_setfaction(u, NULL); u->region = NULL; diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 1ddf6282e..16ff2890b 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -260,7 +260,7 @@ static void test_skillmod(CuTest *tc) { CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0)); a_remove(&u->attribs, a); - a_add(&u->attribs, a = make_skillmod(NOSKILL, SMF_ALWAYS, 0, 2.0, 0)); // NOSKILL means any skill + a_add(&u->attribs, a = make_skillmod(NOSKILL, SMF_ALWAYS, 0, 2.0, 0)); /* NOSKILL means any skill */ CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0)); a_remove(&u->attribs, a); @@ -296,7 +296,7 @@ static void test_skill_familiar(CuTest *tc) { test_cleanup(); - // setup two units + /* setup two units */ mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); fam = test_create_unit(mag->faction, test_create_region(0, 0, 0)); set_level(fam, SK_PERCEPTION, 6); @@ -304,14 +304,14 @@ static void test_skill_familiar(CuTest *tc) { set_level(mag, SK_PERCEPTION, 6); CuAssertIntEquals(tc, 6, effskill(mag, SK_PERCEPTION, 0)); - // make them mage and familiar to each other + /* make them mage and familiar to each other */ CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam)); - // when they are in the same region, the mage gets half their skill as a bonus + /* when they are in the same region, the mage gets half their skill as a bonus */ CuAssertIntEquals(tc, 6, effskill(fam, SK_PERCEPTION, 0)); CuAssertIntEquals(tc, 9, effskill(mag, SK_PERCEPTION, 0)); - // when they are further apart, divide bonus by distance + /* when they are further apart, divide bonus by distance */ r = test_create_region(3, 0, 0); move_unit(fam, r, &r->units); CuAssertIntEquals(tc, 7, effskill(mag, SK_PERCEPTION, 0)); @@ -323,7 +323,6 @@ static void test_age_familiar(CuTest *tc) { test_cleanup(); - // setup two units mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); fam = test_create_unit(mag->faction, test_create_region(0, 0, 0)); CuAssertPtrEquals(tc, 0, get_familiar(mag)); @@ -426,28 +425,28 @@ static void test_remove_unit(CuTest *tc) { remove_unit(&r->units, u1); CuAssertIntEquals(tc, 0, u1->number); CuAssertPtrEquals(tc, 0, u1->region); - // money is given to a survivor: + /* money is given to a survivor: */ CuAssertPtrEquals(tc, 0, u1->items); CuAssertIntEquals(tc, 0, region_getresource(r, rtype)); CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype)); - // unit is removed from f->units: + /* unit is removed from f->units: */ CuAssertPtrEquals(tc, 0, u1->nextF); CuAssertPtrEquals(tc, u2, f->units); CuAssertPtrEquals(tc, 0, u2->nextF); CuAssertPtrEquals(tc, 0, u2->prevF); - // unit is no longer in r->units: + /* unit is no longer in r->units: */ CuAssertPtrEquals(tc, u2, r->units); CuAssertPtrEquals(tc, 0, u2->next); - // unit is in deleted_units: + /* unit is in deleted_units: */ CuAssertPtrEquals(tc, 0, findunit(uno)); CuAssertPtrEquals(tc, f, dfindhash(uno)); remove_unit(&r->units, u2); - // no survivor, give money to peasants: + /* no survivor, give money to peasants: */ CuAssertIntEquals(tc, 100, region_getresource(r, rtype)); - // there are now no more units: + /* there are now no more units: */ CuAssertPtrEquals(tc, 0, r->units); CuAssertPtrEquals(tc, 0, f->units); test_cleanup(); diff --git a/src/kernel/version.c b/src/kernel/version.c index 8cf6a372e..633fbf7bf 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -4,7 +4,7 @@ #include #ifndef ERESSEA_VERSION -// the version number, if it was not passed to make with -D +/* the version number, if it was not passed to make with -D */ #define ERESSEA_VERSION "3.11.0" #endif diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 9faf92ef8..2cf0b42e8 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -659,7 +659,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) xmlFree(propValue); propValue = xmlGetProp(node, BAD_CAST "value"); - wtype->damage[pos] = strdup((const char *)propValue); // TODO: this is a memory leak + wtype->damage[pos] = strdup((const char *)propValue); /* TODO: this is a memory leak */ if (k == 0) wtype->damage[1 - pos] = wtype->damage[pos]; xmlFree(propValue); @@ -1043,7 +1043,7 @@ static int parse_resources(xmlDocPtr doc) else if (strcmp((const char *)propValue, "material") == 0) { int g, num, den = 100; double fval = xml_fvalue(node, "value", 0); - // TODO: extract into a function for reading fractions? + /* TODO: extract into a function for reading fractions? */ num = (int)(fval * den + 0.5); g = gcd(num, den); num /= g; @@ -1635,8 +1635,8 @@ static int parse_races(xmlDocPtr doc) xmlFree(propValue); rc->magres = xml_ivalue(node, "magres", rc->magres); - rc->healing = (int)(xml_fvalue(node, "healing", rc->healing) * 100); // TODO: store as int in XML - rc->maxaura = (int)(xml_fvalue(node, "maxaura", rc->maxaura) * 100); // TODO: store as int in XML + rc->healing = (int)(xml_fvalue(node, "healing", rc->healing) * 100); /* TODO: store as int in XML */ + rc->maxaura = (int)(xml_fvalue(node, "maxaura", rc->maxaura) * 100); /* TODO: store as int in XML */ rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura); rc->recruitcost = xml_ivalue(node, "recruitcost", rc->recruitcost); rc->maintenance = xml_ivalue(node, "maintenance", rc->maintenance); @@ -1722,7 +1722,7 @@ static int parse_races(xmlDocPtr doc) rc->ec_flags |= ECF_REC_UNLIMITED; if (xml_bvalue(node, "equipment", false)) - rc->battle_flags |= BF_EQUIPMENT; // TODO: invert this flag, so rc_get_or_create gets simpler + rc->battle_flags |= BF_EQUIPMENT; /* TODO: invert this flag, so rc_get_or_create gets simpler */ if (xml_bvalue(node, "noblock", false)) rc->battle_flags |= BF_NOBLOCK; if (xml_bvalue(node, "invinciblenonmagic", false)) diff --git a/src/keyword.c b/src/keyword.c index 199811669..ba05cbe4b 100644 --- a/src/keyword.c +++ b/src/keyword.c @@ -13,7 +13,7 @@ const char * keyword(keyword_t kwd) { - static char result[32]; // FIXME: static return value + static char result[32]; /* FIXME: static return value */ if (kwd==NOKEYWORD) { return NULL; } diff --git a/src/keyword.h b/src/keyword.h index 1d8f04bb2..19e55e88f 100644 --- a/src/keyword.h +++ b/src/keyword.h @@ -84,7 +84,6 @@ extern "C" bool keyword_disabled(keyword_t kwd); void enable_keyword(keyword_t kwd, bool enabled); const char *keyword(keyword_t kwd); - // #define keyword(kwd) mkname("keyword", keywords[kwd]) #ifdef __cplusplus #endif diff --git a/src/laws.c b/src/laws.c index 98ff5d9f6..e314e2d85 100644 --- a/src/laws.c +++ b/src/laws.c @@ -736,8 +736,8 @@ growing_herbs(region * r, const int current_season, const int last_weeks_season) void immigration(void) { region *r; - log_info(" - Einwanderung..."); int repopulate = config_get_int("rules.economy.repopulate_maximum", 90); + log_info(" - Einwanderung..."); for (r = regions; r; r = r->next) { if (r->land && r->land->newpeasants) { int rp = rpeasants(r) + r->land->newpeasants; @@ -2124,10 +2124,11 @@ int mail_cmd(unit * u, struct order *ord) int banner_cmd(unit * u, struct order *ord) { - init_order(ord); - const char * s = getstrtoken(); + const char * s; free(u->faction->banner); + init_order(ord); + s = getstrtoken(); u->faction->banner = s ? strdup(s) : 0; add_message(&u->faction->msgs, msg_message("changebanner", "value", u->faction->banner)); @@ -2414,12 +2415,12 @@ static void reshow_other(unit * u, struct order *ord, const char *s) { rc = findrace(s, u->faction->locale); if (itype) { - // if this is a potion, we need the right alchemy skill + /* if this is a potion, we need the right alchemy skill */ int i = i_get(u->items, itype); - err = 36; // we do not have this item? + err = 36; /* we do not have this item? */ if (i <= 0) { - // we don't have the item, but it may be a potion that we know + /* we don't have the item, but it may be a potion that we know */ const potion_type *ptype = resource2potion(item2resource(itype)); if (ptype) { if (2 * ptype->level > effskill(u, SK_ALCHEMY, 0)) { @@ -2724,13 +2725,13 @@ void sinkships(struct region * r) if (!sh->type->construction || sh->size >= sh->type->construction->maxsize) { if (fval(r->terrain, SEA_REGION)) { if (!enoughsailors(sh, crew_skill(sh))) { - // ship is at sea, but not enough people to control it + /* ship is at sea, but not enough people to control it */ double dmg = config_get_flt("rules.ship.damage.nocrewocean", 0.3); damage_ship(sh, dmg); } } else if (!ship_owner(sh)) { - // any ship lying around without an owner slowly rots + /* any ship lying around without an owner slowly rots */ double dmg = config_get_flt("rules.ship.damage.nocrew", 0.05); damage_ship(sh, dmg); } @@ -2971,7 +2972,7 @@ static void ageing(void) a_age(&u->attribs, u); if (u == *up) handle_event(u->attribs, "timer", u); - if (u == *up) //-V581 + if (u == *up) /*-V581 */ up = &(*up)->next; } @@ -2981,7 +2982,7 @@ static void ageing(void) a_age(&s->attribs, s); if (s == *sp) handle_event(s->attribs, "timer", s); - if (s == *sp) //-V581 + if (s == *sp) /*-V581 */ sp = &(*sp)->next; } @@ -3109,7 +3110,7 @@ void new_units(void) } u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u); if (name != NULL) - free(name); // TODO: use a buffer on the stack instead? + free(name); /* TODO: use a buffer on the stack instead? */ fset(u2, UFL_ISNEW); a_add(&u2->attribs, a_new(&at_alias))->data.i = alias; @@ -3158,10 +3159,10 @@ void update_long_order(unit * u) free_orders(&u->old_orders); } - // hungry units do not get long orders: + /* hungry units do not get long orders: */ if (hunger) { if (u->old_orders) { - // keep looking for repeated orders that might clear the old_orders + /* keep looking for repeated orders that might clear the old_orders */ continue; } break; @@ -3169,19 +3170,19 @@ void update_long_order(unit * u) if (is_long(kwd)) { if (thiskwd == NOKEYWORD) { - // we have found the (first) long order - // some long orders can have multiple instances: + /* we have found the (first) long order + * some long orders can have multiple instances: */ switch (kwd) { /* Wenn gehandelt wird, darf kein langer Befehl ausgeführt - * werden. Da Handel erst nach anderen langen Befehlen kommt, - * muss das vorher abgefangen werden. Wir merken uns also - * hier, ob die Einheit handelt. */ + * werden. Da Handel erst nach anderen langen Befehlen kommt, + * muss das vorher abgefangen werden. Wir merken uns also + * hier, ob die Einheit handelt. */ case K_BUY: case K_SELL: case K_CAST: - // non-exclusive orders can be used with others. BUY can be paired with SELL, - // CAST with other CAST orders. compatibility is checked once the second - // long order is analyzed (below). + /* non-exclusive orders can be used with others. BUY can be paired with SELL, + * CAST with other CAST orders. compatibility is checked once the second + * long order is analyzed (below). */ exclusive = false; break; @@ -3192,8 +3193,8 @@ void update_long_order(unit * u) thiskwd = kwd; } else { - // we have found a second long order. this is okay for some, but not all commands. - // u->thisorder is already set, and should not have to be updated. + /* we have found a second long order. this is okay for some, but not all commands. + * u->thisorder is already set, and should not have to be updated. */ switch (kwd) { case K_CAST: if (thiskwd != K_CAST) { @@ -3214,9 +3215,8 @@ void update_long_order(unit * u) } break; default: - // TODO: decide https://bugs.eressea.de/view.php?id=2080#c6011 if (kwd > thiskwd) { - // swap out thisorder for the new one + /* swap out thisorder for the new one */ cmistake(u, u->thisorder, 52, MSG_EVENT); set_order(&u->thisorder, copy_order(ord)); } @@ -3229,11 +3229,11 @@ void update_long_order(unit * u) } } if (hunger) { - // Hungernde Einheiten führen NUR den default-Befehl aus + /* Hungernde Einheiten führen NUR den default-Befehl aus */ set_order(&u->thisorder, default_order(u->faction->locale)); } else if (!exclusive) { - // Wenn die Einheit handelt oder zaubert, muss der Default-Befehl gelöscht werden. + /* Wenn die Einheit handelt oder zaubert, muss der Default-Befehl gelöscht werden. */ set_order(&u->thisorder, NULL); } } @@ -3377,7 +3377,7 @@ void defaultorders(void) free_order(ord); if (!neworders) { /* lange Befehle aus orders und old_orders löschen zu gunsten des neuen */ - // TODO: why only is_exclusive, not is_long? what about CAST, BUY, SELL? + /* TODO: why only is_exclusive, not is_long? what about CAST, BUY, SELL? */ remove_exclusive(&u->orders); remove_exclusive(&u->old_orders); neworders = true; @@ -3522,7 +3522,7 @@ int use_cmd(unit * u, struct order *ord) cmistake(u, ord, 50, MSG_PRODUCE); break; default: - // no error + /* no error */ break; } return err; @@ -3534,12 +3534,13 @@ int pay_cmd(unit * u, struct order *ord) cmistake(u, ord, 6, MSG_EVENT); } else { + building *b = NULL; param_t p; int id; + init_order(ord); p = getparam(u->faction->locale); id = getid(); - building *b = NULL; if (p == P_NOT) { unit *owner = building_owner(u->building); /* If the unit is not the owner of the building: error */ diff --git a/src/laws.test.c b/src/laws.test.c index 5eb742809..cca55beb1 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -758,8 +758,9 @@ static void test_peasant_luck_effect(CuTest *tc) { static void test_luck_message(CuTest *tc) { region* r; + attrib *a; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, NULL); rsetpeasants(r, 1); @@ -767,7 +768,7 @@ static void test_luck_message(CuTest *tc) { CuAssertPtrEquals_Msg(tc, "unexpected message", (void *)NULL, r->msgs); - attrib *a = (attrib *)a_find(r->attribs, &at_peasantluck); + a = (attrib *)a_find(r->attribs, &at_peasantluck); if (!a) a = a_add(&r->attribs, a_new(&at_peasantluck)); a->data.i += 10; @@ -782,7 +783,7 @@ static void test_luck_message(CuTest *tc) { static unit * setup_name_cmd(void) { faction *f; - test_cleanup(); + test_setup(); f = test_create_faction(0); return test_create_unit(f, test_create_region(0, 0, 0)); } @@ -886,7 +887,7 @@ static void test_name_ship(CuTest *tc) { } static void test_long_order_normal(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; order *ord; @@ -906,7 +907,7 @@ static void test_long_order_normal(CuTest *tc) { } static void test_long_order_none(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -918,7 +919,7 @@ static void test_long_order_none(CuTest *tc) { } static void test_long_order_cast(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -932,7 +933,7 @@ static void test_long_order_cast(CuTest *tc) { } static void test_long_order_buy_sell(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -947,7 +948,7 @@ static void test_long_order_buy_sell(CuTest *tc) { } static void test_long_order_multi_long(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -961,7 +962,7 @@ static void test_long_order_multi_long(CuTest *tc) { } static void test_long_order_multi_buy(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -975,7 +976,7 @@ static void test_long_order_multi_buy(CuTest *tc) { } static void test_long_order_multi_sell(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -990,7 +991,7 @@ static void test_long_order_multi_sell(CuTest *tc) { } static void test_long_order_buy_cast(CuTest *tc) { - // TODO: write more tests + /* TODO: write more tests */ unit *u; test_cleanup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -1473,7 +1474,7 @@ static void test_demon_hunger(CuTest * tc) } static void test_armedmen(CuTest *tc) { - // TODO: test RCF_NOWEAPONS and SK_WEAPONLESS + /* TODO: test RCF_NOWEAPONS and SK_WEAPONLESS */ unit *u; item_type *it_sword; weapon_type *wtype; diff --git a/src/magic.c b/src/magic.c index 19890ec0e..3cb297c07 100644 --- a/src/magic.c +++ b/src/magic.c @@ -173,7 +173,7 @@ static void a_initicastle(struct attrib *a) a->data.v = calloc(sizeof(icastle_data), 1); } -static void a_finalizeicastle(struct attrib *a) //-V524 +static void a_finalizeicastle(struct attrib *a) /*-V524 */ { free(a->data.v); } @@ -475,14 +475,14 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells spellno = rng_int() % maxspell; sbe = commonspells[spellno]; if (sbe->level > f->max_spelllevel) { - // not going to pick it in this round, move it to the end for later + /* not going to pick it in this round, move it to the end for later */ commonspells[spellno] = commonspells[--maxspell]; commonspells[maxspell] = sbe; sbe = 0; } else { if (f->spellbook && spellbook_get(f->spellbook, sbe->sp)) { - // already have this spell, remove it from the list of candidates + /* already have this spell, remove it from the list of candidates */ commonspells[spellno] = commonspells[--numspells]; if (maxspell > numspells) { maxspell = numspells; @@ -2942,7 +2942,7 @@ const char *spell_info(const spell * sp, const struct locale *lang) return LOC(lang, mkname("spellinfo", sp->sname)); } -// TODO: should take the name, not the spell (spellref optimizations) +/* TODO: should take the name, not the spell (spellref optimizations) */ const char *spell_name(const spell * sp, const struct locale *lang) { return LOC(lang, mkname("spell", sp->sname)); @@ -2984,7 +2984,7 @@ spell *unit_getspell(struct unit *u, const char *name, const struct locale * lan if (sb) { select_spellbook(&tokens, sb, lang); } -#if 0 // TODO: some familiars can cast spells from the mage's spellbook? +#if 0 /* TODO: some familiars can cast spells from the mage's spellbook? */ u = get_familiar_mage(u); if (u) { sb = unit_get_spellbook(u); diff --git a/src/magic.h b/src/magic.h index f62c533bd..d282767a9 100644 --- a/src/magic.h +++ b/src/magic.h @@ -59,7 +59,7 @@ extern "C" { sppobj_t typ; int flag; union { - struct region *r; //TODO: V117 http://www.viva64.com/en/V117 Memsize type is used in the union. + struct region *r; struct unit *u; struct building *b; struct ship *sh; diff --git a/src/magic.test.c b/src/magic.test.c index 07a6d5257..baf8ede50 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -443,7 +443,7 @@ static void test_max_spellpoints(CuTest *tc) { CuAssertIntEquals(tc, 3, max_spellpoints(u->region, u)); set_level(u, SK_MAGIC, 2); CuAssertIntEquals(tc, 9, max_spellpoints(u->region, u)); - // permanent aura loss: + /* permanent aura loss: */ CuAssertIntEquals(tc, 7, change_maxspellpoints(u, -2)); CuAssertIntEquals(tc, 7, max_spellpoints(u->region, u)); test_cleanup(); diff --git a/src/main.c b/src/main.c index 875a33bf9..dd65ec9e1 100644 --- a/src/main.c +++ b/src/main.c @@ -223,11 +223,11 @@ static int parse_args(int argc, char **argv, int *exitcode) } } - // open logfile on disk: + /* open logfile on disk: */ log_flags = verbosity_to_flags(log_flags); log_open(logfile, log_flags); - // also log to stderr: + /* also log to stderr: */ log_stderr = verbosity_to_flags(verbosity); if (log_stderr) { log_to_file(log_stderr | LOG_FLUSH | LOG_BRIEF, stderr); diff --git a/src/monsters.c b/src/monsters.c index 3c9ee1eb8..0d9857024 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -673,7 +673,7 @@ static order *plan_dragon(unit * u) } if (tr != NULL) { assert(long_order == NULL); - // TODO: per-race planning functions? + /* TODO: per-race planning functions? */ if (rc == rc_wyrm) { long_order = make_movement_order(u, tr, 1, allowed_dragon); } diff --git a/src/monsters.test.c b/src/monsters.test.c index e0eaa3ccc..3f2782173 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -90,7 +90,7 @@ static void test_monsters_attack_ocean(CuTest * tc) unit *u, *m; create_monsters(&f, &f2, &u, &m); - r = findregion(-1, 0); // ocean + r = findregion(-1, 0); /* ocean */ u = test_create_unit(u->faction, r); unit_setid(u, 2); m = test_create_unit(m->faction, r); @@ -125,7 +125,7 @@ static void test_seaserpent_piracy(CuTest * tc) race *rc; create_monsters(&f, &f2, &u, &m); - r = findregion(-1, 0); // ocean + r = findregion(-1, 0); /* ocean */ u = test_create_unit(u->faction, r); unit_setid(u, 2); m = test_create_unit(m->faction, r); @@ -198,7 +198,7 @@ static void test_dragon_moves(CuTest * tc) create_monsters(&f, &f2, &u, &m); rsetmoney(findregion(1, 0), 1000); - r = findregion(0, 0); // plain + r = findregion(0, 0); /* plain */ rsetpeasants(r, 0); rsetmoney(r, 0); diff --git a/src/move.c b/src/move.c index f06a0b901..8ad25bc5a 100644 --- a/src/move.c +++ b/src/move.c @@ -509,10 +509,10 @@ static double overload(const region * r, ship * sh) else { int n = 0, p = 0; int mcabins = sh->type->cabins; + double ovl; getshipweight(sh, &n, &p); - - double ovl = n / (double)sh->type->cargo; + ovl = n / (double)sh->type->cargo; if (mcabins) ovl = MAX(ovl, p / (double)mcabins); return ovl; @@ -801,7 +801,7 @@ region * drift_target(ship *sh) { if (rn != NULL && check_ship_allowed(sh, rn) >= 0) { rnext = rn; if (!fval(rnext->terrain, SEA_REGION)) { - // prefer drifting towards non-ocean regions + /* prefer drifting towards non-ocean regions */ break; } } @@ -952,8 +952,8 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) if ((u->faction == reisender->faction) || (ucontact(u, reisender)) || (alliedunit(u, reisender->faction, HELP_GUARD))) guard_count = guard_count - u->number; else if (sk >= stealth) { - guard_count += u->number; double prob_u = (sk - stealth) * skill_prob; + guard_count += u->number; /* amulet counts at most once */ prob_u += MIN(1, MIN(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; if (u->building && (u->building->type == castle_bt) && u == building_owner(u->building)) @@ -1406,7 +1406,7 @@ static int movement_speed(unit * u) return BP_DRAGON; } switch (old_race(u_race(u))) { - case RC_BIRTHDAYDRAGON: // FIXME: catdragon has RCF_DRAGON, so this cannot happen + case RC_BIRTHDAYDRAGON: /* FIXME: catdragon has RCF_DRAGON, so this cannot happen */ case RC_SONGDRAGON: mp = BP_DRAGON; break; @@ -1473,9 +1473,9 @@ static arg_regions *var_copy_regions(const region_list * begin, int size) if (size > 0) { int i = 0; + arg_regions *dst; assert(size > 0); - arg_regions *dst = - (arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * (size_t)size); + dst = (arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * (size_t)size); assert_alloc(dst); dst->nregions = size; dst->regions = (region **)(dst + 1); @@ -1840,7 +1840,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) } } } - } // storms_enabled + } /* storms_enabled */ if (!fval(tthis, SEA_REGION)) { if (!fval(tnext, SEA_REGION)) { /* check that you're not traveling from one land region to another. */ diff --git a/src/move.test.c b/src/move.test.c index 6a2a0e7db..c444fe4a8 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -434,8 +434,9 @@ static void test_follow_ship_msg(CuTest * tc) { order *ord; traveldir *td = NULL; attrib *a; - - test_cleanup(); + void *p; + + test_setup(); test_create_world(); f = test_create_faction(0); r = findregion(0, 0); @@ -467,7 +468,7 @@ static void test_follow_ship_msg(CuTest * tc) { follow_ship(u, ord); CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "error18")); - void *p = msg->parameters[2].v; + p = msg->parameters[2].v; CuAssertPtrNotNull(tc, p); CuAssertIntEquals(tc, K_FOLLOW, getkeyword((order *)p)); diff --git a/src/names.c b/src/names.c index 969e278d8..cf0d9fd09 100644 --- a/src/names.c +++ b/src/names.c @@ -280,7 +280,7 @@ static void dragon_name(unit * u) if (u->number > 1) { const char *no_article = strchr((const char *)str, ' '); assert(no_article); - // TODO: localization + /* TODO: localization */ sprintf(name, "Die %sn von %s", no_article + 1, rname(u->region, default_locale)); } diff --git a/src/piracy.c b/src/piracy.c index b2f96c596..80b1dd47a 100644 --- a/src/piracy.c +++ b/src/piracy.c @@ -149,8 +149,8 @@ void piracy_cmd(unit * u) region *rc = rconnect(r, dir); aff[dir].value = 0; aff[dir].target = 0; - // TODO this could still result in an illegal movement order (through a wall or whatever) - // which will be prevented by move_cmd below + /* TODO this could still result in an illegal movement order (through a wall or whatever) + * which will be prevented by move_cmd below */ if (rc && ((sh && !fval(rc->terrain, FORBIDDEN_REGION) && can_takeoff(sh, r, rc)) || (canswim(u) && fval(rc->terrain, SWIM_INTO) && fval(rc->terrain, SEA_REGION)))) { @@ -161,7 +161,8 @@ void piracy_cmd(unit * u) faction *f = visible_faction(cap->faction, cap); if (alliedunit(u, f, HELP_FIGHT)) continue; - if (!il || intlist_find(il, cap->faction->no)) { // TODO: shouldn't this be f->no? + if (!il || intlist_find(il, cap->faction->no)) { + /* TODO: shouldn't this be f->no? */ ++aff[dir].value; if (rng_int() % aff[dir].value == 0) { aff[dir].target = f; @@ -202,8 +203,8 @@ void piracy_cmd(unit * u) "ship unit region dir", sh, u, r, target_dir)); /* Befehl konstruieren */ - // TODO: why change u->thisorder? - // FIXME: when u->thisorder == ord, set_order calls free, destroys both. + /* TODO: why change u->thisorder? */ + /* FIXME: when u->thisorder == ord, set_order calls free, destroys both. */ ord = create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[target_dir])); /* Bewegung ausführen */ diff --git a/src/piracy.test.c b/src/piracy.test.c index 82e4e55b7..d690776f1 100644 --- a/src/piracy.test.c +++ b/src/piracy.test.c @@ -97,7 +97,7 @@ static void test_piracy_cmd(CuTest * tc) { CuAssertTrue(tc, u->region != r); CuAssertPtrEquals(tc, u2->region, u->region); CuAssertPtrEquals(tc, u2->region, u->ship->region); - CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); // FIXME: this is testing implementation, not interface + CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); /* FIXME: this is testing implementation, not interface */ CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim")); CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail")); @@ -183,14 +183,14 @@ static void test_piracy_cmd_land_to_land(CuTest * tc) { t_plain = get_or_create_terrain("plain"); stype = test_create_shiptype("boat"); - // create a target: + /* create a target: */ r = test_create_region(0, 0, t_plain); f = test_create_faction(0); u = test_create_unit(f, r); u->ship = test_create_ship(r, stype); target = f->no; - // create a pirate: + /* create a pirate: */ r = test_create_region(1, 0, t_plain); f = test_create_faction(0); u = test_create_unit(f, r); diff --git a/src/platform.h b/src/platform.h index 7ddb612ae..6ccbb8d6d 100644 --- a/src/platform.h +++ b/src/platform.h @@ -15,6 +15,11 @@ #pragma warning(disable: 4456) // declaration hides previous #pragma warning(disable: 4457) // declaration hides function parameter #pragma warning(disable: 4459) // declaration hides global +#else /* assume gcc */ +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L +# define va_copy(a,b) __va_copy(a,b) +#endif + #endif #define _POSIX_C_SOURCE 200809L diff --git a/src/prefix.h b/src/prefix.h index aa04e505b..96d07aa02 100644 --- a/src/prefix.h +++ b/src/prefix.h @@ -8,7 +8,7 @@ extern "C" { #endif int add_raceprefix(const char *); - char **race_prefixes; // zero-terminated array of valid prefixes + char **race_prefixes; /* zero-terminated array of valid prefixes */ void free_prefixes(void); #ifdef __cplusplus diff --git a/src/report.c b/src/report.c index 06244c70c..cf00abbc3 100644 --- a/src/report.c +++ b/src/report.c @@ -100,7 +100,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #if defined(_MSC_VER) && _MSC_VER >= 1900 -# pragma warning(disable: 4774) // TODO: remove this +# pragma warning(disable: 4774) /* TODO: remove this */ #endif extern int *storms; @@ -120,7 +120,7 @@ static void check_errno(const char * file, int line) { static char *gamedate_season(const struct locale *lang) { - static char buf[256]; // FIXME: static return value + static char buf[256]; /* FIXME: static return value */ gamedate gd; get_gamedate(turn, &gd); @@ -1195,7 +1195,7 @@ static void describe(struct stream *out, const region * r, faction * f) bufp = buf; size = sizeof(buf) - 1; - // this localization might not work for every language but is fine for de and en + /* this localization might not work for every language but is fine for de and en */ bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_schemes_prefix"), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1237,7 +1237,7 @@ static void describe(struct stream *out, const region * r, faction * f) for (d = 0; d != MAXDIRECTIONS; ++d) { if (!e->exist[d]) continue; - // this localization might not work for every language but is fine for de and en + /* this localization might not work for every language but is fine for de and en */ if (first) bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_borderlist_prefix"), size); else if (e->lastd == d) @@ -1251,8 +1251,8 @@ static void describe(struct stream *out, const region * r, faction * f) WARN_STATIC_BUFFER(); first = false; } - // TODO name is localized? Works for roads anyway... - // TODO: creating messages during reporting makes them not show up in CR? + /* TODO name is localized? Works for roads anyway... */ + /* TODO: creating messages during reporting makes them not show up in CR? */ msg = msg_message("nr_borderlist_postfix", "transparent object", e->transparent, e->name); bytes = (int)nr_render(msg, f->locale, bufp, size, f); @@ -1987,7 +1987,7 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) { } } if (len >= size || data->counter == data->maxtravel) { - // buffer is full + /* buffer is full */ *writep = 0; paragraph(data->out, data->start, 0, 0, 0); data->writep = data->start; @@ -2332,7 +2332,6 @@ report_plaintext(const char *filename, report_context * ctx, /* Nachrichten an REGION in der Region */ if (r->seen.mode == seen_unit || r->seen.mode == seen_travel) { - // TODO: Bug 2073 message_list *mlist = r_getmessages(r, f); if (mlist) { struct mlist **split = merge_messages(mlist, r->msgs); diff --git a/src/reports.c b/src/reports.c index f904f5799..7d8374ff5 100644 --- a/src/reports.c +++ b/src/reports.c @@ -77,7 +77,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" #if defined(_MSC_VER) && _MSC_VER >= 1900 -# pragma warning(disable: 4774) // TODO: remove this +# pragma warning(disable: 4774) /* TODO: remove this */ #endif #define SCALEWEIGHT 100 /* Faktor, um den die Anzeige von Gewichten skaliert wird */ @@ -680,7 +680,7 @@ size_t size) if (wrptr(&bufp, &size, result) != 0) { WARN_STATIC_BUFFER(); } - // TODO: no need to deref the spellref here (spref->name is good) + /* TODO: no need to deref the spellref here (spref->name is good) */ bufp = STRLCPY(bufp, spell_name(sbe->sp, f->locale), size); } } @@ -851,7 +851,7 @@ const struct unit * u, struct skill * sv, int *dh, int days) void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark) { bool firstline; - static char buf[REPORTWIDTH + 1]; // FIXME: static buffer, artificial limit + static char buf[REPORTWIDTH + 1]; /* FIXME: static buffer, artificial limit */ size_t len = strlen(s); assert(width <= REPORTWIDTH); @@ -882,7 +882,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned } memcpy(buf + indent, s, cut - s); buf[indent + (cut - s)] = 0; - addstrlist(SP, buf); // TODO: too much string copying, cut out this function + addstrlist(SP, buf); /* TODO: too much string copying, cut out this function */ while (*cut == ' ') { ++cut; } @@ -1017,7 +1017,7 @@ static void cb_add_address(region *r, unit *ut, void *cbdata) { } static void add_travelthru_addresses(region *r, faction *f, selist **flist, int stealthmod) { - // for each traveling unit: add the faction of any unit is can see + /* for each traveling unit: add the faction of any unit is can see */ address_data cbdata = { 0 }; cbdata.f = f; cbdata.flist = flist; @@ -1338,7 +1338,7 @@ void prepare_report(report_context *ctx, faction *f) if (f->age<=2) { if ((f->flags&FFL_PWMSG)==0) { - // TODO: this assumes unencrypted passwords + /* TODO: this assumes unencrypted passwords */ f->flags |= FFL_PWMSG; ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->_password)); } @@ -1348,7 +1348,7 @@ void prepare_report(report_context *ctx, faction *f) ctx->report_time = time(NULL); ctx->addresses = NULL; ctx->userdata = NULL; - // [first,last) interval of regions with a unit in it: + /* [first,last) interval of regions with a unit in it: */ ctx->first = firstregion(f); ctx->last = lastregion(f); @@ -1388,9 +1388,9 @@ void prepare_report(report_context *ctx, faction *f) travelthru_map(r, cb_add_seen, f); } } - // [fast,last) interval of seen regions (with lighthouses and travel) - // TODO: what about neighbours? when are they included? do we need - // them outside of the CR? + /* [fast,last) interval of seen regions (with lighthouses and travel) + * TODO: what about neighbours? when are they included? do we need + * them outside of the CR? */ ctx->first = firstregion(f); ctx->last = lastregion(f); } @@ -1582,7 +1582,7 @@ static void var_free_resources(variant x) x.v = 0; } -static void var_free_regions(variant x) //-V524 +static void var_free_regions(variant x) /*-V524 */ { free(x.v); } @@ -1630,7 +1630,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size) static char *f_regionid_s(const region * r, const faction * f) { - static char buf[NAMESIZE + 20]; // FIXME: static return value + static char buf[NAMESIZE + 20]; /* FIXME: static return value */ f_regionid(r, f, buf, sizeof(buf)); return buf; @@ -1689,11 +1689,10 @@ static void eval_spell(struct opstack **stack, const void *userdata) const struct spell *sp = (const struct spell *)opop(stack).v; const char *c = sp ? spell_name(sp, f->locale) : LOC(f->locale, "an_unknown_spell"); - assert(c || !"spell without description!"); - size_t len = strlen(c); variant var; - var.v = strcpy(balloc(len + 1), c); + assert(c || !"spell without description!"); + var.v = strcpy(balloc(strlen(c) + 1), c); opush(stack, var); } @@ -1703,11 +1702,10 @@ static void eval_curse(struct opstack **stack, const void *userdata) const struct curse_type *sp = (const struct curse_type *)opop(stack).v; const char *c = sp ? curse_name(sp, f->locale) : LOC(f->locale, "an_unknown_curse"); - assert(c || !"spell effect without description!"); - size_t len = strlen(c); variant var; - var.v = strcpy(balloc(len + 1), c); + assert(c || !"spell effect without description!"); + var.v = strcpy(balloc(strlen(c) + 1), c); opush(stack, var); } @@ -1947,7 +1945,7 @@ static void eval_regions(struct opstack **stack, const void *userdata) const char *get_mailcmd(const struct locale *loc) { - static char result[64]; // FIXME: static return buffer + static char result[64]; /* FIXME: static return buffer */ snprintf(result, sizeof(result), "%s %d %s", game_name_upper(), game_id(), LOC(loc, "mailcmd")); return result; } @@ -2057,12 +2055,12 @@ int stream_printf(struct stream * out, const char *format, ...) { int result; char buffer[4096]; size_t bytes = sizeof(buffer); - // TODO: should be in storage/stream.c (doesn't exist yet) + /* TODO: should be in storage/stream.c (doesn't exist yet) */ va_start(args, format); result = vsnprintf(buffer, bytes, format, args); if (result >= 0 && (size_t)result < bytes) { bytes = (size_t)result; - // TODO: else = buffer too small + /* TODO: else = buffer too small */ } out->api->write(out->handle, buffer, bytes); va_end(args); diff --git a/src/spells.c b/src/spells.c index 66f5325c9..091d3d076 100644 --- a/src/spells.c +++ b/src/spells.c @@ -4194,7 +4194,7 @@ static int sp_seduce(castorder * co) { const resource_type *rsilver = get_resourcetype(R_SILVER); unit *target; - item **itmp, *items = 0;; + item **itmp, *items = 0; unit *mage = co->magician.u; spellparameter *pa = co->par; int cast_level = co->level; diff --git a/src/spells.test.c b/src/spells.test.c index 3c773d489..07a980e03 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -25,8 +25,9 @@ static void test_good_dreams(CuTest *tc) { unit *u1, *u2; int level; castorder co; - - test_cleanup(); + curse *curse; + + test_setup(); test_create_world(); r = findregion(0, 0); f1 = test_create_faction(0); @@ -38,7 +39,7 @@ static void test_good_dreams(CuTest *tc) { level = sp_gooddreams(&co); CuAssertIntEquals(tc, 10, level); - curse *curse = get_curse(r->attribs, ct_find("gbdream")); + curse = get_curse(r->attribs, ct_find("gbdream")); CuAssertTrue(tc, curse && curse->duration > 1); CuAssertTrue(tc, curse->effect == 1); @@ -81,8 +82,9 @@ static void test_bad_dreams(CuTest *tc) { unit *u1, *u2; int level; castorder co; - - test_cleanup(); + curse *curse; + + test_setup(); test_create_world(); r = findregion(0, 0); f1 = test_create_faction(0); @@ -94,7 +96,7 @@ static void test_bad_dreams(CuTest *tc) { level = sp_baddreams(&co); CuAssertIntEquals(tc, 10, level); - curse *curse = get_curse(r->attribs, ct_find("gbdream")); + curse = get_curse(r->attribs, ct_find("gbdream")); CuAssertTrue(tc, curse && curse->duration > 1); CuAssertTrue(tc, curse->effect == -1); diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 939433617..37191d177 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -47,8 +47,9 @@ #define EFFECT_HEALING_SPELL 5 -// Some spells with a fixed, known ID (in XML). -// TODO: this method of identifying spells is error-prone, do not use it for new spells. +/* Some spells with a fixed, known ID (in XML). + * TODO: this method of identifying spells is error-prone, + * do not use it for new spells. */ enum { SPL_FIREBALL = 4, SPL_HAGEL = 5, diff --git a/src/spy.c b/src/spy.c index 0ca3050c2..d4082cad7 100644 --- a/src/spy.c +++ b/src/spy.c @@ -303,9 +303,9 @@ int setstealth_cmd(unit * u, struct order *ord) } if (rule_stealth_other()) { if (get_keyword(s, u->faction->locale) == K_NUMBER) { - s = gettoken(token, sizeof(token)); int nr = -1; + s = gettoken(token, sizeof(token)); if (s) { nr = atoi36(s); } diff --git a/src/spy.test.c b/src/spy.test.c index 34f6e5067..8341b17d3 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -60,6 +60,7 @@ static void set_factionstealth(unit *u, faction *f) { static void test_all_spy_message(CuTest *tc) { spy_fixture fix; + item_type *itype; setup_spy(&fix); @@ -69,7 +70,6 @@ static void test_all_spy_message(CuTest *tc) { create_mage(fix.victim, M_DRAIG); set_factionstealth(fix.victim, fix.spy->faction); - item_type *itype; itype = it_get_or_create(rt_get_or_create("sword")); new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); i_change(&fix.victim->items, itype, 1); diff --git a/src/study.test.c b/src/study.test.c index 7556e817a..3b411c7df 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -303,7 +303,7 @@ static void test_demon_skillchanges(CuTest *tc) { CuAssertPtrNotNull(tc, u); set_level(u, SK_CROSSBOW, 1); demon_skillchange(u); - // TODO: sensing here + /* TODO: sensing here */ test_cleanup(); } diff --git a/src/test_eressea.c b/src/test_eressea.c index 02d52c5ed..4ffe1f19c 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -52,9 +52,12 @@ void RunTests(CuSuite * suite, const char *name) { bool list = false; #define ADD_SUITE(name) \ - CuSuite *get_##name##_suite(void); \ - if (list) printf("%s\n", #name); \ - if (!list || argc>0) add_suite(get_##name##_suite, #name, argc, argv) + do { \ + CuSuite *get_##name##_suite(void); \ + if (list) printf("%s\n", #name); \ + if (!list || argc>0) add_suite(get_##name##_suite, #name, argc, argv); \ + } while (0) + int RunAllTests(int argc, char *argv[]) { diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index 3de537c7b..e8b6a4879 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -92,7 +92,6 @@ static int changefaction_read(trigger * t, gamedata *data) return AT_READ_FAIL; } ur_add(var, &td->faction, resolve_faction); - // read_reference(&td->faction, store, read_faction_reference, resolve_faction); return AT_READ_OK; } diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 41573d86b..1148b1d5a 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -102,7 +102,6 @@ static int createunit_read(trigger * t, gamedata *data) else { result = AT_READ_FAIL; } - // read_reference(&td->f, store, read_faction_reference, resolve_faction); read_reference(&td->r, data, read_region_reference, RESOLVE_REGION(data->version)); diff --git a/src/upkeep.test.c b/src/upkeep.test.c index e84402d4b..2a91a0df1 100644 --- a/src/upkeep.test.c +++ b/src/upkeep.test.c @@ -35,7 +35,7 @@ void test_upkeep_default(CuTest * tc) config_set("rules.food.flags", "0"); i_change(&u1->items, i_silver, 20); get_food(r); - // since u1 and u2 are not allied, u1 should not help u2 with upkeep + /* since u1 and u2 are not allied, u1 should not help u2 with upkeep */ CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); @@ -63,7 +63,7 @@ void test_upkeep_hunger_damage(CuTest * tc) config_set("rules.food.flags", "0"); u1->hp = 100; get_food(r); - // since u1 and u2 are not allied, u1 should not help u2 with upkeep + /* since u1 and u2 are not allied, u1 should not help u2 with upkeep */ CuAssertTrue(tc, u1->hp < 100); test_cleanup(); @@ -152,7 +152,7 @@ void test_upkeep_free(CuTest * tc) u = test_create_unit(test_create_faction(test_create_race("human")), r); assert(r && u); - config_set("rules.food.flags", "4"); // FOOD_IS_FREE + config_set("rules.food.flags", "4"); /* FOOD_IS_FREE */ get_food(r); CuAssertIntEquals(tc, 0, i_get(u->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u, UFL_HUNGER)); diff --git a/src/util/attrib.c b/src/util/attrib.c index a99a70ba3..fda143168 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -153,7 +153,7 @@ static unsigned int __at_hashkey(const char *s) while (i > 0) { key = (s[--i] + key * 37); } - return key & 0x7fffffff; //TODO: V112 http://www.viva64.com/en/V112 Dangerous magic number 0x7fffffff used: return key & 0x7fffffff;. + return key & 0x7fffffff; } void at_register(attrib_type * at) @@ -161,7 +161,7 @@ void at_register(attrib_type * at) attrib_type *find; if (at->read == NULL) { - log_warning("registering non-persistent attribute %s.\n", at->name); //TODO: V111 http://www.viva64.com/en/V111 Call of function 'log_warning' with variable number of arguments. Second argument has memsize type. + log_warning("registering non-persistent attribute %s.\n", at->name); } at->hashkey = __at_hashkey(at->name); find = at_hash[at->hashkey % MAXATHASH]; @@ -169,7 +169,7 @@ void at_register(attrib_type * at) find = find->nexthash; } if (find && find == at) { - log_warning("attribute '%s' was registered more than once\n", at->name); //TODO: V111 http://www.viva64.com/en/V111 Call of function 'log_warning' with variable number of arguments. Second argument has memsize type. + log_warning("attribute '%s' was registered more than once\n", at->name); return; } else { diff --git a/src/util/attrib.h b/src/util/attrib.h index 45dc9b942..601a6f32a 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -32,14 +32,14 @@ extern "C" { typedef struct attrib { const struct attrib_type *type; union { - afun f; //TODO: V117 http://www.viva64.com/en/V117 Memsize type is used in the union. - void *v; //TODO: V117 http://www.viva64.com/en/V117 Memsize type is used in the union. + afun f; + void *v; int i; float flt; char c; short s; short sa[2]; - char ca[4]; //TODO: V112 http://www.viva64.com/en/V112 Dangerous magic number 4 used: char ca[4];. + char ca[4]; } data; /* internal data, do not modify: */ struct attrib *next; /* next attribute in the list */ diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index 4fc56ce4e..0f3d49801 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -13,7 +13,7 @@ int wrptr(char **ptr, size_t * size, int result) { size_t bytes = (size_t)result; if (result < 0) { - // buffer was too small + /* buffer was too small */ if (*size > 0) { **ptr = 0; *size = 0; diff --git a/src/util/bsdstring.test.c b/src/util/bsdstring.test.c index b5fe81156..d4276ef61 100644 --- a/src/util/bsdstring.test.c +++ b/src/util/bsdstring.test.c @@ -32,7 +32,7 @@ static void test_strlcpy(CuTest * tc) CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 4)); CuAssertStrEquals(tc, "her", buffer); - CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 8)); //-V666 + CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 8)); /*-V666 */ CuAssertStrEquals(tc, "herp", buffer); CuAssertIntEquals(tc, 0x7f, buffer[5]); diff --git a/src/util/language.c b/src/util/language.c index 3f628036d..b3cce61af 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -239,7 +239,7 @@ char *mkname_buf(const char *space, const char *name, char *buffer) const char *mkname(const char *space, const char *name) { - static char zBuffer[128]; // FIXME: static return value + static char zBuffer[128]; /* FIXME: static return value */ return mkname_buf(space, name, zBuffer); } @@ -272,7 +272,7 @@ void add_translation(struct critbit_tree **cbp, const char *key, int i) { if (str) { size_t len = strlen(str); if (!cb) { - // TODO: this will leak, because we do not know how to clean it up */ + /* TODO: this will leak, because we do not know how to clean it up */ *cbp = cb = (struct critbit_tree *)calloc(1, sizeof(struct critbit_tree)); } len = cb_new_kv(str, len, &i, sizeof(int), buffer); @@ -292,7 +292,7 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_ assert(maxstrings > 0); tokens = get_translations(lang, ut); for (i = 0; i != maxstrings; ++i) { - // TODO: swap the name of s and key + /* TODO: swap the name of s and key */ const char * s = string_cb(i); if (s) { const char * key = locale_string(lang, s, false); @@ -349,7 +349,7 @@ void free_locales(void) { for (i = UT_PARAMS; i != UT_RACES; ++i) { struct critbit_tree ** cb = (struct critbit_tree **)get_translations(locales, i); if (*cb) { - // TODO: this crashes? + /* TODO: this crashes? */ cb_clear(*cb); free(*cb); } @@ -373,5 +373,5 @@ void free_locales(void) { free(locales); locales = next; } - memset(lstrs, 0, sizeof(lstrs)); // TODO: does this data need to be free'd? + memset(lstrs, 0, sizeof(lstrs)); /* TODO: does this data need to be free'd? */ } diff --git a/src/util/log.c b/src/util/log.c index 759efba39..24ddce757 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -137,7 +137,7 @@ static int check_dupe(const char *format, int level) static char last_message[32]; /* STATIC_XCALL: used across calls */ static int dupes = 0; /* STATIC_XCALL: used across calls */ if (strncmp(last_message, format, sizeof(last_message)) == 0) { - // TODO: C6054: String 'last_message' might not be zero - terminated. + /* TODO: C6054: String 'last_message' might not be zero - terminated. */ ++dupes; return 1; } @@ -197,16 +197,16 @@ static void log_write(int flags, const char *module, const char *format, va_list int level = flags & LOG_LEVELS; if (lg->flags & level) { int dupe = 0; - va_list copy; - - va_copy(copy, args); if (lg->flags & LOG_BRIEF) { dupe = check_dupe(format, level); } if (dupe == 0) { + va_list copy; + + va_copy(copy, args); lg->log(lg->data, level, NULL, format, copy); + va_end(copy); } - va_end(copy); } } } @@ -220,7 +220,7 @@ void log_fatal(const char *format, ...) va_end(args); } -void log_error(const char *format, ...) //-V524 +void log_error(const char *format, ...) /*-V524 */ { va_list args; va_start(args, format); diff --git a/src/util/parser.test.c b/src/util/parser.test.c index c7ac0bb05..942aa1866 100644 --- a/src/util/parser.test.c +++ b/src/util/parser.test.c @@ -49,11 +49,11 @@ static void test_parse_token_limit_utf8(CuTest *tc) { tok = parse_token(&str, lbuf, sizeof(lbuf)); CuAssertPtrEquals(tc, (void *)(orig + strlen(orig)), (void *)str); - CuAssertStrEquals(tc, tok, "\xc3\xa4\xc3\xb6\xc3\xbc"); // just three letters fit, 6 bytes long + CuAssertStrEquals(tc, tok, "\xc3\xa4\xc3\xb6\xc3\xbc"); /* just three letters fit, 6 bytes long */ tok = parse_token(&str, lbuf, sizeof(lbuf)); CuAssertPtrEquals(tc, NULL, (void *)tok); - str = orig; // now with an extra byte in the front, maxing out lbuf exactly + str = orig; /* now with an extra byte in the front, maxing out lbuf exactly */ tok = parse_token(&str, lbuf, sizeof(lbuf)); CuAssertPtrEquals(tc, (void *)(orig + strlen(orig)), (void *)str); CuAssertStrEquals(tc, tok, "a\xc3\xa4\xc3\xb6\xc3\xbc"); diff --git a/src/util/password.h b/src/util/password.h index b83d544a6..ba55f6cb9 100644 --- a/src/util/password.h +++ b/src/util/password.h @@ -4,9 +4,9 @@ #define PASSWORD_PLAINTEXT 0 #define PASSWORD_DEFAULT PASSWORD_PLAINTEXT -#define VERIFY_OK 0 // password matches hash -#define VERIFY_FAIL 1 // password is wrong -#define VERIFY_UNKNOWN 2 // hashing algorithm not supported +#define VERIFY_OK 0 +#define VERIFY_FAIL 1 +#define VERIFY_UNKNOWN 2 int password_verify(const char *hash, const char *passwd); const char * password_encode(const char *passwd, int algo); bool password_is_implemented(int algo); diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 6be0bdde5..d29cb78ac 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -168,7 +168,7 @@ void addtoken(tnode ** root, const char *str, variant id) next = next->nexthash; if (!next) { tref *ref; - tnode *node = mknode(); // TODO: what is the reason for this empty node to exist? + tnode *node = mknode(); /* TODO: what is the reason for this empty node to exist? */ if (ucs < 'a' || ucs > 'z') { lcs = towlower((wint_t)ucs); diff --git a/src/util/unicode.test.c b/src/util/unicode.test.c index 76cda9a8f..7c1c1031a 100644 --- a/src/util/unicode.test.c +++ b/src/util/unicode.test.c @@ -47,7 +47,7 @@ static void test_unicode_tolower(CuTest * tc) static void test_unicode_utf8_to_other(CuTest *tc) { - const unsigned char uchar_str[] = { 0xc3, 0x98, 0xc5, 0xb8, 0xc2, 0x9d, 'l', 0 }; // ØŸl + const unsigned char uchar_str[] = { 0xc3, 0x98, 0xc5, 0xb8, 0xc2, 0x9d, 'l', 0 }; /* ØŸl */ utf8_t *utf8_str = (utf8_t *)uchar_str; unsigned char ch; size_t sz; @@ -111,7 +111,7 @@ static void test_unicode_bug2262(CuTest *tc) { CuAssertIntEquals(tc, 'u', ucs); CuAssertIntEquals(tc, 0, unicode_utf8_trim(name)); - name[0] = -4; // latin1: ü should fail to decode + name[0] = -4; /* latin1: ü should fail to decode */ CuAssertIntEquals(tc, EILSEQ, unicode_utf8_to_ucs4(&ucs, name, &sz)); CuAssertIntEquals(tc, EILSEQ, unicode_utf8_trim(name)); } diff --git a/src/util/variant.h b/src/util/variant.h index 4559264ed..b65ee0868 100644 --- a/src/util/variant.h +++ b/src/util/variant.h @@ -5,12 +5,12 @@ extern "C" { #endif typedef union variant { - void *v; //TODO: V117 http://www.viva64.com/en/V117 Memsize type is used in the union. + void *v; int i; char c; short s; short sa[2]; - char ca[4]; //TODO: V112 http://www.viva64.com/en/V112 Dangerous magic number 4 used: char ca[4];. + char ca[4]; float f; } variant; diff --git a/src/volcano.c b/src/volcano.c index 89a865017..fb4cfa74c 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -291,10 +291,10 @@ void volcano_update(void) r->terrain = t_volcano; } else if (r->uid == 1246051340 || outbreak_chance()) { - // HACK: a fixed E4-only region-uid in Code. - // FIXME: In E4 gibt es eine Ebene #1246051340, die Smalland heisst. - // da das kein aktiver Vulkan ist, ist dieser Test da nicht idiotisch? - // das sollte bestimmt rn betreffen? + /* HACK: a fixed E4-only region-uid in Code. + * FIXME: In E4 gibt es eine Ebene #1246051340, die Smalland heisst. + * da das kein aktiver Vulkan ist, ist dieser Test da nicht idiotisch? + * das sollte bestimmt rn betreffen? */ region *rn; rn = rrandneighbour(r); volcano_outbreak(r, rn); From 12b1dcaa38e4349335a759a9309d01a1a298e910 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 21:23:24 +0100 Subject: [PATCH 234/271] remove platform-cruft --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fc1e62a7..ae5923313 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,6 @@ IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -ansi -pedantic") - add_definitions(-DHAVE__BOOL) ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP") set(CMAKE_EXE_LINKER_FLAGS_DEBUG From 9e14bf5cf9993594eb4efb76b3bc29f554cc72de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Feb 2017 21:26:38 +0100 Subject: [PATCH 235/271] clang complains about -ansi? --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae5923313..43f109fed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,7 @@ ENDIF() IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -ansi -pedantic") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89") ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP") set(CMAKE_EXE_LINKER_FLAGS_DEBUG From be14394529305cfeeab26e6b06f1621094cedff4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Feb 2017 16:33:24 +0100 Subject: [PATCH 236/271] load locales and rules separately (xml prep work) --- conf/e2/locales.xml | 1 + conf/e2/{config.xml => rules.xml} | 13 ------------- conf/e3/locales.xml | 13 +++++++++++++ conf/e3/{config.xml => rules.xml} | 5 ----- scripts/eressea/xmlconf.lua | 3 ++- 5 files changed, 16 insertions(+), 19 deletions(-) rename conf/e2/{config.xml => rules.xml} (75%) create mode 100644 conf/e3/locales.xml rename conf/e3/{config.xml => rules.xml} (84%) diff --git a/conf/e2/locales.xml b/conf/e2/locales.xml index f71525343..7a31bbc17 100644 --- a/conf/e2/locales.xml +++ b/conf/e2/locales.xml @@ -3,6 +3,7 @@ + diff --git a/conf/e2/config.xml b/conf/e2/rules.xml similarity index 75% rename from conf/e2/config.xml rename to conf/e2/rules.xml index 56c622d04..8d0b01b27 100644 --- a/conf/e2/config.xml +++ b/conf/e2/rules.xml @@ -1,11 +1,5 @@ - - - - - - @@ -26,7 +20,6 @@ - @@ -46,10 +39,4 @@ - - - - - - diff --git a/conf/e3/locales.xml b/conf/e3/locales.xml new file mode 100644 index 000000000..2d94bf202 --- /dev/null +++ b/conf/e3/locales.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/conf/e3/config.xml b/conf/e3/rules.xml similarity index 84% rename from conf/e3/config.xml rename to conf/e3/rules.xml index ac05d5a5a..421b54d7a 100644 --- a/conf/e3/config.xml +++ b/conf/e3/rules.xml @@ -1,8 +1,5 @@ - - - @@ -15,8 +12,6 @@ - - diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 584f8d3e2..84f29eceb 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -4,7 +4,8 @@ if config.install then end if config.rules then local rules = config.rules .. '/' - assert(0 == read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data") + assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") + assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") end eressea.game.reset() From ba1fdcce599110bb95c74b0b3753cbb991cbae91 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 07:47:36 +0100 Subject: [PATCH 237/271] remove race.describe funpointer --- res/e3a/races.xml | 1 - res/eressea/races.xml | 1 - src/kernel/race.c | 4 ---- src/kernel/race.h | 3 --- src/kernel/save.c | 11 ----------- src/kernel/unit.c | 11 +++++++++-- src/kernel/unit.test.c | 14 ++++++++++++-- src/kernel/xmlreader.c | 3 --- src/names.c | 28 ++++++++++------------------ src/names.test.c | 1 - 10 files changed, 31 insertions(+), 46 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index ccc118877..acc002b1a 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -615,7 +615,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 3cf5136a4..9f3624d70 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -602,7 +602,6 @@ regaura="1.000000" weight="100" capacity="540" speed="1.000000" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes"> - diff --git a/src/kernel/race.c b/src/kernel/race.c index 2ede414c7..1385bd932 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -542,10 +542,6 @@ variant read_race_reference(struct storage *store) return result; } -void register_race_description_function(race_desc_func func, const char *name) { - register_function((pf_generic)func, name); -} - void register_race_name_function(race_name_func func, const char *name) { register_function((pf_generic)func, name); } diff --git a/src/kernel/race.h b/src/kernel/race.h index ceb5e59d9..80f2622f3 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -112,7 +112,6 @@ extern "C" { int level; } att; - typedef const char *(*race_desc_func)(const struct race *rc, const struct locale *lang); typedef void (*race_name_func)(struct unit *); typedef struct race { @@ -145,7 +144,6 @@ extern "C" { signed char bonus[MAXSKILLS]; race_name_func generate_name; - race_desc_func describe; void(*age) (struct unit * u); bool(*move_allowed) (const struct region *, const struct region *); struct item *(*itemdrop) (const struct race *, int size); @@ -267,7 +265,6 @@ extern "C" { const char *raceprefix(const struct unit *u); void register_race_name_function(race_name_func, const char *); - void register_race_description_function(race_desc_func, const char *); #ifdef __cplusplus } diff --git a/src/kernel/save.c b/src/kernel/save.c index 3ddaf7a7c..d4045d05f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -695,17 +695,6 @@ unit *read_unit(struct gamedata *data) else u->irace = NULL; - if (rc->describe) { - const char *rcdisp = rc->describe(rc, u->faction->locale); - if (u->display && rcdisp) { - /* see if the data file contains old descriptions */ - if (strcmp(rcdisp, u->display) == 0) { - free(u->display); - u->display = NULL; - } - } - } - READ_INT(data->store, &n); if (n > 0) { building * b = findbuilding(n); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 1acebac6d..ab1669ed9 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -531,8 +531,15 @@ const char *u_description(const unit * u, const struct locale *lang) if (u->display && u->display[0]) { return u->display; } - else if (u_race(u)->describe) { - return u_race(u)->describe(u->_race, lang); + else { + char zText[64]; + const char * d; + const race * rc = u_race(u); + snprintf(zText, sizeof(zText), "describe_%s", rc->_name); + d = locale_getstring(lang, zText); + if (d) { + return d; + } } return NULL; } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 16ff2890b..c187f7bab 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -390,14 +390,24 @@ static void test_limited_skills(CuTest *tc) { static void test_unit_description(CuTest *tc) { race *rc; unit *u; + struct locale *lang; + test_setup(); + lang = test_create_locale(); rc = test_create_race("hodor"); u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0)); + CuAssertPtrEquals(tc, 0, u->display); - CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale)); + CuAssertStrEquals(tc, 0, u_description(u, lang)); u->display = strdup("Hodor"); CuAssertStrEquals(tc, "Hodor", u_description(u, NULL)); - CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale)); + CuAssertStrEquals(tc, "Hodor", u_description(u, lang)); + + free(u->display); + u->display = NULL; + locale_setstring(lang, "describe_hodor", "HODOR"); + CuAssertStrEquals(tc, "HODOR", u_description(u, lang)); + test_cleanup(); } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2cf0b42e8..44a8c161e 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1795,9 +1795,6 @@ static int parse_races(xmlDocPtr doc) if (strcmp((const char *)propValue, "name") == 0) { rc->generate_name = (race_name_func)fun; } - else if (strcmp((const char *)propValue, "describe") == 0) { - rc->describe = (race_desc_func)fun; - } else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } diff --git a/src/names.c b/src/names.c index cf0d9fd09..780386deb 100644 --- a/src/names.c +++ b/src/names.c @@ -45,13 +45,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -static const char *describe_race(const race * rc, const struct locale *lang) -{ - char zText[32]; - sprintf(zText, "describe_%s", rc->_name); - return locale_getstring(lang, zText); -} - static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix) { char zText[32]; @@ -395,29 +388,29 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) int result; UNUSED_ARG(buflen); - /* Prüfen, ob Kurz genug */ + /* Pr�fen, ob Kurz genug */ if (strlen(s) <= maxchars) { return s; } - /* Anzahl der Wörter feststellen */ + /* Anzahl der W�rter feststellen */ while (*p != 0) { result = unicode_utf8_to_ucs4(&ucs, p, &size); assert(result == 0 || "damnit, we're not handling invalid input here!"); - /* Leerzeichen überspringen */ + /* Leerzeichen �berspringen */ while (*p != 0 && !iswalnum((wint_t)ucs)) { p += size; result = unicode_utf8_to_ucs4(&ucs, p, &size); assert(result == 0 || "damnit, we're not handling invalid input here!"); } - /* Counter erhöhen */ + /* Counter erh�hen */ if (*p != 0) ++c; - /* alnums überspringen */ + /* alnums �berspringen */ while (*p != 0 && iswalnum((wint_t)ucs)) { p += size; result = unicode_utf8_to_ucs4(&ucs, p, &size); @@ -425,10 +418,10 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) } } - /* Buchstaben pro Teilkürzel = MAX(1,max/AnzWort) */ + /* Buchstaben pro Teilk�rzel = MAX(1,max/AnzWort) */ bpt = (c > 0) ? MAX(1, maxchars / c) : 1; - /* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */ + /* Einzelne W�rter anspringen und jeweils die ersten BpT kopieren */ p = s; c = 0; @@ -438,7 +431,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) assert(result == 0 || "damnit, we're not handling invalid input here!"); while (*p != 0 && c < maxchars) { - /* Leerzeichen überspringen */ + /* Leerzeichen �berspringen */ while (*p != 0 && !iswalnum((wint_t)ucs)) { p += size; @@ -446,7 +439,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) assert(result == 0 || "damnit, we're not handling invalid input here!"); } - /* alnums übertragen */ + /* alnums �bertragen */ for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) { memcpy(bufp, p, size); @@ -458,7 +451,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) assert(result == 0 || "damnit, we're not handling invalid input here!"); } - /* Bis zum nächsten Leerzeichen */ + /* Bis zum n�chsten Leerzeichen */ while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) { p += size; @@ -474,7 +467,6 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) void register_names(void) { - register_race_description_function(describe_race, "describe_race"); /* function name * generate a name for a nonplayerunit * race->generate_name() */ diff --git a/src/names.test.c b/src/names.test.c index 8109fc2d4..01fe0ff41 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -32,7 +32,6 @@ static void test_names(CuTest * tc) CuAssertPtrNotNull(tc, get_function("namedragon")); CuAssertPtrNotNull(tc, get_function("namedracoid")); CuAssertPtrNotNull(tc, get_function("namegeneric")); - CuAssertPtrNotNull(tc, get_function("describe_race")); test_cleanup(); } From 59f87edbb1ca38e6b078a70d13ef2ea53cd907f2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:00:48 +0100 Subject: [PATCH 238/271] remove unused race.move_allowed method --- res/e3a/races.xml | 1 - res/eressea/races.xml | 5 ----- res/races/dragon.xml | 1 - res/races/wyrm.xml | 1 - res/races/youngdragon.xml | 1 - src/kernel/race.h | 1 - src/kernel/xmlreader.c | 4 ---- src/races/races.c | 4 +--- 8 files changed, 1 insertion(+), 17 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index acc002b1a..1036ba223 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -875,7 +875,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 9f3624d70..6899a8070 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -732,7 +732,6 @@ - @@ -745,7 +744,6 @@ - @@ -758,7 +756,6 @@ - @@ -1141,7 +1138,6 @@ - @@ -1273,7 +1269,6 @@ - diff --git a/res/races/dragon.xml b/res/races/dragon.xml index f8022d0a4..7a36e4b84 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -6,7 +6,6 @@ dragon="yes"> - diff --git a/res/races/wyrm.xml b/res/races/wyrm.xml index 3ee48ca67..dab1a9e1f 100644 --- a/res/races/wyrm.xml +++ b/res/races/wyrm.xml @@ -5,7 +5,6 @@ defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes" income="5000"> - diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index d5b23b601..0ac2d35be 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -6,7 +6,6 @@ teach="no" getitem="yes" resistbash="yes" dragon="yes" income="150"> - diff --git a/src/kernel/race.h b/src/kernel/race.h index 80f2622f3..32ff05ebd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -145,7 +145,6 @@ extern "C" { race_name_func generate_name; void(*age) (struct unit * u); - bool(*move_allowed) (const struct region *, const struct region *); struct item *(*itemdrop) (const struct race *, int size); void(*init_familiar) (struct unit *); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 44a8c161e..508516671 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1798,10 +1798,6 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } - else if (strcmp((const char *)propValue, "move") == 0) { - rc->move_allowed = - (bool(*)(const struct region *, const struct region *))fun; - } else if (strcmp((const char *)propValue, "itemdrop") == 0) { rc->itemdrop = (struct item * (*)(const struct race *, int))fun; } diff --git a/src/races/races.c b/src/races/races.c index 8af9cf2ed..bb699520e 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -88,15 +88,13 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) } } -/* Die Funktionen werden über den hier registrierten Namen in races.xml +/* Die Funktionen werden �ber den hier registrierten Namen in races.xml * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { /* function initfamiliar */ register_function((pf_generic)oldfamiliars, "oldfamiliars"); - register_function((pf_generic)allowed_dragon, "movedragon"); - register_function((pf_generic)allowed_swim, "moveswimming"); register_function((pf_generic)allowed_fly, "moveflying"); register_function((pf_generic)allowed_walk, "movewalking"); From 04154628e6ed8dd91b3c2bc5c7d07e7da1184c43 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:18:04 +0100 Subject: [PATCH 239/271] remove funpointer for spoils --- res/e3a/races.xml | 7 ------- res/eressea/races.xml | 11 ----------- res/races/aquarian.xml | 1 - res/races/cat.xml | 1 - res/races/demon.xml | 1 - res/races/dwarf.xml | 3 +-- res/races/elf.xml | 3 +-- res/races/goblin-2.xml | 1 - res/races/goblin-3.xml | 1 - res/races/goblin.xml | 1 - res/races/halfling.xml | 3 +-- res/races/human.xml | 1 - res/races/insect.xml | 3 +-- res/races/troll.xml | 1 - src/battle.c | 12 +++++------- src/kernel/item.c | 3 +-- src/kernel/item.h | 1 + src/kernel/race.h | 1 - src/kernel/xmlreader.c | 3 --- 19 files changed, 11 insertions(+), 47 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 1036ba223..e2cc60e55 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -34,7 +34,6 @@ - @@ -48,7 +47,6 @@ - @@ -76,7 +74,6 @@ - @@ -103,7 +100,6 @@ - @@ -123,7 +119,6 @@ - @@ -142,7 +137,6 @@ - @@ -165,7 +159,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 6899a8070..70dd1af9f 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -12,7 +12,6 @@ - @@ -780,7 +779,6 @@ - @@ -799,7 +797,6 @@ - @@ -825,7 +822,6 @@ - @@ -858,7 +854,6 @@ - @@ -888,7 +883,6 @@ - @@ -919,7 +913,6 @@ - @@ -951,7 +944,6 @@ - @@ -1149,7 +1141,6 @@ - @@ -1179,7 +1170,6 @@ - @@ -1206,7 +1196,6 @@ - diff --git a/res/races/aquarian.xml b/res/races/aquarian.xml index a0e1189b7..19fd3aee7 100644 --- a/res/races/aquarian.xml +++ b/res/races/aquarian.xml @@ -1,7 +1,6 @@ - diff --git a/res/races/cat.xml b/res/races/cat.xml index 75bc8019a..5986c223c 100644 --- a/res/races/cat.xml +++ b/res/races/cat.xml @@ -1,7 +1,6 @@ - diff --git a/res/races/demon.xml b/res/races/demon.xml index 0ce4c86ff..69d98145f 100644 --- a/res/races/demon.xml +++ b/res/races/demon.xml @@ -6,7 +6,6 @@ unarmedattack="-2" unarmeddefense="-2" playerrace="yes" walk="yes" shapeshift="yes" giveperson="yes" giveunit="yes" getitem="yes" recruitethereal="yes" equipment="yes" healing="1.5"> - diff --git a/res/races/dwarf.xml b/res/races/dwarf.xml index c5c4f2fcf..043b76aa7 100644 --- a/res/races/dwarf.xml +++ b/res/races/dwarf.xml @@ -1,7 +1,6 @@ - @@ -30,4 +29,4 @@ - \ No newline at end of file + diff --git a/res/races/elf.xml b/res/races/elf.xml index ee1278a26..683ee823b 100644 --- a/res/races/elf.xml +++ b/res/races/elf.xml @@ -1,7 +1,6 @@ - @@ -26,4 +25,4 @@ - \ No newline at end of file + diff --git a/res/races/goblin-2.xml b/res/races/goblin-2.xml index f8964d7c0..f26fa780e 100644 --- a/res/races/goblin-2.xml +++ b/res/races/goblin-2.xml @@ -5,7 +5,6 @@ speed="1.0" hp="16" damage="1d5" unarmedattack="-2" unarmeddefense="0" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/goblin-3.xml b/res/races/goblin-3.xml index 4ad83967d..3fd594939 100644 --- a/res/races/goblin-3.xml +++ b/res/races/goblin-3.xml @@ -5,7 +5,6 @@ speed="1.0" hp="16" damage="1d5" unarmedattack="-2" unarmeddefense="0" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/goblin.xml b/res/races/goblin.xml index 101cdaa86..a05d127e3 100644 --- a/res/races/goblin.xml +++ b/res/races/goblin.xml @@ -6,7 +6,6 @@ unarmedattack="-2" unarmeddefense="0" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/halfling.xml b/res/races/halfling.xml index 4801685a0..3628d2b35 100644 --- a/res/races/halfling.xml +++ b/res/races/halfling.xml @@ -1,8 +1,7 @@ - - + diff --git a/res/races/human.xml b/res/races/human.xml index 8f1ad5cb4..f91ba7daf 100644 --- a/res/races/human.xml +++ b/res/races/human.xml @@ -1,7 +1,6 @@ - diff --git a/res/races/insect.xml b/res/races/insect.xml index dc9faa06d..75e16f7af 100644 --- a/res/races/insect.xml +++ b/res/races/insect.xml @@ -1,7 +1,6 @@ - @@ -27,4 +26,4 @@ - \ No newline at end of file + diff --git a/res/races/troll.xml b/res/races/troll.xml index c70020fa2..9168a6d0e 100644 --- a/res/races/troll.xml +++ b/res/races/troll.xml @@ -6,7 +6,6 @@ unarmedattack="-2" unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="1.5"> - diff --git a/src/battle.c b/src/battle.c index 9ce22918a..0ff8eecaa 100644 --- a/src/battle.c +++ b/src/battle.c @@ -925,14 +925,12 @@ void kill_troop(troop dt) if (!df->alive) { char eqname[64]; const struct equipment *eq; - if (u_race(du)->itemdrop) { - item *drops = u_race(du)->itemdrop(u_race(du), du->number - df->run.number); - - if (drops != NULL) { - i_merge(&du->items, &drops); - } + const race *rc = u_race(du); + item *drops = item_spoil(rc, du->number - df->run.number); + if (drops != NULL) { + i_merge(&du->items, &drops); } - sprintf(eqname, "%s_spoils", u_race(du)->_name); + sprintf(eqname, "%s_spoils", rc->_name); eq = get_equipment(eqname); if (eq != NULL) { equip_items(&du->items, eq); diff --git a/src/kernel/item.c b/src/kernel/item.c index 177e44831..c37e3d40c 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1175,7 +1175,7 @@ attrib_type at_resourcelimit = { finalize_resourcelimit, }; -static item *default_spoil(const struct race *rc, int size) +item *item_spoil(const struct race *rc, int size) { item *itm = NULL; @@ -1303,7 +1303,6 @@ void register_resources(void) register_function((pf_generic)res_changepermaura, "changepermaura"); register_function((pf_generic)res_changehp, "changehp"); register_function((pf_generic)res_changeaura, "changeaura"); - register_function((pf_generic)default_spoil, "defaultdrops"); register_item_use(use_potion, "usepotion"); register_item_use(use_potion_delayed, "usepotion_delayed"); diff --git a/src/kernel/item.h b/src/kernel/item.h index e6301c314..79e6f103d 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -309,6 +309,7 @@ extern "C" { extern const struct potion_type *oldpotiontype[]; const struct resource_type *get_resourcetype(resource_t rt); + struct item *item_spoil(const struct race *rc, int size); int get_item(const struct unit * u, const struct item_type *itype); int set_item(struct unit * u, const struct item_type *itype, int value); diff --git a/src/kernel/race.h b/src/kernel/race.h index 32ff05ebd..380b843bd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -145,7 +145,6 @@ extern "C" { race_name_func generate_name; void(*age) (struct unit * u); - struct item *(*itemdrop) (const struct race *, int size); void(*init_familiar) (struct unit *); struct rcoption *options; /* rarely used properties */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 508516671..97fab3b8d 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1798,9 +1798,6 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } - else if (strcmp((const char *)propValue, "itemdrop") == 0) { - rc->itemdrop = (struct item * (*)(const struct race *, int))fun; - } else if (strcmp((const char *)propValue, "initfamiliar") == 0) { rc->init_familiar = (void(*)(struct unit *))fun; } From 5ba3d76efb6e69c82c0e9dfcd2ef22bb02e3c999 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:32:03 +0100 Subject: [PATCH 240/271] remove race.init_familiar funpointer --- res/e3a/races.xml | 19 ------------------- res/eressea/races.xml | 21 --------------------- src/kernel/race.c | 2 +- src/kernel/race.h | 2 +- src/kernel/xmlreader.c | 4 +--- src/spells.c | 15 ++++++++++----- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index e2cc60e55..e81d31b92 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -10,7 +10,6 @@ - @@ -183,7 +182,6 @@ - @@ -210,7 +208,6 @@ - @@ -232,7 +229,6 @@ - @@ -254,7 +250,6 @@ - @@ -278,7 +273,6 @@ - @@ -302,7 +296,6 @@ - @@ -325,7 +318,6 @@ - @@ -352,7 +344,6 @@ - @@ -375,7 +366,6 @@ - @@ -400,7 +390,6 @@ - @@ -427,7 +416,6 @@ - @@ -451,7 +439,6 @@ - @@ -475,7 +462,6 @@ - @@ -498,7 +484,6 @@ - @@ -526,7 +511,6 @@ - @@ -550,7 +534,6 @@ - @@ -573,7 +556,6 @@ - @@ -597,7 +579,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 70dd1af9f..470a33a3f 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -28,7 +28,6 @@ - @@ -62,7 +61,6 @@ - @@ -91,7 +89,6 @@ - @@ -119,7 +116,6 @@ - @@ -149,7 +145,6 @@ - @@ -179,7 +174,6 @@ - @@ -210,7 +204,6 @@ - @@ -245,7 +238,6 @@ - @@ -276,7 +268,6 @@ - @@ -309,7 +300,6 @@ - @@ -341,7 +331,6 @@ - @@ -371,7 +360,6 @@ - @@ -402,7 +390,6 @@ - @@ -432,7 +419,6 @@ - @@ -464,7 +450,6 @@ - @@ -496,7 +481,6 @@ - @@ -526,7 +510,6 @@ - @@ -559,7 +542,6 @@ - @@ -589,7 +571,6 @@ - @@ -882,7 +863,6 @@ - @@ -943,7 +923,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index 1385bd932..e3983bffe 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -226,7 +226,7 @@ race_list *get_familiarraces(void) if (!init) { race *rc = races; for (; rc != NULL; rc = rc->next) { - if (rc->init_familiar != NULL) { + if (rc->flags & RCF_FAMILIAR) { racelist_insert(&familiarraces, rc); } } diff --git a/src/kernel/race.h b/src/kernel/race.h index 380b843bd..1322d3aad 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -145,7 +145,6 @@ extern "C" { race_name_func generate_name; void(*age) (struct unit * u); - void(*init_familiar) (struct unit *); struct rcoption *options; /* rarely used properties */ @@ -226,6 +225,7 @@ extern "C" { #define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ #define RCF_ATTACK_MOVED (1<<29) /* may attack if it has moved */ #define RCF_MIGRANTS (1<<30) /* may have migrant units (human bonus) */ +#define RCF_FAMILIAR (1<<31) /* may be a familiar */ /* Economic flags */ #define ECF_KEEP_ITEM (1<<1) /* gibt Gegenst�nde weg */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 97fab3b8d..2ba8e2b75 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1798,9 +1798,6 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } - else if (strcmp((const char *)propValue, "initfamiliar") == 0) { - rc->init_familiar = (void(*)(struct unit *))fun; - } else { log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name); } @@ -1822,6 +1819,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "race"); assert(propValue != NULL); frc = rc_get_or_create((const char *)propValue); + frc->flags |= RCF_FAMILIAR; if (xml_bvalue(node, "default", false)) { rc->familiars[k] = rc->familiars[0]; rc->familiars[0] = frc; diff --git a/src/spells.c b/src/spells.c index 091d3d076..95b26434f 100644 --- a/src/spells.c +++ b/src/spells.c @@ -34,10 +34,10 @@ #include /* kernel includes */ -#include -#include #include #include +#include +#include #include #include #include @@ -514,11 +514,16 @@ static const race *select_familiar(const race * magerace, magic_t magiegebiet) static void make_familiar(unit * familiar, unit * mage) { /* skills and spells: */ - if (u_race(familiar)->init_familiar != NULL) { - u_race(familiar)->init_familiar(familiar); + const struct equipment *eq; + char eqname[64]; + const race * rc = u_race(familiar); + snprintf(eqname, sizeof(eqname), "%s_familiar", rc->_name); + eq = get_equipment(eqname); + if (eq != NULL) { + equip_items(&familiar->items, eq); } else { - log_error("could not perform initialization for familiar %s.\n", familiar->faction->race->_name); + log_error("could not perform initialization for familiar %s.\n", rc->_name); } /* triggers: */ From 4bd295e3b283c6dae43ca593ecf8af8fd4e7f1d6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 20:42:31 +0100 Subject: [PATCH 241/271] remove the nearly unused illusion race --- res/core/messages.xml | 14 -------------- res/e3a/races.xml | 7 ------- res/eressea/races.xml | 6 ------ src/kernel/race.c | 15 +++++++++++---- src/kernel/race.h | 4 ++-- src/races/CMakeLists.txt | 1 - src/races/illusion.c | 38 -------------------------------------- src/races/races.c | 2 -- src/reports.c | 5 ++--- 9 files changed, 15 insertions(+), 77 deletions(-) delete mode 100644 src/races/illusion.c diff --git a/res/core/messages.xml b/res/core/messages.xml index 3fae49eb3..e312fcc7c 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3266,20 +3266,6 @@ "$unit($unit) marschiert in eine Antimagiezone und löst sich auf." "$unit($unit) walks into an antimagical zone and dissolves." - - - - - "$unit($unit) hat sich unbemerkt verflüchtigt." - "$unit($unit) has dissolved without a trace." - - - - - - "$unit($unit) wird sich bald verflüchtigen." - "$unit($unit) will dissolve soon." - diff --git a/res/e3a/races.xml b/res/e3a/races.xml index e81d31b92..83d356f75 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -696,13 +696,6 @@ - - - - - - - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 470a33a3f..bce464d78 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -745,12 +745,6 @@ - - - - - - diff --git a/src/kernel/race.c b/src/kernel/race.c index e3983bffe..56b0590ae 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -66,7 +66,7 @@ static int rc_changes = 1; static const char *racenames[MAXRACES] = { "dwarf", "elf", NULL, "goblin", "human", "troll", "demon", "insect", - "halfling", "cat", "aquarian", "orc", "snotling", "undead", "illusion", + "halfling", "cat", "aquarian", "orc", "snotling", "undead", NULL, "youngdragon", "dragon", "wyrm", "ent", "catdragon", "dracoid", NULL, "spell", "irongolem", "stonegolem", "shadowdemon", "shadowmaster", "mountainguard", "alp", "toad", "braineater", "peasant", @@ -296,9 +296,16 @@ static race *rc_find_i(const char *name) while (rc && strcmp(rname, rc->_name) != 0) { rc = rc->next; } - if (!rc && strcmp(name, "uruk") == 0) { - rc = rc_find_i("orc"); - log_warning("a reference was made to the retired race '%s', returning '%s'.", name, rc->_name); + if (!rc) { + const char *rc_depr[] = { "uruk", "orc", "illusion", "template", NULL }; + int i; + for (i = 0; rc_depr[i]; i += 2) { + if (strcmp(name, rc_depr[i]) == 0) { + rc = rc_find_i(rc_depr[i + 1]); + log_warning("a reference was made to the retired race '%s', returning '%s'.", name, rc->_name); + break; + } + } } return rc; } diff --git a/src/kernel/race.h b/src/kernel/race.h index 1322d3aad..1039402b0 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -65,8 +65,8 @@ extern "C" { RC_ORC, RC_SNOTLING, RC_UNDEAD, - RC_ILLUSION, - RC_FIREDRAGON, + + RC_FIREDRAGON = 15, RC_DRAGON, RC_WYRM, RC_TREEMAN, diff --git a/src/races/CMakeLists.txt b/src/races/CMakeLists.txt index 1f3044e3a..ff6025581 100644 --- a/src/races/CMakeLists.txt +++ b/src/races/CMakeLists.txt @@ -1,7 +1,6 @@ PROJECT(races C) SET(_FILES dragons.c -illusion.c races.c zombies.c ) diff --git a/src/races/illusion.c b/src/races/illusion.c deleted file mode 100644 index 7411ae4d5..000000000 --- a/src/races/illusion.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Eressea PB(E)M host Copyright (C) 1998-2015 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Henning Peters (faroul@beyond.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ - -#include - -/* kernel includes */ -#include -#include -#include -#include - -/* libc includes */ -#include -#include - -#define ILLUSIONMAX 6 - -void age_illusion(unit * u) -{ - if (u->faction->race != get_race(RC_ILLUSION)) { - if (u->age == ILLUSIONMAX) { - ADDMSG(&u->faction->msgs, msg_message("warnillusiondissolve", "unit", u)); - } - else if (u->age > ILLUSIONMAX) { - set_number(u, 0); - ADDMSG(&u->faction->msgs, msg_message("illusiondissolve", "unit", u)); - } - } -} diff --git a/src/races/races.c b/src/races/races.c index bb699520e..7ca9e976a 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -31,7 +31,6 @@ void age_firedragon(struct unit *u); void age_dragon(struct unit *u); -void age_illusion(struct unit *u); void age_undead(struct unit *u); void age_skeleton(struct unit *u); void age_zombie(struct unit *u); @@ -101,7 +100,6 @@ void register_races(void) /* function age for race->age() */ register_function((pf_generic)age_undead, "ageundead"); - register_function((pf_generic)age_illusion, "ageillusion"); register_function((pf_generic)age_skeleton, "ageskeleton"); register_function((pf_generic)age_zombie, "agezombie"); register_function((pf_generic)age_ghoul, "ageghoul"); diff --git a/src/reports.c b/src/reports.c index 7d8374ff5..a49957b9d 100644 --- a/src/reports.c +++ b/src/reports.c @@ -123,13 +123,12 @@ const char *options[MAXOPTIONS] = { bool omniscient(const faction *f) { - static const race *rc_template, *rc_illusion; + static const race *rc_template; static int cache; if (rc_changed(&cache)) { - rc_illusion = get_race(RC_ILLUSION); rc_template = get_race(RC_TEMPLATE); } - return (f->race == rc_template || f->race == rc_illusion); + return (f->race == rc_template); } From 44f6336e1f8d150430a7f66a6955ddfa5b010040 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 21:04:50 +0100 Subject: [PATCH 242/271] do not register unused functions. --- src/races/races.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/races/races.c b/src/races/races.c index 7ca9e976a..a05f3d211 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -36,16 +36,6 @@ void age_skeleton(struct unit *u); void age_zombie(struct unit *u); void age_ghoul(struct unit *u); -static void oldfamiliars(unit * u) -{ - char fname[64]; - /* these familiars have no special skills. - */ - snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); - create_mage(u, M_GRAY); - equip_unit(u, get_equipment(fname)); -} - static void equip_newunits(const struct equipment *eq, struct unit *u) { struct region *r = u->region; @@ -91,12 +81,7 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { - /* function initfamiliar */ - register_function((pf_generic)oldfamiliars, "oldfamiliars"); - - register_function((pf_generic)allowed_swim, "moveswimming"); - register_function((pf_generic)allowed_fly, "moveflying"); - register_function((pf_generic)allowed_walk, "movewalking"); + register_function((pf_generic)equip_newunits, "equip_newunits"); /* function age for race->age() */ register_function((pf_generic)age_undead, "ageundead"); @@ -105,9 +90,4 @@ void register_races(void) register_function((pf_generic)age_ghoul, "ageghoul"); register_function((pf_generic)age_dragon, "agedragon"); register_function((pf_generic)age_firedragon, "agefiredragon"); - - /* function itemdrop - * to generate battle spoils - * race->itemdrop() */ - register_function((pf_generic)equip_newunits, "equip_newunits"); } From a1dc3dc8e4f43088cf0898a259b81c191e375021 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 21:19:13 +0100 Subject: [PATCH 243/271] remove race.age from XML data (set in rc_create) --- res/e3a/races.xml | 4 ---- res/eressea/races.xml | 6 ------ src/kernel/race.c | 4 ++++ src/kernel/xmlreader.c | 3 --- src/races/races.c | 12 ++++++------ 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 83d356f75..b7111b4f1 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -699,7 +699,6 @@ - @@ -752,7 +751,6 @@ - @@ -788,7 +786,6 @@ - @@ -820,7 +817,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index bce464d78..b9077d98b 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -723,7 +723,6 @@ - @@ -735,7 +734,6 @@ - @@ -748,7 +746,6 @@ - @@ -1019,7 +1016,6 @@ - @@ -1053,7 +1049,6 @@ - @@ -1083,7 +1078,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index 56b0590ae..4e8e0817c 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -327,6 +327,7 @@ race *rc_create(const char *zName) { race *rc; int i; + char zText[64]; assert(zName); rc = (race *)calloc(sizeof(race), 1); @@ -350,6 +351,9 @@ race *rc_create(const char *zName) rc->index = num_races++; ++rc_changes; rc->next = races; + + snprintf(zText, sizeof(zText), "age_%s", zName); + rc->age = (void(*) (struct unit *))get_function(zText); return races = rc; } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2ba8e2b75..5c294d13a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1795,9 +1795,6 @@ static int parse_races(xmlDocPtr doc) if (strcmp((const char *)propValue, "name") == 0) { rc->generate_name = (race_name_func)fun; } - else if (strcmp((const char *)propValue, "age") == 0) { - rc->age = (void(*)(struct unit *))fun; - } else { log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name); } diff --git a/src/races/races.c b/src/races/races.c index a05f3d211..92a3d3e3d 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -84,10 +84,10 @@ void register_races(void) register_function((pf_generic)equip_newunits, "equip_newunits"); /* function age for race->age() */ - register_function((pf_generic)age_undead, "ageundead"); - register_function((pf_generic)age_skeleton, "ageskeleton"); - register_function((pf_generic)age_zombie, "agezombie"); - register_function((pf_generic)age_ghoul, "ageghoul"); - register_function((pf_generic)age_dragon, "agedragon"); - register_function((pf_generic)age_firedragon, "agefiredragon"); + register_function((pf_generic)age_undead, "age_undead"); + register_function((pf_generic)age_skeleton, "age_skeleton"); + register_function((pf_generic)age_zombie, "age_zombie"); + register_function((pf_generic)age_ghoul, "age_ghoul"); + register_function((pf_generic)age_dragon, "age_dragon"); + register_function((pf_generic)age_firedragon, "age_youngdragon"); } From 7e4b0ac71772361c11b345dfbbc9ee232b34ee21 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 21:21:05 +0100 Subject: [PATCH 244/271] fix XML file --- res/races/dragon.xml | 1 - res/races/youngdragon.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/res/races/dragon.xml b/res/races/dragon.xml index 7a36e4b84..f42037312 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -5,7 +5,6 @@ income="1000" walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes"> - diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index 0ac2d35be..df10a44e9 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -5,7 +5,6 @@ defensemodifier="4" scarepeasants="yes" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes" income="150"> - From bfb5a9b69231c1b53ae9d3ad700582d332beb125 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 22:07:36 +0100 Subject: [PATCH 245/271] set age_unit and name_unit funpointers in rc_create. no more in XML races. rename juju-zombie => juju. --- res/core/de/strings.xml | 8 ++++---- res/core/fr/strings.xml | 4 ++-- res/e3a/races.xml | 19 +------------------ res/eressea/races.xml | 23 +---------------------- src/kernel/race.c | 12 ++++++++---- src/kernel/race.h | 8 ++++---- src/kernel/unit.c | 9 ++++++--- src/kernel/unit.test.c | 2 +- src/kernel/xmlreader.c | 24 ------------------------ src/laws.c | 5 +++-- src/names.c | 23 ++++++++++------------- src/names.test.c | 35 ++++++++++++++++++++--------------- 12 files changed, 60 insertions(+), 112 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 3aa71393d..97ded6e8d 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -2379,19 +2379,19 @@ ghoul - + Juju-Zombie juju-zombie - + Juju-Zombies juju-zombies - + Juju-Zombies juju-zombies - + Juju-Zombie juju-zombie diff --git a/res/core/fr/strings.xml b/res/core/fr/strings.xml index d1801b338..7eb091570 100644 --- a/res/core/fr/strings.xml +++ b/res/core/fr/strings.xml @@ -1912,10 +1912,10 @@ zombie - + zombies juju - + zombie juju diff --git a/res/e3a/races.xml b/res/e3a/races.xml index b7111b4f1..2e5a81aee 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -415,7 +415,6 @@ - @@ -588,7 +587,6 @@ - @@ -643,19 +641,16 @@ - - - @@ -667,7 +662,6 @@ - @@ -683,7 +677,6 @@ - @@ -691,14 +684,12 @@ - - @@ -731,7 +722,6 @@ - @@ -750,7 +740,6 @@ - @@ -766,9 +755,8 @@ - + - @@ -785,7 +773,6 @@ - @@ -800,7 +787,6 @@ - @@ -816,7 +802,6 @@ - @@ -831,13 +816,11 @@ - - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index b9077d98b..6deefacc9 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -330,7 +330,6 @@ - @@ -581,7 +580,6 @@ - @@ -652,19 +650,16 @@ - - - @@ -676,7 +671,6 @@ - @@ -691,7 +685,6 @@ - @@ -705,13 +698,11 @@ - - @@ -722,7 +713,6 @@ - @@ -733,7 +723,6 @@ - @@ -745,7 +734,6 @@ - @@ -997,7 +985,6 @@ - @@ -1015,7 +1002,6 @@ - @@ -1030,9 +1016,8 @@ - + - @@ -1048,7 +1033,6 @@ - @@ -1062,7 +1046,6 @@ - @@ -1077,7 +1060,6 @@ - @@ -1091,12 +1073,10 @@ - - @@ -1224,7 +1204,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index 4e8e0817c..4a3a04916 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -74,7 +74,7 @@ static const char *racenames[MAXRACES] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "seaserpent", "shadowknight", NULL, "skeleton", "skeletonlord", "zombie", - "juju-zombie", "ghoul", "ghast", NULL, NULL, "template", + "juju", "ghoul", "ghast", NULL, NULL, "template", "clone" }; @@ -297,7 +297,7 @@ static race *rc_find_i(const char *name) rc = rc->next; } if (!rc) { - const char *rc_depr[] = { "uruk", "orc", "illusion", "template", NULL }; + const char *rc_depr[] = { "uruk", "orc", "illusion", "template", "juju-zombie", "juju", NULL }; int i; for (i = 0; rc_depr[i]; i += 2) { if (strcmp(name, rc_depr[i]) == 0) { @@ -353,7 +353,11 @@ race *rc_create(const char *zName) rc->next = races; snprintf(zText, sizeof(zText), "age_%s", zName); - rc->age = (void(*) (struct unit *))get_function(zText); + rc->age_unit = (race_func)get_function(zText); + + snprintf(zText, sizeof(zText), "name_%s", zName); + rc->name_unit = (race_func)get_function(zText); + return races = rc; } @@ -553,6 +557,6 @@ variant read_race_reference(struct storage *store) return result; } -void register_race_name_function(race_name_func func, const char *name) { +void register_race_function(race_func func, const char *name) { register_function((pf_generic)func, name); } diff --git a/src/kernel/race.h b/src/kernel/race.h index 1039402b0..e464c9447 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -112,7 +112,7 @@ extern "C" { int level; } att; - typedef void (*race_name_func)(struct unit *); + typedef void (*race_func) (struct unit *); typedef struct race { char *_name; @@ -143,8 +143,8 @@ extern "C" { struct att attack[RACE_ATTACKS]; signed char bonus[MAXSKILLS]; - race_name_func generate_name; - void(*age) (struct unit * u); + race_func name_unit; + race_func age_unit; struct rcoption *options; /* rarely used properties */ @@ -262,7 +262,7 @@ extern "C" { variant read_race_reference(struct storage *store); const char *raceprefix(const struct unit *u); - void register_race_name_function(race_name_func, const char *); + void register_race_function(race_func, const char *); #ifdef __cplusplus } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index ab1669ed9..4592d0bc7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1460,8 +1460,11 @@ void default_name(const unit *u, char name[], int len) { void name_unit(unit * u) { const race *rc = u_race(u); - if (rc->generate_name) { - rc->generate_name(u); + if (rc->name_unit) { + rc->name_unit(u); + } + else if (u->faction->flags & FFL_NPC) { + unit_setname(u, NULL); } else { char name[32]; @@ -1514,7 +1517,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, if (dname) { u->_name = strdup(dname); } - else if (urace->generate_name || playerrace(urace)) { + else if (urace->name_unit || playerrace(urace)) { name_unit(u); } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index c187f7bab..7c7bb087b 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -487,7 +487,7 @@ static void test_name_unit(CuTest *tc) { test_setup(); rc = test_create_race("skeleton"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); - rc->generate_name = gen_name; + rc->name_unit = gen_name; name_unit(u); CuAssertStrEquals(tc, "Hodor", unit_getname(u)); test_cleanup(); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 5c294d13a..695f91d69 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1778,30 +1778,6 @@ static int parse_races(xmlDocPtr doc) } xmlXPathFreeObject(result); - /* reading eressea/races/race/function */ - xpath->node = node; - result = xmlXPathEvalExpression(BAD_CAST "function", xpath); - for (k = 0; k != result->nodesetval->nodeNr; ++k) { - xmlNodePtr node = result->nodesetval->nodeTab[k]; - pf_generic fun; - - parse_function(node, &fun, &propValue); - if (fun == NULL) { - log_error("unknown function name '%s' for race %s\n", (const char *)propValue, rc->_name); - xmlFree(propValue); - continue; - } - assert(propValue != NULL); - if (strcmp((const char *)propValue, "name") == 0) { - rc->generate_name = (race_name_func)fun; - } - else { - log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name); - } - xmlFree(propValue); - } - xmlXPathFreeObject(result); - /* reading eressea/races/race/familiar */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "familiar", xpath); diff --git a/src/laws.c b/src/laws.c index e314e2d85..253b45b89 100644 --- a/src/laws.c +++ b/src/laws.c @@ -164,9 +164,10 @@ static void age_unit(region * r, unit * u) } } else { + const race *rc = u_race(u); ++u->age; - if (u->number > 0 && u_race(u)->age) { - u_race(u)->age(u); + if (u->number > 0 && rc->age_unit) { + rc->age_unit(u); } } if (u->region && is_astral(u->region)) { diff --git a/src/names.c b/src/names.c index 780386deb..bc740a704 100644 --- a/src/names.c +++ b/src/names.c @@ -212,11 +212,6 @@ const char *silbe3[SIL3] = { "bus", }; -static void generic_name(unit * u) -{ - unit_setname(u, NULL); -} - static void dragon_name(unit * u) { char name[NAMESIZE + 1]; @@ -469,12 +464,14 @@ void register_names(void) { /* function name * generate a name for a nonplayerunit - * race->generate_name() */ - register_race_name_function(undead_name, "nameundead"); - register_race_name_function(skeleton_name, "nameskeleton"); - register_race_name_function(zombie_name, "namezombie"); - register_race_name_function(ghoul_name, "nameghoul"); - register_race_name_function(dracoid_name, "namedracoid"); - register_race_name_function(dragon_name, "namedragon"); - register_race_name_function(generic_name, "namegeneric"); + * race->name_unit() */ + + register_race_function(undead_name, "name_undead"); + register_race_function(skeleton_name, "name_skeleton"); + register_race_function(zombie_name, "name_zombie"); + register_race_function(ghoul_name, "name_ghoul"); + register_race_function(dracoid_name, "name_dracoid"); + register_race_function(dragon_name, "name_dragon"); + register_race_function(dragon_name, "name_youngdragon"); + register_race_function(dragon_name, "name_wyrm"); } diff --git a/src/names.test.c b/src/names.test.c index 01fe0ff41..7d62d4752 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,31 +13,33 @@ static void test_names(CuTest * tc) { - race_name_func foo; unit *u; race *rc; test_cleanup(); register_names(); + CuAssertPtrNotNull(tc, get_function("name_undead")); + CuAssertPtrNotNull(tc, get_function("name_skeleton")); + CuAssertPtrNotNull(tc, get_function("name_zombie")); + CuAssertPtrNotNull(tc, get_function("name_ghoul")); + CuAssertPtrNotNull(tc, get_function("name_dragon")); + CuAssertPtrNotNull(tc, get_function("name_youngdragon")); + CuAssertPtrNotNull(tc, get_function("name_wyrm")); + CuAssertPtrNotNull(tc, get_function("name_dracoid")); default_locale = test_create_locale(); - u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); rc = test_create_race("undead"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); locale_setstring(default_locale, "undead_name_0", "Graue"); locale_setstring(default_locale, "undead_postfix_0", "Kobolde"); - CuAssertPtrNotNull(tc, foo = (race_name_func)get_function("nameundead")); - rc->generate_name = foo; - rc->generate_name(u); + CuAssertPtrNotNull(tc, rc->name_unit); + CuAssertTrue(tc, rc->name_unit == (race_func)get_function("name_undead")); + name_unit(u); CuAssertStrEquals(tc, "Graue Kobolde", u->_name); - CuAssertPtrNotNull(tc, get_function("nameskeleton")); - CuAssertPtrNotNull(tc, get_function("namezombie")); - CuAssertPtrNotNull(tc, get_function("nameghoul")); - CuAssertPtrNotNull(tc, get_function("namedragon")); - CuAssertPtrNotNull(tc, get_function("namedracoid")); - CuAssertPtrNotNull(tc, get_function("namegeneric")); test_cleanup(); } static void test_monster_names(CuTest *tc) { unit *u; + faction *f; race *rc; test_setup(); @@ -45,11 +48,13 @@ static void test_monster_names(CuTest *tc) { locale_setstring(default_locale, "race::irongolem", "Eisengolem"); locale_setstring(default_locale, "race::irongolem_p", "Eisengolems"); rc = test_create_race("irongolem"); - u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + f = test_create_faction(rc); + f->flags |= FFL_NPC; + u = test_create_unit(f, test_create_region(0, 0, 0)); + unit_setname(u, "Hodor"); CuAssertPtrNotNull(tc, u->_name); - rc->generate_name = (race_name_func)get_function("namegeneric"); - rc->generate_name(u); - CuAssertPtrEquals(tc, 0, u->_name); + name_unit(u); + CuAssertPtrEquals(tc, NULL, u->_name); CuAssertStrEquals(tc, "Eisengolem", unit_getname(u)); u->number = 2; CuAssertStrEquals(tc, "Eisengolems", unit_getname(u)); From deb39f6b8f8386169d4dd1ebe81429e9fdd0b6db Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Feb 2017 14:27:13 +0100 Subject: [PATCH 246/271] test building_effsize does what it does --- src/kernel/building.test.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index e02d16556..8bafcab85 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -515,6 +515,31 @@ static void test_cmp_castle_size(CuTest *tc) { test_cleanup(); } +static void test_building_effsize(CuTest *tc) { + building *b; + building_type *btype; + construction *cons; + + test_setup(); + btype = bt_get_or_create("castle"); + cons = btype->construction = calloc(1, sizeof(construction)); + cons->maxsize = 5; + cons = cons->improvement = calloc(1, sizeof(construction)); + cons->maxsize = 5; + cons = cons->improvement = calloc(1, sizeof(construction)); + cons->maxsize = -1; + b = test_create_building(test_create_region(0,0,0), btype); + b->size = 1; + CuAssertIntEquals(tc, 0, buildingeffsize(b, false)); + b->size = 5; + CuAssertIntEquals(tc, 1, buildingeffsize(b, false)); + b->size = 10; + CuAssertIntEquals(tc, 2, buildingeffsize(b, false)); + b->size = 20; + CuAssertIntEquals(tc, 2, buildingeffsize(b, false)); + test_cleanup(); +} + CuSuite *get_building_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -522,6 +547,7 @@ CuSuite *get_building_suite(void) SUITE_ADD_TEST(suite, test_register_building); SUITE_ADD_TEST(suite, test_btype_defaults); SUITE_ADD_TEST(suite, test_building_set_owner); + SUITE_ADD_TEST(suite, test_building_effsize); SUITE_ADD_TEST(suite, test_buildingowner_resets_when_empty); SUITE_ADD_TEST(suite, test_buildingowner_goes_to_next_when_empty); SUITE_ADD_TEST(suite, test_buildingowner_goes_to_other_when_empty); From 3274065004bf42a0ab670a0c27f4da0da3cf3e20 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Feb 2017 19:38:46 +0100 Subject: [PATCH 247/271] reduce complexity of building_protection. --- .gitignore | 3 ++ res/buildings/castle-2.xml | 13 +++--- res/buildings/castle.xml | 15 ++++--- res/e3a/buildings.xml | 7 ++-- src/battle.c | 18 ++++---- src/battle.test.c | 84 ++++++++++++++++++++------------------ src/kernel/build.h | 3 -- src/kernel/building.c | 36 ++++------------ src/kernel/building.h | 13 ++---- src/kernel/building.test.c | 1 - src/kernel/xmlreader.c | 6 --- src/tests.c | 2 +- 12 files changed, 87 insertions(+), 114 deletions(-) diff --git a/.gitignore b/.gitignore index 4e63f5d9c..d7c102f5a 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ tmp/ tests/config.lua tests/reports/ tests/data/185.dat +/quicklist/ +/cutest/ +/critbit/ diff --git a/res/buildings/castle-2.xml b/res/buildings/castle-2.xml index 593e9ae5e..7b015d199 100644 --- a/res/buildings/castle-2.xml +++ b/res/buildings/castle-2.xml @@ -1,24 +1,23 @@ - - + - + - + - + - + - + diff --git a/res/buildings/castle.xml b/res/buildings/castle.xml index 253f49811..6e9140222 100644 --- a/res/buildings/castle.xml +++ b/res/buildings/castle.xml @@ -1,26 +1,25 @@ - - + - + - + - + - + - + - + diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml index f65654e2f..9eeca952f 100644 --- a/res/e3a/buildings.xml +++ b/res/e3a/buildings.xml @@ -5,15 +5,14 @@ - - + - + - + diff --git a/src/battle.c b/src/battle.c index 0ff8eecaa..23c219109 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1892,10 +1892,11 @@ int skilldiff(troop at, troop dt, int dist) } if (df->building) { - if (df->building->attribs) { + building *b = df->building; + if (b->attribs) { const curse_type *strongwall_ct = ct_find("strongwall"); if (strongwall_ct) { - curse *c = get_curse(df->building->attribs, strongwall_ct); + curse *c = get_curse(b->attribs, strongwall_ct); if (curse_active(c)) { /* wirkt auf alle Geb�ude */ skdiff -= curse_geteffect_int(c); @@ -1903,15 +1904,16 @@ int skilldiff(troop at, troop dt, int dist) } } } - if (df->building->type->protection) { - int beff = df->building->type->protection(df->building, du, DEFENSE_BONUS); - if (beff) { + if (b->type->flags & BTF_FORTIFICATION) { + int stage = buildingeffsize(b, false); + int beff = building_protection(b->type, stage); + if (beff > 0) { skdiff -= beff; is_protected = 2; - if (df->building->attribs) { + if (b->attribs) { const curse_type *magicwalls_ct = ct_find("magicwalls"); if (magicwalls_ct - && curse_active(get_curse(df->building->attribs, magicwalls_ct))) { + && curse_active(get_curse(b->attribs, magicwalls_ct))) { /* Verdoppelt Burgenbonus */ skdiff -= beff; } @@ -2022,7 +2024,7 @@ void damage_building(battle * b, building * bldg, int damage_abs) /* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb�ude passen. */ - if (bldg->type->protection) { + if (bldg->type->flags & BTF_FORTIFICATION) { side *s; bldg->sizeleft = bldg->size; diff --git a/src/battle.test.c b/src/battle.test.c index 5d34766db..987613277 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -60,10 +60,23 @@ static void test_make_fighter(CuTest * tc) test_cleanup(); } -static int add_two(const building * b, const unit * u, building_bonus bonus) { +static int add_two(const building * b, const unit * u) { return 2; } +static building_type * setup_castle(void) { + building_type * btype; + construction *cons; + + btype = bt_get_or_create("castle"); + btype->flags |= BTF_FORTIFICATION; + cons = btype->construction = calloc(1, sizeof(construction)); + cons->maxsize = 5; + cons = cons->improvement = calloc(1, sizeof(construction)); + cons->maxsize = -1; + return btype; +} + static void test_defenders_get_building_bonus(CuTest * tc) { unit *du, *au; @@ -72,16 +85,13 @@ static void test_defenders_get_building_bonus(CuTest * tc) fighter *df, *af; battle *b; side *ds, *as; - int diff; troop dt, at; building_type * btype; test_cleanup(); + btype = setup_castle(); r = test_create_region(0, 0, 0); - btype = bt_get_or_create("castle"); - btype->protection = &add_two; bld = test_create_building(r, btype); - bld->size = 10; du = test_create_unit(test_create_faction(NULL), r); au = test_create_unit(test_create_faction(NULL), r); @@ -101,11 +111,14 @@ static void test_defenders_get_building_bonus(CuTest * tc) at.fighter = af; at.index = 0; - diff = skilldiff(at, dt, 0); - CuAssertIntEquals(tc, -2, diff); + bld->size = 10; /* stage 1 building */ + CuAssertIntEquals(tc, -1, skilldiff(at, dt, 0)); + CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0)); + + bld->size = 1; /* stage 0 building */ + CuAssertIntEquals(tc, 0, skilldiff(at, dt, 0)); + CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0)); - diff = skilldiff(dt, at, 0); - CuAssertIntEquals(tc, 0, diff); free_battle(b); test_cleanup(); } @@ -122,8 +135,8 @@ static void test_attackers_get_no_building_bonus(CuTest * tc) test_cleanup(); r = test_create_region(0, 0, 0); - btype = bt_get_or_create("castle"); - btype->protection = &add_two; + btype = setup_castle(); + btype->flags |= BTF_FORTIFICATION; bld = test_create_building(r, btype); bld->size = 10; @@ -151,9 +164,9 @@ static void test_building_bonus_respects_size(CuTest * tc) faction * f; test_cleanup(); + btype = setup_castle(); r = test_create_region(0, 0, 0); - btype = bt_get_or_create("castle"); - btype->protection = &add_two; + btype->flags |= BTF_FORTIFICATION; bld = test_create_building(r, btype); bld->size = 10; @@ -178,28 +191,25 @@ static void test_building_bonus_respects_size(CuTest * tc) static void test_building_defence_bonus(CuTest * tc) { - unit *au; - region *r; - building * bld; building_type * btype; - faction * f; - int def; test_cleanup(); - r = test_create_region(0, 0, 0); - btype = test_create_buildingtype("castle"); - btype->protection = (int(*)(const struct building *, const struct unit *, building_bonus))get_function("building_protection"); - btype->construction->defense_bonus = 3; - bld = test_create_building(r, btype); - bld->size = 1; + btype = setup_castle(); - f = test_create_faction(NULL); - au = test_create_unit(f, r); - scale_number(au, 1); - u_set_building(au, bld); + btype->maxsize = -1; /* unlimited buildigs get the castle bonus */ + CuAssertIntEquals(tc, 0, building_protection(btype, 0)); + CuAssertIntEquals(tc, 1, building_protection(btype, 1)); + CuAssertIntEquals(tc, 3, building_protection(btype, 2)); + CuAssertIntEquals(tc, 5, building_protection(btype, 3)); + CuAssertIntEquals(tc, 8, building_protection(btype, 4)); + CuAssertIntEquals(tc, 12, building_protection(btype, 5)); + CuAssertIntEquals(tc, 12, building_protection(btype, 6)); - def = btype->protection(bld, au, DEFENSE_BONUS); - CuAssertIntEquals(tc, 3, def); + btype->maxsize = 10; /* limited-size buildings are treated like an E3 watchtower */ + CuAssertIntEquals(tc, 0, building_protection(btype, 0)); + CuAssertIntEquals(tc, 1, building_protection(btype, 1)); + CuAssertIntEquals(tc, 2, building_protection(btype, 2)); + CuAssertIntEquals(tc, 2, building_protection(btype, 3)); test_cleanup(); } @@ -441,10 +451,6 @@ static void test_battle_skilldiff(CuTest *tc) test_cleanup(); } -static int protect(const building *b, const unit *u, building_bonus bonus) { - return (bonus == DEFENSE_BONUS) ? 4 : 0; -} - static void test_battle_skilldiff_building(CuTest *tc) { troop ta, td; @@ -455,7 +461,7 @@ static void test_battle_skilldiff_building(CuTest *tc) const curse_type *strongwall_ct, *magicwalls_ct; test_cleanup(); - btype = test_create_buildingtype("castle"); + btype = setup_castle(); strongwall_ct = ct_find("strongwall"); magicwalls_ct = ct_find("magicwalls"); @@ -470,14 +476,14 @@ static void test_battle_skilldiff_building(CuTest *tc) ua = test_create_unit(test_create_faction(0), r); CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0)); - btype->protection = protect; - CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0)); + ud->building->size = 10; + CuAssertIntEquals(tc, -1, skilldiff(ta, td, 0)); create_curse(NULL, &ud->building->attribs, magicwalls_ct, 1, 1, 1, 1); - CuAssertIntEquals(tc, -8, skilldiff(ta, td, 0)); + CuAssertIntEquals(tc, -2, skilldiff(ta, td, 0)); create_curse(NULL, &ud->building->attribs, strongwall_ct, 1, 1, 2, 1); - CuAssertIntEquals(tc, -10, skilldiff(ta, td, 0)); + CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0)); free_battle(b); test_cleanup(); diff --git a/src/kernel/build.h b/src/kernel/build.h index 38fefb88a..7780a6cd2 100644 --- a/src/kernel/build.h +++ b/src/kernel/build.h @@ -45,9 +45,6 @@ extern "C" { int maxsize; /* maximum size of this type */ int reqsize; /* size of object using up 1 set of requirement. */ - int defense_bonus; /* protection bonus (defense) during combat */ - int close_combat_bonus; /* close combat attack bonus*/ - int ranged_bonus; /* ranged attack bonus */ requirement *materials; /* material req'd to build one object */ const struct building_type *btype; /* building type required to make this thing */ diff --git a/src/kernel/building.c b/src/kernel/building.c index 06078aaba..3c21f4dbe 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -337,40 +337,24 @@ const building_type *findbuildingtype(const char *name, int cmp_castle_size(const building * b, const building * a) { - if (!b || !b->type->protection || !building_owner(b)) { + if (!b || !(b->type->flags & BTF_FORTIFICATION) || !building_owner(b)) { return -1; } - if (!a || !a->type->protection || !building_owner(a)) { + if (!a || !(a->type->flags & BTF_FORTIFICATION) || !building_owner(a)) { return 1; } return b->size - a->size; } -int building_protection(const building * b, const unit * u, building_bonus bonus) +static const int castle_bonus[6] = { 0, 1, 3, 5, 8, 12 }; +static const int watch_bonus[3] = { 0, 1, 2 }; + +int building_protection(const building_type * btype, int stage) { - int i = 0; - int bsize = buildingeffsize(b, false); - const construction *cons = b->type->construction; - if (!cons) { - return 0; - } - - for (i = 0; i < bsize; i++) - { - cons = cons->improvement; - } - - switch (bonus) - { - case DEFENSE_BONUS: - return cons->defense_bonus; - case CLOSE_COMBAT_ATTACK_BONUS: - return cons->close_combat_bonus; - case RANGED_ATTACK_BONUS: - return cons->ranged_bonus; - default: - return 0; + if (btype->maxsize < 0) { + return castle_bonus[MIN(stage, 5)]; } + return watch_bonus[MIN(stage, 2)]; } void write_building_reference(const struct building *b, struct storage *store) @@ -925,8 +909,6 @@ int cmp_current_owner(const building * b, const building * a) void register_buildings(void) { register_function((pf_generic)minimum_wage, "minimum_wage"); - register_function((pf_generic)building_protection, - "building_protection"); register_function((pf_generic)init_smithy, "init_smithy"); register_function((pf_generic)castle_name, "castle_name"); register_function((pf_generic)castle_name_2, "castle_name_2"); diff --git a/src/kernel/building.h b/src/kernel/building.h index 1adce7e09..8c23fdb7c 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -51,13 +51,7 @@ extern "C" { #define BTF_MAGIC 0x40 /* magical effect */ #define BTF_ONEPERTURN 0x80 /* one one sizepoint can be added per turn */ #define BTF_NAMECHANGE 0x100 /* name and description can be changed more than once */ -#define BTF_FORTIFICATION 0x200 /* safe from monsters */ - - typedef enum { - DEFENSE_BONUS, - CLOSE_COMBAT_ATTACK_BONUS, /* TODO: only DEFENSE_BONUS is in use? */ - RANGED_ATTACK_BONUS - } building_bonus; +#define BTF_FORTIFICATION 0x200 /* building_protection, safe from monsters */ typedef struct building_type { char *_name; @@ -77,7 +71,6 @@ extern "C" { const struct building * b, int size); void(*init) (struct building_type *); void(*age) (struct building *); - int(*protection) (const struct building *, const struct unit *, building_bonus bonus); double(*taxes) (const struct building *, int size); struct attrib *attribs; } building_type; @@ -85,8 +78,8 @@ extern "C" { extern struct selist *buildingtypes; extern struct attrib_type at_building_action; - int cmp_castle_size(const struct building * b, const struct building * a); - int building_protection(const struct building * b, const struct unit * u, building_bonus bonus); + int cmp_castle_size(const struct building *b, const struct building *a); + int building_protection(const struct building_type *btype, int stage); building_type *bt_get_or_create(const char *name); bool bt_changed(int *cache); const building_type *bt_find(const char *name); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index e02d16556..4395f1c40 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -376,7 +376,6 @@ static void test_btype_defaults(CuTest *tc) { CuAssertTrue(tc, !btype->name); CuAssertTrue(tc, !btype->init); CuAssertTrue(tc, !btype->age); - CuAssertTrue(tc, !btype->protection); CuAssertTrue(tc, !btype->taxes); CuAssertDblEquals(tc, 1.0, btype->auraregen, 0.0); CuAssertIntEquals(tc, -1, btype->maxsize); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 695f91d69..555c0f679 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -167,9 +167,6 @@ construction ** consPtr) con->maxsize = xml_ivalue(node, "maxsize", -1); con->minskill = xml_ivalue(node, "minskill", -1); con->reqsize = xml_ivalue(node, "reqsize", 1); - con->defense_bonus = xml_ivalue(node, "defense_bonus", 0); - con->close_combat_bonus = xml_ivalue(node, "close_combat_bonus", 0); - con->ranged_bonus = xml_ivalue(node, "ranged_bonus", 0); propValue = xmlGetProp(node, BAD_CAST "building"); if (propValue != NULL) { @@ -301,9 +298,6 @@ static int parse_buildings(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { btype->age = (void(*)(struct building *))fun; } - else if (strcmp((const char *)propValue, "protection") == 0) { - btype->protection = (int(*)(const struct building *, const struct unit *, building_bonus))fun; - } else if (strcmp((const char *)propValue, "taxes") == 0) { btype->taxes = (double(*)(const struct building *, int))fun; } diff --git a/src/tests.c b/src/tests.c index 6a43e6e79..c448a27ae 100644 --- a/src/tests.c +++ b/src/tests.c @@ -230,7 +230,7 @@ building * test_create_building(region * r, const building_type * btype) assert(r); if (!btype) { building_type *bt_castle = test_create_buildingtype("castle"); - bt_castle->protection = building_protection; + bt_castle->flags |= BTF_FORTIFICATION; btype = bt_castle; } b = new_building(btype, r, default_locale); From 82e4d754292478e82af1202524d7ba04293f0fe9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Feb 2017 19:43:17 +0100 Subject: [PATCH 248/271] unused function --- src/battle.test.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/battle.test.c b/src/battle.test.c index 987613277..109561161 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -60,10 +60,6 @@ static void test_make_fighter(CuTest * tc) test_cleanup(); } -static int add_two(const building * b, const unit * u) { - return 2; -} - static building_type * setup_castle(void) { building_type * btype; construction *cons; From 67831ad7083fb4af108a373a3ae3e18a38c418ea Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Feb 2017 20:16:51 +0100 Subject: [PATCH 249/271] we like test_setup. --- src/battle.test.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/battle.test.c b/src/battle.test.c index 109561161..d15c335a9 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -26,7 +26,7 @@ static void test_make_fighter(CuTest * tc) faction * f; const resource_type *rtype; - test_cleanup(); + test_setup(); test_create_horse(); r = test_create_region(0, 0, 0); f = test_create_faction(NULL); @@ -84,7 +84,7 @@ static void test_defenders_get_building_bonus(CuTest * tc) troop dt, at; building_type * btype; - test_cleanup(); + test_setup(); btype = setup_castle(); r = test_create_region(0, 0, 0); bld = test_create_building(r, btype); @@ -129,7 +129,7 @@ static void test_attackers_get_no_building_bonus(CuTest * tc) side *as; building_type * btype; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); btype = setup_castle(); btype->flags |= BTF_FORTIFICATION; @@ -159,7 +159,7 @@ static void test_building_bonus_respects_size(CuTest * tc) building_type * btype; faction * f; - test_cleanup(); + test_setup(); btype = setup_castle(); r = test_create_region(0, 0, 0); btype->flags |= BTF_FORTIFICATION; @@ -189,7 +189,7 @@ static void test_building_defence_bonus(CuTest * tc) { building_type * btype; - test_cleanup(); + test_setup(); btype = setup_castle(); btype->maxsize = -1; /* unlimited buildigs get the castle bonus */ @@ -225,7 +225,7 @@ static void test_natural_armor(CuTest * tc) race *rc; unit *u; - test_cleanup(); + test_setup(); rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); set_level(u, SK_STAMINA, 2); @@ -252,7 +252,7 @@ static void test_calculate_armor(CuTest * tc) race *rc; double magres = 0.0; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); ibelt = it_get_or_create(rt_get_or_create("trollbelt")); ishield = it_get_or_create(rt_get_or_create("shield")); @@ -321,7 +321,7 @@ static void test_magic_resistance(CuTest *tc) race *rc; double magres; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); ishield = it_get_or_create(rt_get_or_create("shield")); ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD); @@ -386,7 +386,7 @@ static void test_projectile_armor(CuTest * tc) item_type *ishield, *ichain; race *rc; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); ishield = it_get_or_create(rt_get_or_create("shield")); ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD); @@ -420,7 +420,7 @@ static void test_battle_skilldiff(CuTest *tc) unit *ua, *ud; battle *b = NULL; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); ud = test_create_unit(test_create_faction(0), r); @@ -456,7 +456,7 @@ static void test_battle_skilldiff_building(CuTest *tc) building_type *btype; const curse_type *strongwall_ct, *magicwalls_ct; - test_cleanup(); + test_setup(); btype = setup_castle(); strongwall_ct = ct_find("strongwall"); magicwalls_ct = ct_find("magicwalls"); From ce2ea95880aef67ff52c1dd773f8b5bcbd41b576 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Feb 2017 20:28:34 +0100 Subject: [PATCH 250/271] begin refactoring limited resources. --- src/economy.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/economy.c b/src/economy.c index 94a1a90fa..f98d0f8e1 100644 --- a/src/economy.c +++ b/src/economy.c @@ -914,6 +914,11 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, variant *savep, return NULL; } +static resource_limit *get_resourcelimit(const resource_type *rtype) { + attrib *a = a_find(rtype->attribs, &at_resourcelimit); + return a ? (resource_limit *)a->data.v : NULL; +} + static void allocate_resource(unit * u, const resource_type * rtype, int want) { const item_type *itype = resource2item(rtype); @@ -921,8 +926,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) int dm = 0; allocation_list *alist; allocation *al; - attrib *a = a_find(rtype->attribs, &at_resourcelimit); - resource_limit *rdata = (resource_limit *)a->data.v; + resource_limit *rdata = get_resourcelimit(rtype); const resource_type *rring; int amount, skill, skill_mod = 0; variant save_mod; @@ -1119,8 +1123,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) { allocation *al; int nreq = 0; - attrib *a = a_find(rtype->attribs, &at_resourcelimit); - resource_limit *rdata = (resource_limit *)a->data.v; + resource_limit *rdata = get_resourcelimit(rtype); int avail = rdata->value; for (al = alist; al; al = al->next) { @@ -1160,10 +1163,9 @@ typedef void(*allocate_function) (const resource_type *, struct region *, static allocate_function get_allocator(const struct resource_type *rtype) { - attrib *a = a_find(rtype->attribs, &at_resourcelimit); + resource_limit *rdata = get_resourcelimit(rtype); - if (a != NULL) { - resource_limit *rdata = (resource_limit *)a->data.v; + if (rdata) { if (rdata->value > 0 || rdata->limit != NULL) { return attrib_allocation; } From 1498f2e1d772a5c4c51ce96348e1c5d07611aac8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Feb 2017 21:10:22 +0100 Subject: [PATCH 251/271] refactor rawmaterial_type. still have to decide if we need it at all. --- src/economy.c | 3 +-- src/economy.test.c | 7 +++---- src/items/seed.c | 12 ++++-------- src/kernel/item.c | 16 ---------------- src/kernel/item.h | 24 +++++------------------- src/kernel/resources.c | 12 ++++++------ src/kernel/resources.h | 24 +++++++++++++++++++++++- src/kernel/xmlreader.c | 19 +++++++------------ 8 files changed, 49 insertions(+), 68 deletions(-) diff --git a/src/economy.c b/src/economy.c index f98d0f8e1..f0a693eca 100644 --- a/src/economy.c +++ b/src/economy.c @@ -915,8 +915,7 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, variant *savep, } static resource_limit *get_resourcelimit(const resource_type *rtype) { - attrib *a = a_find(rtype->attribs, &at_resourcelimit); - return a ? (resource_limit *)a->data.v : NULL; + return rtype->limit; } static void allocate_resource(unit * u, const resource_type * rtype, int want) diff --git a/src/economy.test.c b/src/economy.test.c index 766fb4302..c67237c40 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -348,7 +348,7 @@ static void test_make_item(CuTest *tc) { struct item_type *itype; const struct resource_type *rt_silver; resource_type *rtype; - attrib *a; + rawmaterial_type *rmt; resource_limit *rdata; double d = 0.6; @@ -382,10 +382,9 @@ static void test_make_item(CuTest *tc) { free(itype->construction->materials); itype->construction->materials = 0; rtype->flags |= RTF_LIMITED; - a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); - rdata = (resource_limit *)a->data.v; + rmt = rmt_create(rtype, "rm_stone"); + rdata = rtype->limit = calloc(1, sizeof(resource_limit)); rdata->value = 0; - rmt_create(rtype, "stone"); add_resource(u->region, 1, 300, 150, rtype); u->region->resources->amount = 300; /* there are 300 stones at level 1 */ set_level(u, SK_ALCHEMY, 10); diff --git a/src/items/seed.c b/src/items/seed.c index f17e8ed29..334c6a05d 100644 --- a/src/items/seed.c +++ b/src/items/seed.c @@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /* util includes */ #include @@ -31,6 +32,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include +#include static void produce_seeds(region * r, const resource_type * rtype, int norders) { @@ -48,14 +50,11 @@ static int limit_seeds(const region * r, const resource_type * rtype) void init_seed(void) { - attrib *a; - resource_limit *rdata; resource_type *rtype; rtype = rt_find("seed"); if (rtype != NULL) { - a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); - rdata = (resource_limit *)a->data.v; + resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit)); rdata->limit = limit_seeds; rdata->produce = produce_seeds; } @@ -80,17 +79,14 @@ static int limit_mallornseeds(const region * r, const resource_type * rtype) void init_mallornseed(void) { - attrib *a; - resource_limit *rdata; resource_type *rtype; rtype = rt_find("mallornseed"); if (rtype != NULL) { + resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit)); rtype->flags |= RTF_LIMITED; rtype->flags |= RTF_POOLED; - a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); - rdata = (resource_limit *)a->data.v; rdata->limit = limit_mallornseeds; rdata->produce = produce_mallornseeds; } diff --git a/src/kernel/item.c b/src/kernel/item.c index c37e3d40c..5beac7189 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1159,22 +1159,6 @@ const item_type *finditemtype(const char *name, const struct locale *lang) return 0; } -static void init_resourcelimit(attrib * a) -{ - a->data.v = calloc(sizeof(resource_limit), 1); -} - -static void finalize_resourcelimit(attrib * a) -{ - free(a->data.v); -} - -attrib_type at_resourcelimit = { - "resourcelimit", - init_resourcelimit, - finalize_resourcelimit, -}; - item *item_spoil(const struct race *rc, int size) { item *itm = NULL; diff --git a/src/kernel/item.h b/src/kernel/item.h index 79e6f103d..1d3e5ff29 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -29,6 +29,7 @@ extern "C" { struct unit; struct attrib; struct attrib_type; + struct race; struct region; struct resource_type; struct locale; @@ -37,6 +38,8 @@ extern "C" { struct order; struct storage; struct gamedata; + struct rawmaterial_type; + struct resource_limit; typedef struct item { struct item *next; @@ -76,6 +79,8 @@ extern "C" { rtype_uchange uchange; rtype_uget uget; rtype_name name; + struct rawmaterial_type *raw; + struct resource_limit *limit; /* --- pointers --- */ struct attrib *attribs; struct item_type *itype; @@ -94,25 +99,6 @@ extern "C" { #define RMF_SAVEMATERIAL 0x02 /* fraction (sa[0]/sa[1]), multiplier on resource usage */ #define RMF_REQUIREDBUILDING 0x04 /* building, required to build */ - typedef struct resource_mod { - variant value; - const struct building_type *btype; - const struct race *race; - unsigned int flags; - } resource_mod; - - extern struct attrib_type at_resourcelimit; - typedef int(*rlimit_limit) (const struct region * r, - const struct resource_type * rtype); - typedef void(*rlimit_produce) (struct region * r, - const struct resource_type * rtype, int n); - typedef struct resource_limit { - rlimit_limit limit; - rlimit_produce produce; - int value; - resource_mod *modifiers; - } resource_limit; - /* bitfield values for item_type::flags */ #define ITF_NONE 0x0000 #define ITF_HERB 0x0001 /* this item is a herb */ diff --git a/src/kernel/resources.c b/src/kernel/resources.c index e32c7ad55..d02153e8f 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -195,16 +195,16 @@ struct rawmaterial_type *rmt_find(const char *str) struct rawmaterial_type *rmt_get(const struct resource_type *rtype) { - rawmaterial_type *rmt = rawmaterialtypes; - while (rmt && rmt->rtype != rtype) - rmt = rmt->next; - return rmt; + return rtype->raw; } -struct rawmaterial_type *rmt_create(const struct resource_type *rtype, +struct rawmaterial_type *rmt_create(struct resource_type *rtype, const char *name) { - rawmaterial_type *rmtype = malloc(sizeof(rawmaterial_type)); + rawmaterial_type *rmtype; + + assert(!rtype->raw); + rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); rmtype->name = strdup(name); rmtype->rtype = rtype; rmtype->terraform = terraform_default; diff --git a/src/kernel/resources.h b/src/kernel/resources.h index a1a7abd40..dd4cfd664 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -15,6 +15,9 @@ extern "C" { #endif + struct building_type; + struct race; + enum { RM_USED = 1 << 0, /* resource has been used */ RM_MALLORN = 1 << 1 /* this is not wood. it's mallorn */ @@ -40,6 +43,25 @@ extern "C" { struct rawmaterial *next; } rawmaterial; + typedef int(*rlimit_limit) (const struct region * r, + const struct resource_type * rtype); + typedef void(*rlimit_produce) (struct region * r, + const struct resource_type * rtype, int n); + + typedef struct resource_mod { + variant value; + const struct building_type *btype; + const struct race *race; + unsigned int flags; + } resource_mod; + + typedef struct resource_limit { + rlimit_limit limit; + rlimit_produce produce; + int value; + resource_mod *modifiers; + } resource_limit; + typedef struct rawmaterial_type { char *name; const struct resource_type *rtype; @@ -64,7 +86,7 @@ extern "C" { void add_resource(struct region *r, int level, int base, int divisor, const struct resource_type *rtype); - struct rawmaterial_type *rmt_create(const struct resource_type *rtype, + struct rawmaterial_type *rmt_create(struct resource_type *rtype, const char *name); #ifdef __cplusplus diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 555c0f679..2d08f40a4 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -949,12 +949,6 @@ static int parse_resources(xmlDocPtr doc) rtype->flags |= flags; xmlFree(name); - name = xmlGetProp(node, BAD_CAST "material"); - if (name) { - rmt_create(rtype, (const char *)name); - xmlFree(name); - } - /* reading eressea/resources/resource/function */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "function", xpath); @@ -987,18 +981,20 @@ static int parse_resources(xmlDocPtr doc) } xmlXPathFreeObject(result); + name = xmlGetProp(node, BAD_CAST "material"); + if (name) { + rmt_create(rtype, (const char *)name); + xmlFree(name); + } + /* reading eressea/resources/resource/resourcelimit */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "resourcelimit", xpath); assert(result->nodesetval->nodeNr <= 1); if (result->nodesetval->nodeNr != 0) { - resource_limit *rdata; - attrib *a = a_find(rtype->attribs, &at_resourcelimit); + resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit)); xmlNodePtr limit = result->nodesetval->nodeTab[0]; - if (a == NULL) - a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); - rdata = (resource_limit *)a->data.v; rtype->flags |= RTF_LIMITED; xpath->node = limit; xmlXPathFreeObject(result); @@ -1095,7 +1091,6 @@ static int parse_resources(xmlDocPtr doc) } } xmlXPathFreeObject(result); - /* reading eressea/resources/resource/resourcelimit/function */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "resourcelimit/function", xpath); From f4dc88c3be008c9a4c3517c93d6284697789664d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Feb 2017 07:53:28 +0100 Subject: [PATCH 252/271] strip rawmaterial_type to just the funpointers --- src/kernel/item.c | 3 +++ src/kernel/resources.c | 14 +++++--------- src/kernel/resources.h | 4 ---- src/kernel/save.c | 2 +- src/reports.c | 12 ++++++------ 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/kernel/item.c b/src/kernel/item.c index 5beac7189..9bc321fdb 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1242,6 +1242,9 @@ void free_rtype(resource_type *rtype) { if (rtype->itype) { free_itype(rtype->itype); } + if (rtype->raw) { + free(rtype->raw); + } free(rtype->_name); free(rtype); } diff --git a/src/kernel/resources.c b/src/kernel/resources.c index d02153e8f..1261417f1 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -183,14 +183,13 @@ struct rawmaterial *rm_get(region * r, const struct resource_type *rtype) return rm; } -struct rawmaterial_type *rawmaterialtypes = 0; - struct rawmaterial_type *rmt_find(const char *str) { - rawmaterial_type *rmt = rawmaterialtypes; - while (rmt && strcmp(rmt->name, str) != 0) - rmt = rmt->next; - return rmt; + resource_type *rtype = rt_find(str); + if (!rtype && strncmp(str, "rm_", 3) == 0) { + rtype = rt_find(str+3); + } + return rtype ? rtype->raw : NULL; } struct rawmaterial_type *rmt_get(const struct resource_type *rtype) @@ -205,13 +204,10 @@ struct rawmaterial_type *rmt_create(struct resource_type *rtype, assert(!rtype->raw); rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); - rmtype->name = strdup(name); rmtype->rtype = rtype; rmtype->terraform = terraform_default; rmtype->update = NULL; rmtype->use = use_default; rmtype->visible = visible_default; - rmtype->next = rawmaterialtypes; - rawmaterialtypes = rmtype; return rmtype; } diff --git a/src/kernel/resources.h b/src/kernel/resources.h index dd4cfd664..9d248c0f8 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -63,16 +63,12 @@ extern "C" { } resource_limit; typedef struct rawmaterial_type { - char *name; const struct resource_type *rtype; void(*terraform) (struct rawmaterial *, const struct region *); void(*update) (struct rawmaterial *, const struct region *); void(*use) (struct rawmaterial *, const struct region *, int amount); int(*visible) (const struct rawmaterial *, int skilllevel); - - /* no initialization required */ - struct rawmaterial_type *next; } rawmaterial_type; extern struct rawmaterial_type *rawmaterialtypes; diff --git a/src/kernel/save.c b/src/kernel/save.c index d4045d05f..21ec98e76 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1068,7 +1068,7 @@ void writeregion(struct gamedata *data, const region * r) WRITE_INT(data->store, rhorses(r)); while (res) { - WRITE_TOK(data->store, res->type->name); + WRITE_TOK(data->store, res->type->rtype->_name); WRITE_INT(data->store, res->level); WRITE_INT(data->store, res->amount); WRITE_INT(data->store, res->startlevel); diff --git a/src/reports.c b/src/reports.c index a49957b9d..a70219b0b 100644 --- a/src/reports.c +++ b/src/reports.c @@ -412,32 +412,32 @@ const faction * viewer, bool see_unit) if (money) { if (n >= size) return -1; - report_resource(result + n, "rm_money", money, -1); + report_resource(result + n, "money", money, -1); ++n; } if (peasants) { if (n >= size) return -1; - report_resource(result + n, "rm_peasant", peasants, -1); + report_resource(result + n, "peasant", peasants, -1); ++n; } if (horses) { if (n >= size) return -1; - report_resource(result + n, "rm_horse", horses, -1); + report_resource(result + n, "horse", horses, -1); ++n; } if (saplings) { if (n >= size) return -1; - report_resource(result + n, mallorn ? "rm_mallornsapling" : "rm_sapling", + report_resource(result + n, mallorn ? "mallornsapling" : "sapling", saplings, -1); ++n; } if (trees) { if (n >= size) return -1; - report_resource(result + n, mallorn ? "rm_mallorn" : "rm_tree", trees, + report_resource(result + n, mallorn ? "mallorn" : "tree", trees, -1); ++n; } @@ -469,7 +469,7 @@ const faction * viewer, bool see_unit) if (level >= 0 && visible >= 0) { if (n >= size) return -1; - report_resource(result + n, res->type->name, visible, level); + report_resource(result + n, res->type->rtype->_name, visible, level); n++; } res = res->next; From be42137833d87889df5f157720df80432ba5746d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Feb 2017 08:02:24 +0100 Subject: [PATCH 253/271] fix rmt_find for trees --- src/economy.test.c | 2 +- src/kernel/resources.c | 16 +++++++++++++--- src/kernel/resources.h | 3 +-- src/kernel/xmlreader.c | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/economy.test.c b/src/economy.test.c index c67237c40..2de6265f0 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -382,7 +382,7 @@ static void test_make_item(CuTest *tc) { free(itype->construction->materials); itype->construction->materials = 0; rtype->flags |= RTF_LIMITED; - rmt = rmt_create(rtype, "rm_stone"); + rmt = rmt_create(rtype); rdata = rtype->limit = calloc(1, sizeof(resource_limit)); rdata->value = 0; add_resource(u->region, 1, 300, 150, rtype); diff --git a/src/kernel/resources.c b/src/kernel/resources.c index 1261417f1..e8be234a1 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -185,10 +185,21 @@ struct rawmaterial *rm_get(region * r, const struct resource_type *rtype) struct rawmaterial_type *rmt_find(const char *str) { + const char * replace[] = { "rm_tree", "log", NULL }; resource_type *rtype = rt_find(str); if (!rtype && strncmp(str, "rm_", 3) == 0) { - rtype = rt_find(str+3); + int i; + for (i = 0; replace[i]; i+=2) { + if (strcmp(replace[i], str) == 0) { + rtype = rt_find(replace[i+1]); + break; + } + } + if (!rtype) { + rtype = rt_find(str+3); + } } + assert(rtype); return rtype ? rtype->raw : NULL; } @@ -197,8 +208,7 @@ struct rawmaterial_type *rmt_get(const struct resource_type *rtype) return rtype->raw; } -struct rawmaterial_type *rmt_create(struct resource_type *rtype, - const char *name) +struct rawmaterial_type *rmt_create(struct resource_type *rtype) { rawmaterial_type *rmtype; diff --git a/src/kernel/resources.h b/src/kernel/resources.h index 9d248c0f8..3e93ea1de 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -82,8 +82,7 @@ extern "C" { void add_resource(struct region *r, int level, int base, int divisor, const struct resource_type *rtype); - struct rawmaterial_type *rmt_create(struct resource_type *rtype, - const char *name); + struct rawmaterial_type *rmt_create(struct resource_type *rtype); #ifdef __cplusplus } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2d08f40a4..9ba05e101 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -983,7 +983,7 @@ static int parse_resources(xmlDocPtr doc) name = xmlGetProp(node, BAD_CAST "material"); if (name) { - rmt_create(rtype, (const char *)name); + rmt_create(rtype); xmlFree(name); } From 9cbd5b88e6bf64f1f451a3e831bcb851181bfdc2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Feb 2017 08:07:47 +0100 Subject: [PATCH 254/271] rm_tree is not actually a thing --- src/kernel/resources.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/kernel/resources.c b/src/kernel/resources.c index e8be234a1..ae93d542a 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -185,19 +185,9 @@ struct rawmaterial *rm_get(region * r, const struct resource_type *rtype) struct rawmaterial_type *rmt_find(const char *str) { - const char * replace[] = { "rm_tree", "log", NULL }; resource_type *rtype = rt_find(str); if (!rtype && strncmp(str, "rm_", 3) == 0) { - int i; - for (i = 0; replace[i]; i+=2) { - if (strcmp(replace[i], str) == 0) { - rtype = rt_find(replace[i+1]); - break; - } - } - if (!rtype) { - rtype = rt_find(str+3); - } + rtype = rt_find(str+3); } assert(rtype); return rtype ? rtype->raw : NULL; From 5e2903258c64ce4b12ce0db3b5ca8f142ef91124 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Feb 2017 14:45:19 +0100 Subject: [PATCH 255/271] kill old element from XML --- res/adamantium.xml | 1 - res/core/resources/mallorn.xml | 1 - res/e3a/resources/iron.xml | 1 - 3 files changed, 3 deletions(-) diff --git a/res/adamantium.xml b/res/adamantium.xml index cc1cedadc..decc5636c 100644 --- a/res/adamantium.xml +++ b/res/adamantium.xml @@ -7,7 +7,6 @@ - diff --git a/res/core/resources/mallorn.xml b/res/core/resources/mallorn.xml index 2d301758e..fc678e79e 100644 --- a/res/core/resources/mallorn.xml +++ b/res/core/resources/mallorn.xml @@ -6,7 +6,6 @@ - diff --git a/res/e3a/resources/iron.xml b/res/e3a/resources/iron.xml index b245da358..06b70e45a 100644 --- a/res/e3a/resources/iron.xml +++ b/res/e3a/resources/iron.xml @@ -6,6 +6,5 @@ - From f06d86007c35780f1164405435b7320416fe32e1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Feb 2017 22:08:16 +0100 Subject: [PATCH 256/271] seed normalization (broken) --- res/core/resources/mallornseed.xml | 4 ++ res/core/resources/seed.xml | 4 ++ res/e3a/resources/seed.xml | 8 ++- scripts/eressea/resources.lua | 46 +++++++++++++-- scripts/tests/common.lua | 62 ++++++++++++-------- src/eressea.c | 9 ++- src/gmtool.c | 1 - src/items/CMakeLists.txt | 2 - src/items/itemtypes.c | 33 ----------- src/items/itemtypes.h | 25 -------- src/items/seed.c | 93 ------------------------------ src/items/seed.h | 31 ---------- src/kernel/xmlreader.c | 4 +- 13 files changed, 102 insertions(+), 220 deletions(-) delete mode 100644 src/items/itemtypes.c delete mode 100644 src/items/itemtypes.h delete mode 100644 src/items/seed.c delete mode 100644 src/items/seed.h diff --git a/res/core/resources/mallornseed.xml b/res/core/resources/mallornseed.xml index 7a5a0310f..01b8a3416 100644 --- a/res/core/resources/mallornseed.xml +++ b/res/core/resources/mallornseed.xml @@ -3,4 +3,8 @@ + + + + diff --git a/res/core/resources/seed.xml b/res/core/resources/seed.xml index 99f5f5804..2bda26eeb 100644 --- a/res/core/resources/seed.xml +++ b/res/core/resources/seed.xml @@ -3,4 +3,8 @@ + + + + diff --git a/res/e3a/resources/seed.xml b/res/e3a/resources/seed.xml index 21652f364..2bda26eeb 100644 --- a/res/e3a/resources/seed.xml +++ b/res/e3a/resources/seed.xml @@ -1,4 +1,10 @@ - + + + + + + + diff --git a/scripts/eressea/resources.lua b/scripts/eressea/resources.lua index 94908c1ab..2829d00c7 100644 --- a/scripts/eressea/resources.lua +++ b/scripts/eressea/resources.lua @@ -38,8 +38,47 @@ function hp_changeresource(u, delta) return hp end +local function mallorn_region(r) + return r:get_flag(1) -- RF_MALLORN +end + +function seed_limit(r) + if mallorn_region(r) then + return 0 + end + return r:get_resource("seed") +end + +function seed_produce(r, n) + if not mallorn_region(r) then + local seeds = r:get_resource("seed") + if seeds>=n then + r:set_resource("seed", seeds-n) + else + r:set_resource("seed", 0) + end + end +end + +function mallornseed_limit(r) + if mallorn_region(r) then + return r:get_resource("seed") + end + return 0 +end + +function mallornseed_produce(r, n) + if mallorn_region(r) then + local seeds = r:get_resource("seed") + if seeds>=n then + r:set_resource("seed", seeds-n) + else + r:set_resource("seed", 0) + end + end +end function horse_limit(r) - return r:get_resource("horse") + return r:get_resource("horse") end function horse_produce(r, n) @@ -52,9 +91,6 @@ function horse_produce(r, n) end function log_limit(r) --- if r:get_flag(1) then -- RF_MALLORN --- return 0 --- end return r:get_resource("tree") + r:get_resource("sapling") end @@ -75,7 +111,7 @@ function log_produce(r, n) end function mallorn_limit(r) - if not r:get_flag(1) then -- RF_MALLORN + if not mallorn_region(r) then return 0 end return r:get_resource("tree") + r:get_resource("sapling") diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 96673bfd3..27177d1b6 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -438,10 +438,9 @@ function test_recruit() u:add_item("money", 110*n+20) u:add_order("REKRUTIERE " .. n) process_orders() - assert(u.number == n+1) + assert_equal(n+1, u.number) local p = r:get_resource("peasant") - assert(p<200 and p>=200-n) - -- assert(u:get_item("money")==10) + assert_true(p<200 and p>=200-n) end function test_produce() @@ -468,7 +467,7 @@ function test_work() u:clear_orders() u:add_order("ARBEITEN") process_orders() - assert(u:get_item("money")>=10) + assert_equal(20, u:get_item("money")) end function test_upkeep() @@ -480,7 +479,7 @@ function test_upkeep() u:clear_orders() u:add_order("LERNE Waffenbau") process_orders() - assert(u:get_item("money")==u.number) + assert_equal(u:get_item("money"), u.number) end function test_id() @@ -488,50 +487,63 @@ function test_id() local f = faction.create("noreply11@eressea.de", "human", "de") f.id = atoi36("42") - assert(get_faction(42)~=f) - assert(get_faction("42")==f) - assert(get_faction(atoi36("42"))==f) + assert_not_equal(f, get_faction(42)) + assert_equal(f, get_faction("42")) + assert_equal(f, get_faction(atoi36("42"))) local u = unit.create(f, r, 1) u.id = atoi36("42") - assert(get_unit(42)~=u) - assert(get_unit("42")==u) - assert(get_unit(atoi36("42"))==u) + assert_not_equal(get_unit(42), u) + assert_equal(get_unit("42"), u) + assert_equal(get_unit(atoi36("42")), u) local b = building.create(r, "castle") -- b.id = atoi36("42") local fortytwo = itoa36(b.id) - assert(get_building(fortytwo)==b) - assert(get_building(atoi36(fortytwo))==b) + assert_equal(get_building(fortytwo), b) + assert_equal(get_building(atoi36(fortytwo)), b) local s = _test_create_ship(r) assert_not_nil(s) -- s.id = atoi36("42") local fortytwo = itoa36(s.id) - assert(get_ship(fortytwo)==s) - assert(get_ship(atoi36(fortytwo))==s) + assert_equal(get_ship(fortytwo), s) + assert_equal(get_ship(atoi36(fortytwo)), s) end function test_herbalism() - local r = region.create(0, 0, "plain") - local f = faction.create("noreply12@eressea.de", "human", "de") - local u = unit.create(f, r, 1) - u:add_item("money", u.number * 100) - u:set_skill("herbalism", 5) - u:clear_orders() - u:add_order("MACHE Samen") - process_orders() + local r = region.create(0, 0, "plain") + local f = faction.create("herbalism@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + + eressea.settings.set("rules.grow.formula", 0) -- plants do not grow + u:add_item("money", u.number * 100) + u:set_skill("herbalism", 5) + + r:set_resource("seed", 100) + r:set_flag(1, false) -- regular trees + u:clear_orders() + u:add_order("MACHE Samen") + process_orders() + assert_equal(1, u:get_item("seed")) + assert_equal(99, r:get_resource("seed")) + r:set_flag(1, true) -- mallorn + u:clear_orders() + u:add_order("MACHE Mallornsamen") + process_orders() + assert_equal(1, u:get_item("mallornseed")) + assert_equal(98, r:get_resource("seed")) end function test_mallorn() local r = region.create(0, 0, "plain") r:set_flag(1, false) -- not mallorn r:set_resource("tree", 100) - assert(r:get_resource("tree")==100) + assert_equal(100, r:get_resource("tree")) local m = region.create(0, 0, "plain") m:set_flag(1, true) -- mallorn m:set_resource("tree", 100) - assert(m:get_resource("tree")==100) + assert_equal(100, m:get_resource("tree")) local f = faction.create("noreply13@eressea.de", "human", "de") diff --git a/src/eressea.c b/src/eressea.c index dead153cb..07ea132a8 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -21,7 +21,10 @@ #include #include #include -#include +#include +#include +#include + #include #include #include @@ -81,7 +84,9 @@ void game_init(void) #endif wormholes_register(); - register_itemtypes(); + register_weapons(); + register_xerewards(); + register_artrewards(); #ifdef USE_LIBXML2 register_xmlreader(); #endif diff --git a/src/gmtool.c b/src/gmtool.c index 5a0cd576c..3551c3436 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -47,7 +47,6 @@ #include #include -#include #include #include diff --git a/src/items/CMakeLists.txt b/src/items/CMakeLists.txt index 0a2c581b4..b2bf2dfe5 100644 --- a/src/items/CMakeLists.txt +++ b/src/items/CMakeLists.txt @@ -7,8 +7,6 @@ xerewards.test.c SET(_FILES artrewards.c demonseye.c -itemtypes.c -seed.c speedsail.c weapons.c xerewards.c diff --git a/src/items/itemtypes.c b/src/items/itemtypes.c deleted file mode 100644 index 930829668..000000000 --- a/src/items/itemtypes.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - */ - -#include -#include "itemtypes.h" - -#include "xerewards.h" -#include "artrewards.h" -#include "weapons.h" -#include "seed.h" - -void register_itemtypes(void) -{ - /* registering misc. functions */ - register_weapons(); - register_xerewards(); - register_artrewards(); -} - -void init_itemtypes(void) -{ - init_seed(); - init_mallornseed(); -} diff --git a/src/items/itemtypes.h b/src/items/itemtypes.h deleted file mode 100644 index ec705c55b..000000000 --- a/src/items/itemtypes.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - */ - -#ifndef H_ITM_ITEMS -#define H_ITM_ITEMS -#ifdef __cplusplus -extern "C" { -#endif - - extern void init_itemtypes(void); - extern void register_itemtypes(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/items/seed.c b/src/items/seed.c deleted file mode 100644 index 334c6a05d..000000000 --- a/src/items/seed.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#include - -#include "seed.h" - -/* kernel includes */ -#include -#include -#include -#include - -/* util includes */ -#include -#include - -/* libc includes */ -#include -#include - -static void produce_seeds(region * r, const resource_type * rtype, int norders) -{ - assert(r->land && r->land->trees[0] >= norders); - r->land->trees[0] -= norders; -} - -static int limit_seeds(const region * r, const resource_type * rtype) -{ - if ((r->flags & RF_MALLORN)) { - return 0; - } - return r->land ? r->land->trees[0] : 0; -} - -void init_seed(void) -{ - resource_type *rtype; - - rtype = rt_find("seed"); - if (rtype != NULL) { - resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit)); - rdata->limit = limit_seeds; - rdata->produce = produce_seeds; - } -} - -/* mallorn */ - -static void -produce_mallornseeds(region * r, const resource_type * rtype, int norders) -{ - assert(r->flags & RF_MALLORN); - r->land->trees[0] -= norders; -} - -static int limit_mallornseeds(const region * r, const resource_type * rtype) -{ - if (!(r->flags & RF_MALLORN)) { - return 0; - } - return r->land ? r->land->trees[0] : 0; -} - -void init_mallornseed(void) -{ - resource_type *rtype; - - rtype = rt_find("mallornseed"); - if (rtype != NULL) { - resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit)); - rtype->flags |= RTF_LIMITED; - rtype->flags |= RTF_POOLED; - - rdata->limit = limit_mallornseeds; - rdata->produce = produce_mallornseeds; - } -} diff --git a/src/items/seed.h b/src/items/seed.h deleted file mode 100644 index c853adfde..000000000 --- a/src/items/seed.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef H_ITM_SEED -#define H_ITM_SEED -#ifdef __cplusplus -extern "C" { -#endif - - extern void init_seed(void); - extern void init_mallornseed(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 9ba05e101..27adba598 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1061,7 +1061,7 @@ static int parse_resources(xmlDocPtr doc) /* reading eressea/resources/resource/resourcelimit/function */ result = xmlXPathEvalExpression(BAD_CAST "function", xpath); - if (result->nodesetval != NULL) + if (result->nodesetval != NULL) { for (k = 0; k != result->nodesetval->nodeNr; ++k) { xmlNodePtr node = result->nodesetval->nodeTab[k]; pf_generic fun; @@ -1089,6 +1089,7 @@ static int parse_resources(xmlDocPtr doc) } xmlFree(propValue); } + } } xmlXPathFreeObject(result); /* reading eressea/resources/resource/resourcelimit/function */ @@ -1118,7 +1119,6 @@ static int parse_resources(xmlDocPtr doc) /* make sure old items (used in requirements) are available */ init_resources(); - init_itemtypes(); return 0; } From 6ce487e48511911e45dcb85c6354bfc894af9157 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Feb 2017 22:19:48 +0100 Subject: [PATCH 257/271] MACHE Samen geht in E3 nicht. limited ist unnoetig --- res/e3a/resources/mallornseed.xml | 2 +- res/e3a/resources/seed.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/res/e3a/resources/mallornseed.xml b/res/e3a/resources/mallornseed.xml index 4a348c212..576035b34 100644 --- a/res/e3a/resources/mallornseed.xml +++ b/res/e3a/resources/mallornseed.xml @@ -1,4 +1,4 @@ - + diff --git a/res/e3a/resources/seed.xml b/res/e3a/resources/seed.xml index 21652f364..62c971540 100644 --- a/res/e3a/resources/seed.xml +++ b/res/e3a/resources/seed.xml @@ -1,4 +1,4 @@ - + From 794dae11cf73b272c76867bc82643778351c5c6f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 14:29:14 +0100 Subject: [PATCH 258/271] remove artsculpture and genericbuilding. deal with buildings having an unknown type. --- res/core/common/buildings.xml | 3 +-- res/core/de/strings.xml | 2 +- res/core/en/strings.xml | 2 +- res/core/fr/strings.xml | 2 +- src/kernel/building.c | 9 +++++++-- src/kernel/save.c | 5 +++++ 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/res/core/common/buildings.xml b/res/core/common/buildings.xml index cf183086b..17f779843 100644 --- a/res/core/common/buildings.xml +++ b/res/core/common/buildings.xml @@ -4,9 +4,8 @@ - + - diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 97ded6e8d..002727630 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -912,7 +912,7 @@ Traumschlößchen - + Struktur diff --git a/res/core/en/strings.xml b/res/core/en/strings.xml index d80c742b9..063194c5d 100644 --- a/res/core/en/strings.xml +++ b/res/core/en/strings.xml @@ -310,7 +310,7 @@ dam - + structure diff --git a/res/core/fr/strings.xml b/res/core/fr/strings.xml index 7eb091570..c69bb5b75 100644 --- a/res/core/fr/strings.xml +++ b/res/core/fr/strings.xml @@ -324,7 +324,7 @@ barrage - + bâtiment diff --git a/src/kernel/building.c b/src/kernel/building.c index 3c21f4dbe..6d0db8f43 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -325,8 +325,13 @@ const building_type *findbuildingtype(const char *name, building_type *btype = (building_type *)selist_get(ql, qi); const char *n = LOC(lang, btype->_name); - type.v = (void *)btype; - addtoken((struct tnode **)&bn->names, n, type); + if (!n) { + log_error("building type %s has no translation in %s", + btype->_name, locale_name(lang)); + } else { + type.v = (void *)btype; + addtoken((struct tnode **)&bn->names, n, type); + } } bnames = bn; } diff --git a/src/kernel/save.c b/src/kernel/save.c index 21ec98e76..8316121f3 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1529,6 +1529,11 @@ struct building *read_building(gamedata *data) { READ_INT(store, &b->size); READ_STR(store, name, sizeof(name)); b->type = bt_find(name); + if (!b->type) { + log_error("building %d has unknown type %s", b->no, name); + b->type = bt_find("building"); + assert(b->type); + } read_attribs(data, &b->attribs, b); /* repairs, bug 2221: */ From 2d4b61afa90c938468c730e017eff7bbc5393ead Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 14:32:18 +0100 Subject: [PATCH 259/271] the artacademy was E2-only --- res/core/common/buildings.xml | 1 - res/core/de/strings.xml | 8 -------- res/eressea/buildings.xml | 1 + res/eressea/strings.xml | 8 ++++++++ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/res/core/common/buildings.xml b/res/core/common/buildings.xml index 17f779843..540e9f085 100644 --- a/res/core/common/buildings.xml +++ b/res/core/common/buildings.xml @@ -5,7 +5,6 @@ - diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 002727630..5bde79c29 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -915,14 +915,6 @@ Struktur - - Akademie der Künste - academy of arts - - - Skulptur - sculpture - diff --git a/res/eressea/buildings.xml b/res/eressea/buildings.xml index 64d65cff0..670ab484e 100644 --- a/res/eressea/buildings.xml +++ b/res/eressea/buildings.xml @@ -4,4 +4,5 @@ + diff --git a/res/eressea/strings.xml b/res/eressea/strings.xml index 61a35ebe5..28547679d 100644 --- a/res/eressea/strings.xml +++ b/res/eressea/strings.xml @@ -352,6 +352,14 @@ + + Akademie der Künste + academy of arts + + + Skulptur + sculpture + Horn des Tanzes horn of dancing From 25d3aacffaf6b19b1352b037f31ba45df31f78dc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 14:38:08 +0100 Subject: [PATCH 260/271] remove artrewards, they predate my backups --- res/eressea/artrewards.xml | 14 ---- res/eressea/items.xml | 13 ---- res/eressea/strings.xml | 36 --------- res/items.xml | 3 - src/eressea.c | 2 - src/items/CMakeLists.txt | 1 - src/items/artrewards.c | 155 ------------------------------------- src/items/artrewards.h | 30 ------- 8 files changed, 254 deletions(-) delete mode 100644 res/items.xml delete mode 100644 src/items/artrewards.c delete mode 100644 src/items/artrewards.h diff --git a/res/eressea/artrewards.xml b/res/eressea/artrewards.xml index 6cb836c52..2a3c09950 100644 --- a/res/eressea/artrewards.xml +++ b/res/eressea/artrewards.xml @@ -1,20 +1,6 @@ - - - - - - - - - - - - - - diff --git a/res/eressea/items.xml b/res/eressea/items.xml index 8b2df7add..69f84c890 100644 --- a/res/eressea/items.xml +++ b/res/eressea/items.xml @@ -63,19 +63,6 @@ - - - - - - - - - - - - - diff --git a/res/eressea/strings.xml b/res/eressea/strings.xml index 28547679d..f7497b810 100644 --- a/res/eressea/strings.xml +++ b/res/eressea/strings.xml @@ -356,42 +356,6 @@ Akademie der Künste academy of arts - - Skulptur - sculpture - - - Horn des Tanzes - horn of dancing - - - Hörner des Tanzes - horns of dancing - - - Miniatur einer Akademie der Künste - academy of arts in a box - - - Miniaturen einer Akademie der Künste - academies of arts in a box - - - Miniatur einer Skulptur - art sculpture in a box - - - Miniaturen einer Skulptur - art sculptures in a box - - - Gefangener Windgeist - trapped air elemental - - - Gefangene Windgeister - trapped air elementals - Auratrank aura potion diff --git a/res/items.xml b/res/items.xml deleted file mode 100644 index 108e6d398..000000000 --- a/res/items.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/eressea.c b/src/eressea.c index 07ea132a8..8001355f1 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -86,7 +85,6 @@ void game_init(void) register_weapons(); register_xerewards(); - register_artrewards(); #ifdef USE_LIBXML2 register_xmlreader(); #endif diff --git a/src/items/CMakeLists.txt b/src/items/CMakeLists.txt index b2bf2dfe5..bbf192a66 100644 --- a/src/items/CMakeLists.txt +++ b/src/items/CMakeLists.txt @@ -5,7 +5,6 @@ xerewards.test.c ) SET(_FILES -artrewards.c demonseye.c speedsail.c weapons.c diff --git a/src/items/artrewards.c b/src/items/artrewards.c deleted file mode 100644 index 23ab2119e..000000000 --- a/src/items/artrewards.c +++ /dev/null @@ -1,155 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#include -#include "artrewards.h" - -/* kernel includes */ -#include -#include -#include -#include -#include -#include -#include -#include - -/* util includes */ -#include -#include - -/* libc includes */ -#include -#include -#include -#include - -#define HORNRANGE 10 -#define HORNDURATION 3 -#define HORNIMMUNITY 30 - -static int age_peaceimmune(attrib * a, void *owner) -{ - UNUSED_ARG(owner); - return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; -} - -static attrib_type at_peaceimmune = { - "peaceimmune", - NULL, NULL, - age_peaceimmune, - a_writeint, - a_readint -}; - -static int -use_hornofdancing(struct unit *u, const struct item_type *itype, -int amount, struct order *ord) -{ - region *r; - int regionsPacified = 0; - - for (r = regions; r; r = r->next) { - if (distance(u->region, r) < HORNRANGE) { - if (a_find(r->attribs, &at_peaceimmune) == NULL) { - attrib *a; - - create_curse(u, &r->attribs, ct_find("peacezone"), - 20, HORNDURATION, 1.0, 0); - - a = a_add(&r->attribs, a_new(&at_peaceimmune)); - a->data.i = HORNIMMUNITY; - - ADDMSG(&r->msgs, msg_message("hornofpeace_r_success", - "unit region", u, u->region)); - - regionsPacified++; - } - else { - ADDMSG(&r->msgs, msg_message("hornofpeace_r_nosuccess", - "unit region", u, u->region)); - } - } - } - - if (regionsPacified > 0) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success", - "pacified", regionsPacified)); - } - else { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess", - "")); - } - - return 0; -} - -#define SPEEDUP 2 - -static int -useonother_trappedairelemental(struct unit *u, int shipId, -const struct item_type *itype, int amount, struct order *ord) -{ - curse *c; - ship *sh; - - if (shipId <= 0) { - cmistake(u, ord, 20, MSG_MOVE); - return -1; - } - - sh = findshipr(u->region, shipId); - if (!sh) { - cmistake(u, ord, 20, MSG_MOVE); - return -1; - } - - c = - create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP, - 0); - c_setflag(c, CURSE_NOAGE); - - ADDMSG(&u->faction->msgs, msg_message("trappedairelemental_success", - "unit region command ship", u, u->region, ord, sh)); - - use_pooled(u, itype->rtype, GET_DEFAULT, 1); - - return 0; -} - -static int -use_trappedairelemental(struct unit *u, -const struct item_type *itype, int amount, struct order *ord) -{ - ship *sh = u->ship; - - if (sh == NULL) { - cmistake(u, ord, 20, MSG_MOVE); - return -1; - } - return useonother_trappedairelemental(u, sh->no, itype, amount, ord); -} - -void register_artrewards(void) -{ - at_register(&at_peaceimmune); - register_item_use(use_hornofdancing, "use_hornofdancing"); - register_item_use(use_trappedairelemental, "use_trappedairelemental"); - register_item_useonother(useonother_trappedairelemental, - "useonother_trappedairelemental"); -} diff --git a/src/items/artrewards.h b/src/items/artrewards.h deleted file mode 100644 index 779e7cc5f..000000000 --- a/src/items/artrewards.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef H_ITM_ARTREWARDS -#define H_ITM_ARTREWARDS -#ifdef __cplusplus -extern "C" { -#endif - - extern void register_artrewards(void); - -#ifdef __cplusplus -} -#endif -#endif From 158e0646e1b5b8059f8863b93b5dc0e6f8427064 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 15:48:49 +0100 Subject: [PATCH 261/271] implement fractions --- src/util/CMakeLists.txt | 1 + src/util/variant.c | 36 ++++++++++++++++++++++++++++++++++++ src/util/variant.h | 6 ++++++ 3 files changed, 43 insertions(+) create mode 100644 src/util/variant.c diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 842bcf58c..743ff4d88 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -56,6 +56,7 @@ strings.c translation.c umlaut.c unicode.c +variant.c xml.c ) FOREACH(_FILE ${_FILES}) diff --git a/src/util/variant.c b/src/util/variant.c new file mode 100644 index 000000000..e3461f861 --- /dev/null +++ b/src/util/variant.c @@ -0,0 +1,36 @@ +#include "variant.h" +#include + +static int lcd(int a, int b) { + return a * b; +} + +variant frac_add(variant a, variant b) +{ + int num, den; + variant v; + den = lcd(a.sa[1], b.sa[1]); + num = a.sa[0] * lcd / a.sa[1] + b.sa[0] * lcd / b.sa[1]; + assert(num >= SHRT_MIN && num <= SHRT_MAX); + assert(den >= SHRT_MIN && den <= SHRT_MAX); + v.sa[0] = (short)num; + v.sa[1] = (short)den; + return v; +} + +variant frac_mul(variant a, variant b) +{ + variant v = a; + return v; +} + +variant frac_div(variant a, variant b) +{ + variant v = a; + return v; +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/util/variant.h b/src/util/variant.h index b65ee0868..8c78bc3ac 100644 --- a/src/util/variant.h +++ b/src/util/variant.h @@ -1,3 +1,5 @@ +#pragma once + #ifndef STRUCT_VARIANT_H #define STRUCT_VARIANT_H #ifdef __cplusplus @@ -19,6 +21,10 @@ extern "C" { VAR_FLOAT } variant_type; + variant frac_add(variant a, variant b); + variant frac_mul(variant a, variant b); + variant frac_div(variant a, variant b); + #ifdef __cplusplus } #endif From 234eb62226d665880b23e808ba2817fed66a7c76 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 17:51:35 +0100 Subject: [PATCH 262/271] short and sweet math with fractions. goinf to use this for magres. --- src/test_eressea.c | 2 ++ src/util/CMakeLists.txt | 1 + src/util/variant.c | 54 +++++++++++++++++++++++++++++------------ src/util/variant.h | 1 + src/util/variant.test.c | 28 +++++++++++++++++++++ 5 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 src/util/variant.test.c diff --git a/src/test_eressea.c b/src/test_eressea.c index 4ffe1f19c..1d991725f 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -6,6 +6,7 @@ #include #include #include +#include #pragma warning(disable: 4210) @@ -85,6 +86,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(unicode); ADD_SUITE(strings); ADD_SUITE(log); + ADD_SUITE(variant); ADD_SUITE(rng); /* items */ ADD_SUITE(xerewards); diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 743ff4d88..91ed118ae 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -28,6 +28,7 @@ log.test.c # translation.test.c umlaut.test.c unicode.test.c +variant.test.c # xml.test.c ) diff --git a/src/util/variant.c b/src/util/variant.c index e3461f861..74d7adb1c 100644 --- a/src/util/variant.c +++ b/src/util/variant.c @@ -1,16 +1,39 @@ +#include #include "variant.h" + +#include #include -static int lcd(int a, int b) { - return a * b; +static int gcd(int a, int b) { + const int primes[] = { 3, 5, 7, 11, 13, 17, 19, 23, 0 }; + int i = 0, g = 1, p = 2; + while (p && p <= a && p <= b) { + if (a % p == 0 && b % p == 0) { + a /= p; + b /= p; + g *= p; + } + else { + p = primes[i++]; + } + } + return g; } -variant frac_add(variant a, variant b) +static int lcm(int a, int b) { + int x; + if (a == b) return a; + x = (a * b); + x = (x > 0 ? x : -x) / gcd(a, b); + return x; +} + +variant frac_make(int num, int den) { - int num, den; variant v; - den = lcd(a.sa[1], b.sa[1]); - num = a.sa[0] * lcd / a.sa[1] + b.sa[0] * lcd / b.sa[1]; + int g = gcd(num, den); + num /= g; + den /= g; assert(num >= SHRT_MIN && num <= SHRT_MAX); assert(den >= SHRT_MIN && den <= SHRT_MAX); v.sa[0] = (short)num; @@ -18,19 +41,20 @@ variant frac_add(variant a, variant b) return v; } +variant frac_add(variant a, variant b) +{ + int num, den; + den = lcm(a.sa[1], b.sa[1]); + num = a.sa[0] * den / a.sa[1] + b.sa[0] * den / b.sa[1]; + return frac_make(num, den); +} + variant frac_mul(variant a, variant b) { - variant v = a; - return v; + return frac_make(a.sa[0] * b.sa[0], a.sa[1] * b.sa[1]); } variant frac_div(variant a, variant b) { - variant v = a; - return v; + return frac_make(a.sa[0] * b.sa[1], a.sa[1] * b.sa[0]); } - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/util/variant.h b/src/util/variant.h index 8c78bc3ac..f98fa0b80 100644 --- a/src/util/variant.h +++ b/src/util/variant.h @@ -21,6 +21,7 @@ extern "C" { VAR_FLOAT } variant_type; + variant frac_make(int num, int den); variant frac_add(variant a, variant b); variant frac_mul(variant a, variant b); variant frac_div(variant a, variant b); diff --git a/src/util/variant.test.c b/src/util/variant.test.c new file mode 100644 index 000000000..6344e5c33 --- /dev/null +++ b/src/util/variant.test.c @@ -0,0 +1,28 @@ +#include +#include "variant.h" + +#include + +static void test_fractions(CuTest *tc) { + variant a, b; + a = frac_make(120, 12000); + CuAssertIntEquals(tc, 1, a.sa[0]); + CuAssertIntEquals(tc, 100, a.sa[1]); + b = frac_make(23, 2300); + a = frac_add(a, b); + CuAssertIntEquals(tc, 1, a.sa[0]); + CuAssertIntEquals(tc, 50, a.sa[1]); + a = frac_mul(a, b); + CuAssertIntEquals(tc, 1, a.sa[0]); + CuAssertIntEquals(tc, 5000, a.sa[1]); + a = frac_div(b, b); + CuAssertIntEquals(tc, 1, a.sa[0]); + CuAssertIntEquals(tc, 1, a.sa[1]); +} + +CuSuite *get_variant_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_fractions); + return suite; +} From e0229be5007f14e85162b65808bbe3617c2da300 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 17:55:06 +0100 Subject: [PATCH 263/271] also implement subtraction. --- src/util/variant.c | 6 ++++++ src/util/variant.h | 1 + src/util/variant.test.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/util/variant.c b/src/util/variant.c index 74d7adb1c..2ffe4a4e3 100644 --- a/src/util/variant.c +++ b/src/util/variant.c @@ -49,6 +49,12 @@ variant frac_add(variant a, variant b) return frac_make(num, den); } +variant frac_sub(variant a, variant b) +{ + b.sa[0] = -b.sa[0]; + return frac_add(a, b); +} + variant frac_mul(variant a, variant b) { return frac_make(a.sa[0] * b.sa[0], a.sa[1] * b.sa[1]); diff --git a/src/util/variant.h b/src/util/variant.h index f98fa0b80..4bd5d952d 100644 --- a/src/util/variant.h +++ b/src/util/variant.h @@ -23,6 +23,7 @@ extern "C" { variant frac_make(int num, int den); variant frac_add(variant a, variant b); + variant frac_sub(variant a, variant b); variant frac_mul(variant a, variant b); variant frac_div(variant a, variant b); diff --git a/src/util/variant.test.c b/src/util/variant.test.c index 6344e5c33..793e4f683 100644 --- a/src/util/variant.test.c +++ b/src/util/variant.test.c @@ -18,6 +18,10 @@ static void test_fractions(CuTest *tc) { a = frac_div(b, b); CuAssertIntEquals(tc, 1, a.sa[0]); CuAssertIntEquals(tc, 1, a.sa[1]); + a = frac_sub(a, a); + CuAssertIntEquals(tc, 0, a.sa[0]); + a = frac_mul(a, b); + CuAssertIntEquals(tc, 0, a.sa[0]); } CuSuite *get_variant_suite(void) From e557140ad1038dc745c656f06c76c3a0696fa618 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 20:47:31 +0100 Subject: [PATCH 264/271] more fractions functionality. --- src/util/variant.c | 14 ++++++++++++++ src/util/variant.h | 8 ++++++++ src/util/variant.test.c | 10 +++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/util/variant.c b/src/util/variant.c index 2ffe4a4e3..c1d42808d 100644 --- a/src/util/variant.c +++ b/src/util/variant.c @@ -4,6 +4,9 @@ #include #include +const variant frac_zero = { .sa = { 0, 1 } }; +const variant frac_one = { .sa = { 1, 1 } }; + static int gcd(int a, int b) { const int primes[] = { 3, 5, 7, 11, 13, 17, 19, 23, 0 }; int i = 0, g = 1, p = 2; @@ -28,6 +31,10 @@ static int lcm(int a, int b) { return x; } +bool frac_equal(variant a, variant b) { + return frac_sign(frac_sub(a, b)) == 0; +} + variant frac_make(int num, int den) { variant v; @@ -64,3 +71,10 @@ variant frac_div(variant a, variant b) { return frac_make(a.sa[0] * b.sa[1], a.sa[1] * b.sa[0]); } + +int frac_sign(variant a) { + if (a.sa[0] == 0) return 0; + if (a.sa[0] > 0 && a.sa[1] > 0) return 1; + if (a.sa[0] < 0 && a.sa[1] < 0) return 1; + return -1; +} diff --git a/src/util/variant.h b/src/util/variant.h index 4bd5d952d..ae75c5cda 100644 --- a/src/util/variant.h +++ b/src/util/variant.h @@ -2,6 +2,9 @@ #ifndef STRUCT_VARIANT_H #define STRUCT_VARIANT_H + +#include + #ifdef __cplusplus extern "C" { #endif @@ -21,11 +24,16 @@ extern "C" { VAR_FLOAT } variant_type; + extern const variant frac_zero; + extern const variant frac_one; + variant frac_make(int num, int den); variant frac_add(variant a, variant b); variant frac_sub(variant a, variant b); variant frac_mul(variant a, variant b); variant frac_div(variant a, variant b); + int frac_sign(variant a); + bool frac_equal(variant a, variant b); #ifdef __cplusplus } diff --git a/src/util/variant.test.c b/src/util/variant.test.c index 793e4f683..12299720b 100644 --- a/src/util/variant.test.c +++ b/src/util/variant.test.c @@ -20,8 +20,16 @@ static void test_fractions(CuTest *tc) { CuAssertIntEquals(tc, 1, a.sa[1]); a = frac_sub(a, a); CuAssertIntEquals(tc, 0, a.sa[0]); - a = frac_mul(a, b); + a = frac_sub(frac_one, a); + CuAssertIntEquals(tc, 1, a.sa[0]); + CuAssertIntEquals(tc, 1, a.sa[1]); + a = frac_mul(a, frac_zero); CuAssertIntEquals(tc, 0, a.sa[0]); + CuAssertIntEquals(tc, 1, frac_sign(frac_make(-1, -1))); + CuAssertIntEquals(tc, 1, frac_sign(frac_make(1, 1))); + CuAssertIntEquals(tc, -1, frac_sign(frac_make(-1, 1))); + CuAssertIntEquals(tc, -1, frac_sign(frac_make(1, -1))); + CuAssertIntEquals(tc, 0, frac_sign(frac_make(0, 1))); } CuSuite *get_variant_suite(void) From 3a985108a669d300408cb93a77e7898e2518fb1f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 24 Feb 2017 20:47:47 +0100 Subject: [PATCH 265/271] change all magic resistance to use fractions. --- src/battle.c | 36 ++++++++++------ src/battle.h | 2 +- src/battle.test.c | 67 ++++++++++++++++------------- src/economy.test.c | 2 +- src/guard.test.c | 6 +-- src/kernel/building.h | 2 +- src/kernel/building.test.c | 2 +- src/kernel/item.c | 4 +- src/kernel/item.h | 10 ++--- src/kernel/jsonconf.c | 2 +- src/kernel/jsonconf.test.c | 3 +- src/kernel/race.c | 5 ++- src/kernel/race.h | 4 +- src/kernel/race.test.c | 3 +- src/kernel/xmlreader.c | 47 ++++++++------------ src/laws.test.c | 4 +- src/magic.c | 88 ++++++++++++++++++++++++-------------- src/magic.h | 2 +- src/magic.test.c | 12 +++--- src/spells.c | 7 ++- src/spy.test.c | 2 +- src/volcano.c | 11 +++-- 22 files changed, 178 insertions(+), 143 deletions(-) diff --git a/src/battle.c b/src/battle.c index 23c219109..9864adc41 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1059,7 +1059,7 @@ static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_ return modifier; } -int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awtype, double *magres) { +int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awtype, variant *magres) { fighter *df = dt.fighter; unit *du = df->unit; int ar = 0, an, am; @@ -1110,21 +1110,31 @@ int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awty if (magres) { /* calculate damage multiplier for magical damage */ - double res = 1.0 - magic_resistance(du); + variant res; + + res = frac_sub(frac_one, magic_resistance(du)); if (u_race(du)->battle_flags & BF_EQUIPMENT) { /* der Effekt von Laen steigt nicht linear */ - if (armor && fval(armor, ATF_LAEN)) - res *= (1 - armor->magres); - if (shield && fval(shield, ATF_LAEN)) - res *= (1 - shield->magres); - if (dwtype) - res *= (1 - dwtype->magres); + if (armor && fval(armor, ATF_LAEN)) { + res = frac_mul(res, frac_sub(frac_one, armor->magres)); + } + if (shield && fval(shield, ATF_LAEN)) { + res = frac_mul(res, frac_sub(frac_one, shield->magres)); + } + if (dwtype) { + res = frac_mul(res, frac_sub(frac_one, dwtype->magres)); + } } - /* gegen Magie wirkt nur nat�rliche und magische R�stung */ + /* gegen Magie wirkt nur natuerliche und magische Ruestung */ ar = an + am; - *magres = res > 0 ? res : 0; + if (res.sa[0] >= 0) { + *magres = res; + } + else { + *magres = frac_make(0, 1); + } } return ar; @@ -1147,7 +1157,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) const weapon_type *dwtype = NULL; const weapon_type *awtype = NULL; const weapon *weapon; - double res = 1.0; + variant res = frac_make(1, 1); int rda, sk = 0, sd; bool magic = false; @@ -1190,9 +1200,9 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) return false; } - /* TODO not sure if res could be > 1 here */ if (magic) { - da = (int)(MAX(da * res, 0)); + res = frac_mul(frac_make(da, 1), res); + da = res.sa[0] / res.sa[1]; } if (type != AT_COMBATSPELL && type != AT_SPELL) { diff --git a/src/battle.h b/src/battle.h index 1b4cf2588..85e65cf66 100644 --- a/src/battle.h +++ b/src/battle.h @@ -248,7 +248,7 @@ extern "C" { int count_enemies(struct battle *b, const struct fighter *af, int minrow, int maxrow, int select); int natural_armor(struct unit * u); - int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, double *magres); + int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, union variant *magres); bool terminate(troop dt, troop at, int type, const char *damage, bool missile); extern void message_all(battle * b, struct message *m); diff --git a/src/battle.test.c b/src/battle.test.c index d15c335a9..b00d06a98 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -250,23 +250,24 @@ static void test_calculate_armor(CuTest * tc) armor_type *ashield, *achain; item_type *ibelt, *ishield, *ichain; race *rc; - double magres = 0.0; + variant magres = frac_zero; + variant v50p = frac_make(1, 2); test_setup(); r = test_create_region(0, 0, 0); ibelt = it_get_or_create(rt_get_or_create("trollbelt")); ishield = it_get_or_create(rt_get_or_create("shield")); - ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD); + ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD); ichain = it_get_or_create(rt_get_or_create("chainmail")); - achain = new_armortype(ichain, 0.0, 0.5, 3, ATF_NONE); - wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1); + achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE); + wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1); rc = test_create_race("human"); du = test_create_unit(test_create_faction(rc), r); dt.index = 0; dt.fighter = setup_fighter(&b, du); CuAssertIntEquals_Msg(tc, "default ac", 0, calculate_armor(dt, 0, 0, &magres)); - CuAssertDblEquals_Msg(tc, "magres unmodified", 1.0, magres, 0.01); + CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[0], magres.sa[1]); free_battle(b); b = NULL; @@ -299,13 +300,13 @@ static void test_calculate_armor(CuTest * tc) wtype->flags = WTF_NONE; CuAssertIntEquals_Msg(tc, "magical attack", 3, calculate_armor(dt, 0, 0, &magres)); - CuAssertDblEquals_Msg(tc, "magres unmodified", 1.0, magres, 0.01); + CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[1], magres.sa[0]); ashield->flags |= ATF_LAEN; achain->flags |= ATF_LAEN; - magres = 1.0; + magres = frac_one; CuAssertIntEquals_Msg(tc, "laen armor", 3, calculate_armor(dt, 0, 0, &magres)); - CuAssertDblEquals_Msg(tc, "laen magres bonus", 0.25, magres, 0.01); + CuAssertIntEquals_Msg(tc, "laen magres bonus", 4, magres.sa[1]); free_battle(b); test_cleanup(); } @@ -319,38 +320,42 @@ static void test_magic_resistance(CuTest *tc) armor_type *ashield, *achain; item_type *ishield, *ichain; race *rc; - double magres; + variant magres; + variant v50p = frac_make(1, 2); + variant v10p = frac_make(1, 10); test_setup(); r = test_create_region(0, 0, 0); ishield = it_get_or_create(rt_get_or_create("shield")); - ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD); + ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD); ichain = it_get_or_create(rt_get_or_create("chainmail")); - achain = new_armortype(ichain, 0.0, 0.5, 3, ATF_NONE); + achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE); rc = test_create_race("human"); du = test_create_unit(test_create_faction(rc), r); dt.index = 0; + i_change(&du->items, ishield, 1); dt.fighter = setup_fighter(&b, du); calculate_armor(dt, 0, 0, &magres); - CuAssertDblEquals_Msg(tc, "no magres bonus", 0.0, magic_resistance(du), 0.01); - CuAssertDblEquals_Msg(tc, "no magres reduction", 1.0, magres, 0.01); + CuAssertIntEquals_Msg(tc, "no magres reduction", magres.sa[1], magres.sa[0]); + magres = magic_resistance(du); + CuAssertIntEquals_Msg(tc, "no magres reduction", 0, magres.sa[0]); ashield->flags |= ATF_LAEN; - ashield->magres = 0.1; + ashield->magres = v10p; calculate_armor(dt, 0, 0, &magres); + CuAssert(tc, "laen reduction => 10%%", frac_equal(frac_make(9, 10), magres)); free_battle(b); b = NULL; - i_change(&du->items, ishield, 1); i_change(&du->items, ichain, 1); achain->flags |= ATF_LAEN; - achain->magres = 0.1; + achain->magres = v10p; ashield->flags |= ATF_LAEN; - ashield->magres = 0.1; + ashield->magres = v10p; dt.fighter = setup_fighter(&b, du); calculate_armor(dt, 0, 0, &magres); - CuAssertDblEquals_Msg(tc, "laen reduction", 0.81, magres, 0.01); + CuAssert(tc, "2x laen reduction => 81%%", frac_equal(frac_make(81, 100), magres)); free_battle(b); b = NULL; @@ -359,17 +364,20 @@ static void test_magic_resistance(CuTest *tc) set_level(du, SK_MAGIC, 2); dt.fighter = setup_fighter(&b, du); calculate_armor(dt, 0, 0, &magres); - CuAssertDblEquals_Msg(tc, "skill bonus", 0.1, magic_resistance(du), 0.01); - CuAssertDblEquals_Msg(tc, "skill reduction", 0.9, magres, 0.01); - rc->magres = 50; /* percentage, gets added to skill bonus */ + CuAssert(tc, "skill reduction => 90%%", frac_equal(magres, frac_make(9, 10))); + magres = magic_resistance(du); + CuAssert(tc, "skill reduction", frac_equal(magres, v10p)); + rc->magres = v50p; /* percentage, gets added to skill bonus */ calculate_armor(dt, 0, 0, &magres); - CuAssertDblEquals_Msg(tc, "race bonus", 0.6, magic_resistance(du), 0.01); - CuAssertDblEquals_Msg(tc, "race reduction", 0.4, magres, 0.01); + CuAssert(tc, "race reduction => 40%%", frac_equal(magres, frac_make(4, 10))); + magres = magic_resistance(du); + CuAssert(tc, "race bonus => 60%%", frac_equal(magres, frac_make(60, 100))); - rc->magres = 150; /* should not cause negative damage multiplier */ - CuAssertDblEquals_Msg(tc, "magic resistance is never > 0.9", 0.9, magic_resistance(du), 0.01); + rc->magres = frac_make(15, 10); /* 150% resistance should not cause negative damage multiplier */ + magres = magic_resistance(du); + CuAssert(tc, "magic resistance is never > 0.9", frac_equal(magres, frac_make(9, 10))); calculate_armor(dt, 0, 0, &magres); - CuAssertDblEquals_Msg(tc, "damage reduction is never < 0.1", 0.1, magres, 0.01); + CuAssert(tc, "damage reduction is never < 0.1", frac_equal(magres, frac_make(1, 10))); free_battle(b); test_cleanup(); @@ -385,14 +393,15 @@ static void test_projectile_armor(CuTest * tc) armor_type *ashield, *achain; item_type *ishield, *ichain; race *rc; + variant v50p = frac_make(1, 2); test_setup(); r = test_create_region(0, 0, 0); ishield = it_get_or_create(rt_get_or_create("shield")); - ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD); + ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD); ichain = it_get_or_create(rt_get_or_create("chainmail")); - achain = new_armortype(ichain, 0.0, 0.5, 3, ATF_NONE); - wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1); + achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE); + wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1); rc = test_create_race("human"); rc->battle_flags |= BF_EQUIPMENT; du = test_create_unit(test_create_faction(rc), r); diff --git a/src/economy.test.c b/src/economy.test.c index 2de6265f0..4ddd20105 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -211,7 +211,7 @@ static void test_tax_cmd(CuTest *tc) { silver = get_resourcetype(R_SILVER)->itype; sword = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(sword, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 1); + new_weapontype(sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 1); i_change(&u->items, sword, 1); set_level(u, SK_MELEE, 1); diff --git a/src/guard.test.c b/src/guard.test.c index fb55129ee..17aa2891c 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -42,7 +42,7 @@ static void test_guard_unskilled(CuTest * tc) test_setup(); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); r = test_create_region(0, 0, 0); u = test_create_unit(test_create_faction(0), r); ug = test_create_unit(test_create_faction(0), r); @@ -61,7 +61,7 @@ static void test_guard_armed(CuTest * tc) test_setup(); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); r = test_create_region(0, 0, 0); u = test_create_unit(test_create_faction(0), r); ug = test_create_unit(test_create_faction(0), r); @@ -80,7 +80,7 @@ static void test_is_guard(CuTest * tc) test_setup(); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); r = test_create_region(0, 0, 0); ug = test_create_unit(test_create_faction(0), r); i_change(&ug->items, itype, 1); diff --git a/src/kernel/building.h b/src/kernel/building.h index 8c23fdb7c..6d66aa9ab 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -60,7 +60,7 @@ extern "C" { int capacity; /* Kapazit�t pro Gr��enpunkt */ int maxcapacity; /* Max. Kapazit�t */ int maxsize; /* how big can it get, with all the extensions? */ - int magres; /* how well it resists against spells */ + variant magres; /* how well it resists against spells */ int magresbonus; /* bonus it gives the target against spells */ int fumblebonus; /* bonus that reduces fumbling */ double auraregen; /* modifier for aura regeneration inside building */ diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 1286fd6b4..2819d4a16 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -381,7 +381,7 @@ static void test_btype_defaults(CuTest *tc) { CuAssertIntEquals(tc, -1, btype->maxsize); CuAssertIntEquals(tc, 1, btype->capacity); CuAssertIntEquals(tc, -1, btype->maxcapacity); - CuAssertIntEquals(tc, 0, btype->magres); + CuAssertIntEquals(tc, 0, btype->magres.sa[0]); CuAssertIntEquals(tc, 0, btype->magresbonus); CuAssertIntEquals(tc, 0, btype->fumblebonus); CuAssertIntEquals(tc, 0, btype->flags); diff --git a/src/kernel/item.c b/src/kernel/item.c index 9bc321fdb..6e64c147f 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -275,7 +275,7 @@ luxury_type *new_luxurytype(item_type * itype, int price) } weapon_type *new_weapontype(item_type * itype, - int wflags, double magres, const char *damage[], int offmod, int defmod, + int wflags, variant magres, const char *damage[], int offmod, int defmod, int reload, skill_t sk, int minskill) { weapon_type *wtype; @@ -301,7 +301,7 @@ weapon_type *new_weapontype(item_type * itype, return wtype; } -armor_type *new_armortype(item_type * itype, double penalty, double magres, +armor_type *new_armortype(item_type * itype, double penalty, variant magres, int prot, unsigned int flags) { armor_type *atype; diff --git a/src/kernel/item.h b/src/kernel/item.h index 1d3e5ff29..c1ac38517 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -181,7 +181,7 @@ extern "C" { const item_type *itype; unsigned int flags; double penalty; - double magres; + variant magres; int prot; float projectile; /* chance, dass ein projektil abprallt */ } armor_type; @@ -205,7 +205,7 @@ extern "C" { int minskill; int offmod; int defmod; - double magres; + variant magres; int reload; /* time to reload this weapon */ weapon_mod *modifiers; /* --- functions --- */ @@ -244,14 +244,12 @@ extern "C" { /* creation */ resource_type *rt_get_or_create(const char *name); item_type *it_get_or_create(resource_type *rtype); - item_type *new_itemtype(resource_type * rtype, int iflags, int weight, - int capacity); luxury_type *new_luxurytype(item_type * itype, int price); weapon_type *new_weapontype(item_type * itype, int wflags, - double magres, const char *damage[], int offmod, int defmod, int reload, + variant magres, const char *damage[], int offmod, int defmod, int reload, skill_t sk, int minskill); armor_type *new_armortype(item_type * itype, double penalty, - double magres, int prot, unsigned int flags); + variant magres, int prot, unsigned int flags); potion_type *new_potiontype(item_type * itype, int level); typedef enum { diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 2478c838f..287aa61db 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -460,7 +460,7 @@ static void json_race(cJSON *json, race *rc) { break; case cJSON_Number: if (strcmp(child->string, "magres") == 0) { - rc->magres = child->valueint; + rc->magres = frac_make(child->valueint, 100); } else if (strcmp(child->string, "maxaura") == 0) { rc->maxaura = child->valueint; diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index dcf748d00..8b8ac8c14 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -163,8 +163,7 @@ static void test_races(CuTest * tc) CuAssertPtrNotNull(tc, rc); CuAssertIntEquals(tc, RCF_NPC | RCF_WALK | RCF_UNDEAD, rc->flags); CuAssertStrEquals(tc, "1d4", rc->def_damage); - CuAssertIntEquals(tc, 100, rc->magres); - CuAssertDblEquals(tc, 1.0, rc_magres(rc), 0.0); + CuAssertTrue(tc, frac_equal(frac_one, rc->magres)); CuAssertIntEquals(tc, 200, rc->maxaura); CuAssertDblEquals(tc, 2.0, rc_maxaura(rc), 0.0); CuAssertDblEquals(tc, 3.0, rc->regaura, 0.0); diff --git a/src/kernel/race.c b/src/kernel/race.c index 4a3a04916..d159fd6d8 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -331,6 +331,7 @@ race *rc_create(const char *zName) assert(zName); rc = (race *)calloc(sizeof(race), 1); + rc->magres.sa[1] = 1; rc->hitpoints = 1; rc->weight = PERSON_WEIGHT; rc->capacity = 540; @@ -383,8 +384,8 @@ bool r_insectstalled(const region * r) return fval(r->terrain, ARCTIC_REGION); } -double rc_magres(const race *rc) { - return rc->magres / 100.0; +variant rc_magres(const race *rc) { + return rc->magres; } double rc_maxaura(const race *rc) { diff --git a/src/kernel/race.h b/src/kernel/race.h index e464c9447..f14b8e54f 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -116,7 +116,7 @@ extern "C" { typedef struct race { char *_name; - int magres; + variant magres; int healing; int maxaura; /* Faktor auf Maximale Aura */ double regaura; /* Faktor auf Regeneration */ @@ -182,7 +182,7 @@ extern "C" { int rc_luxury_trade(const struct race *rc); int rc_herb_trade(const struct race *rc); - double rc_magres(const struct race *rc); + variant rc_magres(const struct race *rc); double rc_maxaura(const struct race *rc); int rc_armor_bonus(const struct race *rc); int rc_scare(const struct race *rc); diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index 8363d8b72..07ecbdd45 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -24,8 +24,7 @@ static void test_rc_defaults(CuTest *tc) { rc = rc_get_or_create("human"); CuAssertStrEquals(tc, "human", rc->_name); CuAssertIntEquals(tc, 0, rc_armor_bonus(rc)); - CuAssertIntEquals(tc, 0, rc->magres); - CuAssertDblEquals(tc, 0.0, rc_magres(rc), 0.0); + CuAssertIntEquals(tc, 0, rc->magres.sa[0]); CuAssertIntEquals(tc, 0, rc->healing); CuAssertDblEquals(tc, 0.0, rc_maxaura(rc), 0.0); CuAssertDblEquals(tc, 1.0, rc->recruit_multi, 0.0); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 27adba598..74459270c 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -61,6 +61,19 @@ without prior permission by the authors of Eressea. #include #ifdef USE_LIBXML2 + +static variant xml_fraction(xmlNodePtr node, const char *name) { + xmlChar *propValue = xmlGetProp(node, BAD_CAST name); + if (propValue != NULL) { + int num, den = 100; + double fval = atof((const char *)propValue); + num = (int)(fval * den + 0.5); + xmlFree(propValue); + return frac_make(num, den); + } + return frac_make(0, 1); +} + static void xml_readtext(xmlNodePtr node, struct locale **lang, xmlChar ** text) { xmlChar *propValue = xmlGetProp(node, BAD_CAST "locale"); @@ -245,7 +258,7 @@ static int parse_buildings(xmlDocPtr doc) btype->maxcapacity = xml_ivalue(node, "maxcapacity", btype->maxcapacity); btype->maxsize = xml_ivalue(node, "maxsize", btype->maxsize); - btype->magres = xml_ivalue(node, "magres", btype->magres); + btype->magres = frac_make(xml_ivalue(node, "magres", 0), 100); btype->magresbonus = xml_ivalue(node, "magresbonus", btype->magresbonus); btype->fumblebonus = xml_ivalue(node, "fumblebonus", btype->fumblebonus); btype->auraregen = xml_fvalue(node, "auraregen", btype->auraregen); @@ -582,7 +595,7 @@ static armor_type *xml_readarmor(xmlXPathContextPtr xpath, item_type * itype) unsigned int flags = ATF_NONE; int ac = xml_ivalue(node, "ac", 0); double penalty = xml_fvalue(node, "penalty", 0.0); - double magres = xml_fvalue(node, "magres", 0.0); + variant magres = xml_fraction(node, "magres"); if (xml_bvalue(node, "laen", false)) flags |= ATF_LAEN; @@ -607,7 +620,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) int offmod = xml_ivalue(node, "offmod", 0); int defmod = xml_ivalue(node, "defmod", 0); int reload = xml_ivalue(node, "reload", 0); - double magres = xml_fvalue(node, "magres", 0.0); + variant magres = xml_fraction(node, "magres"); if (xml_bvalue(node, "armorpiercing", false)) flags |= WTF_ARMORPIERCING; @@ -899,22 +912,6 @@ static int parse_rules(xmlDocPtr doc) return 0; } -static int gcd(int num, int den) { - const int primes[] = { 3, 5, 7, 11, 0 }; - int i=0, g = 1, p = 2; - while (p && p<=den && p<=num) { - if (num % p == 0 && den % p == 0) { - num /= p; - den /= p; - g *= p; - } - else { - p = primes[i++]; - } - } - return g; -} - static int parse_resources(xmlDocPtr doc) { xmlXPathContextPtr xpath = xmlXPathNewContext(doc); @@ -1031,15 +1028,7 @@ static int parse_resources(xmlDocPtr doc) rdata->modifiers[k].flags = RMF_SKILL; } else if (strcmp((const char *)propValue, "material") == 0) { - int g, num, den = 100; - double fval = xml_fvalue(node, "value", 0); - /* TODO: extract into a function for reading fractions? */ - num = (int)(fval * den + 0.5); - g = gcd(num, den); - num /= g; - den /= g; - rdata->modifiers[k].value.sa[0] = (short)num; - rdata->modifiers[k].value.sa[1] = (short)den; + rdata->modifiers[k].value = xml_fraction(node, "value"); rdata->modifiers[k].flags = RMF_SAVEMATERIAL; } else if (strcmp((const char *)propValue, "require") == 0) { @@ -1623,7 +1612,7 @@ static int parse_races(xmlDocPtr doc) rc->def_damage = strdup((const char *)propValue); xmlFree(propValue); - rc->magres = xml_ivalue(node, "magres", rc->magres); + rc->magres = frac_make(xml_ivalue(node, "magres", 100), 100); rc->healing = (int)(xml_fvalue(node, "healing", rc->healing) * 100); /* TODO: store as int in XML */ rc->maxaura = (int)(xml_fvalue(node, "maxaura", rc->maxaura) * 100); /* TODO: store as int in XML */ rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura); diff --git a/src/laws.test.c b/src/laws.test.c index cca55beb1..c27651d83 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -611,7 +611,7 @@ void setup_guard(guard_fixture *fix, bool armed) { if (armed) { item_type *itype; itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); i_change(&u->items, itype, 1); set_level(u, SK_MELEE, 2); } @@ -1481,7 +1481,7 @@ static void test_armedmen(CuTest *tc) { test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); it_sword = test_create_itemtype("sword"); - wtype = new_weapontype(it_sword, 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1); + wtype = new_weapontype(it_sword, 0, frac_make(1, 2), 0, 0, 0, 0, SK_MELEE, 1); CuAssertIntEquals(tc, 0, armedmen(u, false)); CuAssertIntEquals(tc, 0, armedmen(u, true)); set_level(u, SK_MELEE, 1); diff --git a/src/magic.c b/src/magic.c index 65b454c04..de1336d66 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1135,27 +1135,29 @@ static int farcasting(unit * magician, region * r) /* allgemeine Magieresistenz einer Einheit, * reduziert magischen Schaden */ -double magic_resistance(unit * target) +variant magic_resistance(unit * target) { attrib *a; curse *c; const curse_type * ct_goodresist = 0, *ct_badresist = 0; const resource_type *rtype; const race *rc = u_race(target); - double probability = rc_magres(rc); + variant v, prob = rc_magres(rc); const plane *pl = rplane(target->region); if (rc == get_race(RC_HIRNTOETER) && !pl) { - probability /= 2; + prob.sa[1] *= 2; } assert(target->number > 0); /* Magier haben einen Resistenzbonus vom Magietalent * 5% */ - probability += effskill(target, SK_MAGIC, 0) * 0.05; + prob = frac_add(prob, frac_make(effskill(target, SK_MAGIC, 0), 20)); /* Auswirkungen von Zaubern auf der Einheit */ c = get_curse(target->attribs, ct_find("magicresistance")); if (c) { - probability += 0.01 * curse_geteffect(c) * get_cursedmen(target, c); + /* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */ + int effect = curse_geteffect_int(c) * get_cursedmen(target, c); + prob = frac_add(prob, frac_make(effect, 100)); } /* Unicorn +10 */ @@ -1163,7 +1165,7 @@ double magic_resistance(unit * target) if (rtype) { int n = i_get(target->items, rtype->itype); if (n) { - probability += n * 0.1 / target->number; + prob = frac_add(prob, frac_make(n, target->number * 10)); } } @@ -1180,13 +1182,15 @@ double magic_resistance(unit * target) if (mage != NULL) { if (ct_goodresist && c->type == ct_goodresist) { if (alliedunit(mage, target->faction, HELP_GUARD)) { - probability += curse_geteffect(c) * 0.01; + /* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */ + prob = frac_add(prob, frac_make(curse_geteffect_int(c), 100)); ct_goodresist = 0; /* only one effect per region */ } } else if (ct_badresist && c->type == ct_badresist) { if (!alliedunit(mage, target->faction, HELP_GUARD)) { - probability -= curse_geteffect(c) * 0.01; + /* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */ + prob = frac_sub(prob, frac_make(curse_geteffect_int(c), 100)); ct_badresist = 0; /* only one effect per region */ } } @@ -1202,11 +1206,18 @@ double magic_resistance(unit * target) const struct building_type *btype = building_is_active(b) ? b->type : NULL; /* gesegneter Steinkreis gibt 30% dazu */ - if (btype) - probability += btype->magresbonus * 0.01; + if (btype) { + /* TODO: legacy. building-bonus is an integer-percentage */ + prob = frac_add(prob, frac_make(btype->magresbonus, 100)); + } } - return (probability<0.9) ? probability : 0.9; + /* resistance must never be more than 90% */ + v = frac_make(9, 10); + if (frac_sign(frac_sub(prob, v)) > 0) { /* prob < 90% */ + return v; /* at most 90% */ + } + return prob; } /* ------------------------------------------------------------- */ @@ -1223,12 +1234,12 @@ double magic_resistance(unit * target) bool target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) { - double probability = 0.0; + variant v02p, v98p, prob = frac_make(t_bonus, 100); + attrib *a = NULL; - if (magician == NULL) - return true; - if (obj == NULL) + if (magician == NULL || obj == NULL) { return true; + } switch (objtyp) { case TYP_UNIT: @@ -1248,43 +1259,56 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) pa = sk; } - /* Contest */ - probability = 0.05 * (10 + pa - at); - - probability += magic_resistance((unit *)obj); + /* Contest, probability = 0.05 * (10 + pa - at); */ + prob = frac_add(prob, frac_make(10 + pa - at, 20)); + prob = frac_add(prob, magic_resistance((unit *)obj)); break; } case TYP_REGION: - /* Bonus durch Zauber */ + /* Bonus durch Zauber probability += - 0.01 * get_curseeffect(((region *)obj)->attribs, C_RESIST_MAGIC, 0); + 0.01 * get_curseeffect(((region *)obj)->attribs, C_RESIST_MAGIC, 0); */ + a = ((region *)obj)->attribs; break; case TYP_BUILDING: - /* Bonus durch Zauber */ + /* Bonus durch Zauber probability += - 0.01 * get_curseeffect(((building *)obj)->attribs, C_RESIST_MAGIC, 0); - - /* Bonus durch Typ */ - probability += 0.01 * ((building *)obj)->type->magres; - + 0.01 * get_curseeffect(((building *)obj)->attribs, C_RESIST_MAGIC, 0); */ + a = ((building *)obj)->attribs; + /* Bonus durch Typ + probability += 0.01 * ((building *)obj)->type->magres; */ + prob = frac_add(prob, ((building *)obj)->type->magres); break; case TYP_SHIP: /* Bonus durch Zauber */ - probability += - 0.01 * get_curseeffect(((ship *)obj)->attribs, C_RESIST_MAGIC, 0); + a = ((ship *)obj)->attribs; break; } - probability = MAX(0.02, probability + t_bonus * 0.01); - probability = MIN(0.98, probability); + if (a) { + const struct curse_type *ct_resist = ct_find(oldcursename(C_RESIST_MAGIC)); + curse * c = get_curse(a, ct_resist); + int effect = curse_geteffect_int(c); + prob = frac_add(prob, frac_make(effect, 100)); + } + + /* ignore results < 2% and > 98% */ + v02p = frac_make(1, 50); + v98p = frac_make(49, 50); + if (frac_sign(frac_sub(prob, v02p)) < 0) { + prob = v02p; + } + else if (frac_sign(frac_sub(prob, v98p)) > 0) { + prob = v98p; + } /* gibt true, wenn die Zufallszahl kleiner als die chance ist und * false, wenn sie gleich oder größer ist, dh je größer die * Magieresistenz (chance) desto eher gibt die Funktion true zurück */ - return chance(probability); + return rng_int() % prob.sa[1] < prob.sa[0]; } /* ------------------------------------------------------------- */ diff --git a/src/magic.h b/src/magic.h index d282767a9..37fe33eae 100644 --- a/src/magic.h +++ b/src/magic.h @@ -315,7 +315,7 @@ extern "C" { bool is_magic_resistant(struct unit *magician, struct unit *target, int resist_bonus); /* Mapperfunktion für target_resists_magic() vom Typ struct unit. */ - extern double magic_resistance(struct unit *target); + variant magic_resistance(struct unit *target); /* gibt die Chance an, mit der einem Zauber widerstanden wird. Je * größer, desto resistenter ist da Opfer */ bool target_resists_magic(struct unit *magician, void *obj, int objtyp, diff --git a/src/magic.test.c b/src/magic.test.c index baf8ede50..a5a842172 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -414,15 +414,15 @@ static void test_magic_resistance(CuTest *tc) { test_setup(); rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); - CuAssertDblEquals(tc, rc->magres/100.0, magic_resistance(u), 0.01); - rc->magres = 100; - CuAssertDblEquals_Msg(tc, "magic resistance is capped at 0.9", 0.9, magic_resistance(u), 0.01); + CuAssertTrue(tc, frac_equal(rc->magres, magic_resistance(u))); + rc->magres = frac_one; + CuAssert(tc, "magic resistance is capped at 0.9", frac_equal(magic_resistance(u), frac_make(9, 10))); rc = test_create_race("braineater"); - rc->magres = 100; + rc->magres = frac_one; u_setrace(u, rc); - CuAssertDblEquals_Msg(tc, "brain eaters outside astral space have 50% magres", 0.5, magic_resistance(u), 0.01); + CuAssert(tc, "brain eaters outside astral space have 50% magres", frac_equal(magic_resistance(u), frac_make(1, 2))); u->region->_plane = get_astralplane(); - CuAssertDblEquals_Msg(tc, "brain eaters in astral space have full magres", 0.9, magic_resistance(u), 0.01); + CuAssert(tc, "brain eaters in astral space have full magres", frac_equal(magic_resistance(u), frac_make(9, 10))); test_cleanup(); } diff --git a/src/spells.c b/src/spells.c index 95b26434f..fcee1b51b 100644 --- a/src/spells.c +++ b/src/spells.c @@ -2851,7 +2851,8 @@ static int dc_age(struct curse *c) while (*up != NULL) { unit *u = *up; int hp; - double damage = c->effect * u->number; + variant dmg = frac_make(u->number, 1); + double damage = c->effect; if (u->number <= 0 || target_resists_magic(mage, u, TYP_UNIT, 0)) { up = &u->next; @@ -2859,7 +2860,9 @@ static int dc_age(struct curse *c) } /* Reduziert durch Magieresistenz */ - damage *= (1.0 - magic_resistance(u)); + dmg = frac_mul(dmg, frac_sub(frac_make(1,1), magic_resistance(u))); + damage *= dmg.sa[0]; + damage /= dmg.sa[1]; hp = change_hitpoints(u, -(int)damage); ADDMSG(&u->faction->msgs, msg_message((hp>0)?"poison_damage":"poison_death", "region unit", r, u)); diff --git a/src/spy.test.c b/src/spy.test.c index 8341b17d3..ae1550689 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -71,7 +71,7 @@ static void test_all_spy_message(CuTest *tc) { set_factionstealth(fix.victim, fix.spy->faction); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); i_change(&fix.victim->items, itype, 1); spy_message(99, fix.spy, fix.victim); diff --git a/src/volcano.c b/src/volcano.c index fb4cfa74c..9734bb2cd 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -80,7 +80,6 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic) int *hp, hpstack[20]; int h; int i, dead = 0, hp_rem = 0, heiltrank; - double magres = magic_resistance(u); assert(u->number); if (fval(u_race(u), RCF_ILLUSIONARY) || u_race(u) == get_race(RC_SPELL)) { @@ -105,10 +104,14 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic) /* Schaden */ for (i = 0; i < u->number; i++) { int damage = dice_rand(dam); - if (magic) - damage = (int)(damage * (1.0 - magres)); - if (physical) + if (magic) { + variant magres = magic_resistance(u); + magres = frac_sub(frac_make(1, 1), magres); + damage = damage * magres.sa[0] / magres.sa[1]; + } + if (physical) { damage -= nb_armor(u, i); + } hp[i] -= damage; } From 6031dff6850ec50b61d1f937383cce353390fcbb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Feb 2017 19:50:32 +0100 Subject: [PATCH 266/271] resource_limit.value is always zero, never initialized. kill it. --- clibs | 2 +- src/economy.c | 4 ++-- src/economy.test.c | 1 - src/kernel/resources.h | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clibs b/clibs index 27c8b3202..b91413316 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 +Subproject commit b91413316ce13044c555084a9f605983586107b4 diff --git a/src/economy.c b/src/economy.c index f0a693eca..f9ded29de 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1123,7 +1123,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) allocation *al; int nreq = 0; resource_limit *rdata = get_resourcelimit(rtype); - int avail = rdata->value; + int avail = 0; for (al = alist; al; al = al->next) { nreq += required(al->want, al->save); @@ -1165,7 +1165,7 @@ static allocate_function get_allocator(const struct resource_type *rtype) resource_limit *rdata = get_resourcelimit(rtype); if (rdata) { - if (rdata->value > 0 || rdata->limit != NULL) { + if (rdata->limit != NULL) { return attrib_allocation; } return leveled_allocation; diff --git a/src/economy.test.c b/src/economy.test.c index 4ddd20105..aea42491d 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -384,7 +384,6 @@ static void test_make_item(CuTest *tc) { rtype->flags |= RTF_LIMITED; rmt = rmt_create(rtype); rdata = rtype->limit = calloc(1, sizeof(resource_limit)); - rdata->value = 0; add_resource(u->region, 1, 300, 150, rtype); u->region->resources->amount = 300; /* there are 300 stones at level 1 */ set_level(u, SK_ALCHEMY, 10); diff --git a/src/kernel/resources.h b/src/kernel/resources.h index 3e93ea1de..d7c0e5bfd 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -58,7 +58,6 @@ extern "C" { typedef struct resource_limit { rlimit_limit limit; rlimit_produce produce; - int value; resource_mod *modifiers; } resource_limit; From d039ca2b2ed552d959da14712aa0a334b63d1946 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Feb 2017 21:07:13 +0100 Subject: [PATCH 267/271] fix display of sapling and mallornsapling. remove mateiral from XML where it's not needed. --- res/core/de/strings.xml | 40 ++-------------------------------- res/core/resources/horse.xml | 2 +- res/core/resources/log.xml | 2 +- res/core/resources/mallorn.xml | 2 +- 4 files changed, 5 insertions(+), 41 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 5bde79c29..26e8cc862 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -6611,53 +6611,17 @@ EINLADEN INVITE - - Steine - stones - - - Pferde - horses - - - Bauern - peasants - - - Silber - silver - - - Laen - laen - - - + Schößlinge saplings - + Mallornschößlinge mallorn saplings - - Bäume - trees - - - - Mallorn - mallorn - - - - Eisen - iron - - Winter winter diff --git a/res/core/resources/horse.xml b/res/core/resources/horse.xml index 53699c696..d7f794491 100644 --- a/res/core/resources/horse.xml +++ b/res/core/resources/horse.xml @@ -1,5 +1,5 @@ - + diff --git a/res/core/resources/log.xml b/res/core/resources/log.xml index e3a33ef8b..48662878f 100644 --- a/res/core/resources/log.xml +++ b/res/core/resources/log.xml @@ -1,5 +1,5 @@ - + diff --git a/res/core/resources/mallorn.xml b/res/core/resources/mallorn.xml index fc678e79e..96892b802 100644 --- a/res/core/resources/mallorn.xml +++ b/res/core/resources/mallorn.xml @@ -1,5 +1,5 @@ - + From 84c6a4b7b56d1bd6b96a874d0e85e2126959fa14 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Feb 2017 21:24:47 +0100 Subject: [PATCH 268/271] remove last vestiges of the rm_* material names --- clibs | 2 +- res/adamantium.xml | 2 +- res/core/resources/iron.xml | 2 +- res/core/resources/laen.xml | 2 +- res/core/resources/stone.xml | 2 +- res/e3a/resources/iron.xml | 2 +- res/e3a/resources/stone.xml | 2 +- src/economy.test.c | 3 +-- src/kernel/xmlreader.c | 4 +--- 9 files changed, 9 insertions(+), 12 deletions(-) diff --git a/clibs b/clibs index b91413316..27c8b3202 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit b91413316ce13044c555084a9f605983586107b4 +Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 diff --git a/res/adamantium.xml b/res/adamantium.xml index decc5636c..bb94dfc12 100644 --- a/res/adamantium.xml +++ b/res/adamantium.xml @@ -1,7 +1,7 @@ - + diff --git a/res/core/resources/iron.xml b/res/core/resources/iron.xml index 3f8897abc..469840669 100644 --- a/res/core/resources/iron.xml +++ b/res/core/resources/iron.xml @@ -1,5 +1,5 @@ - + diff --git a/res/core/resources/laen.xml b/res/core/resources/laen.xml index 12062bf07..30531c0fe 100644 --- a/res/core/resources/laen.xml +++ b/res/core/resources/laen.xml @@ -1,5 +1,5 @@ - + diff --git a/res/core/resources/stone.xml b/res/core/resources/stone.xml index c227dcc5c..91d3aac5d 100644 --- a/res/core/resources/stone.xml +++ b/res/core/resources/stone.xml @@ -1,5 +1,5 @@ - + diff --git a/res/e3a/resources/iron.xml b/res/e3a/resources/iron.xml index 06b70e45a..7ffe36f1e 100644 --- a/res/e3a/resources/iron.xml +++ b/res/e3a/resources/iron.xml @@ -1,5 +1,5 @@ - + diff --git a/res/e3a/resources/stone.xml b/res/e3a/resources/stone.xml index 746b79c21..dfb039093 100644 --- a/res/e3a/resources/stone.xml +++ b/res/e3a/resources/stone.xml @@ -1,5 +1,5 @@ - + diff --git a/src/economy.test.c b/src/economy.test.c index aea42491d..6d9c84542 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -348,7 +348,6 @@ static void test_make_item(CuTest *tc) { struct item_type *itype; const struct resource_type *rt_silver; resource_type *rtype; - rawmaterial_type *rmt; resource_limit *rdata; double d = 0.6; @@ -382,7 +381,7 @@ static void test_make_item(CuTest *tc) { free(itype->construction->materials); itype->construction->materials = 0; rtype->flags |= RTF_LIMITED; - rmt = rmt_create(rtype); + rmt_create(rtype); rdata = rtype->limit = calloc(1, sizeof(resource_limit)); add_resource(u->region, 1, 300, 150, rtype); u->region->resources->amount = 300; /* there are 300 stones at level 1 */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 74459270c..737a12f66 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -978,10 +978,8 @@ static int parse_resources(xmlDocPtr doc) } xmlXPathFreeObject(result); - name = xmlGetProp(node, BAD_CAST "material"); - if (name) { + if (xml_bvalue(node, "material", false)) { rmt_create(rtype); - xmlFree(name); } /* reading eressea/resources/resource/resourcelimit */ From 114d088bb502c1f7173b7586b1edef59ecb5b2d2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Feb 2017 13:08:50 +0100 Subject: [PATCH 269/271] allow testers.txt to contain comments --- s/preview | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/preview b/s/preview index 0c1467627..1607afc55 100755 --- a/s/preview +++ b/s/preview @@ -160,7 +160,7 @@ case "$1" in done if [ $sent -eq 0 ]; then if [ -e ../$factions ]; then - for faction in $(cat ../$factions) ; do + for faction in $(grep -v -E '^#' ../$factions) ; do send $faction done fi From 7a1cebb25977571ccd02e18674f7cc01db3fe708 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Feb 2017 13:10:23 +0100 Subject: [PATCH 270/271] silence the preview-build --- s/preview | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/preview b/s/preview index 1607afc55..40dc2952c 100755 --- a/s/preview +++ b/s/preview @@ -27,7 +27,7 @@ git fetch || abort "failed to update source. do you have local changes?" [ -z $1 ] || git checkout $1 git pull git submodule update -s/build || abort "build failed." +s/build > /dev/null || abort "build failed." } function assert_file() { From f4180638af0bf83b68621245bfe57f681c658ca6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Feb 2017 13:12:47 +0100 Subject: [PATCH 271/271] also silence the git pull command and valgrind --- s/preview | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s/preview b/s/preview index 40dc2952c..68fe6e39f 100755 --- a/s/preview +++ b/s/preview @@ -25,7 +25,7 @@ cd $SOURCE rm -rf crypto tolua git fetch || abort "failed to update source. do you have local changes?" [ -z $1 ] || git checkout $1 -git pull +git pull -q git submodule update s/build > /dev/null || abort "build failed." } @@ -79,7 +79,7 @@ SUPP="$SOURCE/share/debian-7_8.supp" SERVER="$SOURCE/Debug/eressea/eressea" VALGRIND=$(which valgrind) if [ ! -z $VALGRIND ]; then -SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER" +SERVER="$VALGRIND --quiet --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER" fi $SERVER -v$verbose -t$turn $SOURCE/scripts/run-turn.lua let turn=$turn+1