server/src/common/gamecode/report.c

3281 lines
77 KiB
C
Raw Normal View History

2001-01-25 10:37:55 +01:00
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2003
2001-01-25 10:37:55 +01:00
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
#define INDENT 0
#include <config.h>
2001-02-10 11:40:12 +01:00
#include <eressea.h>
2001-01-25 10:37:55 +01:00
2001-02-10 11:40:12 +01:00
/* modules includes */
2001-01-25 10:37:55 +01:00
#include <modules/score.h>
2001-02-10 11:40:12 +01:00
/* attributes includes */
#include <attributes/overrideroads.h>
#include <attributes/viewrange.h>
#include <attributes/otherfaction.h>
2005-10-23 13:27:55 +02:00
#include <attributes/alliance.h>
#ifdef AT_OPTION
# include <attributes/option.h>
#endif
2001-02-10 11:40:12 +01:00
/* gamecode includes */
2001-04-26 19:41:06 +02:00
#include "creport.h"
2001-02-10 11:40:12 +01:00
#include "economy.h"
#include "monster.h"
#include "laws.h"
/* kernel includes */
2004-06-21 18:45:27 +02:00
#include <kernel/alchemy.h>
#include <kernel/alliance.h>
2004-06-21 18:45:27 +02:00
#include <kernel/border.h>
#include <kernel/build.h>
#include <kernel/building.h>
#include <kernel/calendar.h>
2004-06-21 18:45:27 +02:00
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
#include <kernel/karma.h>
#include <kernel/message.h>
#include <kernel/movement.h>
#include <kernel/objtypes.h>
#include <kernel/order.h>
#include <kernel/plane.h>
#include <kernel/pool.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/render.h>
#include <kernel/reports.h>
#include <kernel/resources.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/skill.h>
#include <kernel/teleport.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>
2004-06-21 18:45:27 +02:00
#include <kernel/unit.h>
2005-10-23 13:27:55 +02:00
#include <kernel/alliance.h>
#ifdef USE_UGROUPS
# include <ugroup.h>
#endif
2001-02-10 11:40:12 +01:00
2001-01-25 10:37:55 +01:00
/* util includes */
#include <util/bsdstring.h>
2001-02-10 11:40:12 +01:00
#include <goodies.h>
2001-01-25 10:37:55 +01:00
#include <base36.h>
#include <nrmessage.h>
#include <translation.h>
#include <util/message.h>
#include <log.h>
2001-01-25 10:37:55 +01:00
/* libc includes */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
2001-01-25 10:37:55 +01:00
#include <string.h>
#include <stdio.h>
2001-04-26 19:41:06 +02:00
#include <time.h>
2001-01-25 10:37:55 +01:00
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#ifdef HAVE_STAT
#include <sys/types.h>
#include <sys/stat.h>
#endif
2001-01-25 10:37:55 +01:00
extern int quiet;
extern int *storms;
extern int weeks_per_month;
extern int months_per_year;
2001-01-25 10:37:55 +01:00
boolean nocr = false;
boolean nonr = false;
boolean nosh = false;
2001-01-25 10:37:55 +01:00
boolean nomer = false;
boolean noreports = false;
2001-01-25 10:37:55 +01:00
2005-05-05 02:12:54 +02:00
static size_t
strxcpy(char * dst, const char * src) {
2005-05-05 02:12:54 +02:00
size_t s = 0;
while ((*dst++ = *src++)!=0) ++s;
return s;
}
int
read_datenames(const char *filename)
2001-01-25 10:37:55 +01:00
{
FILE *namesFP;
char line[256];
int i;
size_t l;
2001-01-25 10:37:55 +01:00
if( (namesFP=fopen(filename,"r")) == NULL) {
log_error(("Kann Datei '%s' nicht <20>ffnen, Abbruch\n", filename));
return -1;
2001-01-25 10:37:55 +01:00
}
fgets(line,255,namesFP);
l = strlen(line)-1;
if(line[l] == '\n') line[l] = 0;
agename = strdup(mkname("calendar", line));
2001-01-25 10:37:55 +01:00
fgets(line,255,namesFP);
seasons = strtol(line, NULL, 10);
seasonnames = malloc(sizeof(char *) * seasons);
for (i=0;i<seasons;i++) {
2001-01-25 10:37:55 +01:00
fgets(line,255,namesFP);
l = strlen(line)-1;
if(line[l] == '\n') line[l] = 0;
seasonnames[i] = strdup(mkname("calendar", line));
2001-01-25 10:37:55 +01:00
}
fgets(line,255,namesFP);
weeks_per_month = strtol(line, NULL, 10);
weeknames = malloc(sizeof(char *) * weeks_per_month);
weeknames2 = malloc(sizeof(char *) * weeks_per_month);
for(i=0;i<weeks_per_month;i++) {
char * np;
fgets(line,255,namesFP);
l = strlen(line)-1;
if(line[l] == '\n') line[l] = 0;
np = strtok(line,":");
weeknames[i] = strdup(mkname("calendar", np));
2001-01-25 10:37:55 +01:00
np = strtok(NULL,":");
weeknames2[i] = strdup(mkname("calendar", np));
2001-01-25 10:37:55 +01:00
}
fgets(line,255,namesFP);
months_per_year = strtol(line, NULL, 10);
monthnames = malloc(sizeof(char *) * months_per_year);
month_season = malloc(sizeof(int) * months_per_year);
2001-01-25 10:37:55 +01:00
storms = malloc(sizeof(int) * months_per_year);
for(i=0;i<months_per_year;i++) {
char * np;
fgets(line,255,namesFP);
l = strlen(line)-1;
if(line[l] == '\n') line[l] = 0;
np = strtok(line,":");
monthnames[i] = strdup(mkname("calendar", np));
month_season[i] = atoi(strtok(NULL,":"));
2001-01-25 10:37:55 +01:00
storms[i] = atoi(strtok(NULL,":"));
}
fclose(namesFP);
return 0;
2001-01-25 10:37:55 +01:00
}
static char *
gamedate_season(const struct locale * lang)
{
static char buf[256];
gamedate gd;
get_gamedate(turn, &gd);
sprintf(buf, LOC(lang, "nr_calendar_season"),
LOC(lang, weeknames[gd.week]),
LOC(lang, monthnames[gd.month]),
gd.year,
LOC(lang, agename),
LOC(lang, seasonnames[gd.season]));
return buf;
}
static char *
gamedate2(const struct locale * lang)
2001-01-25 10:37:55 +01:00
{
static char buf[256];
gamedate gd;
get_gamedate(turn, &gd);
sprintf(buf, "in %s des Monats %s im Jahre %d %s.",
LOC(lang, weeknames2[gd.week]),
LOC(lang, monthnames[gd.month]),
gd.year,
LOC(lang, agename));
return buf;
2001-01-25 10:37:55 +01:00
}
static void
rpsnr(FILE * F, const char * s, int offset)
{
char inset[REPORTWIDTH];
const char *l, *x = s;
char ui=0;
size_t indent = 0, len;
len = strlen(s);
while (*x++ == ' ');
indent = x - s - 1;
if (*(x - 1) && indent && *x == ' ') indent += 2;
if (!indent) indent = offset;
x = s;
memset(inset, 32, indent * sizeof(char));
inset[indent] = 0;
while (s <= x+len) {
size_t line = min(len-(s-x), REPORTWIDTH - indent*ui);
char * br = strchr(s, '\n');
l = s + line;
if(br && br < l) {
l = br;
} else {
if (*l) {
while (*l!=' ' && l!=s) --l;
/* wenn nicht gefunden, harte breaks: */
if (s == l) l = s + REPORTWIDTH - indent;
}
}
if (*s) {
#if INDENT
putc(' ', F);
#endif
if (s!=x) {
fputs(inset, F);
}
fwrite(s, sizeof(char), l-s, F);
putc('\n', F);
}
s = l+1; ui=1;
}
}
int outi;
char outbuf[4096];
void
rpc(FILE * F, char c, size_t num)
{
while(num > 0) {
putc(c, F);
num--;
}
}
void
rnl(FILE * F)
{
int i;
int rc, vc;
i = outi;
assert(i < 4096);
while (i && isspace((int)outbuf[i - 1]))
i--;
outbuf[i] = 0;
i = 0;
rc = 0;
vc = 0;
while (outbuf[i]) {
switch (outbuf[i]) {
case ' ':
vc++;
break;
case '\t':
vc = (vc & ~7) + 8;
break;
default:
/* ER: Tabs in Reports sind Mist. Die versauen die *
* Anzeige von Einheiten in Burgen und Schiffen. while
* (rc / 8 != vc / 8) { if ((rc & 7) == 7) putc(' ',
* F); else putc('\t', F); rc = (rc & ~7) + 8; } */
while (rc != vc) {
putc(' ', F);
rc++;
}
putc(outbuf[i], F);
rc++;
vc++;
}
i++;
assert(i < 4096);
}
putc('\n', F);
outi = 0;
}
static void
rps(FILE * F, const char * src)
{
rpsnr(F, src, 0);
2001-01-25 10:37:55 +01:00
}
static void
centre(FILE * F, const char *s, boolean breaking)
{
/* Bei Namen die genau 80 Zeichen lang sind, kann es hier Probleme
* geben. Seltsamerweise wird i dann auf MAXINT oder aehnlich
* initialisiert. Deswegen keine Strings die laenger als REPORTWIDTH
* sind! */
if (breaking && REPORTWIDTH < strlen(s)) {
strlist *T, *SP = 0;
sparagraph(&SP, s, 0, 0);
T = SP;
while (SP) {
centre(F, SP->s, false);
SP = SP->next;
}
freestrlist(T);
} else {
rpc(F, ' ', (REPORTWIDTH - strlen(s)+1) / 2);
fputs(s, F);
putc('\n', F);
}
}
static void
rparagraph(FILE *F, const char *s, int indent, char mark)
{
static char mbuf[BUFSIZE+1];
/* static size_t bsize = 0; */
size_t size;
char inset[REPORTWIDTH];
if (indent) {
memset(inset, ' ', indent);
inset[indent]=0;
if (mark)
inset[indent - 2] = mark;
} else {
assert(mark == 0);
inset[0] = 0;
}
inset[indent]=0;
size = strlen(s)+indent+1;
if (size==1) return;
strcpy(mbuf, inset);
strncpy(mbuf+indent, s, BUFSIZE-indent);
*(mbuf+size-1)=0;
rps(F, mbuf);
}
static void
report_spell(FILE * F, spell *sp, const struct locale * lang)
2001-01-25 10:37:55 +01:00
{
int k, itemanz, costtyp;
2001-01-25 10:37:55 +01:00
int dh = 0;
2005-05-05 02:12:54 +02:00
char * bufp;
2001-01-25 10:37:55 +01:00
rnl(F);
centre(F, spell_name(sp, lang), true);
2001-01-25 10:37:55 +01:00
rnl(F);
strcpy(buf,"Beschreibung:");
rps(F, buf);
rparagraph(F, spell_info(sp, lang), 0, 0);
2001-01-25 10:37:55 +01:00
rnl(F);
2005-05-05 02:12:54 +02:00
bufp = strcpy(buf, "Art: ");
2001-01-25 10:37:55 +01:00
if (sp->sptyp & PRECOMBATSPELL) {
bufp += strxcpy(bufp, "Pr<EFBFBD>kampfzauber");
2001-01-25 10:37:55 +01:00
} else if (sp->sptyp & COMBATSPELL) {
bufp += strxcpy(bufp, "Kampfzauber");
2001-01-25 10:37:55 +01:00
} else if (sp->sptyp & POSTCOMBATSPELL) {
bufp += strxcpy(bufp, "Postkampfzauber");
2001-01-25 10:37:55 +01:00
} else {
bufp += strxcpy(bufp, "Normaler Zauber");
2001-01-25 10:37:55 +01:00
}
rps(F, buf);
strcpy(buf, "Komponenten:");
rps(F, buf);
for (k = 0; sp->components[k].type; ++k) {
const resource_type * rtype = sp->components[k].type;
itemanz = sp->components[k].amount;
costtyp = sp->components[k].cost;
if (itemanz > 0){
if (sp->sptyp & SPELLLEVEL) {
bufp = buf + sprintf(buf, " %d %s", itemanz, LOC(lang, resourcename(rtype, itemanz!=1)));
if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR ) {
bufp += strxcpy(bufp, " * Stufe");
}
} else {
if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR ) {
itemanz *= sp->level;
}
sprintf(buf, " %d %s", itemanz, LOC(lang, resourcename(rtype, itemanz!=1)));
}
2001-01-25 10:37:55 +01:00
rps(F, buf);
}
}
bufp = buf + strxcpy(buf, "Modifikationen: ");
2001-01-25 10:37:55 +01:00
if (sp->sptyp & FARCASTING) {
bufp += strxcpy(bufp, "Fernzauber");
2001-01-25 10:37:55 +01:00
dh = 1;
}
if (sp->sptyp & OCEANCASTABLE) {
if (dh == 1){
bufp += strxcpy(bufp, ", ");
2001-01-25 10:37:55 +01:00
}
bufp += strxcpy(bufp, "Seezauber");
2001-01-25 10:37:55 +01:00
dh = 1;
}
if (sp->sptyp & ONSHIPCAST) {
if (dh == 1){
bufp += strxcpy(bufp, ", ");
2001-01-25 10:37:55 +01:00
}
bufp += strxcpy(bufp, "Schiffszauber");
2001-01-25 10:37:55 +01:00
dh = 1;
}
if (sp->sptyp & NOTFAMILIARCAST) {
if (dh == 1){
bufp += strxcpy(bufp, ", k");
2001-01-25 10:37:55 +01:00
} else {
bufp += strxcpy(bufp, "K");
2001-01-25 10:37:55 +01:00
}
bufp += strxcpy(bufp, "ann nicht vom Vertrauten gezaubert werden");
2001-01-25 10:37:55 +01:00
dh = 1;
}
if(dh == 0) bufp += strxcpy(bufp, "Keine");
2001-01-25 10:37:55 +01:00
rps(F, buf);
sprintf(buf, "Stufe: %d", sp->level);
rps(F, buf);
sprintf(buf, "Rang: %d", sp->rank);
rps(F, buf);
rnl(F);
2005-05-05 02:12:54 +02:00
strcpy(buf, "Syntax: ");
2001-01-25 10:37:55 +01:00
rps(F, buf);
2005-05-05 02:12:54 +02:00
if (!sp->syntax) {
if (sp->sptyp & ISCOMBATSPELL) {
bufp = buf + strxcpy(buf, "KAMPFZAUBER ");
2005-05-05 02:12:54 +02:00
} else {
bufp = buf + strxcpy(buf, "ZAUBERE ");
2001-01-25 10:37:55 +01:00
}
/* Reihenfolge beachten: Erst REGION, dann STUFE! */
if (sp->sptyp & FARCASTING) {
bufp += strxcpy(bufp, "[REGION x y] ");
2001-01-25 10:37:55 +01:00
}
if (sp->sptyp & SPELLLEVEL) {
bufp += strxcpy(bufp, "[STUFE n] ");
2001-01-25 10:37:55 +01:00
}
bufp += strxcpy(bufp, "\"");
bufp += strxcpy(bufp, spell_name(sp, lang));
bufp += strxcpy(bufp, "\" ");
2001-01-25 10:37:55 +01:00
if (sp->sptyp & ONETARGET){
if (sp->sptyp & UNITSPELL) {
bufp += strxcpy(bufp, "<Einheit-Nr>");
2001-01-25 10:37:55 +01:00
} else if (sp->sptyp & SHIPSPELL) {
bufp += strxcpy(bufp, "<Schiff-Nr>");
2001-01-25 10:37:55 +01:00
} else if (sp->sptyp & BUILDINGSPELL) {
bufp += strxcpy(bufp, "<Geb<65>ude-Nr>");
2001-01-25 10:37:55 +01:00
}
2005-05-05 02:12:54 +02:00
} else {
2001-01-25 10:37:55 +01:00
if (sp->sptyp & UNITSPELL) {
bufp += strxcpy(bufp, "<Einheit-Nr> [<Einheit-Nr> ...]");
2001-01-25 10:37:55 +01:00
} else if (sp->sptyp & SHIPSPELL) {
bufp += strxcpy(bufp, "<Schiff-Nr> [<Schiff-Nr> ...]");
2001-01-25 10:37:55 +01:00
} else if (sp->sptyp & BUILDINGSPELL) {
bufp += strxcpy(bufp, "<Geb<65>ude-Nr> [<Geb<65>ude-Nr> ...]");
2001-01-25 10:37:55 +01:00
}
}
2005-05-05 02:12:54 +02:00
} else {
bufp = buf + strxcpy(buf, sp->syntax);
2001-01-25 10:37:55 +01:00
}
rps(F, buf);
rnl(F);
}
void
sparagraph(strlist ** SP, const char *s, int indent, char mark)
{
/* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer
* mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf.
* Vgl. spunit (). */
int i, j, width;
int firstline;
static char buf[REPORTWIDTH + 1];
width = REPORTWIDTH - indent;
firstline = 1;
for (;;) {
i = 0;
do {
j = i;
while (s[j] && s[j] != ' ')
j++;
if (j > width) {
/* j zeigt auf das ende der aktuellen zeile, i zeigt auf den anfang der
* n<EFBFBD>chsten zeile. existiert ein wort am anfang der zeile, welches
* l<EFBFBD>nger als eine zeile ist, mu<EFBFBD> dieses hier abgetrennt werden. */
if (i == 0)
i = width - 1;
break;
}
i = j + 1;
}
while (s[j]);
for (j = 0; j != indent; j++)
buf[j] = ' ';
if (firstline && mark)
buf[indent - 2] = mark;
for (j = 0; j != i - 1; j++)
buf[indent + j] = s[j];
buf[indent + j] = 0;
addstrlist(SP, buf);
if (s[i - 1] == 0)
break;
s += i;
firstline = 0;
}
}
int
hat_in_region(item_t it, region * r, faction * f)
{
unit *u;
for (u = r->units; u; u = u->next) {
if (u->faction == f && get_item(u, it) > 0) {
return 1;
}
}
return 0;
}
static void
2002-05-10 18:49:31 +02:00
print_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int indent)
2001-01-25 10:37:55 +01:00
{
attrib *a = NULL;
int self = 0;
region *r;
/* Die Sichtbarkeit eines Zaubers und die Zaubermeldung sind bei
* Geb<EFBFBD>uden und Schiffen je nach, ob man Besitzer ist, verschieden.
* Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer.
* Spezialf<EFBFBD>lle (besonderes Talent, verursachender Magier usw. werde
* bei jedem curse gesondert behandelt. */
if (typ == TYP_SHIP){
ship * sh = (ship*)obj;
2004-06-21 18:45:27 +02:00
unit * owner = shipowner(sh);
a = sh->attribs;
r = sh->region;
2004-06-21 18:45:27 +02:00
if((owner) != NULL){
if (owner->faction == viewer){
self = 2;
} else { /* steht eine person der Partei auf dem Schiff? */
unit *u = NULL;
for (u = r->units; u; u = u->next) {
if (u->ship == sh) {
self = 1;
break;
}
}
}
}
} else if (typ == TYP_BUILDING) {
building * b = (building*)obj;
unit * owner;
a = b->attribs;
r = b->region;
if((owner = buildingowner(r,b)) != NULL){
if (owner->faction == viewer){
self = 2;
} else { /* steht eine Person der Partei in der Burg? */
unit *u = NULL;
for (u = r->units; u; u = u->next) {
if (u->building == b) {
self = 1;
break;
}
}
}
}
} else if (typ == TYP_UNIT) {
unit *u = (unit *)obj;
a = u->attribs;
r = u->region;
if (u->faction == viewer){
self = 2;
}
} else if (typ == TYP_REGION) {
r = (region *)obj;
a = r->attribs;
} else {
/* fehler */
}
2001-01-25 10:37:55 +01:00
for(;a;a=a->next) {
int dh = 0;
if (fval(a->type, ATF_CURSE)) {
curse *c = (curse *)a->data.v;
if (c->type->curseinfo) {
2002-05-11 22:38:34 +02:00
if (c->type->cansee) {
2002-05-11 19:08:54 +02:00
self = c->type->cansee(viewer, obj, typ, c, self);
}
dh = c->type->curseinfo(viewer->locale, obj, typ, c, self);
}
2001-01-25 10:37:55 +01:00
if (dh == 1) {
rnl(F);
rparagraph(F, buf, indent, 0);
}
} else if (a->type==&at_effect && self) {
effect_data * data = (effect_data *)a->data.v;
sprintf(buf, "Auf der Einheit lieg%s %d Wirkung%s %s.",
2001-01-25 10:37:55 +01:00
(data->value==1 ? "t" : "en"),
data->value,
2001-01-25 10:37:55 +01:00
(data->value==1 ? "" : "en"),
2001-05-27 12:11:36 +02:00
LOC(default_locale, resourcename(data->type->itype->rtype, 0)));
2001-01-25 10:37:55 +01:00
rnl(F);
rparagraph(F, buf, indent, 0);
}
}
}
static void
rps_nowrap(FILE * F, const char *s)
{
const char *x = s;
size_t indent = 0;
2001-01-25 10:37:55 +01:00
while (*x++ == ' ');
indent = x - s - 1;
if (*(x - 1) && indent && *x == ' ')
indent += 2;
x = s;
while (*s) {
if (s == x) {
x = strchr(x + 1, ' ');
if (!x)
x = s + strlen(s);
}
rpc(F, *s++, 1);
}
}
static void
rpunit(FILE * F, const faction * f, const unit * u, int indent, int mode)
{
attrib *a_otherfaction;
char marker;
2001-01-25 10:37:55 +01:00
int dh;
boolean isbattle = (boolean)(mode == see_battle);
#ifdef USE_UGROUPS
2001-04-28 17:39:13 +02:00
ugroup *ug = findugroup(u);
#endif
if(u->race == new_race[RC_SPELL]) return;
2001-01-25 10:37:55 +01:00
#ifdef USE_UGROUPS
if(u->faction != f && (isbattle || ug)) {
2001-04-28 17:39:13 +02:00
if(is_ugroupleader(u, ug)) {
rnl(F);
dh = bufunit_ugroupleader(f, u, indent, mode);
} else {
return;
}
} else
#endif
{
2001-04-28 17:39:13 +02:00
rnl(F);
dh = bufunit(f, u, indent, mode);
}
a_otherfaction = a_find(u->attribs, &at_otherfaction);
if(u->faction == f) {
marker = '*';
} else {
2002-03-24 10:40:50 +01:00
if(a_otherfaction && f != u->faction && get_otherfaction(a_otherfaction) == f
&& !fval(u, UFL_PARTEITARNUNG)) {
marker = '!';
} else {
if(dh && !fval(u, UFL_PARTEITARNUNG)) {
marker = '+';
} else {
marker = '-';
}
}
}
rparagraph(F, buf, indent, marker);
2001-04-28 17:39:13 +02:00
2001-01-25 10:37:55 +01:00
if(!isbattle){
#ifdef USE_UGROUPS
2001-04-28 17:39:13 +02:00
if(ug) {
int i;
for(i=0; i<ug->members; i++) {
2002-05-10 18:49:31 +02:00
print_curses(F, f, ug->unit_array[i], TYP_UNIT, indent);
2001-04-28 17:39:13 +02:00
}
2001-05-18 09:06:47 +02:00
} else
#endif /* USE_UGROUPS */
print_curses(F, f, u, TYP_UNIT, indent);
2001-01-25 10:37:55 +01:00
}
}
static void
rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, boolean centered, boolean categorized)
2001-01-25 10:37:55 +01:00
{
messageclass * category;
if (!msgs) return;
for (category=msgclasses; category; category=category->next) {
int k = 0;
struct mlist * m = msgs->begin;
while (m) {
2001-01-25 10:37:55 +01:00
#ifdef MSG_LEVELS
if (!debug && get_msglevel(viewer->warnings, viewer->msglevels, m->type) < m->level) continue;
#endif
/* messagetype * mt = m->type; */
if (strcmp(nr_section(m->msg), category->name)==0)
{
char lbuf[8192], *bufp = lbuf;
size_t rsize, size = sizeof(lbuf);
2001-01-25 10:37:55 +01:00
if (!k && categorized) {
const char * name;
char cat_identifier[24];
sprintf(cat_identifier, "section_%s", category->name);
name = LOC(viewer->locale, cat_identifier);
2001-01-25 10:37:55 +01:00
k = 1;
rnl(F);
if (centered) centre(F, name, true);
else {
if (indent>0) strcpy(lbuf, " ");
strcpy(lbuf+indent, name);
rpsnr(F, lbuf, 2);
2001-01-25 10:37:55 +01:00
}
rnl(F);
}
if (indent>0) {
rsize = strlcpy(lbuf, " ", indent);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
2005-06-19 11:01:00 +02:00
}
rsize = nr_render(m->msg, viewer->locale, bufp, size, viewer);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
2005-06-19 11:01:00 +02:00
rpsnr(F, lbuf, 2);
2001-01-25 10:37:55 +01:00
}
m = m->next;
2001-01-25 10:37:55 +01:00
}
}
}
static void
rp_battles(FILE * F, faction * f)
{
if (f->battles!=NULL) {
2005-06-19 12:22:51 +02:00
struct bmsg * bm = f->battles;
rnl(F);
centre(F, LOC(f->locale, "section_battle"), false);
rnl(F);
2005-06-11 10:09:55 +02:00
2005-06-19 12:22:51 +02:00
while (bm) {
RENDER(f, buf, 80, ("battle::header", "region", bm->r));
rnl(F);
centre(F, buf, true);
rnl(F);
rp_messages(F, bm->msgs, f, 0, true, false);
2005-06-19 12:22:51 +02:00
bm = bm->next;
}
}
}
2001-01-25 10:37:55 +01:00
char *
f_regionid(const region * r, const faction * f)
{
static int i = 0;
static char bufs[4][NAMESIZE + 20];
char * buf = bufs[(++i)%4];
plane *pl = NULL;
if (!r)
strcpy(buf, "(Chaos)");
else {
pl = getplane(r);
if(pl && fval(pl,PFL_NOCOORDS)) {
strncpy(buf, rname(r, f->locale), NAMESIZE);
buf[NAMESIZE]=0;
2001-01-25 10:37:55 +01:00
} else {
strncpy(buf, rname(r, f->locale), NAMESIZE);
buf[NAMESIZE]=0;
sprintf(buf+strlen(buf), " (%d,%d%s%s)", region_x(r,f), region_y(r,f), pl?",":"", pl?pl->name:"");
}
2001-01-25 10:37:55 +01:00
}
return buf;
}
static void
prices(FILE * F, const region * r, const faction * f)
2001-01-25 10:37:55 +01:00
{
const luxury_type *sale=NULL;
struct demand * dmd;
message * m;
int n = 0;
2001-01-25 10:37:55 +01:00
if (r->land==NULL || r->land->demands==NULL) return;
for (dmd=r->land->demands;dmd;dmd=dmd->next) {
if (dmd->value==0) sale = dmd->type;
else if (dmd->value > 0) n++;
2001-01-25 10:37:55 +01:00
}
assert(sale!=NULL);
m = msg_message("nr_market_sale", "product price",
sale->itype->rtype, sale->price);
nr_render(m, f->locale, buf, sizeof(buf), f);
2005-05-05 02:12:54 +02:00
msg_release(m);
2001-01-25 10:37:55 +01:00
2005-05-05 02:12:54 +02:00
if (n > 0) {
char * bufp = buf + strlen(buf);
bufp += strxcpy(bufp, " ");
bufp += strxcpy(bufp, LOC(f->locale, "nr_trade_intro"));
bufp += strxcpy(bufp, " ");
2001-01-25 10:37:55 +01:00
for (dmd=r->land->demands;dmd;dmd=dmd->next) if(dmd->value > 0) {
m = msg_message("nr_market_price", "product price",
dmd->type->itype->rtype, dmd->value * dmd->type->price);
2005-05-05 02:12:54 +02:00
nr_render(m, f->locale, bufp, sizeof(buf)-(bufp-buf), f);
msg_release(m);
n--;
2005-05-05 02:12:54 +02:00
bufp += strlen(bufp);
if (n == 0) {
bufp += strxcpy(bufp, LOC(f->locale, "nr_trade_end"));
2005-05-05 02:12:54 +02:00
}
else if (n == 1) {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, "nr_trade_final"));
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
} else {
bufp += strxcpy(bufp, LOC(f->locale, "nr_trade_next"));
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
}
}
2001-01-25 10:37:55 +01:00
}
/* Schreibe Paragraphen */
rparagraph(F, buf, 0, 0);
}
boolean
see_border(const border * b, const faction * f, const region * r)
2001-01-25 10:37:55 +01:00
{
boolean cs = b->type->fvisible(b, f, r);
if (!cs) {
cs = b->type->rvisible(b, r);
if (!cs) {
const unit * us = r->units;
2001-01-25 10:37:55 +01:00
while (us && !cs) {
if (us->faction==f) {
cs = b->type->uvisible(b, us);
if (cs) break;
}
us=us->next;
}
}
}
return cs;
}
const char *
2002-09-02 22:36:12 +02:00
trailinto(const region * r, const struct locale * lang)
{
char ref[32];
const char * s;
if (r) {
const char * tname;
if (is_cursed(r->attribs, C_MAELSTROM, 0)) {
/* das kostet. evtl. w<>re ein FL_CURSED gut? */
tname = "maelstrom";
} else {
tname = terrain_name(r);
}
strcat(strcpy(ref, tname), "_trail");
s = locale_string(lang, ref);
if (s && *s) {
if (strstr(s, "%s")) return s;
}
}
return "%s";
}
static void
eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int */
{
const struct faction * f = (const struct faction *)userdata;
const struct locale * lang = (const struct locale*)opop(stack).v;
const struct region * r = (const struct region*)opop(stack).v;
const char * trail = trailinto(r, lang);
const char * rn = f_regionid(r, f);
variant var;
char * x = var.v = balloc(strlen(trail)+strlen(rn));
sprintf(x, trail, rn);
opush(stack, var);
}
2001-01-25 10:37:55 +01:00
static void
describe(FILE * F, const region * r, int partial, faction * f)
2001-01-25 10:37:55 +01:00
{
int n;
boolean dh;
direction_t d;
int trees;
int ytrees;
2001-01-25 10:37:55 +01:00
attrib *a;
const char *tname;
struct edge {
struct edge * next;
char * name;
boolean transparent;
boolean block;
boolean exist[MAXDIRECTIONS];
direction_t lastd;
} * edges = NULL, * e;
boolean see[MAXDIRECTIONS];
2005-05-05 02:12:54 +02:00
char * bufp = buf;
2001-01-25 10:37:55 +01:00
2005-05-05 02:12:54 +02:00
for (d = 0; d != MAXDIRECTIONS; d++) {
/* Nachbarregionen, die gesehen werden, ermitteln */
2001-01-25 10:37:55 +01:00
region *r2 = rconnect(r, d);
border *b;
see[d] = true;
if (!r2) continue;
for (b=get_borders(r, r2);b;) {
struct edge * e = edges;
boolean transparent = b->type->transparent(b, f);
const char * name = b->type->name(b, r, f, GF_DETAILED|GF_ARTICLE);
if (!transparent) see[d] = false;
if (!see_border(b, f, r)) {
b = b->next;
continue;
}
while (e && (e->transparent != transparent || strcmp(name,e->name))) e = e->next;
if (!e) {
e = calloc(sizeof(struct edge), 1);
e->name = strdup(name);
e->transparent = transparent;
e->next = edges;
edges = e;
}
e->lastd=d;
e->exist[d] = true;
b = b->next;
}
}
bufp += strxcpy(bufp, f_regionid(r, f));
2001-01-25 10:37:55 +01:00
if (partial == 1) {
bufp += strxcpy(bufp, " (durchgereist)");
2001-01-25 10:37:55 +01:00
}
else if (partial == 3) {
bufp += strxcpy(bufp, " (benachbart)");
2001-01-25 10:37:55 +01:00
}
else if (partial == 2) {
bufp += strxcpy(bufp, " (vom Turm erblickt)");
2001-01-25 10:37:55 +01:00
}
/* Terrain */
bufp += strxcpy(bufp, ", ");
2001-01-25 10:37:55 +01:00
if(is_cursed(r->attribs,C_MAELSTROM, 0))
tname = "maelstrom";
else {
tname = terrain_name(r);
2001-01-25 10:37:55 +01:00
}
bufp += strxcpy(bufp, LOC(f->locale, tname));
2001-01-25 10:37:55 +01:00
/* B<>ume */
trees = rtrees(r,2);
ytrees = rtrees(r,1);
if (production(r)) {
2005-05-05 02:12:54 +02:00
if (trees > 0 || ytrees > 0) {
2005-05-05 05:19:35 +02:00
bufp += sprintf(bufp, ", %d/%d ", trees, ytrees);
if (fval(r, RF_MALLORN)) {
if (trees == 1)
bufp += strxcpy(bufp, LOC(f->locale, "nr_mallorntree"));
else
bufp += strxcpy(bufp, LOC(f->locale, "nr_mallorntree_p"));
}
else if (trees == 1)
bufp += strxcpy(bufp, LOC(f->locale, "nr_tree"));
else
bufp += strxcpy(bufp, LOC(f->locale, "nr_tree_p"));
}
}
2001-01-25 10:37:55 +01:00
/* iron & stone */
if (partial == 0 && f != (faction *) NULL) {
struct rawmaterial * res;
for (res=r->resources;res;res=res->next) {
int level = -1;
int visible = -1;
int maxskill = 0;
const item_type * itype = resource2item(res->type->rtype);
if (res->type->visible==NULL) {
visible = res->amount;
level = res->level + itype->construction->minskill - 1;
} else {
const unit * u;
for (u=r->units; visible!=res->amount && u!=NULL; u=u->next) {
if (u->faction == f) {
int s = eff_skill(u, itype->construction->skill, r);
if (s>maxskill) {
if (s>=itype->construction->minskill) {
level = res->level + itype->construction->minskill - 1;
}
maxskill = s;
visible = res->type->visible(res, maxskill);
}
}
}
}
if (level>=0 && visible >= 0) {
2005-05-05 02:12:54 +02:00
bufp += snprintf(bufp, sizeof(buf)-(bufp-buf), ", %d %s/%d",
visible, LOC(f->locale, res->type->name),
res->level + itype->construction->minskill - 1);
}
}
2001-01-25 10:37:55 +01:00
}
/* peasants & silver */
2001-01-25 10:37:55 +01:00
if (rpeasants(r)) {
int n = rpeasants(r);
bufp += sprintf(bufp, ", %d", n);
2001-01-25 10:37:55 +01:00
if(fval(r, RF_ORCIFIED)) {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, n==1?"rc_orc":"rc_orc_p"));
2001-01-25 10:37:55 +01:00
} else {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, n==1?"peasant":"peasant_p"));
2001-01-25 10:37:55 +01:00
}
if (rmoney(r) && partial == 0) {
2005-05-05 02:12:54 +02:00
bufp += sprintf(bufp, ", %d ", rmoney(r));
bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_SILVER], rmoney(r)!=1)));
2001-01-25 10:37:55 +01:00
}
}
/* Pferde */
if (rhorses(r)) {
2005-05-05 02:12:54 +02:00
bufp += sprintf(bufp, ", %d ", rhorses(r));
bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_HORSE], (rhorses(r)>1)?GR_PLURAL:0)));
2001-01-25 10:37:55 +01:00
}
2005-05-05 02:12:54 +02:00
strcpy(bufp++, ".");
2001-01-25 10:37:55 +01:00
if (r->display && r->display[0]) {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, r->display);
2001-01-25 10:37:55 +01:00
n = r->display[strlen(r->display) - 1];
if (n != '!' && n != '?' && n != '.')
2005-05-05 02:12:54 +02:00
strcpy(bufp++, ".");
2001-01-25 10:37:55 +01:00
}
{
const faction * owner = region_owner(r);
if (owner!=NULL) {
bufp += strxcpy(bufp, " Die Region ist im Besitz von ");
bufp += strxcpy(bufp, factionname(owner));
2005-05-05 02:12:54 +02:00
strcpy(bufp++, ".");
}
}
if (!is_cursed(r->attribs, C_REGCONF, 0)) {
2001-02-10 11:40:12 +01:00
attrib *a_do = a_find(r->attribs, &at_overrideroads);
2001-02-04 09:42:36 +01:00
if(a_do) {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, (char *)a_do->data.v);
2001-02-04 09:42:36 +01:00
} else {
int nrd = 0;
2001-02-04 09:42:36 +01:00
/* Nachbarregionen, die gesehen werden, ermitteln */
for (d = 0; d != MAXDIRECTIONS; d++)
if (see[d] && rconnect(r, d)) nrd++;
2001-02-04 09:42:36 +01:00
/* Richtungen aufz<66>hlen */
2001-02-04 09:42:36 +01:00
dh = false;
for (d = 0; d != MAXDIRECTIONS; d++) if (see[d]) {
region * r2 = rconnect(r, d);
if(!r2) continue;
nrd--;
if (dh) {
if (nrd == 0) {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, "nr_nb_final"));
} else {
bufp += strxcpy(bufp, LOC(f->locale, "nr_nb_next"));
}
bufp += strxcpy(bufp, LOC(f->locale, directions[d]));
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += sprintf(bufp, trailinto(r2, f->locale),
f_regionid(r2, f));
}
else {
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
MSG(("nr_vicinitystart", "dir region", d, r2), bufp, sizeof(buf)-(bufp-buf), f->locale, f);
2005-05-05 04:35:48 +02:00
bufp += strlen(bufp);
dh = true;
2001-02-04 09:42:36 +01:00
}
}
/* Spezielle Richtungen */
for (a = a_find(r->attribs, &at_direction);a;a = a->nexttype) {
spec_direction * d = (spec_direction *)(a->data.v);
2005-05-05 02:12:54 +02:00
strcpy(bufp++, " ");
bufp += strxcpy(bufp, d->desc);
bufp += strxcpy(bufp, " (\"");
bufp += strxcpy(bufp, d->keyword);
bufp += strxcpy(bufp, "\")");
2005-05-05 02:12:54 +02:00
strcpy(bufp++, ".");
2001-02-04 09:42:36 +01:00
dh = 1;
}
2001-01-25 10:37:55 +01:00
}
} else {
bufp += strxcpy(bufp, " Gro<72>e Verwirrung bef<65>llt alle Reisenden in dieser Region.");
2001-01-25 10:37:55 +01:00
}
2005-05-05 02:12:54 +02:00
rnl(F);
rparagraph(F, buf, 0, 0);
2001-01-25 10:37:55 +01:00
if (partial==0 && rplane(r) == get_astralplane() &&
2001-01-25 10:37:55 +01:00
!is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
/* Sonderbehandlung Teleport-Ebene */
region_list *rl = astralregions(r, inhabitable);
region_list *rl2;
2001-01-25 10:37:55 +01:00
if (rl) {
strcpy(buf, "Schemen der Regionen ");
rl2 = rl;
while(rl2) {
scat(f_regionid(rl2->data, f));
2001-01-25 10:37:55 +01:00
rl2 = rl2->next;
if(rl2) scat(", ");
}
scat(" sind erkennbar.");
free_regionlist(rl);
/* Schreibe Paragraphen */
rnl(F);
rparagraph(F, buf, 0, 0);
}
}
n = 0;
/* Wirkungen permanenter Spr<70>che */
print_curses(F, f, r, TYP_REGION,0);
2001-01-25 10:37:55 +01:00
/* Produktionsreduktion */
a = a_find(r->attribs, &at_reduceproduction);
if(a) {
sprintf(buf, "Die Region ist verw<72>stet, der Boden karg.");
rparagraph(F, buf, 0, 0);
}
if (edges) rnl(F);
for (e=edges;e;e=e->next) {
2005-05-05 05:19:35 +02:00
char * bufp = buf;
2001-01-25 10:37:55 +01:00
boolean first = true;
for (d=0;d!=MAXDIRECTIONS;++d) {
if (!e->exist[d]) continue;
if (first) bufp += strxcpy(bufp, "Im ");
2001-01-25 10:37:55 +01:00
else {
if (e->lastd==d) bufp += strxcpy(bufp, " und im ");
else bufp += strxcpy(bufp, ", im ");
2001-01-25 10:37:55 +01:00
}
bufp += strxcpy(bufp, LOC(f->locale, directions[d]));
2001-01-25 10:37:55 +01:00
first = false;
}
if (!e->transparent) bufp += strxcpy(bufp, " versperrt ");
else bufp += strxcpy(bufp, " befindet sich ");
bufp += strxcpy(bufp, e->name);
if (!e->transparent) bufp += strxcpy(bufp, " die Sicht.");
2005-05-05 02:12:54 +02:00
else strcpy(bufp++, ".");
2001-01-25 10:37:55 +01:00
rparagraph(F, buf, 0, 0);
}
if (edges) {
while (edges) {
e = edges->next;
free(edges->name);
free(edges);
edges = e;
}
}
}
static void
statistics(FILE * F, const region * r, const faction * f)
2001-01-25 10:37:55 +01:00
{
const unit *u;
int number, p;
message * m;
item *itm, *items = NULL;
p = rpeasants(r);
number = 0;
/* z<>hlen */
for (u = r->units; u; u = u->next)
if (u->faction == f && u->race != new_race[RC_SPELL]) {
for (itm=u->items;itm;itm=itm->next) {
i_change(&items, itm->type, itm->number);
}
number += u->number;
}
/* Ausgabe */
rnl(F);
m = msg_message("nr_stat_header", "region", r);
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
rnl(F);
2001-01-25 10:37:55 +01:00
/* Region */
if (fval(r->terrain, LAND_REGION) && rmoney(r)) {
2005-04-11 21:10:38 +02:00
m = msg_message("nr_stat_maxentertainment", "max", entertainmoney(r));
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
}
if (production(r) && (!fval(r->terrain, SEA_REGION) || f->race == new_race[RC_AQUARIAN])) {
m = msg_message("nr_stat_salary", "max", wage(r, f, f->race));
2005-04-11 21:10:38 +02:00
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
}
if (p) {
2005-04-11 21:10:38 +02:00
m = msg_message("nr_stat_recruits", "max", p / RECRUITFRACTION);
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
if (!TradeDisabled()) {
if (buildingtype_exists(r, bt_find("caravan"))) {
m = msg_message("nr_stat_luxuries", "max",
(p * 2) / TRADE_FRACTION);
} else {
m = msg_message("nr_stat_luxuries", "max",
p / TRADE_FRACTION);
}
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
2005-04-11 21:10:38 +02:00
}
}
/* Info <20>ber Einheiten */
2001-01-25 10:37:55 +01:00
2005-04-11 21:10:38 +02:00
m = msg_message("nr_stat_people", "max", number);
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
for (itm = items; itm; itm=itm->next) {
sprintf(buf, "%s: %d",
LOC(f->locale, resourcename(itm->type->rtype, GR_PLURAL)),
itm->number);
rps(F, buf);
}
while (items) i_free(i_remove(&items, items));
2001-01-25 10:37:55 +01:00
}
static void
durchreisende(FILE * F, const region * r, const faction * f)
2001-01-25 10:37:55 +01:00
{
attrib *ru;
int maxtravel;
2001-01-25 10:37:55 +01:00
int counter;
maxtravel = counter = 0;
2001-01-25 10:37:55 +01:00
/* Wieviele sind aufzulisten? F<>r die Grammatik. */
if (fval(r, RF_TRAVELUNIT)) {
for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) {
unit * u = (unit*)ru->data.v;
if (cansee_durchgezogen(f, r, u, 0) > 0 && r!=u->region) {
if (u->ship && !fval(u, UFL_OWNER))
continue;
maxtravel++;
}
}
2001-01-25 10:37:55 +01:00
if (!maxtravel)
return;
} else return;
2001-01-25 10:37:55 +01:00
/* Auflisten. */
buf[0] = 0;
rnl(F);
for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) {
unit * u = (unit*)ru->data.v;
if (cansee_durchgezogen(f, r, u, 0) > 0 && r!=u->region) {
if (u->ship && !fval(u, UFL_OWNER))
2001-01-25 10:37:55 +01:00
continue;
counter++;
if (u->ship != (ship *) NULL) {
if (counter == 1) {
scat("Die ");
} else {
scat("die ");
}
scat(shipname(u->ship));
} else {
scat(unitname(u));
}
if (counter + 1 < maxtravel) {
2001-01-25 10:37:55 +01:00
scat(", ");
} else if (counter + 1 == maxtravel) {
2001-01-25 10:37:55 +01:00
scat(" und ");
}
}
}
if (maxtravel == 1) {
2001-01-25 10:37:55 +01:00
scat(" hat die Region durchquert.");
rparagraph(F, buf, 0, 0);
} else {
scat(" haben die Region durchquert.");
rparagraph(F, buf, 0, 0);
}
}
static int
buildingmaintenance(const building * b, const resource_type * rtype)
{
const building_type * bt = b->type;
int c, cost=0;
static boolean init = false;
static const curse_type * nocost_ct;
if (!init) { init = true; nocost_ct = ct_find("nocost"); }
if (curse_active(get_curse(b->attribs, nocost_ct))) {
return 0;
}
for (c=0;bt->maintenance && bt->maintenance[c].number;++c) {
const maintenance * m = bt->maintenance + c;
if (m->rtype==rtype) {
if (fval(m, MTF_VARIABLE))
cost += (b->size * m->number);
else
cost += m->number;
}
}
return cost;
}
static int
report_template(const char * filename, report_context * ctx)
2001-01-25 10:37:55 +01:00
{
faction * f = ctx->f;
2004-06-21 18:45:27 +02:00
region *r;
plane *pl;
region *last = lastregion(f);
FILE * F = fopen(filename, "wt");
if (F==NULL) {
perror(filename);
return -1;
}
2001-01-25 10:37:55 +01:00
2004-06-21 18:45:27 +02:00
rps_nowrap(F, "");
rnl(F);
rps_nowrap(F, LOC(f->locale, "nr_template"));
rnl(F);
rps_nowrap(F, "");
rnl(F);
2001-01-25 10:37:55 +01:00
2004-06-21 18:45:27 +02:00
sprintf(buf, "%s %s \"%s\"", LOC(f->locale, "ERESSEA"), factionid(f), LOC(f->locale, "enterpasswd"));
rps_nowrap(F, buf);
rnl(F);
2001-01-25 10:37:55 +01:00
2004-06-21 18:45:27 +02:00
rps_nowrap(F, "");
rnl(F);
sprintf(buf, "; ECHECK %s-w4 -r%d -v%s", (f->options & Pow(O_SILBERPOOL)) ? "-l " : "",
f->race->recruitcost, ECHECK_VERSION);
/* -v3.4: ECheck Version 3.4.x */
rps_nowrap(F, buf);
rnl(F);
2001-01-25 10:37:55 +01:00
for (r = firstregion(f); r != last; r = r->next) {
2004-06-21 18:45:27 +02:00
unit *u;
int dh = 0;
for (u = r->units; u; u = u->next)
if (u->faction == f && u->race != new_race[RC_SPELL]) {
order * ord;
if (!dh) {
rps_nowrap(F, "");
rnl(F);
pl = getplane(r);
if (pl && fval(pl, PFL_NOCOORDS)) {
sprintf(buf, "%s; %s", LOC(f->locale, parameters[P_REGION]), rname(r, f->locale));
} else if (pl && pl->id != 0) {
sprintf(buf, "%s %d,%d,%d ; %s", LOC(f->locale, parameters[P_REGION]), region_x(r,f),
region_y(r,f), pl->id, rname(r, f->locale));
} else {
sprintf(buf, "%s %d,%d ; %s", LOC(f->locale, parameters[P_REGION]), region_x(r,f),
region_y(r,f), rname(r, f->locale));
}
rps_nowrap(F, buf);
rnl(F);
sprintf(buf,"; ECheck Lohn %d", wage(r, f, f->race));
2004-06-21 18:45:27 +02:00
rps_nowrap(F, buf);
rnl(F);
rps_nowrap(F, "");
rnl(F);
}
dh = 1;
2001-01-25 10:37:55 +01:00
2004-06-21 18:45:27 +02:00
sprintf(buf, "%s %s; %s [%d,%d$", LOC(u->faction->locale, parameters[P_UNIT]),
unitid(u), u->name, u->number, get_money(u));
if (u->building != NULL && fval(u, UFL_OWNER)) {
building * b = u->building;
int cost = buildingmaintenance(b, r_silver);
2001-01-25 10:37:55 +01:00
2004-06-21 18:45:27 +02:00
if (cost > 0) {
scat(",U");
icat(cost);
}
2001-01-25 10:37:55 +01:00
#if TODO
2004-06-21 18:45:27 +02:00
if (buildingdaten[u->building->typ].spezial != 0) {
scat("+");
}
2001-01-25 10:37:55 +01:00
#endif
2004-06-21 18:45:27 +02:00
} else if (u->ship) {
if (fval(u, UFL_OWNER))
scat(",S");
else
scat(",s");
scat(shipid(u->ship));
}
if (lifestyle(u) == 0)
scat(",I");
scat("]");
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
2004-06-21 18:45:27 +02:00
for (ord = u->orders; ord; ord = ord->next) {
if (u->old_orders && is_repeated(ord)) continue; /* unit has defaults */
2004-06-21 18:45:27 +02:00
if (is_persistent(ord)) {
strcpy(buf, " ");
write_order(ord, u->faction->locale, buf+2, sizeof(buf)-2);
rps_nowrap(F, buf);
rnl(F);
}
}
2001-01-25 10:37:55 +01:00
2004-06-21 18:45:27 +02:00
/* If the lastorder begins with an @ it should have
* been printed in the loop before. */
#ifdef LASTORDER
2004-06-21 18:45:27 +02:00
if (u->lastorder && !is_persistent(u->lastorder)) {
strcpy(buf, " ");
write_order(u->lastorder, u->faction->locale, buf+2, sizeof(buf)-2);
rps_nowrap(F, buf);
rnl(F);
}
#endif
2004-06-21 18:45:27 +02:00
}
}
rps_nowrap(F, "");
rnl(F);
sprintf(buf, LOC(f->locale, parameters[P_NEXT]));
rps_nowrap(F, buf);
rnl(F);
fclose(F);
return 0;
2001-01-25 10:37:55 +01:00
}
static void
show_allies(const faction * f, const ally * allies)
2001-01-25 10:37:55 +01:00
{
int allierte = 0;
int i=0, h, hh = 0;
int dh = 0;
const ally * sf;
for (sf = allies; sf; sf = sf->next) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (mode > 0) ++allierte;
2001-01-25 10:37:55 +01:00
}
for (sf = allies; sf; sf = sf->next) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (mode <= 0) continue;
i++;
if (dh) {
if (i == allierte)
scat(" und ");
else
scat(", ");
2001-01-25 10:37:55 +01:00
}
dh = 1;
hh = 0;
scat(factionname(sf->faction));
scat(" (");
if ((mode & HELP_ALL) == HELP_ALL) {
scat("Alles");
} else
for (h = 1; h < HELP_ALL; h *= 2) {
if ((mode & h) == h)
switch (h) {
case HELP_TRAVEL:
scat("Durchreise");
hh = 1;
break;
case HELP_MONEY:
scat("Silber");
hh = 1;
break;
case HELP_FIGHT:
if (hh)
scat(", ");
scat("K<EFBFBD>mpfe");
hh = 1;
break;
case HELP_OBSERVE:
if (hh)
scat(", ");
scat("Wahrnehmung");
hh = 1;
break;
case HELP_GIVE:
if (hh)
scat(", ");
scat("Gib");
hh = 1;
break;
case HELP_GUARD:
if (hh)
scat(", ");
scat("Bewache");
hh = 1;
break;
case HELP_FSTEALTH:
if (hh)
scat(", ");
scat("Parteitarnung");
hh = 1;
break;
}
}
scat(")");
2001-01-25 10:37:55 +01:00
}
}
static void
allies(FILE * F, const faction * f)
2001-01-25 10:37:55 +01:00
{
const group * g = f->groups;
2001-01-25 10:37:55 +01:00
if (f->allies) {
if (!f->allies->next) {
strcpy(buf, "Wir helfen der Partei ");
} else {
strcpy(buf, "Wir helfen den Parteien ");
}
show_allies(f, f->allies);
2001-01-25 10:37:55 +01:00
scat(".");
rparagraph(F, buf, 0, 0);
rnl(F);
}
while (g) {
if (g->allies) {
if (!g->allies->next) {
sprintf(buf, "%s hilft der Partei ", g->name);
} else {
sprintf(buf, "%s hilft den Parteien ", g->name);
}
show_allies(f, g->allies);
2001-01-25 10:37:55 +01:00
scat(".");
rparagraph(F, buf, 0, 0);
rnl(F);
}
g = g->next;
}
}
#ifdef ENEMIES
static void
enemies(FILE * F, const faction * f)
{
faction_list * flist = f->enemies;
if (flist!=NULL) {
strcpy(buf, "Wir liegen im Krieg mit ");
for (;flist!=NULL;flist = flist->next) {
const faction * enemy = flist->data;
scat(factionname(enemy));
if (flist->next) {
scat(", ");
} else {
scat(".");
}
}
rparagraph(F, buf, 0, 0);
rnl(F);
}
}
#endif
2001-01-25 10:37:55 +01:00
static void
guards(FILE * F, const region * r, const faction * see)
2001-01-25 10:37:55 +01:00
{ /* die Partei see sieht dies; wegen
* "unbekannte Partei", wenn man es selbst ist... */
2001-01-25 10:37:55 +01:00
faction* guardians[512];
2001-01-25 10:37:55 +01:00
int nextguard = 0;
2001-01-25 10:37:55 +01:00
unit *u;
int i;
2001-01-25 10:37:55 +01:00
boolean tarned = false;
/* Bewachung */
2001-01-25 10:37:55 +01:00
for (u = r->units; u; u = u->next) {
if (getguard(u)) {
faction *f = u->faction;
faction *fv = visible_faction(see, u);
2001-01-25 10:37:55 +01:00
if(fv != f && see != fv) {
f = fv;
}
if (f != see && fval(u, UFL_PARTEITARNUNG)) {
tarned=true;
} else {
for (i=0;i!=nextguard;++i) if (guardians[i]==f) break;
if (i==nextguard) {
guardians[nextguard++] = f;
}
}
}
}
2001-01-25 10:37:55 +01:00
if (nextguard || tarned) {
strcpy(buf, "Die Region wird von ");
} else {
return;
}
for (i = 0; i!=nextguard+(tarned?1:0); ++i) {
if (i!=0) {
if (i == nextguard-(tarned?0:1))
scat(" und ");
else
scat(", ");
}
if (i<nextguard) scat(factionname(guardians[i]));
else scat("unbekannten Einheiten");
}
scat(" bewacht.");
rnl(F);
rparagraph(F, buf, 0, 0);
2001-01-25 10:37:55 +01:00
}
static void
rpline(FILE * F)
{
rpc(F, ' ', 1);
rpc(F, '-', REPORTWIDTH);
rnl(F);
}
static void
list_address(FILE * F, const faction * uf, const faction_list * seenfactions)
2001-01-25 10:37:55 +01:00
{
const faction_list *flist = seenfactions;
2001-01-25 10:37:55 +01:00
centre(F, LOC(uf->locale, "nr_addresses"), false);
2001-01-25 10:37:55 +01:00
rnl(F);
while (flist!=NULL) {
const faction * f = flist->data;
if (f->no!=MONSTER_FACTION) {
sprintf(buf, "%s: %s; %s", factionname(f), f->email, f->banner);
rparagraph(F, buf, 4, (char)(ALLIED(uf, f)?'+':'*'));
#ifdef SHORTPWDS
if (f->shortpwds) {
shortpwd * spwd = f->shortpwds;
while (spwd) {
if (spwd->used) {
sprintf(buf, "Vertretung: %s", spwd->email);
rparagraph(F, buf, 6, '-');
}
spwd=spwd->next;
}
}
#endif
}
flist = flist->next;
2001-01-25 10:37:55 +01:00
}
rnl(F);
rpline(F);
}
void
report_building(FILE *F, const region * r, const building * b, const faction * f, int mode)
{
int i;
unit *u;
const char * bname;
2002-09-02 22:36:12 +02:00
const struct locale * lang = NULL;
2001-01-25 10:37:55 +01:00
const building_type * type = b->type;
static const struct building_type * bt_illusion;
2001-01-25 10:37:55 +01:00
if (!bt_illusion) bt_illusion = bt_find("illusion");
2001-01-25 10:37:55 +01:00
if (f) lang = f->locale;
sprintf(buf, "%s, %s %d, ", buildingname(b), LOC(f->locale, "nr_size"),
b->size);
if (b->type==bt_illusion) {
attrib * a = a_find(b->attribs, &at_icastle);
if (a!=NULL) {
type = ((icastle_data*)a->data.v)->type;
}
}
bname = LOC(lang, buildingtype(type, b, b->size));
strcat(buf, bname);
if (type!=b->type) {
unit * owner = buildingowner(r, b);
if (owner && owner->faction==f) {
/* illusion. report real type */
char lbuf[32];
bname = LOC(lang, buildingtype(b->type, b, b->size));
sprintf(lbuf, " (%s)", bname);
strcat(buf, lbuf);
}
}
2001-01-25 10:37:55 +01:00
if (b->size < type->maxsize) {
scat(" (im Bau)");
}
if (b->besieged > 0 && mode>=see_lighthouse) {
scat(", belagert von ");
icat(b->besieged);
scat(" Personen ");
if (b->besieged >= b->size * SIEGEFACTOR) {
scat("(abgeschnitten)");
} else {
scat("(unvollst<73>ndig belagert)");
}
}
i = 0;
if (b->display && b->display[0]) {
2001-01-25 10:37:55 +01:00
scat("; ");
scat(b->display);
i = b->display[strlen(b->display) - 1];
}
2005-10-23 13:27:55 +02:00
#ifdef WDW_PYRAMID
2001-01-25 10:37:55 +01:00
if (i != '!' && i != '?' && i != '.')
2005-10-23 13:27:55 +02:00
scat(", ");
if (b->type == bt_find("pyramid")) {
2005-10-23 13:27:55 +02:00
unit * owner = buildingowner(r, b);
scat("Gr<EFBFBD><EFBFBD>enstufe ");
icat(wdw_pyramid_level(b));
scat(".");
if (owner && owner->faction==f) {
const construction *ctype = b->type->construction;
int completed = b->size;
int c;
scat(" Baukosten pro Gr<47><72>enpunkt: ");
while(ctype->improvement != NULL &&
ctype->improvement != ctype &&
ctype->maxsize > 0 &&
ctype->maxsize <= completed)
{
completed -= ctype->maxsize;
ctype = ctype->improvement;
}
assert(ctype->materials != NULL);
2001-01-25 10:37:55 +01:00
2005-10-23 13:27:55 +02:00
for (c=0;ctype->materials[c].number;c++) {
const resource_type * rtype = ctype->materials[c].rtype;
2005-10-23 13:27:55 +02:00
int number = ctype->materials[c].number;
if(c > 0) {
scat(", ");
}
icat(number);
scat(" ");
scat(locale_string(lang, resourcename(rtype, number!=1?GR_PLURAL:0)));
2005-10-23 13:27:55 +02:00
}
scat(".");
}
}
2005-10-23 13:27:55 +02:00
#else
if (i != '!' && i != '?' && i != '.')
scat(".");
#endif
2001-01-25 10:37:55 +01:00
rparagraph(F, buf, 2, 0);
if (mode<see_lighthouse) return;
print_curses(F, f, b, TYP_BUILDING, 4);
2001-01-25 10:37:55 +01:00
for (u = r->units; u; u = u->next)
if (u->building == b && fval(u, UFL_OWNER)) {
2001-01-25 10:37:55 +01:00
rpunit(F, f, u, 6, mode);
break;
}
for (u = r->units; u; u = u->next)
if (u->building == b && !fval(u, UFL_OWNER))
2001-01-25 10:37:55 +01:00
rpunit(F, f, u, 6, mode);
}
int
report_plaintext(const char * filename, report_context * ctx)
2001-01-25 10:37:55 +01:00
{
int flag = 0;
char ch;
int dh;
int anyunits;
const struct region *r;
faction * f = ctx->f;
2001-01-25 10:37:55 +01:00
building *b;
ship *sh;
unit *u;
char pzTime[64];
2001-01-25 10:37:55 +01:00
attrib *a;
message * m;
2001-01-25 10:37:55 +01:00
unsigned char op;
region * last = lastregion(f);
int ix = Pow(O_STATISTICS);
int wants_stats = (f->options & ix);
FILE * F = fopen(filename, "wt");
if (F==NULL) {
perror(filename);
return -1;
}
strftime(pzTime, 64, "%A, %d. %B %Y, %H:%M", localtime(&ctx->report_time));
m = msg_message("nr_header_date", "game date", global.gamename, pzTime);
nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m);
2001-04-26 19:41:06 +02:00
centre(F, buf, true);
centre(F, gamedate_season(f->locale), true);
2001-01-25 10:37:55 +01:00
rnl(F);
sprintf(buf, "%s, %s/%s (%s)", factionname(f),
LOC(f->locale, rc_name(f->race, 1)),
LOC(f->locale, mkname("school", magietypen[f->magiegebiet])),
f->email);
2001-01-25 10:37:55 +01:00
centre(F, buf, true);
2002-09-02 22:36:12 +02:00
if (f->alliance!=NULL) {
centre(F, alliancename(f->alliance), true);
}
2001-01-25 10:37:55 +01:00
buf[0] = 0;
dh = 0;
for (a=a_find(f->attribs, &at_faction_special); a; a=a->nexttype) {
char buf2[80];
2001-01-25 10:37:55 +01:00
dh++;
if(fspecials[a->data.sa[0]].maxlevel != 100) {
2001-01-25 10:37:55 +01:00
sprintf(buf2, "%s (%d)", fspecials[a->data.sa[0]].name, a->data.sa[1]);
} else {
sprintf(buf2, "%s", fspecials[a->data.sa[0]].name);
}
if(dh > 1) strcat(buf, ", ");
strcat(buf, buf2);
}
if(dh > 0) centre(F, buf, true);
dh = 0;
if (f->karma > 0) {
2001-01-25 10:37:55 +01:00
sprintf(buf, "Deine Partei hat %d Karma.", f->karma);
centre(F, buf, true);
}
if (f->age <= 2) {
if (f->age <= 1) {
2002-04-20 14:41:49 +02:00
ADDMSG(&f->msgs, msg_message("changepasswd",
"value", f->passw));
}
RENDER(f, buf, sizeof(buf), ("newbie_password", "password", f->passw));
2001-01-25 10:37:55 +01:00
rnl(F);
centre(F, buf, true);
rnl(F);
centre(F, LOC(f->locale, "newbie_info_1"), true);
2001-01-25 10:37:55 +01:00
rnl(F);
centre(F, LOC(f->locale, "newbie_info_2"), true);
if ((f->options & want(O_COMPUTER)) == 0) {
f->options |= want(O_COMPUTER);
rnl(F);
centre(F, LOC(f->locale, "newbie_info_3"), true);
}
2001-01-25 10:37:55 +01:00
}
rnl(F);
#ifdef SCORE_MODULE
2001-01-25 10:37:55 +01:00
if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) {
RENDER(f, buf, sizeof(buf), ("nr_score", "score average", f->score, average_score_of_age(f->age, f->age / 24 + 1)));
2001-01-25 10:37:55 +01:00
centre(F, buf, true);
}
#endif
m = msg_message("nr_population", "population units", count_all(f), f->no_units);
nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m);
centre(F, buf, true);
if (f->race == new_race[RC_HUMAN]) {
int maxmig = count_maxmigrants(f);
m = msg_message("nr_migrants", "units maxunits", count_migrants(f), maxmig);
2005-07-25 21:10:21 +02:00
nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m);
2001-01-25 10:37:55 +01:00
centre(F, buf, true);
}
#ifdef HEROES
{
int maxh = maxheroes(f);
if (maxh) {
message * msg = msg_message("nr_heroes", "units maxunits", countheroes(f), maxh);
nr_render(msg, f->locale, buf, sizeof(buf), f);
msg_release(msg);
centre(F, buf, true);
}
}
2004-12-20 11:09:59 +01:00
#endif
2001-01-25 10:37:55 +01:00
if (f->items!=NULL) {
message * msg = msg_message("nr_claims", "items", f->items);
nr_render(msg, f->locale, buf, sizeof(buf), f);
msg_release(msg);
rnl(F);
centre(F, buf, true);
}
2001-01-25 10:37:55 +01:00
if (f->age > 1 && f->lastorders != turn) {
rnl(F);
if (turn - f->lastorders == 1) {
centre(F, LOC(f->locale, "nr_nmr"), true);
2001-01-25 10:37:55 +01:00
} else {
sprintf(buf,
"Deine Partei hat seit %d Runden keinen Zug abgegeben! Wenn du"
" drei Runden nacheinander keinen Zug abgibst, wird sie"
" automatisch gel<65>scht.",
turn - f->lastorders);
centre(F, buf, true);
}
rnl(F);
}
/* Insekten-Winter-Warnung */
if(f->race == new_race[RC_INSECT]) {
static int thisseason = -1;
if (thisseason<0) thisseason = get_gamedate(turn+1, 0)->season;
if (thisseason == 0) {
2001-01-25 10:37:55 +01:00
strcpy(buf, "Es ist Winter, und Insekten k<>nnen nur in W<>sten oder mit "
"Hilfe des Nestw<74>rme-Tranks Personen rekrutieren.");
centre(F, buf, true);
rnl(F);
} else {
static int nextseason = -1;
if (nextseason<0) nextseason = get_gamedate(turn+2, 0)->season;
if (nextseason == 0) {
strcpy(buf, "Es ist Sp<53>therbst, und diese Woche ist die letzte vor dem "
"Winter, in der Insekten rekrutieren k<>nnen.");
centre(F, buf, true);
rnl(F);
}
2001-01-25 10:37:55 +01:00
}
}
sprintf(buf, "%s:", LOC(f->locale, "nr_options"));
2001-01-25 10:37:55 +01:00
for (op = 0; op != MAXOPTIONS; op++) {
if (f->options & (int) pow(2, op)) {
scat(" ");
scat(LOC(f->locale, options[op]));
#ifdef AT_OPTION
if(op == O_NEWS) {
attrib *a = a_find(f->attribs, &at_option_news);
if(!a) {
/* Zur Altlastenbeseitigung */
f->options = f->options & ~op;
} else {
int sec = a->data.i;
int i;
scat("(");
for(i=1; sec != 0; i *= 2) {
if(sec & i) {
icat(i);
sec = sec & ~i;
if(sec) scat(",");
}
}
scat(")");
}
}
#endif
2001-01-25 10:37:55 +01:00
flag++;
}
}
if (flag > 0) {
rnl(F);
centre(F, buf, true);
}
/* Der Report soll sp<73>ter einmal durch einen Makroprozessor laufen.
* (enno) was? wer hat das geschrieben?
* Momentan ist das wegen der der Mailverschickmimik schwierig. */
rp_messages(F, f->msgs, f, 0, true, true);
rp_battles(F, f);
2001-01-25 10:37:55 +01:00
a = a_find(f->attribs, &at_reportspell);
if (a) {
rnl(F);
centre(F, LOC(f->locale, "section_newspells"), true);
2001-01-25 10:37:55 +01:00
while (a) {
spell *sp = (spell *)a->data.v;
report_spell(F, sp, f->locale);
2001-01-25 10:37:55 +01:00
a = a->nexttype;
}
}
ch = 0;
for (a=a_find(f->attribs, &at_showitem);a;a=a->nexttype) {
const potion_type * ptype = resource2potion(((const item_type*)a->data.v)->rtype);
2003-03-14 20:50:54 +01:00
const char * description = NULL;
2001-01-25 10:37:55 +01:00
requirement * m;
if (ptype!=NULL) {
const char * pname = resourcename(ptype->itype->rtype, 0);
m = ptype->itype->construction->materials;
if (ch==0) {
rnl(F);
centre(F, LOC(f->locale, "section_newpotions"), true);
ch = 1;
}
rnl(F);
centre(F, LOC(f->locale, pname), true);
sprintf(buf, "%s %d", LOC(f->locale, "nr_level"), ptype->level);
centre(F, buf, true);
rnl(F);
sprintf(buf, "%s: ", LOC(f->locale, "nr_herbsrequired"));
while (m->number) {
scat(LOC(f->locale, resourcename(m->rtype, 0)));
++m;
if (m->number) scat(", ");
}
centre(F, buf, true);
rnl(F);
if (description==NULL) {
const char * potiontext = mkname("potion", pname);
description = LOC(f->locale, potiontext);
}
centre(F, description, true);
}
2001-01-25 10:37:55 +01:00
}
rnl(F);
centre(F, LOC(f->locale, "nr_alliances"), false);
2001-01-25 10:37:55 +01:00
rnl(F);
#ifdef ENEMIES
enemies(F, f);
#endif
2001-01-25 10:37:55 +01:00
allies(F, f);
rpline(F);
anyunits = 0;
for (r=firstregion(f);r!=last;r=r->next) {
2001-01-25 10:37:55 +01:00
boolean unit_in_region = false;
boolean durchgezogen_in_region = false;
int turm_sieht_region = false;
seen_region * sd = find_seen(ctx->seen, r);
if (sd==NULL) continue;
2001-01-25 10:37:55 +01:00
switch (sd->mode) {
case see_lighthouse:
turm_sieht_region = true;
break;
case see_far:
break;
case see_travel:
durchgezogen_in_region = true;
break;
case see_unit:
unit_in_region = true;
anyunits = true;
break;
default:
continue;
}
r = sd->r;
/* Beschreibung */
if (unit_in_region) {
describe(F, r, 0, f);
if (!TradeDisabled() && !fval(r->terrain, SEA_REGION) && rpeasants(r)/TRADE_FRACTION > 0) {
2001-01-25 10:37:55 +01:00
rnl(F);
prices(F, r, f);
}
guards(F, r, f);
durchreisende(F, r, f);
}
else {
if (sd->mode==see_far) {
describe(F, r, 3, f);
guards(F, r, f);
durchreisende(F, r, f);
}
else if (turm_sieht_region) {
describe(F, r, 2, f);
durchreisende(F, r, f);
} else {
describe(F, r, 1, f);
durchreisende(F, r, f);
}
}
2001-01-25 10:37:55 +01:00
/* Statistik */
if (wants_stats && unit_in_region == 1)
statistics(F, r, f);
/* Nachrichten an REGION in der Region */
if (unit_in_region || durchgezogen_in_region) {
message_list * mlist = r_getmessages(r, f);
2001-01-25 10:37:55 +01:00
rp_messages(F, r->msgs, f, 0, true, true);
if (mlist) rp_messages(F, mlist, f, 0, true, true);
2001-01-25 10:37:55 +01:00
}
/* Burgen und ihre Einheiten */
for (b = rbuildings(r); b; b = b->next) {
rnl(F);
report_building(F, r, b, f, sd->mode);
}
/* Restliche Einheiten */
if (sd->mode>=see_lighthouse) {
for (u = r->units; u; u = u->next) {
if (!u->building && !u->ship) {
if ((u->faction == f) ||
(unit_in_region && cansee(f, r, u, 0)) ||
(durchgezogen_in_region && cansee(f, r, u, -1)) ||
(sd->mode==see_far && cansee(f, r, u, -2)) ||
(turm_sieht_region && cansee(f, r, u, -2)))
{
if (dh == 0 && !(rbuildings(r) || r->ships)) {
dh = 1;
/* rnl(F); */
}
rpunit(F, f, u, 4, sd->mode);
}
}
}
}
/* Schiffe und ihre Einheiten */
for (sh = r->ships; sh; sh = sh->next) {
faction *of = NULL;
rnl(F);
/* Gewicht feststellen */
for (u = r->units; u; u = u->next) {
if (u->ship == sh && fval(u, UFL_OWNER)) {
of = u->faction;
break;
}
}
if (of == f) {
int n = 0, p = 0;
getshipweight(sh, &n, &p);
n = (n+99) / 100; /* 1 Silber = 1 GE */
2001-01-25 10:37:55 +01:00
sprintf(buf, "%s, %s, (%d/%d)", shipname(sh),
LOC(f->locale, sh->type->name[0]), n, shipcapacity(sh) / 100);
} else {
sprintf(buf, "%s, %s", shipname(sh), LOC(f->locale, sh->type->name[0]));
}
2001-01-25 10:37:55 +01:00
assert(sh->type->construction->improvement==NULL); /* sonst ist construction::size nicht ship_type::maxsize */
if (sh->size!=sh->type->construction->maxsize) {
sprintf(buf+strlen(buf), ", %s (%d/%d)",
LOC(f->locale, "nr_undercons"), sh->size,
sh->type->construction->maxsize);
}
if (sh->damage) {
sprintf(buf+strlen(buf), ", %d%% %s",
sh->damage*100/(sh->size*DAMAGE_SCALE),
LOC(f->locale, "nr_damaged"));
}
if (!fval(r->terrain, SEA_REGION)) {
if (sh->coast != NODIRECTION) {
scat(", ");
scat(LOC(f->locale, coasts[sh->coast]));
}
}
ch = 0;
if (sh->display && sh->display[0]) {
scat("; ");
scat(sh->display);
2001-01-25 10:37:55 +01:00
ch = sh->display[strlen(sh->display) - 1];
}
if (ch != '!' && ch != '?' && ch != '.')
scat(".");
2001-01-25 10:37:55 +01:00
rparagraph(F, buf, 2, 0);
2001-01-25 10:37:55 +01:00
print_curses(F,f,sh,TYP_SHIP,4);
2001-01-25 10:37:55 +01:00
for (u = r->units; u; u = u->next) {
if (u->ship == sh && fval(u, UFL_OWNER)) {
rpunit(F, f, u, 6, sd->mode);
break;
}
}
for (u = r->units; u; u = u->next) {
if (u->ship == sh && !fval(u, UFL_OWNER)) {
rpunit(F, f, u, 6, sd->mode);
}
}
}
rnl(F);
rpline(F);
}
if (f->no != MONSTER_FACTION) {
if (!anyunits) {
rnl(F);
rparagraph(F, LOC(f->locale, "nr_youaredead"), 0, 0);
} else {
list_address(F, f, ctx->addresses);
}
}
fclose(F);
return 0;
2001-01-25 10:37:55 +01:00
}
void
base36conversion(void)
{
region * r;
for (r=regions;r;r=r->next) {
unit * u;
for (u=r->units;u;u=u->next) {
if (forbiddenid(u->no)) {
uunhash(u);
u->no = newunitid();
uhash(u);
}
}
}
}
#define FMAXHASH 1021
2001-01-25 10:37:55 +01:00
struct fsee {
struct fsee * nexthash;
faction * f;
struct see {
struct see * next;
faction * seen;
unit * proof;
} * see;
} * fsee[FMAXHASH];
#define REPORT_NR (1 << O_REPORT)
#define REPORT_CR (1 << O_COMPUTER)
#define REPORT_ZV (1 << O_ZUGVORLAGE)
#define REPORT_ZIP (1 << O_COMPRESS)
#define REPORT_BZIP2 (1 << O_BZIP2)
int
init_reports(void)
{
update_intervals();
#ifdef HAVE_STAT
{
stat_type st;
if (stat(reportpath(), &st)==0) return 0;
}
#endif
if (makedir(reportpath(), 0700)!=0) {
if (errno!=EEXIST) {
perror("could not create reportpath");
return -1;
}
}
return 0;
}
2001-01-25 10:37:55 +01:00
unit *
can_find(faction * f, faction * f2)
{
int key = f->no % FMAXHASH;
struct fsee * fs = fsee[key];
struct see * ss;
if (f==f2) return f->units;
while (fs && fs->f!=f) fs=fs->nexthash;
if (!fs) return NULL;
ss=fs->see;
while (ss && ss->seen!=f2) ss=ss->next;
if (ss) {
/* bei TARNE PARTEI yxz muss die Partei von unit proof nicht
* wirklich Partei f2 sein! */
/* assert(ss->proof->faction==f2); */
2001-01-25 10:37:55 +01:00
return ss->proof;
}
return NULL;
}
static void
add_find(faction * f, unit * u, faction *f2)
2001-01-25 10:37:55 +01:00
{
/* faction f sees f2 through u */
int key = f->no % FMAXHASH;
struct fsee ** fp = &fsee[key];
struct fsee * fs;
struct see ** sp;
struct see * ss;
while (*fp && (*fp)->f!=f) fp=&(*fp)->nexthash;
if (!*fp) {
fs = *fp = calloc(sizeof(struct fsee), 1);
fs->f = f;
} else fs = *fp;
sp = &fs->see;
while (*sp && (*sp)->seen!=f2) sp=&(*sp)->next;
if (!*sp) {
ss = *sp = calloc(sizeof(struct see), 1);
ss->proof = u;
ss->seen = f2;
} else ss = *sp;
ss->proof = u;
}
static void
2001-01-25 10:37:55 +01:00
update_find(void)
{
region * r;
static boolean initial = true;
if (initial) for (r=regions;r;r=r->next) {
unit * u;
for (u=r->units;u;u=u->next) {
faction * lastf = u->faction;
unit * u2;
for (u2=r->units;u2;u2=u2->next) {
if (u2->faction==lastf || u2->faction==u->faction)
continue;
if (seefaction(u->faction, r, u2, 0)) {
faction *fv = visible_faction(u->faction, u2);
lastf = fv;
add_find(u->faction, u2, fv);
2001-01-25 10:37:55 +01:00
}
}
}
}
initial = false;
}
boolean
kann_finden(faction * f1, faction * f2)
{
update_find();
return (boolean)(can_find(f1, f2)!=NULL);
}
/******* summary *******/
int dropouts[2];
int * age = NULL;
typedef struct summary {
int waffen;
int factions;
int ruestungen;
int schiffe;
int gebaeude;
int maxskill;
2004-09-12 11:28:43 +02:00
int heroes;
int inhabitedregions;
int peasants;
int nunits;
int playerpop;
double playermoney;
double peasantmoney;
int armed_men;
int poprace[MAXRACES];
int factionrace[MAXRACES];
int landregionen;
int regionen_mit_spielern;
int landregionen_mit_spielern;
int orkifizierte_regionen;
int inactive_volcanos;
int active_volcanos;
int spielerpferde;
int pferde;
struct language {
struct language * next;
int number;
const struct locale * locale;
} * languages;
2001-01-25 10:37:55 +01:00
} summary;
summary *
make_summary(void)
2001-01-25 10:37:55 +01:00
{
faction *f;
region *r;
unit *u;
summary * s = calloc(1, sizeof(summary));
for (f = factions; f; f = f->next) {
const struct locale * lang = f->locale;
struct language * plang = s->languages;
while (plang && plang->locale != lang) plang=plang->next;
if (!plang) {
2002-01-20 12:35:06 +01:00
plang = calloc(sizeof(struct language), 1);
plang->next = s->languages;
s->languages = plang;
plang->locale = lang;
}
++plang->number;
2001-01-25 10:37:55 +01:00
f->nregions = 0;
f->num_total = 0;
2001-01-25 10:37:55 +01:00
f->money = 0;
if (f->alive && f->units) {
s->factions++;
/* Problem mit Monsterpartei ... */
if (f->no!=MONSTER_FACTION) {
s->factionrace[old_race(f->race)]++;
}
}
}
2001-01-25 10:37:55 +01:00
/* Alles z<>hlen */
for (r = regions; r; r = r->next) {
s->pferde += rhorses(r);
s->schiffe += listlen(r->ships);
s->gebaeude += listlen(r->buildings);
if (!fval(r->terrain, SEA_REGION)) {
2001-01-25 10:37:55 +01:00
s->landregionen++;
if (r->units) {
s->landregionen_mit_spielern++;
}
if (fval(r, RF_ORCIFIED)) {
s->orkifizierte_regionen++;
}
if (rterrain(r) == T_VOLCANO) {
s->inactive_volcanos++;
} else if(rterrain(r) == T_VOLCANO_SMOKING) {
s->active_volcanos++;
}
2001-01-25 10:37:55 +01:00
}
if (r->units) {
s->regionen_mit_spielern++;
}
if (rpeasants(r) || r->units) {
s->inhabitedregions++;
s->peasants += rpeasants(r);
s->peasantmoney += rmoney(r);
/* Einheiten Info. nregions darf nur einmal pro Partei
* incrementiert werden. */
for (u = r->units; u; u = u->next) freset(u->faction, FL_DH);
for (u = r->units; u; u = u->next) {
f = u->faction;
if (u->faction->no != MONSTER_FACTION) {
skill * sv;
item * itm;
2001-01-25 10:37:55 +01:00
s->nunits++;
s->playerpop += u->number;
2004-09-12 11:28:43 +02:00
if (u->flags & UFL_HERO) {
s->heroes += u->number;
}
2001-01-25 10:37:55 +01:00
s->spielerpferde += get_item(u, I_HORSE);
s->playermoney += get_money(u);
s->armed_men += armedmen(u);
for (itm=u->items;itm;itm=itm->next) {
if (itm->type->rtype->wtype) {
s->waffen += itm->number;
}
if (itm->type->rtype->atype) {
s->ruestungen += itm->number;
}
}
2001-01-25 10:37:55 +01:00
s->spielerpferde += get_item(u, I_HORSE);
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
skill_t sk = sv->id;
int aktskill = eff_skill(u, sk, r);
2001-01-25 10:37:55 +01:00
if (aktskill > s->maxskill) s->maxskill = aktskill;
}
if (!fval(f, FL_DH)) {
f->nregions++;
fset(f, FL_DH);
}
}
f->num_total += u->number;
2001-01-25 10:37:55 +01:00
f->money += get_money(u);
s->poprace[old_race(u->race)] += u->number;
2001-01-25 10:37:55 +01:00
}
}
}
return s;
}
static char *
pcomp(double i, double j)
2001-01-25 10:37:55 +01:00
{
sprintf(buf, "%.0f (%s%.0f)", i, (i>=j)?"+":"", i-j);
2001-01-25 10:37:55 +01:00
return buf;
}
static char *
rcomp(int i, int j)
{
sprintf(buf, "%d (%s%d,%s%d%%)",
i, (i>=j)?"+":"", i-j, (i>=j)?"+":"",j?((i-j)*100)/j:0);
return buf;
}
static void
writemonument(void)
{
FILE * F;
region *r;
building *b;
building *buildings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
int size[7] = {0,0,0,0,0,0,0};
int i, j, ra;
int count = 0;
unit *owner;
for (r = regions; r; r = r->next) {
for (b = r->buildings; b; b = b->next) {
if (b->type == bt_find("monument") && b->display && *b->display) {
2001-01-25 10:37:55 +01:00
freset(b, FL_DH);
count++;
if(b->size > size[6]) {
for(i=0; i <= 6; i++) if(b->size >= size[i]) {
for(j=5;j >= i; j--) {
size[j+1] = size[j];
buildings[j+1] = buildings[j];
}
buildings[i] = b;
size[i] = b->size;
break;
}
}
}
}
}
for(i=0; i <= 6; i++) if(buildings[i]) {
fset(buildings[i], FL_DH);
}
2001-01-28 09:50:46 +01:00
{
char zText[MAX_PATH];
sprintf(zText, "%s/news-monument", basepath());
F = cfopen(zText, "w");
if (!F) return;
}
2001-01-25 10:37:55 +01:00
fprintf(F, "\n--- maintitle ---\n\n");
for(i = 0; i<=6; i++) {
if (buildings[i] != NULL) {
fprintf(F, "In %s", rname(buildings[i]->region, NULL));
if ((owner=buildingowner(buildings[i]->region,buildings[i]))!=NULL && !fval(owner,UFL_PARTEITARNUNG)) {
2001-01-25 10:37:55 +01:00
fprintf(F, ", Eigent<6E>mer: %s", factionname(owner->faction));
}
fprintf(F, "\n\n");
report_building(F, buildings[i]->region, buildings[i], findfaction(0), see_neighbour);
fprintf(F, "\n\n");
}
}
fprintf(F, "\n--- newcomer ---\n\n");
if(count > 7) {
ra = rand()%(count-7);
j = 0;
for (r = regions; r; r = r->next) {
for (b = r->buildings; b; b = b->next) {
if (b->type == bt_find("monument") && b->display && *b->display && !fval(b, FL_DH)) {
2001-01-25 10:37:55 +01:00
j++;
if(j == ra) {
fprintf(F, "In %s", rname(b->region, NULL));
if ((owner=buildingowner(b->region,b))!=NULL && !fval(owner,UFL_PARTEITARNUNG)) {
2001-01-25 10:37:55 +01:00
fprintf(F, ", Eigent<6E>mer: %s", factionname(owner->faction));
}
fprintf(F, "\n\n");
report_building(F, b->region, b, findfaction(0), see_neighbour);
fprintf(F, "\n\n");
}
}
}
}
}
fclose(F);
}
static void
writeadresses(void)
{
faction *f;
FILE *F;
char zText[MAX_PATH];
sprintf(zText, "%s/adressen", basepath());
F = cfopen(zText, "w");
if (!F) return;
for (f = factions; f; f = f->next) {
if (f->no != MONSTER_FACTION && playerrace(f->race)) {
fprintf(F, "%s:%s:%s\n", factionname(f), f->email, f->banner);
}
}
fclose(F);
}
static void
writenewssubscriptions(void)
{
char zText[MAX_PATH];
FILE *F;
sprintf(zText, "%s/news-subscriptions", basepath());
F = cfopen(zText, "w");
if (!F) return;
#ifdef AT_OPTION
{
faction *f;
for(f=factions; f; f=f->next) {
attrib *a = a_find(f->attribs, &at_option_news);
if(!a) {
fprintf(F, "%s:0\n", f->email);
} else {
fprintf(F, "%s:%d\n", f->email, a->data.i);
}
}
}
#endif
fclose(F);
}
2001-01-25 10:37:55 +01:00
static void
writeforward(void)
{
FILE *forwardFile;
region *r;
faction *f;
2001-01-25 10:37:55 +01:00
unit *u;
2001-01-28 09:50:46 +01:00
{
char zText[MAX_PATH];
sprintf(zText, "%s/aliases", basepath());
forwardFile = cfopen(zText, "w");
if (!forwardFile) return;
}
2001-01-25 10:37:55 +01:00
for (f = factions; f; f = f->next) {
if (f->no != MONSTER_FACTION) {
fprintf(forwardFile,"partei-%s: %s\n", factionid(f), f->email);
}
}
2001-01-25 10:37:55 +01:00
for (r = regions; r; r = r->next) {
for (u = r->units; u; u = u->next) {
if (u->faction->no != MONSTER_FACTION) {
fprintf(forwardFile,"einheit-%s: %s\n", unitid(u), u->faction->email);
}
}
}
fclose(forwardFile);
}
static void
writeturn(void)
{
char zText[MAX_PATH];
FILE *f;
sprintf(zText, "%s/datum", basepath());
f = cfopen(zText, "w");
if (!f) return;
2002-07-29 09:35:37 +02:00
fputs(gamedate2(default_locale), f);
fclose(f);
sprintf(zText, "%s/turn", basepath());
f = cfopen(zText, "w");
if (!f) return;
fprintf(f,"%d",turn);
fclose(f);
}
2002-02-18 17:19:50 +01:00
static void
out_faction(FILE *file, faction *f)
{
if (alliances!=NULL) {
fprintf(file, "%s (%s/%d) (%.3s/%.3s), %d Einh., %d Pers., $%d, %d %s\n",
f->name, itoa36(f->no), f->alliance?f->alliance->id:0,
LOC(default_locale, rc_name(f->race, 0)), magietypen[f->magiegebiet],
f->no_units, f->num_total, f->money, turn - f->lastorders,
turn - f->lastorders != 1 ? "NMRs" : "NMR ");
} else {
fprintf(file, "%s (%.3s/%.3s), %d Einh., %d Pers., $%d, %d %s\n",
factionname(f), LOC(default_locale, rc_name(f->race, 0)),
magietypen[f->magiegebiet], f->no_units, f->num_total, f->money,
turn - f->lastorders, turn - f->lastorders != 1 ? "NMRs" : "NMR ");
}
2002-02-18 17:19:50 +01:00
}
2001-01-25 10:37:55 +01:00
void
report_summary(summary * s, summary * o, boolean full)
{
FILE * F = NULL;
2001-01-25 10:37:55 +01:00
int i, newplayers = 0;
faction * f;
int * nmrs = malloc(sizeof(int)*(NMRTimeout()+1));
2001-01-25 10:37:55 +01:00
2001-01-28 09:50:46 +01:00
{
char zText[MAX_PATH];
if (full) {
sprintf(zText, "%s/parteien.full", basepath());
} else {
2001-02-04 14:20:12 +01:00
sprintf(zText, "%s/parteien", basepath());
2001-01-28 09:50:46 +01:00
}
F = cfopen(zText, "w");
if (!F) return;
2001-01-25 10:37:55 +01:00
}
printf("Schreibe Zusammenfassung (parteien)...\n");
2002-07-29 09:35:37 +02:00
fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale));
fprintf(F, "Auswertung Nr: %d\n\n", turn);
2001-01-25 10:37:55 +01:00
fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions));
fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits));
2001-01-25 10:37:55 +01:00
fprintf(F, "Spielerpopulation: %s\n",
pcomp(s->playerpop, o->playerpop));
fprintf(F, " davon bewaffnet: %s\n",
pcomp(s->armed_men, o->armed_men));
2004-09-12 11:28:43 +02:00
#ifdef HEROES
fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes));
#endif
2001-01-25 10:37:55 +01:00
2004-09-12 11:28:43 +02:00
if (full) {
2001-01-25 10:37:55 +01:00
fprintf(F, "Regionen: %d\n", listlen(regions));
fprintf(F, "Bewohnte Regionen: %d\n", s->inhabitedregions);
fprintf(F, "Landregionen: %d\n", s->landregionen);
fprintf(F, "Spielerregionen: %d\n", s->regionen_mit_spielern);
fprintf(F, "Landspielerregionen: %d\n", s->landregionen_mit_spielern);
fprintf(F, "Orkifizierte Regionen: %d\n", s->orkifizierte_regionen);
fprintf(F, "Inaktive Vulkane: %d\n", s->inactive_volcanos);
fprintf(F, "Aktive Vulkane: %d\n\n", s->active_volcanos);
2001-01-25 10:37:55 +01:00
}
for (i = 0; i < MAXRACES; i++) {
const race * rc = new_race[i];
if (s->factionrace[i] && rc && playerrace(rc)
&& i != RC_TEMPLATE && i != RC_CLONE) {
fprintf(F, "%14sv<73>lker: %s\n", LOC(default_locale, rc_name(rc, 3)),
pcomp(s->factionrace[i], o->factionrace[i]));
}
}
2001-01-25 10:37:55 +01:00
if(full) {
fprintf(F, "\n");
{
struct language * plang = s->languages;
while (plang!=NULL) {
struct language * olang = o->languages;
int nold = 0;
while (olang && olang->locale!=plang->locale) olang=olang->next;
if (olang) nold = olang->number;
fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale),
rcomp(plang->number, nold));
plang=plang->next;
}
}
}
2001-01-25 10:37:55 +01:00
fprintf(F, "\n");
if (full) {
for (i = 0; i < MAXRACES; i++) {
const race * rc = new_race[i];
if (s->poprace[i]) {
fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)),
rcomp(s->poprace[i], o->poprace[i]));
}
}
} else {
for (i = 0; i < MAXRACES; i++) {
const race * rc = new_race[i];
if (s->poprace[i] && playerrace(rc)
&& i != RC_TEMPLATE && i != RC_CLONE) {
fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)),
rcomp(s->poprace[i], o->poprace[i]));
}
}
}
2001-01-25 10:37:55 +01:00
if (full) {
fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen,o->waffen));
fprintf(F, "R<EFBFBD>stungen: %s\n",
pcomp(s->ruestungen,o->ruestungen));
fprintf(F, "ungez<EFBFBD>hmte Pferde: %s\n", pcomp(s->pferde, o->pferde));
fprintf(F, "gez<EFBFBD>hmte Pferde: %s\n",
pcomp(s->spielerpferde,o->spielerpferde));
fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe));
fprintf(F, "Geb<EFBFBD>ude: %s\n", pcomp(s->gebaeude, o->gebaeude));
fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants,o->peasants));
fprintf(F, "Population gesamt: %d\n\n", s->playerpop+s->peasants);
fprintf(F, "Reichtum Spieler: %s Silber\n",
2001-01-25 10:37:55 +01:00
pcomp(s->playermoney,o->playermoney));
fprintf(F, "Reichtum Bauern: %s Silber\n",
2001-01-25 10:37:55 +01:00
pcomp(s->peasantmoney, o->peasantmoney));
fprintf(F, "Reichtum gesamt: %s Silber\n\n",
pcomp(s->playermoney+s->peasantmoney, o->playermoney+o->peasantmoney));
2001-01-25 10:37:55 +01:00
}
fprintf(F, "\n\n");
for (i = 0; i <= NMRTimeout(); ++i) {
2001-01-25 10:37:55 +01:00
nmrs[i] = 0;
}
for (f = factions; f; f = f->next) {
if (fval(f, FFL_ISNEW)) {
++newplayers;
} else if (f->no != MONSTER_FACTION) {
int nmr = turn-f->lastorders;
if (nmr<0 || nmr>NMRTimeout()) {
log_error(("faction %s has %d NMRS\n", factionid(f), nmr));
nmr = max(0, nmr);
nmr = min(nmr, NMRTimeout());
}
nmrs[nmr]++;
2001-01-25 10:37:55 +01:00
}
}
for (i = 0; i <= NMRTimeout(); ++i) {
if (i == NMRTimeout()) {
2002-02-18 17:19:50 +01:00
fprintf(F, "+ NMRs:\t\t %d\n", nmrs[i]);
} else {
fprintf(F, "%d %s:\t\t %d\n", i,
i != 1 ? "NMRs" : "NMR ", nmrs[i]);
}
2001-01-25 10:37:55 +01:00
}
if (age) {
if (age[2] != 0) {
fprintf(F, "Erstabgaben:\t %d%%\n", 100 - (dropouts[0] * 100 / age[2]));
}
if (age[3] != 0) {
fprintf(F, "Zweitabgaben:\t %d%%\n", 100 - (dropouts[1] * 100 / age[3]));
}
}
fprintf(F, "Neue Spieler:\t %d\n", newplayers);
if (full) {
if (factions)
fprintf(F, "\nParteien:\n\n");
2001-01-25 10:37:55 +01:00
for (f = factions; f; f = f->next) {
out_faction(F, f);
}
2002-02-18 17:19:50 +01:00
if (NMRTimeout() && full) {
fprintf(F, "\n\nFactions with NMRs:\n");
for (i = NMRTimeout(); i > 0; --i) {
for(f=factions; f; f=f->next) {
if(i == NMRTimeout()) {
if(turn - f->lastorders >= i) {
out_faction(F, f);
}
} else {
if(turn - f->lastorders == i) {
out_faction(F, f);
}
}
}
}
}
}
fclose(F);
2001-01-25 10:37:55 +01:00
if (full) {
2001-01-25 10:37:55 +01:00
printf("Schreibe Liste der Adressen (adressen)...\n");
writeadresses();
writenewssubscriptions();
2001-01-25 10:37:55 +01:00
writeforward();
printf("writing date & turn\n");
writeturn();
2001-01-25 10:37:55 +01:00
writemonument();
}
free(nmrs);
2001-01-25 10:37:55 +01:00
}
/******* end summary ******/
static void
eval_unit(struct opstack ** stack, const void * userdata) /* unit -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct unit * u = (const struct unit *)opop(stack).v;
const char * c = u?unitname(u):LOC(f->locale, "an_unknown_unit");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_spell(struct opstack ** stack, const void * userdata) /* unit -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct spell * sp = (const struct spell *)opop(stack).v;
const char * c = sp?spell_name(sp, f->locale):LOC(f->locale, "an_unknown_spell");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_unitname(struct opstack ** stack, const void * userdata) /* unit -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct unit * u = (const struct unit *)opop(stack).v;
const char * c = u?u->name:LOC(f->locale, "an_unknown_unit");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_unitid(struct opstack ** stack, const void * userdata) /* unit -> int */
{
const struct faction * f = (const struct faction *)userdata;
const struct unit * u = (const struct unit *)opop(stack).v;
const char * c = u?u->name:LOC(f->locale, "an_unknown_unit");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_faction(struct opstack ** stack, const void * userdata) /* faction -> string */
{
const struct faction * f = (const struct faction *)opop(stack).v;
const char * c = factionname(f);
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
2002-09-02 22:36:12 +02:00
static void
eval_alliance(struct opstack ** stack, const void * userdata) /* faction -> string */
{
const struct alliance * al = (const struct alliance *)opop(stack).v;
2002-09-02 22:36:12 +02:00
const char * c = alliancename(al);
variant var;
2002-09-02 22:36:12 +02:00
if (c!=NULL) {
size_t len = strlen(c);
var.v = strcpy(balloc(len+1), c);
2002-09-02 22:36:12 +02:00
}
else var.v = NULL;
opush(stack, var);
2002-09-02 22:36:12 +02:00
}
static void
eval_region(struct opstack ** stack, const void * userdata) /* region -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct region * r = (const struct region *)opop(stack).v;
const char * c = regionname(r, f);
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_ship(struct opstack ** stack, const void * userdata) /* ship -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct ship * u = (const struct ship *)opop(stack).v;
const char * c = u?shipname(u):LOC(f->locale, "an_unknown_ship");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_building(struct opstack ** stack, const void * userdata) /* building -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct building * u = (const struct building *)opop(stack).v;
const char * c = u?buildingname(u):LOC(f->locale, "an_unknown_building");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_weight(struct opstack ** stack, const void * userdata) /* region -> string */
{
char buffer[32];
const struct faction * f = (const struct faction *)userdata;
const struct locale * lang = f->locale;
int weight = opop_i(stack);
variant var;
if (weight % SCALEWEIGHT == 0) {
if (weight==SCALEWEIGHT) {
sprintf(buffer, "1 %s", LOC(lang, "weight_unit"));
} else {
sprintf(buffer, "%u %s", weight/SCALEWEIGHT, LOC(lang, "weight_unit_p"));
}
} else {
if (weight==1) {
sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT);
} else {
sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"), SCALEWEIGHT);
}
}
var.v = strcpy(balloc(strlen(buffer)+1), buffer);
opush(stack, var);
}
static void
eval_resource(struct opstack ** stack, const void * userdata)
{
const faction * report = (const faction*)userdata;
int j = opop(stack).i;
const struct resource_type * res = (const struct resource_type *)opop(stack).v;
const char * c = LOC(report->locale, resourcename(res, j!=1));
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_race(struct opstack ** stack, const void * userdata)
{
const faction * report = (const faction*)userdata;
int j = opop(stack).i;
const race * r = (const race *)opop(stack).v;
const char * c = LOC(report->locale, rc_name(r, j!=1));
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
2004-06-21 18:45:27 +02:00
static void
eval_order(struct opstack ** stack, const void * userdata) /* order -> string */
{
const faction * report = (const faction*)userdata;
const struct order * ord = (const struct order *)opop(stack).v;
static char buf[256];
size_t len;
variant var;
write_order(ord, report->locale, buf, sizeof(buf));
len = strlen(buf);
var.v = strcpy(balloc(len+1), buf);
opush(stack, var);
2004-06-21 18:45:27 +02:00
}
static void
eval_resources(struct opstack ** stack, const void * userdata) /* order -> string */
{
const faction * report = (const faction*)userdata;
const struct resource * res = (const struct resource *)opop(stack).v;
static char buf[256];
size_t len = sizeof(buf);
variant var;
char * edit = buf;
while (res!=NULL && len > 4) {
const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0);
int written = snprintf(edit, len, "%d %s", res->number, LOC(report->locale, rname));
len -= written;
edit += written;
res = res->next;
if (res!=NULL && len>2) {
strcat(edit, ", ");
edit += 2;
len -= 2;
}
}
*edit = 0;
var.v = strcpy(balloc(edit-buf+1), buf);
opush(stack, var);
}
static void
eval_direction(struct opstack ** stack, const void * userdata)
{
const faction * report = (const faction*)userdata;
int i = opop(stack).i;
const char * c = LOC(report->locale, (i>=0)?directions[i]:"unknown_direction");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
}
static void
eval_skill(struct opstack ** stack, const void * userdata)
{
const faction * report = (const faction*)userdata;
skill_t sk = (skill_t)opop(stack).i;
const char * c = skillname(sk, report->locale);
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
2001-05-20 09:23:54 +02:00
}
static void
eval_int36(struct opstack ** stack, const void * userdata)
{
int i = opop(stack).i;
2001-05-20 09:23:54 +02:00
const char * c = itoa36(i);
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len+1), c);
opush(stack, var);
unused(userdata);
}
void
report_init(void)
{
/* register functions that turn message contents to readable strings */
2002-09-02 22:36:12 +02:00
add_function("alliance", &eval_alliance);
add_function("region", &eval_region);
add_function("weight", &eval_weight);
add_function("resource", &eval_resource);
add_function("race", &eval_race);
add_function("faction", &eval_faction);
add_function("ship", &eval_ship);
add_function("unit", &eval_unit);
add_function("unit.name", &eval_unitname);
add_function("unit.id", &eval_unitid);
add_function("building", &eval_building);
add_function("skill", &eval_skill);
2004-06-21 18:45:27 +02:00
add_function("order", &eval_order);
add_function("direction", &eval_direction);
2001-05-20 09:23:54 +02:00
add_function("int36", &eval_int36);
add_function("trail", &eval_trail);
2004-06-21 18:45:27 +02:00
add_function("spell", &eval_spell);
add_function("resources", &eval_resources);
2004-06-21 18:45:27 +02:00
register_reporttype("nr", &report_plaintext, 1<<O_REPORT);
register_reporttype("txt", &report_template, 1<<O_ZUGVORLAGE);
}
void
report_cleanup(void)
{
int i;
for (i=0;i!=FMAXHASH;++i) {
while (fsee[i]) {
struct fsee * fs = fsee[i]->nexthash;
free(fsee[i]);
fsee[i] = fs;
}
}
}