better naming.

* init_ functions need to be run *after* xml is laoded
* register_ fucntons are run *before* xml is loaded

DNC, WIP
This commit is contained in:
Enno Rehling 2010-02-21 09:19:48 +00:00
parent 21d7e08222
commit d0b1f8ac77
51 changed files with 278 additions and 726 deletions

View File

@ -1,62 +1,9 @@
#include <platform.h>
#include <util/log.h>
#include <kernel/eressea.h>
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 <eressea.h>
#include <kernel/config.h>
#include <iniparser/iniparser.h>
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;

View File

@ -25,9 +25,3 @@ attrib_type at_alliance = {
a_readint,
ATF_UNIQUE
};
void
init_alliance(void)
{
at_register(&at_alliance);
}

View File

@ -17,7 +17,6 @@ extern "C" {
#endif
extern struct attrib_type at_alliance;
extern void init_alliance(void);
#ifdef __cplusplus
}

View File

@ -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 <util/attrib.h>
/*
* 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 */
}

View File

@ -16,7 +16,7 @@
extern "C" {
#endif
extern void init_attributes(void);
extern void register_attributes(void);
#ifdef __cplusplus
}

View File

@ -40,9 +40,3 @@ make_follow(struct unit * u)
a->data.v = u;
return a;
}
void
init_follow(void)
{
at_register(&at_follow);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -64,9 +64,3 @@ make_hate(struct unit * u)
a->data.v = u;
return a;
}
void
init_hate(void)
{
at_register(&at_hate);
}

View File

@ -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
}

View File

@ -36,9 +36,3 @@ make_iceberg(direction_t dir)
a->data.i = (int)dir;
return a;
}
void
init_iceberg(void)
{
at_register(&at_iceberg);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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 <platform.h>
#include <kernel/config.h>
#include "option.h"
#include <kernel/save.h>
#include <util/attrib.h>
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);
}

View File

@ -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

View File

@ -34,9 +34,3 @@ make_orcification(int orcification)
a->data.i = orcification;
return a;
}
void
init_orcification(void)
{
at_register(&at_orcification);
}

View File

@ -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
}

View File

@ -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)
{

View File

@ -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);

View File

@ -51,9 +51,3 @@ set_racename(attrib ** palist, const char * name)
}
}
}
void
init_racename(void)
{
at_register(&at_racename);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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
}

View File

@ -55,9 +55,3 @@ make_targetregion(struct region * r)
a->data.v = r;
return a;
}
void
init_targetregion(void)
{
at_register(&at_targetregion);
}

View File

@ -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
}

View File

@ -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 <platform.h>
#include <kernel/config.h>
#include "variable.h"
#include <kernel/save.h>
#include <util/attrib.h>
#include <util/storage.h>
/* libc includes */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
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);
}

View File

@ -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

View File

@ -4,3 +4,4 @@
#include <util/listbox.c>
#include <gmtool.c>
#include <eressea.c>

View File

@ -54,7 +54,6 @@
#include <attributes/movement.c>
#include <attributes/moved.c>
#include <attributes/object.c>
#include <attributes/option.c>
#include <attributes/orcification.c>
#include <attributes/otherfaction.c>
#include <attributes/overrideroads.c>
@ -63,7 +62,6 @@
#include <attributes/reduceproduction.c>
#include <attributes/targetregion.c>
#include <attributes/viewrange.c>
#include <attributes/variable.c>
#include <items/artrewards.c>
#include <items/demonseye.c>

View File

@ -11,9 +11,9 @@
#include <kernel/building.c>
#include <kernel/calendar.c>
#include <kernel/command.c>
#include <kernel/config.c>
#include <kernel/curse.c>
#include <kernel/equipment.c>
#include <kernel/eressea.c>
#include <kernel/faction.c>
#include <kernel/group.c>
#include <kernel/item.c>
@ -46,7 +46,6 @@
#include <modules/autoseed.c>
#include <modules/dungeon.c>
#include <modules/gmcmd.c>
#include <modules/infocmd.c>
#include <modules/museum.c>
#include <modules/score.c>
#include <modules/weather.c>

