From 54fbc30359d7087716b12f5c980fdef1b70770e5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 Jun 2005 13:22:31 +0000 Subject: [PATCH] =?UTF-8?q?Kalender=20aus=20timestrings=20heraus=20und=20i?= =?UTF-8?q?n=20die=20xml-files=20hinein.=20Ziemlicher=20Aufwand=20f=C3=BCr?= =?UTF-8?q?=20(fast)=20keinerlei=20neue=20Features=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/economy.c | 1 + src/common/gamecode/report.c | 82 ++++++---------------- src/common/kernel/Jamfile | 1 + src/common/kernel/calendar.c | 15 ++++ src/common/kernel/calendar.h | 20 ++++++ src/common/kernel/eressea.c | 13 +--- src/common/kernel/kernel.vcproj | 6 ++ src/common/kernel/reports.h | 10 --- src/common/kernel/xmlreader.c | 119 +++++++++++++++++++++++++++++++- src/eressea/main.c | 3 - src/eressea/server.cpp | 4 -- src/res/calendar.xml | 23 ++++++ src/res/de/strings.xml | 4 ++ src/res/eressea.xml | 3 +- src/res/eressea/calendar.xml | 23 ++++++ src/res/hse4.xml | 8 +-- src/res/timestrings | 20 ------ src/res/vinyambar-wdw.xml | 5 +- src/todo.txt | 2 + 19 files changed, 243 insertions(+), 119 deletions(-) create mode 100644 src/common/kernel/calendar.c create mode 100644 src/common/kernel/calendar.h create mode 100644 src/res/calendar.xml create mode 100644 src/res/eressea/calendar.xml delete mode 100644 src/res/timestrings diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 22886ebb3..bc7a91fc8 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -30,6 +30,7 @@ /* kernel includes */ #include #include +#include #include #include #include diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 0da481c57..e357eb7f4 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -100,14 +101,6 @@ boolean nosh = false; boolean nomer = false; boolean noreports = false; -char **seasonnames; -char **weeknames; -char **weeknames2; -char **monthnames; -int *month_season; -char *agename; -int seasons; - static size_t strxcpy(char * dst, const char * src) { size_t s = 0; @@ -207,46 +200,28 @@ season(int turn) return month_season[month]; } -#if 0 -static char * -gamedate(const struct locale * lang) +static void +get_gamedate(int * year, int * month, int * week) { - int year,month,week,r; - static char buf[256]; - int t = turn - FirstTurn(); + int weeks_per_year = months_per_year * weeks_per_month; + int t = turn - FirstTurn(); - if (t<0) t = turn; - assert(lang); + if (t<0) t = turn; - year = t/(months_per_year * weeks_per_month) + 1; - r = t - (year-1) * months_per_year * weeks_per_month; - month = r/weeks_per_month; - week = r%weeks_per_month; - sprintf(buf, LOC(lang, "nr_calendar"), - LOC(lang, weeknames[week]), - LOC(lang, monthnames[month]), - LOC(lang, year), - LOC(lang, agename)); - - return buf; + *week = t%weeks_per_month; /* 0 - weeks_per_month-1 */ + *month = (t/weeks_per_month + first_month)%months_per_year; /* 0 - months_per_year-1 */ + *year = t/(weeks_per_year) + 1; } -#endif static char * gamedate_season(const struct locale * lang) { - int year,month,week,r; static char buf[256]; - int t = turn - FirstTurn(); + int year, month, week; - if (t<0) t = turn; - assert(lang); + get_gamedate(&year, &month, &week); - year = t/(months_per_year * weeks_per_month) + 1; - r = t - (year-1) * months_per_year * weeks_per_month; - month = r/weeks_per_month; - week = r%weeks_per_month; - sprintf(buf, LOC(lang, "nr_calendar_season"), + sprintf(buf, LOC(lang, "nr_calendar_season"), LOC(lang, weeknames[week]), LOC(lang, monthnames[month]), year, @@ -259,38 +234,25 @@ gamedate_season(const struct locale * lang) static char * gamedate2(const struct locale * lang) { - int year,month,week,r; static char buf[256]; - int t = turn - FirstTurn(); + int year, month, week; - if (t<0) t = turn; - - year = t/(months_per_year * weeks_per_month) + 1; - r = t - (year-1) * months_per_year * weeks_per_month; - month = r/weeks_per_month; /* 0 - months_per_year-1 */ - week = r%weeks_per_month; /* 0 - weeks_per_month-1 */ - sprintf(buf, "in %s des Monats %s im Jahre %d %s.", - LOC(lang, weeknames2[week]), - LOC(lang, monthnames[month]), - year, - LOC(lang, agename)); - return buf; + get_gamedate(&year, &month, &week); + sprintf(buf, "in %s des Monats %s im Jahre %d %s.", + LOC(lang, weeknames2[week]), + LOC(lang, monthnames[month]), + year, + LOC(lang, agename)); + return buf; } static char * gamedate_short(const struct locale * lang) { - int year,month,week,r; static char buf[256]; - int t = turn - FirstTurn(); - - if (t<0) t = turn; - - year = t/(months_per_year * weeks_per_month) + 1; - r = t - (year-1) * months_per_year * weeks_per_month; - month = r/weeks_per_month; /* 0 - months_per_year-1 */ - week = r%weeks_per_month; /* 0 - weeks_per_month-1 */ + int year, month, week; + get_gamedate(&year, &month, &week); sprintf(buf, "%d/%s/%d", week+1, LOC(lang, monthnames[month]), year); return buf; diff --git a/src/common/kernel/Jamfile b/src/common/kernel/Jamfile index 04c521b70..56216fe18 100644 --- a/src/common/kernel/Jamfile +++ b/src/common/kernel/Jamfile @@ -13,6 +13,7 @@ SOURCES = border.c build.c building.c + calendar.c combatspells.c curse.c eressea.c diff --git a/src/common/kernel/calendar.c b/src/common/kernel/calendar.c new file mode 100644 index 000000000..75f1d31ed --- /dev/null +++ b/src/common/kernel/calendar.c @@ -0,0 +1,15 @@ +#include +#include "calendar.h" + +int first_turn = 0; +int first_month = 0; +int weeks_per_month = 0; +int months_per_year = 0; +char **seasonnames = NULL; +char **weeknames = NULL; +char **weeknames2 = NULL; +char **monthnames = NULL; +int *month_season = NULL; +char *agename = NULL; +int seasons = 0; + diff --git a/src/common/kernel/calendar.h b/src/common/kernel/calendar.h new file mode 100644 index 000000000..ee9328bed --- /dev/null +++ b/src/common/kernel/calendar.h @@ -0,0 +1,20 @@ +#ifndef KRNL_CALENDAR_H +#define KRNL_CALENDAR_H + +extern char *agename; +extern int first_turn; +extern int first_month; + +extern int seasons; +extern char **seasonnames; + +extern int months_per_year; +extern char **monthnames; +extern int *month_season; +extern int *storms; /* in movement.c */ + +extern char **weeknames; +extern char **weeknames2; +extern int weeks_per_month; + +#endif diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index e0151e897..7d8947ecb 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -36,6 +36,7 @@ #include "battle.h" #include "border.h" #include "building.h" +#include "calendar.h" #include "curse.h" #include "faction.h" #include "group.h" @@ -195,12 +196,7 @@ AllianceRestricted(void) int FirstTurn(void) { - static int value = -1; - if (value<0) { - const char * str = get_param(global.parameters, "firstturn"); - value = str?atoi(str):0; - } - return value; + return first_turn; } int @@ -690,7 +686,7 @@ stripfaction (faction * f) while (f->battles) { struct bmsg * b = f->battles; f->battles = b->next; - free_messagelist(b->msgs); + if (b->msgs) free_messagelist(b->msgs); } freelist(f->allies); @@ -3011,9 +3007,6 @@ add_income(unit * u, int type, int want, int qty) u, u->region, type, want, qty)); } -int weeks_per_month; -int months_per_year; - int month(int offset) { diff --git a/src/common/kernel/kernel.vcproj b/src/common/kernel/kernel.vcproj index 1b26fed6b..850c497d8 100644 --- a/src/common/kernel/kernel.vcproj +++ b/src/common/kernel/kernel.vcproj @@ -189,6 +189,9 @@ + + @@ -310,6 +313,9 @@ + + diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 31ab0cb21..04f50c31f 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -89,16 +89,6 @@ extern void get_seen_interval(struct seen_region ** seen, struct region ** first extern const char* resname(resource_t res, int i); -extern char **seasonnames; -extern char **weeknames; -extern char **monthnames; -extern int *month_season; -extern int *storms; /* in movement.c */ -extern char *agename; -extern int seasons; -extern int weeks_per_month; -extern int months_per_year; - extern void report_item(const struct unit * owner, const struct item * i, const struct faction * viewer, const char ** name, const char ** basename, int * number, boolean singular); extern void report_building(FILE *F, const struct region * r, const struct building * b, const struct faction * f, int mode); extern int bufunit(const struct faction * f, const struct unit * u, int indent, int mode); diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index dabc88225..7fa74c32d 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -24,6 +24,7 @@ without prior permission by the authors of Eressea. #include "ship.h" #include "skill.h" #include "spell.h" +#include "calendar.h" /* util includes */ #include @@ -74,13 +75,13 @@ xml_to_locale(const xmlChar * xmlStr) size_t outbytes = sizeof(zText); if (context==(iconv_t)-1) { - context = iconv_open("", "UTF-8"); + context = iconv_open("", "UTF-8"); } assert(context!=(iconv_t)-1); iconv(context, &inbuf, &inbytes, &outbuf, &outbytes); if (inbytes!=0) { - log_error(("string is too long: %d chars remain in %s.\n", inbytes, (const char*)xmlStr)); + log_error(("string is too long: %d chars remain in %s.\n", inbytes, (const char*)xmlStr)); } return zText; } @@ -305,6 +306,119 @@ parse_buildings(xmlDocPtr doc) return 0; } +static int +parse_calendar(xmlDocPtr doc) +{ + xmlXPathContextPtr xpath = xmlXPathNewContext(doc); + xmlXPathObjectPtr xpathCalendars; + xmlNodeSetPtr nsetCalendars; + int rv = 0; + + /* reading eressea/buildings/building */ + xpathCalendars = xmlXPathEvalExpression(BAD_CAST "/eressea/calendar", xpath); + nsetCalendars = xpathCalendars->nodesetval; + if (nsetCalendars==NULL || nsetCalendars->nodeNr!=1) { + log_error(("invalid or missing calendar data in %s\n", doc->name)); + rv = -1; + } else { + xmlNodePtr calendar = nsetCalendars->nodeTab[0]; + xmlXPathObjectPtr xpathWeeks, xpathMonths, xpathSeasons; + xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons; + xmlChar * property = xmlGetProp(calendar, BAD_CAST "name"); + xmlChar * newyear = xmlGetProp(calendar, BAD_CAST "newyear"); + + first_turn = xml_ivalue(calendar, "start", 0); + if (property) { + agename = strdup(mkname("calendar", (const char*)property)); + xmlFree(property); + } + + xpath->node = calendar; + xpathWeeks = xmlXPathEvalExpression(BAD_CAST "week", xpath); + nsetWeeks = xpathWeeks->nodesetval; + if (nsetWeeks!=NULL) { + int i; + + weeks_per_month = nsetWeeks->nodeNr; + weeknames = malloc(sizeof(char *) * weeks_per_month); + weeknames2 = malloc(sizeof(char *) * weeks_per_month); + for (i=0;i!=nsetWeeks->nodeNr;++i) { + xmlNodePtr week = nsetWeeks->nodeTab[i]; + xmlChar * property = xmlGetProp(week, BAD_CAST "name"); + if (property) { + weeknames[i] = strdup(mkname("calendar", (const char*)property)); + weeknames2[i] = malloc(strlen(weeknames[i])+3); + sprintf(weeknames2[i], "%s_d", weeknames[i]); + xmlFree(property); + } + } + } + xmlXPathFreeObject(xpathWeeks); + + months_per_year = 0; + xpathSeasons = xmlXPathEvalExpression(BAD_CAST "season", xpath); + nsetSeasons = xpathSeasons->nodesetval; + if (nsetSeasons!=NULL) { + int i; + + seasons = nsetSeasons->nodeNr; + seasonnames = malloc(sizeof(char *) * seasons); + storms = malloc(sizeof(int) * seasons); + + for (i=0;i!=nsetSeasons->nodeNr;++i) { + xmlNodePtr season = nsetSeasons->nodeTab[i]; + xmlChar * property = xmlGetProp(season, BAD_CAST "name"); + if (property) { + seasonnames[i] = strdup(mkname("calendar", (const char*)property)); + xmlFree(property); + } + } + } + + xpathMonths = xmlXPathEvalExpression(BAD_CAST "season/month", xpath); + nsetMonths = xpathMonths->nodesetval; + if (nsetMonths!=NULL) { + int i; + + months_per_year = nsetMonths->nodeNr; + monthnames = malloc(sizeof(char *) * months_per_year); + month_season = malloc(sizeof(int) * months_per_year); + storms = malloc(sizeof(int) * months_per_year); + + for (i=0;i!=nsetMonths->nodeNr;++i) { + xmlNodePtr month = nsetMonths->nodeTab[i]; + xmlChar * property = xmlGetProp(month, BAD_CAST "name"); + int j; + + if (property) { + if (newyear && strcmp((const char*)newyear, (const char*)property)==0) { + first_month = i; + xmlFree(newyear); + newyear = NULL; + } + monthnames[i] = strdup(mkname("calendar", (const char*)property)); + xmlFree(property); + } + for (j=0;j!=seasons;++j) { + xmlNodePtr season = month->parent; + if (season==nsetSeasons->nodeTab[j]) { + month_season[i] = j; + break; + } + } + assert(j!=seasons); + storms[i] = xml_ivalue(nsetMonths->nodeTab[i], "storm", 0); + } + } + xmlXPathFreeObject(xpathMonths); + xmlXPathFreeObject(xpathSeasons); + } + xmlXPathFreeObject(xpathCalendars); + xmlXPathFreeContext(xpath); + + return rv; +} + static int parse_ships(xmlDocPtr doc) { @@ -1248,4 +1362,5 @@ register_xmlreader(void) xml_register_callback(parse_buildings); xml_register_callback(parse_ships); xml_register_callback(parse_equipment); + xml_register_callback(parse_calendar); } diff --git a/src/eressea/main.c b/src/eressea/main.c index c672bb5ff..8c410af3e 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -603,9 +603,6 @@ main(int argc, char *argv[]) "orders %s.\n", global.data_version / 10, global.data_version % 10, turn, orders); - strcat(strcpy(zText, resourcepath()), "/timestrings"); - if ((i=read_datenames(zText))!=0) return i; - kernel_init(); game_init(); #if defined(BETA_CODE) diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 330731443..5a8e74667 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -650,7 +650,6 @@ main(int argc, char *argv[]) int i; char * lc_ctype; char * lc_numeric; - char zText[MAX_PATH]; setup_signal_handler(); @@ -679,9 +678,6 @@ main(int argc, char *argv[]) global.vm_state = luaState; if ((i=read_args(argc, argv, luaState))!=0) return i; - strcat(strcpy(zText, resourcepath()), "/timestrings"); - if ((i=read_datenames(zText))!=0) return i; - kernel_init(); game_init(); diff --git a/src/res/calendar.xml b/src/res/calendar.xml new file mode 100644 index 000000000..42f83d58b --- /dev/null +++ b/src/res/calendar.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index b734f0bec..54f012f2a 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -5695,6 +5695,10 @@ des zweiten Zeitalters the second age + + neuer Zeitrechnung + of the new age + diff --git a/src/res/eressea.xml b/src/res/eressea.xml index 45b49f7ff..8bfdc03cd 100644 --- a/src/res/eressea.xml +++ b/src/res/eressea.xml @@ -11,7 +11,7 @@ - + Game specific @@ -25,7 +25,6 @@ - diff --git a/src/res/eressea/calendar.xml b/src/res/eressea/calendar.xml new file mode 100644 index 000000000..74ce8e54b --- /dev/null +++ b/src/res/eressea/calendar.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/res/hse4.xml b/src/res/hse4.xml index 1caed6c28..3fc46f129 100644 --- a/src/res/hse4.xml +++ b/src/res/hse4.xml @@ -11,10 +11,8 @@ - - - - + + @@ -46,7 +44,7 @@ Bitte denke daran, deine Befehle mit dem Betreff ERESSEA BEFEHLE an hse-server@eressea.de zu senden. Am besten, du verwendest die Befehlsvorlage am Ende des Reports. - Remember to send your orders to hse-server@eressea.de with the subject ERESSEA ORDERS. + Remember to send your orders to hse-server@eressea.de with the subject ERESSEA ORDERS. hse-server@eressea.de diff --git a/src/res/timestrings b/src/res/timestrings deleted file mode 100644 index df846bed4..000000000 --- a/src/res/timestrings +++ /dev/null @@ -1,20 +0,0 @@ -secondage -4 -winter -spring -summer -fall -3 -firstweek:firstweek_d -secondweek:secondweek_d -thirdweek:thirdweek_d -9 -month_1:2:30 -month_2:3:60 -month_3:3:80 -month_4:0:50 -month_5:0:30 -month_6:0:60 -month_7:1:60 -month_8:1:10 -month_9:2:10 diff --git a/src/res/vinyambar-wdw.xml b/src/res/vinyambar-wdw.xml index efd64dfda..f9e5d4d80 100644 --- a/src/res/vinyambar-wdw.xml +++ b/src/res/vinyambar-wdw.xml @@ -3,16 +3,15 @@ - + - - + Game specific diff --git a/src/todo.txt b/src/todo.txt index 9a6a6dc0a..c9e7d8e82 100644 --- a/src/todo.txt +++ b/src/todo.txt @@ -1,3 +1,5 @@ +TODO: + parteien- oder gruppenweises aftermath-markieren. XUL for Eressea