bugfix travelthru()
This commit is contained in:
Enno Rehling 2004-04-12 11:00:22 +00:00
parent 618bb6363a
commit a3ffe42a89
5 changed files with 136 additions and 112 deletions

View File

@ -569,14 +569,13 @@ matmod(const attrib * a, const unit * u, const resource_type * material, int val
return value; 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 int
build(unit * u, const construction * ctype, int completed, int want) 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; const construction * type = ctype;
int skills; /* number of skill points remainig */ int skills; /* number of skill points remainig */

View File

@ -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 void
travelthru(unit * u, region * r) travelthru(const unit * u, region * r)
{ {
attrib *ru = a_add(&r->attribs, a_new(&at_travelunit)); 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 /* the first and last region of the faction gets reset, because travelthrough
* could be in regions that are located before the [first, last] interval, * 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) { while (*ri) {
region * r = *ri++; region * r = *ri++;
region * rn = *ri?*ri:to; region * rn = *ri?*ri:to;
direction_t dir = reldirection(r, rn); direction_t dir = reldirection(r, rn);
attrib * a = a_find(r->attribs, &at_traveldir_new); attrib * a = a_find(r->attribs, &at_traveldir_new);
traveldir * td = NULL; traveldir * td = NULL;
@ -473,6 +480,16 @@ leave_trail(unit * u, region **route, region * to)
td->dir = dir; td->dir = dir;
td->age = 2; td->age = 2;
}
}
static void
travel_route(const unit * u, region ** route)
{
region **ri = route;
while (*ri) {
region * r = *ri++;
travelthru(u, r); travelthru(u, r);
} }
} }
@ -498,6 +515,7 @@ move_ship(ship * sh, region * from, region * to, region ** route)
leave_trail(u, route, to); leave_trail(u, route, to);
trail=true; trail=true;
} }
if (route!=NULL) travel_route(u, route);
if (from!=to) { if (from!=to) {
u->ship = NULL; /* damit move_unit() kein leave() macht */ u->ship = NULL; /* damit move_unit() kein leave() macht */
move_unit(u, to, ulist); move_unit(u, to, ulist);

View File

@ -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 int enoughsailors(struct region * r, struct ship * sh);
extern boolean canswim(struct unit *u); extern boolean canswim(struct unit *u);
extern struct unit *kapitaen(struct region * r, struct ship * sh); 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 struct ship * move_ship(struct ship * sh, struct region * from, struct region * to, struct region ** route);
extern void follow_unit(void); extern void follow_unit(void);

View File

@ -1,13 +1,13 @@
/* vi: set ts=2: /* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de> | | Enno Rehling <enno@eressea-pbem.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de> | (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#include <config.h> #include <config.h>
#include "log.h" #include "log.h"
@ -21,117 +21,123 @@
static int flags = LOG_FLUSH|LOG_CPERROR|LOG_CPWARNING; static int flags = LOG_FLUSH|LOG_CPERROR|LOG_CPWARNING;
static FILE * logfile; static FILE * logfile;
void
log_flush(void)
{
fflush(logfile);
}
void void
log_puts(const char * str) log_puts(const char * str)
{ {
if (!logfile) logfile = stderr; if (!logfile) logfile = stderr;
fputs(str, logfile); fputs(str, logfile);
} }
void void
log_printf(const char * format, ...) log_printf(const char * format, ...)
{ {
va_list marker; va_list marker;
if (!logfile) logfile = stderr; if (!logfile) logfile = stderr;
va_start(marker, format); va_start(marker, format);
vfprintf(logfile, format, marker); vfprintf(logfile, format, marker);
va_end(marker); va_end(marker);
if (flags & LOG_FLUSH) { if (flags & LOG_FLUSH) {
fflush(logfile); log_flush();
} }
} }
void void
log_open(const char * filename) log_open(const char * filename)
{ {
if (logfile) log_close(); if (logfile) log_close();
logfile = fopen(filename, "a"); logfile = fopen(filename, "a");
if (logfile) { if (logfile) {
/* Get UNIX-style time and display as number and string. */ /* Get UNIX-style time and display as number and string. */
time_t ltime; time_t ltime;
time( &ltime ); time( &ltime );
log_printf( "===\n=== Logfile started at %s===\n", ctime( &ltime ) ); log_printf( "===\n=== Logfile started at %s===\n", ctime( &ltime ) );
} }
} }
void void
log_close(void) log_close(void)
{ {
if (!logfile || logfile == stderr || logfile == stdout) return; if (!logfile || logfile == stderr || logfile == stdout) return;
if (logfile) { if (logfile) {
/* Get UNIX-style time and display as number and string. */ /* Get UNIX-style time and display as number and string. */
time_t ltime; time_t ltime;
time( &ltime ); time( &ltime );
log_printf("===\n=== Logfile closed at %s===\n\n", ctime( &ltime ) ); log_printf("===\n=== Logfile closed at %s===\n\n", ctime( &ltime ) );
} }
fclose(logfile); fclose(logfile);
logfile = 0; logfile = 0;
} }
void void
_log_warn(const char * format, ...) _log_warn(const char * format, ...)
{ {
va_list marker; va_list marker;
if (!logfile) logfile = stderr; if (!logfile) logfile = stderr;
fputs("WARNING: ", logfile); fputs("WARNING: ", logfile);
va_start(marker, format); va_start(marker, format);
vfprintf(logfile, format, marker); vfprintf(logfile, format, marker);
va_end(marker); va_end(marker);
if (logfile!=stderr) { if (logfile!=stderr) {
if (flags & LOG_CPWARNING) { if (flags & LOG_CPWARNING) {
fputs("\bWARNING: ", stderr); fputs("\bWARNING: ", stderr);
va_start(marker, format); va_start(marker, format);
vfprintf(stderr, format, marker); vfprintf(stderr, format, marker);
va_end(marker); va_end(marker);
} }
if (flags & LOG_FLUSH) { if (flags & LOG_FLUSH) {
fflush(logfile); log_flush();
} }
} }
} }
void void
_log_error(const char * format, ...) _log_error(const char * format, ...)
{ {
va_list marker; va_list marker;
if (!logfile) logfile = stderr; if (!logfile) logfile = stderr;
fputs("ERROR: ", logfile); fputs("ERROR: ", logfile);
va_start(marker, format); va_start(marker, format);
vfprintf(logfile, format, marker); vfprintf(logfile, format, marker);
va_end(marker); va_end(marker);
if (logfile!=stderr) { if (logfile!=stderr) {
if (flags & LOG_CPERROR) { if (flags & LOG_CPERROR) {
fputs("\bERROR: ", stderr); fputs("\bERROR: ", stderr);
va_start(marker, format); va_start(marker, format);
vfprintf(stderr, format, marker); vfprintf(stderr, format, marker);
va_end(marker); va_end(marker);
} }
if (flags & LOG_FLUSH) { if (flags & LOG_FLUSH) {
fflush(logfile); log_flush();
} }
} }
} }
void void
_log_info(unsigned int flag, const char * format, ...) _log_info(unsigned int flag, const char * format, ...)
{ {
va_list marker; va_list marker;
if (!logfile) logfile = stderr; if (!logfile) logfile = stderr;
fprintf(logfile, "INFO[%u]: ", flag); fprintf(logfile, "INFO[%u]: ", flag);
va_start(marker, format); va_start(marker, format);
vfprintf(logfile, format, marker); vfprintf(logfile, format, marker);
va_end(marker); va_end(marker);
if (logfile!=stderr) { if (logfile!=stderr) {
if (flags & flag) { if (flags & flag) {
fprintf(stderr, "\bINFO[%u]: ", flag); fprintf(stderr, "\bINFO[%u]: ", flag);
va_start(marker, format); va_start(marker, format);
vfprintf(stderr, format, marker); vfprintf(stderr, format, marker);
va_end(marker); va_end(marker);
} }
if (flags & LOG_FLUSH) { if (flags & LOG_FLUSH) {
fflush(logfile); log_flush();
} }
} }
} }

