From e4aa8f505ecd93068cdc9497a4eb65355a9ae16d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 14:18:36 +0100 Subject: [PATCH 01/22] cppcheck warnings for battle --- src/attributes/dict.c | 6 ------ src/battle.c | 16 ++++++---------- src/battle.test.c | 4 +--- src/bind_config.c | 2 +- src/util/path.c | 6 ++++++ src/util/path.h | 6 ------ 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 83a53dbeb..8e7dfb20a 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -52,13 +52,7 @@ typedef struct dict_data { char *name; union { int i; - char *str; double real; - struct unit *u; - struct region *r; - struct building *b; - struct ship *sh; - struct faction *f; } data; } dict_data; diff --git a/src/battle.c b/src/battle.c index b7482e48a..306637db1 100644 --- a/src/battle.c +++ b/src/battle.c @@ -393,7 +393,6 @@ static int get_row(const side * s, int row, const side * vs) int line, result; int retreat = 0; int size[NUMROWS]; - int front = 0; battle *b = s->battle; memset(counted, 0, sizeof(counted)); @@ -426,6 +425,7 @@ static int get_row(const side * s, int row, const side * vs) break; } if (enemyfront) { + int front = 0; for (line = FIRST_ROW; line != NUMROWS; ++line) { front += size[line]; if (!front || front < enemyfront / ROW_FACTOR) @@ -1142,7 +1142,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* Schild */ side *ds = df->side; - int hp, ar; + int ar; const weapon_type *dwtype = NULL; const weapon_type *awtype = NULL; @@ -1257,7 +1257,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* jeder Schaden wird um effect% reduziert bis der Schild duration * Trefferpunkte aufgefangen hat */ if (me->typ == SHIELD_REDUCE) { - hp = rda * (me->effect / 100); + int hp = rda * (me->effect / 100); rda -= hp; me->duration -= hp; } @@ -2875,12 +2875,9 @@ static void print_stats(battle * b) { side *s2; side *s; - int i = 0; for (s = b->sides; s != b->sides + b->nsides; ++s) { bfaction *bf; - ++i; - for (bf = b->factions; bf; bf = bf->next) { faction *f = bf->faction; const char *loc_army = LOC(f->locale, "battle_army"); @@ -3046,8 +3043,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) { #define WMAX 20 weapon weapons[WMAX]; - int owp[WMAX]; - int dwp[WMAX]; region *r = b->region; item *itm; fighter *fig = NULL; @@ -3160,6 +3155,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) /* F�r alle Waffengattungen wird bestimmt, wie viele der Personen mit * ihr k�mpfen k�nnten, und was ihr Wert darin ist. */ if (u_race(u)->battle_flags & BF_EQUIPMENT) { + int owp[WMAX]; + int dwp[WMAX]; int oi = 0, di = 0, w = 0; for (itm = u->items; itm && w != WMAX; itm = itm->next) { const weapon_type *wtype = resource2weapon(itm->type->rtype); @@ -3480,7 +3477,6 @@ static int battle_report(battle * b) { side *s, *s2; bool cont = false; - bool komma; bfaction *bf; for (s = b->sides; s != b->sides + b->nsides; ++s) { @@ -3503,6 +3499,7 @@ static int battle_report(battle * b) char buf[32 * MAXSIDES]; message *m; sbstring sbs; + bool komma = false; sbs_init(&sbs, buf, sizeof(buf)); battle_message_faction(b, fac, msg_separator); @@ -3514,7 +3511,6 @@ static int battle_report(battle * b) battle_message_faction(b, fac, m); msg_release(m); - komma = false; for (s = b->sides; s != b->sides + b->nsides; ++s) { if (s->alive) { int r, k = 0, *alive = get_alive(s); diff --git a/src/battle.test.c b/src/battle.test.c index d446cbebb..b69996ddf 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -446,7 +446,6 @@ static void test_battle_skilldiff(CuTest *tc) td.index = 0; ta.fighter = setup_fighter(&b, ua); ta.index = 0; - ua = test_create_unit(test_create_faction(NULL), r); CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0)); ta.fighter->person[0].attack = 2; @@ -483,7 +482,6 @@ static void test_battle_skilldiff_building(CuTest *tc) td.index = 0; ta.fighter = setup_fighter(&b, ua); ta.index = 0; - ua = test_create_unit(test_create_faction(NULL), r); CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0)); ud->building->size = 10; @@ -502,8 +500,8 @@ static void test_battle_skilldiff_building(CuTest *tc) static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax) { skill *sv = unit_skill(u, sk); - char buf[256]; if (sv) { + char buf[256]; sprintf(buf, "%s level %d != %d", msg, sv->level, level); CuAssertIntEquals_Msg(tc, buf, level, sv->level); sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax); diff --git a/src/bind_config.c b/src/bind_config.c index 83c65364d..2d4086ccf 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -63,11 +63,11 @@ int config_parse(const char *json) int config_read(const char *filename, const char * relpath) { - char name[PATH_MAX]; FILE *F; json_relpath = relpath; if (relpath) { + char name[PATH_MAX]; path_join(relpath, filename, name, sizeof(name)); F = fopen(name, "r"); } diff --git a/src/util/path.c b/src/util/path.c index 3ede6b4ee..bdbf7646d 100644 --- a/src/util/path.c +++ b/src/util/path.c @@ -8,6 +8,12 @@ #include #include +#ifdef WIN32 +#define PATH_DELIM '\\' +#else +#define PATH_DELIM '/' +#endif + char * path_join(const char *p1, const char *p2, char *dst, size_t len) { size_t sz; assert(p1 && p2); diff --git a/src/util/path.h b/src/util/path.h index 58e505df9..5a4e22270 100644 --- a/src/util/path.h +++ b/src/util/path.h @@ -1,10 +1,4 @@ #include -#ifdef WIN32 -#define PATH_DELIM '\\' -#else -#define PATH_DELIM '/' -#endif - char * path_join(const char *p1, const char *p2, char *dst, size_t len); From 7b01581302480649817b3904b068963d939f523d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 14:29:25 +0100 Subject: [PATCH 02/22] CATAPULT_STRUCTURAL_DAMAGE was broken. check for PDCURSES, not WIN32 --- src/battle.c | 1 - src/gmtool.c | 11 ++++++++++- src/gmtool.h | 2 ++ src/gmtool_structs.h | 6 ------ src/items/weapons.c | 2 -- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/battle.c b/src/battle.c index 306637db1..fd658cd69 100644 --- a/src/battle.c +++ b/src/battle.c @@ -86,7 +86,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define TACTICS_MODIFIER 1 /* modifier for generals in the front/rear */ #define CATAPULT_INITIAL_RELOAD 4 /* erster schuss in runde 1 + rng_int() % INITIAL */ -#define CATAPULT_STRUCTURAL_DAMAGE #define BASE_CHANCE 70 /* 70% Basis-�berlebenschance */ #define TDIFF_CHANGE 5 /* 5% h�her pro Stufe */ diff --git a/src/gmtool.c b/src/gmtool.c index d74f1e46b..010adce6f 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -144,7 +144,7 @@ static void init_curses(void) short bcol = COLOR_BLACK; short hcol = COLOR_MAGENTA; start_color(); -#ifdef WIN32 +#ifdef __PDCURSES__ /* looks crap on putty with TERM=linux */ if (can_change_color()) { init_color(COLOR_YELLOW, 1000, 1000, 0); @@ -422,6 +422,15 @@ static bool handle_info_region(window * wnd, state * st, int c) return false; } +int wxborder(WINDOW *win) +{ +#ifdef __PDCURSES__ + return wborder(win, 0, 0, 0, 0, 0, 0, 0, 0); +#else + return wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); +#endif +} + static void paint_info_region(window * wnd, const state * st) { WINDOW *win = wnd->handle; diff --git a/src/gmtool.h b/src/gmtool.h index 5a2449c9a..6d299fe74 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -41,6 +41,8 @@ extern "C" { void make_block(int x, int y, int radius, const struct terrain_type *terrain); void seed_players(struct newfaction **players, bool new_island); + int wxborder(WINDOW *win); + #ifdef __cplusplus } #endif diff --git a/src/gmtool_structs.h b/src/gmtool_structs.h index b6003313c..9779ffaf0 100644 --- a/src/gmtool_structs.h +++ b/src/gmtool_structs.h @@ -90,12 +90,6 @@ extern "C" { #define TWIDTH 2 /* width of tile */ #define THEIGHT 1 /* height of tile */ -#ifdef WIN32 -#define wxborder(win) wborder(win, 0, 0, 0, 0, 0, 0, 0, 0) -#else -#define wxborder(win) wborder(win, '|', '|', '-', '-', '+', '+', '+', '+') -#endif - #ifdef __cplusplus } #endif diff --git a/src/items/weapons.c b/src/items/weapons.c index 53721bca6..fd2e7cf19 100644 --- a/src/items/weapons.c +++ b/src/items/weapons.c @@ -138,7 +138,6 @@ int *casualties) /* If battle succeeds */ if (hits(*at, dt, wp)) { d += terminate(dt, *at, AT_STANDARD, wp->type->damage[0], true); -#ifdef CATAPULT_STRUCTURAL_DAMAGE if (dt.fighter->unit->building && rng_int() % 100 < 5) { double dmg = config_get_flt("rules.building.damage.catapult", 1); damage_building(b, dt.fighter->unit->building, dmg); @@ -147,7 +146,6 @@ int *casualties) double dmg = config_get_flt("rules.ship.damage.catapult", 0.01); damage_ship(dt.fighter->unit->ship, dmg) } -#endif } } From a286cb45f11887d5749714a76a20cb31fcd16b18 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 14:54:45 +0100 Subject: [PATCH 03/22] compilation fix, disable catapult damage code. --- src/gmtool.h | 2 -- src/gmtool_structs.h | 2 ++ src/items/weapons.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gmtool.h b/src/gmtool.h index 6d299fe74..5a2449c9a 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -41,8 +41,6 @@ extern "C" { void make_block(int x, int y, int radius, const struct terrain_type *terrain); void seed_players(struct newfaction **players, bool new_island); - int wxborder(WINDOW *win); - #ifdef __cplusplus } #endif diff --git a/src/gmtool_structs.h b/src/gmtool_structs.h index 9779ffaf0..aedee2aa9 100644 --- a/src/gmtool_structs.h +++ b/src/gmtool_structs.h @@ -90,6 +90,8 @@ extern "C" { #define TWIDTH 2 /* width of tile */ #define THEIGHT 1 /* height of tile */ +int wxborder(WINDOW *win); + #ifdef __cplusplus } #endif diff --git a/src/items/weapons.c b/src/items/weapons.c index fd2e7cf19..6c764b123 100644 --- a/src/items/weapons.c +++ b/src/items/weapons.c @@ -138,14 +138,16 @@ int *casualties) /* If battle succeeds */ if (hits(*at, dt, wp)) { d += terminate(dt, *at, AT_STANDARD, wp->type->damage[0], true); +/* CATAPULT_STRUCTURAL_DAMAGE if (dt.fighter->unit->building && rng_int() % 100 < 5) { double dmg = config_get_flt("rules.building.damage.catapult", 1); damage_building(b, dt.fighter->unit->building, dmg); } else if (dt.fighter->unit->ship && rng_int() % 100 < 5) { double dmg = config_get_flt("rules.ship.damage.catapult", 0.01); - damage_ship(dt.fighter->unit->ship, dmg) + damage_ship(dt.fighter->unit->ship, dmg); } +*/ } } From 51fb719bb6ce25e44749c0f12440b9da244ddd36 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 16:36:22 +0100 Subject: [PATCH 04/22] add a Readline module, fix detection, keep disabled for now --- CMakeLists.txt | 2 ++ cmake/Modules/FindReadline.cmake | 47 ++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 6 ++++ src/console.c | 5 ++-- src/console.h | 4 +-- 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 cmake/Modules/FindReadline.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e7311253..b14e2cf1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ else (MSVC) find_package (Curses) endif (MSVC) +find_package (Readline) + if (ERESSEA_DB STREQUAL "db") find_package (BerkeleyDB REQUIRED QUIET) else() diff --git a/cmake/Modules/FindReadline.cmake b/cmake/Modules/FindReadline.cmake new file mode 100644 index 000000000..bb73fee7f --- /dev/null +++ b/cmake/Modules/FindReadline.cmake @@ -0,0 +1,47 @@ +# - Try to find readline include dirs and libraries +# +# Usage of this module as follows: +# +# find_package(Readline) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# READLINE_ROOT_DIR Set this variable to the root installation of +# readline if the module has problems finding the +# proper installation path. +# +# Variables defined by this module: +# +# READLINE_FOUND System has readline, include and lib dirs found +# READLINE_INCLUDE_DIR The readline include directories. +# READLINE_LIBRARY The readline library. + +find_path(READLINE_ROOT_DIR + NAMES include/readline/readline.h +) + +find_path(READLINE_INCLUDE_DIR + NAMES readline/readline.h + HINTS ${READLINE_ROOT_DIR}/include +) + +find_library(READLINE_LIBRARY + NAMES readline + HINTS ${READLINE_ROOT_DIR}/lib +) + +if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY) + set(READLINE_FOUND TRUE) +else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY) + FIND_LIBRARY(READLINE_LIBRARY NAMES readline) + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY ) + MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY) +endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY) + +mark_as_advanced( + READLINE_ROOT_DIR + READLINE_INCLUDE_DIR + READLINE_LIBRARY +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a17a45e9..b1232cc1e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -295,6 +295,12 @@ target_link_libraries(test_eressea ${DB_LIBRARIES}) add_definitions(-DUSE_DB) endif(SQLITE3_FOUND) +if (READLINE_FOUND) +include_directories (${READLINE_INCLUDE_DIR}) +target_link_libraries(eressea ${READLINE_LIBRARY}) +add_definitions(-DUSE_READLINE) +endif (READLINE_FOUND) + if (CURSES_FOUND) include_directories (${CURSES_INCLUDE_DIR}) target_link_libraries(eressea ${CURSES_LIBRARIES}) diff --git a/src/console.c b/src/console.c index c20c0d8b9..7a32b83f0 100644 --- a/src/console.c +++ b/src/console.c @@ -29,7 +29,7 @@ #define lua_strlen(L, idx) lua_rawlen(L, idx) #endif -#if defined(LUA_USE_READLINE) +#ifdef LUA_USE_READLINE #include #include #include @@ -58,7 +58,7 @@ static int lua_readline(lua_State * l, char *b, const char *prompt) } } -void set_readline(readline foo) +void set_readline(readline_fun foo) { my_readline = foo; } @@ -190,7 +190,6 @@ static int pushline(lua_State * L, int firstline) lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */ else lua_pushstring(L, b); - lua_freeline(L, b); return 1; } diff --git a/src/console.h b/src/console.h index fdc869f11..de0e64348 100644 --- a/src/console.h +++ b/src/console.h @@ -30,8 +30,8 @@ extern "C" { extern int lua_console(struct lua_State *L); extern int lua_do(struct lua_State *L); - typedef int (*readline) (struct lua_State *, char *, size_t, const char *); - extern void set_readline(readline foo); + typedef int (*readline_fun) (struct lua_State *, char *, size_t, const char *); + extern void set_readline(readline_fun foo); #ifdef __cplusplus } From 4ce7932d14a381776198cc38236b4f5cec9dede8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:01:16 +0100 Subject: [PATCH 05/22] add some checks (cppcheck is weird). --- src/battle.test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/battle.test.c b/src/battle.test.c index b69996ddf..4b59e1abf 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -281,8 +281,10 @@ static void test_calculate_armor(CuTest * tc) b = NULL; i_change(&du->items, ibelt, 1); dt.fighter = setup_fighter(&b, du); + CuAssertIntEquals_Msg(tc, "without natural armor", 0, natural_armor(du)); CuAssertIntEquals_Msg(tc, "magical armor", 1, calculate_armor(dt, 0, 0, 0)); rc->armor = 2; + CuAssertIntEquals_Msg(tc, "with natural armor", 2, natural_armor(du)); CuAssertIntEquals_Msg(tc, "natural armor", 3, calculate_armor(dt, 0, 0, 0)); rc->armor = 0; free_battle(b); From 05242aaf2dc81493280f13a6bce3789bbddd2016 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:18:30 +0100 Subject: [PATCH 06/22] Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. --- src/donations.test.c | 2 +- src/economy.test.c | 18 ++++++++-------- src/give.test.c | 34 +++++++++++++++---------------- src/kernel/build.test.c | 2 +- src/kernel/messages.c | 2 +- src/laws.test.c | 30 +++++++++++++-------------- src/market.test.c | 2 +- src/monsters.test.c | 4 ++-- src/move.test.c | 12 +++++------ src/orderfile.test.c | 2 +- src/piracy.test.c | 12 +++++------ src/renumber.test.c | 2 +- src/spells.test.c | 4 ++-- src/spells/flyingship.test.c | 2 +- src/spells/magicresistance.test.c | 4 ++-- src/spy.test.c | 26 +++++++++++------------ src/study.test.c | 12 +++++------ src/tests.c | 6 +++--- src/triggers/shock.test.c | 2 +- src/util/message.h | 3 ++- src/util/message.test.c | 2 +- src/volcano.test.c | 8 ++++---- src/wormhole.test.c | 8 ++++---- 23 files changed, 100 insertions(+), 99 deletions(-) diff --git a/src/donations.test.c b/src/donations.test.c index e61ca2536..a3a428a73 100644 --- a/src/donations.test.c +++ b/src/donations.test.c @@ -13,7 +13,7 @@ static void test_add_donation(CuTest *tc) { region *r; test_setup(); - mt_register(mt_new_va("donation", "from:faction", "to:faction", "amount:int", NULL)); + mt_register(mt_new_va("donation", "from:faction", "to:faction", "amount:int", MT_NEW_END)); r = test_create_region(0, 0, NULL); f1 = test_create_faction(NULL); f2 = test_create_faction(NULL); diff --git a/src/economy.test.c b/src/economy.test.c index d4322fef7..943ac2090 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -143,10 +143,10 @@ static struct unit *create_recruiter(void) { static void setup_production(void) { init_resources(); - mt_register(mt_new_va("produce", "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", NULL)); - mt_register(mt_new_va("income", "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", NULL)); - mt_register(mt_new_va("buy", "unit:unit", "money:int", NULL)); - mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", NULL)); + mt_register(mt_new_va("produce", "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", MT_NEW_END)); + mt_register(mt_new_va("income", "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", MT_NEW_END)); + mt_register(mt_new_va("buy", "unit:unit", "money:int", MT_NEW_END)); + mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", MT_NEW_END)); } static void test_heroes_dont_recruit(CuTest * tc) { @@ -377,11 +377,11 @@ static void test_tax_cmd(CuTest *tc) { } static void setup_economy(void) { - mt_register(mt_new_va("recruit", "unit:unit", "region:region", "amount:int", "want:int", NULL)); - mt_register(mt_new_va("maintenance", "unit:unit", "building:building", NULL)); - mt_register(mt_new_va("maintenancefail", "unit:unit", "building:building", NULL)); - mt_register(mt_new_va("maintenance_nowork", "building:building", NULL)); - mt_register(mt_new_va("maintenance_noowner", "building:building", NULL)); + mt_register(mt_new_va("recruit", "unit:unit", "region:region", "amount:int", "want:int", MT_NEW_END)); + mt_register(mt_new_va("maintenance", "unit:unit", "building:building", MT_NEW_END)); + mt_register(mt_new_va("maintenancefail", "unit:unit", "building:building", MT_NEW_END)); + mt_register(mt_new_va("maintenance_nowork", "building:building", MT_NEW_END)); + mt_register(mt_new_va("maintenance_noowner", "building:building", MT_NEW_END)); } /** diff --git a/src/give.test.c b/src/give.test.c index 1f1985b6a..3e58216c9 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -54,24 +54,24 @@ static void setup_give(struct give *env) { } /* success messages: */ - mt_register(mt_new_va("receive_person", "unit:unit", "target:unit", "amount:int", NULL)); - mt_register(mt_new_va("give_person", "unit:unit", "target:unit", "amount:int", NULL)); - mt_register(mt_new_va("give_person_peasants", "unit:unit", "amount:int", NULL)); - mt_register(mt_new_va("give_person_ocean", "unit:unit", "amount:int", NULL)); - mt_register(mt_new_va("receive", "unit:unit", "target:unit", "resource:resource", "amount:int", NULL)); - mt_register(mt_new_va("give", "unit:unit", "target:unit", "resource:resource", "amount:int", NULL)); - mt_register(mt_new_va("give_peasants", "unit:unit", "resource:resource", "amount:int", NULL)); + mt_register(mt_new_va("receive_person", "unit:unit", "target:unit", "amount:int", MT_NEW_END)); + mt_register(mt_new_va("give_person", "unit:unit", "target:unit", "amount:int", MT_NEW_END)); + mt_register(mt_new_va("give_person_peasants", "unit:unit", "amount:int", MT_NEW_END)); + mt_register(mt_new_va("give_person_ocean", "unit:unit", "amount:int", MT_NEW_END)); + mt_register(mt_new_va("receive", "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END)); + mt_register(mt_new_va("give", "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END)); + mt_register(mt_new_va("give_peasants", "unit:unit", "resource:resource", "amount:int", MT_NEW_END)); /* error messages: */ - mt_register(mt_new_va("too_many_units_in_faction", "unit:unit", "region:region", "command:order", "allowed:int", NULL)); - mt_register(mt_new_va("too_many_units_in_alliance", "unit:unit", "region:region", "command:order", "allowed:int", NULL)); - mt_register(mt_new_va("feedback_no_contact", "unit:unit", "region:region", "command:order", "target:unit", NULL)); - mt_register(mt_new_va("feedback_give_forbidden", "unit:unit", "region:region", "command:order", NULL)); - mt_register(mt_new_va("peasants_give_invalid", "unit:unit", "region:region", "command:order", NULL)); - mt_register(mt_new_va("giverestriction", "unit:unit", "region:region", "command:order", "turns:int", NULL)); - mt_register(mt_new_va("error_unit_size", "unit:unit", "region:region", "command:order", "maxsize:int", NULL)); - mt_register(mt_new_va("nogive_reserved", "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", NULL)); - mt_register(mt_new_va("race_notake", "unit:unit", "region:region", "command:order", "race:race", NULL)); - mt_register(mt_new_va("race_noregroup", "unit:unit", "region:region", "command:order", "race:race", NULL)); + mt_register(mt_new_va("too_many_units_in_faction", "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END)); + mt_register(mt_new_va("too_many_units_in_alliance", "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END)); + mt_register(mt_new_va("feedback_no_contact", "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END)); + mt_register(mt_new_va("feedback_give_forbidden", "unit:unit", "region:region", "command:order", MT_NEW_END)); + mt_register(mt_new_va("peasants_give_invalid", "unit:unit", "region:region", "command:order", MT_NEW_END)); + mt_register(mt_new_va("giverestriction", "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END)); + mt_register(mt_new_va("error_unit_size", "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END)); + mt_register(mt_new_va("nogive_reserved", "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END)); + mt_register(mt_new_va("race_notake", "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END)); + mt_register(mt_new_va("race_noregroup", "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END)); } static void test_give_unit(CuTest * tc) { diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index ece28f4eb..d7a12325d 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -256,7 +256,7 @@ static void test_build_destroy_road(CuTest *tc) message *m; test_setup(); - mt_register(mt_new_va("destroy_road", "unit:unit", "from:region", "to:region", NULL)); + mt_register(mt_new_va("destroy_road", "unit:unit", "from:region", "to:region", MT_NEW_END)); r2 = test_create_region(1, 0, 0); r = test_create_region(0, 0, NULL); rsetroad(r, D_EAST, 100); diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 03883f127..d14ad4740 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -162,7 +162,7 @@ static message *missing_message(const char *name) { log_warning("trying to create undefined message of type \"%s\"\n", name); if (strcmp(name, "missing_message") != 0) { if (!mt_find("missing_message")) { - mt_register(mt_new_va("missing_message", "name:string", NULL)); + mt_register(mt_new_va("missing_message", "name:string", MT_NEW_END)); } return msg_message("missing_message", "name", name); } diff --git a/src/laws.test.c b/src/laws.test.c index 5edde187d..17de35fa1 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -257,7 +257,7 @@ static void test_force_leave_buildings(CuTest *tc) { building * b; test_setup(); - mt_register(mt_new_va("force_leave_building", "unit:unit", "owner:unit", "building:building", NULL)); + mt_register(mt_new_va("force_leave_building", "unit:unit", "owner:unit", "building:building", MT_NEW_END)); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(u1->faction, r); @@ -287,7 +287,7 @@ static void test_force_leave_ships(CuTest *tc) { ship *sh; test_setup(); - mt_register(mt_new_va("force_leave_ship", "unit:unit", "owner:unit", "ship:ship", NULL)); + mt_register(mt_new_va("force_leave_ship", "unit:unit", "owner:unit", "ship:ship", MT_NEW_END)); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); @@ -875,7 +875,7 @@ static void test_luck_message(CuTest *tc) { attrib *a; test_setup(); - mt_register(mt_new_va("peasantluck_success", "births:int", NULL)); + mt_register(mt_new_va("peasantluck_success", "births:int", MT_NEW_END)); setup_terrains(tc); r = test_create_region(0, 0, NULL); rsetpeasants(r, 1); @@ -900,8 +900,8 @@ static unit * setup_name_cmd(void) { faction *f; test_setup(); - mt_register(mt_new_va("renamed_building_seen", "renamer:unit", "region:region", "building:building", NULL)); - mt_register(mt_new_va("renamed_building_notseen", "region:region", "building:building", NULL)); + mt_register(mt_new_va("renamed_building_seen", "renamer:unit", "region:region", "building:building", MT_NEW_END)); + mt_register(mt_new_va("renamed_building_notseen", "region:region", "building:building", MT_NEW_END)); f = test_create_faction(NULL); return test_create_unit(f, test_create_region(0, 0, NULL)); } @@ -1300,9 +1300,9 @@ static void test_ally_cmd(CuTest *tc) { static void test_nmr_warnings(CuTest *tc) { faction *f1, *f2; test_setup(); - mt_register(mt_new_va("nmr_warning", NULL)); - mt_register(mt_new_va("nmr_warning_final", NULL)); - mt_register(mt_new_va("warn_dropout", "faction:faction", "turn:int", NULL)); + mt_register(mt_new_va("nmr_warning", MT_NEW_END)); + mt_register(mt_new_va("nmr_warning_final", MT_NEW_END)); + mt_register(mt_new_va("warn_dropout", "faction:faction", "turn:int", MT_NEW_END)); config_set("nmr.timeout", "3"); f1 = test_create_faction(NULL); f2 = test_create_faction(NULL); @@ -1324,9 +1324,9 @@ static unit * setup_mail_cmd(void) { faction *f; test_setup(); - mt_register(mt_new_va("regionmessage", "region:region", "sender:unit", "string:string", NULL)); - mt_register(mt_new_va("unitmessage", "region:region", "sender:unit", "string:string", "unit:unit", NULL)); - mt_register(mt_new_va("mail_result", "message:string", "unit:unit", NULL)); + mt_register(mt_new_va("regionmessage", "region:region", "sender:unit", "string:string", MT_NEW_END)); + mt_register(mt_new_va("unitmessage", "region:region", "sender:unit", "string:string", "unit:unit", MT_NEW_END)); + mt_register(mt_new_va("mail_result", "message:string", "unit:unit", MT_NEW_END)); f = test_create_faction(NULL); return test_create_unit(f, test_create_region(0, 0, NULL)); } @@ -1443,7 +1443,7 @@ static void test_show_without_item(CuTest *tc) struct locale *loc; test_setup(); - mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", NULL)); + mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", MT_NEW_END)); loc = get_or_create_locale("de"); locale_setstring(loc, parameters[P_ANY], "ALLE"); @@ -1488,7 +1488,7 @@ static void test_show_race(CuTest *tc) { test_setup(); - mt_register(mt_new_va("msg_event", "string:string", NULL)); + mt_register(mt_new_va("msg_event", "string:string", MT_NEW_END)); test_create_race("human"); rc = test_create_race("elf"); @@ -1528,8 +1528,8 @@ static void test_show_both(CuTest *tc) { message * msg; test_setup(); - mt_register(mt_new_va("msg_event", "string:string", NULL)); - mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", NULL)); + mt_register(mt_new_va("msg_event", "string:string", MT_NEW_END)); + mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", MT_NEW_END)); rc = test_create_race("elf"); test_create_itemtype("elvenhorse"); diff --git a/src/market.test.c b/src/market.test.c index 1fc8307fa..452f75091 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -33,7 +33,7 @@ static void test_market_curse(CuTest * tc) building_type *btype; test_setup(); - mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", NULL)); + mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", MT_NEW_END)); htype = test_create_itemtype("herb"); htype->flags |= ITF_HERB; diff --git a/src/monsters.test.c b/src/monsters.test.c index 32efc6a4c..47ae526f4 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -48,7 +48,7 @@ static void create_monsters(unit **up, unit **um) { region *r; faction *fp, *fm; - mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", NULL)); + mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", MT_NEW_END)); test_create_horse(); default_locale = test_create_locale(); fp = test_create_faction(NULL); @@ -216,7 +216,7 @@ static void test_dragon_moves(CuTest * tc) plan_monsters(m->faction); CuAssertPtrNotNull(tc, find_order("move east", m)); - mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", NULL)); + mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", MT_NEW_END)); random_growl(m, findregion(1, 0), 3); diff --git a/src/move.test.c b/src/move.test.c index 3aca0c2ab..3c8dccf32 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -28,8 +28,8 @@ #include static void setup_move(void) { - mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", NULL)); - mt_register(mt_new_va("moveblocked", "unit:unit", "direction:int", NULL)); + mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END)); + mt_register(mt_new_va("moveblocked", "unit:unit", "direction:int", MT_NEW_END)); } static void test_ship_not_allowed_in_coast(CuTest * tc) @@ -285,9 +285,9 @@ void setup_drift (struct drift_fixture *fix) { u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat)); assert(fix->sh); - mt_register(mt_new_va("ship_drift", "ship:ship", "dir:int", NULL)); - mt_register(mt_new_va("shipsink", "ship:ship", NULL)); - mt_register(mt_new_va("massive_overload", "ship:ship", NULL)); + mt_register(mt_new_va("ship_drift", "ship:ship", "dir:int", MT_NEW_END)); + mt_register(mt_new_va("shipsink", "ship:ship", MT_NEW_END)); + mt_register(mt_new_va("massive_overload", "ship:ship", MT_NEW_END)); } static void test_ship_no_overload(CuTest *tc) { @@ -482,7 +482,7 @@ static void test_follow_ship_msg(CuTest * tc) { td->dir = D_NORTHWEST; td->age = 2; - mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order", NULL)); + mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order", MT_NEW_END)); init_order_depr(ord); getstrtoken(); diff --git a/src/orderfile.test.c b/src/orderfile.test.c index 500c68fdf..904814856 100644 --- a/src/orderfile.test.c +++ b/src/orderfile.test.c @@ -63,7 +63,7 @@ static void test_faction_password_bad(CuTest *tc) { const char *orders[] = { "ERESSEA 1 password", NULL }; test_setup(); - mt_register(mt_new_va("wrongpasswd", "password:string", NULL)); + mt_register(mt_new_va("wrongpasswd", "password:string", MT_NEW_END)); f = test_create_faction(NULL); renumber_faction(f, 1); diff --git a/src/piracy.test.c b/src/piracy.test.c index 22f5ccc5a..110dc3dcf 100644 --- a/src/piracy.test.c +++ b/src/piracy.test.c @@ -30,12 +30,12 @@ static void setup_piracy(void) { st_boat = test_create_shiptype("boat"); st_boat->cargo = 1000; - mt_register(mt_new_va("piratenovictim", "ship:ship", "unit:unit", "region:region", NULL)); - mt_register(mt_new_va("piratesawvictim", "ship:ship", "unit:unit", "region:region", "dir:int", NULL)); - mt_register(mt_new_va("shipsail", "ship:ship", "from:region", "to:region", NULL)); - mt_register(mt_new_va("shipfly", "ship:ship", "from:region", "to:region", NULL)); - mt_register(mt_new_va("shipnoshore", "ship:ship", "region:region", NULL)); - mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", NULL)); + mt_register(mt_new_va("piratenovictim", "ship:ship", "unit:unit", "region:region", MT_NEW_END)); + mt_register(mt_new_va("piratesawvictim", "ship:ship", "unit:unit", "region:region", "dir:int", MT_NEW_END)); + mt_register(mt_new_va("shipsail", "ship:ship", "from:region", "to:region", MT_NEW_END)); + mt_register(mt_new_va("shipfly", "ship:ship", "from:region", "to:region", MT_NEW_END)); + mt_register(mt_new_va("shipnoshore", "ship:ship", "region:region", MT_NEW_END)); + mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END)); } static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const char *p_shiptype, diff --git a/src/renumber.test.c b/src/renumber.test.c index 0c2030379..f176cc3d2 100644 --- a/src/renumber.test.c +++ b/src/renumber.test.c @@ -38,7 +38,7 @@ static void test_renumber_faction_duplicate(CuTest *tc) { const struct locale *lang; test_setup_ex(tc); - mt_register(mt_new_va("renumber_inuse", "id:int", NULL)); + mt_register(mt_new_va("renumber_inuse", "id:int", MT_NEW_END)); f2 = test_create_faction(NULL); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); no = f->no; diff --git a/src/spells.test.c b/src/spells.test.c index e151e7680..dc0644ecc 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -130,8 +130,8 @@ static void test_view_reality(CuTest *tc) { test_setup(); setup_spells(); - mt_register(mt_new_va("spell_astral_only", "unit:unit", "region:region", "command:order", NULL)); - mt_register(mt_new_va("viewreality_effect", "unit:unit", NULL)); + mt_register(mt_new_va("spell_astral_only", "unit:unit", "region:region", "command:order", MT_NEW_END)); + mt_register(mt_new_va("viewreality_effect", "unit:unit", MT_NEW_END)); r = test_create_region(0, 0, NULL); ra = test_create_region(real2tp(r->x), real2tp(r->y), NULL); ra->_plane = get_astralplane(); diff --git a/src/spells/flyingship.test.c b/src/spells/flyingship.test.c index 3459adcd3..4440c5fdf 100644 --- a/src/spells/flyingship.test.c +++ b/src/spells/flyingship.test.c @@ -29,7 +29,7 @@ static void test_flyingship(CuTest * tc) ship *sh1, *sh2; test_setup(); - mt_register(mt_new_va("flying_ship_result", "mage:unit", "ship:ship", NULL)); + mt_register(mt_new_va("flying_ship_result", "mage:unit", "ship:ship", MT_NEW_END)); par.param = &par_data_ptr; par_data.typ = SPP_SHIP; diff --git a/src/spells/magicresistance.test.c b/src/spells/magicresistance.test.c index ccce0216c..86a66bc0e 100644 --- a/src/spells/magicresistance.test.c +++ b/src/spells/magicresistance.test.c @@ -29,7 +29,7 @@ static void test_magicresistance_unit(CuTest *tc) { curse *c; test_setup(); - mt_register(mt_new_va("magicresistance_unit", "unit:unit", "id:int", NULL)); + mt_register(mt_new_va("magicresistance_unit", "unit:unit", "id:int", MT_NEW_END)); r = test_create_plain(0, 0); f1 = test_create_faction(NULL); u1 = test_create_unit(f1, r); @@ -57,7 +57,7 @@ static void test_magicresistance_building(CuTest *tc) { curse *c; test_setup(); - mt_register(mt_new_va("magicresistance_building", "building:building", "id:int", NULL)); + mt_register(mt_new_va("magicresistance_building", "building:building", "id:int", MT_NEW_END)); r = test_create_plain(0, 0); f1 = test_create_faction(NULL); u1 = test_create_unit(f1, r); diff --git a/src/spy.test.c b/src/spy.test.c index 79108f03b..c6a74822c 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -33,19 +33,19 @@ typedef struct { } spy_fixture; static void setup_spy(spy_fixture *fix) { - mt_register(mt_new_va("spyreport", "spy:unit", "target:unit", "status:int", NULL)); - mt_register(mt_new_va("spyreport_mage", "spy:unit", "target:unit", "type:int", NULL)); - mt_register(mt_new_va("spyreport_faction", "spy:unit", "target:unit", "faction:faction", NULL)); - mt_register(mt_new_va("spyreport_skills", "spy:unit", "target:unit", "skills:string", NULL)); - mt_register(mt_new_va("spyreport_items", "spy:unit", "target:unit", "items:items", NULL)); - mt_register(mt_new_va("destroy_ship_0", "unit:unit", "ship:ship", NULL)); - mt_register(mt_new_va("destroy_ship_1", "unit:unit", "ship:ship", NULL)); - mt_register(mt_new_va("destroy_ship_2", "unit:unit", "ship:ship", NULL)); - mt_register(mt_new_va("destroy_ship_3", "ship:ship", NULL)); - mt_register(mt_new_va("destroy_ship_4", "ship:ship", NULL)); - mt_register(mt_new_va("sink_msg", "ship:ship", "region:region", NULL)); - mt_register(mt_new_va("sink_lost_msg", "unit:unit", "region:region", "dead:int", NULL)); - mt_register(mt_new_va("sink_saved_msg", "unit:unit", "region:region", NULL)); + mt_register(mt_new_va("spyreport", "spy:unit", "target:unit", "status:int", MT_NEW_END)); + mt_register(mt_new_va("spyreport_mage", "spy:unit", "target:unit", "type:int", MT_NEW_END)); + mt_register(mt_new_va("spyreport_faction", "spy:unit", "target:unit", "faction:faction", MT_NEW_END)); + mt_register(mt_new_va("spyreport_skills", "spy:unit", "target:unit", "skills:string", MT_NEW_END)); + mt_register(mt_new_va("spyreport_items", "spy:unit", "target:unit", "items:items", MT_NEW_END)); + mt_register(mt_new_va("destroy_ship_0", "unit:unit", "ship:ship", MT_NEW_END)); + mt_register(mt_new_va("destroy_ship_1", "unit:unit", "ship:ship", MT_NEW_END)); + mt_register(mt_new_va("destroy_ship_2", "unit:unit", "ship:ship", MT_NEW_END)); + mt_register(mt_new_va("destroy_ship_3", "ship:ship", MT_NEW_END)); + mt_register(mt_new_va("destroy_ship_4", "ship:ship", MT_NEW_END)); + mt_register(mt_new_va("sink_msg", "ship:ship", "region:region", MT_NEW_END)); + mt_register(mt_new_va("sink_lost_msg", "unit:unit", "region:region", "dead:int", MT_NEW_END)); + mt_register(mt_new_va("sink_saved_msg", "unit:unit", "region:region", MT_NEW_END)); if (fix) { fix->r = test_create_region(0, 0, NULL); diff --git a/src/study.test.c b/src/study.test.c index b89d0ed07..46722c0f6 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -58,9 +58,9 @@ typedef struct { } study_fixture; static void setup_study(void) { - mt_register(mt_new_va("studycost", "unit:unit", "region:region", "cost:int", "skill:int", NULL)); - mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", NULL)); - mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", NULL)); + mt_register(mt_new_va("studycost", "unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END)); + mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END)); + mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", MT_NEW_END)); } static void setup_locale(struct locale *lang) { @@ -218,7 +218,7 @@ static void test_academy_building(CuTest *tc) { message * msg; test_setup(); - mt_register(mt_new_va("teach_asgood", "unit:unit", "region:region", "command:order", "student:unit", NULL)); + mt_register(mt_new_va("teach_asgood", "unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END)); random_source_inject_constant(0.0); init_resources(); @@ -636,8 +636,8 @@ static void test_teach_message(CuTest *tc) { teaching_info *teach; test_setup(); - mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", NULL)); - mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", NULL)); + mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END)); + mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", MT_NEW_END)); init_resources(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u, 20); diff --git a/src/tests.c b/src/tests.c index 18ecdef34..282814148 100644 --- a/src/tests.c +++ b/src/tests.c @@ -231,9 +231,9 @@ static void test_reset(void) { } random_source_reset(); - mt_register(mt_new_va("changepasswd", "value:string", NULL)); - mt_register(mt_new_va("starvation", "unit:unit", "region:region", "dead:int", "live:int", NULL)); - mt_register(mt_new_va("malnourish", "unit:unit", "region:region", NULL)); + mt_register(mt_new_va("changepasswd", "value:string", MT_NEW_END)); + mt_register(mt_new_va("starvation", "unit:unit", "region:region", "dead:int", "live:int", MT_NEW_END)); + mt_register(mt_new_va("malnourish", "unit:unit", "region:region", MT_NEW_END)); if (errno) { int error = errno; diff --git a/src/triggers/shock.test.c b/src/triggers/shock.test.c index 314c877df..dad675e64 100644 --- a/src/triggers/shock.test.c +++ b/src/triggers/shock.test.c @@ -12,7 +12,7 @@ #include static void shock_setup(void) { - mt_register(mt_new_va("shock", "mage:unit", "reason:string", NULL)); + mt_register(mt_new_va("shock", "mage:unit", "reason:string", MT_NEW_END)); } static void test_shock(CuTest *tc) { diff --git a/src/util/message.h b/src/util/message.h index 5937fb83e..7521b8e24 100644 --- a/src/util/message.h +++ b/src/util/message.h @@ -45,8 +45,9 @@ extern "C" { void mt_clear(void); struct message_type *mt_new(const char *name, const char *args[]); struct message_type *mt_new_va(const char *name, ...); +#define MT_NEW_END ((const char *)0) /* mt_new("simple_sentence", "subject:string", "predicate:string", - * "object:string", "lang:locale", NULL); */ + * "object:string", "lang:locale", MT_NEW_END); */ struct message *msg_create(const struct message_type *type, variant args[]); diff --git a/src/util/message.test.c b/src/util/message.test.c index e86b3aa38..4b00b4006 100644 --- a/src/util/message.test.c +++ b/src/util/message.test.c @@ -8,7 +8,7 @@ static void test_mt_new(CuTest *tc) { message_type *mt; test_setup(); - mt = mt_new_va("test", "name:string", "number:int", NULL); + mt = mt_new_va("test", "name:string", "number:int", MT_NEW_END); mt_register(mt); CuAssertPtrNotNull(tc, mt); CuAssertStrEquals(tc, "test", mt->name); diff --git a/src/volcano.test.c b/src/volcano.test.c index bc2aa2165..8a8358c1c 100644 --- a/src/volcano.test.c +++ b/src/volcano.test.c @@ -20,7 +20,7 @@ static void test_volcano_update(CuTest *tc) { const struct terrain_type *t_volcano, *t_active; test_setup(); - mt_register(mt_new_va("volcanostopsmoke", "region:region", NULL)); + mt_register(mt_new_va("volcanostopsmoke", "region:region", MT_NEW_END)); t_volcano = test_create_terrain("volcano", LAND_REGION); t_active = test_create_terrain("activevolcano", LAND_REGION); r = test_create_region(0, 0, t_active); @@ -42,9 +42,9 @@ static void test_volcano_outbreak(CuTest *tc) { const struct terrain_type *t_volcano, *t_active; test_setup(); - mt_register(mt_new_va("volcanooutbreak", "regionv:region", "regionn:region", NULL)); - mt_register(mt_new_va("volcanooutbreaknn", "region:region", NULL)); - mt_register(mt_new_va("volcano_dead", "unit:unit", "region:region", "dead:int", NULL)); + mt_register(mt_new_va("volcanooutbreak", "regionv:region", "regionn:region", MT_NEW_END)); + mt_register(mt_new_va("volcanooutbreaknn", "region:region", MT_NEW_END)); + mt_register(mt_new_va("volcano_dead", "unit:unit", "region:region", "dead:int", MT_NEW_END)); t_volcano = test_create_terrain("volcano", LAND_REGION); t_active = test_create_terrain("activevolcano", LAND_REGION); r = test_create_region(0, 0, t_active); diff --git a/src/wormhole.test.c b/src/wormhole.test.c index eafa86572..e275d4d67 100644 --- a/src/wormhole.test.c +++ b/src/wormhole.test.c @@ -19,10 +19,10 @@ void sort_wormhole_regions(selist *rlist, region **match, int count); void make_wormholes(region **match, int count, const building_type *bt_wormhole); static void setup_wormholes(void) { - mt_register(mt_new_va("wormhole_appear", "region:region", NULL)); - mt_register(mt_new_va("wormhole_dissolve", "region:region", NULL)); - mt_register(mt_new_va("wormhole_exit", "unit:unit", "region:region", NULL)); - mt_register(mt_new_va("wormhole_requirements", "unit:unit", "region:region", NULL)); + mt_register(mt_new_va("wormhole_appear", "region:region", MT_NEW_END)); + mt_register(mt_new_va("wormhole_dissolve", "region:region", MT_NEW_END)); + mt_register(mt_new_va("wormhole_exit", "unit:unit", "region:region", MT_NEW_END)); + mt_register(mt_new_va("wormhole_requirements", "unit:unit", "region:region", MT_NEW_END)); } static void test_make_wormholes(CuTest *tc) { From 6dd3783ecb8ae7b5151f2c2b6b6ba18bfa6ad13e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:19:54 +0100 Subject: [PATCH 07/22] unused #define --- src/eressea.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/eressea.c b/src/eressea.c index 95d190d70..d4543a39a 100644 --- a/src/eressea.c +++ b/src/eressea.c @@ -50,9 +50,7 @@ void game_done(void) free_game(); creport_cleanup(); -#ifdef REPORT_FORMAT_NR report_cleanup(); -#endif #endif calendar_cleanup(); free_functions(); From d802f6ea6700ba9a3073892cca387c627ca6cc48 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:28:42 +0100 Subject: [PATCH 08/22] cppcheck: reduce variable scope. --- src/economy.c | 38 +++++++++++++++++++------------------- src/economy.h | 2 +- src/steal.c | 3 +-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/economy.c b/src/economy.c index 82890888e..670036b16 100644 --- a/src/economy.c +++ b/src/economy.c @@ -141,11 +141,11 @@ static void scramble(void *data, unsigned int n, size_t width) } } -unsigned int expand_production(region * r, econ_request * requests, econ_request ***results) +int expand_production(region * r, econ_request * requests, econ_request ***results) { unit *u; econ_request *o; - unsigned int norders = 0; + int norders = 0; /* Alle Units ohne production haben ein -1, alle units mit orders haben ein * 0 hier stehen */ @@ -190,7 +190,7 @@ static void free_requests(econ_request *requests) { } } -static unsigned int expandorders(region * r, econ_request * requests) { +static int expandorders(region * r, econ_request * requests) { return expand_production(r, requests, &g_requests); } @@ -333,7 +333,7 @@ static int do_recruiting(recruitment * recruits, int available) for (req = rec->requests; req; req = req->next) { unit *u = req->unit; const race *rc = u_race(u); /* race is set in recruit() */ - int number, dec; + int number; double multi = 2.0 * rc->recruit_multi; number = (int)(get / multi); @@ -359,7 +359,7 @@ static int do_recruiting(recruitment * recruits, int available) } add_recruits(u, number, req->qty); if (number > 0) { - dec = (int)(number * multi); + int dec = (int)(number * multi); if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) { recruited += dec; } @@ -388,8 +388,7 @@ void free_recruitments(recruitment * recruits) /* Rekrutierung */ static void expandrecruit(region * r, econ_request * recruitorders) { - recruitment *recruits = NULL; - + recruitment *recruits; int orc_total = 0; /* peasant limited: */ @@ -430,12 +429,10 @@ static int recruit_cost(const faction * f, const race * rc) static void recruit(unit * u, struct order *ord, econ_request ** recruitorders) { region *r = u->region; - plane *pl; econ_request *o; int recruitcost = -1; const faction *f = u->faction; const struct race *rc = u_race(u); - const char *str; int n; init_order_depr(ord); @@ -447,6 +444,8 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders) if (u->number == 0) { char token[128]; + const char *str; + str = gettoken(token, sizeof(token)); if (str && str[0]) { /* Monsters can RECRUIT 15 DRACOID @@ -506,7 +505,7 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders) } if (recruitcost) { - pl = getplane(r); + plane *pl = getplane(r); if (pl && fval(pl, PFL_NORECRUITS)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_pflnorecruit", "")); return; @@ -1006,7 +1005,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) } } - assert(sk != NOSKILL || "limited resource needs a required skill for making it"); + assert(sk != NOSKILL || !"limited resource needs a required skill for making it"); skill = effskill(u, sk, 0); if (skill == 0) { add_message(&u->faction->msgs, @@ -1075,10 +1074,10 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) { const item_type *itype = resource2item(rtype); rawmaterial *rm = rm_get(r, rtype); - int need; - bool first = true; if (rm != NULL) { + int need; + bool first = true; do { int avail = rm->amount; int nreq = 0; @@ -1302,7 +1301,6 @@ int make_cmd(unit * u, struct order *ord) int m = INT_MAX; const char *s; const struct locale *lang = u->faction->locale; - char ibuf[16]; keyword_t kwd; kwd = init_order_depr(ord); @@ -1310,6 +1308,7 @@ int make_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); if (s) { + char ibuf[16]; m = atoip(s); sprintf(ibuf, "%d", m); if (!strcmp(ibuf, (const char *)s)) { @@ -1676,8 +1675,8 @@ static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 }; static void expandselling(region * r, econ_request * sellorders, int limit) { - int money, price, max_products; - unsigned int j, norders; + int money, max_products; + int norders; /* int m, n = 0; */ int maxsize = 0, maxeffsize = 0; int taxcollected = 0; @@ -1754,11 +1753,12 @@ static void expandselling(region * r, econ_request * sellorders, int limit) norders = expandorders(r, sellorders); if (norders > 0) { + int j; for (j = 0; j != norders; j++) { const luxury_type *search = NULL; const luxury_type *ltype = g_requests[j]->type.trade.ltype; int multi = r_demand(r, ltype); - int i; + int i, price; int use = 0; for (i = 0, search = luxurytypes; search != ltype; search = search->next) { /* TODO: this is slow and lame! */ @@ -2339,13 +2339,13 @@ static void research_cmd(unit * u, struct order *ord) static void expandentertainment(region * r) { - unit *u; int m = entertainmoney(r); econ_request *o; for (o = &entertainers[0]; o != nextentertainer; ++o) { double part = m / (double)entertaining; - u = o->unit; + unit *u = o->unit; + if (entertaining <= m) u->n = o->qty; else diff --git a/src/economy.h b/src/economy.h index ec12ae0ca..d3e8f0aa0 100644 --- a/src/economy.h +++ b/src/economy.h @@ -71,7 +71,7 @@ extern "C" { void produce(struct region *r); void auto_work(struct region *r); - unsigned int expand_production(struct region * r, struct econ_request * requests, struct econ_request ***results); + int expand_production(struct region * r, struct econ_request * requests, struct econ_request ***results); typedef enum income_t { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT } income_t; void add_income(struct unit * u, income_t type, int want, int qty); diff --git a/src/steal.c b/src/steal.c index 65316f1dd..9403b4fd8 100644 --- a/src/steal.c +++ b/src/steal.c @@ -49,8 +49,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. void expandstealing(region * r, econ_request * stealorders) { const resource_type *rsilver = get_resourcetype(R_SILVER); - unsigned int j; - unsigned int norders; + int norders, j; econ_request **requests; assert(rsilver); From fc2506ee83af2f6074a87245b4c24dd559726b6e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:58:45 +0100 Subject: [PATCH 09/22] cppcheck: DMAXHASH was unused. cppcheck: remove warnings, reduce variable scopes. --- src/give.c | 26 +++++++++-------- src/gmtool.c | 23 +++++++-------- src/helpers.c | 57 +++++++++++++++++++------------------ src/items.c | 5 ++-- src/items/xerewards.test.c | 2 +- src/jsonconf.c | 3 +- src/jsreport.c | 5 ++-- src/kernel/ally.c | 2 +- src/kernel/building.c | 12 ++++---- src/kernel/connection.c | 8 +++--- src/kernel/curse.c | 2 +- src/kernel/equipment.test.c | 2 +- src/kernel/faction.c | 11 ------- src/kernel/faction.test.c | 2 +- src/kernel/group.test.c | 2 +- src/kernel/unit.c | 37 ------------------------ 16 files changed, 77 insertions(+), 122 deletions(-) diff --git a/src/give.c b/src/give.c index 5d5673bd2..284908e3b 100644 --- a/src/give.c +++ b/src/give.c @@ -158,13 +158,15 @@ static bool limited_give(const item_type * type) int give_quota(const unit * src, const unit * dst, const item_type * type, int n) { - double divisor; - if (!limited_give(type)) { return n; } if (dst && src && src->faction != dst->faction) { - divisor = config_get_flt("rules.items.give_divisor", 1); + static int config; + static double divisor = 1.0; + if (config_changed(&config)) { + divisor = config_get_flt("rules.items.give_divisor", divisor); + } assert(divisor <= 0 || divisor >= 1); if (divisor >= 1) { /* predictable > correct: */ @@ -305,8 +307,6 @@ static bool rule_transfermen(void) message * give_men(int n, unit * u, unit * u2, struct order *ord) { - ship *sh; - int k = 0; int error = 0; message * msg; int maxt = max_transfers(); @@ -391,7 +391,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) } if (has_skill(u, SK_ALCHEMY) || has_skill(u2, SK_ALCHEMY)) { - k = count_skill(u2->faction, SK_ALCHEMY); + int k = count_skill(u2->faction, SK_ALCHEMY); /* Falls die Zieleinheit keine Alchemisten sind, werden sie nun * welche. */ @@ -414,6 +414,14 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) } if (error == 0) { + ship *sh = leftship(u); + + /* Einheiten von Schiffen können nicht NACH in von + * Nicht-alliierten bewachten Regionen ausführen */ + if (sh) { + set_leftship(u2, sh); + } + if (u2->number == 0) { set_racename(&u2->attribs, get_racename(u->attribs)); u_setrace(u2, u_race(u)); @@ -426,12 +434,6 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) } } - /* Einheiten von Schiffen können nicht NACH in von - * Nicht-alliierten bewachten Regionen ausführen */ - sh = leftship(u); - if (sh) { - set_leftship(u2, sh); - } transfermen(u, u2, n); if (maxt >= 0 && u->faction != u2->faction) { u2->faction->newbies += n; diff --git a/src/gmtool.c b/src/gmtool.c index 010adce6f..6051ed9cc 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -137,10 +137,10 @@ int umvwaddnstr(WINDOW *w, int y, int x, const char * str, int len) { static void init_curses(void) { - int fg, bg; initscr(); if (has_colors() || force_color) { + int fg, bg; short bcol = COLOR_BLACK; short hcol = COLOR_MAGENTA; start_color(); @@ -316,11 +316,11 @@ static void paint_map(window * wnd, const state * st) int yp = (lines - vy - 1) * THEIGHT; for (vx = 0; vx != cols; ++vx) { map_region *mr = mr_get(&st->display, vx, vy); - int attr = 0; - int hl = 0; int xp = vx * TWIDTH + (vy & 1) * TWIDTH / 2; int nx, ny; if (mr) { + int attr = 0; + int hl = 0; cnormalize(&mr->coord, &nx, &ny); if (tagged_region(st->selected, nx, ny)) { attr |= A_REVERSE; @@ -335,10 +335,10 @@ static void paint_map(window * wnd, const state * st) map_region *cursor_region(const view * v, const coordinate * c) { - coordinate relpos; - int cx, cy; - if (c) { + int cx, cy; + coordinate relpos; + relpos.x = c->x - v->topleft.x; relpos.y = c->y - v->topleft.y; cy = relpos.y; @@ -435,13 +435,14 @@ static void paint_info_region(window * wnd, const state * st) { WINDOW *win = wnd->handle; int size = getmaxx(win) - 2; - int line = 0, maxline = getmaxy(win) - 2; + int maxline = getmaxy(win) - 2; map_region *mr = cursor_region(&st->display, &st->cursor); UNUSED_ARG(st); werase(win); wxborder(win); if (mr && mr->r) { + int line = 0; const region *r = mr->r; if (r->land) { umvwaddnstr(win, line++, 1, (char *)r->land->name, size); @@ -717,10 +718,10 @@ static void select_regions(state * st, int selectmode) doupdate(); findmode = getch(); if (findmode == 'n') { /* none */ - int i; sprintf(sbuffer, "%snone", status); statusline(st->wnd_status->handle, sbuffer); if (selectmode & MODE_SELECT) { + int i; for (i = 0; i != MAXTHASH; ++i) { tag **tp = &st->selected->tags[i]; while (*tp) { @@ -945,7 +946,6 @@ static void handlekey(state * st, int c) static int findmode = 0; region *r; char sbuffer[80]; - static char kbuffer[80]; int n, nx, ny, minpop, maxpop; switch (c) { @@ -1328,6 +1328,7 @@ static void handlekey(state * st, int c) } } if (wnd == NULL) { + static char kbuffer[80]; if (kbuffer[0] == 0) { strcpy(kbuffer, "getch:"); } @@ -1399,9 +1400,9 @@ void run_mapper(void) int split = 20; state *st; point tl; - char sbuffer[512]; if (!new_players) { + char sbuffer[512]; path_join(basepath(), "newfactions", sbuffer, sizeof(sbuffer)); new_players = read_newfactions(sbuffer); } @@ -1443,8 +1444,6 @@ void run_mapper(void) view *vi = &st->display; getbegyx(hwinmap, x, y); - width = getmaxx(hwinmap) - x; - height = getmaxy(hwinmap) - y; coor2point(&st->cursor, &p); if (st->cursor.pl != vi->pl) { diff --git a/src/helpers.c b/src/helpers.c index b5c4c05ba..8bea72331 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -1,4 +1,4 @@ -/* +/* +-------------------+ | | Enno Rehling | Eressea PBEM host | Christian Schlittchen @@ -228,7 +228,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta) if (lua_isfunction(L, -1)) { tolua_pushusertype(L, u, TOLUA_CAST "unit"); lua_pushinteger(L, delta); - + if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); log_error("change(%s) calling '%s': %s.\n", unitname(u), fname, error); @@ -254,39 +254,40 @@ use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord) lua_State *L = (lua_State *)global.vm_state; int len, result = 0; char fname[64]; - int (*callout)(unit *, const item_type *, int, struct order *); len = snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name); if (len > 0 && (size_t)len < sizeof(fname)) { - callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname); - if (callout) { - return callout(u, itype, amount, ord); - } + int(*callout)(unit *, const item_type *, int, struct order *); + callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname); + if (callout) { + return callout(u, itype, amount, ord); + } - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); - lua_pushinteger(L, amount); - lua_pushstring(L, getstrtoken()); - tolua_pushusertype(L, (void *)ord, TOLUA_CAST "order"); - if (lua_pcall(L, 4, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error); - lua_pop(L, 1); + lua_getglobal(L, fname); + if (lua_isfunction(L, -1)) { + tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); + lua_pushinteger(L, amount); + lua_pushstring(L, getstrtoken()); + tolua_pushusertype(L, (void *)ord, TOLUA_CAST "order"); + if (lua_pcall(L, 4, 1, 0) != 0) { + const char *error = lua_tostring(L, -1); + log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error); + lua_pop(L, 1); + } + else { + result = (int)lua_tonumber(L, -1); + lua_pop(L, 1); + } + return result; + } + lua_pop(L, 1); + if (itype->flags & ITF_POTION) { + return use_potion(u, itype, amount, ord); } else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); + log_error("no such callout: %s", fname); } - return result; - } - lua_pop(L, 1); - if (itype->flags & ITF_POTION) { - return use_potion(u, itype, amount, ord); - } else { - log_error("no such callout: %s", fname); - } - log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname); + log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname); } return result; } diff --git a/src/items.c b/src/items.c index ba9f35388..e9e1d7e8a 100644 --- a/src/items.c +++ b/src/items.c @@ -121,14 +121,14 @@ use_antimagiccrystal(unit * u, const struct item_type *itype, int amount, struct order *ord) { region *r = u->region; - const resource_type *rt_crystal = NULL; + const resource_type *rt_crystal; int i; rt_crystal = rt_find("antimagic"); assert(rt_crystal != NULL); for (i = 0; i != amount; ++i) { - int effect, duration = 2; + int effect; double force; spell *sp = find_spell("antimagiczone"); attrib **ap = &r->attribs; @@ -172,6 +172,7 @@ struct order *ord) } if (force > 0) { + int duration = 2; create_curse(u, &r->attribs, &ct_antimagiczone, force, duration, effect, 0); } diff --git a/src/items/xerewards.test.c b/src/items/xerewards.test.c index c0d20079e..8e30d88eb 100644 --- a/src/items/xerewards.test.c +++ b/src/items/xerewards.test.c @@ -43,7 +43,7 @@ static void test_manacrystal(CuTest *tc) { static void test_skillpotion(CuTest *tc) { unit *u; const struct item_type *itype; - skill* pSkill = NULL; + skill* pSkill; int initialWeeks_Entertainment = 0; int initialWeeks_Stamina = 0; int initialWeeks_Magic = 0; diff --git a/src/jsonconf.c b/src/jsonconf.c index 3c5411b9d..0c1c0c97e 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -124,7 +124,7 @@ static void json_maintenance_i(cJSON *json, maintenance *mt) { static void json_maintenance(cJSON *json, maintenance **mtp) { cJSON *child; maintenance *mt; - int i, size = 1; + int size = 1; if (json->type == cJSON_Array) { size = cJSON_GetArraySize(json); @@ -135,6 +135,7 @@ static void json_maintenance(cJSON *json, maintenance **mtp) { } *mtp = mt = (struct maintenance *) calloc(sizeof(struct maintenance), size + 1); if (json->type == cJSON_Array) { + int i; for (i = 0, child = json->child; child; child = child->next, ++i) { if (child->type == cJSON_Object) { json_maintenance_i(child, mt + i); diff --git a/src/jsreport.c b/src/jsreport.c index dc22c760a..a5c730438 100644 --- a/src/jsreport.c +++ b/src/jsreport.c @@ -27,7 +27,7 @@ static int report_json(const char *filename, report_context * ctx, const char *c if (config_get_int("jsreport.enabled", 0) != 0) { FILE * F = fopen(filename, "w"); if (F) { - int x, y, minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN; + int minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN; seen_region *sr; region *r; /* traverse all regions */ @@ -44,12 +44,13 @@ static int report_json(const char *filename, report_context * ctx, const char *c else if (tx > maxx) maxx = tx; } if (maxx >= minx && maxy >= miny) { - int w = maxx - minx + 1, h = maxy - miny + 1; + int y, w = maxx - minx + 1, h = maxy - miny + 1; fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F); fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w); fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w); fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F); for (y = miny; y <= maxy; ++y) { + int x; for (x = minx; x <= maxx; ++x) { int data = 0; int tx = x, ty = y; diff --git a/src/kernel/ally.c b/src/kernel/ally.c index dbb6aff3a..2f3d6a017 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -233,7 +233,6 @@ alliedfaction(const struct plane *pl, const struct faction *f, /* Die Gruppe von Einheit u hat helfe zu f2 gesetzt. */ int alliedunit(const unit * u, const faction * f2, int mode) { - ally *sf; int automode; assert(u); @@ -242,6 +241,7 @@ int alliedunit(const unit * u, const faction * f2, int mode) if (u->faction == f2) return mode; if (u->faction != NULL && f2 != NULL) { + ally *sf; plane *pl; if (mode & HELP_FIGHT) { diff --git a/src/kernel/building.c b/src/kernel/building.c index 35efa8579..ad26d114b 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -350,7 +350,7 @@ building *new_building(const struct building_type * btype, region * r, { building **bptr = &r->buildings; building *b = (building *)calloc(1, sizeof(building)); - const char *bname = 0; + const char *bname; char buffer[32]; b->no = newcontainerid(); @@ -363,14 +363,12 @@ building *new_building(const struct building_type * btype, region * r, *bptr = b; update_lighthouse(b); - if (!bname) { - bname = LOC(lang, btype->_name); - } + bname = LOC(lang, btype->_name); if (!bname) { bname = LOC(lang, parameters[P_GEBAEUDE]); - } - if (!bname) { - bname = parameters[P_GEBAEUDE]; + if (!bname) { + bname = parameters[P_GEBAEUDE]; + } } assert(bname); snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no)); diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 516cb6ead..35e96658d 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -156,9 +156,10 @@ connection *get_borders(const region * r1, const region * r2) connection *new_border(border_type * type, region * from, region * to) { - connection *b, **bp = get_borders_i(from, to); + connection *b, **bp; assert(from && to); + bp = get_borders_i(from, to); while (*bp) { bp = &(*bp)->next; } @@ -242,7 +243,7 @@ void b_read(connection * b, gamedata * data) assert(!"invalid variant type in connection"); result = 0; } - assert(result >= 0 || "EOF encountered?"); + assert(result >= 0 || !"EOF encountered?"); } void b_write(const connection * b, storage * store) @@ -559,8 +560,7 @@ static bool b_validroad(const connection * b) static bool b_rvisibleroad(const connection * b, const region * r) { - int x = b->data.i; - x = (r == b->from) ? b->data.sa[0] : b->data.sa[1]; + int x = (r == b->from) ? b->data.sa[0] : b->data.sa[1]; if (x == 0) { return false; } diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 0f215dbee..ae4f481a1 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -609,7 +609,6 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, static void do_transfer_curse(curse * c, const unit * u, unit * u2, int n) { - int cursedmen = 0; int men = get_cursedmen(u, c); bool dogive = false; const curse_type *ct = c->type; @@ -622,6 +621,7 @@ static void do_transfer_curse(curse * c, const unit * u, unit * u2, int n) case CURSE_SPREADMODULO: { + int cursedmen = 0; int i; int u_number = u->number; for (i = 0; i < n + 1 && u_number > 0; i++) { diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 5c0757601..1a1bbfdf1 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -60,8 +60,8 @@ static void test_get_equipment(CuTest * tc) eq = get_equipment("catapult"); CuAssertPtrEquals(tc, NULL, eq); eq = create_equipment("catapult"); - eq = get_equipment("catapult"); CuAssertPtrNotNull(tc, eq); + CuAssertPtrEquals(tc, eq, get_equipment("catapult")); CuAssertStrEquals(tc, "catapult", equipment_name(eq)); eq = get_equipment("catapultammo123"); CuAssertPtrNotNull(tc, eq); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 90649600f..9db764ac3 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -874,17 +874,6 @@ int writepasswd(void) } void free_factions(void) { -#ifdef DMAXHASH - int i; - for (i = 0; i != DMAXHASH; ++i) { - while (deadhash[i]) { - dead *d = deadhash[i]; - deadhash[i] = d->nexthash; - free(d); - } - } -#endif free_flist(&factions); free_flist(&dead_factions); } - diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 904609be5..6be958e47 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -242,7 +242,7 @@ static void test_set_email(CuTest *tc) { sprintf(email, "enno"); faction_setemail(f, email); - email[0] = 0; + CuAssertTrue(tc, email != f->email); CuAssertStrEquals(tc, "enno", f->email); CuAssertStrEquals(tc, "enno", faction_getemail(f)); faction_setemail(f, "bugs@eressea.de"); diff --git a/src/kernel/group.test.c b/src/kernel/group.test.c index d3bf4e2d9..5581fee69 100644 --- a/src/kernel/group.test.c +++ b/src/kernel/group.test.c @@ -53,7 +53,7 @@ static void test_group_readwrite_dead_faction(CuTest *tc) { gamedata_init(&data, &store, RELEASE_VERSION); write_game(&data); free_gamedata(); - f = f2 = NULL; + f = NULL; data.strm.api->rewind(data.strm.handle); read_game(&data); mstream_done(&data.strm); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 367ea4d97..fd0918cc1 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -358,42 +358,6 @@ int gift_items(unit * u, int flags) static unit *deleted_units = NULL; -#define DMAXHASH 7919 -#undef DMAXHASH /* TODO: makes dfindhash slow! */ -#ifdef DMAXHASH -typedef struct dead { - struct dead *nexthash; - faction *f; - int no; -} dead; - -static dead *deadhash[DMAXHASH]; - -static void dhash(int no, faction * f) -{ - dead *hash = (dead *)calloc(1, sizeof(dead)); - dead *old = deadhash[no % DMAXHASH]; - hash->no = no; - hash->f = f; - deadhash[no % DMAXHASH] = hash; - hash->nexthash = old; -} - -faction *dfindhash(int no) -{ - dead *old; - - if (no < 0) - return 0; - - for (old = deadhash[no % DMAXHASH]; old; old = old->nexthash) { - if (old->no == no) { - return old->f; - } - } - return 0; -} -#else struct faction *dfindhash(int no) { unit *u; @@ -404,7 +368,6 @@ struct faction *dfindhash(int no) { } return NULL; } -#endif int remove_unit(unit ** ulist, unit * u) { From 13cc8841d319b36eb1febc2dd300c1d13795786a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 18:10:09 +0100 Subject: [PATCH 10/22] msg_setting is a dead feature, remove leftovers. --- src/kernel/messages.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/kernel/messages.c b/src/kernel/messages.c index d14ad4740..7b9040745 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -46,16 +46,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -typedef struct msg_setting { - struct msg_setting *next; - const struct message_type *type; - int level; -} msg_setting; - -/************ Compatibility function *************/ #define MAXSTRLEN (4*DISPLAYSIZE+3) -#include "region.h" -#include static void arg_set(variant args[], const message_type * mtype, const char *buffer, @@ -267,7 +258,7 @@ void addmessage(region * r, faction * f, const char *s, msg_t mtype, int level) message * msg_error(const unit * u, struct order *ord, int mno) { static char msgname[20]; - if (fval(u->faction, FFL_NPC)) { + if (u->faction->flags & FFL_NPC) { return NULL; } sprintf(msgname, "error%d", mno); From 120b03d2f59cefd4ba3c02979d367770ea27c120 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 18:14:48 +0100 Subject: [PATCH 11/22] Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. --- src/kernel/messages.c | 2 +- src/kernel/messages.test.c | 2 +- src/spells.c | 18 +++++++++--------- src/spy.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 7b9040745..9875d303e 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -83,7 +83,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord, log_warning("trying to create message of unknown type \"%s\"\n", name); if (!mt_find("missing_feedback")) { mt_register(mt_new_va("missing_feedback", "unit:unit", - "region:region", "command:order", "name:string", NULL)); + "region:region", "command:order", "name:string", MT_NEW_END)); } return msg_message("missing_feedback", "name unit region command", name, u, u->region, ord); diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index 4afe25518..ad6a08071 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -12,7 +12,7 @@ void test_missing_message(CuTest *tc) { test_setup(); message_handle_missing(MESSAGE_MISSING_REPLACE); - msg = msg_message("unknown", "unit", NULL); + msg = msg_message("unknown", "unit", (unit *)NULL); CuAssertPtrNotNull(tc, msg); CuAssertPtrNotNull(tc, msg->type); CuAssertStrEquals(tc, msg->type->name, "missing_message"); diff --git a/src/spells.c b/src/spells.c index 8334d19c0..7bab3fd2e 100644 --- a/src/spells.c +++ b/src/spells.c @@ -838,7 +838,7 @@ static int sp_magicstreet(castorder * co) /* melden, 1x pro Partei */ { message *seen = msg_message("path_effect", "mage region", mage, r); - message *unseen = msg_message("path_effect", "mage region", NULL, r); + message *unseen = msg_message("path_effect", "mage region", (unit *)NULL, r); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -895,7 +895,7 @@ static int sp_summonent(castorder * co) /* melden, 1x pro Partei */ { message *seen = msg_message("ent_effect", "mage amount", mage, ents); - message *unseen = msg_message("ent_effect", "mage amount", NULL, ents); + message *unseen = msg_message("ent_effect", "mage amount", (unit *)NULL, ents); report_effect(r, mage, seen, unseen); msg_release(unseen); msg_release(seen); @@ -989,7 +989,7 @@ static int sp_maelstrom(castorder * co) /* melden, 1x pro Partei */ if (c) { message *seen = msg_message("maelstrom_effect", "mage", mage); - message *unseen = msg_message("maelstrom_effect", "mage", NULL); + message *unseen = msg_message("maelstrom_effect", "mage", (unit *)NULL); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -1033,7 +1033,7 @@ static int sp_mallorn(castorder * co) /* melden, 1x pro Partei */ { message *seen = msg_message("mallorn_effect", "mage", mage); - message *unseen = msg_message("mallorn_effect", "mage", NULL); + message *unseen = msg_message("mallorn_effect", "mage", (unit *)NULL); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -1068,7 +1068,7 @@ static int sp_blessedharvest(castorder * co) duration, 1.0, 0)) { const char * effect = co->sp->sname[0]=='b' ? "harvest_effect" : "raindance_effect"; message *seen = msg_message(effect, "mage", mage); - message *unseen = msg_message(effect, "mage", NULL); + message *unseen = msg_message(effect, "mage", (unit *)NULL); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -1114,7 +1114,7 @@ static int sp_hain(castorder * co) { message *seen = msg_message("growtree_effect", "mage amount", mage, trees); message *unseen = - msg_message("growtree_effect", "mage amount", NULL, trees); + msg_message("growtree_effect", "mage amount", (unit *)NULL, trees); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -1160,7 +1160,7 @@ static int sp_mallornhain(castorder * co) { message *seen = msg_message("growtree_effect", "mage amount", mage, trees); message *unseen = - msg_message("growtree_effect", "mage amount", NULL, trees); + msg_message("growtree_effect", "mage amount", (unit *)NULL, trees); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -2675,7 +2675,7 @@ static int sp_firewall(castorder * co) /* melden, 1x pro Partei */ { message *seen = msg_message("firewall_effect", "mage region", mage, r); - message *unseen = msg_message("firewall_effect", "mage region", NULL, r); + message *unseen = msg_message("firewall_effect", "mage region", (unit *)NULL, r); report_effect(r, mage, seen, unseen); msg_release(seen); msg_release(unseen); @@ -4368,7 +4368,7 @@ int sp_puttorest(castorder * co) int dead = deathcount(r); int laid_to_rest = dice((int)(co->force * 2), 100); message *seen = msg_message("puttorest", "mage", mage); - message *unseen = msg_message("puttorest", "mage", NULL); + message *unseen = msg_message("puttorest", "mage", (unit *)NULL); if (laid_to_rest < dead) laid_to_rest = dead; diff --git a/src/spy.c b/src/spy.c index 8d9d4fe8c..94d6c4e7d 100644 --- a/src/spy.c +++ b/src/spy.c @@ -466,7 +466,7 @@ static void sink_ship(region * r, ship * sh, unit * saboteur) move_unit(u, safety, NULL); } else { - msg = msg_message("sink_lost_msg", "dead region unit", dead, NULL, u); + msg = msg_message("sink_lost_msg", "dead region unit", dead, (region *)NULL, u); } add_message(&u->faction->msgs, msg); msg_release(msg); From 4181e23d15bd7ac9577003f235c16178f53b822f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 18:30:20 +0100 Subject: [PATCH 12/22] FAST_CONNECT is always on. fix more cppcheck messages. --- src/kernel/build.c | 5 +-- src/kernel/curse.c | 19 --------- src/kernel/item.c | 18 +++----- src/kernel/order.c | 8 ++-- src/kernel/pathfinder.c | 7 ---- src/kernel/race.c | 5 ++- src/kernel/region.c | 10 +---- src/kernel/region.h | 6 --- src/kernel/ship.c | 13 ------ src/laws.c | 6 --- src/laws.h | 2 - src/magic.c | 8 ---- src/names.c | 91 ----------------------------------------- src/report.c | 23 ----------- src/util/attrib.c | 22 ---------- src/util/attrib.h | 2 - 16 files changed, 17 insertions(+), 228 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 677cf96fc..686964481 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -449,8 +449,7 @@ static int use_materials(unit *u, const construction *type, int n, int completed 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 */ + int multi, canuse = 100; /* normalization */ canuse = matmod(u, rtype, canuse); assert(canuse >= 0); assert(canuse % 100 == 0 @@ -472,12 +471,12 @@ static int count_materials(unit *u, const construction *type, int n, int complet 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); canuse = matmod(u, rtype, canuse); assert(canuse >= 0); if (type->reqsize > 1) { + int need, prebuilt; prebuilt = required(completed, type->reqsize, type->materials[c].number); for (; n;) { diff --git a/src/kernel/curse.c b/src/kernel/curse.c index ae4f481a1..b0d69e0eb 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -291,25 +291,6 @@ void ct_register(const curse_type * ct) selist_set_insert(ctlp, (void *)ct, NULL); } -void ct_remove(const char *c) -{ - unsigned int hash = tolower(c[0]); - selist *ctl = cursetypes[hash]; - - if (ctl) { - int 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) { - selist_delete(&ctl, qi); - break; - } - } - } -} - const curse_type *ct_find(const char *c) { unsigned int hash = tolower(c[0]); diff --git a/src/kernel/item.c b/src/kernel/item.c index 74951895a..5d50e6625 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -346,14 +346,7 @@ const weapon_type *resource2weapon(const resource_type * rtype) const luxury_type *resource2luxury(const resource_type * rtype) { -#ifdef AT_LTYPE - attrib *a = a_find(rtype->attribs, &at_ltype); - if (a) - return (const luxury_type *)a->data.v; - return NULL; -#else return rtype->ltype; -#endif } resource_type *rt_find(const char *name) @@ -670,11 +663,6 @@ void init_resources(void) rtype->itype = it_get_or_create(rtype); rtype->itype->flags |= ITF_ANIMAL | ITF_BIG; - rtype = rt_get_or_create(resourcenames[R_SAPLING]); - rtype = rt_get_or_create(resourcenames[R_TREE]); - rtype = rt_get_or_create(resourcenames[R_MALLORN_SAPLING]); - rtype = rt_get_or_create(resourcenames[R_MALLORN_TREE]); - /* "special" spell components */ rtype = rt_get_or_create(resourcenames[R_AURA]); rtype->uchange = res_changeaura; @@ -685,6 +673,12 @@ void init_resources(void) rtype = rt_get_or_create(resourcenames[R_PEASANT]); rtype->uchange = res_changepeasants; + /* trees are important, too: */ + rt_get_or_create(resourcenames[R_SAPLING]); + rt_get_or_create(resourcenames[R_TREE]); + rt_get_or_create(resourcenames[R_MALLORN_SAPLING]); + rt_get_or_create(resourcenames[R_MALLORN_TREE]); + /* alte typen registrieren: */ init_oldpotions(); } diff --git a/src/kernel/order.c b/src/kernel/order.c index 8defd05c9..7099dab19 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -107,7 +107,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape) { - const char *str, *text; + const char *text; order_data *od = NULL; keyword_t kwd = ORD_KEYWORD(ord); @@ -128,7 +128,7 @@ int stream_order(struct stream *out, const struct order *ord, const struct local text = OD_STRING(od); } if (kwd != NOKEYWORD) { - str = (const char *)LOC(lang, keyword(kwd)); + const char *str = (const char *)LOC(lang, keyword(kwd)); assert(str); swrite(str, 1, strlen(str), out); } @@ -242,10 +242,10 @@ order *create_order(keyword_t kwd, const struct locale * lang, va_start(marker, params); sbs_init(&sbs, zBuffer, sizeof(zBuffer)); while (*params) { - int i; - const char *s; tok = strchr(params, '%'); if (tok) { + const char *s; + int i; if (tok != params) { sbs_strncat(&sbs, params, tok - params); } diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index ba45f926c..3c06fc3d7 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -30,13 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define MAXDEPTH 1024 -bool allowed_swim(const region * src, const region * r) -{ - if (fval(r->terrain, SWIM_INTO)) - return true; - return false; -} - bool allowed_walk(const region * src, const region * r) { if (fval(r->terrain, WALK_INTO)) diff --git a/src/kernel/race.c b/src/kernel/race.c index cb63647b5..edf415223 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -98,7 +98,6 @@ enum { 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) { rc->options = malloc(sizeof(rcoption)); @@ -106,6 +105,7 @@ static void rc_setoption(race *rc, int k, const char *value) { rc->options->key[1] = RCO_NONE; v = rc->options->value; } else { + int i; for (i=0;!v && i < MAXOPTIONS;++i) { if (rc->options->key[i]==key) { v = rc->options->value+i; @@ -196,9 +196,10 @@ static rc_xref *xrefs; race_t old_race(const struct race * rc) { static int cache; - int i, l, r; + int l, r; if (rc_changed(&cache)) { + int i; if (!xrefs) { xrefs = malloc(sizeof(rc_xref) * MAXRACES); } diff --git a/src/kernel/region.c b/src/kernel/region.c index 3f25f156b..28c228176 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -319,8 +319,6 @@ void runhash(region * r) { unsigned int rid = coor_hashkey(r->x, r->y); int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH); - -#ifdef FAST_CONNECT int d, di; for (d = 0, di = MAXDIRECTIONS / 2; d != MAXDIRECTIONS; ++d, ++di) { region *rc = r->connect[d]; @@ -331,7 +329,6 @@ void runhash(region * r) r->connect[d] = NULL; } } -#endif while (regionhash[key] != NULL && regionhash[key] != r) { key = (key + gk) % RMAXHASH; } @@ -343,23 +340,19 @@ region *r_connect(const region * r, direction_t dir) { region *result; int x, y; -#ifdef FAST_CONNECT region *rmodify = (region *)r; assert(dir >= 0 && dir < MAXDIRECTIONS); if (r->connect[dir]) return r->connect[dir]; -#endif assert(dir < MAXDIRECTIONS); x = r->x + delta_x[dir]; y = r->y + delta_y[dir]; pnormalize(&x, &y, rplane(r)); result = rfindhash(x, y); -#ifdef FAST_CONNECT if (result) { rmodify->connect[dir] = result; result->connect[back[dir]] = rmodify; } -#endif return result; } @@ -973,7 +966,7 @@ void free_regions(void) */ static char *makename(void) { - int s, v, k, e, p = 0, x = 0; + int s, k, e, p = 0, x = 0; size_t nk, ne, nv, ns; static char name[16]; const char *kons = "bcdfghklmnprstvwz", @@ -989,6 +982,7 @@ static char *makename(void) ns = strlen(start); for (s = rng_int() % 3 + 2; s > 0; s--) { + int v; if (x > 0) { k = rng_int() % (int)nk; name[p] = kons[k]; diff --git a/src/kernel/region.h b/src/kernel/region.h index ce1f9ea94..bb6e7398c 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -31,10 +31,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define MAXREGIONS 524287 /* must be prime for hashing. 262139 was a little small */ #define MAXTREES 100 * 1000 * 1000 /* bug 2360: some players are crazy */ - /* FAST_CONNECT: regions are directly connected to neighbours, saves doing - a hash-access each time a neighbour is needed, 6 extra pointers per hex */ -#define FAST_CONNECT - #define RF_CHAOTIC (1<<0) /* persistent */ #define RF_MALLORN (1<<1) /* persistent */ #define RF_BLOCKED (1<<2) /* persistent */ @@ -136,9 +132,7 @@ extern "C" { struct attrib *attribs; const struct terrain_type *terrain; struct rawmaterial *resources; -#ifdef FAST_CONNECT struct region *connect[MAXDIRECTIONS]; /* use rconnect(r, dir) to access */ -#endif struct { seen_mode mode; } seen; diff --git a/src/kernel/ship.c b/src/kernel/ship.c index d7e6238b1..8b38f1375 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -172,19 +172,6 @@ struct ship *findship(int i) return sfindhash(i); } -struct ship *findshipr(const region * r, int n) -{ - ship *sh; - - for (sh = r->ships; sh; sh = sh->next) { - if (sh->no == n) { - assert(sh->region == r); - return sh; - } - } - return 0; -} - void damage_ship(ship * sh, double percent) { double damage = diff --git a/src/laws.c b/src/laws.c index d90d2f173..c7ea00cb3 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4211,12 +4211,6 @@ cansee(const faction * f, const region * r, const unit * u, int modifier) return (rings <= 0 && stealth <= 0); } -bool cansee_ex(const faction * f, const region * r, const unit * u, int modifier, seen_mode mode) -{ - UNUSED_ARG(mode); - return cansee(f, r, u, modifier); -} - bool cansee_unit(const unit * u, const unit * target, int modifier) /* target->region kann != u->region sein, wenn es um durchreisen geht */ { diff --git a/src/laws.h b/src/laws.h index fe255485e..56ed9623b 100755 --- a/src/laws.h +++ b/src/laws.h @@ -98,8 +98,6 @@ extern "C" { void nmr_warnings(void); - bool cansee_ex(const struct faction * f, const struct region * r, - const struct unit * u, int modifier, seen_mode mode); bool cansee(const struct faction * f, const struct region * r, const struct unit *u, int modifier); bool cansee_durchgezogen(const struct faction *f, const struct region *r, diff --git a/src/magic.c b/src/magic.c index 6855c307f..f2108b8f2 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2356,14 +2356,6 @@ static void set_clone(unit * mage, unit * clone) assert(!a->data.v || a->data.v == mage); } -unit *has_clone(unit * mage) -{ - attrib *a = a_find(mage->attribs, &at_clone); - if (a) - return (unit *)a->data.v; - return NULL; -} - static void * resolve_clone(int id, void *data) { UNUSED_ARG(id); if (data) { diff --git a/src/names.c b/src/names.c index d8abc077b..eb3aa8a6c 100644 --- a/src/names.c +++ b/src/names.c @@ -369,97 +369,6 @@ static void dracoid_name(unit * u) unit_setname(u, name); } -/** returns an abbreviation of a string. - * TODO: buflen is being ignored */ - -const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) -{ - const char *p = s; - char *bufp; - unsigned int c = 0; - size_t bpt, i; - ucs4_t ucs; - size_t size; - int result; - - UNUSED_ARG(buflen); - /* Pr�fen, ob Kurz genug */ - if (strlen(s) <= maxchars) { - return s; - } - /* 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 */ - 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 */ - if (*p != 0) - ++c; - - /* alnums �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!"); - } - } - - /* 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 */ - - p = s; - c = 0; - bufp = buf; - - result = unicode_utf8_to_ucs4(&ucs, p, &size); - assert(result == 0 || "damnit, we're not handling invalid input here!"); - - while (*p != 0 && c < maxchars) { - /* 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!"); - } - - /* alnums �bertragen */ - - for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) { - memcpy(bufp, p, size); - p += size; - bufp += size; - ++c; - - result = unicode_utf8_to_ucs4(&ucs, p, &size); - assert(result == 0 || "damnit, we're not handling invalid input here!"); - } - - /* Bis zum n�chsten Leerzeichen */ - - while (c < maxchars && *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!"); - } - } - - *bufp = 0; - - return buf; -} - void register_names(void) { /* function name diff --git a/src/report.c b/src/report.c index 6543b153b..e86ac031a 100644 --- a/src/report.c +++ b/src/report.c @@ -2395,29 +2395,6 @@ struct fsee { #define REPORT_ZIP (1 << O_COMPRESS) #define REPORT_BZIP2 (1 << O_BZIP2) -unit *can_find(faction * f, faction * f2) -{ - int key = f->no % FMAXHASH; - struct fsee *fs = fsee[key]; - struct see *ss; - if (f == f2) - return f->units; - while (fs && fs->f != f) - fs = fs->nexthash; - if (!fs) - return NULL; - ss = fs->see; - while (ss && ss->seen != f2) - ss = ss->next; - if (ss) { - /* bei TARNE PARTEI yxz muss die Partei von unit proof nicht - * wirklich Partei f2 sein! */ - /* assert(ss->proof->faction==f2); */ - return ss->proof; - } - return NULL; -} - void register_nr(void) { if (!nocr) diff --git a/src/util/attrib.c b/src/util/attrib.c index 8a90f3bca..a47ec65cc 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -54,11 +54,7 @@ int read_attribs(gamedata *data, attrib **alist, void *owner) { void write_attribs(storage *store, attrib *alist, const void *owner) { -#if RELEASE_VERSION < ATHASH_VERSION - a_write_orig(store, alist, owner); -#else a_write(store, alist, owner); -#endif } int a_readint(attrib * a, void *owner, struct gamedata *data) @@ -518,24 +514,6 @@ void a_write(struct storage *store, const attrib * attribs, const void *owner) { WRITE_INT(store, 0); } -void a_write_orig(struct storage *store, const attrib * attribs, const void *owner) -{ - const attrib *na = attribs; - - while (na) { - if (na->type->write) { - assert(na->type->hashkey || !"attribute not registered"); - WRITE_TOK(store, na->type->name); - na->type->write(na, owner, store); - na = na->next; - } - else { - na = na->nexttype; - } - } - WRITE_TOK(store, "end"); -} - void attrib_done(void) { cb_clear(&cb_deprecated); memset(at_hash, 0, sizeof(at_hash[0]) * MAXATHASH); diff --git a/src/util/attrib.h b/src/util/attrib.h index 6043a960f..f2d54447a 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -81,8 +81,6 @@ extern "C" { int a_age(attrib ** attribs, void *owner); int a_read_orig(struct gamedata *data, attrib ** attribs, void *owner); - void a_write_orig(struct storage *store, const attrib * attribs, const void *owner); - int a_read(struct gamedata *data, attrib ** attribs, void *owner); void a_write(struct storage *store, const attrib * attribs, const void *owner); From 8c554edfee637b7725fd8aae6b4b45de6c1c4064 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 18:35:40 +0100 Subject: [PATCH 13/22] findunitg was deprecated. --- src/kernel/unit.c | 22 ++-------------------- src/kernel/unit.h | 1 - src/monsters.c | 2 +- src/orderfile.c | 2 +- src/renumber.c | 2 +- src/steal.c | 2 +- 6 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index fd0918cc1..a6ab5c2f9 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -75,8 +75,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#define FIND_FOREIGN_TEMP - int weight(const unit * u) { int w = 0, n = 0, in_bag = 0; @@ -124,19 +122,6 @@ unit *findunitr(const region * r, int n) return (u && u->region == r) ? u : 0; } -/* TODO: deprecated, replace with findunit(n) */ -unit *findunitg(int n, const region * hint) -{ - UNUSED_ARG(hint); - /* Abfangen von Syntaxfehlern. */ - if (n <= 0) - return NULL; - - /* findunit global! */ - hint = 0; - return ufindhash(n); -} - #define UMAXHASH MAXUNITS static unit *unithash[UMAXHASH]; static unit *delmarker = (unit *)unithash; /* a funny hack */ @@ -416,9 +401,6 @@ int remove_unit(unit ** ulist, unit * u) u->next = deleted_units; deleted_units = u; -#ifdef DMAXHASH - dhash(u->no, u->faction); -#endif u->region = NULL; @@ -435,11 +417,11 @@ unit *findnewunit(const region * r, const faction * f, int n) for (u2 = r->units; u2; u2 = u2->next) if (u2->faction == f && ualias(u2) == n) return u2; -#ifdef FIND_FOREIGN_TEMP + for (u2 = r->units; u2; u2 = u2->next) if (ualias(u2) == n) return u2; -#endif + return 0; } diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 91a3ec930..b70082a4b 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -248,7 +248,6 @@ extern "C" { void remove_empty_units_in_region(struct region * r); void remove_empty_units(void); - struct unit *findunitg(int n, const struct region *hint); struct unit *findunit(int n); struct unit *findunitr(const struct region *r, int n); diff --git a/src/monsters.c b/src/monsters.c index d1979414d..d2a7cc68f 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -772,7 +772,7 @@ void plan_monsters(faction * f) } } else if (tu) { - tu = findunitg(ta->data.i, NULL); + tu = findunit(ta->data.i); if (tu != NULL) { long_order = make_movement_order(u, tu->region, 2, allowed_walk); } diff --git a/src/orderfile.c b/src/orderfile.c index a82b599a0..ac80db0a2 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -27,7 +27,7 @@ static unit *unitorders(input *in, faction *f) return NULL; i = getid(); - u = findunitg(i, NULL); + u = findunit(i); if (u && u->faction == f) { order **ordp; diff --git a/src/renumber.c b/src/renumber.c index 1319eaa5f..45ee0cccc 100644 --- a/src/renumber.c +++ b/src/renumber.c @@ -113,7 +113,7 @@ int renumber_cmd(unit * u, order * ord) break; } - if (findunitg(i, u->region)) { + if (findunit(i)) { cmistake(u, ord, 115, MSG_EVENT); break; } diff --git a/src/steal.c b/src/steal.c index 9403b4fd8..68a4239ec 100644 --- a/src/steal.c +++ b/src/steal.c @@ -71,7 +71,7 @@ void expandstealing(region * r, econ_request * stealorders) break; } - u = findunitg(requests[j]->type.steal.no, r); + u = findunit(requests[j]->type.steal.no); if (u && u->region == r) { n = get_pooled(u, rsilver, GET_ALL, INT_MAX); From aacd0885df3f70805846f9149d28c1cdaf742d6a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 19:17:20 +0100 Subject: [PATCH 14/22] fix termination bug in itoa functions. --- src/gmtool.c | 2 +- src/kernel/unit.h | 1 - src/util/base36.c | 12 +++++++++--- src/util/base36.h | 1 + src/util/base36.test.c | 23 +++++++++++++++-------- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/gmtool.c b/src/gmtool.c index 6051ed9cc..65ca7fe07 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -1247,7 +1247,7 @@ static void handlekey(state * st, int c) else if (findmode == 'F') { faction *f = select_faction(st); if (f != NULL) { - itoab_r(f->no, 36, locate, sizeof(locate)); + itoa36_r(f->no, locate, sizeof(locate)); findmode = 'f'; } else { diff --git a/src/kernel/unit.h b/src/kernel/unit.h index b70082a4b..c242e0bd2 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -249,7 +249,6 @@ extern "C" { void remove_empty_units(void); struct unit *findunit(int n); - struct unit *findunitr(const struct region *r, int n); void default_name(const unit *u, char name[], int len); diff --git a/src/util/base36.c b/src/util/base36.c index 3ded21a54..30020de30 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -58,7 +58,7 @@ const char *itoab_r(int i, int base, char *s, size_t len) assert(len > 2); dst = s + len - 2; - *dst = 0; + dst[1] = 0; if (i != 0) { int neg = 0; @@ -92,12 +92,18 @@ const char *itoab_r(int i, int base, char *s, size_t len) assert(i == 0 || !"itoab: static buffer exhausted"); } } - else - *dst = '0'; + else { + dst[0] = '0'; + } return dst; } +const char *itoa36_r(int i, char *result, size_t len) +{ + return itoab_r(i, 36, result, len); +} + const char *itoab(int i, int base) { static char sstr[80]; diff --git a/src/util/base36.h b/src/util/base36.h index 804952ab7..05c81d2c0 100644 --- a/src/util/base36.h +++ b/src/util/base36.h @@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + const char *itoa36_r(int i, char *result, size_t len); const char *itoab_r(int i, int base, char *result, size_t len); const char *itoab(int i, int base); const char *itoa36(int i); diff --git a/src/util/base36.test.c b/src/util/base36.test.c index 226fd86ab..90d5b42f7 100644 --- a/src/util/base36.test.c +++ b/src/util/base36.test.c @@ -5,6 +5,7 @@ #include #include "base36.h" #include +#include #include static void test_atoi36(CuTest * tc) @@ -19,14 +20,20 @@ static void test_atoi36(CuTest * tc) static void test_itoa36(CuTest * tc) { - CuAssertStrEquals(tc, itoa36(0), "0"); - CuAssertStrEquals(tc, itoa10(INT_MAX), "2147483647"); - CuAssertStrEquals(tc, itoab(INT_MAX, 8), "17777777777"); - CuAssertStrEquals(tc, itoab(INT_MAX, 4), "1333333333333333"); - CuAssertStrEquals(tc, itoab(-1, 5), "-1"); - CuAssertStrEquals(tc, itoa36(-1), "-1"); - CuAssertStrEquals(tc, itoa36(-10), "-a"); - CuAssertStrEquals(tc, itoa36(666), "ii"); + char buf[10]; + CuAssertStrEquals(tc, itoa36(0), "0"); + CuAssertStrEquals(tc, itoa10(INT_MAX), "2147483647"); + CuAssertStrEquals(tc, itoab(INT_MAX, 8), "17777777777"); + CuAssertStrEquals(tc, itoab(INT_MAX, 4), "1333333333333333"); + CuAssertStrEquals(tc, itoab(-1, 5), "-1"); + CuAssertStrEquals(tc, itoa36(-1), "-1"); + CuAssertStrEquals(tc, itoa36(-10), "-a"); + CuAssertStrEquals(tc, itoa36(666), "ii"); + + memset(buf, 255, sizeof(buf)); + CuAssertStrEquals(tc, itoa36_r(-10, buf, sizeof(buf)), "-a"); + memset(buf, 255, sizeof(buf)); + CuAssertStrEquals(tc, itoab_r(666, 36, buf, sizeof(buf)), "ii"); } CuSuite *get_base36_suite(void) From b7dcee7e08d0bc020e0556931b34ff87fbbd0893 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 19:36:28 +0100 Subject: [PATCH 15/22] fix goto-select-faction (itoa bug). --- src/gmtool.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gmtool.c b/src/gmtool.c index 65ca7fe07..9b57da81d 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -946,6 +946,7 @@ static void handlekey(state * st, int c) static int findmode = 0; region *r; char sbuffer[80]; + const char *loc = locate; int n, nx, ny, minpop, maxpop; switch (c) { @@ -1247,7 +1248,7 @@ static void handlekey(state * st, int c) else if (findmode == 'F') { faction *f = select_faction(st); if (f != NULL) { - itoa36_r(f->no, locate, sizeof(locate)); + loc = itoa36_r(f->no, locate, sizeof(locate)); findmode = 'f'; } else { @@ -1260,8 +1261,9 @@ static void handlekey(state * st, int c) break; } /* achtung: fall-through ist absicht: */ - if (!strlen(locate)) + if (!strlen(loc)) { break; + } case 'n': if (findmode == 'u') { unit *u = findunit(atoi36(locate)); @@ -1273,9 +1275,9 @@ 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); + snprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", loc); statusline(st->wnd_status->handle, sbuffer); - f = findfaction(atoi36(locate)); + f = findfaction(atoi36(loc)); if (f == NULL) { statusline(st->wnd_status->handle, "faction not found."); beep(); From 079a55fe41bc9d63c7c53b7a5d607dbce4dcb461 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 20:06:47 +0100 Subject: [PATCH 16/22] cppcheck warnings --- src/kernel/build.c | 20 ++++++++++---------- src/kernel/building.test.c | 2 +- src/orderfile.c | 7 ++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 686964481..b2774fbd7 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -476,14 +476,14 @@ static int count_materials(unit *u, const construction *type, int n, int complet assert(canuse >= 0); if (type->reqsize > 1) { - int need, prebuilt; - prebuilt = - required(completed, type->reqsize, type->materials[c].number); - for (; n;) { - need = + int prebuilt = required(completed, type->reqsize, + type->materials[c].number); + while (n > 0) { + int need = required(completed + n, type->reqsize, type->materials[c].number); - if (need - prebuilt <= canuse) + if (need - prebuilt <= canuse) { break; + } --n; /* TODO: optimieren? */ } } @@ -704,7 +704,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * * gefunden wurde, dann wird nicht einfach eine neue erbaut. Ansonsten * baut man an der eigenen burg weiter. */ - /* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */ + /* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */ if (id > 0) { /* eine Nummer angegeben, keine neue Burg bauen */ b = findbuilding(id); if (!b || b->region != u->region) { /* eine Burg mit dieser Nummer gibt es hier nicht */ @@ -893,12 +893,12 @@ static void build_ship(unit * u, ship * sh, int want) if (n) ADDMSG(&u->faction->msgs, - msg_message("buildship", "ship unit size", sh, u, n)); + msg_message("buildship", "ship unit size", sh, u, n)); } void create_ship(unit * u, const struct ship_type *newtype, int want, -order * ord) + order * ord) { ship *sh; int msize; @@ -940,7 +940,7 @@ order * ord) } new_order = create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale, - parameters[P_SHIP]), sh->no); + parameters[P_SHIP]), sh->no); replace_order(&u->orders, ord, new_order); free_order(new_order); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 8d5b86dc9..de34d59b5 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -247,7 +247,7 @@ static void test_buildingowner_resets_when_empty(CuTest * tc) u_set_building(u, bld); CuAssertPtrEquals(tc, u, building_owner(bld)); u->number = 0; - CuAssertPtrEquals(tc, 0, building_owner(bld)); + CuAssertPtrEquals(tc, NULL, building_owner(bld)); u->number = 1; CuAssertPtrEquals(tc, u, building_owner(bld)); test_teardown(); diff --git a/src/orderfile.c b/src/orderfile.c index ac80db0a2..1eca97686 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -121,10 +121,8 @@ static unit *unitorders(input *in, faction *f) static faction *factionorders(void) { - faction *f = NULL; int fid = getid(); - - f = findfaction(fid); + faction *f = findfaction(fid); if (f != NULL && !fval(f, FFL_NPC)) { char token[128]; @@ -231,9 +229,8 @@ int readorders(const char *filename) { input in; int result; + FILE *F = fopen(filename, "r"); - FILE *F = NULL; - F = fopen(filename, "r"); if (!F) { perror(filename); return -1; From 72daecd27ef7d2ded90c38b1a3242729b2c00abf Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:01:32 +0100 Subject: [PATCH 17/22] cppcheck false positives --- src/battle.test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/battle.test.c b/src/battle.test.c index 4b59e1abf..7d968c091 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -116,10 +116,12 @@ static void test_defenders_get_building_bonus(CuTest * tc) at.index = 0; bld->size = 10; /* stage 1 building */ + CuAssertIntEquals(tc, 1, buildingeffsize(bld, false)); CuAssertIntEquals(tc, -1, skilldiff(at, dt, 0)); CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0)); bld->size = 1; /* stage 0 building */ + CuAssertIntEquals(tc, 0, buildingeffsize(bld, false)); CuAssertIntEquals(tc, 0, skilldiff(at, dt, 0)); CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0)); From 5d9d299e688d620031701b9dd9c9bb8c56487591 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 17:21:09 +0100 Subject: [PATCH 18/22] refactor repotring items --- s/cppcheck | 3 ++- src/creport.c | 53 ++++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/s/cppcheck b/s/cppcheck index 441faaa65..b87143d04 100755 --- a/s/cppcheck +++ b/s/cppcheck @@ -1,3 +1,4 @@ #!/bin/sh -cppcheck -U_MSC_VER --enable=all -IcJSON -Isrc -Iclibs -Istorage src +cppcheck --enable=all -U_MSC_VER -UCLEANUP_CODE \ + -IcJSON -Isrc -Iclibs -Istorage src diff --git a/src/creport.c b/src/creport.c index fa17c426d..a81bbba93 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1509,6 +1509,31 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) } } +static void report_itemtype(FILE *F, faction *f, const item_type *itype) { + const char *ch; + const char *description = NULL; + const char *pname = resourcename(itype->rtype, 0); + const char *potiontext = mkname("potion", pname); + + ch = resourcename(itype->rtype, 0); + fprintf(F, "TRANK %d\n", str_hash(ch)); + fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch))); + fprintf(F, "%d;Stufe\n", potion_level(itype)); + description = LOC(f->locale, potiontext); + fprintf(F, "\"%s\";Beschr\n", description); + if (itype->construction) { + requirement *m = itype->construction->materials; + + fprintf(F, "ZUTATEN\n"); + + while (m->number) { + ch = resourcename(m->rtype, 0); + fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch))); + m++; + } + } +} + /* main function of the creport. creates the header and traverses all regions */ static int report_computer(const char *filename, report_context * ctx, const char *bom) @@ -1653,33 +1678,9 @@ report_computer(const char *filename, report_context * ctx, const char *bom) for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; a = a->next) { const item_type *itype = (const item_type *)a->data.v; - const char *ch; - const char *description = NULL; - if (itype == NULL) - continue; - ch = resourcename(itype->rtype, 0); - fprintf(F, "TRANK %d\n", str_hash(ch)); - fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch))); - fprintf(F, "%d;Stufe\n", potion_level(itype)); - - if (description == NULL) { - const char *pname = resourcename(itype->rtype, 0); - const char *potiontext = mkname("potion", pname); - description = LOC(f->locale, potiontext); - } - - fprintf(F, "\"%s\";Beschr\n", description); - if (itype->construction) { - requirement *m = itype->construction->materials; - - fprintf(F, "ZUTATEN\n"); - - while (m->number) { - ch = resourcename(m->rtype, 0); - fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch))); - m++; - } + if (itype) { + report_itemtype(F, f, itype); } } From a0fcdc83fe778f5f40146b79fb2c1d0e857f704f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 18:30:44 +0100 Subject: [PATCH 19/22] ignore TODO code --- s/cppcheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/cppcheck b/s/cppcheck index b87143d04..7ab41f66f 100755 --- a/s/cppcheck +++ b/s/cppcheck @@ -1,4 +1,4 @@ #!/bin/sh -cppcheck --enable=all -U_MSC_VER -UCLEANUP_CODE \ +cppcheck --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ -IcJSON -Isrc -Iclibs -Istorage src From 15e2d827067ebecdf446bfcb71169e5824c2dc06 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 19:37:23 +0100 Subject: [PATCH 20/22] ignore some more defines --- s/cppcheck | 1 + 1 file changed, 1 insertion(+) diff --git a/s/cppcheck b/s/cppcheck index 7ab41f66f..cbaf949c3 100755 --- a/s/cppcheck +++ b/s/cppcheck @@ -1,4 +1,5 @@ #!/bin/sh cppcheck --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ + -UERESSEA_BUILDNO -UERESSEA_VERSION \ -IcJSON -Isrc -Iclibs -Istorage src From aae7e9b95409f15395daba6402a4527b6eae8b79 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 19:45:20 +0100 Subject: [PATCH 21/22] immer noch FAST_CONNECT Reste --- src/kernel/region.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/kernel/region.h b/src/kernel/region.h index bb6e7398c..d37da2290 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -241,11 +241,7 @@ extern "C" { struct alliance *region_get_alliance(const struct region *r); struct region *r_connect(const struct region *, direction_t dir); -#ifdef FAST_CONNECT -# define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, (direction_t)dir)) -#else -# define rconnect(r, dir) r_connect(r, (direction_t)dir) -#endif +#define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, (direction_t)dir)) void free_regions(void); void free_land(struct land_region * lr); From 43268b913b227aa9abf8d34c357d7966b1939e53 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 20:04:55 +0100 Subject: [PATCH 22/22] cppcheck ignores tests --- s/cppcheck | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/s/cppcheck b/s/cppcheck index cbaf949c3..9c51309f8 100755 --- a/s/cppcheck +++ b/s/cppcheck @@ -1,5 +1,8 @@ #!/bin/sh -cppcheck --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ +IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }') + +cppcheck $IGNORE \ + --quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ -UERESSEA_BUILDNO -UERESSEA_VERSION \ -IcJSON -Isrc -Iclibs -Istorage src