From f37430e3c187e47472494bc8e2ef789e3aa1d1ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Feb 2010 20:28:14 +0000 Subject: [PATCH] moved all initialization code out of main and made it compile. --- src/basic/main.c | 29 +++------- src/common/eressea.c | 37 ++++++++++--- src/common/gamecode/creport.c | 2 +- src/common/gamecode/creport.h | 2 +- src/common/gamecode/report.c | 2 +- src/common/gamecode/report.h | 2 +- src/common/gamecode/xmlreport.c | 2 +- src/common/gamecode/xmlreport.h | 2 +- src/common/gmtool.c | 4 -- src/common/kernel/battle.c | 3 -- src/common/kernel/config.c | 94 +++++++++++++++++++++++++++++---- src/common/kernel/config.h | 14 ++++- src/common/kernel/reports.c | 11 +--- src/common/kernel/reports.h | 3 +- src/common/kernel/save.c | 9 ---- src/common/kernel/save.h | 2 - src/common/modules/xmas.c | 2 +- src/common/modules/xmas.h | 2 +- src/common/triggers/triggers.c | 2 +- src/common/triggers/triggers.h | 2 +- src/eressea/main.c | 1 - 21 files changed, 149 insertions(+), 78 deletions(-) diff --git a/src/basic/main.c b/src/basic/main.c index e8d69ecb0..ca8cb5a6c 100644 --- a/src/basic/main.c +++ b/src/basic/main.c @@ -2,39 +2,26 @@ #include #include +#include #include #include -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) { diff --git a/src/common/eressea.c b/src/common/eressea.c index 5762dc7b7..38f72b2e8 100644 --- a/src/common/eressea.c +++ b/src/common/eressea.c @@ -25,6 +25,31 @@ #include #endif // BINDINGS_TOLUA +#if MUSEUM_MODULE +#include +#endif +#if ARENA_MODULE +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include 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(); diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 0d0eceeb5..26ac42a44 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -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); diff --git a/src/common/gamecode/creport.h b/src/common/gamecode/creport.h index cbde77874..473f1f0bc 100644 --- a/src/common/gamecode/creport.h +++ b/src/common/gamecode/creport.h @@ -18,7 +18,7 @@ extern "C" { #include extern void creport_cleanup(void); -extern void creport_init(void); +extern void register_cr(void); extern int crwritemap(const char * filename); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 9228228f2..90aeb3217 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -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< extern void xmlreport_cleanup(void); -extern void xmlreport_init(void); +extern void register_xr(void); extern int crwritemap(const char * filename); diff --git a/src/common/gmtool.c b/src/common/gmtool.c index dc9cfe2fb..5d1ce1227 100644 --- a/src/common/gmtool.c +++ b/src/common/gmtool.c @@ -68,10 +68,6 @@ #include #include -extern const char * g_reportdir; -extern const char * g_datadir; -extern const char * g_basedir; - static int g_quit; int force_color = 0; diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 0f7644eaa..f1136bc98 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -96,9 +96,6 @@ typedef enum combatmagic { DO_POSTCOMBATSPELL } combatmagic_t; -/* external variables */ -boolean battledebug = true; - /* globals */ static int obs_count = 0; diff --git a/src/common/kernel/config.c b/src/common/kernel/config.c index 1dada40f6..49026d740 100644 --- a/src/common/kernel/config.c +++ b/src/common/kernel/config.c @@ -76,6 +76,8 @@ #include #include +#include + /* libc includes */ #include #include @@ -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; +} diff --git a/src/common/kernel/config.h b/src/common/kernel/config.h index 5609c8193..2682f1b0f 100644 --- a/src/common/kernel/config.h +++ b/src/common/kernel/config.h @@ -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 */ diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index fb022763f..71e00f5d0 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -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); diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 50c55540d..3003ceee6 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -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; diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index a84239593..d2b6a7a9d 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -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) { diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index 07749e0e1..0773298e6 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -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); diff --git a/src/common/modules/xmas.c b/src/common/modules/xmas.c index 74a80fa26..01f0b4297 100644 --- a/src/common/modules/xmas.c +++ b/src/common/modules/xmas.c @@ -75,7 +75,7 @@ trigger_xmasgate(building * b) } void -init_xmas(void) +register_xmas(void) { tt_register(&tt_xmasgate); } diff --git a/src/common/modules/xmas.h b/src/common/modules/xmas.h index a3c9d02b3..334ab8b38 100644 --- a/src/common/modules/xmas.h +++ b/src/common/modules/xmas.h @@ -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 } diff --git a/src/common/triggers/triggers.c b/src/common/triggers/triggers.c index 236b1fde6..c2663f9e9 100644 --- a/src/common/triggers/triggers.c +++ b/src/common/triggers/triggers.c @@ -42,7 +42,7 @@ #include void -init_triggers(void) +register_triggers(void) { if (verbosity>=2) printf("- registering triggers\n"); tt_register(&tt_changefaction); diff --git a/src/common/triggers/triggers.h b/src/common/triggers/triggers.h index 918325da8..99cb21514 100644 --- a/src/common/triggers/triggers.h +++ b/src/common/triggers/triggers.h @@ -18,7 +18,7 @@ extern "C" { #endif -void init_triggers(void); +void register_triggers(void); #ifdef __cplusplus } diff --git a/src/eressea/main.c b/src/eressea/main.c index bb255221b..f8f3795f0 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -28,7 +28,6 @@ /* initialization - TODO: init in separate module */ #include -#include #include #include