diff -Nur -Xfreeciv/diff_ignore freeciv/ai/Makefile.am test-ailog/ai/Makefile.am --- freeciv/ai/Makefile.am Sun Aug 25 07:28:54 2002 +++ test-ailog/ai/Makefile.am Sat Sep 28 10:39:17 2002 @@ -31,6 +31,8 @@ aidata.h \ aihand.c \ aihand.h \ + ailog.c \ + ailog.h \ aitech.c \ aitech.h \ aitools.c \ diff -Nur -Xfreeciv/diff_ignore freeciv/ai/aicity.c test-ailog/ai/aicity.c --- freeciv/ai/aicity.c Fri Sep 27 16:48:33 2002 +++ test-ailog/ai/aicity.c Sat Sep 28 10:41:17 2002 @@ -48,6 +48,7 @@ #include "aihand.h" #include "aitools.h" #include "aidata.h" +#include "ailog.h" #include "aiunit.h" #include "aicity.h" diff -Nur -Xfreeciv/diff_ignore freeciv/ai/ailog.c test-ailog/ai/ailog.c --- freeciv/ai/ailog.c Wed Dec 31 18:00:00 1969 +++ test-ailog/ai/ailog.c Sat Sep 28 12:22:04 2002 @@ -0,0 +1,136 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "city.h" +#include "log.h" +#include "shared.h" +#include "support.h" +#include "unit.h" + +#include "gotohand.h" + +/* General AI logging functions */ + +/************************************************************************** +... +**************************************************************************/ +void CITY_LOG(int level, struct city *pcity, const char *msg, ...) +{ + char buffer[500]; + char buffer2[500]; + va_list ap; + int minlevel = MIN(LOGLEVEL_CITY, level); + + if (minlevel > log_level) { + return; + } + + my_snprintf(buffer, sizeof(buffer), "%s's %s(%d,%d) [s%d d%d u%d g%d] ", + city_owner(pcity)->name, pcity->name, + pcity->x, pcity->y, pcity->size, + pcity->ai.danger, pcity->ai.urgency, + pcity->ai.grave_danger); + + va_start(ap, msg); + my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); + va_end(ap); + + cat_snprintf(buffer, sizeof(buffer), buffer2); + freelog(minlevel, buffer); +} + +/************************************************************************** +... +**************************************************************************/ +void UNIT_LOG(int level, struct unit *punit, const char *msg, ...) +{ + char buffer[500]; + char buffer2[500]; + va_list ap; + int minlevel = MIN(LOGLEVEL_UNIT, level); + + if (minlevel > log_level) { + return; + } + + my_snprintf(buffer, sizeof(buffer), "%s's %s[%d] (%d,%d)->(%d,%d) ", + unit_owner(punit)->name, unit_type(punit)->name, + punit->id, punit->x, punit->y, + punit->goto_dest_x, punit->goto_dest_y); + + va_start(ap, msg); + my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); + va_end(ap); + + cat_snprintf(buffer, sizeof(buffer), buffer2); + freelog(minlevel, buffer); +} + +/************************************************************************** + Only makes a log message when a GOTO fails +**************************************************************************/ +void GOTO_LOG(int level, struct unit *punit, enum goto_result result, + const char *msg, ...) +{ + int minlevel = MIN(LOGLEVEL_GOTO, level); + + if (minlevel <= log_level && (result == GR_FAILED || result == GR_FOUGHT)) { + char buffer[500]; + char buffer2[500]; + va_list ap; + + my_snprintf(buffer, sizeof(buffer), + "%s's %s[%d] on GOTO (%d,%d)->(%d,%d) %s : ", + unit_owner(punit)->name, unit_type(punit)->name, + punit->id, punit->x, punit->y, + punit->goto_dest_x, punit->goto_dest_y, + (result == GR_FAILED) ? "failed" : "fought"); + + va_start(ap, msg); + my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); + va_end(ap); + + cat_snprintf(buffer, sizeof(buffer), buffer2); + freelog(minlevel, buffer); + } +} + +/************************************************************************** +... +**************************************************************************/ +void BODYGUARD_LOG(int level, struct unit *punit, const char *msg) +{ + char buffer[500]; + struct unit *pcharge; + int minlevel = MIN(LOGLEVEL_BODYGUARD, level); + + if (minlevel > log_level) { + return; + } + + pcharge = find_unit_by_id(punit->ai.charge); + my_snprintf(buffer, sizeof(buffer), + "%s's bodyguard %s[%d] (%d,%d)[%d@%d,%d]->(%d,%d) ", + unit_owner(punit)->name, unit_type(punit)->name, + punit->id, punit->x, punit->y, + pcharge ? pcharge->id : -1, pcharge ? pcharge->x : -1, + pcharge ? pcharge->y : -1, + punit->goto_dest_x, punit->goto_dest_y); + cat_snprintf(buffer, sizeof(buffer), msg); + freelog(minlevel, buffer); +} diff -Nur -Xfreeciv/diff_ignore freeciv/ai/ailog.h test-ailog/ai/ailog.h --- freeciv/ai/ailog.h Wed Dec 31 18:00:00 1969 +++ test-ailog/ai/ailog.h Sat Sep 28 10:38:22 2002 @@ -0,0 +1,34 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ +#ifndef FC__AILOG_H +#define FC__AILOG_H + +struct unit; +struct city; + +/* + * Change these and remake to watch logs from a specific + * part of the AI code. + */ +#define LOGLEVEL_BODYGUARD LOG_DEBUG +#define LOGLEVEL_UNIT LOG_DEBUG +#define LOGLEVEL_GOTO LOG_DEBUG +#define LOGLEVEL_CITY LOG_DEBUG + +void CITY_LOG(int level, struct city *pcity, const char *msg, ...); +void UNIT_LOG(int level, struct unit *punit, const char *msg, ...); +void GOTO_LOG(int level, struct unit *punit, enum goto_result result, + const char *msg, ...); +void BODYGUARD_LOG(int level, struct unit *punit, const char *msg); + +#endif /* FC__AILOG_H */ diff -Nur -Xfreeciv/diff_ignore freeciv/ai/aitools.c test-ailog/ai/aitools.c --- freeciv/ai/aitools.c Sun Sep 15 09:41:35 2002 +++ test-ailog/ai/aitools.c Sat Sep 28 10:40:12 2002 @@ -32,6 +32,7 @@ #include "unittools.h" #include "aicity.h" +#include "ailog.h" #include "aiunit.h" #include "aitools.h" diff -Nur -Xfreeciv/diff_ignore freeciv/ai/aitools.h test-ailog/ai/aitools.h --- freeciv/ai/aitools.h Wed Sep 4 23:26:26 2002 +++ test-ailog/ai/aitools.h Sat Sep 28 10:38:53 2002 @@ -14,73 +14,12 @@ #define FC__AITOOLS_H #include "shared.h" /* bool type */ -#include "unit.h" - -/* - * Change these and remake to watch logs from a specific - * part of the AI code. - */ -#define LOGLEVEL_BODYGUARD LOG_DEBUG -#define LOGLEVEL_UNIT LOG_DEBUG -#define LOGLEVEL_GOTO LOG_DEBUG -#define LOGLEVEL_CITY LOG_DEBUG - -/* General AI logging macros */ - -#define CITY_LOG(level, pcity, msg...) \ - { \ - char buffer[500]; \ - sprintf(buffer, "%s's %s(%d,%d) [s%d d%d u%d g%d] ", \ - city_owner(pcity)->name, pcity->name, \ - pcity->x, pcity->y, pcity->size, \ - pcity->ai.danger, pcity->ai.urgency, \ - pcity->ai.grave_danger); \ - cat_snprintf(buffer, sizeof(buffer), msg); \ - freelog(MIN(LOGLEVEL_CITY, level), buffer); \ - } - -#define UNIT_LOG(level, punit, msg...) \ - { \ - char buffer[500]; \ - sprintf(buffer, "%s's %s[%d] (%d,%d)->(%d,%d) ", \ - unit_owner(punit)->name, unit_type(punit)->name, \ - punit->id, punit->x, punit->y, \ - punit->goto_dest_x, punit->goto_dest_y); \ - cat_snprintf(buffer, sizeof(buffer), msg); \ - freelog(MIN(LOGLEVEL_UNIT, level), buffer); \ - } - -/* Only makes a log message when a GOTO fails */ -#define GOTO_LOG(level, punit, result, msg...) \ - if (result == GR_FAILED || result == GR_FOUGHT) { \ - char buffer[500]; \ - sprintf(buffer, "%s's %s[%d] on GOTO (%d,%d)->(%d,%d) %s : ", \ - unit_owner(punit)->name, unit_type(punit)->name, \ - punit->id, punit->x, punit->y, \ - punit->goto_dest_x, punit->goto_dest_y, \ - (result==GR_FAILED) ? "failed" : "fought"); \ - cat_snprintf(buffer, sizeof(buffer), msg); \ - freelog(MIN(LOGLEVEL_GOTO, level), buffer); \ - } \ - -#define BODYGUARD_LOG(level, punit, msg) \ - { \ - char buffer[500]; \ - struct unit *pcharge = find_unit_by_id(punit->ai.charge); \ - sprintf(buffer, "%s's bodyguard %s[%d] (%d,%d)[%d@%d,%d]->(%d,%d) ",\ - unit_owner(punit)->name, unit_type(punit)->name, \ - punit->id, punit->x, punit->y, \ - pcharge ? pcharge->id : -1, pcharge ? pcharge->x : -1,\ - pcharge ? pcharge->y : -1, \ - punit->goto_dest_x, punit->goto_dest_y); \ - cat_snprintf(buffer, sizeof(buffer), msg); \ - freelog(MIN(LOGLEVEL_BODYGUARD, level), buffer); \ - } struct ai_choice; struct city; struct government; struct player; +struct unit; enum bodyguard_enum { BODYGUARD_WANTED=-1, diff -Nur -Xfreeciv/diff_ignore freeciv/ai/aiunit.c test-ailog/ai/aiunit.c --- freeciv/ai/aiunit.c Fri Sep 27 16:48:34 2002 +++ test-ailog/ai/aiunit.c Sat Sep 28 10:40:35 2002 @@ -45,6 +45,7 @@ #include "aihand.h" #include "aitools.h" #include "aidata.h" +#include "ailog.h" #include "aiunit.h" diff -Nur -Xfreeciv/diff_ignore freeciv/common/log.c test-ailog/common/log.c --- freeciv/common/log.c Sat Sep 28 11:07:44 2002 +++ test-ailog/common/log.c Sat Sep 28 11:07:24 2002 @@ -25,10 +25,11 @@ #include "log.h" -static int log_level; static const char *log_filename; static log_callback_fn log_callback; + int logd_init_counter = 1; +int log_level; struct logd_fileinfo { char *name; diff -Nur -Xfreeciv/diff_ignore freeciv/common/log.h test-ailog/common/log.h --- freeciv/common/log.h Sat Sep 28 11:07:44 2002 +++ test-ailog/common/log.h Sat Sep 28 11:07:14 2002 @@ -40,6 +40,7 @@ #endif extern int logd_init_counter; /* increment this to force re-init */ +extern int log_level; /* Return an updated struct logdebug_afile_info: */ struct logdebug_afile_info logdebug_update(const char *file);