From 7b4b2ea4cfb7f493a6712e272e872a9ab796184c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Feb 2010 08:03:17 +0000 Subject: [PATCH] various configurations => rules --- src/basic/main.c | 109 +++++ src/common/gamecode/laws.c | 54 +-- src/common/kernel/eressea.c | 26 +- src/common/kernel/eressea.h | 7 +- src/common/kernel/xmlreader.c | 2 - src/eressea/main.c | 36 +- src/res/conquest.xml | 25 -- src/res/e3a.xml | 5 +- src/res/eressea.xml | 3 +- src/res/eressea2.xml | 136 ------- src/res/eressea2/equipment.xml | 38 -- src/res/eressea2/races.xml | 297 -------------- src/res/eressea2/spells.xml | 699 --------------------------------- src/res/eressea2/terrains.xml | 85 ---- src/res/eressea2/weapons.xml | 275 ------------- src/res/vinyambar-3.xml | 5 +- src/res/vinyambar-classic.xml | 3 +- src/res/vinyambar-wdw.xml | 3 +- src/res/vinyambar.xml | 5 +- 19 files changed, 201 insertions(+), 1612 deletions(-) delete mode 100644 src/res/conquest.xml delete mode 100644 src/res/eressea2.xml delete mode 100644 src/res/eressea2/equipment.xml delete mode 100644 src/res/eressea2/races.xml delete mode 100644 src/res/eressea2/spells.xml delete mode 100644 src/res/eressea2/terrains.xml delete mode 100644 src/res/eressea2/weapons.xml diff --git a/src/basic/main.c b/src/basic/main.c index bf13b20d0..08899bc79 100644 --- a/src/basic/main.c +++ b/src/basic/main.c @@ -1,6 +1,115 @@ #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; +} + +static void +load_inifile(const char * filename) +{ + dictionary * d = iniparser_new(filename); + if (d) { + const char * str; + + 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; +} int main(int argc, char ** argv) { + int err; + + load_inifile("eressea.ini"); + + err = eressea_init(); + if (err) { + log_error(("initialization failed with code %d\n", err)); + return err; + } + + err = eressea_run(luafile); + if (err) { + log_error(("server execution failed with code %d\n", err)); + return err; + } + + eressea_done(); return 0; } diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index c5b0602dd..828c0757a 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3214,48 +3214,47 @@ ageing(void) static int maxunits(const faction *f) { - if (global.unitsperalliance == true) { - float mult = 1.0; - -#if KARMA_MODULE - faction *f2; - for (f2 = factions; f2; f2 = f2->next) { - if (f2->alliance == f->alliance) { - mult += 0.4f * fspecial(f2, FS_ADMINISTRATOR); - } - } -#endif /* KARMA_MODULE */ - return (int) (global.maxunits * mult); + int flimit = rule_faction_limit(); + int alimit = rule_alliance_limit(); + if (alimit==0) { + return flimit; } -#if KARMA_MODULE - return (int) (global.maxunits * (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR))); -#else - return global.maxunits; -#endif /* KARMA_MODULE */ + if (flimit==0) { + return alimit; + } + return MIN(alimit, flimit); } -static boolean +static int checkunitnumber(const faction *f, int add) { - if (global.maxunits==0) return true; - if (global.unitsperalliance == true) { + int alimit, flimit; + + alimit = rule_alliance_limit(); + if (alimit) { /* if unitsperalliance is true, maxunits returns the number of units allowed in an alliance */ faction *f2; int unitsinalliance = add; - int maxu = maxunits(f); for (f2 = factions; f2; f2 = f2->next) { if (f->alliance == f2->alliance) { unitsinalliance += f2->no_units; } - if (unitsinalliance > maxu) return false; + if (unitsinalliance > alimit) { + return 1; + } } - - return true; } - return (f->no_units + add < maxunits(f)); + flimit = rule_alliance_limit(); + if (flimit) { + if (f->no_units + add < flimit) { + return 2; + } + } + + return 0; } static void @@ -3282,9 +3281,10 @@ new_units (void) int alias; ship * sh; order ** newordersp; + int err = checkunitnumber(u->faction, 1); - if (!checkunitnumber(u->faction, 1)) { - if (global.unitsperalliance) { + if (err) { + if (err==1) { ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, "too_many_units_in_alliance", "allowed", maxunits(u->faction))); } else { diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index c8fc7f8e8..cfebc9ce4 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -587,7 +587,7 @@ skill_limit(faction * f, skill_t sk) return m; } -char * g_basedir; +const char * g_basedir; const char * basepath(void) @@ -2703,6 +2703,7 @@ int rule_stealth_faction(void) static int rule = -1; if (rule<0) { rule = get_param_int(global.parameters, "rules.stealth.faction", 1); + assert(rule>=0); } return rule; } @@ -2712,6 +2713,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); } return rule_owners; } @@ -2721,6 +2723,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); } return rule_taxation; } @@ -2730,6 +2733,27 @@ int rule_blessed_harvest(void) static int rule = -1; if (rule<0) { rule = get_param_int(global.parameters, "rules.magic.blessed_harvest", HARVEST_WORK); + assert(rule>=0); + } + return rule; +} + +int rule_alliance_limit(void) +{ + static int rule = -1; + if (rule<0) { + rule = get_param_int(global.parameters, "rules.limit.alliance", 0); + assert(rule>=0); + } + return rule; +} + +int rule_faction_limit(void) +{ + static int rule = -1; + if (rule<0) { + rule = get_param_int(global.parameters, "rules.limit.faction", 0); + assert(rule>=0); } return rule; } diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index bf617b438..5160f1611 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -258,6 +258,9 @@ int rule_stealth_faction(void); #define HARVEST_WORK 0x00 #define HARVEST_TAXES 0x01 int rule_blessed_harvest(void); +extern int rule_give(void); +extern int rule_alliance_limit(void); +extern int rule_faction_limit(void); extern int count_all(const struct faction * f); extern int count_migrants (const struct faction * f); @@ -376,8 +379,6 @@ extern const struct race * new_race[]; /* globale settings des Spieles */ typedef struct settings { const char *gamename; - boolean unitsperalliance; - unsigned int maxunits; struct attrib *attribs; unsigned int data_turn; boolean disabled[MAXKEYWORDS]; @@ -426,8 +427,6 @@ typedef struct helpmode { extern struct helpmode helpmodes[]; -extern int rule_give(void); - #define GIVE_SELF 1 #define GIVE_PEASANTS 2 #define GIVE_LUXURIES 4 diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index ec58ce2aa..5db22dac0 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -2088,9 +2088,7 @@ parse_main(xmlDocPtr doc) if (nodes->nodeNr>0) { xmlNodePtr node = nodes->nodeTab[0]; - global.unitsperalliance = xml_bvalue(node, "unitsperalliance", false); global.producexpchance = (float)xml_fvalue(node, "learningbydoing", 1.0/3); - global.maxunits = xml_ivalue(node, "units", INT_MAX); propValue = xmlGetProp(node, BAD_CAST "name"); if (propValue!=NULL) { diff --git a/src/eressea/main.c b/src/eressea/main.c index 678d4285c..f38fb29dd 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -406,6 +406,11 @@ read_args(int argc, char **argv, lua_State * luaState) nocr = true; nocr = true; } + else if (strcmp(argv[i]+2, "version")==0) { + printf("\n%s PBEM host\n" + "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" + "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); + } else if (strcmp(argv[i]+2, "xml")==0) game_name = argv[++i]; else if (strcmp(argv[i]+2, "ignore-errors")==0) g_ignore_errors = true; else if (strcmp(argv[i]+2, "nonr")==0) nonr = true; @@ -594,33 +599,36 @@ write_skills(void) fclose(F); } +void locale_init(void) +{ + char * lc_ctype; + char * lc_numeric; + + lc_ctype = setlocale(LC_CTYPE, ""); + lc_numeric = 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 main(int argc, char *argv[]) { int i; - char * lc_ctype; - char * lc_numeric; lua_State * L; static int write_csv = 0; setup_signal_handler(); log_open("eressea.log"); - - lc_ctype = setlocale(LC_CTYPE, ""); - lc_numeric = setlocale(LC_NUMERIC, "C"); - assert(towlower(0xC4)==0xE4); - if (lc_ctype) lc_ctype = strdup(lc_ctype); - if (lc_numeric) lc_numeric = strdup(lc_numeric); - + locale_init(); load_inifile("eressea.ini"); L = lua_init(); global.vm_state = L; - if (verbosity>=4) { - printf("\n%s PBEM host\n" - "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" - "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); - } if ((i=read_args(argc, argv, L))!=0) return i; #ifdef CRTDBG diff --git a/src/res/conquest.xml b/src/res/conquest.xml deleted file mode 100644 index d3e8d2304..000000000 --- a/src/res/conquest.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - Localization - - - - - - - - - - - - - - - - Game specific - - - - - diff --git a/src/res/e3a.xml b/src/res/e3a.xml index efcdb37dd..874bf1463 100644 --- a/src/res/e3a.xml +++ b/src/res/e3a.xml @@ -56,7 +56,7 @@ - + @@ -170,13 +170,14 @@ + - + diff --git a/src/res/eressea.xml b/src/res/eressea.xml index 1d5f845e0..cce31579b 100644 --- a/src/res/eressea.xml +++ b/src/res/eressea.xml @@ -46,7 +46,7 @@ - + @@ -97,6 +97,7 @@ + diff --git a/src/res/eressea2.xml b/src/res/eressea2.xml deleted file mode 100644 index 38a0570d6..000000000 --- a/src/res/eressea2.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eressea-server@eressea.de - eressea-server@eressea.de - - - Bitte denke daran, deine Befehle mit dem Betreff - ERESSEA BEFEHLE an eressea-server@eressea.de zu senden. - Remember to send your orders to - eressea-server@eressea.de with the subject ERESSEA ORDERS. - - - ERESSEA BEFEHLE - ERESSEA ORDERS - - - diff --git a/src/res/eressea2/equipment.xml b/src/res/eressea2/equipment.xml deleted file mode 100644 index e11edf1db..000000000 --- a/src/res/eressea2/equipment.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/res/eressea2/races.xml b/src/res/eressea2/races.xml deleted file mode 100644 index cf02a0675..000000000 --- a/src/res/eressea2/races.xml +++ /dev/null @@ -1,297 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/res/eressea2/spells.xml b/src/res/eressea2/spells.xml deleted file mode 100644 index 9e786157a..000000000 --- a/src/res/eressea2/spells.xml +++ /dev/null @@ -1,699 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/res/eressea2/terrains.xml b/src/res/eressea2/terrains.xml deleted file mode 100644 index f6a03a496..000000000 --- a/src/res/eressea2/terrains.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/res/eressea2/weapons.xml b/src/res/eressea2/weapons.xml deleted file mode 100644 index dc7112577..000000000 --- a/src/res/eressea2/weapons.xml +++ /dev/null @@ -1,275 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/res/vinyambar-3.xml b/src/res/vinyambar-3.xml index 14bbe0450..9703bc044 100644 --- a/src/res/vinyambar-3.xml +++ b/src/res/vinyambar-3.xml @@ -11,9 +11,9 @@ - + - + @@ -25,6 +25,7 @@ + diff --git a/src/res/vinyambar-classic.xml b/src/res/vinyambar-classic.xml index 30991f2f6..fb501df70 100644 --- a/src/res/vinyambar-classic.xml +++ b/src/res/vinyambar-classic.xml @@ -9,7 +9,7 @@ - + Game specific @@ -18,6 +18,7 @@ + diff --git a/src/res/vinyambar-wdw.xml b/src/res/vinyambar-wdw.xml index 55278b3be..ee3238223 100644 --- a/src/res/vinyambar-wdw.xml +++ b/src/res/vinyambar-wdw.xml @@ -22,7 +22,7 @@ - + @@ -72,6 +72,7 @@ + diff --git a/src/res/vinyambar.xml b/src/res/vinyambar.xml index 25f93d2ae..31825132c 100644 --- a/src/res/vinyambar.xml +++ b/src/res/vinyambar.xml @@ -9,9 +9,9 @@ - + Game specific - + @@ -19,6 +19,7 @@ +