From cacb4505671dd43bf32f980b1a4536d4a459df93 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 05:13:44 +0100 Subject: [PATCH] game.start in eressea.ini overrides calendar --- s/setup | 3 ++- src/bindings.c | 2 +- src/calendar.c | 9 +++++++-- src/calendar.h | 6 +++--- src/kernel/xmlreader.c | 7 ++++++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/s/setup b/s/setup index 848175ddc..e3e8e113d 100755 --- a/s/setup +++ b/s/setup @@ -96,7 +96,8 @@ touch eressea.ini ini_start ini_sec game ini_add game locales de,en -ini_add id $game +ini_add game id $game +ini_add game start 1 ini_sec lua ini_add lua install $SOURCE ini_add lua paths $SOURCE/scripts:$SOURCE/lunit diff --git a/src/bindings.c b/src/bindings.c index 94e78fb70..14eae1c56 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -948,7 +948,7 @@ static int init_data(const char *filename, const char *catalog) return l; } if (turn < 0) { - turn = first_turn; + turn = first_turn(); } return 0; } diff --git a/src/calendar.c b/src/calendar.c index 7a27328a7..2099b6631 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1,10 +1,10 @@ #include #include "calendar.h" +#include #include #include -int first_turn = 0; int first_month = 0; int weeks_per_month = 4; int months_per_year = 12; @@ -16,10 +16,15 @@ int *month_season = NULL; char *agename = NULL; int seasons = 0; +int first_turn(void) +{ + return config_get_int("game.start", 1); +} + const gamedate *get_gamedate(int turn, gamedate * gd) { int weeks_per_year = months_per_year * weeks_per_month; - int t = turn - first_turn; + int t = turn - first_turn(); assert(gd); if (t < 0) diff --git a/src/calendar.h b/src/calendar.h index 86f665c1a..d398cd77c 100644 --- a/src/calendar.h +++ b/src/calendar.h @@ -13,7 +13,6 @@ extern "C" { }; extern char *agename; - extern int first_turn; extern int first_month; extern int seasons; @@ -35,8 +34,9 @@ extern "C" { int week; } gamedate; - extern const gamedate *get_gamedate(int turn, gamedate * gd); - extern void calendar_cleanup(void); +const gamedate *get_gamedate(int turn, gamedate * gd); +void calendar_cleanup(void); +int first_turn(void); #ifdef __cplusplus } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2f38cdab3..2ba9d785a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -375,8 +375,13 @@ static int parse_calendar(xmlDocPtr doc) xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons; xmlChar *propValue = xmlGetProp(calendar, BAD_CAST "name"); xmlChar *newyear = xmlGetProp(calendar, BAD_CAST "newyear"); + xmlChar *start; - first_turn = xml_ivalue(calendar, "start", first_turn); + start = xmlGetProp(calendar, BAD_CAST "start"); + if (start && config_get("game.start")==NULL) { + config_set("game.start", (const char *)start); + xmlFree(start); + } if (propValue) { free(agename); agename = strdup(mkname("calendar", (const char *)propValue));