From d0b1f8ac77e10295fb697abc4ad20251f68a95ea Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Feb 2010 09:19:48 +0000 Subject: [PATCH] better naming. * init_ functions need to be run *after* xml is laoded * register_ fucntons are run *before* xml is loaded DNC, WIP --- src/basic/main.c | 61 +------ src/common/attributes/alliance.c | 6 - src/common/attributes/alliance.h | 1 - src/common/attributes/attributes.c | 47 ++---- src/common/attributes/attributes.h | 2 +- src/common/attributes/follow.c | 6 - src/common/attributes/follow.h | 1 - src/common/attributes/gm.c | 6 - src/common/attributes/gm.h | 1 - src/common/attributes/hate.c | 6 - src/common/attributes/hate.h | 1 - src/common/attributes/iceberg.c | 6 - src/common/attributes/iceberg.h | 1 - src/common/attributes/key.c | 6 - src/common/attributes/key.h | 1 - src/common/attributes/moved.c | 6 - src/common/attributes/moved.h | 1 - src/common/attributes/movement.c | 6 - src/common/attributes/movement.h | 1 - src/common/attributes/option.c | 36 ---- src/common/attributes/option.h | 28 ---- src/common/attributes/orcification.c | 6 - src/common/attributes/orcification.h | 1 - src/common/attributes/otherfaction.c | 6 - src/common/attributes/otherfaction.h | 2 +- src/common/attributes/racename.c | 6 - src/common/attributes/racename.h | 1 - src/common/attributes/reduceproduction.c | 6 - src/common/attributes/reduceproduction.h | 1 - src/common/attributes/targetregion.c | 6 - src/common/attributes/targetregion.h | 1 - src/common/attributes/variable.c | 47 ------ src/common/attributes/variable.h | 27 --- src/common/build/curses.c | 1 + src/common/build/gamecode.c | 2 - src/common/build/kernel.c | 3 +- src/common/eressea.c | 203 +++++++++++++++++++++++ src/common/eressea.h | 15 ++ src/common/gamecode.vcproj | 8 + src/common/gamecode/laws.c | 50 ++---- src/common/gamecode/laws.h | 1 + src/common/gamecode/report.c | 31 +--- src/common/kernel.vcproj | 24 --- src/common/kernel/config.c | 21 +-- src/common/kernel/config.h | 1 - src/common/modules/gmcmd.c | 2 +- src/common/modules/gmcmd.h | 2 +- src/common/modules/infocmd.c | 123 -------------- src/common/modules/infocmd.h | 27 --- src/common/settings.h | 1 - src/eressea/main.c | 149 +---------------- 51 files changed, 278 insertions(+), 726 deletions(-) delete mode 100644 src/common/attributes/option.c delete mode 100644 src/common/attributes/option.h delete mode 100644 src/common/attributes/variable.c delete mode 100644 src/common/attributes/variable.h create mode 100644 src/common/eressea.c create mode 100644 src/common/eressea.h delete mode 100644 src/common/modules/infocmd.c delete mode 100644 src/common/modules/infocmd.h diff --git a/src/basic/main.c b/src/basic/main.c index 08899bc79..e8d69ecb0 100644 --- a/src/basic/main.c +++ b/src/basic/main.c @@ -1,62 +1,9 @@ #include #include -#include -int eressea_init(void) -{ - global.vm_state = lua_init(); - kernel_init(); - game_init(); - - return 0; -} - -void eressea_done(void) -{ - game_done(); - kernel_done(); - lua_done((lua_State *)global.vm_state); - log_close(); -} - -static int -log_lua_error(lua_State * L) -{ - static int s_abort_on_errors = 0; - const char* error = lua_tostring(L, -1); - - log_error(("A LUA error occurred: %s\n", error)); - lua_pop(L, 1); - - if (s_abort_on_errors) { - abort(); - } - return 1; -} - -int eressea_run(const char * luafile, const char * entry_point) -{ - lua_State * L = (lua_State *)global.vm_state; - /* run the main script */ - if (luafile) { - char buf[MAX_PATH]; - strcpy(buf, luafile); - lua_getglobal(L, "dofile"); - lua_pushstring(L, buf); - if (lua_pcall(L, 1, 0, 0) != 0) { - log_lua_error(L); - } - } - if (entry_point) { - lua_getglobal(L, entry_point); - if (lua_pcall(L, 0, 1, 0) != 0) { - log_lua_error(L); - } - } else { - lua_console(L); - } - return 0; -} +#include +#include +#include static void load_inifile(const char * filename) @@ -104,7 +51,7 @@ int main(int argc, char ** argv) return err; } - err = eressea_run(luafile); + err = eressea_run(luafile, entry_point); if (err) { log_error(("server execution failed with code %d\n", err)); return err; diff --git a/src/common/attributes/alliance.c b/src/common/attributes/alliance.c index 7b19e4e44..1e3dd4dbb 100644 --- a/src/common/attributes/alliance.c +++ b/src/common/attributes/alliance.c @@ -25,9 +25,3 @@ attrib_type at_alliance = { a_readint, ATF_UNIQUE }; - -void -init_alliance(void) -{ - at_register(&at_alliance); -} diff --git a/src/common/attributes/alliance.h b/src/common/attributes/alliance.h index 45507ce4b..71707ccb6 100644 --- a/src/common/attributes/alliance.h +++ b/src/common/attributes/alliance.h @@ -17,7 +17,6 @@ extern "C" { #endif extern struct attrib_type at_alliance; -extern void init_alliance(void); #ifdef __cplusplus } diff --git a/src/common/attributes/attributes.c b/src/common/attributes/attributes.c index 8c8c6d5cc..d32953268 100644 --- a/src/common/attributes/attributes.c +++ b/src/common/attributes/attributes.c @@ -32,10 +32,6 @@ #include "raceprefix.h" #include "reduceproduction.h" #include "targetregion.h" -#include "variable.h" -#ifdef AT_OPTION -# include "option.h" -#endif #ifdef WDW_PYRAMID # include "alliance.h" #endif @@ -51,40 +47,31 @@ /* util includes */ #include -/* - * library initialization - */ - attrib_type at_unitdissolve = { "unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars }; void -init_attributes(void) +register_attributes(void) { at_register(&at_object); at_register(&at_unitdissolve); - at_register(&at_overrideroads); - at_register(&at_raceprefix); + at_register(&at_overrideroads); + at_register(&at_raceprefix); + at_register(&at_iceberg); + at_register(&at_key); + at_register(&at_gm); + at_register(&at_follow); + at_register(&at_targetregion); + at_register(&at_orcification); + at_register(&at_hate); + at_register(&at_reduceproduction); + at_register(&at_otherfaction); + at_register(&at_racename); + at_register(&at_movement); + at_register(&at_moved); - init_iceberg(); - init_key(); - init_gm(); - init_follow(); /* only for old datafiles */ - init_targetregion(); - init_orcification(); - init_hate(); - init_reduceproduction(); - init_otherfaction(); - init_racename(); - init_movement(); - - init_moved(); -#ifdef AT_OPTION - init_option(); -#endif - init_variable(); #ifdef WDW_PYRAMID - init_alliance(); -#endif + at_register(&at_alliance); +#endif /* WDW_PYRAMID */ } diff --git a/src/common/attributes/attributes.h b/src/common/attributes/attributes.h index e4f85a10f..50b0b4bfd 100644 --- a/src/common/attributes/attributes.h +++ b/src/common/attributes/attributes.h @@ -16,7 +16,7 @@ extern "C" { #endif -extern void init_attributes(void); +extern void register_attributes(void); #ifdef __cplusplus } diff --git a/src/common/attributes/follow.c b/src/common/attributes/follow.c index b6db8be7c..b70417ea9 100644 --- a/src/common/attributes/follow.c +++ b/src/common/attributes/follow.c @@ -40,9 +40,3 @@ make_follow(struct unit * u) a->data.v = u; return a; } - -void -init_follow(void) -{ - at_register(&at_follow); -} diff --git a/src/common/attributes/follow.h b/src/common/attributes/follow.h index a663ccb69..d6b129809 100644 --- a/src/common/attributes/follow.h +++ b/src/common/attributes/follow.h @@ -23,7 +23,6 @@ extern struct attrib_type at_follow; struct unit; extern struct attrib * make_follow(struct unit * u); -extern void init_follow(void); #ifdef __cplusplus } diff --git a/src/common/attributes/gm.c b/src/common/attributes/gm.c index 67c60b9d2..69414fe25 100644 --- a/src/common/attributes/gm.c +++ b/src/common/attributes/gm.c @@ -55,9 +55,3 @@ make_gm(const struct plane * pl) a->data.v = (void*)pl; return a; } - -void -init_gm(void) -{ - at_register(&at_gm); -} diff --git a/src/common/attributes/gm.h b/src/common/attributes/gm.h index 913582059..a197ae500 100644 --- a/src/common/attributes/gm.h +++ b/src/common/attributes/gm.h @@ -24,7 +24,6 @@ struct plane; extern struct attrib_type at_gm; extern struct attrib * make_gm(const struct plane *pl); -extern void init_gm(void); #ifdef __cplusplus } diff --git a/src/common/attributes/hate.c b/src/common/attributes/hate.c index cb0cf2f0b..5d483c60a 100644 --- a/src/common/attributes/hate.c +++ b/src/common/attributes/hate.c @@ -64,9 +64,3 @@ make_hate(struct unit * u) a->data.v = u; return a; } - -void -init_hate(void) -{ - at_register(&at_hate); -} diff --git a/src/common/attributes/hate.h b/src/common/attributes/hate.h index 96207d172..cb347e681 100644 --- a/src/common/attributes/hate.h +++ b/src/common/attributes/hate.h @@ -23,7 +23,6 @@ extern struct attrib_type at_hate; struct unit; extern struct attrib * make_hate(struct unit * u); -extern void init_hate(void); #ifdef __cplusplus } diff --git a/src/common/attributes/iceberg.c b/src/common/attributes/iceberg.c index a3c5edf49..aa80985be 100644 --- a/src/common/attributes/iceberg.c +++ b/src/common/attributes/iceberg.c @@ -36,9 +36,3 @@ make_iceberg(direction_t dir) a->data.i = (int)dir; return a; } - -void -init_iceberg(void) -{ - at_register(&at_iceberg); -} diff --git a/src/common/attributes/iceberg.h b/src/common/attributes/iceberg.h index afed58385..fa14e390e 100644 --- a/src/common/attributes/iceberg.h +++ b/src/common/attributes/iceberg.h @@ -21,7 +21,6 @@ extern "C" { extern struct attrib_type at_iceberg; extern struct attrib * make_iceberg(direction_t dir); -extern void init_iceberg(void); #ifdef __cplusplus } diff --git a/src/common/attributes/key.c b/src/common/attributes/key.c index ac5f7edd8..9d66e0544 100644 --- a/src/common/attributes/key.c +++ b/src/common/attributes/key.c @@ -53,9 +53,3 @@ find_key(attrib * alist, int key) } return (a && a->type==&at_key)?a:NULL; } - -void -init_key(void) -{ - at_register(&at_key); -} diff --git a/src/common/attributes/key.h b/src/common/attributes/key.h index c7548e5b3..75d5e9215 100644 --- a/src/common/attributes/key.h +++ b/src/common/attributes/key.h @@ -23,7 +23,6 @@ extern struct attrib_type at_key; extern struct attrib * make_key(int key); extern struct attrib * find_key(struct attrib * alist, int key); extern struct attrib * add_key(struct attrib ** alist, int key); -extern void init_key(void); #ifdef __cplusplus } diff --git a/src/common/attributes/moved.c b/src/common/attributes/moved.c index 73a43e7bf..b8d609db3 100644 --- a/src/common/attributes/moved.c +++ b/src/common/attributes/moved.c @@ -57,9 +57,3 @@ set_moved(attrib ** alist) if (a==NULL) a = a_add(alist, a_new(&at_moved)); a->data.i = 2; } - -void -init_moved(void) -{ - at_register(&at_moved); -} diff --git a/src/common/attributes/moved.h b/src/common/attributes/moved.h index ece70572c..9c09c1723 100644 --- a/src/common/attributes/moved.h +++ b/src/common/attributes/moved.h @@ -23,7 +23,6 @@ struct attrib_type; extern boolean get_moved(struct attrib ** alist); extern void set_moved(struct attrib ** alist); -extern void init_moved(void); extern struct attrib_type at_moved; diff --git a/src/common/attributes/movement.c b/src/common/attributes/movement.c index ecafc54dc..1348c9c31 100644 --- a/src/common/attributes/movement.c +++ b/src/common/attributes/movement.c @@ -53,9 +53,3 @@ set_movement(attrib ** alist, int type) if (a==NULL) a = a_add(alist, a_new(&at_movement)); a->data.i |= type; } - -void -init_movement(void) -{ - at_register(&at_movement); -} diff --git a/src/common/attributes/movement.h b/src/common/attributes/movement.h index 792b21039..cce9b5696 100644 --- a/src/common/attributes/movement.h +++ b/src/common/attributes/movement.h @@ -20,7 +20,6 @@ extern "C" { extern boolean get_movement(struct attrib * const * alist, int type); extern void set_movement(struct attrib ** alist, int type); -extern void init_movement(void); extern struct attrib_type at_movement; diff --git a/src/common/attributes/option.c b/src/common/attributes/option.c deleted file mode 100644 index 8fda51e8a..000000000 --- a/src/common/attributes/option.c +++ /dev/null @@ -1,36 +0,0 @@ -/* vi: set ts=2: - * - * - * Eressea PB(E)M host Copyright (C) 1998-2003 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Henning Peters (faroul@beyond.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ - -#include -#include -#include "option.h" - -#include -#include - -attrib_type at_option_news = { - "option_news", - NULL, - NULL, - NULL, - a_writeint, - a_readint, - ATF_UNIQUE -}; - -void -init_option(void) -{ - at_register(&at_option_news); -} diff --git a/src/common/attributes/option.h b/src/common/attributes/option.h deleted file mode 100644 index ba548480a..000000000 --- a/src/common/attributes/option.h +++ /dev/null @@ -1,28 +0,0 @@ -/* vi: set ts=2: - * - * - * Eressea PB(E)M host Copyright (C) 1998-2003 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Henning Peters (faroul@beyond.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ - -#ifndef H_ATTRIBUTE_OPTION -#define H_ATTRIBUTE_OPTION -#ifdef __cplusplus -extern "C" { -#endif - -extern struct attrib_type at_option_news; -extern void init_option(void); - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/src/common/attributes/orcification.c b/src/common/attributes/orcification.c index 70da3a34c..f0b5d3f44 100644 --- a/src/common/attributes/orcification.c +++ b/src/common/attributes/orcification.c @@ -34,9 +34,3 @@ make_orcification(int orcification) a->data.i = orcification; return a; } - -void -init_orcification(void) -{ - at_register(&at_orcification); -} diff --git a/src/common/attributes/orcification.h b/src/common/attributes/orcification.h index 255ca6052..80fe0b3fe 100644 --- a/src/common/attributes/orcification.h +++ b/src/common/attributes/orcification.h @@ -18,7 +18,6 @@ extern "C" { extern struct attrib_type at_orcification; extern struct attrib * make_orcification(int orcification); -extern void init_orcification(void); #ifdef __cplusplus } diff --git a/src/common/attributes/otherfaction.c b/src/common/attributes/otherfaction.c index 294ee3404..3d8a2f552 100644 --- a/src/common/attributes/otherfaction.c +++ b/src/common/attributes/otherfaction.c @@ -60,12 +60,6 @@ struct attrib * return a; } -void -init_otherfaction(void) -{ - at_register(&at_otherfaction); -} - faction * visible_faction(const faction *f, const unit * u) { diff --git a/src/common/attributes/otherfaction.h b/src/common/attributes/otherfaction.h index 9b2c18935..9152844e5 100644 --- a/src/common/attributes/otherfaction.h +++ b/src/common/attributes/otherfaction.h @@ -18,7 +18,7 @@ extern "C" { struct faction; struct attrib; extern struct attrib_type at_otherfaction; -extern void init_otherfaction(void); + extern struct faction * get_otherfaction(const struct attrib * a); extern struct attrib * make_otherfaction(struct faction * f); extern struct faction * visible_faction(const struct faction *f, const struct unit * u); diff --git a/src/common/attributes/racename.c b/src/common/attributes/racename.c index f4232e532..b653f3cf9 100644 --- a/src/common/attributes/racename.c +++ b/src/common/attributes/racename.c @@ -51,9 +51,3 @@ set_racename(attrib ** palist, const char * name) } } } - -void -init_racename(void) -{ - at_register(&at_racename); -} diff --git a/src/common/attributes/racename.h b/src/common/attributes/racename.h index fbc991011..1460fdc64 100644 --- a/src/common/attributes/racename.h +++ b/src/common/attributes/racename.h @@ -23,7 +23,6 @@ struct attrib; extern void set_racename(struct attrib ** palist, const char * name); extern const char * get_racename(struct attrib * alist); -extern void init_racename(void); extern struct attrib_type at_racename; diff --git a/src/common/attributes/reduceproduction.c b/src/common/attributes/reduceproduction.c index e4c14ee91..d2ad0da5e 100644 --- a/src/common/attributes/reduceproduction.c +++ b/src/common/attributes/reduceproduction.c @@ -45,9 +45,3 @@ make_reduceproduction(int percent, int time) a->data.sa[1] = (short)time; return a; } - -void -init_reduceproduction(void) -{ - at_register(&at_reduceproduction); -} diff --git a/src/common/attributes/reduceproduction.h b/src/common/attributes/reduceproduction.h index 697b7472b..0eec26fd9 100644 --- a/src/common/attributes/reduceproduction.h +++ b/src/common/attributes/reduceproduction.h @@ -20,7 +20,6 @@ extern "C" { extern struct attrib * make_reduceproduction(int percent, int time); extern struct attrib_type at_reduceproduction; -extern void init_reduceproduction(void); #ifdef __cplusplus } diff --git a/src/common/attributes/targetregion.c b/src/common/attributes/targetregion.c index 88bdea6e3..61a1589fe 100644 --- a/src/common/attributes/targetregion.c +++ b/src/common/attributes/targetregion.c @@ -55,9 +55,3 @@ make_targetregion(struct region * r) a->data.v = r; return a; } - -void -init_targetregion(void) -{ - at_register(&at_targetregion); -} diff --git a/src/common/attributes/targetregion.h b/src/common/attributes/targetregion.h index f5143643b..29fda1d6d 100644 --- a/src/common/attributes/targetregion.h +++ b/src/common/attributes/targetregion.h @@ -22,7 +22,6 @@ extern struct attrib_type at_targetregion; struct region; extern struct attrib * make_targetregion(struct region *); -extern void init_targetregion(void); #ifdef __cplusplus } diff --git a/src/common/attributes/variable.c b/src/common/attributes/variable.c deleted file mode 100644 index 9483c2ce5..000000000 --- a/src/common/attributes/variable.c +++ /dev/null @@ -1,47 +0,0 @@ -/* vi: set ts=2: - * - * - * Eressea PB(E)M host Copyright (C) 1998-2004 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ - -#include -#include -#include "variable.h" - -#include - -#include -#include - -/* libc includes */ -#include -#include -#include -#include - -static int -read_variable(struct attrib *a, storage * store) -{ - char * key = store->r_tok(store); - char * value = store->r_str(store); - free(key); - free(value); - - return AT_READ_FAIL; -} - -attrib_type at_variable = { - "variable", NULL, NULL, NULL, - NULL, read_variable -}; -void -init_variable(void) -{ - at_register(&at_variable); -} diff --git a/src/common/attributes/variable.h b/src/common/attributes/variable.h deleted file mode 100644 index d8f95999e..000000000 --- a/src/common/attributes/variable.h +++ /dev/null @@ -1,27 +0,0 @@ -/* vi: set ts=2: - * - * - * Eressea PB(E)M host Copyright (C) 1998-2004 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ - -#ifndef H_ATTRIBUTE_VARIABLE -#define H_ATTRIBUTE_VARIABLE - -#ifdef __cplusplus -extern "C" { -#endif - -void init_variable(void); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/src/common/build/curses.c b/src/common/build/curses.c index c2c21fb77..24a6fec70 100644 --- a/src/common/build/curses.c +++ b/src/common/build/curses.c @@ -4,3 +4,4 @@ #include #include +#include diff --git a/src/common/build/gamecode.c b/src/common/build/gamecode.c index c2b051add..41416aab6 100644 --- a/src/common/build/gamecode.c +++ b/src/common/build/gamecode.c @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -63,7 +62,6 @@ #include #include #include -#include #include #include diff --git a/src/common/build/kernel.c b/src/common/build/kernel.c index 5da321951..89062a38c 100644 --- a/src/common/build/kernel.c +++ b/src/common/build/kernel.c @@ -11,9 +11,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include diff --git a/src/common/eressea.c b/src/common/eressea.c new file mode 100644 index 000000000..5762dc7b7 --- /dev/null +++ b/src/common/eressea.c @@ -0,0 +1,203 @@ +#include +#include "settings.h" +#include "eressea.h" + +#include +#include +#include + +/* lua includes */ +#ifdef BINDINGS_TOLUA +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // BINDINGS_TOLUA + + + +static const struct { + const char * name; + int (*func)(lua_State *); +} lualibs[] = { + {"", luaopen_base}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_DBLIBNAME, luaopen_debug}, +#if LUA_VERSION_NUM>=501 + {LUA_OSLIBNAME, luaopen_os}, +#endif + { NULL, NULL } +}; + +static void +openlibs(lua_State * L) +{ + int i; + for (i=0;lualibs[i].func;++i) { + lua_pushcfunction(L, lualibs[i].func); + lua_pushstring(L, lualibs[i].name); + lua_call(L, 1, 0); + } +} + +static void +lua_done(lua_State * L) +{ + lua_close(L); +} + +static lua_State * +lua_init(void) +{ + lua_State * L = lua_open(); + + openlibs(L); +#ifdef BINDINGS_TOLUA + register_tolua_helpers(); + tolua_eressea_open(L); + tolua_sqlite_open(L); + tolua_unit_open(L); + tolua_building_open(L); + tolua_ship_open(L); + tolua_region_open(L); + tolua_faction_open(L); + tolua_attrib_open(L); + tolua_unit_open(L); + tolua_message_open(L); + tolua_hashtable_open(L); + tolua_gmtool_open(L); + tolua_storage_open(L); +#endif + return L; +} + +static void +game_done(void) +{ +#ifdef CLEANUP_CODE + /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur + * zum Debugging interessant, wenn man Leak Detection hat, und nach + * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt + * wird (temporäre Hilsstrukturen) */ + + free_game(); + + creport_cleanup(); +#ifdef REPORT_FORMAT_NR + report_cleanup(); +#endif + calendar_cleanup(); +#endif +} + +static void +game_init(void) +{ + init_triggers(); + init_xmas(); + + reports_init(); + report_init(); + creport_init(); + xmlreport_init(); + + debug_language("locales.log"); + register_races(); + register_names(); + register_resources(); + register_buildings(); + register_itemfunctions(); +#ifdef TODO + register_curses(); + register_spells(); + register_gcspells(); +#endif +#if DUNGEON_MODULE + register_dungeon(); +#endif +#if MUSEUM_MODULE + register_museum(); +#endif +#if ARENA_MODULE + register_arena(); +#endif + register_wormholes(); + + register_itemtypes(); + register_xmlreader(); + register_archetypes(); + enable_xml_gamecode(); + + register_attributes(); + register_gmcmd(); + +} + +int eressea_init(void) +{ + global.vm_state = lua_init(); + kernel_init(); + game_init(); + + return 0; +} + +void eressea_done(void) +{ + game_done(); + kernel_done(); + lua_done((lua_State *)global.vm_state); + log_close(); +} + +static int +log_lua_error(lua_State * L) +{ + static int s_abort_on_errors = 0; + const char* error = lua_tostring(L, -1); + + log_error(("A LUA error occurred: %s\n", error)); + lua_pop(L, 1); + + if (s_abort_on_errors) { + abort(); + } + return 1; +} + +int eressea_run(const char * luafile, const char * entry_point) +{ + lua_State * L = (lua_State *)global.vm_state; + /* run the main script */ + if (luafile) { + lua_getglobal(L, "dofile"); + lua_pushstring(L, luafile); + if (lua_pcall(L, 1, 0, 0) != 0) { + log_lua_error(L); + } + } + if (entry_point) { + lua_getglobal(L, entry_point); + if (lua_pcall(L, 0, 1, 0) != 0) { + log_lua_error(L); + } + } else { + lua_console(L); + } + return 0; +} diff --git a/src/common/eressea.h b/src/common/eressea.h new file mode 100644 index 000000000..c2d15d458 --- /dev/null +++ b/src/common/eressea.h @@ -0,0 +1,15 @@ +#ifndef H_ERESSEA_LIB +#define H_ERESSEA_LIB +#ifdef __cplusplus +extern "C" { +#endif + +int eressea_init(void); +void eressea_done(void); +int eressea_run(const char * luafile, const char * entry_point); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/common/gamecode.vcproj b/src/common/gamecode.vcproj index f198fb2b5..ea714a652 100644 --- a/src/common/gamecode.vcproj +++ b/src/common/gamecode.vcproj @@ -330,6 +330,14 @@ > + + + + diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 9b972e91e..44eaaa333 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -26,7 +26,6 @@ #include "laws.h" #include -#include #include /* gamecode includes */ @@ -90,11 +89,6 @@ #include -#ifdef AT_OPTION -/* attributes includes */ -#include -#endif - /* libc includes */ #include #include @@ -2149,29 +2143,7 @@ send_cmd(unit * u, struct order * ord) s = getstrtoken(); option = findoption(s, u->faction->locale); -#ifdef AT_OPTION - /* Sonderbehandlung Zeitungsoption */ - if (option == O_NEWS) { - attrib *a = a_find(u->faction->attribs, &at_option_news); - if(a) a->data.i = 0; - while((s = getstrtoken())) { - if(findparam(s) == P_NOT) { - a_removeall(&u->faction->attribs, &at_option_news); - u->faction->options = u->faction->options & ~O_NEWS; - break; - } else { - int sec = atoi(s); - if(sec != 0) { - if(!a) a_add(&u->faction->attribs, a_new(&at_option_news)); - a->data.i = a->data.i & (1<<(sec-1)); - u->faction->options = u->faction->options | O_NEWS; - } - } - } - return 0; - } -#endif if (option == -1) { cmistake(u, ord, 135, MSG_EVENT); } else { @@ -4027,11 +3999,6 @@ init_processor(void) add_proc_region(p, &enter_1, "Kontaktieren & Betreten (1. Versuch)"); add_proc_order(p, K_USE, &use_cmd, 0, "Benutzen"); -#if INFOCMD_MODULE - if (!global.disabled[K_INFO]) { - add_proc_global(p, &infocommands, NULL); - } -#endif if (!global.disabled[K_GM]) { add_proc_global(p, &gmcommands, "GM Kommandos"); } @@ -4236,3 +4203,20 @@ update_subscriptions(void) } fclose(F); } + +int +init_data(const char * filename) +{ + int l; + + l = read_xml(filename); + if (l) return l; + + init_locales(); + init_archetypes(); + + if (turn<0) { + turn = first_turn; + } + return 0; +} diff --git a/src/common/gamecode/laws.h b/src/common/gamecode/laws.h index b84670247..3a1939bfe 100644 --- a/src/common/gamecode/laws.h +++ b/src/common/gamecode/laws.h @@ -34,6 +34,7 @@ void find_address(void); void update_guards(void); void update_subscriptions(void); void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver); +int init_data(const char * filename); /* eressea-specific. put somewhere else, please. */ void processorders(void); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 8e6223925..9228228f2 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -26,9 +26,6 @@ #include #include #include -#ifdef AT_OPTION -# include -#endif /* gamecode includes */ #include "creport.h" @@ -2120,33 +2117,7 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); bytes = (int)strlcpy(bufp, LOC(f->locale, options[op]), size); if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); -#ifdef AT_OPTION - if(op == O_NEWS) { - attrib *a = a_find(f->attribs, &at_option_news); - if(!a) { - /* Zur Altlastenbeseitigung */ - f->options = f->options & ~op; - } else { - int sec = a->data.i; - int i; - bytes = (int)strlcpy(bufp, "(", size); - if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); - for (i=1; sec != 0; i *= 2) { - if(sec & i) { - bytes = (int)strlcpy(bufp, itoa10(i), size); - if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); - sec = sec & ~i; - if (sec) { - bytes = (int)strlcpy(bufp, ",", size); - if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); - } - } - } - bytes = (int)strlcpy(bufp, ")", size); - if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); - } - } -#endif + flag++; } } diff --git a/src/common/kernel.vcproj b/src/common/kernel.vcproj index 007ecd275..35d82090c 100644 --- a/src/common/kernel.vcproj +++ b/src/common/kernel.vcproj @@ -773,14 +773,6 @@ RelativePath=".\modules\gmcmd.h" > - - - - @@ -949,14 +941,6 @@ RelativePath=".\attributes\object.h" > - - - - @@ -1013,14 +997,6 @@ RelativePath=".\attributes\targetregion.h" > - - - - diff --git a/src/common/kernel/config.c b/src/common/kernel/config.c index f57d211ce..1dada40f6 100644 --- a/src/common/kernel/config.c +++ b/src/common/kernel/config.c @@ -96,7 +96,6 @@ region *regions; faction *factions; struct settings global = { "Eressea", /* gamename */ - 1000, /* maxunits */ }; FILE *logfile; FILE *updatelog; @@ -2197,22 +2196,6 @@ const char * localenames[] = { NULL }; -int -init_data(const char * filename) -{ - int l; - - l = read_xml(filename); - if (l) return l; - - init_locales(); - - if (turn<0) { - turn = first_turn; - } - return 0; -} - void init_locales(void) { @@ -2713,7 +2696,7 @@ int rule_region_owners(void) static int rule_owners = -1; if (rule_owners<0) { rule_owners = get_param_int(global.parameters, "rules.region_owners", 0); - assert(rule>=0); + assert(rule_owners>=0); } return rule_owners; } @@ -2723,7 +2706,7 @@ int rule_auto_taxation(void) static int rule_taxation = -1; if (rule_taxation<0) { rule_taxation = get_param_int(global.parameters, "rules.economy.taxation", TAX_ORDER); - assert(rule>=0); + assert(rule_taxation>=0); } return rule_taxation; } diff --git a/src/common/kernel/config.h b/src/common/kernel/config.h index b40f11868..5609c8193 100644 --- a/src/common/kernel/config.h +++ b/src/common/kernel/config.h @@ -118,7 +118,6 @@ extern const char *options[MAXOPTIONS]; /* ------------------------------------------------------------- */ extern int shipspeed(const struct ship * sh, const struct unit * u); -extern int init_data(const char * filename); #define i2b(i) ((boolean)((i)?(true):(false))) diff --git a/src/common/modules/gmcmd.c b/src/common/modules/gmcmd.c index 04a18e92e..caaaf99f0 100644 --- a/src/common/modules/gmcmd.c +++ b/src/common/modules/gmcmd.c @@ -566,7 +566,7 @@ static tnode g_tell; static tnode g_kill; void -init_gmcmd(void) +register_gmcmd(void) { at_register(&at_gmcreate); at_register(&at_permissions); diff --git a/src/common/modules/gmcmd.h b/src/common/modules/gmcmd.h index 8293a77ab..d7b8e19d2 100644 --- a/src/common/modules/gmcmd.h +++ b/src/common/modules/gmcmd.h @@ -24,7 +24,7 @@ struct unit; struct faction; struct region; -extern void init_gmcmd(void); +extern void register_gmcmd(void); /* initialize this module */ extern void gmcommands(void); diff --git a/src/common/modules/infocmd.c b/src/common/modules/infocmd.c deleted file mode 100644 index 7c33b450d..000000000 --- a/src/common/modules/infocmd.c +++ /dev/null @@ -1,123 +0,0 @@ -/* vi: set ts=2: - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - - */ -#include -#include - -#if INFOCMD_MODULE -#include "infocmd.h" - -#include "command.h" - -/* kernel includes */ -#include -#include -#include -#include -#include - -/* util includes */ -#include -#include - -/* libc includes */ -#include -#include -#include - -static void -info_email(const tnode * tnext, const char * str, void * data, struct order * ord) -{ - unused(str); - unused(data); - unused(ord); -} - -static void -info_name(const tnode * tnext, const char * str, void * data, struct order * ord) -{ - unused(tnext); - unused(str); - unused(data); - unused(ord); -} - -static void -info_address(const tnode * tnext, const char * str, void * data, struct order * ord) -{ -} - -static void -info_phone(const tnode * tnext, const char * str, void * data, struct order * ord) -{ -} - -static void -info_vacation(const tnode * tnext, const char * str, void * data, struct order * ord) -{ - -#ifdef SQLOUTPUT - if (sqlstream!=NULL) { - unit * u = (unit*)data; - faction * f = u->faction; - const char * email = sqlquote(igetstrtoken(str)); - int duration = atoi(getstrtoken()); - time_t start_time = time(NULL); - time_t end_time = start_time + 60*60*24*duration; - struct tm start = *localtime(&start_time); - struct tm end = *localtime(&end_time); - fprintf(sqlstream, "UPDATE factions SET vacation = '%s' WHERE id = '%s';\n", email, itoa36(f->no)); - fprintf(sqlstream, "UPDATE factions SET vacation_start = '%04d-%02d-%02d' WHERE id = '%s';\n", - start.tm_year, start.tm_mon, start.tm_mday, itoa36(f->no)); - fprintf(sqlstream, "UPDATE factions SET vacation_end = '%04d-%02d-%02d' WHERE id = '%s';\n", - end.tm_year, end.tm_mon, end.tm_mday, itoa36(f->no)); - } -#endif -} - -static tnode g_keys; -static tnode g_info; - -void -infocommands(void) -{ - region ** rp = ®ions; - while (*rp) { - region * r = *rp; - unit **up = &r->units; - while (*up) { - unit * u = *up; - order * ord; - for (ord = u->orders; ord; ord = ord->next) { - if (get_keyword(ord) == K_INFO) { - do_command(&g_keys, u, ord); - } - } - if (u==*up) up = &u->next; - } - if (*rp==r) rp = &r->next; - } -} - -void -init_info(void) -{ - add_command(&g_keys, &g_info, "info", NULL); - - add_command(&g_info, NULL, "email", &info_email); - add_command(&g_info, NULL, "name", &info_name); - add_command(&g_info, NULL, "adresse", &info_address); - add_command(&g_info, NULL, "telefon", &info_phone); - add_command(&g_info, NULL, "urlaub", &info_vacation); -} -#endif /* INFOCMD_MODULE */ - diff --git a/src/common/modules/infocmd.h b/src/common/modules/infocmd.h deleted file mode 100644 index f22929795..000000000 --- a/src/common/modules/infocmd.h +++ /dev/null @@ -1,27 +0,0 @@ -/* vi: set ts=2: - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - - */ -#ifndef INFOCMD_H -#define INFOCMD_H -#ifdef __cplusplus -extern "C" { -#endif - -#if INFOCMD_MODULE -extern void init_info(void); -extern void infocommands(void); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/common/settings.h b/src/common/settings.h index cbf907261..78bd22926 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -47,7 +47,6 @@ #define XECMD_MODULE 1 #define KARMA_MODULE 0 #define DUNGEON_MODULE 0 -#define INFOCMD_MODULE 0 #define CHANGED_CROSSBOWS 0 /* use the WTF_ARMORPIERCING flag */ #undef GLOBAL_WARMING /* number of turns before global warming sets in */ diff --git a/src/eressea/main.c b/src/eressea/main.c index f38fb29dd..bb255221b 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -21,9 +21,10 @@ /* config includes */ #include -#include +#include #include +#include /* initialization - TODO: init in separate module */ #include @@ -34,7 +35,6 @@ /* modules includes */ #include #include -#include #if MUSEUM_MODULE #include #endif @@ -192,133 +192,6 @@ setup_signal_handler(void) } #endif -static void -game_init(void) -{ - init_triggers(); - init_xmas(); - - reports_init(); - report_init(); - creport_init(); - xmlreport_init(); - - debug_language("locales.log"); - register_races(); - register_names(); - register_resources(); - register_buildings(); - register_itemfunctions(); -#ifdef TODO - register_curses(); - register_spells(); - register_gcspells(); -#endif -#if DUNGEON_MODULE - register_dungeon(); -#endif -#if MUSEUM_MODULE - register_museum(); -#endif -#if ARENA_MODULE - register_arena(); -#endif - register_wormholes(); - - register_itemtypes(); - register_xmlreader(); - register_archetypes(); - enable_xml_gamecode(); - - /* init_data(game_name); */ - - init_archetypes(); - init_attributes(); - - init_gmcmd(); -#if INFOCMD_MODULE - init_info(); -#endif -} - -static const struct { - const char * name; - int (*func)(lua_State *); -} lualibs[] = { - {"", luaopen_base}, - {LUA_TABLIBNAME, luaopen_table}, - {LUA_IOLIBNAME, luaopen_io}, - {LUA_STRLIBNAME, luaopen_string}, - {LUA_MATHLIBNAME, luaopen_math}, - {LUA_LOADLIBNAME, luaopen_package}, - {LUA_DBLIBNAME, luaopen_debug}, -#if LUA_VERSION_NUM>=501 - {LUA_OSLIBNAME, luaopen_os}, -#endif - { NULL, NULL } -}; - -static void -openlibs(lua_State * L) -{ - int i; - for (i=0;lualibs[i].func;++i) { - lua_pushcfunction(L, lualibs[i].func); - lua_pushstring(L, lualibs[i].name); - lua_call(L, 1, 0); - } -} - -static lua_State * -lua_init(void) -{ - lua_State * L = lua_open(); - - openlibs(L); -#ifdef BINDINGS_TOLUA - register_tolua_helpers(); - tolua_eressea_open(L); - tolua_sqlite_open(L); - tolua_unit_open(L); - tolua_building_open(L); - tolua_ship_open(L); - tolua_region_open(L); - tolua_faction_open(L); - tolua_attrib_open(L); - tolua_unit_open(L); - tolua_message_open(L); - tolua_hashtable_open(L); - tolua_gmtool_open(L); - tolua_storage_open(L); -#endif - return L; -} - -static void -lua_done(lua_State * luaState) -{ - lua_close(luaState); -} - -static void -game_done(void) -{ -#ifdef CLEANUP_CODE - /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur - * zum Debugging interessant, wenn man Leak Detection hat, und nach - * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt - * wird (temporäre Hilsstrukturen) */ - - free_game(); - - creport_cleanup(); -#ifdef REPORT_FORMAT_NR - report_cleanup(); -#endif - calendar_cleanup(); -#endif -} - #define CRTDBG #ifdef CRTDBG void @@ -601,18 +474,9 @@ write_skills(void) void locale_init(void) { - char * lc_ctype; - char * lc_numeric; - - lc_ctype = setlocale(LC_CTYPE, ""); - lc_numeric = setlocale(LC_NUMERIC, "C"); + setlocale(LC_CTYPE, ""); + setlocale(LC_NUMERIC, "C"); assert(towlower(0xC4)==0xE4); /* Ä => ä */ - if (lc_ctype) { - lc_ctype = strdup(lc_ctype); - } - if (lc_numeric) { - lc_numeric = strdup(lc_numeric); - } } int @@ -668,11 +532,6 @@ main(int argc, char *argv[]) lua_done(L); log_close(); - setlocale(LC_CTYPE, lc_ctype); - setlocale(LC_NUMERIC, lc_numeric); - free(lc_ctype); - free(lc_numeric); - if (global.inifile) iniparser_free(global.inifile); return 0;