View File

@ -1,13 +1,13 @@
/* vi: set ts=2: /* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de> | | Enno Rehling <enno@eressea-pbem.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de> | (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#ifndef H_UTIL_LOG #ifndef H_UTIL_LOG
#define H_UTIL_LOG #define H_UTIL_LOG
@ -15,19 +15,20 @@
extern "C" { extern "C" {
#endif #endif
extern void log_open(const char * filename); extern void log_open(const char * filename);
extern void log_printf(const char * str, ...); extern void log_printf(const char * str, ...);
extern void log_puts(const char * str); extern void log_puts(const char * str);
extern void log_close(void); extern void log_close(void);
extern void log_flush(void);
#define log_warning(x) _log_warn x #define log_warning(x) _log_warn x
#define log_error(x) _log_error x #define log_error(x) _log_error x
#define log_info(x) _log_info x #define log_info(x) _log_info x
/* use macros above instead of these: */ /* use macros above instead of these: */
extern void _log_warn(const char * format, ...); extern void _log_warn(const char * format, ...);
extern void _log_error(const char * format, ...); extern void _log_error(const char * format, ...);
extern void _log_info(unsigned int flag, const char * format, ...); extern void _log_info(unsigned int flag, const char * format, ...);
#define LOG_FLUSH (1<<0) #define LOG_FLUSH (1<<0)
#define LOG_CPWARNING (1<<1) #define LOG_CPWARNING (1<<1)