203
src/common/eressea.c Normal file
View File

@ -0,0 +1,203 @@
#include <platform.h>
#include "settings.h"
#include "eressea.h"
#include <kernel/config.h>
#include <util/console.h>
#include <util/log.h>
/* lua includes */
#ifdef BINDINGS_TOLUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <bindings/bindings.h>
#include <bindings/helpers.h>
#include <bindings/bind_attrib.h>
#include <bindings/bind_building.h>
#include <bindings/bind_faction.h>
#include <bindings/bind_gmtool.h>
#include <bindings/bind_hashtable.h>
#include <bindings/bind_message.h>
#include <bindings/bind_region.h>
#include <bindings/bind_ship.h>
#include <bindings/bind_storage.h>
#include <bindings/bind_unit.h>
#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;
}

15
src/common/eressea.h Normal file
View File

@ -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

View File

@ -330,6 +330,14 @@
>
</File>
</Filter>
<File
RelativePath=".\eressea.c"
>
</File>
<File
RelativePath=".\eressea.h"
>
</File>
<File
RelativePath=".\gmtool.c"
>

View File

@ -26,7 +26,6 @@
#include "laws.h"
#include <modules/gmcmd.h>
#include <modules/infocmd.h>
#include <modules/wormhole.h>
/* gamecode includes */
@ -90,11 +89,6 @@
#include <modules/xecmd.h>
#ifdef AT_OPTION
/* attributes includes */
#include <attributes/option.h>
#endif
/* libc includes */
#include <assert.h>
#include <stdio.h>
@ -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;
}

View File

@ -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);

View File

@ -26,9 +26,6 @@
#include <attributes/otherfaction.h>
#include <attributes/alliance.h>
#include <attributes/reduceproduction.h>
#ifdef AT_OPTION
# include <attributes/option.h>
#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++;
}
}

View File

@ -773,14 +773,6 @@
RelativePath=".\modules\gmcmd.h"
>
</File>
<File
RelativePath=".\modules\infocmd.c"
>
</File>
<File
RelativePath=".\modules\infocmd.h"
>
</File>
<File
RelativePath=".\modules\museum.c"
>
@ -949,14 +941,6 @@
RelativePath=".\attributes\object.h"
>
</File>
<File
RelativePath=".\attributes\option.c"
>
</File>
<File
RelativePath=".\attributes\option.h"
>
</File>
<File
RelativePath=".\attributes\orcification.c"
>
@ -1013,14 +997,6 @@
RelativePath=".\attributes\targetregion.h"
>
</File>
<File
RelativePath=".\attributes\variable.c"
>
</File>
<File
RelativePath=".\attributes\variable.h"
>
</File>
<File
RelativePath=".\attributes\viewrange.c"
>

View File

@ -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;
}

View File

@ -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)))

View File

@ -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);

View File

@ -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);

View File

@ -1,123 +0,0 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <platform.h>
#include <kernel/config.h>
#if INFOCMD_MODULE
#include "infocmd.h"
#include "command.h"
/* kernel includes */
#include <kernel/order.h>
#include <kernel/faction.h>
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/save.h>
/* util includes */
#include <base36.h>
#include <sql.h>
/* libc includes */
#include <string.h>
#include <time.h>
#include <stdlib.h>
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 = &regions;
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 */

View File

@ -1,27 +0,0 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
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

View File

@ -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 */

View File

@ -21,9 +21,10 @@
/* config includes */
#include <platform.h>
#include <kernel/eressea.h>
#include <kernel/config.h>
#include <gmtool.h>
#include <eressea.h>
/* initialization - TODO: init in separate module */
#include <attributes/attributes.h>
@ -34,7 +35,6 @@
/* modules includes */
#include <modules/xmas.h>
#include <modules/gmcmd.h>
#include <modules/infocmd.h>
#if MUSEUM_MODULE
#include <modules/museum.h>
#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); /* &Auml; => &auml; */
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;