server/src/gamecode/summary.c

414 lines
11 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
/* vi: set ts=2:
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
* | | Enno Rehling <enno@eressea.de>
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
* | (c) 1998 - 2007 |
* | | This program may not be used, modified or distributed
* +-------------------+ without prior permission by the authors of Eressea.
*
*/
/* wenn platform.h nicht vor curses included wird, kompiliert es unter windows nicht */
#include <platform.h>
#include <kernel/config.h>
#include "summary.h"
#include "laws.h"
#include <kernel/alliance.h>
#include <kernel/calendar.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/reports.h>
#include <kernel/save.h>
#include <kernel/skill.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/lists.h>
#include <string.h>
2011-03-07 08:02:35 +01:00
#undef SUMMARY_BOM /* write a BOM in the summary file */
2010-08-08 10:06:34 +02:00
typedef struct summary {
int waffen;
int factions;
int ruestungen;
int schiffe;
int gebaeude;
int maxskill;
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 {
2011-03-07 08:02:35 +01:00
struct language *next;
2010-08-08 10:06:34 +02:00
int number;
2011-03-07 08:02:35 +01:00
const struct locale *locale;
} *languages;
2010-08-08 10:06:34 +02:00
} summary;
2011-03-07 08:02:35 +01:00
static char *pcomp(double i, double j)
2010-08-08 10:06:34 +02:00
{
static char buf[32];
2011-03-07 08:02:35 +01:00
sprintf(buf, "%.0f (%s%.0f)", i, (i >= j) ? "+" : "", i - j);
2010-08-08 10:06:34 +02:00
return buf;
}
2011-03-07 08:02:35 +01:00
static char *rcomp(int i, int j)
2010-08-08 10:06:34 +02:00
{
static char buf[32];
sprintf(buf, "%d (%s%d,%s%d%%)",
2011-03-07 08:02:35 +01:00
i, (i >= j) ? "+" : "", i - j, (i >= j) ? "+" : "",
j ? ((i - j) * 100) / j : 0);
2010-08-08 10:06:34 +02:00
return buf;
}
2011-03-07 08:02:35 +01:00
static void out_faction(FILE * file, const struct faction *f)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
if (alliances != NULL) {
2010-08-08 10:06:34 +02:00
fprintf(file, "%s (%s/%d) (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\n",
2011-03-07 08:02:35 +01:00
f->name, itoa36(f->no), f_get_alliance(f) ? f->alliance->id : 0,
2010-08-08 10:06:34 +02:00
LOC(default_locale, rc_name(f->race, 0)), magic_school[f->magiegebiet],
f->no_units, f->num_total, f->money, turn - f->lastorders);
} else {
fprintf(file, "%s (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\n",
factionname(f), LOC(default_locale, rc_name(f->race, 0)),
magic_school[f->magiegebiet], f->no_units, f->num_total, f->money,
turn - f->lastorders);
}
}
2011-03-07 08:02:35 +01:00
static char *gamedate2(const struct locale *lang)
2010-08-08 10:06:34 +02: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]),
2011-03-07 08:02:35 +01:00
gd.year, agename ? LOC(lang, agename) : "");
2010-08-08 10:06:34 +02:00
return buf;
}
2011-03-07 08:02:35 +01:00
static void writeturn(void)
2010-08-08 10:06:34 +02:00
{
char zText[MAX_PATH];
FILE *f;
sprintf(zText, "%s/datum", basepath());
f = cfopen(zText, "w");
2011-03-07 08:02:35 +01:00
if (!f)
return;
2010-08-08 10:06:34 +02:00
fputs(gamedate2(default_locale), f);
fclose(f);
sprintf(zText, "%s/turn", basepath());
f = cfopen(zText, "w");
2011-03-07 08:02:35 +01:00
if (!f)
return;
2010-08-08 10:06:34 +02:00
fprintf(f, "%d\n", turn);
fclose(f);
}
2011-03-07 08:02:35 +01:00
void report_summary(summary * s, summary * o, boolean full)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
FILE *F = NULL;
2010-08-08 10:06:34 +02:00
int i, newplayers = 0;
2011-03-07 08:02:35 +01:00
faction *f;
2010-08-08 10:06:34 +02:00
char zText[MAX_PATH];
if (full) {
sprintf(zText, "%s/parteien.full", basepath());
} else {
sprintf(zText, "%s/parteien", basepath());
}
F = cfopen(zText, "w");
2011-03-07 08:02:35 +01:00
if (!F)
return;
2010-08-08 10:06:34 +02:00
#ifdef SUMMARY_BOM
else {
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);
}
#endif
printf("Schreibe Zusammenfassung (parteien)...\n");
2011-03-07 08:02:35 +01:00
fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale));
fprintf(F, "Auswertung Nr: %d\n\n", turn);
fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions));
fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits));
fprintf(F, "Spielerpopulation: %s\n", pcomp(s->playerpop, o->playerpop));
fprintf(F, " davon bewaffnet: %s\n", pcomp(s->armed_men, o->armed_men));
fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes));
2010-08-08 10:06:34 +02:00
if (full) {
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);
}
for (i = 0; i < MAXRACES; i++) {
2011-03-07 08:02:35 +01:00
const race *rc = new_race[i];
2010-08-08 10:06:34 +02:00
if (s->factionrace[i] && rc && playerrace(rc)
&& i != RC_TEMPLATE && i != RC_CLONE) {
2011-03-07 08:02:35 +01:00
fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, 3)),
LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i],
o->factionrace[i]));
2010-08-08 10:06:34 +02:00
}
}
2011-03-07 08:02:35 +01:00
if (full) {
2010-08-08 10:06:34 +02:00
fprintf(F, "\n");
{
2011-03-07 08:02:35 +01:00
struct language *plang = s->languages;
while (plang != NULL) {
struct language *olang = o->languages;
2010-08-08 10:06:34 +02:00
int nold = 0;
2011-03-07 08:02:35 +01:00
while (olang && olang->locale != plang->locale)
olang = olang->next;
if (olang)
nold = olang->number;
2010-08-08 10:06:34 +02:00
fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale),
rcomp(plang->number, nold));
2011-03-07 08:02:35 +01:00
plang = plang->next;
2010-08-08 10:06:34 +02:00
}
}
}
fprintf(F, "\n");
if (full) {
for (i = 0; i < MAXRACES; i++) {
2011-03-07 08:02:35 +01:00
const race *rc = new_race[i];
2010-08-08 10:06:34 +02:00
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++) {
2011-03-07 08:02:35 +01:00
const race *rc = new_race[i];
2010-08-08 10:06:34 +02:00
if (s->poprace[i] && playerrace(rc)
&& i != RC_TEMPLATE && i != RC_CLONE) {
2011-03-07 08:02:35 +01:00
fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)),
rcomp(s->poprace[i], o->poprace[i]));
2010-08-08 10:06:34 +02:00
}
}
}
if (full) {
2011-03-07 08:02:35 +01:00
fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen, o->waffen));
2010-08-08 10:06:34 +02:00
fprintf(F, "Ruestungen: %s\n",
2011-03-07 08:02:35 +01:00
pcomp(s->ruestungen, o->ruestungen));
2010-08-08 10:06:34 +02:00
fprintf(F, "ungezaehmte Pferde: %s\n", pcomp(s->pferde, o->pferde));
fprintf(F, "gezaehmte Pferde: %s\n",
2011-03-07 08:02:35 +01:00
pcomp(s->spielerpferde, o->spielerpferde));
2010-08-08 10:06:34 +02:00
fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe));
fprintf(F, "Gebaeude: %s\n", pcomp(s->gebaeude, o->gebaeude));
2011-03-07 08:02:35 +01:00
fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants, o->peasants));
2010-08-08 10:06:34 +02:00
2011-03-07 08:02:35 +01:00
fprintf(F, "Population gesamt: %d\n\n", s->playerpop + s->peasants);
2010-08-08 10:06:34 +02:00
fprintf(F, "Reichtum Spieler: %s Silber\n",
2011-03-07 08:02:35 +01:00
pcomp(s->playermoney, o->playermoney));
2010-08-08 10:06:34 +02:00
fprintf(F, "Reichtum Bauern: %s Silber\n",
pcomp(s->peasantmoney, o->peasantmoney));
fprintf(F, "Reichtum gesamt: %s Silber\n\n",
2011-03-07 08:02:35 +01:00
pcomp(s->playermoney + s->peasantmoney,
o->playermoney + o->peasantmoney));
2010-08-08 10:06:34 +02:00
}
fprintf(F, "\n\n");
newplayers = update_nmrs();
for (i = 0; i <= NMRTimeout(); ++i) {
if (i == NMRTimeout()) {
fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]);
} else {
fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]);
}
}
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");
for (f = factions; f; f = f->next) {
out_faction(F, f);
}
if (NMRTimeout() && full) {
fprintf(F, "\n\nFactions with NMRs:\n");
for (i = NMRTimeout(); i > 0; --i) {
2011-03-07 08:02:35 +01:00
for (f = factions; f; f = f->next) {
if (i == NMRTimeout()) {
if (turn - f->lastorders >= i) {
2010-08-08 10:06:34 +02:00
out_faction(F, f);
}
} else {
2011-03-07 08:02:35 +01:00
if (turn - f->lastorders == i) {
2010-08-08 10:06:34 +02:00
out_faction(F, f);
}
}
}
}
}
}
fclose(F);
if (full) {
printf("writing date & turn\n");
writeturn();
}
free(nmrs);
nmrs = NULL;
}
2011-03-07 08:02:35 +01:00
summary *make_summary(void)
2010-08-08 10:06:34 +02:00
{
faction *f;
region *r;
unit *u;
2011-03-07 08:02:35 +01:00
summary *s = calloc(1, sizeof(summary));
2010-08-08 10:06:34 +02:00
for (f = factions; f; f = f->next) {
2011-03-07 08:02:35 +01:00
const struct locale *lang = f->locale;
struct language *plang = s->languages;
while (plang && plang->locale != lang)
plang = plang->next;
2010-08-08 10:06:34 +02:00
if (!plang) {
plang = calloc(sizeof(struct language), 1);
plang->next = s->languages;
s->languages = plang;
plang->locale = lang;
}
++plang->number;
f->nregions = 0;
f->num_total = 0;
f->money = 0;
if (f->alive && f->units) {
s->factions++;
/* Problem mit Monsterpartei ... */
if (!is_monsters(f)) {
s->factionrace[old_race(f->race)]++;
}
}
}
/* 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)) {
s->landregionen++;
if (r->units) {
s->landregionen_mit_spielern++;
}
if (fval(r, RF_ORCIFIED)) {
s->orkifizierte_regionen++;
}
if (r->terrain == newterrain(T_VOLCANO)) {
s->inactive_volcanos++;
} else if (r->terrain == newterrain(T_VOLCANO_SMOKING)) {
s->active_volcanos++;
}
}
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
2011-03-07 08:02:35 +01:00
* incrementiert werden. */
2010-08-08 10:06:34 +02:00
2011-03-07 08:02:35 +01:00
for (u = r->units; u; u = u->next)
freset(u->faction, FFL_SELECT);
2010-08-08 10:06:34 +02:00
for (u = r->units; u; u = u->next) {
f = u->faction;
if (!is_monsters(u->faction)) {
2011-03-07 08:02:35 +01:00
skill *sv;
item *itm;
2010-08-08 10:06:34 +02:00
s->nunits++;
s->playerpop += u->number;
if (u->flags & UFL_HERO) {
s->heroes += u->number;
}
s->spielerpferde += get_item(u, I_HORSE);
s->playermoney += get_money(u);
s->armed_men += armedmen(u, true);
2011-03-07 08:02:35 +01:00
for (itm = u->items; itm; itm = itm->next) {
2010-08-08 10:06:34 +02:00
if (itm->type->rtype->wtype) {
s->waffen += itm->number;
}
if (itm->type->rtype->atype) {
s->ruestungen += itm->number;
}
}
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);
2011-03-07 08:02:35 +01:00
if (aktskill > s->maxskill)
s->maxskill = aktskill;
2010-08-08 10:06:34 +02:00
}
if (!fval(f, FFL_SELECT)) {
f->nregions++;
fset(f, FFL_SELECT);
}
}
f->num_total += u->number;
f->money += get_money(u);
s->poprace[old_race(u->race)] += u->number;
}
}
}
return s;
}