From e841177e6f08cad9dd2adea4ae606a1c5506cdb6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 18 Feb 2018 10:37:13 +0100 Subject: [PATCH 01/10] fix types for CMakeCache --- s/build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s/build b/s/build index 636777541..709c92510 100755 --- a/s/build +++ b/s/build @@ -37,10 +37,10 @@ BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') if [ "$BRANCH" = "master" ] ; then VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') echo "$BRANCH $VERSION" -CMAKE_ARGS="-DERESSEA_VERSION=$VERSION ${CMAKE_ARGS}" +CMAKE_ARGS="-DERESSEA_VERSION:STRING=$VERSION ${CMAKE_ARGS}" else REV=$(git rev-parse --short HEAD) -CMAKE_ARGS="-DERESSEA_BUILDNO=$REV $CMAKE_ARGS" +CMAKE_ARGS="-DERESSEA_BUILDNO:STRING=$REV $CMAKE_ARGS" fi cmake ${CMAKE_ARGS} From de52d8d669ebe9a0a7fad14aa252f5c772b7167c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 18 Feb 2018 11:46:05 +0100 Subject: [PATCH 02/10] BUG 2419: add a spell alias. --- src/attributes/seenspell.c | 2 +- src/kernel/spell.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/attributes/seenspell.c b/src/attributes/seenspell.c index 170cc33b4..6c78d19f4 100644 --- a/src/attributes/seenspell.c +++ b/src/attributes/seenspell.c @@ -94,7 +94,7 @@ static int read_seenspell(variant *var, void *owner, struct gamedata *data) } sp = find_spell(token); if (!sp) { - log_info("read_seenspell: could not find spell '%s'\n", token); + log_error("read_seenspell: could not find spell '%s'\n", token); return AT_READ_FAIL; } var->v = sp; diff --git a/src/kernel/spell.c b/src/kernel/spell.c index ca97bf1f0..785f270b3 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -135,6 +135,7 @@ spell * create_spell(const char * name) } static const char *sp_aliases[][2] = { + { "create_potion_p14", "create_potion_healing" }, { "gwyrrdfamiliar", "summon_familiar" }, { "illaunfamiliar", "summon_familiar" }, { "draigfamiliar", "summon_familiar" }, @@ -150,16 +151,20 @@ static const char *sp_alias(const char *zname) if (strcmp(sp_aliases[i][0], zname) == 0) return sp_aliases[i][1]; } - return zname; + return NULL; } spell *find_spell(const char *name) { const char * match; spell * sp = 0; - const char * alias = sp_alias(name); - - match = cb_find_str(&cb_spells, alias); + match = cb_find_str(&cb_spells, name); + if (!match) { + const char * alias = sp_alias(name); + if (alias) { + match = cb_find_str(&cb_spells, alias); + } + } if (match) { cb_get_kv(match, &sp, sizeof(sp)); } From fa1e81f6ac62d9bed24602f60058c2f9555f36cc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 23 Feb 2018 21:24:15 +0100 Subject: [PATCH 03/10] write a log of dead factions. --- src/eressea.c | 19 ++++++++----------- src/kernel/config.c | 2 +- src/kernel/faction.c | 22 +++++++++++++++++++++- src/kernel/faction.h | 1 + src/main.c | 1 + 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/eressea.c b/src/eressea.c index 03f194238..81f19b5a6 100644 --- a/src/eressea.c +++ b/src/eressea.c @@ -4,6 +4,7 @@ #include "kernel/calendar.h" #include "kernel/config.h" #include "kernel/curse.h" +#include "kernel/faction.h" #include "kernel/building.h" #include "kernel/equipment.h" #include "kernel/item.h" @@ -37,22 +38,17 @@ #include #include +/* manually free() everything at exit? */ +#undef CLEANUP_CODE + void game_done(void) { -#undef CLEANUP_CODE + log_dead_factions(); + #ifdef CLEANUP_CODE - /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur - * zum Debugging interessant, wenn man Leak Detection hat, und nach - * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benoetigt - * wird (temporaere Hilsstrukturen) */ - - free_game(); - + free_gamedata(); creport_cleanup(); -#ifdef REPORT_FORMAT_NR report_cleanup(); -#endif -#endif calendar_cleanup(); free_functions(); free_config(); @@ -60,6 +56,7 @@ void game_done(void) free_locales(); kernel_done(); dblib_close(); +#endif } void game_init(void) diff --git a/src/kernel/config.c b/src/kernel/config.c index 05690e301..8c7e64afe 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -778,8 +778,8 @@ void free_gamedata(void) free(forbidden_ids); forbidden_ids = NULL; - free_donations(); free_factions(); + free_donations(); free_units(); free_regions(); free_borders(); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 36f467c6e..165551f8f 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -738,7 +738,6 @@ void remove_empty_factions(void) faction *f = *fp; if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) { - log_debug("dead: %s", factionname(f)); destroyfaction(fp); } else { @@ -876,6 +875,27 @@ int writepasswd(void) return 1; } +void log_dead_factions(void) +{ + if (dead_factions) { + const char *logname = config_get("game.deadlog"); + if (logname) { + FILE *F; + char path[PATH_MAX]; + + join_path(basepath(), logname, path, sizeof(path)); + F = fopen(path, "at"); + if (F) { + faction *f; + for (f = dead_factions; f; f = f->next) { + fprintf(F, "%d\t%d\t%d\t%s\t%s\t%s\n", turn, f->lastorders, f->age, itoa36(f->no), f->email, f->name); + } + fclose(F); + } + } + } +} + void free_factions(void) { #ifdef DMAXHASH int i; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 25913e73d..8d13f64d1 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -133,6 +133,7 @@ extern "C" { void renumber_faction(faction * f, int no); void free_factions(void); + void log_dead_factions(void); void remove_empty_factions(void); void update_interval(struct faction *f, struct region *r); diff --git a/src/main.c b/src/main.c index ae6d2158c..489d0d868 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,7 @@ static void load_inifile(void) static const char * valid_keys[] = { "game.id", + "game.deadlog", "game.name", "game.start", "game.locale", From 1f7a25b4c57a5fb4332c393c49e83d4b722546fd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Feb 2018 16:48:39 +0100 Subject: [PATCH 04/10] disable an intermittent check. --- scripts/tests/e2/items.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index ce7b76b40..2a84fcd54 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -162,7 +162,8 @@ function test_use_foolpotion() turn_process() assert_equal(0, u:get_item('p7')) assert_equal(0, u2:effect('p7')) - assert_equal(0, u2:get_skill('crossbow')) +-- disabled, intermittent: +-- assert_equal(0, u2:get_skill('crossbow')) assert_equal(1, f:count_msg_type('givedumb')) turn_end() end From 02c6c863a36251316150afe6187de2243089e746 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 18 Feb 2018 10:31:57 +0100 Subject: [PATCH 05/10] BUG 2416: Prefer sqlite over db backend --- s/cmake-init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s/cmake-init b/s/cmake-init index 5da7e985f..75e3fd7ac 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -1,8 +1,8 @@ #!/bin/sh -ERESSEA_DB=sqlite -if [ -e /usr/include/db.h ] ; then ERESSEA_DB=db +if [ -e /usr/include/sqlite3.h ] ; then +ERESSEA_DB=sqlite fi # Parse command line arguments From 6c2f42ab610de912949050c14fd6b1fbbaf4f3d8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Feb 2018 17:59:03 +0100 Subject: [PATCH 06/10] upgrade clibs library --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index 147584ad7..7eb6713ff 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 147584ad70b220abf6a4e97ca76e785729b9ac32 +Subproject commit 7eb6713ff73d29e67d2bc87fb037a9c738c2c512 From c432bcf22e681b93f77f00c76152259744dfd355 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 18 Feb 2018 10:37:13 +0100 Subject: [PATCH 07/10] fix types for CMakeCache --- s/build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s/build b/s/build index 636777541..709c92510 100755 --- a/s/build +++ b/s/build @@ -37,10 +37,10 @@ BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') if [ "$BRANCH" = "master" ] ; then VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') echo "$BRANCH $VERSION" -CMAKE_ARGS="-DERESSEA_VERSION=$VERSION ${CMAKE_ARGS}" +CMAKE_ARGS="-DERESSEA_VERSION:STRING=$VERSION ${CMAKE_ARGS}" else REV=$(git rev-parse --short HEAD) -CMAKE_ARGS="-DERESSEA_BUILDNO=$REV $CMAKE_ARGS" +CMAKE_ARGS="-DERESSEA_BUILDNO:STRING=$REV $CMAKE_ARGS" fi cmake ${CMAKE_ARGS} From 8a00cc3b965bf8c5e3b9dba524d1e27d3b4fd89a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Feb 2018 18:58:50 +0100 Subject: [PATCH 08/10] foolpotion test is not intermittent if we disable study.random_progress --- scripts/tests/e2/items.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 2a84fcd54..e444a9c73 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -9,6 +9,7 @@ function setup() eressea.settings.set("rules.ship.storms", "0") eressea.settings.set("rules.encounters", "0") eressea.settings.set("magic.regeneration.enable", "0") + eressea.settings.set("study.random_progress", "0") end function test_water_of_life() @@ -162,8 +163,7 @@ function test_use_foolpotion() turn_process() assert_equal(0, u:get_item('p7')) assert_equal(0, u2:effect('p7')) --- disabled, intermittent: --- assert_equal(0, u2:get_skill('crossbow')) + assert_equal(0, u2:get_skill('crossbow')) assert_equal(1, f:count_msg_type('givedumb')) turn_end() end From 42c86d122e8764cd138e86436e57ab5e959b73e4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Feb 2018 19:41:36 +0100 Subject: [PATCH 09/10] stop using MINMAX macros. --- src/bindings.c | 3 +- src/economy.h | 3 + src/kernel/pool.c | 18 ++-- src/monsters.c | 31 +++++-- src/randenc.c | 70 ++++++++------- src/reports.c | 222 +++++++++++++++++++++++----------------------- src/reports.h | 3 +- 7 files changed, 189 insertions(+), 161 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index 35657b5be..2364775fb 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -458,8 +458,7 @@ static int tolua_write_report(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); if (f) { - time_t ltime = time(0); - int result = write_reports(f, ltime); + int result = write_reports(f); lua_pushinteger(L, result); } else { diff --git a/src/economy.h b/src/economy.h index 6d58a1f9f..8d022ebbc 100644 --- a/src/economy.h +++ b/src/economy.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_GC_ECONOMY #define H_GC_ECONOMY + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/pool.c b/src/kernel/pool.c index e58bc131e..52e445c94 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -16,11 +16,14 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include -#include +#endif + #include "pool.h" #include "ally.h" +#include "config.h" #include "faction.h" #include "item.h" #include "order.h" @@ -168,7 +171,8 @@ int count) use = have; else if (rtype->itype && mode & (GET_SLACK | GET_RESERVE)) { int reserve = get_reservation(u, rtype->itype); - int slack = MAX(0, have - reserve); + int slack = have - reserve; + if (slack < 0) slack = 0; if (mode & GET_RESERVE) use = have - slack; else if (mode & GET_SLACK) @@ -206,18 +210,20 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) } if ((mode & GET_SLACK) && (mode & GET_RESERVE)) { - n = MIN(use, have); + n = (use < have) ? use : have; } else if (rtype->itype) { int reserve = get_reservation(u, rtype->itype); - int slack = MAX(0, have - reserve); + int slack = have - reserve; + if (slack < 0) slack = 0; if (mode & GET_RESERVE) { n = have - slack; - n = MIN(use, n); + if (n > use) n = use; change_reservation(u, rtype->itype, -n); } else if (mode & GET_SLACK) { - n = MIN(use, slack); + n = slack; + if (n > use) n = use; } } if (n > 0) { diff --git a/src/monsters.c b/src/monsters.c index 99f32cedb..59664480a 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -17,7 +17,9 @@ * permission from the authors. */ +#ifdef _MSC_VER #include +#endif #include "monsters.h" @@ -132,7 +134,10 @@ static void reduce_weight(unit * u) if (itype->weight >= 10 && itype->rtype->wtype == 0 && itype->rtype->atype == 0) { if (itype->capacity < itype->weight) { - int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); + int reduce = (weight - capacity) / itype->weight; + if (reduce > itm->number) { + reduce = itm->number; + } give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } @@ -147,7 +152,10 @@ static void reduce_weight(unit * u) const item_type *itype = itm->type; weight += itm->number * itype->weight; if (itype->capacity < itype->weight) { - int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); + int reduce = (weight - capacity) / itype->weight; + if (reduce > itm->number) { + reduce = itm->number; + } give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } @@ -1027,10 +1035,12 @@ static void eaten_by_monster(unit * u) n = (int)(n * multi); if (n > 0) { + n = lovar(n); - n = MIN(rpeasants(u->region), n); if (n > 0) { + int p = rpeasants(u->region); + if (p < n) n = p; deathcounts(u->region, n); rsetpeasants(u->region, rpeasants(u->region) - n); ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); @@ -1048,8 +1058,9 @@ static void absorbed_by_monster(unit * u) if (n > 0) { n = lovar(n); - n = MIN(rpeasants(u->region), n); if (n > 0) { + int p = rpeasants(u->region); + if (p < n) n = p; rsetpeasants(u->region, rpeasants(u->region) - n); scale_number(u, u->number + n); ADDMSG(&u->region->msgs, msg_message("absorbpeasants", @@ -1063,7 +1074,10 @@ static int scareaway(region * r, int anzahl) int n, p, diff = 0, emigrants[MAXDIRECTIONS]; direction_t d; - anzahl = MIN(MAX(1, anzahl), rpeasants(r)); + p = rpeasants(r); + if (anzahl < 1) anzahl = 1; + if (anzahl > p) anzahl = p; + assert(p >= 0 && anzahl >= 0); /* Wandern am Ende der Woche (normal) oder wegen Monster. Die * Wanderung wird erst am Ende von demographics () ausgefuehrt. @@ -1073,9 +1087,7 @@ static int scareaway(region * r, int anzahl) for (d = 0; d != MAXDIRECTIONS; d++) emigrants[d] = 0; - p = rpeasants(r); - assert(p >= 0 && anzahl >= 0); - for (n = MIN(p, anzahl); n; n--) { + for (n = anzahl; n; n--) { direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); region *rc = rconnect(r, dir); @@ -1104,8 +1116,9 @@ static void scared_by_monster(unit * u) } if (n > 0) { n = lovar(n); - n = MIN(rpeasants(u->region), n); if (n > 0) { + int p = rpeasants(u->region); + if (p < n) n = p; n = scareaway(u->region, n); if (n > 0) { ADDMSG(&u->region->msgs, msg_message("fleescared", diff --git a/src/randenc.c b/src/randenc.c index 499591294..7a65ce378 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -16,49 +16,52 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include -#include +#endif + #include "randenc.h" -#include "volcano.h" +#include "chaos.h" #include "economy.h" #include "monsters.h" #include "move.h" -#include "chaos.h" #include "study.h" +#include "volcano.h" -#include -#include +#include "spells/unitcurse.h" +#include "spells/regioncurse.h" /* attributes includes */ -#include -#include +#include "attributes/racename.h" +#include "attributes/reduceproduction.h" /* kernel includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "kernel/building.h" +#include "kernel/config.h" +#include "kernel/curse.h" +#include "kernel/equipment.h" +#include "kernel/faction.h" +#include "kernel/item.h" +#include "kernel/messages.h" +#include "kernel/order.h" +#include "kernel/plane.h" +#include "kernel/pool.h" +#include "kernel/race.h" +#include "kernel/region.h" +#include "kernel/ship.h" +#include "kernel/terrain.h" +#include "kernel/terrainid.h" +#include "kernel/unit.h" /* util includes */ -#include -#include -#include -#include -#include -#include -#include +#include "util/attrib.h" +#include "util/language.h" +#include "util/lists.h" +#include "util/log.h" +#include "util/rand.h" +#include "util/message.h" +#include "util/rng.h" /* libc includes */ #include @@ -785,9 +788,8 @@ static void rotting_herbs(void) int n = itm->number; double k = n * rot_chance / 100.0; if (fval(itm->type, ITF_HERB)) { - double nv = normalvariate(k, k / 4); - int inv = (int)nv; - int delta = MIN(n, inv); + int delta = (int)normalvariate(k, k / 4); + if (n < delta) delta = n; if (!i_change(itmp, itm->type, -delta)) { continue; } @@ -823,7 +825,9 @@ void randomevents(void) while (*blist) { building *b = *blist; if (fval(b->type, BTF_DECAY) && !building_owner(b)) { - b->size -= MAX(1, (b->size * 20) / 100); + int delta = (b->size * 20) / 100; + if (delta < 1) delta = 1; + b->size -= delta; if (b->size == 0) { remove_building(blist, r->buildings); } diff --git a/src/reports.c b/src/reports.c index 69e7a3555..862dd165a 100644 --- a/src/reports.c +++ b/src/reports.c @@ -16,12 +16,12 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include -#include +#endif #include "reports.h" #include "battle.h" -#include "kernel/calendar.h" #include "guard.h" #include "laws.h" #include "spells.h" @@ -30,48 +30,50 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "donations.h" /* attributes includes */ -#include -#include -#include -#include -#include +#include "attributes/attributes.h" +#include "attributes/follow.h" +#include "attributes/otherfaction.h" +#include "attributes/racename.h" +#include "attributes/stealth.h" -#include +#include "spells/unitcurse.h" /* kernel includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "kernel/config.h" +#include "kernel/calendar.h" +#include "kernel/ally.h" +#include "kernel/alliance.h" +#include "kernel/connection.h" +#include "kernel/building.h" +#include "kernel/curse.h" +#include "kernel/faction.h" +#include "kernel/group.h" +#include "kernel/item.h" +#include "kernel/messages.h" +#include "kernel/order.h" +#include "kernel/plane.h" +#include "kernel/race.h" +#include "kernel/region.h" +#include "kernel/resources.h" +#include "kernel/ship.h" +#include "kernel/spell.h" +#include "kernel/spellbook.h" +#include "kernel/terrain.h" +#include "kernel/unit.h" /* util includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "util/attrib.h" +#include "util/base36.h" +#include "util/bsdstring.h" +#include "util/functions.h" +#include "util/goodies.h" +#include "util/language.h" +#include "util/lists.h" +#include "util/log.h" +#include "util/macros.h" +#include "util/path.h" +#include "util/strings.h" +#include "util/translation.h" #include #include @@ -610,6 +612,70 @@ report_resources(const region * r, resource_report * result, int size, return n; } +static size_t spskill(char *buffer, size_t size, const struct locale * lang, + const struct unit * u, struct skill * sv, int *dh) +{ + char *bufp = buffer; + int effsk; + + if (!u->number) + return 0; + if (sv->level <= 0) { + if (sv->old <= 0 || (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) == 0) { + return 0; + } + } + + bufp = STRLCPY(bufp, ", ", size); + + if (!*dh) { + bufp = STRLCPY(bufp, LOC(lang, "nr_skills"), size); + bufp = STRLCPY(bufp, ": ", size); + *dh = 1; + } + bufp = STRLCPY(bufp, skillname(sv->id, lang), size); + bufp = STRLCPY(bufp, " ", size); + + if (sv->id == SK_MAGIC) { + sc_mage *mage = get_mage(u); + if (mage && mage->magietyp != M_GRAY) { + bufp = STRLCPY(bufp, LOC(lang, mkname("school", + magic_school[mage->magietyp])), size); + bufp = STRLCPY(bufp, " ", size); + } + } + + if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) { + int i = u_geteffstealth(u); + if (i >= 0) { + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0) + WARN_STATIC_BUFFER(); + } + } + + effsk = eff_skill(u, sv, 0); + if (wrptr(&bufp, &size, snprintf(bufp, size, "%d", effsk)) != 0) + WARN_STATIC_BUFFER(); + + if (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) { + int oldeff = 0; + int diff; + + if (sv->old > 0) { + oldeff = sv->old + get_modifier(u, sv->id, sv->old, u->region, false); + if (oldeff < 0) oldeff = 0; + } + + diff = effsk - oldeff; + + if (diff != 0) { + if (wrptr(&bufp, &size, snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0) + WARN_STATIC_BUFFER(); + } + } + return bufp - buffer; +} + int bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, char *buf, size_t size) @@ -750,7 +816,7 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, if (u->faction == f) { skill *sv; for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { - size_t bytes = spskill(bufp, size, lang, u, sv, &dh, 1); + size_t bytes = spskill(bufp, size, lang, u, sv, &dh); assert(bytes <= INT_MAX); if (wrptr(&bufp, &size, (int)bytes) != 0) WARN_STATIC_BUFFER(); @@ -918,71 +984,6 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, return dh; } -size_t -spskill(char *buffer, size_t size, const struct locale * lang, - const struct unit * u, struct skill * sv, int *dh, int days) -{ - char *bufp = buffer; - int effsk; - - if (!u->number) - return 0; - if (sv->level <= 0) { - if (sv->old <= 0 || (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) == 0) { - return 0; - } - } - - bufp = STRLCPY(bufp, ", ", size); - - if (!*dh) { - bufp = STRLCPY(bufp, LOC(lang, "nr_skills"), size); - bufp = STRLCPY(bufp, ": ", size); - *dh = 1; - } - bufp = STRLCPY(bufp, skillname(sv->id, lang), size); - bufp = STRLCPY(bufp, " ", size); - - if (sv->id == SK_MAGIC) { - sc_mage *mage = get_mage(u); - if (mage && mage->magietyp != M_GRAY) { - bufp = STRLCPY(bufp, LOC(lang, mkname("school", - magic_school[mage->magietyp])), size); - bufp = STRLCPY(bufp, " ", size); - } - } - - if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) { - int i = u_geteffstealth(u); - if (i >= 0) { - if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0) - WARN_STATIC_BUFFER(); - } - } - - effsk = eff_skill(u, sv, 0); - if (wrptr(&bufp, &size, snprintf(bufp, size, "%d", effsk)) != 0) - WARN_STATIC_BUFFER(); - - if (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) { - int oldeff = 0; - int diff; - - if (sv->old > 0) { - oldeff = sv->old + get_modifier(u, sv->id, sv->old, u->region, false); - } - - oldeff = MAX(0, oldeff); - diff = effsk - oldeff; - - if (diff != 0) { - if (wrptr(&bufp, &size, snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0) - WARN_STATIC_BUFFER(); - } - } - return bufp - buffer; -} - void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark) { bool firstline; @@ -1013,7 +1014,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned firstline = false; } if (!cut) { - cut = s + MIN(len, REPORTWIDTH); + cut = s + ((len < REPORTWIDTH) ? len : REPORTWIDTH); } memcpy(buf + indent, s, cut - s); buf[indent + (cut - s)] = 0; @@ -1669,7 +1670,7 @@ void finish_reports(report_context *ctx) { } } -int write_reports(faction * f, time_t ltime) +int write_reports(faction * f) { bool gotit = false; struct report_context ctx; @@ -1758,7 +1759,6 @@ int reports(void) { faction *f; FILE *mailit; - time_t ltime = time(NULL); int retval = 0; char path[4096]; const char * rpath = reportpath(); @@ -1775,7 +1775,7 @@ int reports(void) for (f = factions; f; f = f->next) { if (f->email && !fval(f, FFL_NPC)) { - int error = write_reports(f, ltime); + int error = write_reports(f); if (error) retval = error; if (mailit) @@ -1998,6 +1998,7 @@ static void eval_unitsize(struct opstack **stack, const void *userdata) const struct unit *u = (const struct unit *)opop(stack).v; variant var; + UNUSED_ARG(userdata); var.i = u->number; opush(stack, var); } @@ -2009,6 +2010,7 @@ static void eval_faction(struct opstack **stack, const void *userdata) size_t len = strlen(c); variant var; + UNUSED_ARG(userdata); var.v = strcpy(balloc(len + 1), c); opush(stack, var); } @@ -2018,6 +2020,8 @@ static void eval_alliance(struct opstack **stack, const void *userdata) const struct alliance *al = (const struct alliance *)opop(stack).v; const char *c = alliancename(al); variant var; + + UNUSED_ARG(userdata); if (c != NULL) { size_t len = strlen(c); var.v = strcpy(balloc(len + 1), c); diff --git a/src/reports.h b/src/reports.h index 0c285257e..d09cce992 100644 --- a/src/reports.h +++ b/src/reports.h @@ -60,12 +60,11 @@ extern "C" { void sparagraph(struct strlist **SP, const char *s, unsigned int indent, char mark); void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark); const char *hp_status(const struct unit *u); - size_t spskill(char *pbuf, size_t siz, const struct locale *lang, const struct unit *u, struct skill *sv, int *dh, int days); /* mapper */ void spunit(struct strlist **SP, const struct faction *f, const struct unit *u, unsigned int indent, seen_mode mode); int reports(void); - int write_reports(struct faction *f, time_t ltime); + int write_reports(struct faction *f); int init_reports(void); void reorder_units(struct region * r); From cf46acdc6a91543e6c55a367d16abd27ead21233 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Feb 2018 19:46:34 +0100 Subject: [PATCH 10/10] bufunit does not write an indent, doe not need the parameter. --- src/bind_unit.c | 2 +- src/bindings.c | 2 +- src/report.c | 2 +- src/reports.c | 4 ++-- src/reports.h | 4 ++-- src/reports.test.c | 28 ++++++++++++++-------------- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/bind_unit.c b/src/bind_unit.c index 4dd6313d8..2ae39bf20 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -55,7 +55,7 @@ static int tolua_bufunit(lua_State * L) { if (f) { char buf[8192]; int mode = (int)tolua_tonumber(L, 3, (int)seen_unit); - bufunit(f, u, 0, mode, buf, sizeof(buf)); + bufunit(f, u, mode, buf, sizeof(buf)); tolua_pushstring(L, buf); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 2364775fb..90f734fd9 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -923,7 +923,7 @@ static int tolua_report_unit(lua_State * L) char buffer[512]; unit *u = (unit *)tolua_tousertype(L, 1, 0); faction *f = (faction *)tolua_tousertype(L, 2, 0); - bufunit(f, u, 0, seen_unit, buffer, sizeof(buffer)); + bufunit(f, u, seen_unit, buffer, sizeof(buffer)); tolua_pushstring(L, buffer); return 1; } diff --git a/src/report.c b/src/report.c index 44b1bd6ad..1bcec6de8 100644 --- a/src/report.c +++ b/src/report.c @@ -695,7 +695,7 @@ nr_unit(struct stream *out, const faction * f, const unit * u, int indent, seen_ return; newline(out); - dh = bufunit(f, u, indent, mode, buf, sizeof(buf)); + dh = bufunit(f, u, mode, buf, sizeof(buf)); if (u->faction == f) { marker = '*'; diff --git a/src/reports.c b/src/reports.c index 862dd165a..20879a191 100644 --- a/src/reports.c +++ b/src/reports.c @@ -677,7 +677,7 @@ static size_t spskill(char *buffer, size_t size, const struct locale * lang, } int -bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, char *buf, +bufunit(const faction * f, const unit * u, seen_mode mode, char *buf, size_t size) { int i, dh; @@ -1055,7 +1055,7 @@ spunit(struct strlist **SP, const struct faction *f, const unit * u, unsigned in seen_mode mode) { char buf[DISPLAYSIZE]; - int dh = bufunit(f, u, indent, mode, buf, sizeof(buf)); + int dh = bufunit(f, u, mode, buf, sizeof(buf)); lparagraph(SP, buf, indent, (char)((u->faction == f) ? '*' : (dh ? '+' : '-'))); } diff --git a/src/reports.h b/src/reports.h index d09cce992..d631f6f38 100644 --- a/src/reports.h +++ b/src/reports.h @@ -90,8 +90,8 @@ extern "C" { void register_reporttype(const char *extension, report_fun write, int flag); - int bufunit(const struct faction *f, const struct unit *u, unsigned int indent, - seen_mode mode, char *buf, size_t size); + int bufunit(const struct faction *f, const struct unit *u, seen_mode mode, + char *buf, size_t size); const char *trailinto(const struct region *r, const struct locale *lang); diff --git a/src/reports.test.c b/src/reports.test.c index cdc09c83c..e86fbbbf8 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -199,56 +199,56 @@ static void test_bufunit_fstealth(CuTest *tc) { key_set(&u->attribs, 42, 42); /* report to ourselves */ - bufunit(f1, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f1, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressive.", buf); /* ... also when we are anonymous */ u->flags |= UFL_ANON_FACTION; - bufunit(f1, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f1, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf); u->flags &= ~UFL_ANON_FACTION; /* we see that our unit is cloaked */ set_factionstealth(u, f2); CuAssertPtrNotNull(tc, u->attribs); - bufunit(f1, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f1, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human, aggressive.", buf); /* ... also when we are anonymous */ u->flags |= UFL_ANON_FACTION; - bufunit(f1, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f1, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf); u->flags &= ~UFL_ANON_FACTION; /* we can see that someone is presenting as us */ - bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f2, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human.", buf); /* ... but not if they are anonymous */ u->flags |= UFL_ANON_FACTION; - bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f2, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf); u->flags &= ~UFL_ANON_FACTION; /* we see the same thing as them when we are an ally */ al = ally_add(&f1->allies, f2); al->status = HELP_FSTEALTH; - bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f2, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf); /* ... also when they are anonymous */ u->flags |= UFL_ANON_FACTION; - bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f2, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf); u->flags &= ~UFL_ANON_FACTION; /* fstealth has no influence when we are allies, same results again */ set_factionstealth(u, NULL); - bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f2, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buf); u->flags |= UFL_ANON_FACTION; - bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); + bufunit(f2, u, seen_unit, buf, sizeof(buf)); CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf); u->flags &= ~UFL_ANON_FACTION; @@ -278,20 +278,20 @@ static void test_bufunit(CuTest *tc) { unit_setname(u, "Hodor"); unit_setid(u, 1); - bufunit(u->faction, u, 0, 0, buffer, sizeof(buffer)); + bufunit(u->faction, u, 0, buffer, sizeof(buffer)); CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressiv.", buffer); set_level(u, SK_ALCHEMY, 1); - bufunit(u->faction, u, 0, 0, buffer, sizeof(buffer)); + bufunit(u->faction, u, 0, buffer, sizeof(buffer)); CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressiv, Talente: Alchemie 2.", buffer); set_level(u, SK_SAILING, 1); - bufunit(u->faction, u, 0, 0, buffer, sizeof(buffer)); + bufunit(u->faction, u, 0, buffer, sizeof(buffer)); CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressiv, Talente: Alchemie 2, Segeln 1.", buffer); f = test_create_faction(NULL); f->locale = get_or_create_locale("de"); - bufunit(f, u, 0, 0, buffer, sizeof(buffer)); + bufunit(f, u, 0, buffer, sizeof(buffer)); CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buffer); test_teardown();