From 001d9461a19d8eb7b0ce957cc540c290183ac160 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 1 May 2005 11:32:24 +0000 Subject: [PATCH] =?UTF-8?q?Wir=20machen=20jetzt=20wieder=20eine=20Kopie=20?= =?UTF-8?q?alter=20l=C3=A4nglicher=20Befehle.=20Vielleciht=20hilft=20es.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/creport.c | 8 +++++ src/common/gamecode/laws.c | 6 ++++ src/common/gamecode/report.c | 9 +++++ src/common/kernel/order.c | 62 ++++++++++++++++++++++++++++++++++- src/common/kernel/order.h | 2 ++ src/common/kernel/reports.c | 23 ++++++++----- src/common/kernel/save.c | 25 +++++++++++++- src/common/kernel/unit.h | 6 ++-- src/common/util/log.c | 6 +++- 9 files changed, 134 insertions(+), 13 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index ae08a34d3..940f56b89 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -765,6 +765,14 @@ cr_output_unit(FILE * F, const region * r, fwriteorder(F, u->lastorder, f->locale); fputc('\n', F); } +#else + for (ord = u->old_orders; ord; ord = ord->next) { + /* this new order will replace the old defaults */ + if (is_persistent(ord)) { + fwriteorder(F, ord, f->locale); + fputc('\n', F); + } + } #endif for (ord = u->orders; ord; ord = ord->next) { #ifdef LASTORDER diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 7bbd2aa38..baa8042d4 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3422,6 +3422,12 @@ setdefaults (void) #endif /* check all orders for a potential new long order this round: */ for (ord = u->orders; ord; ord = ord->next) { +#ifndef LASTORDER + if (u->old_orders && is_repeated(ord)) { + /* this new order will replace the old defaults */ + free_orders(&u->old_orders); + } +#endif if (is_exclusive(ord)) { /* Über dieser Zeile nur Befehle, die auch eine idle Faction machen darf */ if (idle(u->faction)) { diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index fcecb81b1..2afc9e58d 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1665,6 +1665,15 @@ order_template(FILE * F, faction * f) rps_nowrap(F, buf); rnl(F); +#ifndef LASTORDER + for (ord = u->old_orders; ord; ord = ord->next) { + /* this new order will replace the old defaults */ + strcpy(buf, " "); + write_order(ord, u->faction->locale, buf+2, sizeof(buf)-2); + rps_nowrap(F, buf); + rnl(F); + } +#endif for (ord = u->orders; ord; ord = ord->next) { if (is_persistent(ord)) { strcpy(buf, " "); diff --git a/src/common/kernel/order.c b/src/common/kernel/order.c index 7ad145359..d78e5c8df 100644 --- a/src/common/kernel/order.c +++ b/src/common/kernel/order.c @@ -166,6 +166,66 @@ parse_order(const char * s, const struct locale * lang) } } +boolean +is_repeated(const order * ord) +{ + const struct locale * lang = locale_array[ord->_lindex]; + param_t param; + + switch (ord->_keyword) { + case K_CAST: + case K_BUY: + case K_SELL: + case K_ROUTE: + case K_DRIVE: + case K_WORK: + case K_BESIEGE: + case K_ENTERTAIN: + case K_TAX: + case K_RESEARCH: + case K_SPY: + case K_STEAL: + case K_SABOTAGE: + case K_STUDY: + case K_TEACH: + case K_ZUECHTE: + case K_PIRACY: + return true; + +#if GROWING_TREES + case K_PFLANZE: + return true; +#endif + + case K_FOLLOW: + /* FOLLOW is only a long order if we are following a ship. */ + parser_pushstate(); + init_tokens(ord); + skip_token(); + param = getparam(lang); + parser_popstate(); + + if (param == P_SHIP) return true; + break; + + case K_MAKE: + /* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen + * Arten von MACHE zaehlen aber als neue defaults und werden + * behandelt wie die anderen (deswegen kein break nach case + * K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl) + * abgespeichert). */ + parser_pushstate(); + init_tokens(ord); /* initialize token-parser */ + skip_token(); + param = getparam(lang); + parser_popstate(); + + if (param != P_TEMP) return true; + break; + } + return false; +} + boolean is_exclusive(const order * ord) { @@ -242,7 +302,7 @@ is_persistent(const order * ord) return true; } - return persist || is_exclusive(ord); + return persist || is_repeated(ord); } char * diff --git a/src/common/kernel/order.h b/src/common/kernel/order.h index 3e43ad27c..91b0e762d 100644 --- a/src/common/kernel/order.h +++ b/src/common/kernel/order.h @@ -50,6 +50,8 @@ extern void set_order(struct order ** destp, struct order * src); extern char * getcommand(const struct order * ord); extern boolean is_persistent(const struct order *ord); extern boolean is_exclusive(const struct order *ord); +extern boolean is_repeated(const order * ord); + extern char * write_order(const struct order * ord, const struct locale * lang, char * buffer, size_t size); #ifdef __cplusplus } diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index fd285c434..c927bf758 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -179,12 +179,13 @@ bufunit(const faction * f, const unit * u, int indent, int mode) item * itm; item * show; faction *fv = visible_faction(f, u); + char * bufp = buf; if (fspecial(u->faction, FS_HIDDEN)) a_fshidden = a_find(u->attribs, &at_fshidden); - strcpy(buf, unitname(u)); - + strcpy(bufp, unitname(u)); + bufp += strlen(bufp); if (!isbattle) { attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction); @@ -192,21 +193,27 @@ bufunit(const faction * f, const unit * u, int indent, int mode) attrib *a = a_find(u->attribs, &at_group); if (a) { group * g = (group*)a->data.v; - scat(", "); - scat(groupid(g, f)); + strcat(bufp, ", "); + strcat(bufp + 2, groupid(g, f)); + bufp += strlen(bufp); } if (getarnt) { - scat(", "); scat(LOC(f->locale, "anonymous")); + strcat(bufp, ", "); + strcat(bufp + 2, LOC(f->locale, "anonymous")); + bufp += 2 + strlen(bufp); } else if (a_otherfaction) { faction * otherfaction = get_otherfaction(a_otherfaction); if (otherfaction) { - scat(", "); - scat(factionname(otherfaction)); + strcat(bufp, ", "); + strcat(bufp + 2, factionname(otherfaction)); + bufp += 2 + strlen(bufp); } } } else { if (getarnt) { - scat(", "); scat(LOC(f->locale, "anonymous")); + strcat(bufp, ", "); + strcat(bufp + 2, LOC(f->locale, "anonymous")); + bufp += 2 + strlen(bufp); } else { scat(", "); if(a_otherfaction diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index a2e3ed95b..0e720f2ff 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -479,7 +479,24 @@ unitorders(FILE * F, struct faction * f) printf(",_%4s_", itoa36(u->no)); fflush(stdout); } - free_orders(&u->orders); + + if (!fval(u, UFL_ORDERS)) { + /* alle wiederholbaren, langen befehle werden gesichert: */ + fset(u, UFL_ORDERS); + u->old_orders = u->orders; + ordp = &u->old_orders; + while (*ordp) { + order * ord = *ordp; + if (!is_repeated(ord)) { + ordp = &ord->next; + free_order(ord); + } else { + ordp = &ord->next; + } + } + } else { + free_orders(&u->orders); + } u->orders = 0; ordp = &u->orders; @@ -1221,6 +1238,12 @@ writeunit(FILE * F, const unit * u) wi(F, u->status); wi(F, u->flags & UFL_SAVEMASK); wnl(F); +#ifndef LASTORDER + for (ord = u->old_orders; ord; ord=ord->next) { + fwriteorder(F, ord, u->faction->locale); + fputc(' ', F); + } +#endif for (ord = u->orders; ord; ord=ord->next) { if (is_persistent(ord)) { fwriteorder(F, ord, u->faction->locale); diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index 2bc7e0610..4553f8ead 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -50,7 +50,7 @@ struct skill; #define UFL_TRADER (1<<20) /* Händler, pseudolang */ #define UFL_NOAID (1<<22) /* Einheit hat Noaid-Status */ - +#define UFL_ORDERS (1<<24) /* Einheit hat Befehle erhalten */ #define UFL_TAKEALL (1<<25) /* Einheit nimmt alle Gegenstände an */ /* Flags, die gespeichert werden sollen: */ @@ -92,10 +92,12 @@ typedef struct unit { } * reservations; /* orders */ - struct order *orders; + struct order * orders; struct order * thisorder; #ifdef LASTORDER struct order * lastorder; +#else + struct order * old_orders; #endif /* race and illusionary race */ diff --git a/src/common/util/log.c b/src/common/util/log.c index dcef41cf0..6f93a2a6d 100644 --- a/src/common/util/log.c +++ b/src/common/util/log.c @@ -30,6 +30,7 @@ log_flush(void) void log_puts(const char * str) { + fflush(stdout); if (!logfile) logfile = stderr; fputs(str, logfile); } @@ -78,6 +79,7 @@ void _log_warn(const char * format, ...) { va_list marker; + fflush(stdout); if (!logfile) logfile = stderr; fputs("WARNING: ", logfile); va_start(marker, format); @@ -100,6 +102,7 @@ void _log_error(const char * format, ...) { va_list marker; + fflush(stdout); if (!logfile) logfile = stderr; fputs("ERROR: ", logfile); @@ -114,13 +117,14 @@ _log_error(const char * format, ...) va_end(marker); } log_flush(); - } } +} void _log_info(unsigned int flag, const char * format, ...) { va_list marker; + fflush(stdout); if (!logfile) logfile = stderr; fprintf(logfile, "INFO[%u]: ", flag);