diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 6c93dfadd..91caa58f7 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -569,14 +569,13 @@ matmod(const attrib * a, const unit * u, const resource_type * material, int val return value; } +/** Use up resources for building an object. +* Build up to 'size' points of 'type', where 'completed' +* of the first object have already been finished. return the +* actual size that could be built. +*/ int build(unit * u, const construction * ctype, int completed, int want) - /* Use up resources for building an object. returns the actual size - * being built - * Build up to 'size' points of 'type', where 'completed' - * of the first object have already been finished. return the - * actual size that could be built. - */ { const construction * type = ctype; int skills; /* number of skill points remainig */ diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 5e084744b..ce9716c57 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -432,12 +432,19 @@ do_maelstrom(region *r, unit *u) } } +/** sets a marker in the region telling that the unit has travelled through it + * this is used for two distinctly different purposes: + * - to report that a unit has travelled through. the report function + * makes sure to only report the ships of travellers, not the travellers + * themselves + * - to report the region to the traveller + */ void -travelthru(unit * u, region * r) +travelthru(const unit * u, region * r) { attrib *ru = a_add(&r->attribs, a_new(&at_travelunit)); - ru->data.v = u; + ru->data.v = (void*)u; /* the first and last region of the faction gets reset, because travelthrough * could be in regions that are located before the [first, last] interval, @@ -454,7 +461,7 @@ leave_trail(unit * u, region **route, region * to) while (*ri) { region * r = *ri++; - region * rn = *ri?*ri:to; + region * rn = *ri?*ri:to; direction_t dir = reldirection(r, rn); attrib * a = a_find(r->attribs, &at_traveldir_new); traveldir * td = NULL; @@ -473,6 +480,16 @@ leave_trail(unit * u, region **route, region * to) td->dir = dir; td->age = 2; + } +} + +static void +travel_route(const unit * u, region ** route) +{ + region **ri = route; + + while (*ri) { + region * r = *ri++; travelthru(u, r); } } @@ -498,6 +515,7 @@ move_ship(ship * sh, region * from, region * to, region ** route) leave_trail(u, route, to); trail=true; } + if (route!=NULL) travel_route(u, route); if (from!=to) { u->ship = NULL; /* damit move_unit() kein leave() macht */ move_unit(u, to, ulist); diff --git a/src/common/kernel/movement.h b/src/common/kernel/movement.h index 2c697a952..b9c13e515 100644 --- a/src/common/kernel/movement.h +++ b/src/common/kernel/movement.h @@ -57,7 +57,7 @@ extern struct unit *is_guarded(struct region * r, struct unit * u, unsigned int extern int enoughsailors(struct region * r, struct ship * sh); extern boolean canswim(struct unit *u); extern struct unit *kapitaen(struct region * r, struct ship * sh); -extern void travelthru(struct unit * u, struct region * r); +extern void travelthru(const struct unit * u, struct region * r); extern struct ship * move_ship(struct ship * sh, struct region * from, struct region * to, struct region ** route); extern void follow_unit(void); diff --git a/src/common/util/log.c b/src/common/util/log.c index 58d3c4dad..e7f705fae 100644 --- a/src/common/util/log.c +++ b/src/common/util/log.c @@ -1,13 +1,13 @@ /* vi: set ts=2: - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich ++-------------------+ Christian Schlittchen +| | Enno Rehling +| Eressea PBEM host | Katja Zedel +| (c) 1998 - 2003 | Henning Peters +| | Ingo Wilken ++-------------------+ Stefan Reich - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. +This program may not be used, modified or distributed +without prior permission by the authors of Eressea. */ #include #include "log.h" @@ -21,117 +21,123 @@ static int flags = LOG_FLUSH|LOG_CPERROR|LOG_CPWARNING; static FILE * logfile; +void +log_flush(void) +{ + fflush(logfile); +} + void log_puts(const char * str) { - if (!logfile) logfile = stderr; - fputs(str, logfile); + if (!logfile) logfile = stderr; + fputs(str, logfile); } void log_printf(const char * format, ...) { - va_list marker; - if (!logfile) logfile = stderr; - va_start(marker, format); - vfprintf(logfile, format, marker); - va_end(marker); - if (flags & LOG_FLUSH) { - fflush(logfile); - } + va_list marker; + if (!logfile) logfile = stderr; + va_start(marker, format); + vfprintf(logfile, format, marker); + va_end(marker); + if (flags & LOG_FLUSH) { + log_flush(); + } } void log_open(const char * filename) { - if (logfile) log_close(); - logfile = fopen(filename, "a"); - if (logfile) { - /* Get UNIX-style time and display as number and string. */ - time_t ltime; - time( <ime ); - log_printf( "===\n=== Logfile started at %s===\n", ctime( <ime ) ); - } + if (logfile) log_close(); + logfile = fopen(filename, "a"); + if (logfile) { + /* Get UNIX-style time and display as number and string. */ + time_t ltime; + time( <ime ); + log_printf( "===\n=== Logfile started at %s===\n", ctime( <ime ) ); + } } void log_close(void) { - if (!logfile || logfile == stderr || logfile == stdout) return; - if (logfile) { - /* Get UNIX-style time and display as number and string. */ - time_t ltime; - time( <ime ); - log_printf("===\n=== Logfile closed at %s===\n\n", ctime( <ime ) ); - } - fclose(logfile); - logfile = 0; + if (!logfile || logfile == stderr || logfile == stdout) return; + if (logfile) { + /* Get UNIX-style time and display as number and string. */ + time_t ltime; + time( <ime ); + log_printf("===\n=== Logfile closed at %s===\n\n", ctime( <ime ) ); + } + fclose(logfile); + logfile = 0; } void _log_warn(const char * format, ...) { - va_list marker; - if (!logfile) logfile = stderr; - fputs("WARNING: ", logfile); - va_start(marker, format); - vfprintf(logfile, format, marker); - va_end(marker); - if (logfile!=stderr) { - if (flags & LOG_CPWARNING) { - fputs("\bWARNING: ", stderr); - va_start(marker, format); - vfprintf(stderr, format, marker); - va_end(marker); - } - if (flags & LOG_FLUSH) { - fflush(logfile); - } - } + va_list marker; + if (!logfile) logfile = stderr; + fputs("WARNING: ", logfile); + va_start(marker, format); + vfprintf(logfile, format, marker); + va_end(marker); + if (logfile!=stderr) { + if (flags & LOG_CPWARNING) { + fputs("\bWARNING: ", stderr); + va_start(marker, format); + vfprintf(stderr, format, marker); + va_end(marker); + } + if (flags & LOG_FLUSH) { + log_flush(); + } + } } void _log_error(const char * format, ...) { - va_list marker; - if (!logfile) logfile = stderr; + va_list marker; + if (!logfile) logfile = stderr; - fputs("ERROR: ", logfile); - va_start(marker, format); - vfprintf(logfile, format, marker); - va_end(marker); - if (logfile!=stderr) { - if (flags & LOG_CPERROR) { - fputs("\bERROR: ", stderr); - va_start(marker, format); - vfprintf(stderr, format, marker); - va_end(marker); - } - if (flags & LOG_FLUSH) { - fflush(logfile); - } - } + fputs("ERROR: ", logfile); + va_start(marker, format); + vfprintf(logfile, format, marker); + va_end(marker); + if (logfile!=stderr) { + if (flags & LOG_CPERROR) { + fputs("\bERROR: ", stderr); + va_start(marker, format); + vfprintf(stderr, format, marker); + va_end(marker); + } + if (flags & LOG_FLUSH) { + log_flush(); + } + } } void _log_info(unsigned int flag, const char * format, ...) { - va_list marker; - if (!logfile) logfile = stderr; + va_list marker; + if (!logfile) logfile = stderr; - fprintf(logfile, "INFO[%u]: ", flag); - va_start(marker, format); - vfprintf(logfile, format, marker); - va_end(marker); - if (logfile!=stderr) { - if (flags & flag) { - fprintf(stderr, "\bINFO[%u]: ", flag); - va_start(marker, format); - vfprintf(stderr, format, marker); - va_end(marker); - } - if (flags & LOG_FLUSH) { - fflush(logfile); - } - } + fprintf(logfile, "INFO[%u]: ", flag); + va_start(marker, format); + vfprintf(logfile, format, marker); + va_end(marker); + if (logfile!=stderr) { + if (flags & flag) { + fprintf(stderr, "\bINFO[%u]: ", flag); + va_start(marker, format); + vfprintf(stderr, format, marker); + va_end(marker); + } + if (flags & LOG_FLUSH) { + log_flush(); + } + } } diff --git a/src/common/util/log.h b/src/common/util/log.h index 6f796de61..07008330b 100644 --- a/src/common/util/log.h +++ b/src/common/util/log.h @@ -1,13 +1,13 @@ /* vi: set ts=2: - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich ++-------------------+ Christian Schlittchen +| | Enno Rehling +| Eressea PBEM host | Katja Zedel +| (c) 1998 - 2003 | Henning Peters +| | Ingo Wilken ++-------------------+ Stefan Reich - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. +This program may not be used, modified or distributed +without prior permission by the authors of Eressea. */ #ifndef H_UTIL_LOG #define H_UTIL_LOG @@ -15,19 +15,20 @@ extern "C" { #endif -extern void log_open(const char * filename); -extern void log_printf(const char * str, ...); -extern void log_puts(const char * str); -extern void log_close(void); + extern void log_open(const char * filename); + extern void log_printf(const char * str, ...); + extern void log_puts(const char * str); + extern void log_close(void); + extern void log_flush(void); #define log_warning(x) _log_warn x #define log_error(x) _log_error x #define log_info(x) _log_info x -/* use macros above instead of these: */ -extern void _log_warn(const char * format, ...); -extern void _log_error(const char * format, ...); -extern void _log_info(unsigned int flag, const char * format, ...); + /* use macros above instead of these: */ + extern void _log_warn(const char * format, ...); + extern void _log_error(const char * format, ...); + extern void _log_info(unsigned int flag, const char * format, ...); #define LOG_FLUSH (1<<0) #define LOG_CPWARNING (1<<1)