server/src/gamecode/creport.c

1680 lines
45 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
/* vi: set ts=2:
+-------------------+ Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
| (c) 1998 - 2008 | Katja Zedel <katze@felidae.kn-bremen.de>
+-------------------+
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <platform.h>
#include <kernel/config.h>
#include "creport.h"
/* tweakable features */
#define RENDER_CRMESSAGES
#define BUFFERSIZE 32768
#define RESOURCECOMPAT
/* modules include */
#include <modules/score.h>
/* attributes include */
#include <attributes/follow.h>
#include <attributes/racename.h>
#include <attributes/orcification.h>
#include <attributes/otherfaction.h>
#include <attributes/raceprefix.h>
/* gamecode includes */
#include "laws.h"
#include "economy.h"
/* kernel includes */
#include <kernel/alchemy.h>
#include <kernel/alliance.h>
#include <kernel/connection.h>
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
#include <kernel/magic.h>
#include <kernel/message.h>
#include <kernel/move.h>
#include <kernel/order.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/reports.h>
#include <kernel/resources.h>
#include <kernel/ship.h>
#include <kernel/skill.h>
#include <kernel/teleport.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/save.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/crmessage.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/log.h>
#include <util/message.h>
#include <util/nrmessage.h>
#include <util/quicklist.h>
2010-08-08 10:06:34 +02:00
#include <libxml/encoding.h>
/* libc includes */
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* imports */
extern int verbosity;
boolean opt_cr_absolute_coords = false;
/* globals */
#define C_REPORT_VERSION 66
#define TAG_LOCALE "de"
#ifdef TAG_LOCALE
2011-03-07 08:02:35 +01:00
static const char *crtag(const char *key)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
static const struct locale *lang = NULL;
if (!lang)
lang = find_locale(TAG_LOCALE);
2010-08-08 10:06:34 +02:00
return locale_string(lang, key);
}
#else
#define crtag(x) (x)
#endif
/*
* translation table
*/
typedef struct translation {
2011-03-07 08:02:35 +01:00
struct translation *next;
char *key;
const char *value;
2010-08-08 10:06:34 +02:00
} translation;
#define TRANSMAXHASH 257
2011-03-07 08:02:35 +01:00
static translation *translation_table[TRANSMAXHASH];
static translation *junkyard;
static const char *add_translation(const char *key, const char *value)
2010-08-08 10:06:34 +02:00
{
int kk = ((key[0] << 5) + key[0]) % TRANSMAXHASH;
2011-03-07 08:02:35 +01:00
translation *t = translation_table[kk];
while (t && strcmp(t->key, key) != 0)
t = t->next;
2010-08-08 10:06:34 +02:00
if (!t) {
if (junkyard) {
t = junkyard;
junkyard = junkyard->next;
2011-03-07 08:02:35 +01:00
} else
t = malloc(sizeof(translation));
2010-08-08 10:06:34 +02:00
t->key = strdup(key);
t->value = value;
t->next = translation_table[kk];
translation_table[kk] = t;
}
return crtag(key);
}
2011-03-07 08:02:35 +01:00
static void write_translations(FILE * F)
2010-08-08 10:06:34 +02:00
{
int i;
fputs("TRANSLATION\n", F);
2011-03-07 08:02:35 +01:00
for (i = 0; i != TRANSMAXHASH; ++i) {
translation *t = translation_table[i];
2010-08-08 10:06:34 +02:00
while (t) {
fprintf(F, "\"%s\";%s\n", t->value, crtag(t->key));
t = t->next;
}
}
}
2011-03-07 08:02:35 +01:00
static void reset_translations(void)
2010-08-08 10:06:34 +02:00
{
int i;
2011-03-07 08:02:35 +01:00
for (i = 0; i != TRANSMAXHASH; ++i) {
translation *t = translation_table[i];
2010-08-08 10:06:34 +02:00
while (t) {
2011-03-07 08:02:35 +01:00
translation *c = t->next;
2010-08-08 10:06:34 +02:00
free(t->key);
t->next = junkyard;
junkyard = t;
t = c;
}
translation_table[i] = 0;
}
}
#include <kernel/objtypes.h>
2011-03-07 08:02:35 +01:00
static void print_items(FILE * F, item * items, const struct locale *lang)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
item *itm;
2010-08-08 10:06:34 +02:00
2011-03-07 08:02:35 +01:00
for (itm = items; itm; itm = itm->next) {
2010-08-08 10:06:34 +02:00
int in = itm->number;
2011-03-07 08:02:35 +01:00
const char *ic = resourcename(itm->type->rtype, 0);
if (itm == items)
fputs("GEGENSTAENDE\n", F);
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;%s\n", in, add_translation(ic, LOC(lang, ic)));
}
}
static void
cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t typ)
2010-08-08 10:06:34 +02:00
{
boolean header = false;
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. */
2011-03-07 08:02:35 +01:00
if (typ == TYP_SHIP) {
ship *sh = (ship *) obj;
unit *owner = ship_owner(sh);
2010-08-08 10:06:34 +02:00
a = sh->attribs;
r = sh->region;
if (owner != NULL) {
2011-03-07 08:02:35 +01:00
if (owner->faction == viewer) {
2010-08-08 10:06:34 +02:00
self = 2;
2011-03-07 08:02:35 +01:00
} else { /* steht eine person der Partei auf dem Schiff? */
2010-08-08 10:06:34 +02:00
unit *u = NULL;
for (u = r->units; u; u = u->next) {
if (u->ship == sh) {
self = 1;
break;
}
}
}
}
} else if (typ == TYP_BUILDING) {
2011-03-07 08:02:35 +01:00
building *b = (building *) obj;
unit *owner = building_owner(b);
2010-08-08 10:06:34 +02:00
a = b->attribs;
r = b->region;
2011-03-07 08:02:35 +01:00
if (owner != NULL) {
if (owner->faction == viewer) {
2010-08-08 10:06:34 +02:00
self = 2;
2011-03-07 08:02:35 +01:00
} else { /* steht eine Person der Partei in der Burg? */
2010-08-08 10:06:34 +02:00
unit *u = NULL;
for (u = r->units; u; u = u->next) {
if (u->building == b) {
self = 1;
break;
}
}
}
}
} else if (typ == TYP_UNIT) {
2011-03-07 08:02:35 +01:00
unit *u = (unit *) obj;
2010-08-08 10:06:34 +02:00
a = u->attribs;
r = u->region;
if (u->faction == viewer) {
self = 2;
}
} else if (typ == TYP_REGION) {
2011-03-07 08:02:35 +01:00
r = (region *) obj;
2010-08-08 10:06:34 +02:00
a = r->attribs;
} else {
/* fehler */
}
while (a) {
if (fval(a->type, ATF_CURSE)) {
2011-03-07 08:02:35 +01:00
curse *c = (curse *) a->data.v;
message *msg;
2010-08-08 10:06:34 +02:00
if (c->type->cansee) {
self = c->type->cansee(viewer, obj, typ, c, self);
}
msg = msg_curse(c, obj, typ, self);
if (msg) {
char buf[BUFFERSIZE];
if (!header) {
header = 1;
fputs("EFFECTS\n", F);
}
nr_render(msg, viewer->locale, buf, sizeof(buf), viewer);
fprintf(F, "\"%s\"\n", buf);
msg_release(msg);
}
2011-03-07 08:02:35 +01:00
} else if (a->type == &at_effect && self) {
effect_data *data = (effect_data *) a->data.v;
if (data->value > 0) {
const char *key = resourcename(data->type->itype->rtype, 0);
2010-08-08 10:06:34 +02:00
if (!header) {
header = 1;
fputs("EFFECTS\n", F);
}
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%d %s\"\n", data->value, add_translation(key,
locale_string(default_locale, key)));
2010-08-08 10:06:34 +02:00
}
}
a = a->next;
}
}
2011-03-07 08:02:35 +01:00
static int cr_unit(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
unit *u = (unit *) var.v;
sprintf(buffer, "%d", u ? u->no : -1);
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_ship(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
ship *u = (ship *) var.v;
sprintf(buffer, "%d", u ? u->no : -1);
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_building(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
building *u = (building *) var.v;
sprintf(buffer, "%d", u ? u->no : -1);
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_faction(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
faction *f = (faction *) var.v;
sprintf(buffer, "%d", f ? f->no : -1);
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_region(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const faction *report = (const faction *)userdata;
region *r = (region *) var.v;
2010-08-08 10:06:34 +02:00
if (r) {
2011-03-07 08:02:35 +01:00
plane *pl = rplane(r);
2010-08-08 10:06:34 +02:00
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(report, &nx, &ny, pl, r);
sprintf(buffer, "%d %d %d", nx, ny, plane_id(pl));
return 0;
}
return -1;
}
2011-03-07 08:02:35 +01:00
static int cr_resource(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const faction *report = (const faction *)userdata;
const resource_type *r = (const resource_type *)var.v;
2010-08-08 10:06:34 +02:00
if (r) {
2011-03-07 08:02:35 +01:00
const char *key = resourcename(r, 0);
2010-08-08 10:06:34 +02:00
sprintf(buffer, "\"%s\"",
add_translation(key, locale_string(report->locale, key)));
return 0;
}
return -1;
}
2011-03-07 08:02:35 +01:00
static int cr_race(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const faction *report = (const faction *)userdata;
const struct race *rc = (const race *)var.v;
const char *key = rc_name(rc, 0);
2010-08-08 10:06:34 +02:00
sprintf(buffer, "\"%s\"",
add_translation(key, locale_string(report->locale, key)));
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_alliance(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const alliance *al = (const alliance *)var.v;
if (al != NULL) {
2010-08-08 10:06:34 +02:00
sprintf(buffer, "%d", al->id);
}
unused(userdata);
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_skill(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const faction *report = (const faction *)userdata;
skill_t sk = (skill_t) var.i;
if (sk != NOSKILL)
sprintf(buffer, "\"%s\"",
add_translation(mkname("skill", skillnames[sk]), skillname(sk,
report->locale)));
else
strcpy(buffer, "\"\"");
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_order(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
order *ord = (order *) var.v;
if (ord != NULL) {
char *wp = buffer;
char *cmd = getcommand(ord);
const char *rp = cmd;
2010-08-08 10:06:34 +02:00
*wp++ = '\"';
while (*rp) {
switch (*rp) {
2011-03-07 08:02:35 +01:00
case '\"':
case '\\':
*wp++ = '\\';
default:
*wp++ = *rp++;
2010-08-08 10:06:34 +02:00
}
}
*wp++ = '\"';
*wp++ = 0;
free(cmd);
2011-03-07 08:02:35 +01:00
} else
strcpy(buffer, "\"\"");
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_resources(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
faction *f = (faction *) userdata;
resource *rlist = (resource *) var.v;
char *wp = buffer;
if (rlist != NULL) {
const char *name = resourcename(rlist->type, rlist->number != 1);
wp +=
sprintf(wp, "\"%d %s", rlist->number, add_translation(name, LOC(f->locale,
name)));
2010-08-08 10:06:34 +02:00
for (;;) {
rlist = rlist->next;
2011-03-07 08:02:35 +01:00
if (rlist == NULL)
break;
name = resourcename(rlist->type, rlist->number != 1);
wp +=
sprintf(wp, ", %d %s", rlist->number, add_translation(name,
LOC(f->locale, name)));
2010-08-08 10:06:34 +02:00
}
strcat(wp, "\"");
}
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_regions(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
faction *f = (faction *) userdata;
const arg_regions *rdata = (const arg_regions *)var.v;
if (rdata != NULL && rdata->nregions > 0) {
region *r = rdata->regions[0];
plane *pl = rplane(r);
2010-08-08 10:06:34 +02:00
int i, z = plane_id(pl);
2011-03-07 08:02:35 +01:00
char *wp = buffer;
2010-08-08 10:06:34 +02:00
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
wp += sprintf(wp, "\"%d %d %d", nx, ny, z);
2011-03-07 08:02:35 +01:00
for (i = 1; i != rdata->nregions; ++i) {
2010-08-08 10:06:34 +02:00
r = rdata->regions[i];
pl = rplane(r);
z = plane_id(pl);
wp += sprintf(wp, ", %d %d %d", nx, ny, z);
}
strcat(wp, "\"");
} else {
strcpy(buffer, "\"\"");
}
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_spell(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const faction *report = (const faction *)userdata;
spell *sp = (spell *) var.v;
if (sp != NULL)
sprintf(buffer, "\"%s\"", spell_name(sp, report->locale));
else
strcpy(buffer, "\"\"");
2010-08-08 10:06:34 +02:00
return 0;
}
2011-03-07 08:02:35 +01:00
static int cr_curse(variant var, char *buffer, const void *userdata)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const faction *report = (const faction *)userdata;
const curse_type *ctype = (const curse_type *)var.v;
if (ctype != NULL) {
2010-08-08 10:06:34 +02:00
sprintf(buffer, "\"%s\"", curse_name(ctype, report->locale));
2011-03-07 08:02:35 +01:00
} else
strcpy(buffer, "\"\"");
2010-08-08 10:06:34 +02:00
return 0;
}
/*static int msgno; */
#define MTMAXHASH 1021
static struct known_mtype {
2011-03-07 08:02:35 +01:00
const struct message_type *mtype;
struct known_mtype *nexthash;
} *mtypehash[MTMAXHASH];
2010-08-08 10:06:34 +02:00
2011-03-07 08:02:35 +01:00
static void report_crtypes(FILE * F, const struct locale *lang)
2010-08-08 10:06:34 +02:00
{
int i;
2011-03-07 08:02:35 +01:00
for (i = 0; i != MTMAXHASH; ++i) {
struct known_mtype *kmt;
for (kmt = mtypehash[i]; kmt; kmt = kmt->nexthash) {
const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype);
2010-08-08 10:06:34 +02:00
if (nrt) {
unsigned int hash = kmt->mtype->key;
fprintf(F, "MESSAGETYPE %d\n", hash);
fputc('\"', F);
fputs(escape_string(nrt_string(nrt), NULL, 0), F);
fputs("\";text\n", F);
fprintf(F, "\"%s\";section\n", nrt_section(nrt));
}
}
while (mtypehash[i]) {
kmt = mtypehash[i];
mtypehash[i] = mtypehash[i]->nexthash;
free(kmt);
}
}
}
2011-03-07 08:02:35 +01:00
static unsigned int messagehash(const struct message *msg)
2010-08-08 10:06:34 +02:00
{
variant var;
var.v = (void *)msg;
return (unsigned int)var.i;
}
2011-03-07 08:02:35 +01:00
static void render_messages(FILE * F, faction * f, message_list * msgs)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
struct mlist *m = msgs->begin;
2010-08-08 10:06:34 +02:00
while (m) {
2011-03-07 08:02:35 +01:00
char crbuffer[BUFFERSIZE]; /* gross, wegen spionage-messages :-( */
2010-08-08 10:06:34 +02:00
boolean printed = false;
2011-03-07 08:02:35 +01:00
const struct message_type *mtype = m->msg->type;
2010-08-08 10:06:34 +02:00
unsigned int hash = mtype->key;
#ifdef RENDER_CRMESSAGES
2011-03-07 08:02:35 +01:00
char nrbuffer[1024 * 32];
2010-08-08 10:06:34 +02:00
nrbuffer[0] = '\0';
if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) > 0) {
2010-08-08 10:06:34 +02:00
fprintf(F, "MESSAGE %u\n", messagehash(m->msg));
fprintf(F, "%d;type\n", hash);
fwritestr(F, nrbuffer);
fputs(";rendered\n", F);
printed = true;
}
#endif
crbuffer[0] = '\0';
2011-03-07 08:02:35 +01:00
if (cr_render(m->msg, crbuffer, (const void *)f) == 0) {
if (crbuffer[0] && !printed) {
2011-03-07 08:02:35 +01:00
fprintf(F, "MESSAGE %u\n", messagehash(m->msg));
fputs(crbuffer, F);
}
2010-08-08 10:06:34 +02:00
} else {
log_error("could not render cr-message %p: %s\n", m->msg, m->msg->type->name);
2010-08-08 10:06:34 +02:00
}
if (printed) {
unsigned int ihash = hash % MTMAXHASH;
2011-03-07 08:02:35 +01:00
struct known_mtype *kmt = mtypehash[ihash];
while (kmt && kmt->mtype != mtype)
kmt = kmt->nexthash;
if (kmt == NULL) {
kmt = (struct known_mtype *)malloc(sizeof(struct known_mtype));
2010-08-08 10:06:34 +02:00
kmt->nexthash = mtypehash[ihash];
kmt->mtype = mtype;
mtypehash[ihash] = kmt;
}
}
m = m->next;
}
}
2011-03-07 08:02:35 +01:00
static void cr_output_messages(FILE * F, message_list * msgs, faction * f)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
if (msgs)
render_messages(F, f, msgs);
2010-08-08 10:06:34 +02:00
}
/* prints a building */
static void
2011-03-07 08:02:35 +01:00
cr_output_building(FILE * F, building * b, const unit * owner, int fno,
faction * f)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
const char *bname, *billusion;
2010-08-08 10:06:34 +02:00
fprintf(F, "BURG %d\n", b->no);
report_building(b, &bname, &billusion);
if (billusion) {
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";Typ\n", add_translation(billusion, LOC(f->locale,
billusion)));
if (owner && owner->faction == f) {
fprintf(F, "\"%s\";wahrerTyp\n", add_translation(bname, LOC(f->locale,
bname)));
2010-08-08 10:06:34 +02:00
}
} else {
fprintf(F, "\"%s\";Typ\n", add_translation(bname, LOC(f->locale, bname)));
}
fprintf(F, "\"%s\";Name\n", b->name);
if (b->display && b->display[0])
fprintf(F, "\"%s\";Beschr\n", b->display);
if (b->size)
fprintf(F, "%d;Groesse\n", b->size);
if (owner)
fprintf(F, "%d;Besitzer\n", owner ? owner->no : -1);
if (fno >= 0)
fprintf(F, "%d;Partei\n", fno);
if (b->besieged)
fprintf(F, "%d;Belagerer\n", b->besieged);
cr_output_curses(F, f, b, TYP_BUILDING);
}
2011-03-07 08:02:35 +01:00
2010-08-08 10:06:34 +02:00
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* prints a ship */
static void
2011-03-07 08:02:35 +01:00
cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain,
const faction * f, const region * r)
2010-08-08 10:06:34 +02:00
{
int w = 0;
assert(sh);
fprintf(F, "SCHIFF %d\n", sh->no);
fprintf(F, "\"%s\";Name\n", sh->name);
if (sh->display && sh->display[0])
fprintf(F, "\"%s\";Beschr\n", sh->display);
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";Typ\n", add_translation(sh->type->name[0],
locale_string(f->locale, sh->type->name[0])));
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;Groesse\n", sh->size);
if (sh->damage) {
2011-03-07 08:02:35 +01:00
int percent =
(sh->damage * 100 + DAMAGE_SCALE - 1) / (sh->size * DAMAGE_SCALE);
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;Schaden\n", percent);
}
if (u)
fprintf(F, "%d;Kapitaen\n", u ? u->no : -1);
if (fcaptain >= 0)
fprintf(F, "%d;Partei\n", fcaptain);
/* calculate cargo */
if (u && (u->faction == f || omniscient(f))) {
int n = 0, p = 0;
int mweight = shipcapacity(sh);
getshipweight(sh, &n, &p);
fprintf(F, "%d;capacity\n", mweight);
fprintf(F, "%d;cargo\n", n);
fprintf(F, "%d;speed\n", shipspeed(sh, u));
}
/* shore */
w = NODIRECTION;
2011-03-07 08:02:35 +01:00
if (!fval(r->terrain, SEA_REGION))
w = sh->coast;
2010-08-08 10:06:34 +02:00
if (w != NODIRECTION)
fprintf(F, "%d;Kueste\n", w);
cr_output_curses(F, f, sh, TYP_SHIP);
}
static void
2011-03-07 08:02:35 +01:00
fwriteorder(FILE * F, const struct order *ord, const struct locale *lang,
boolean escape)
2010-08-08 10:06:34 +02:00
{
char ebuf[1024];
char obuf[1024];
2011-03-07 08:02:35 +01:00
const char *str = obuf;
2010-08-08 10:06:34 +02:00
fputc('"', F);
write_order(ord, obuf, sizeof(obuf));
if (escape) {
str = escape_string(obuf, ebuf, sizeof(ebuf));
}
2011-03-07 08:02:35 +01:00
if (str[0])
fputs(str, F);
2010-08-08 10:06:34 +02:00
fputc('"', F);
}
2011-03-07 08:02:35 +01:00
static void cr_output_spells(FILE * F, quicklist * slist, const faction * f,
int maxlevel)
2010-08-08 10:06:34 +02:00
{
if (slist) {
2011-03-07 08:02:35 +01:00
quicklist *ql;
int qi;
2010-08-08 10:06:34 +02:00
fprintf(F, "SPRUECHE\n");
2011-03-07 08:02:35 +01:00
for (ql = slist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spell *sp = (spell *) ql_get(ql, qi);
2010-08-08 10:06:34 +02:00
if (sp->level <= maxlevel) {
2011-03-07 08:02:35 +01:00
const char *name =
add_translation(mkname("spell", sp->sname), spell_name(sp,
f->locale));
2010-08-08 10:06:34 +02:00
fprintf(F, "\"%s\"\n", name);
}
}
}
}
/* prints all that belongs to a unit */
2011-03-07 08:02:35 +01:00
static void cr_output_unit(FILE * F, const region * r, const faction * f, /* observers faction */
const unit * u, int mode)
2010-08-08 10:06:34 +02:00
{
/* Race attributes are always plural and item attributes always
* singular */
2011-03-07 08:02:35 +01:00
const char *str;
const item_type *lasttype;
2010-08-08 10:06:34 +02:00
int pr;
item *itm, *show;
2011-03-07 08:02:35 +01:00
building *b;
const char *pzTmp;
skill *sv;
2010-08-08 10:06:34 +02:00
const attrib *a_fshidden = NULL;
boolean itemcloak = false;
2011-03-07 08:02:35 +01:00
static const curse_type *itemcloak_ct = 0;
2010-08-08 10:06:34 +02:00
static boolean init = false;
item result[MAX_INVENTORY];
2011-03-07 08:02:35 +01:00
if (fval(u->race, RCF_INVISIBLE))
return;
2010-08-08 10:06:34 +02:00
if (!init) {
init = true;
itemcloak_ct = ct_find("itemcloak");
}
2011-03-07 08:02:35 +01:00
if (itemcloak_ct != NULL) {
2010-08-08 10:06:34 +02:00
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
}
assert(u && u->number);
fprintf(F, "EINHEIT %d\n", u->no);
fprintf(F, "\"%s\";Name\n", u->name);
str = u_description(u, f->locale);
if (str) {
fprintf(F, "\"%s\";Beschr\n", str);
}
{
/* print faction information */
2011-03-07 08:02:35 +01:00
const faction *sf = visible_faction(f, u);
const char *prefix = raceprefix(u);
2010-08-08 10:06:34 +02:00
if (u->faction == f || omniscient(f)) {
2011-03-07 08:02:35 +01:00
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
const faction *otherfaction =
a_otherfaction ? get_otherfaction(a_otherfaction) : NULL;
2010-08-08 10:06:34 +02:00
/* my own faction, full info */
const attrib *a = NULL;
2011-03-07 08:02:35 +01:00
unit *mage;
if (fval(u, UFL_GROUP))
a = a_find(u->attribs, &at_group);
if (a != NULL) {
const group *g = (const group *)a->data.v;
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;gruppe\n", g->gid);
}
fprintf(F, "%d;Partei\n", u->faction->no);
2011-03-07 08:02:35 +01:00
if (sf != u->faction)
fprintf(F, "%d;Verkleidung\n", sf->no);
2010-08-08 10:06:34 +02:00
if (fval(u, UFL_ANON_FACTION))
fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_ANON_FACTION)));
if (otherfaction) {
2011-03-07 08:02:35 +01:00
if (otherfaction != u->faction) {
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;Anderepartei\n", otherfaction->no);
}
}
mage = get_familiar_mage(u);
if (mage) {
fprintf(F, "%u;familiarmage\n", mage->no);
}
} else {
if (fval(u, UFL_ANON_FACTION)) {
/* faction info is hidden */
fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_ANON_FACTION)));
} else {
2011-03-07 08:02:35 +01:00
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
const faction *otherfaction =
a_otherfaction ? get_otherfaction(a_otherfaction) : NULL;
2010-08-08 10:06:34 +02:00
/* other unit. show visible faction, not u->faction */
fprintf(F, "%d;Partei\n", sf->no);
if (sf == f) {
fprintf(F, "1;Verraeter\n");
}
if (a_otherfaction) {
2011-03-07 08:02:35 +01:00
if (otherfaction != u->faction) {
2010-08-08 10:06:34 +02:00
if (alliedunit(u, f, HELP_FSTEALTH)) {
fprintf(F, "%d;Anderepartei\n", otherfaction->no);
}
}
}
}
}
if (prefix) {
prefix = mkname("prefix", prefix);
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale,
prefix)));
2010-08-08 10:06:34 +02:00
}
}
if (u->faction != f && a_fshidden
2011-03-07 08:02:35 +01:00
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
2010-08-08 10:06:34 +02:00
fprintf(F, "-1;Anzahl\n");
} else {
fprintf(F, "%d;Anzahl\n", u->number);
}
pzTmp = get_racename(u->attribs);
if (pzTmp) {
fprintf(F, "\"%s\";Typ\n", pzTmp);
2011-03-07 08:02:35 +01:00
if (u->faction == f && fval(u->race, RCF_SHAPESHIFTANY)) {
const char *zRace = rc_name(u->race, 1);
2010-08-08 10:06:34 +02:00
fprintf(F, "\"%s\";wahrerTyp\n",
add_translation(zRace, locale_string(f->locale, zRace)));
}
} else {
2011-03-07 08:02:35 +01:00
const race *irace = u_irace(u);
const char *zRace = rc_name(irace, 1);
2010-08-08 10:06:34 +02:00
fprintf(F, "\"%s\";Typ\n",
add_translation(zRace, locale_string(f->locale, zRace)));
2011-03-07 08:02:35 +01:00
if (u->faction == f && irace != u->race) {
assert(skill_enabled[SK_STEALTH]
|| !"we're resetting this on load, so.. ircase should never be used");
2010-08-08 10:06:34 +02:00
zRace = rc_name(u->race, 1);
fprintf(F, "\"%s\";wahrerTyp\n",
add_translation(zRace, locale_string(f->locale, zRace)));
}
}
if (u->building) {
assert(u->building->region);
fprintf(F, "%d;Burg\n", u->building->no);
}
if (u->ship) {
assert(u->ship->region);
fprintf(F, "%d;Schiff\n", u->ship->no);
}
2011-03-07 08:02:35 +01:00
if (is_guard(u, GUARD_ALL) != 0) {
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;bewacht\n", 1);
}
2011-03-07 08:02:35 +01:00
if ((b = usiege(u)) != NULL) {
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;belagert\n", b->no);
}
/* additional information for own units */
if (u->faction == f || omniscient(f)) {
2011-03-07 08:02:35 +01:00
order *ord;
2010-08-08 10:06:34 +02:00
const char *xc;
2011-03-07 08:02:35 +01:00
const char *c;
2010-08-08 10:06:34 +02:00
int i;
i = ualias(u);
2011-03-07 08:02:35 +01:00
if (i > 0)
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;temp\n", i);
2011-03-07 08:02:35 +01:00
else if (i < 0)
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;alias\n", -i);
i = get_money(u);
fprintf(F, "%d;Kampfstatus\n", u->status);
fprintf(F, "%d;weight\n", weight(u));
if (fval(u, UFL_NOAID)) {
fputs("1;unaided\n", F);
}
if (fval(u, UFL_STEALTH)) {
i = u_geteffstealth(u);
if (i >= 0) {
fprintf(F, "%d;Tarnung\n", i);
}
}
xc = uprivate(u);
if (xc) {
fprintf(F, "\"%s\";privat\n", xc);
}
c = hp_status(u);
if (c && *c && (u->faction == f || omniscient(f))) {
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";hp\n", add_translation(c,
locale_string(u->faction->locale, c)));
2010-08-08 10:06:34 +02:00
}
if (fval(u, UFL_HERO)) {
fputs("1;hero\n", F);
}
if (fval(u, UFL_HUNGER) && (u->faction == f)) {
fputs("1;hunger\n", F);
}
if (is_mage(u)) {
fprintf(F, "%d;Aura\n", get_spellpoints(u));
2011-03-07 08:02:35 +01:00
fprintf(F, "%d;Auramax\n", max_spellpoints(u->region, u));
2010-08-08 10:06:34 +02:00
}
/* default commands */
fprintf(F, "COMMANDS\n");
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, true);
fputc('\n', F);
}
}
for (ord = u->orders; ord; ord = ord->next) {
2011-03-07 08:02:35 +01:00
if (u->old_orders && is_repeated(ord))
continue; /* unit has defaults */
2010-08-08 10:06:34 +02:00
if (is_persistent(ord)) {
fwriteorder(F, ord, f->locale, true);
fputc('\n', F);
}
}
/* talents */
pr = 0;
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
2011-03-07 08:02:35 +01:00
if (sv->level > 0) {
2010-08-08 10:06:34 +02:00
skill_t sk = sv->id;
int esk = eff_skill(u, sk, r);
if (!pr) {
pr = 1;
fprintf(F, "TALENTE\n");
}
2011-03-07 08:02:35 +01:00
fprintf(F, "%d %d;%s\n", u->number * level_days(sv->level), esk,
add_translation(mkname("skill", skillnames[sk]), skillname(sk,
f->locale)));
2010-08-08 10:06:34 +02:00
}
}
/* spells */
if (is_mage(u)) {
2011-03-07 08:02:35 +01:00
sc_mage *mage = get_mage(u);
quicklist **slistp = get_spelllist(mage, u->faction);
2010-08-08 10:06:34 +02:00
int i, maxlevel = effskill(u, SK_MAGIC);
cr_output_spells(F, *slistp, f, maxlevel);
2011-03-07 08:02:35 +01:00
for (i = 0; i != MAXCOMBATSPELLS; ++i) {
const spell *sp = mage->combatspells[i].sp;
2010-08-08 10:06:34 +02:00
if (sp) {
2011-03-07 08:02:35 +01:00
const char *name =
add_translation(mkname("spell", sp->sname), spell_name(sp,
f->locale));
2010-08-08 10:06:34 +02:00
fprintf(F, "KAMPFZAUBER %d\n", i);
fprintf(F, "\"%s\";name\n", name);
fprintf(F, "%d;level\n", mage->combatspells[i].level);
}
}
}
}
/* items */
pr = 0;
if (f == u->faction || omniscient(f)) {
2010-08-08 10:06:34 +02:00
show = u->items;
2011-03-07 08:02:35 +01:00
} else if (itemcloak == false && mode >= see_unit && !(a_fshidden
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
2010-08-08 10:06:34 +02:00
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
2011-03-07 08:02:35 +01:00
assert(n >= 0);
if (n > 0)
show = result;
else
show = NULL;
2010-08-08 10:06:34 +02:00
} else {
show = NULL;
}
lasttype = NULL;
2011-03-07 08:02:35 +01:00
for (itm = show; itm; itm = itm->next) {
const char *ic;
2010-08-08 10:06:34 +02:00
int in;
2011-03-07 08:02:35 +01:00
assert(itm->type != lasttype
|| !"error: list contains two objects of the same item");
2010-08-08 10:06:34 +02:00
report_item(u, itm, f, NULL, &ic, &in, true);
2011-03-07 08:02:35 +01:00
if (in == 0)
continue;
2010-08-08 10:06:34 +02:00
if (!pr) {
pr = 1;
fputs("GEGENSTAENDE\n", F);
}
2011-03-07 08:02:35 +01:00
fprintf(F, "%d;%s\n", in, add_translation(ic, locale_string(f->locale,
ic)));
2010-08-08 10:06:34 +02:00
}
cr_output_curses(F, f, u, TYP_UNIT);
}
2011-03-07 08:02:35 +01:00
2010-08-08 10:06:34 +02:00
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* prints allies */
2011-03-07 08:02:35 +01:00
static void show_allies_cr(FILE * F, const faction * f, const ally * sf)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
for (; sf; sf = sf->next)
if (sf->faction) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (mode != 0 && sf->status > 0) {
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
fprintf(F, "%d;Status\n", sf->status & HELP_ALL);
}
2010-08-08 10:06:34 +02:00
}
}
/* prints allies */
2011-03-07 08:02:35 +01:00
static void show_alliances_cr(FILE * F, const faction * f)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
alliance *al = f_get_alliance(f);
2010-08-08 10:06:34 +02:00
if (al) {
2011-03-07 08:02:35 +01:00
faction *lead = alliance_get_leader(al);
2010-08-08 10:06:34 +02:00
assert(lead);
fprintf(F, "ALLIANCE %d\n", al->id);
fprintf(F, "\"%s\";name\n", al->name);
fprintf(F, "%d;leader\n", lead->no);
}
}
/* prints all visible spells in a region */
2011-03-07 08:02:35 +01:00
static void show_active_spells(const region * r)
2010-08-08 10:06:34 +02:00
{
char fogwall[MAXDIRECTIONS];
2011-03-07 08:02:35 +01:00
#ifdef TODO /* alte Regionszauberanzeigen umstellen */
2010-08-08 10:06:34 +02:00
unit *u;
int env = 0;
#endif
memset(fogwall, 0, sizeof(char) * MAXDIRECTIONS);
}
2011-03-07 08:02:35 +01:00
2010-08-08 10:06:34 +02:00
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* this is a copy of laws.c->find_address output changed. */
2011-03-07 08:02:35 +01:00
static void cr_find_address(FILE * F, const faction * uf, quicklist * addresses)
2010-08-08 10:06:34 +02:00
{
int i = 0;
2011-03-07 08:02:35 +01:00
quicklist *flist = addresses;
while (flist) {
2011-03-07 08:02:35 +01:00
const faction *f = (const faction *)ql_get(flist, i);
if (uf != f) {
2010-08-08 10:06:34 +02:00
fprintf(F, "PARTEI %d\n", f->no);
fprintf(F, "\"%s\";Parteiname\n", f->name);
2011-03-07 08:02:35 +01:00
if (f->email)
fprintf(F, "\"%s\";email\n", f->email);
if (f->banner)
fprintf(F, "\"%s\";banner\n", f->banner);
2010-08-08 10:06:34 +02:00
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
2011-03-07 08:02:35 +01:00
if (f->alliance && f->alliance == uf->alliance) {
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;alliance\n", f->alliance->id);
}
}
ql_advance(&flist, &i, 1);
2010-08-08 10:06:34 +02:00
}
}
2011-03-07 08:02:35 +01:00
2010-08-08 10:06:34 +02:00
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
2011-03-07 08:02:35 +01:00
static void cr_reportspell(FILE * F, spell * sp, const struct locale *lang)
2010-08-08 10:06:34 +02:00
{
int k;
2011-03-07 08:02:35 +01:00
const char *name =
add_translation(mkname("spell", sp->sname), spell_name(sp, lang));
2010-08-08 10:06:34 +02:00
fprintf(F, "ZAUBER %d\n", hashstring(sp->sname));
fprintf(F, "\"%s\";name\n", name);
fprintf(F, "%d;level\n", sp->level);
fprintf(F, "%d;rank\n", sp->rank);
fprintf(F, "\"%s\";info\n", spell_info(sp, lang));
2011-03-07 08:02:35 +01:00
if (sp->parameter)
fprintf(F, "\"%s\";syntax\n", sp->parameter);
else
fputs("\"\";syntax\n", F);
if (sp->sptyp & PRECOMBATSPELL)
fputs("\"precombat\";class\n", F);
else if (sp->sptyp & COMBATSPELL)
fputs("\"combat\";class\n", F);
else if (sp->sptyp & POSTCOMBATSPELL)
fputs("\"postcombat\";class\n", F);
else
fputs("\"normal\";class\n", F);
if (sp->sptyp & FARCASTING)
fputs("1;far\n", F);
if (sp->sptyp & OCEANCASTABLE)
fputs("1;ocean\n", F);
if (sp->sptyp & ONSHIPCAST)
fputs("1;ship\n", F);
if (!(sp->sptyp & NOTFAMILIARCAST))
fputs("1;familiar\n", F);
2010-08-08 10:06:34 +02:00
fputs("KOMPONENTEN\n", F);
for (k = 0; sp->components[k].type; ++k) {
2011-03-07 08:02:35 +01:00
const resource_type *rtype = sp->components[k].type;
2010-08-08 10:06:34 +02:00
int itemanz = sp->components[k].amount;
int costtyp = sp->components[k].cost;
if (itemanz > 0) {
2011-03-07 08:02:35 +01:00
const char *name = resourcename(rtype, 0);
fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL
|| costtyp == SPC_LINEAR, add_translation(name, LOC(lang, name)));
2010-08-08 10:06:34 +02:00
}
}
}
2011-03-07 08:02:35 +01:00
static char *cr_output_resource(char *buf, const char *name,
const struct locale *loc, int amount, int level)
2010-08-08 10:06:34 +02:00
{
buf += sprintf(buf, "RESOURCE %u\n", hashstring(name));
buf += sprintf(buf, "\"%s\";type\n", add_translation(name, LOC(loc, name)));
2011-03-07 08:02:35 +01:00
if (amount >= 0) {
if (level >= 0)
buf += sprintf(buf, "%d;skill\n", level);
2010-08-08 10:06:34 +02:00
buf += sprintf(buf, "%d;number\n", amount);
}
return buf;
}
static void
2011-03-07 08:02:35 +01:00
cr_borders(seen_region ** seen, const region * r, const faction * f,
int seemode, FILE * F)
2010-08-08 10:06:34 +02:00
{
direction_t d;
int g = 0;
2011-03-07 08:02:35 +01:00
for (d = 0; d != MAXDIRECTIONS; d++) { /* Nachbarregionen, die gesehen werden, ermitteln */
const region *r2 = rconnect(r, d);
const connection *b;
if (!r2)
continue;
if (seemode == see_neighbour) {
seen_region *sr = find_seen(seen, r2);
if (sr == NULL || sr->mode <= see_neighbour)
continue;
2010-08-08 10:06:34 +02:00
}
b = get_borders(r, r2);
while (b) {
boolean cs = b->type->fvisible(b, f, r);
if (!cs) {
cs = b->type->rvisible(b, r);
if (!cs) {
2011-03-07 08:02:35 +01:00
unit *us = r->units;
2010-08-08 10:06:34 +02:00
while (us && !cs) {
2011-03-07 08:02:35 +01:00
if (us->faction == f) {
2010-08-08 10:06:34 +02:00
cs = b->type->uvisible(b, us);
2011-03-07 08:02:35 +01:00
if (cs)
break;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
us = us->next;
2010-08-08 10:06:34 +02:00
}
}
}
if (cs) {
2011-03-07 08:02:35 +01:00
const char *bname = mkname("border", b->type->name(b, r, f, GF_PURE));
2010-08-08 10:06:34 +02:00
fprintf(F, "GRENZE %d\n", ++g);
fprintf(F, "\"%s\";typ\n", LOC(default_locale, bname));
fprintf(F, "%d;richtung\n", d);
2011-03-07 08:02:35 +01:00
if (!b->type->transparent(b, f))
fputs("1;opaque\n", F);
2010-08-08 10:06:34 +02:00
/* hack: */
if (b->type == &bt_road && r->terrain->max_road) {
2011-03-07 08:02:35 +01:00
int p = rroad(r, d) * 100 / r->terrain->max_road;
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;prozent\n", p);
}
}
b = b->next;
}
}
}
static void
cr_output_resources(FILE * F, report_context * ctx, seen_region * sr)
{
char cbuf[BUFFERSIZE], *pos = cbuf;
2011-03-07 08:02:35 +01:00
region *r = sr->r;
faction *f = ctx->f;
2010-08-08 10:06:34 +02:00
resource_report result[MAX_RAWMATERIALS];
int n, size = report_resources(sr, result, MAX_RAWMATERIALS, f);
#ifdef RESOURCECOMPAT
int trees = rtrees(r, 2);
int saplings = rtrees(r, 1);
2011-03-07 08:02:35 +01:00
if (trees > 0)
fprintf(F, "%d;Baeume\n", trees);
if (saplings > 0)
fprintf(F, "%d;Schoesslinge\n", saplings);
2010-08-08 10:06:34 +02:00
if (fval(r, RF_MALLORN) && (trees > 0 || saplings > 0))
fprintf(F, "1;Mallorn\n");
2011-03-07 08:02:35 +01:00
for (n = 0; n < size; ++n) {
if (result[n].level >= 0 && result[n].number >= 0) {
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;%s\n", result[n].number, crtag(result[n].name));
}
}
#endif
2011-03-07 08:02:35 +01:00
for (n = 0; n < size; ++n) {
if (result[n].number >= 0) {
pos =
cr_output_resource(pos, result[n].name, f->locale, result[n].number,
result[n].level);
2010-08-08 10:06:34 +02:00
}
}
2011-03-07 08:02:35 +01:00
if (pos != cbuf)
fputs(cbuf, F);
2010-08-08 10:06:34 +02:00
}
static void
cr_region_header(FILE * F, int plid, int nx, int ny, unsigned int uid)
{
2011-03-07 08:02:35 +01:00
if (plid == 0) {
2010-08-08 10:06:34 +02:00
fprintf(F, "REGION %d %d\n", nx, ny);
} else {
fprintf(F, "REGION %d %d %d\n", nx, ny, plid);
}
2011-03-07 08:02:35 +01:00
if (uid)
fprintf(F, "%d;id\n", uid);
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
faction *f = ctx->f;
region *r = sr->r;
plane *pl = rplane(r);
2010-08-08 10:06:34 +02:00
int plid = plane_id(pl), nx, ny;
2011-03-07 08:02:35 +01:00
const char *tname;
2010-08-08 10:06:34 +02:00
int oc[4][2], o = 0;
int uid = r->uid;
#ifdef OCEAN_NEIGHBORS_GET_NO_ID
2011-03-07 08:02:35 +01:00
if (sr->mode <= see_neighbour && !r->land) {
2010-08-08 10:06:34 +02:00
uid = 0;
}
#endif
if (opt_cr_absolute_coords) {
nx = r->x;
ny = r->y;
} else {
nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
}
if (pl) {
2011-03-07 08:02:35 +01:00
if (ny == pl->maxy) {
2010-08-08 10:06:34 +02:00
oc[o][0] = nx;
2011-03-07 08:02:35 +01:00
oc[o++][1] = pl->miny - 1;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
if (nx == pl->maxx) {
oc[o][0] = pl->minx - 1;
2010-08-08 10:06:34 +02:00
oc[o++][1] = ny;
}
2011-03-07 08:02:35 +01:00
if (ny == pl->miny) {
2010-08-08 10:06:34 +02:00
oc[o][0] = nx;
2011-03-07 08:02:35 +01:00
oc[o++][1] = pl->maxy + 1;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
if (nx == pl->minx) {
oc[o][0] = pl->maxx + 1;
2010-08-08 10:06:34 +02:00
oc[o++][1] = ny;
}
}
while (o--) {
cr_region_header(F, plid, oc[o][0], oc[o][1], uid);
fputs("\"wrap\";visibility\n", F);
}
cr_region_header(F, plid, nx, ny, uid);
if (r->land) {
2011-03-07 08:02:35 +01:00
const char *str = rname(r, f->locale);
2010-08-08 10:06:34 +02:00
if (str && str[0]) {
fprintf(F, "\"%s\";Name\n", str);
}
}
tname = terrain_name(r);
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale,
tname)));
if (sr->mode != see_unit)
fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]);
2010-08-08 10:06:34 +02:00
if (sr->mode == see_neighbour) {
cr_borders(ctx->seen, r, f, sr->mode, F);
} else {
2011-03-07 08:02:35 +01:00
building *b;
ship *sh;
unit *u;
2010-08-08 10:06:34 +02:00
int stealthmod = stealth_modifier(sr->mode);
if (r->display && r->display[0])
fprintf(F, "\"%s\";Beschr\n", r->display);
if (fval(r->terrain, LAND_REGION)) {
fprintf(F, "%d;Bauern\n", rpeasants(r));
2011-03-07 08:02:35 +01:00
if (fval(r, RF_ORCIFIED)) {
2010-08-08 10:06:34 +02:00
fprintf(F, "1;Verorkt\n");
}
fprintf(F, "%d;Pferde\n", rhorses(r));
2011-03-07 08:02:35 +01:00
if (sr->mode >= see_unit) {
2010-08-08 10:06:34 +02:00
if (rule_region_owners()) {
2011-03-07 08:02:35 +01:00
faction *owner = region_get_owner(r);
2010-08-08 10:06:34 +02:00
if (owner) {
fprintf(F, "%d;owner\n", owner->no);
}
}
fprintf(F, "%d;Silber\n", rmoney(r));
if (skill_enabled[SK_ENTERTAINMENT]) {
fprintf(F, "%d;Unterh\n", entertainmoney(r));
}
2011-03-07 08:02:35 +01:00
if (is_cursed(r->attribs, C_RIOT, 0)) {
2010-08-08 10:06:34 +02:00
fputs("0;Rekruten\n", F);
} else {
fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION);
}
if (production(r)) {
2011-03-07 08:02:35 +01:00
int p_wage = wage(r, NULL, NULL, turn + 1);
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;Lohn\n", p_wage);
2011-03-07 08:02:35 +01:00
if (is_mourning(r, turn + 1)) {
2010-08-08 10:06:34 +02:00
fputs("1;mourning\n", F);
}
}
if (r->land->ownership) {
fprintf(F, "%d;morale\n", r->land->morale);
}
}
/* this writes both some tags (RESOURCECOMPAT) and a block.
* must not write any blocks before it */
cr_output_resources(F, ctx, sr);
2011-03-07 08:02:35 +01:00
if (sr->mode >= see_unit) {
2010-08-08 10:06:34 +02:00
/* trade */
if (markets_module() && r->land) {
2011-03-07 08:02:35 +01:00
const item_type *lux = r_luxury(r);
const item_type *herb = r->land->herbtype;
2010-08-08 10:06:34 +02:00
if (lux || herb) {
fputs("PREISE\n", F);
if (lux) {
2011-03-07 08:02:35 +01:00
const char *ch = resourcename(lux->rtype, 0);
fprintf(F, "%d;%s\n", 1, add_translation(ch,
locale_string(f->locale, ch)));
2010-08-08 10:06:34 +02:00
}
if (herb) {
2011-03-07 08:02:35 +01:00
const char *ch = resourcename(herb->rtype, 0);
fprintf(F, "%d;%s\n", 1, add_translation(ch,
locale_string(f->locale, ch)));
2010-08-08 10:06:34 +02:00
}
}
2011-03-07 08:02:35 +01:00
} else if (rpeasants(r) / TRADE_FRACTION > 0) {
struct demand *dmd = r->land->demands;
2010-08-08 10:06:34 +02:00
fputs("PREISE\n", F);
while (dmd) {
2011-03-07 08:02:35 +01:00
const char *ch = resourcename(dmd->type->itype->rtype, 0);
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;%s\n", (dmd->value
2011-03-07 08:02:35 +01:00
? dmd->value * dmd->type->price
: -dmd->type->price),
2010-08-08 10:06:34 +02:00
add_translation(ch, locale_string(f->locale, ch)));
2011-03-07 08:02:35 +01:00
dmd = dmd->next;
2010-08-08 10:06:34 +02:00
}
}
}
}
if (r->land) {
print_items(F, r->land->items, f->locale);
}
cr_output_curses(F, f, r, TYP_REGION);
cr_borders(ctx->seen, r, f, sr->mode, F);
2011-03-07 08:02:35 +01:00
if (sr->mode == see_unit && is_astral(r)
&& !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
2010-08-08 10:06:34 +02:00
/* Sonderbehandlung Teleport-Ebene */
region_list *rl = astralregions(r, inhabitable);
if (rl) {
region_list *rl2 = rl;
2011-03-07 08:02:35 +01:00
while (rl2) {
region *r = rl2->data;
2010-08-08 10:06:34 +02:00
int nx = r->x, ny = r->y;
2011-03-07 08:02:35 +01:00
plane *plx = rplane(r);
2010-08-08 10:06:34 +02:00
pnormalize(&nx, &ny, plx);
adjust_coordinates(f, &nx, &ny, plx, r);
fprintf(F, "SCHEMEN %d %d\n", nx, ny);
fprintf(F, "\"%s\";Name\n", rname(r, f->locale));
rl2 = rl2->next;
}
free_regionlist(rl);
}
}
/* describe both passed and inhabited regions */
show_active_spells(r);
if (fval(r, RF_TRAVELUNIT)) {
boolean seeunits = false, seeships = false;
2011-03-07 08:02:35 +01:00
const attrib *ru;
2010-08-08 10:06:34 +02:00
/* show units pulled through region */
2011-03-07 08:02:35 +01:00
for (ru = a_find(r->attribs, &at_travelunit);
ru && ru->type == &at_travelunit; ru = ru->next) {
unit *u = (unit *) ru->data.v;
if (cansee_durchgezogen(f, r, u, 0) && r != u->region) {
if (u->ship && ship_owner(u->ship)==u) {
if (!seeships) {
fprintf(F, "DURCHSCHIFFUNG\n");
}
seeships = true;
fprintf(F, "\"%s\"\n", shipname(u->ship));
}
2010-08-08 10:06:34 +02:00
}
}
2011-03-07 08:02:35 +01:00
for (ru = a_find(r->attribs, &at_travelunit);
ru && ru->type == &at_travelunit; ru = ru->next) {
unit *u = (unit *) ru->data.v;
if (cansee_durchgezogen(f, r, u, 0) && r != u->region) {
if (!u->ship) {
if (!seeunits) {
fprintf(F, "DURCHREISE\n");
}
seeunits = true;
fprintf(F, "\"%s\"\n", unitname(u));
}
2010-08-08 10:06:34 +02:00
}
}
}
cr_output_messages(F, r->msgs, f);
{
2011-03-07 08:02:35 +01:00
message_list *mlist = r_getmessages(r, f);
if (mlist)
cr_output_messages(F, mlist, f);
2010-08-08 10:06:34 +02:00
}
/* buildings */
for (b = rbuildings(r); b; b = b->next) {
int fno = -1;
u = building_owner(b);
if (u && !fval(u, UFL_ANON_FACTION)) {
2011-03-07 08:02:35 +01:00
const faction *sf = visible_faction(f, u);
2010-08-08 10:06:34 +02:00
fno = sf->no;
}
cr_output_building(F, b, u, fno, f);
}
/* ships */
for (sh = r->ships; sh; sh = sh->next) {
int fno = -1;
u = ship_owner(sh);
2010-08-08 10:06:34 +02:00
if (u && !fval(u, UFL_ANON_FACTION)) {
2011-03-07 08:02:35 +01:00
const faction *sf = visible_faction(f, u);
2010-08-08 10:06:34 +02:00
fno = sf->no;
}
cr_output_ship(F, sh, u, fno, f, r);
}
/* visible units */
for (u = r->units; u; u = u->next) {
2011-03-07 08:02:35 +01:00
if (u->building || u->ship || (stealthmod > INT_MIN
&& cansee(f, r, u, stealthmod))) {
2010-08-08 10:06:34 +02:00
cr_output_unit(F, r, f, u, sr->mode);
}
}
}
}
/* main function of the creport. creates the header and traverses all regions */
static int
2011-03-07 08:02:35 +01:00
report_computer(const char *filename, report_context * ctx, const char *charset)
2010-08-08 10:06:34 +02:00
{
static int era = -1;
int i;
2011-03-07 08:02:35 +01:00
faction *f = ctx->f;
const char *prefix;
region *r;
const char *mailto = locale_string(f->locale, "mailto");
const attrib *a;
seen_region *sr = NULL;
2010-08-08 10:06:34 +02:00
#if SCORE_MODULE
int score = 0, avgscore = 0;
#endif
int enc = xmlParseCharEncoding(charset);
2011-03-07 08:02:35 +01:00
FILE *F = fopen(filename, "wt");
if (era < 0) {
2010-08-08 10:06:34 +02:00
era = get_param_int(global.parameters, "world.era", 2);
}
2011-03-07 08:02:35 +01:00
if (F == NULL) {
2010-08-08 10:06:34 +02:00
perror(filename);
return -1;
2011-03-07 08:02:35 +01:00
} else if (enc == XML_CHAR_ENCODING_UTF8) {
2011-03-08 07:31:06 +01:00
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
2010-08-08 10:06:34 +02:00
fwrite(utf8_bom, 1, 3, F);
}
/* must call this to get all the neighbour regions */
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* initialisations, header and lists */
fprintf(F, "VERSION %d\n", C_REPORT_VERSION);
fprintf(F, "\"%s\";charset\n", charset);
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
fprintf(F, "%d;noskillpoints\n", 1);
fprintf(F, "%ld;date\n", ctx->report_time);
fprintf(F, "\"%s\";Spiel\n", global.gamename);
fprintf(F, "\"%s\";Konfiguration\n", "Standard");
fprintf(F, "\"%s\";Koordinaten\n", "Hex");
fprintf(F, "%d;Basis\n", 36);
fprintf(F, "%d;Runde\n", turn);
fprintf(F, "%d;Zeitalter\n", era);
2011-03-07 08:02:35 +01:00
if (mailto != NULL) {
2010-08-08 10:06:34 +02:00
fprintf(F, "\"%s\";mailto\n", mailto);
fprintf(F, "\"%s\";mailcmd\n", locale_string(f->locale, "mailcmd"));
}
show_alliances_cr(F, f);
fprintf(F, "PARTEI %d\n", f->no);
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
if (f_get_alliance(f)) {
fprintf(F, "%d;alliance\n", f->alliance->id);
fprintf(F, "%d;joined\n", f->alliance_joindate);
}
fprintf(F, "%d;age\n", f->age);
fprintf(F, "%d;Optionen\n", f->options);
#if SCORE_MODULE
2011-03-07 08:02:35 +01:00
if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) {
2010-08-08 10:06:34 +02:00
score = f->score;
avgscore = average_score_of_age(f->age, f->age / 24 + 1);
}
fprintf(F, "%d;Punkte\n", score);
fprintf(F, "%d;Punktedurchschnitt\n", avgscore);
#endif
{
2011-03-07 08:02:35 +01:00
const char *zRace = rc_name(f->race, 1);
2010-08-08 10:06:34 +02:00
fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace)));
}
prefix = get_prefix(f->attribs);
2011-03-07 08:02:35 +01:00
if (prefix != NULL) {
2010-08-08 10:06:34 +02:00
prefix = mkname("prefix", prefix);
fprintf(F, "\"%s\";typprefix\n",
add_translation(prefix, LOC(f->locale, prefix)));
}
fprintf(F, "%d;Rekrutierungskosten\n", f->race->recruitcost);
fprintf(F, "%d;Anzahl Personen\n", count_all(f));
fprintf(F, "\"%s\";Magiegebiet\n", magic_school[f->magiegebiet]);
if (f->race == new_race[RC_HUMAN]) {
fprintf(F, "%d;Anzahl Immigranten\n", count_migrants(f));
fprintf(F, "%d;Max. Immigranten\n", count_maxmigrants(f));
}
i = countheroes(f);
2011-03-07 08:02:35 +01:00
if (i > 0)
fprintf(F, "%d;heroes\n", i);
2010-08-08 10:06:34 +02:00
i = maxheroes(f);
2011-03-07 08:02:35 +01:00
if (i > 0)
fprintf(F, "%d;max_heroes\n", i);
2010-08-08 10:06:34 +02:00
if (f->age > 1 && f->lastorders != turn) {
2011-03-07 08:02:35 +01:00
fprintf(F, "%d;nmr\n", turn - f->lastorders);
2010-08-08 10:06:34 +02:00
}
fprintf(F, "\"%s\";Parteiname\n", f->name);
fprintf(F, "\"%s\";email\n", f->email);
2011-03-07 08:02:35 +01:00
if (f->banner)
fprintf(F, "\"%s\";banner\n", f->banner);
2010-08-08 10:06:34 +02:00
print_items(F, f->items, f->locale);
fputs("OPTIONEN\n", F);
2011-03-07 08:02:35 +01:00
for (i = 0; i != MAXOPTIONS; ++i) {
2010-08-08 10:06:34 +02:00
int flag = want(i);
if (options[i]) {
2011-03-07 08:02:35 +01:00
fprintf(F, "%d;%s\n", (f->options & flag) ? 1 : 0, options[i]);
} else if (f->options & flag) {
2010-08-08 10:06:34 +02:00
f->options &= (~flag);
}
}
show_allies_cr(F, f, f->allies);
{
2011-03-07 08:02:35 +01:00
group *g;
for (g = f->groups; g; g = g->next) {
2010-08-08 10:06:34 +02:00
fprintf(F, "GRUPPE %d\n", g->gid);
fprintf(F, "\"%s\";name\n", g->name);
prefix = get_prefix(g->attribs);
2011-03-07 08:02:35 +01:00
if (prefix != NULL) {
2010-08-08 10:06:34 +02:00
prefix = mkname("prefix", prefix);
fprintf(F, "\"%s\";typprefix\n",
add_translation(prefix, LOC(f->locale, prefix)));
}
show_allies_cr(F, f, g->allies);
}
}
cr_output_messages(F, f->msgs, f);
{
2011-03-07 08:02:35 +01:00
struct bmsg *bm;
for (bm = f->battles; bm; bm = bm->next) {
plane *pl = rplane(bm->r);
2010-08-08 10:06:34 +02:00
int plid = plane_id(pl);
2011-03-07 08:02:35 +01:00
region *r = bm->r;
2010-08-08 10:06:34 +02:00
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
2011-03-07 08:02:35 +01:00
if (!plid)
fprintf(F, "BATTLE %d %d\n", nx, ny);
2010-08-08 10:06:34 +02:00
else {
fprintf(F, "BATTLE %d %d %d\n", nx, ny, plid);
}
cr_output_messages(F, bm->msgs, f);
}
}
cr_find_address(F, f, ctx->addresses);
a = a_find(f->attribs, &at_reportspell);
2011-03-07 08:02:35 +01:00
while (a && a->type == &at_reportspell) {
spell *sp = (spell *) a->data.v;
2010-08-08 10:06:34 +02:00
cr_reportspell(F, sp, f->locale);
a = a->next;
}
2011-03-07 08:02:35 +01:00
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
a = a->next) {
const potion_type *ptype =
resource2potion(((const item_type *)a->data.v)->rtype);
const char *ch;
const char *description = NULL;
if (ptype == NULL)
continue;
2010-08-08 10:06:34 +02:00
ch = resourcename(ptype->itype->rtype, 0);
fprintf(F, "TRANK %d\n", hashstring(ch));
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";Name\n", add_translation(ch, locale_string(f->locale,
ch)));
2010-08-08 10:06:34 +02:00
fprintf(F, "%d;Stufe\n", ptype->level);
2011-03-07 08:02:35 +01:00
if (description == NULL) {
const char *pname = resourcename(ptype->itype->rtype, 0);
const char *potiontext = mkname("potion", pname);
2010-08-08 10:06:34 +02:00
description = LOC(f->locale, potiontext);
}
fprintf(F, "\"%s\";Beschr\n", description);
if (ptype->itype->construction) {
2011-03-07 08:02:35 +01:00
requirement *m = ptype->itype->construction->materials;
2010-08-08 10:06:34 +02:00
fprintf(F, "ZUTATEN\n");
while (m->number) {
ch = resourcename(m->rtype, 0);
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\"\n", add_translation(ch, locale_string(f->locale,
ch)));
2010-08-08 10:06:34 +02:00
m++;
}
}
}
/* traverse all regions */
2011-03-07 08:02:35 +01:00
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
2010-08-08 10:06:34 +02:00
sr = find_seen(ctx->seen, r);
}
2011-03-07 08:02:35 +01:00
for (; sr != NULL; sr = sr->next) {
2010-08-08 10:06:34 +02:00
cr_output_region(F, ctx, sr);
}
report_crtypes(F, f->locale);
write_translations(F);
reset_translations();
fclose(F);
return 0;
}
2011-03-07 08:02:35 +01:00
int crwritemap(const char *filename)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
FILE *F = fopen(filename, "w");
region *r;
2010-08-08 10:06:34 +02:00
fprintf(F, "VERSION %d\n", C_REPORT_VERSION);
fputs("\"UTF-8\";charset\n", F);
2011-03-07 08:02:35 +01:00
for (r = regions; r; r = r->next) {
plane *pl = rplane(r);
2010-08-08 10:06:34 +02:00
int plid = plane_id(pl);
if (plid) {
fprintf(F, "REGION %d %d %d\n", r->x, r->y, plid);
} else {
fprintf(F, "REGION %d %d\n", r->x, r->y);
}
2011-03-07 08:02:35 +01:00
fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale),
LOC(default_locale, terrain_name(r)));
2010-08-08 10:06:34 +02:00
}
fclose(F);
return 0;
}
2011-03-07 08:02:35 +01:00
void register_cr(void)
2010-08-08 10:06:34 +02:00
{
tsf_register("report", &cr_ignore);
tsf_register("string", &cr_string);
tsf_register("order", &cr_order);
tsf_register("spell", &cr_spell);
tsf_register("curse", &cr_curse);
tsf_register("int", &cr_int);
tsf_register("unit", &cr_unit);
tsf_register("region", &cr_region);
tsf_register("faction", &cr_faction);
tsf_register("ship", &cr_ship);
tsf_register("building", &cr_building);
tsf_register("skill", &cr_skill);
tsf_register("resource", &cr_resource);
tsf_register("race", &cr_race);
tsf_register("direction", &cr_int);
tsf_register("alliance", &cr_alliance);
tsf_register("resources", &cr_resources);
tsf_register("items", &cr_resources);
tsf_register("regions", &cr_regions);
2011-03-07 08:02:35 +01:00
if (!nocr)
register_reporttype("cr", &report_computer, 1 << O_COMPUTER);
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
void creport_cleanup(void)
2010-08-08 10:06:34 +02:00
{
while (junkyard) {
2011-03-07 08:02:35 +01:00
translation *t = junkyard;
2010-08-08 10:06:34 +02:00
junkyard = junkyard->next;
free(t);
}
junkyard = 0;
}