forked from github/server
moved all initialization code out of main and made it compile.
This commit is contained in:
parent
3a0bc89a85
commit
da1bdfb088
|
@ -2,39 +2,26 @@
|
|||
#include <util/log.h>
|
||||
|
||||
#include <eressea.h>
|
||||
#include <gmtool.h>
|
||||
#include <kernel/config.h>
|
||||
#include <iniparser/iniparser.h>
|
||||
|
||||
static void
|
||||
load_inifile(const char * filename)
|
||||
static const char * luafile = "init.lua";
|
||||
static const char * entry_point = NULL;
|
||||
static int memdebug = 0;
|
||||
|
||||
static void load_config(const char * filename)
|
||||
{
|
||||
dictionary * d = iniparser_new(filename);
|
||||
if (d) {
|
||||
const char * str;
|
||||
load_inifile(d);
|
||||
|
||||
g_basedir = iniparser_getstring(d, "eressea:base", g_basedir);
|
||||
lomem = iniparser_getint(d, "eressea:lomem", lomem)?1:0;
|
||||
memdebug = iniparser_getint(d, "eressea:memcheck", memdebug);
|
||||
|
||||
str = iniparser_getstring(d, "eressea:encoding", NULL);
|
||||
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
||||
|
||||
verbosity = iniparser_getint(d, "eressea:verbose", 2);
|
||||
sqlpatch = iniparser_getint(d, "eressea:sqlpatch", false);
|
||||
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
||||
|
||||
entry_point = iniparser_getstring(d, "eressea:run", entry_point);
|
||||
luafile = iniparser_getstring(d, "eressea:load", luafile);
|
||||
g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir);
|
||||
|
||||
str = iniparser_getstring(d, "eressea:locales", "de,en");
|
||||
make_locales(str);
|
||||
|
||||
/* only one value in the [editor] section */
|
||||
force_color = iniparser_getint(d, "editor:color", force_color);
|
||||
|
||||
/* excerpt from [config] (the rest is used in bindings.c) */
|
||||
game_name = iniparser_getstring(d, "config:game", game_name);
|
||||
}
|
||||
global.inifile = d;
|
||||
}
|
||||
|
@ -43,7 +30,7 @@ int main(int argc, char ** argv)
|
|||
{
|
||||
int err;
|
||||
|
||||
load_inifile("eressea.ini");
|
||||
load_config("eressea.ini");
|
||||
|
||||
err = eressea_init();
|
||||
if (err) {
|
||||
|
|
|
@ -25,6 +25,31 @@
|
|||
#include <bindings/bind_unit.h>
|
||||
#endif // BINDINGS_TOLUA
|
||||
|
||||
#if MUSEUM_MODULE
|
||||
#include <modules/museum.h>
|
||||
#endif
|
||||
#if ARENA_MODULE
|
||||
#include <modules/arena.h>
|
||||
#endif
|
||||
#include <triggers/triggers.h>
|
||||
#include <util/language.h>
|
||||
#include <kernel/xmlreader.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/names.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/building.h>
|
||||
#include <modules/wormhole.h>
|
||||
#include <modules/gmcmd.h>
|
||||
#include <modules/xmas.h>
|
||||
#include <gamecode/archetype.h>
|
||||
#include <gamecode/report.h>
|
||||
#include <gamecode/items.h>
|
||||
#include <gamecode/creport.h>
|
||||
#include <gamecode/xmlreport.h>
|
||||
#include <races/races.h>
|
||||
#include <items/itemtypes.h>
|
||||
#include <attributes/attributes.h>
|
||||
|
||||
|
||||
static const struct {
|
||||
|
@ -108,13 +133,13 @@ game_done(void)
|
|||
static void
|
||||
game_init(void)
|
||||
{
|
||||
init_triggers();
|
||||
init_xmas();
|
||||
register_triggers();
|
||||
register_xmas();
|
||||
|
||||
reports_init();
|
||||
report_init();
|
||||
creport_init();
|
||||
xmlreport_init();
|
||||
register_reports();
|
||||
register_nr();
|
||||
register_cr();
|
||||
register_xr();
|
||||
|
||||
debug_language("locales.log");
|
||||
register_races();
|
||||
|
|
|
@ -1572,7 +1572,7 @@ crwritemap(const char * filename)
|
|||
}
|
||||
|
||||
void
|
||||
creport_init(void)
|
||||
register_cr(void)
|
||||
{
|
||||
tsf_register("report", &cr_ignore);
|
||||
tsf_register("string", &cr_string);
|
||||
|
|
|
@ -18,7 +18,7 @@ extern "C" {
|
|||
#include <time.h>
|
||||
|
||||
extern void creport_cleanup(void);
|
||||
extern void creport_init(void);
|
||||
extern void register_cr(void);
|
||||
|
||||
extern int crwritemap(const char * filename);
|
||||
|
||||
|
|
|
@ -2426,7 +2426,7 @@ kann_finden(faction * f1, faction * f2)
|
|||
/******* end summary ******/
|
||||
|
||||
void
|
||||
report_init(void)
|
||||
register_nr(void)
|
||||
{
|
||||
if (!nocr) register_reporttype("nr", &report_plaintext, 1<<O_REPORT);
|
||||
if (!nonr) register_reporttype("txt", &report_template, 1<<O_ZUGVORLAGE);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void report_init(void);
|
||||
extern void register_nr(void);
|
||||
extern void report_cleanup(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -732,7 +732,7 @@ report_xml(const char * filename, report_context * ctx, const char * encoding)
|
|||
}
|
||||
|
||||
void
|
||||
xmlreport_init(void)
|
||||
register_xr(void)
|
||||
{
|
||||
register_reporttype("xml", &report_xml, 1<<O_XML);
|
||||
#ifdef USE_ICONV
|
||||
|
|
|
@ -16,7 +16,7 @@ extern "C" {
|
|||
#include <time.h>
|
||||
|
||||
extern void xmlreport_cleanup(void);
|
||||
extern void xmlreport_init(void);
|
||||
extern void register_xr(void);
|
||||
|
||||
extern int crwritemap(const char * filename);
|
||||
|
||||
|
|
|
@ -68,10 +68,6 @@
|
|||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
extern const char * g_reportdir;
|
||||
extern const char * g_datadir;
|
||||
extern const char * g_basedir;
|
||||
|
||||
static int g_quit;
|
||||
int force_color = 0;
|
||||
|
||||
|
|
|
@ -96,9 +96,6 @@ typedef enum combatmagic {
|
|||
DO_POSTCOMBATSPELL
|
||||
} combatmagic_t;
|
||||
|
||||
/* external variables */
|
||||
boolean battledebug = true;
|
||||
|
||||
/* globals */
|
||||
static int obs_count = 0;
|
||||
|
||||
|
|
|
@ -76,6 +76,8 @@
|
|||
#include <libxml/tree.h>
|
||||
#include <libxml/xpath.h>
|
||||
|
||||
#include <iniparser/iniparser.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -101,6 +103,7 @@ FILE *logfile;
|
|||
FILE *updatelog;
|
||||
const struct race * new_race[MAXRACES];
|
||||
boolean sqlpatch = false;
|
||||
boolean battledebug = false;
|
||||
int turn = 0;
|
||||
|
||||
#if XECMD_MODULE
|
||||
|
@ -586,15 +589,6 @@ skill_limit(faction * f, skill_t sk)
|
|||
return m;
|
||||
}
|
||||
|
||||
const char * g_basedir;
|
||||
|
||||
const char *
|
||||
basepath(void)
|
||||
{
|
||||
if (g_basedir) return g_basedir;
|
||||
return ".";
|
||||
}
|
||||
|
||||
int
|
||||
count_skill(faction * f, skill_t sk)
|
||||
{
|
||||
|
@ -2152,6 +2146,52 @@ get_param_int(const struct param * p, const char * key, int def)
|
|||
return def;
|
||||
}
|
||||
|
||||
static const char * g_datadir;
|
||||
const char *
|
||||
datapath(void)
|
||||
{
|
||||
static char zText[MAX_PATH];
|
||||
if (g_datadir) return g_datadir;
|
||||
return strcat(strcpy(zText, basepath()), "/data");
|
||||
}
|
||||
|
||||
void
|
||||
set_datapath(const char * path)
|
||||
{
|
||||
g_datadir = path;
|
||||
}
|
||||
|
||||
|
||||
static const char * g_reportdir;
|
||||
const char *
|
||||
reportpath(void)
|
||||
{
|
||||
static char zText[MAX_PATH];
|
||||
if (g_reportdir) return g_reportdir;
|
||||
return strcat(strcpy(zText, basepath()), "/reports");
|
||||
}
|
||||
|
||||
void
|
||||
set_reportpath(const char * path)
|
||||
{
|
||||
g_reportdir = path;
|
||||
}
|
||||
|
||||
static const char * g_basedir;
|
||||
const char *
|
||||
basepath(void)
|
||||
{
|
||||
if (g_basedir) return g_basedir;
|
||||
return ".";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_basepath(const char * path)
|
||||
{
|
||||
g_basedir = path;
|
||||
}
|
||||
|
||||
float
|
||||
get_param_flt(const struct param * p, const char * key, float def)
|
||||
{
|
||||
|
@ -3211,3 +3251,39 @@ free_gamedata(void)
|
|||
}
|
||||
++global.cookie; /* readgame() already does this, but sjust in case */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
load_inifile(dictionary * d)
|
||||
{
|
||||
const char * reportdir = reportpath();
|
||||
const char * datadir = datapath();
|
||||
const char * basedir = basepath();
|
||||
const char * str;
|
||||
|
||||
assert(d);
|
||||
|
||||
str = iniparser_getstring(d, "eressea:base", basedir);
|
||||
if (str!=basedir) set_basepath(str);
|
||||
str = iniparser_getstring(d, "eressea:report", reportdir);
|
||||
if (str!=reportdir) set_reportpath(str);
|
||||
str = iniparser_getstring(d, "eressea:data", datadir);
|
||||
if (str!=datadir) set_datapath(str);
|
||||
|
||||
lomem = iniparser_getint(d, "eressea:lomem", lomem)?1:0;
|
||||
|
||||
str = iniparser_getstring(d, "eressea:encoding", NULL);
|
||||
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
||||
|
||||
verbosity = iniparser_getint(d, "eressea:verbose", 2);
|
||||
sqlpatch = iniparser_getint(d, "eressea:sqlpatch", false);
|
||||
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
||||
|
||||
str = iniparser_getstring(d, "eressea:locales", "de,en");
|
||||
make_locales(str);
|
||||
|
||||
/* excerpt from [config] (the rest is used in bindings.c) */
|
||||
game_name = iniparser_getstring(d, "config:game", game_name);
|
||||
|
||||
global.inifile = d;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ extern "C" {
|
|||
/* this should always be the first thing included after platform.h */
|
||||
#include "types.h"
|
||||
|
||||
typedef struct _dictionary_ dictionary;
|
||||
|
||||
/* experimental gameplay features (that don't affect the savefile) */
|
||||
/* TODO: move these settings to settings.h or into configuration files */
|
||||
#define GOBLINKILL /* Goblin-Spezialklau kann tödlich enden */
|
||||
|
@ -363,7 +365,16 @@ enum {
|
|||
};
|
||||
extern int movewhere(const struct unit *u, const char * token, struct region * r, struct region** resultp);
|
||||
|
||||
extern const char * datapath(void);
|
||||
extern void set_datapath(const char * path);
|
||||
|
||||
extern const char * basepath(void);
|
||||
extern void set_basepath(const char *);
|
||||
void load_inifile(dictionary * d);
|
||||
|
||||
extern const char * reportpath(void);
|
||||
extern void set_reportpath(const char *);
|
||||
|
||||
extern void kernel_init(void);
|
||||
extern void kernel_done(void);
|
||||
|
||||
|
@ -385,7 +396,7 @@ typedef struct settings {
|
|||
void * vm_state;
|
||||
float producexpchance;
|
||||
int cookie;
|
||||
struct _dictionary_ * inifile;
|
||||
dictionary * inifile;
|
||||
|
||||
struct global_functions {
|
||||
int (*wage)(const struct region *r, const struct faction * f, const struct race * rc, int in_turn);
|
||||
|
@ -396,6 +407,7 @@ extern settings global;
|
|||
|
||||
extern int produceexp(struct unit * u, skill_t sk, int n);
|
||||
|
||||
extern boolean battledebug;
|
||||
extern boolean sqlpatch;
|
||||
extern boolean lomem; /* save memory */
|
||||
|
||||
|
|
|
@ -73,7 +73,6 @@ boolean nocr = false;
|
|||
boolean nonr = false;
|
||||
boolean noreports = false;
|
||||
|
||||
const char * g_reportdir;
|
||||
const char * visibility[] = {
|
||||
"none",
|
||||
"neighbour",
|
||||
|
@ -94,14 +93,6 @@ const char *coasts[MAXDIRECTIONS] =
|
|||
"coast::w"
|
||||
};
|
||||
|
||||
const char *
|
||||
reportpath(void)
|
||||
{
|
||||
static char zText[MAX_PATH];
|
||||
if (g_reportdir) return g_reportdir;
|
||||
return strcat(strcpy(zText, basepath()), "/reports");
|
||||
}
|
||||
|
||||
static char *
|
||||
groupid(const struct group * g, const struct faction * f)
|
||||
{
|
||||
|
@ -2143,7 +2134,7 @@ report_action(region * r, unit * actor, message * msg, int flags)
|
|||
|
||||
|
||||
void
|
||||
reports_init(void)
|
||||
register_reports(void)
|
||||
{
|
||||
/* register datatypes for the different message objects */
|
||||
register_argtype("alliance", NULL, NULL, VAR_VOIDPTR);
|
||||
|
|
|
@ -99,11 +99,10 @@ extern void register_reporttype(const char * extension, report_fun write, int fl
|
|||
|
||||
extern int bufunit(const struct faction * f, const struct unit * u, int indent, int mode, char * buf, size_t size);
|
||||
|
||||
extern const char * reportpath(void);
|
||||
extern const char * trailinto(const struct region * r, const struct locale * lang);
|
||||
extern const char * report_kampfstatus(const struct unit * u, const struct locale * lang);
|
||||
|
||||
extern void reports_init(void);
|
||||
extern void register_reports(void);
|
||||
|
||||
extern int update_nmrs(void);
|
||||
extern int * nmrs;
|
||||
|
|
|
@ -90,7 +90,6 @@
|
|||
|
||||
/* exported symbols symbols */
|
||||
const char * game_name = "eressea";
|
||||
const char * g_datadir;
|
||||
int firstx = 0, firsty = 0;
|
||||
int enc_gamedata = 0;
|
||||
|
||||
|
@ -512,14 +511,6 @@ create_backup(char *file)
|
|||
#endif
|
||||
}
|
||||
|
||||
const char *
|
||||
datapath(void)
|
||||
{
|
||||
static char zText[MAX_PATH];
|
||||
if (g_datadir) return g_datadir;
|
||||
return strcat(strcpy(zText, basepath()), "/data");
|
||||
}
|
||||
|
||||
void
|
||||
read_items(struct storage * store, item **ilist)
|
||||
{
|
||||
|
|
|
@ -55,8 +55,6 @@ extern void write_items(struct storage * store, struct item *it);
|
|||
extern void write_unit(struct storage * store, const struct unit * u);
|
||||
extern struct unit * read_unit(struct storage * store);
|
||||
|
||||
extern const char * datapath(void);
|
||||
|
||||
extern int a_readint(struct attrib * a, struct storage * store);
|
||||
extern void a_writeint(const struct attrib * a, struct storage * store);
|
||||
extern int a_readshorts(struct attrib * a, struct storage * store);
|
||||
|
|
|
@ -75,7 +75,7 @@ trigger_xmasgate(building * b)
|
|||
}
|
||||
|
||||
void
|
||||
init_xmas(void)
|
||||
register_xmas(void)
|
||||
{
|
||||
tt_register(&tt_xmasgate);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ struct unit;
|
|||
|
||||
extern struct trigger *trigger_xmasgate(struct building * b);
|
||||
|
||||
extern void init_xmas(void);
|
||||
extern void register_xmas(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void
|
||||
init_triggers(void)
|
||||
register_triggers(void)
|
||||
{
|
||||
if (verbosity>=2) printf("- registering triggers\n");
|
||||
tt_register(&tt_changefaction);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void init_triggers(void);
|
||||
void register_triggers(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
/* initialization - TODO: init in separate module */
|
||||
#include <attributes/attributes.h>
|
||||
#include <triggers/triggers.h>
|
||||
#include <items/itemtypes.h>
|
||||
#include <races/races.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue