make summary a little prettier.

This commit is contained in:
Enno Rehling 2018-01-28 11:37:42 +01:00
parent b6e8822044
commit 70cc56b223
2 changed files with 41 additions and 12 deletions

View file

@ -169,10 +169,43 @@ static void writeturn(void)
fclose(f); fclose(f);
} }
void report_summary(summary * s, bool full) static int count_umlaut(const char *s)
{
int result = 0;
const char *cp;
for (cp = s; *cp; ++cp) {
if (*cp & 0x80) {
++result;
}
}
return result;
}
static void summarize_players(const summary *s, FILE *F) {
int i;
const char * suffix = LOC(default_locale, "stat_tribe_p");
for (i = 0; i < MAXRACES; i++) {
if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) {
const race *rc = get_race(i);
if (rc && playerrace(rc)) {
int lpad = 6;
const char * pad = " ";
const char *rccat = LOC(default_locale, rc_name_s(rc, NAME_CATEGORY));
fprintf(F, "%16s%s:", rccat, suffix);
lpad -= count_umlaut(rccat);
assert(lpad >= 0);
fputs(pad + lpad, F);
fprintf(F, "%8d\n", s->factionrace[i]);
}
}
}
}
void report_summary(const summary * s, bool full)
{ {
FILE *F = NULL; FILE *F = NULL;
int i, newplayers = 0; int newplayers = 0;
faction *f; faction *f;
char zText[4096]; char zText[4096];
int timeout = NMRTimeout(); int timeout = NMRTimeout();
@ -213,15 +246,7 @@ void report_summary(summary * s, bool full)
fprintf(F, "Aktive Vulkane: %8d\n\n", s->active_volcanos); fprintf(F, "Aktive Vulkane: %8d\n\n", s->active_volcanos);
} }
for (i = 0; i < MAXRACES; i++) { summarize_players(s, F);
if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) {
const race *rc = get_race(i);
if (rc && playerrace(rc)) {
fprintf(F, "%13s%s: %8d\n", LOC(default_locale, rc_name_s(rc, NAME_CATEGORY)),
LOC(default_locale, "stat_tribe_p"), s->factionrace[i]);
}
}
}
if (full) { if (full) {
fprintf(F, "\n"); fprintf(F, "\n");
@ -237,6 +262,7 @@ void report_summary(summary * s, bool full)
fprintf(F, "\n"); fprintf(F, "\n");
if (full) { if (full) {
int i;
for (i = 0; i < MAXRACES; i++) { for (i = 0; i < MAXRACES; i++) {
if (s->poprace[i]) { if (s->poprace[i]) {
const race *rc = get_race(i); const race *rc = get_race(i);
@ -246,6 +272,7 @@ void report_summary(summary * s, bool full)
} }
} }
else { else {
int i;
for (i = 0; i < MAXRACES; i++) { for (i = 0; i < MAXRACES; i++) {
if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) { if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) {
const race *rc = get_race(i); const race *rc = get_race(i);
@ -280,6 +307,7 @@ void report_summary(summary * s, bool full)
newplayers = update_nmrs(); newplayers = update_nmrs();
if (nmrs) { if (nmrs) {
int i;
for (i = 0; i <= timeout; ++i) { for (i = 0; i <= timeout; ++i) {
if (i == timeout) { if (i == timeout) {
fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]); fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]);
@ -308,6 +336,7 @@ void report_summary(summary * s, bool full)
} }
if (timeout>0 && full) { if (timeout>0 && full) {
int i;
fprintf(F, "\n\nFactions with NMRs:\n"); fprintf(F, "\n\nFactions with NMRs:\n");
for (i = timeout; i > 0; --i) { for (i = timeout; i > 0; --i) {
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {

View file

@ -19,7 +19,7 @@ extern "C" {
struct summary; struct summary;
void report_summary(struct summary *sum, bool full); void report_summary(const struct summary *sum, bool full);
struct summary *make_summary(void); struct summary *make_summary(void);
void free_summary(struct summary *sum); void free_summary(struct summary *sum);
int update_nmrs(void); int update_nmrs(void);