Kalender aus timestrings heraus und in die xml-files hinein. Ziemlicher Aufwand für (fast) keinerlei neue Features :-)

This commit is contained in:
Enno Rehling 2005-06-04 13:22:31 +00:00
parent 42ea90a6fc
commit 54fbc30359
19 changed files with 243 additions and 119 deletions

View file

@ -30,6 +30,7 @@
/* kernel includes */
#include <kernel/alchemy.h>
#include <kernel/building.h>
#include <kernel/calendar.h>
#include <kernel/faction.h>
#include <kernel/give.h>
#include <kernel/item.h>

View file

@ -40,6 +40,7 @@
#include <kernel/border.h>
#include <kernel/build.h>
#include <kernel/building.h>
#include <kernel/calendar.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
@ -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;

View file

@ -13,6 +13,7 @@ SOURCES =
border.c
build.c
building.c
calendar.c
combatspells.c
curse.c
eressea.c

View file

@ -0,0 +1,15 @@
#include <config.h>
#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;

View file

@ -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

View file

@ -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)
{

View file

@ -189,6 +189,9 @@
<File
RelativePath=".\building.h">
</File>
<File
RelativePath=".\calendar.h">
</File>
<File
RelativePath=".\creation.h">
</File>
@ -310,6 +313,9 @@
<File
RelativePath=".\building.c">
</File>
<File
RelativePath=".\calendar.c">
</File>
<File
RelativePath=".\combatspells.c">
</File>

View file

@ -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);

View file

@ -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 <util/functions.h>
@ -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);
}

View file

@ -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)

View file

@ -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();

23
src/res/calendar.xml Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<calendar name="secondage" newyear="month_1" start="0">
<season name="winter">
<month name="month_4" storm="50" />
<month name="month_5" storm="30" />
<month name="month_6" storm="60" />
</season>
<season name="spring">
<month name="month_7" storm="60" />
<month name="month_8" storm="10" />
</season>
<season name="summer">
<month name="month_9" storm="60" />
<month name="month_1" storm="10" />
</season>
<season name="fall">
<month name="month_2" storm="60" />
<month name="month_3" storm="80" />
</season>
<week name="firstweek" />
<week name="secondweek" />
<week name="thirdweek" />
</calendar>

View file

@ -5695,6 +5695,10 @@
<text locale="de">des zweiten Zeitalters</text>
<text locale="en">the second age</text>
</string>
<string name="newage">
<text locale="de">neuer Zeitrechnung</text>
<text locale="en">of the new age</text>
</string>
</namespace>
<namespace name="school">

View file

@ -11,7 +11,7 @@
<xi:include href="prefixes.xml"/>
<xi:include href="ships.xml"/>
<xi:include href="buildings.xml"/>
<xi:include href="equipment.xml"/>
<xi:include href="eressea/calendar.xml"/>
<game name="Eressea" welcome="eressea">
<comment>Game specific</comment>
@ -25,7 +25,6 @@
<param name="hunger.long" value="1"/>
<param name="database.gameid" value="0"/>
<param name="rules.check_overload" value="0"/>
<param name="firstturn" value="184"/>
<param name="report.mailit" value="/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin"/>
</game>
<xi:include href="eressea/de/strings.xml"/>

View file

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<calendar name="secondage" newyear="month_1" start="184">
<season name="winter">
<month name="month_4" storm="50" />
<month name="month_5" storm="30" />
<month name="month_6" storm="60" />
</season>
<season name="spring">
<month name="month_7" storm="60" />
<month name="month_8" storm="10" />
</season>
<season name="summer">
<month name="month_9" storm="60" />
<month name="month_1" storm="10" />
</season>
<season name="fall">
<month name="month_2" storm="60" />
<month name="month_3" storm="80" />
</season>
<week name="firstweek" />
<week name="secondweek" />
<week name="thirdweek" />
</calendar>

View file

@ -11,10 +11,8 @@
<xi:include href="prefixes.xml"/>
<xi:include href="ships.xml"/>
<xi:include href="buildings.xml"/>
<xi:include file="terrains.xml"/>
<xi:include file="alchemy.xml"/>
<xi:include file="technologies.xml"/>
<xi:include file="skills.xml"/>
<xi:include href="calendar.xml"/>
<equipment>
<item name="wood" amount="5"/>
<item name="stone" amount="10"/>
@ -46,7 +44,7 @@
<strings>
<string name="newbie_info_1">
<text locale="de">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.</text>
<text locale="en">Remember to send your orders to hse-server@eressea.de with the subject ERESSEA ORDERS.</text>
<text locale="en">Remember to send your orders to hse-server@eressea.de with the subject ERESSEA ORDERS.</text>
</string>
<string name="mailto">
<text locale="de">hse-server@eressea.de</text>

View file

@ -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

View file

@ -3,16 +3,15 @@
<xi:include href="messages.xml"/>
<!-- Localization -->
<xi:include href="de/strings.xml"/>
<xi:include href="en/strings.xml"/>
<xi:include href="resources.xml"/>
<xi:include href="races.xml"/>
<xi:include href="prefixes.xml"/>
<xi:include href="resources.xml"/>
<xi:include href="ships.xml"/>
<xi:include href="buildings.xml"/>
<xi:include href="equipment.xml"/>
<xi:include href="calendar.xml"/>
<game name="Wettstreit der Weisen" unitsperalliance="yes" units="1000" welcome="vinyambar">
<comment>Game specific</comment>

View file

@ -1,3 +1,5 @@
TODO:
parteien- oder gruppenweises aftermath-markieren.
XUL for Eressea