From 6acb1e22c569c3d361ffb634c03f010da77a6854 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 9 Aug 2007 06:42:37 +0000 Subject: [PATCH] - fixed the summary.c - implemented unicode_utf8_strcasecmp function - fixed some xml files - code compiles and runs on the console TODO: * switch from xmlChar to char again * eliminate remaining warnings * report.[hc] are still disabled OPTIONAL: * handle latin1 input? --- src/common/gamecode/laws.c | 6 +- src/common/gamecode/laws.h | 3 + src/common/gamecode/report.c | 399 --------------------------------- src/common/gamecode/report.h | 4 - src/common/gamecode/spells.h | 14 +- src/common/gamecode/summary.c | 407 ++++++++++++++++++++++++++++++++++ src/common/gamecode/summary.h | 25 +++ src/common/kernel/group.c | 4 +- src/common/kernel/item.c | 4 +- src/common/kernel/reports.c | 40 ++-- src/common/kernel/reports.h | 4 +- src/common/kernel/xmlreader.c | 11 +- src/common/races/races.c | 9 +- src/common/spells/spells.h | 1 + src/common/util/unicode.c | 31 +++ src/common/util/unicode.h | 1 + src/eressea/lua/gamecode.cpp | 80 +------ src/eressea/server.cpp | 7 - src/res/messages.xml | 14 +- src/res/races.xml | 2 +- src/scripts/default.lua | 19 +- 21 files changed, 550 insertions(+), 535 deletions(-) create mode 100644 src/common/gamecode/summary.c create mode 100644 src/common/gamecode/summary.h diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index e4c7582b3..b2dce521e 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -119,9 +119,6 @@ #define DMRISEHAFEN 0.2F /* weekly chance that demand goes up with harbor */ -/* - external symbols ------------------------------------------ */ -extern int dropouts[2]; -extern int * age; /* - exported global symbols ----------------------------------- */ boolean nobattle = false; boolean nomonsters = false; @@ -1027,6 +1024,9 @@ quit(void) } } +int dropouts[2]; +int * age = NULL; + static void parse_restart(void) { diff --git a/src/common/gamecode/laws.h b/src/common/gamecode/laws.h index 2cd2d7344..d9308496a 100644 --- a/src/common/gamecode/laws.h +++ b/src/common/gamecode/laws.h @@ -38,6 +38,9 @@ void update_guards(void); void processorders(void); extern struct attrib_type at_germs; +extern int dropouts[2]; +extern int * age; + #ifdef __cplusplus } #endif diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 1caa549b6..203c0563c 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -101,12 +101,6 @@ extern int *storms; extern int weeks_per_month; extern int months_per_year; -boolean nocr = false; -boolean nonr = false; -boolean nosh = false; -boolean nomer = false; -boolean noreports = false; - static size_t strxcpy(char * dst, const char * src) { size_t s = 0; @@ -132,21 +126,6 @@ gamedate_season(const struct locale * lang) return buf; } -static char * -gamedate2(const struct locale * lang) -{ - 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; -} - void rpc(FILE * F, char c, size_t num) { @@ -2187,26 +2166,6 @@ struct fsee { #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; -} - unit * can_find(faction * f, faction * f2) @@ -2284,166 +2243,6 @@ kann_finden(faction * f1, faction * f2) 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; - 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; -} summary; - -summary * -make_summary(void) -{ - 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) { - 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 (f->no!=MONSTER_FACTION) { - 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 (rterrain(r) == T_VOLCANO) { - s->inactive_volcanos++; - } else if(rterrain(r) == 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 - * incrementiert werden. */ - - for (u = r->units; u; u = u->next) freset(u->faction, FFL_SELECT); - for (u = r->units; u; u = u->next) { - f = u->faction; - if (u->faction->no != MONSTER_FACTION) { - skill * sv; - item * itm; - - 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); - 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; - } - } - - 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); - if (aktskill > s->maxskill) s->maxskill = aktskill; - } - 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; -} - -static char * -pcomp(double i, double j) -{ - sprintf(buf, "%.0f (%s%.0f)", i, (i>=j)?"+":"", i-j); - 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) { @@ -2525,204 +2324,6 @@ writemonument(void) } -static void -writeturn(void) -{ - char zText[MAX_PATH]; - FILE *f; - - sprintf(zText, "%s/datum", basepath()); - f = cfopen(zText, "w"); - if (!f) return; - fputs(gamedate2(default_locale), f); - fclose(f); - sprintf(zText, "%s/turn", basepath()); - f = cfopen(zText, "w"); - if (!f) return; - fprintf(f, "%d\n", turn); - fclose(f); -} - -static void -out_faction(FILE *file, faction *f) -{ - if (alliances!=NULL) { - fprintf(file, "%s (%s/%d) (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\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); - } else { - fprintf(file, "%s (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\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); - } -} - -void -report_summary(summary * s, summary * o, boolean full) -{ - FILE * F = NULL; - int i, newplayers = 0; - faction * f; - char zText[MAX_PATH]; - - if (full) { - sprintf(zText, "%s/parteien.full", basepath()); - } else { - sprintf(zText, "%s/parteien", basepath()); - } - F = cfopen(zText, "w"); - if (!F) return; - printf("Schreibe Zusammenfassung (parteien)...\n"); - 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)); -#ifdef HEROES - fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes)); -#endif - - 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++) { - const race * rc = new_race[i]; - if (s->factionrace[i] && rc && playerrace(rc) - && i != RC_TEMPLATE && i != RC_CLONE) { - fprintf(F, "%14svölker: %s\n", LOC(default_locale, rc_name(rc, 3)), - pcomp(s->factionrace[i], o->factionrace[i])); - } - } - - 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; - } - } - } - - 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])); - } - } - } - - if (full) { - fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen,o->waffen)); - fprintf(F, "Rüstungen: %s\n", - pcomp(s->ruestungen,o->ruestungen)); - fprintf(F, "ungezähmte Pferde: %s\n", pcomp(s->pferde, o->pferde)); - fprintf(F, "gezähmte Pferde: %s\n", - pcomp(s->spielerpferde,o->spielerpferde)); - fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe)); - fprintf(F, "Gebä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", - pcomp(s->playermoney,o->playermoney)); - fprintf(F, "Reichtum Bauern: %s Silber\n", - pcomp(s->peasantmoney, o->peasantmoney)); - fprintf(F, "Reichtum gesamt: %s Silber\n\n", - pcomp(s->playermoney+s->peasantmoney, o->playermoney+o->peasantmoney)); - } - - 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) { - 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); - - if (full) { - printf("writing date & turn\n"); - writeturn(); - - writemonument(); - } - free(nmrs); - nmrs = NULL; -} /******* end summary ******/ static void diff --git a/src/common/gamecode/report.h b/src/common/gamecode/report.h index 6c18c01f6..79c1c39da 100644 --- a/src/common/gamecode/report.h +++ b/src/common/gamecode/report.h @@ -18,10 +18,6 @@ extern "C" { extern void report_init(void); extern void report_cleanup(void); - struct summary; - extern void report_summary(struct summary * n, struct summary * o, boolean full); - extern struct summary * make_summary(void); - #ifdef __cplusplus } #endif diff --git a/src/common/gamecode/spells.h b/src/common/gamecode/spells.h index 9df06274d..64998ae08 100644 --- a/src/common/gamecode/spells.h +++ b/src/common/gamecode/spells.h @@ -2,14 +2,20 @@ * +-------------------+ Christian Schlittchen * | | Enno Rehling * | Eressea PBEM host | Katja Zedel - * | (c) 1998 - 2005 | + * | (c) 1998 - 2007 | * | | This program may not be used, modified or distributed * +-------------------+ without prior permission by the authors of Eressea. */ #ifndef GC_SPELLS_H #define GC_SPELLS_H - -extern void register_gcspells(void); - +#ifdef __cplusplus +extern "C" { +#endif + + extern void register_gcspells(void); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/common/gamecode/summary.c b/src/common/gamecode/summary.c new file mode 100644 index 000000000..051f58d38 --- /dev/null +++ b/src/common/gamecode/summary.c @@ -0,0 +1,407 @@ +/* vi: set ts=2: + * +-------------------+ Christian Schlittchen + * | | Enno Rehling + * | Eressea PBEM host | Katja Zedel + * | (c) 1998 - 2007 | + * | | This program may not be used, modified or distributed + * +-------------------+ without prior permission by the authors of Eressea. + * + */ + +/* wenn config.h nicht vor curses included wird, kompiliert es unter windows nicht */ +#include +#include + +#include "summary.h" + +#include "laws.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +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 { + struct language * next; + int number; + const struct locale * locale; + } * languages; +} summary; + +static char * +pcomp(double i, double j) +{ + static char buf[32]; + sprintf(buf, "%.0f (%s%.0f)", i, (i>=j)?"+":"", i-j); + return buf; +} + +static char * +rcomp(int i, int j) +{ + static char buf[32]; + sprintf(buf, "%d (%s%d,%s%d%%)", + i, (i>=j)?"+":"", i-j, (i>=j)?"+":"",j?((i-j)*100)/j:0); + return buf; +} + + +static void +out_faction(FILE *file, const struct faction *f) +{ + if (alliances!=NULL) { + fprintf(file, "%s (%s/%d) (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\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); + } else { + fprintf(file, "%s (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\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); + } +} + +static char * +gamedate2(const struct locale * lang) +{ + 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; +} + +static void +writeturn(void) +{ + char zText[MAX_PATH]; + FILE *f; + + sprintf(zText, "%s/datum", basepath()); + f = cfopen(zText, "w"); + if (!f) return; + fputs(gamedate2(default_locale), f); + fclose(f); + sprintf(zText, "%s/turn", basepath()); + f = cfopen(zText, "w"); + if (!f) return; + fprintf(f, "%d\n", turn); + fclose(f); +} + +void +report_summary(summary * s, summary * o, boolean full) +{ + FILE * F = NULL; + int i, newplayers = 0; + faction * f; + char zText[MAX_PATH]; + + if (full) { + sprintf(zText, "%s/parteien.full", basepath()); + } else { + sprintf(zText, "%s/parteien", basepath()); + } + F = cfopen(zText, "w"); + if (!F) return; + printf("Schreibe Zusammenfassung (parteien)...\n"); + 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)); +#ifdef HEROES + fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes)); +#endif + + 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++) { + const race * rc = new_race[i]; + if (s->factionrace[i] && rc && playerrace(rc) + && i != RC_TEMPLATE && i != RC_CLONE) { + fprintf(F, "%14svölker: %s\n", LOC(default_locale, rc_name(rc, 3)), + pcomp(s->factionrace[i], o->factionrace[i])); + } + } + + 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; + } + } + } + + 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])); + } + } + } + + if (full) { + fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen,o->waffen)); + fprintf(F, "Rüstungen: %s\n", + pcomp(s->ruestungen,o->ruestungen)); + fprintf(F, "ungezähmte Pferde: %s\n", pcomp(s->pferde, o->pferde)); + fprintf(F, "gezähmte Pferde: %s\n", + pcomp(s->spielerpferde,o->spielerpferde)); + fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe)); + fprintf(F, "Gebä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", + pcomp(s->playermoney,o->playermoney)); + fprintf(F, "Reichtum Bauern: %s Silber\n", + pcomp(s->peasantmoney, o->peasantmoney)); + fprintf(F, "Reichtum gesamt: %s Silber\n\n", + pcomp(s->playermoney+s->peasantmoney, o->playermoney+o->peasantmoney)); + } + + 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) { + 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); + + if (full) { + printf("writing date & turn\n"); + writeturn(); + } + free(nmrs); + nmrs = NULL; +} + +summary * +make_summary(void) +{ + 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) { + 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 (f->no!=MONSTER_FACTION) { + 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 (rterrain(r) == T_VOLCANO) { + s->inactive_volcanos++; + } else if(rterrain(r) == 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 + * incrementiert werden. */ + + for (u = r->units; u; u = u->next) freset(u->faction, FFL_SELECT); + for (u = r->units; u; u = u->next) { + f = u->faction; + if (u->faction->no != MONSTER_FACTION) { + skill * sv; + item * itm; + + 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); + 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; + } + } + + 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); + if (aktskill > s->maxskill) s->maxskill = aktskill; + } + 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; +} diff --git a/src/common/gamecode/summary.h b/src/common/gamecode/summary.h new file mode 100644 index 000000000..f7419a30b --- /dev/null +++ b/src/common/gamecode/summary.h @@ -0,0 +1,25 @@ +/* vi: set ts=2: + * +-------------------+ Christian Schlittchen + * | | Enno Rehling + * | Eressea PBEM host | Katja Zedel + * | (c) 1998 - 2007 | + * | | This program may not be used, modified or distributed + * +-------------------+ without prior permission by the authors of Eressea. + * + */ + +#ifndef H_GC_SUMMARY +#define H_GC_SUMMARY + +#ifdef __cplusplus +extern "C" { +#endif + + struct summary; + extern void report_summary(struct summary * n, struct summary * o, boolean full); + extern struct summary * make_summary(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/common/kernel/group.c b/src/common/kernel/group.c index 11930d507..8d281ff50 100644 --- a/src/common/kernel/group.c +++ b/src/common/kernel/group.c @@ -29,10 +29,12 @@ #include #include #include +#include /* libc includes */ #include #include +#include #define GMAXHASH 2039 static group * ghash[GMAXHASH]; @@ -73,7 +75,7 @@ init_group(faction * f, group * g) static group * find_groupbyname(group * g, const xmlChar * name) { - while (g && xml_strcasecmp(name, g->name)) g = g->next; + while (g && unicode_utf8_strcasecmp(name, g->name)!=0) g = g->next; return g; } diff --git a/src/common/kernel/item.c b/src/common/kernel/item.c index 30cd9b06c..cbbe75498 100644 --- a/src/common/kernel/item.c +++ b/src/common/kernel/item.c @@ -330,13 +330,13 @@ rt_register(resource_type * rtype) const resource_type * item2resource(const item_type * itype) { - return itype->rtype; + return itype?itype->rtype:NULL; } const item_type * resource2item(const resource_type * rtype) { - return rtype->itype; + return rtype?rtype->itype:NULL; } const weapon_type * diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index b8e09ee6b..cf43989b4 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -63,6 +63,10 @@ #include #include +boolean nocr = false; +boolean nonr = false; +boolean noreports = false; + const char * g_reportdir; const char * visibility[] = { "none", @@ -1353,11 +1357,7 @@ nmr_warnings(void) for (fa=factions;fa;fa=fa->next) { if (alliedfaction(NULL, f, fa, FRIEND) && alliedfaction(NULL, fa, f, FRIEND)) { if (msg==NULL) { - char buf[4096]; - sprintf(buf, "Achtung: %s hat einige Zeit keine " - "Züge eingeschickt und könnte dadurch in Kürze aus dem " - "Spiel ausscheiden.", factionname(f)); - msg = msg_message("msg_event", "string", buf); + msg = msg_message("warn_dropout", "faction", f); } add_message(&fa->msgs, msg); } @@ -1443,22 +1443,24 @@ global_report(const char * filename) } #endif -void -writeaddresses(void) +int +init_reports(void) { - faction *f; - FILE *F; - char zText[MAX_PATH]; - sprintf(zText, "%s/addresses", basepath()); - F = cfopen(zText, "w"); - if (!F) return; + update_intervals(); - 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); +#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; } } - fclose(F); + return 0; } int @@ -1478,7 +1480,7 @@ reports(void) sprintf(path, "%s/reports.txt", reportpath()); mailit = fopen(path, "w"); if (mailit == NULL) { - log_error(("%s konnte nicht geöffnet werden!\n", path)); + log_error(("%s could not be opened!\n", path)); } for (f = factions; f; f = f->next) { @@ -1557,7 +1559,7 @@ static variant var_copy_regions(variant x) { region_list * rsrc; - size_t size = 0; + int size = 0; for (rsrc = (region_list*)x.v; rsrc!=NULL; rsrc=rsrc->next) { ++size; diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 031ada85c..8fe5d36c1 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -32,6 +32,9 @@ extern "C" { extern const char *directions[]; extern const char *coasts[]; +extern boolean nonr; +extern boolean nocr; +extern boolean noreports; /* kann_finden speedups */ extern boolean kann_finden(struct faction * f1, struct faction * f2); @@ -100,7 +103,6 @@ extern int bufunit(const struct faction * f, const struct unit * u, int indent, extern const char * reportpath(void); extern const xmlChar * trailinto(const struct region * r, const struct locale * lang); extern const xmlChar * report_kampfstatus(const struct unit * u, const struct locale * lang); - extern void writeaddresses(void); extern void reports_init(void); diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 84307d4d5..32ec27029 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -458,11 +458,14 @@ parse_directions(xmlDocPtr doc) xpathDirections = xmlXPathEvalExpression(BAD_CAST "/eressea/directions/dir", xpath); nsetDirections = xpathDirections->nodesetval; if (nsetDirections!=NULL) { - xmlNodePtr dir = nsetDirections->nodeTab[0]; - xmlChar * property = xmlGetProp(dir, BAD_CAST "name"); + int k; + for (k=0;k!=nsetDirections->nodeNr;++k) { + xmlNodePtr dir = nsetDirections->nodeTab[k]; + xmlChar * property = xmlGetProp(dir, BAD_CAST "name"); - register_special_direction((const char *)property); - xmlFree(property); + register_special_direction((const char *)property); + xmlFree(property); + } } xmlXPathFreeObject(xpathDirections); xmlXPathFreeContext(xpath); diff --git a/src/common/races/races.c b/src/common/races/races.c index 44883fc86..b39ba6609 100644 --- a/src/common/races/races.c +++ b/src/common/races/races.c @@ -109,7 +109,7 @@ default_spoil(const struct race * rc, int size) } /* Die Funktionen werden über den hier registrierten Namen in races.xml -* in die jeweilige Rassendefiniton eingebunden */ + * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { @@ -118,8 +118,11 @@ register_races(void) register_function((pf_generic)allowed_dragon, "movedragon"); - /* function age - * race->age() */ + register_function((pf_generic)allowed_swim, "moveswimming"); + register_function((pf_generic)allowed_fly, "moveflying"); + register_function((pf_generic)allowed_walk, "movewalking"); + + /* function age for race->age() */ register_function((pf_generic)age_undead, "ageundead"); register_function((pf_generic)age_illusion, "ageillusion"); register_function((pf_generic)age_skeleton, "ageskeleton"); diff --git a/src/common/spells/spells.h b/src/common/spells/spells.h index ee52a315d..7eeec6d1c 100644 --- a/src/common/spells/spells.h +++ b/src/common/spells/spells.h @@ -28,6 +28,7 @@ extern "C" { */ extern struct border_type bt_chaosgate; extern struct border_type bt_firewall; + typedef struct wall_data { struct unit * mage; int force; diff --git a/src/common/util/unicode.c b/src/common/util/unicode.c index 4c99ca479..bb978f062 100644 --- a/src/common/util/unicode.c +++ b/src/common/util/unicode.c @@ -13,6 +13,37 @@ #include +int +unicode_utf8_strcasecmp(const xmlChar * a, const xmlChar * b) +{ + while (*a && *b) { + int ret; + size_t size; + wint_t ucsa = *a, ucsb = *b; + + if (ucsa>0x7F) { + ret = unicode_utf8_to_ucs4(&ucsa, a, &size); + if (ret!=0) return -1; + a += size; + } else ++a; + if (ucsb>0x7F) { + ret = unicode_utf8_to_ucs4(&ucsb, b, &size); + if (ret!=0) return -1; + b += size; + } else ++b; + + if (ucsb!=ucsa) { + ucsb = towlower(ucsb); + ucsa = towlower(ucsa); + if (ucsbucsa) return -1; + } + } + if (*b) return -1; + if (*a) return 1; + return 0; +} + /* Convert a UTF-8 encoded character to UCS-4. */ int unicode_utf8_to_ucs4(wint_t *ucs4_character, const xmlChar *utf8_string, diff --git a/src/common/util/unicode.h b/src/common/util/unicode.h index 86ce3e1a1..24f7cf660 100644 --- a/src/common/util/unicode.h +++ b/src/common/util/unicode.h @@ -22,6 +22,7 @@ extern "C" { #include #define USE_UNICODE extern int unicode_utf8_to_ucs4(wint_t *ucs4_character, const xmlChar *utf8_string, size_t *length); + extern int unicode_utf8_strcasecmp(const xmlChar * a, const xmlChar * b); #ifdef __cplusplus } diff --git a/src/eressea/lua/gamecode.cpp b/src/eressea/lua/gamecode.cpp index 452673ca6..1e6dbfbf6 100644 --- a/src/eressea/lua/gamecode.cpp +++ b/src/eressea/lua/gamecode.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -65,26 +66,6 @@ lua_planmonsters(void) } } -#define ISLANDSIZE 20 -#define TURNS_PER_ISLAND 4 -static void -lua_autoseed(const char * filename, bool new_island) -{ - newfaction * players = read_newfactions(filename); - if (players!=NULL) { - rng_init(players->subscription); - while (players) { - int n = listlen(players); - int k = (n+ISLANDSIZE-1)/ISLANDSIZE; - k = n / k; - n = autoseed(&players, k, new_island || (turn % TURNS_PER_ISLAND)==0); - if (n==0) { - break; - } - } - } -} - #ifdef LUABIND_NO_EXCEPTIONS static void error_callback(lua_State * L) @@ -92,15 +73,6 @@ error_callback(lua_State * L) } #endif -static int -get_direction(const char * name) -{ - for (int i=0;i!=MAXDIRECTIONS;++i) { - if (strcasecmp(directions[i], name)==0) return i; - } - return NODIRECTION; -} - static int lua_writereport(faction * f) { @@ -115,46 +87,6 @@ lua_writereports(void) return reports(); } -static void -lua_equipunit(unit& u, const char * eqname) -{ - equip_unit(&u, get_equipment(eqname)); -} - -static void -update_subscriptions(void) -{ - FILE * F; - char zText[MAX_PATH]; - faction * f; - strcat(strcpy(zText, basepath()), "/subscriptions"); - F = fopen(zText, "r"); - if (F==NULL) { - log_info((0, "could not open %s.\n", zText)); - return; - } - for (;;) { - char zFaction[5]; - int subscription, fno; - if (fscanf(F, "%d %s", &subscription, zFaction)<=0) break; - fno = atoi36(zFaction); - f = findfaction(fno); - if (f!=NULL) { - f->subscription=subscription; - } - } - fclose(F); - - sprintf(zText, "subscriptions.%u", turn); - F = fopen(zText, "w"); - for (f=factions;f!=NULL;f=f->next) { - fprintf(F, "%s:%u:%s:%s:%s:%u:\n", - itoa36(f->no), f->subscription, f->email, f->override, - dbrace(f->race), f->lastorders); - } - fclose(F); -} - static void message_unit(unit& sender, unit& target, const char * str) { @@ -173,15 +105,6 @@ message_region(unit& sender, const char * str) ADDMSG(&sender.region->msgs, msg_message("mail_result", "unit message", &sender, str)); } -static void -lua_learnskill(unit& u, const char * skname, float chances) -{ - skill_t sk = sk_find(skname); - if (sk!=NOSKILL) { - learn_skill(&u, sk, chances); - } -} - static int read_game(const char * filename) { @@ -218,7 +141,6 @@ write_summary() summary * sum_end = make_summary(); report_summary(sum_end, sum_begin, false); report_summary(sum_end, sum_begin, true); - writeaddresses(); return 0; } return -1; diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 4e6148798..34c47452c 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -136,11 +136,6 @@ extern "C" { extern const char * g_basedir; extern const char * g_resourcedir; - extern boolean nonr; - extern boolean nosh; - extern boolean nocr; - extern boolean noreports; - extern boolean nomer; extern boolean nobattle; extern boolean nomonsters; extern boolean battledebug; @@ -436,7 +431,6 @@ usage(const char * prog, const char * arg) "--debug : schreibt Debug-Ausgaben in die Datei debug\n" "--nocr : keine CRs\n" "--nonr : keine Reports\n" - "--nosh : keine Mail-Skripte\n" "--crabsolute : absolute Koordinaten im CR\n" "--help : help\n", prog); return -1; @@ -484,7 +478,6 @@ read_args(int argc, char **argv, lua_State * luaState) else if (strcmp(argv[i]+2, "ignore-errors")==0) g_ignore_errors = true; else if (strcmp(argv[i]+2, "dirtyload")==0) dirtyload = true; else if (strcmp(argv[i]+2, "nonr")==0) nonr = true; - else if (strcmp(argv[i]+2, "nosh")==0) nosh = true; else if (strcmp(argv[i]+2, "lomem")==0) lomem = true; else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true; else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true; diff --git a/src/res/messages.xml b/src/res/messages.xml index 73a9d8590..7d25e53cd 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -1735,7 +1735,6 @@ "$unit($unit) in $region($region): '$order($command)' - Der Elementar ist zu klein, um das Gebäude zu tragen." - @@ -1746,9 +1745,7 @@ "$unit($unit) in $region($region): '$order($command)' - Der Elementar weigert sich, nach $direction($direction) zu gehen." - "$unit($unit) in $region($region): '$order($command)' - The elemental refuses to go $direction($direction)." - @@ -7012,6 +7009,8 @@ + + @@ -7021,6 +7020,7 @@ "$unit($unit) übergibt $int($amount) $resource($resource,$amount) an die Bauern." "$unit($unit) gives $int($amount) $resource($resource,$amount) to the local peasants." + @@ -7471,7 +7471,6 @@ "$unit($mage) erschafft in $region($region) eine verheerende Feuersbrunst. $int($amount) Bäume fallen den Flammen zum Opfer." "$unit($mage) creates a flaming inferno in $region($region). $int($amount) trees fall vistim to the flames." - @@ -8315,5 +8314,12 @@ "$unit($unit) in $region($region): '$order($command)' - Dieser Zauber kann nciht auf Untote gezaubert werden." + + + + + + "Achtung: $faction($faction) hat einige Zeit keine Züge eingeschickt und könnte dadurch in Kürze aus dem Spiel ausscheiden" + diff --git a/src/res/races.xml b/src/res/races.xml index ea783ae58..935cf251a 100644 --- a/src/res/races.xml +++ b/src/res/races.xml @@ -661,7 +661,7 @@ - + diff --git a/src/scripts/default.lua b/src/scripts/default.lua index 3bc259d71..db2e63687 100644 --- a/src/scripts/default.lua +++ b/src/scripts/default.lua @@ -18,14 +18,24 @@ function write_emails(locales) end end +function write_addresses() + local file + local faction + + file = io.open(basepath .. "/adressen", "w") + for faction in factions() do + -- print(faction.id .. " - " .. faction.locale) + file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.banner .. "\n") + end + + file:close() +end + function write_aliases() local file - local key - local locale + local faction file = io.open(basepath .. "/aliases." .. locale, "w") - - local faction for faction in factions() do local unit file:write("partei-" .. itoa36(faction.id) .. ": " .. faction.email .. "\n") @@ -43,4 +53,5 @@ function write_files(locales) write_emails(locales) write_aliases() write_summary() + write_addresses() end