From 06a04d0e20032d74f68362f2011e3a2caac47df7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 19:48:03 +0200 Subject: [PATCH 1/2] fix logging for sp_igjarjuk, temporarily set log-levels for the game to error|warn|info remove some code that accesses `verbosity` variable (todo: hide it more, fix logging) --- process/run-turn | 2 +- src/creport.c | 1 - src/kernel/faction.c | 3 +- src/laws.c | 8 ++--- src/listbox.c | 7 ++--- src/main.c | 4 +-- src/monsters.c | 22 +++++--------- src/reports.c | 8 ++--- src/spells/combatspells.c | 10 +++--- src/spells/combatspells.h | 64 +++++++++++++++++++-------------------- src/util/log.h | 4 +-- 11 files changed, 57 insertions(+), 76 deletions(-) diff --git a/process/run-turn b/process/run-turn index 80e12b093..0c5ee8fd2 100755 --- a/process/run-turn +++ b/process/run-turn @@ -9,6 +9,6 @@ fi cd $ERESSEA/game-$GAME echo "running turn $TURN, game $GAME" -$ERESSEA/server/bin/eressea -v1 -t $TURN run-turn.lua +$ERESSEA/server/bin/eressea -v3 -t $TURN run-turn.lua mkdir -p log ln -f eressea.log log/eressea.log.$TURN diff --git a/src/creport.c b/src/creport.c index 85dde4a93..aea88f03a 100644 --- a/src/creport.c +++ b/src/creport.c @@ -81,7 +81,6 @@ without prior permission by the authors of Eressea. #include /* imports */ -extern int verbosity; bool opt_cr_absolute_coords = false; /* globals */ diff --git a/src/kernel/faction.c b/src/kernel/faction.c index e57dd64ed..c47abada1 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -608,8 +608,7 @@ void remove_empty_factions(void) ursprung *ur = f->ursprung; while (ur && ur->id != 0) ur = ur->next; - if (verbosity >= 2) - log_printf(stdout, "\t%s\n", factionname(f)); + log_debug("dead: %s", factionname(f)); /* Einfach in eine Datei schreiben und später vermailen */ diff --git a/src/laws.c b/src/laws.c index a04655439..2f3cd2728 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4064,11 +4064,10 @@ void process(void) region *r; processor *pglobal = proc; - if (verbosity >= 3) - printf("- Step %u\n", prio); + log_debug("- Step %u\n", prio); while (proc && proc->priority == prio) { if (proc->name && verbosity >= 1) - log_printf(stdout, " - %s\n", proc->name); + log_debug(" - %s\n", proc->name); proc = proc->next; } @@ -4164,8 +4163,7 @@ void process(void) } } - if (verbosity >= 3) - printf("\n - Leere Gruppen loeschen...\n"); + log_debug("\n - Leere Gruppen loeschen...\n"); for (f = factions; f; f = f->next) { group **gp = &f->groups; while (*gp) { diff --git a/src/listbox.c b/src/listbox.c index 525970637..3686cbba1 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -88,9 +88,7 @@ list_selection *do_selection(list_selection * sel, const char *title, width = (int)strlen(s->str); } ++height; - if (verbosity >= 5) { - log_printf(stdout, "s %s w %d h %d\n", s->str, width, height); - } + log_debug("s %s w %d h %d\n", s->str, width, height); } if (height == 0 || width == 0) return 0; @@ -99,8 +97,7 @@ list_selection *do_selection(list_selection * sel, const char *title, if (height + 2 > SY) height = SY - 2; - if (verbosity >= 5) - log_printf(stdout, "w %d h %d\n", width, height); + log_debug("w %d h %d\n", width, height); wn = newwin(height + 2, width + 4, (SY - height - 2) / 2, (SX - width - 4) / 2); diff --git a/src/main.c b/src/main.c index a1ebc6f06..5559a2086 100644 --- a/src/main.c +++ b/src/main.c @@ -202,10 +202,10 @@ static int parse_args(int argc, char **argv, int *exitcode) log_stderr = LOG_CPERROR | LOG_CPWARNING; break; case 3: - log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG; + log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO; break; default: - log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG | LOG_CPINFO; + log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO | LOG_CPDEBUG; break; } diff --git a/src/monsters.c b/src/monsters.c index d81ba7f81..95dd6164c 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -943,11 +943,9 @@ void spawn_dragons(void) fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, get_equipment("monster_dragon")); - if (verbosity >= 2) { - log_printf(stdout, "%d %s in %s.\n", u->number, - LOC(default_locale, - rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL)); - } + log_debug("spawning %d %s in %s.\n", u->number, + LOC(default_locale, + rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL)); name_unit(u); @@ -976,6 +974,7 @@ void spawn_undead(void) /* Chance 0.1% * chaosfactor */ if (r->land && unburied > r->land->peasants / 20 && rng_int() % 10000 < (100 + 100 * chaosfactor(r))) { + message *msg; unit *u; /* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen. * Lieber sammeln lassen, bis sie mindestens 5% der Bevölkerung sind, und @@ -1018,14 +1017,10 @@ void spawn_undead(void) deathcounts(r, -undead); name_unit(u); - if (verbosity >= 2) { - log_printf(stdout, "%d %s in %s.\n", u->number, - LOC(default_locale, - rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL)); - } - - { - message *msg = msg_message("undeadrise", "region", r); + log_debug("spawning %d %s in %s.\n", u->number, + LOC(default_locale, + rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL)); + msg = msg_message("undeadrise", "region", r); add_message(&r->msgs, msg); for (u = r->units; u; u = u->next) freset(u->faction, FFL_SELECT); @@ -1036,7 +1031,6 @@ void spawn_undead(void) add_message(&u->faction->msgs, msg); } msg_release(msg); - } } else { int i = deathcount(r); diff --git a/src/reports.c b/src/reports.c index 9d4d7f21c..21d51afa2 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1681,9 +1681,7 @@ int write_reports(faction * f, time_t ltime) log_warning("errno was %d before writing reports", errno); errno = 0; } - if (verbosity >= 2) { - log_printf(stdout, "Reports for %s:", factionname(f)); - } + log_debug("Reports for %s:", factionname(f)); for (rtype = report_types; rtype != NULL; rtype = rtype->next) { if (f->options & rtype->flag) { int error; @@ -1795,9 +1793,7 @@ int reports(void) int retval = 0; char path[MAX_PATH]; - if (verbosity >= 1) { - log_printf(stdout, "Writing reports for turn %d:", turn); - } + log_info("Writing reports for turn %d:", turn); report_donations(); remove_empty_units(); diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index dc7bb1bda..4b8cc8b51 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -872,9 +872,7 @@ static fighter *summon_allies(const fighter *fi, const race *rc, int number) { a->data.ca[1] = 100; a_add(&u->attribs, a); - msg = - msg_message("sp_wolfhowl_effect", "mage amount race", - mage, u->number, rc); + msg = msg_message("sp_wolfhowl_effect", "mage amount race", mage, u->number, rc); message_all(b, msg); msg_release(msg); @@ -883,12 +881,12 @@ static fighter *summon_allies(const fighter *fi, const race *rc, int number) { int sp_igjarjuk(castorder *co) { unit *u; - fighter * fi = co->magician.fig; + fighter *fm = co->magician.fig, *fi; const race *rc = get_race(RC_WYRM); - fi = summon_allies(fi, rc, 1); + fi = summon_allies(fm, rc, 1); u = fi->unit; unit_setname(u, "Igjarjuk"); - log_debug("%s calls a wyrm in %s", unitname(fi->unit), regionname(u->region, 0)); + log_info("%s summons Igjarjuk in %s", unitname(fm->unit), regionname(u->region, 0)); return co->level; } diff --git a/src/spells/combatspells.h b/src/spells/combatspells.h index 8b06fabb1..4e3173a66 100644 --- a/src/spells/combatspells.h +++ b/src/spells/combatspells.h @@ -17,40 +17,40 @@ extern "C" { #endif - struct fighter; + struct castorder; /* Kampfzauber */ - extern int sp_fumbleshield(struct castorder * co); - extern int sp_shadowknights(struct castorder * co); - extern int sp_combatrosthauch(struct castorder * co); - extern int sp_kampfzauber(struct castorder * co); - extern int sp_healing(struct castorder * co); - extern int sp_keeploot(struct castorder * co); - extern int sp_reanimate(struct castorder * co); - extern int sp_chaosrow(struct castorder * co); - extern int sp_flee(struct castorder * co); - extern int sp_berserk(struct castorder * co); - extern int sp_tiredsoldiers(struct castorder * co); - extern int sp_reeling_arrows(struct castorder * co); - extern int sp_denyattack(struct castorder * co); - extern int sp_sleep(struct castorder * co); - extern int sp_windshield(struct castorder * co); - extern int sp_strong_wall(struct castorder * co); - extern int sp_petrify(struct castorder * co); - extern int sp_hero(struct castorder * co); - extern int sp_frighten(struct castorder * co); - extern int sp_mindblast(struct castorder * co); - extern int sp_mindblast_temp(struct castorder * co); - extern int sp_speed(struct castorder * co); - extern int sp_wolfhowl(struct castorder * co); - extern int sp_igjarjuk(struct castorder * co); - extern int sp_dragonodem(struct castorder * co); - extern int sp_reduceshield(struct castorder * co); - extern int sp_armorshield(struct castorder * co); - extern int sp_stun(struct castorder * co); - extern int sp_undeadhero(struct castorder * co); - extern int sp_shadowcall(struct castorder * co); - extern int sp_immolation(struct castorder * co); + int sp_fumbleshield(struct castorder * co); + int sp_shadowknights(struct castorder * co); + int sp_combatrosthauch(struct castorder * co); + int sp_kampfzauber(struct castorder * co); + int sp_healing(struct castorder * co); + int sp_keeploot(struct castorder * co); + int sp_reanimate(struct castorder * co); + int sp_chaosrow(struct castorder * co); + int sp_flee(struct castorder * co); + int sp_berserk(struct castorder * co); + int sp_tiredsoldiers(struct castorder * co); + int sp_reeling_arrows(struct castorder * co); + int sp_denyattack(struct castorder * co); + int sp_sleep(struct castorder * co); + int sp_windshield(struct castorder * co); + int sp_strong_wall(struct castorder * co); + int sp_petrify(struct castorder * co); + int sp_hero(struct castorder * co); + int sp_frighten(struct castorder * co); + int sp_mindblast(struct castorder * co); + int sp_mindblast_temp(struct castorder * co); + int sp_speed(struct castorder * co); + int sp_wolfhowl(struct castorder * co); + int sp_igjarjuk(struct castorder * co); + int sp_dragonodem(struct castorder * co); + int sp_reduceshield(struct castorder * co); + int sp_armorshield(struct castorder * co); + int sp_stun(struct castorder * co); + int sp_undeadhero(struct castorder * co); + int sp_shadowcall(struct castorder * co); + int sp_immolation(struct castorder * co); #ifdef __cplusplus } diff --git a/src/util/log.h b/src/util/log.h index ef93ca3a5..40a667de4 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -30,8 +30,8 @@ extern "C" { #define LOG_FLUSH 0x01 #define LOG_CPWARNING 0x02 #define LOG_CPERROR 0x04 -#define LOG_CPDEBUG 0x08 -#define LOG_CPINFO 0x10 +#define LOG_CPINFO 0x08 +#define LOG_CPDEBUG 0x10 extern int log_flags; extern int log_stderr; From a0271390573f524d8b2ade7911c9734d5e5ccbea Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 20:58:09 +0200 Subject: [PATCH 2/2] remove global variable `verbosity` in favor of static in main.c (use log_* functions everywhere) --- src/battle.c | 8 +------- src/kernel/config.c | 2 -- src/kernel/config.h | 20 +------------------- src/laws.c | 6 +++--- src/main.c | 1 + src/report.c | 1 - tests/data/test.dat | Bin 0 -> 159 bytes tests/orders.txt | 3 +++ tests/runtests.bat | 9 +++++++++ 9 files changed, 18 insertions(+), 32 deletions(-) create mode 100644 tests/data/test.dat create mode 100644 tests/orders.txt create mode 100644 tests/runtests.bat diff --git a/src/battle.c b/src/battle.c index f9bfa0770..3980d71c8 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3757,8 +3757,6 @@ static int battle_report(battle * b) } } - if (verbosity > 0) - log_printf(stdout, " %d", b->turn); fflush(stdout); for (bf = b->factions; bf; bf = bf->next) { @@ -4349,8 +4347,7 @@ void do_battle(region * r) do_combatmagic(b, DO_PRECOMBATSPELL); print_stats(b); /* gibt die Kampfaufstellung aus */ - if (verbosity > 0) - log_printf(stdout, "%s (%d, %d) : ", rname(r, default_locale), r->x, r->y); + log_debug("battle in %s (%d, %d) : ", regionname(r, 0), r->x, r->y); for (; battle_report(b) && b->turn <= max_turns; ++b->turn) { if (bdebug) { @@ -4362,9 +4359,6 @@ void do_battle(region * r) } - if (verbosity > 0) - log_printf(stdout, "\n"); - /* Auswirkungen berechnen: */ aftermath(b); if (rule_force_leave(FORCE_LEAVE_POSTCOMBAT)) { diff --git a/src/kernel/config.c b/src/kernel/config.c index 573126137..7c528b06d 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -438,8 +438,6 @@ static attrib_type at_npcfaction = { ATF_UNIQUE }; -int verbosity = 1; - FILE *debug; /* ----------------------------------------------------------------------- */ diff --git a/src/kernel/config.h b/src/kernel/config.h index 056de8f84..e30d462d1 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -313,28 +313,10 @@ extern "C" { extern bool battledebug; extern bool sqlpatch; extern bool lomem; /* save memory */ - extern int turn; - extern int verbosity; - - /** report options **/ - extern const char *options[MAXOPTIONS]; - - extern struct helpmode helpmodes[]; - extern const char *parameters[]; - extern const char *localenames[]; - extern settings global; - - extern bool battledebug; - extern bool sqlpatch; - extern bool lomem; /* save memory */ - - extern int turn; - extern int verbosity; extern bool getunitpeasants; - /** report options **/ - extern const char *options[MAXOPTIONS]; + extern const char *options[MAXOPTIONS]; /* report options */ #ifdef __cplusplus } diff --git a/src/laws.c b/src/laws.c index 2f3cd2728..488f6bbda 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4064,10 +4064,10 @@ void process(void) region *r; processor *pglobal = proc; - log_debug("- Step %u\n", prio); + log_debug("- Step %u", prio); while (proc && proc->priority == prio) { - if (proc->name && verbosity >= 1) - log_debug(" - %s\n", proc->name); + if (proc->name) + log_debug(" - %s", proc->name); proc = proc->next; } diff --git a/src/main.c b/src/main.c index 5559a2086..fee0eaab0 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,7 @@ static const char *logfile = "eressea.log"; static const char *luafile = 0; static const char *inifile = "eressea.ini"; static int memdebug = 0; +static int verbosity = 1; static void load_inifile(dictionary * d) { diff --git a/src/report.c b/src/report.c index b63b45755..e77ff1d9e 100644 --- a/src/report.c +++ b/src/report.c @@ -96,7 +96,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -extern int verbosity; extern int *storms; extern int weeks_per_month; extern int months_per_year; diff --git a/tests/data/test.dat b/tests/data/test.dat new file mode 100644 index 0000000000000000000000000000000000000000..a4f9d46ede1b6d416e983a0c697415f89d3cc6f7 GIT binary patch literal 159 zcma!HWME)oU|?WoW=_pZX%Yo885n?Kt)CXpv}fSR%`eR>NzBaaU|{6*&d*Lw$}CRI z0V&}q%8f5B$F=rT>TeNatQea6+%*kbC%}Om# s&0%KEtt=|aU|`PA%wc9J&dkYXV$aM=PR%P$1=|nO$mj?nfmVPh0AQIZ-2eap literal 0 HcmV?d00001 diff --git a/tests/orders.txt b/tests/orders.txt new file mode 100644 index 000000000..3e1e89acb --- /dev/null +++ b/tests/orders.txt @@ -0,0 +1,3 @@ +ERESSEA 72vx "naeg86" +EINHEIT nqLx +BENENNEN EINHEIT 'Goldene Herde' diff --git a/tests/runtests.bat b/tests/runtests.bat new file mode 100644 index 000000000..3bb41c982 --- /dev/null +++ b/tests/runtests.bat @@ -0,0 +1,9 @@ +@ECHO OFF +SET BUILD=..\build-vs12\eressea\Debug\ +SET SERVER=%BUILD%\eressea.exe +%BUILD%\test_eressea.exe +%SERVER% ..\scripts\run-tests.lua +%SERVER% ..\scripts\run-tests-e2.lua +%SERVER% ..\scripts\run-tests-e3.lua +PAUSE +RMDIR /s /q reports