game.start in eressea.ini overrides calendar

This commit is contained in:
Enno Rehling 2017-01-22 05:13:44 +01:00
parent 0496c66028
commit 847cfb5425
5 changed files with 19 additions and 8 deletions

View file

@ -96,7 +96,8 @@ touch eressea.ini
ini_start ini_start
ini_sec game ini_sec game
ini_add game locales de,en ini_add game locales de,en
ini_add id $game ini_add game id $game
ini_add game start 1
ini_sec lua ini_sec lua
ini_add lua install $SOURCE ini_add lua install $SOURCE
ini_add lua paths $SOURCE/scripts:$SOURCE/lunit ini_add lua paths $SOURCE/scripts:$SOURCE/lunit

View file

@ -948,7 +948,7 @@ static int init_data(const char *filename, const char *catalog)
return l; return l;
} }
if (turn < 0) { if (turn < 0) {
turn = first_turn; turn = first_turn();
} }
return 0; return 0;
} }

View file

@ -1,10 +1,10 @@
#include <platform.h> #include <platform.h>
#include "calendar.h" #include "calendar.h"
#include <kernel/config.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
int first_turn = 0;
int first_month = 0; int first_month = 0;
int weeks_per_month = 4; int weeks_per_month = 4;
int months_per_year = 12; int months_per_year = 12;
@ -16,10 +16,15 @@ int *month_season = NULL;
char *agename = NULL; char *agename = NULL;
int seasons = 0; int seasons = 0;
int first_turn(void)
{
return config_get_int("game.start", 1);
}
const gamedate *get_gamedate(int turn, gamedate * gd) const gamedate *get_gamedate(int turn, gamedate * gd)
{ {
int weeks_per_year = months_per_year * weeks_per_month; int weeks_per_year = months_per_year * weeks_per_month;
int t = turn - first_turn; int t = turn - first_turn();
assert(gd); assert(gd);
if (t < 0) if (t < 0)

View file

@ -13,7 +13,6 @@ extern "C" {
}; };
extern char *agename; extern char *agename;
extern int first_turn;
extern int first_month; extern int first_month;
extern int seasons; extern int seasons;
@ -35,8 +34,9 @@ extern "C" {
int week; int week;
} gamedate; } gamedate;
extern const gamedate *get_gamedate(int turn, gamedate * gd); const gamedate *get_gamedate(int turn, gamedate * gd);
extern void calendar_cleanup(void); void calendar_cleanup(void);
int first_turn(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -375,8 +375,13 @@ static int parse_calendar(xmlDocPtr doc)
xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons; xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons;
xmlChar *propValue = xmlGetProp(calendar, BAD_CAST "name"); xmlChar *propValue = xmlGetProp(calendar, BAD_CAST "name");
xmlChar *newyear = xmlGetProp(calendar, BAD_CAST "newyear"); 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) { if (propValue) {
free(agename); free(agename);
agename = strdup(mkname("calendar", (const char *)propValue)); agename = strdup(mkname("calendar", (const char *)propValue));