diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 85f12e7ef..381ad5c75 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -379,6 +379,7 @@ typedef struct settings { void * vm_state; float producexpchance; int cookie; + struct _dictionary_ * inifile; struct global_functions { int (*wage)(const struct region *r, const struct faction * f, const struct race * rc, int in_turn); diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index d42e7d3d6..52cdbeaf6 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -338,6 +338,7 @@ extern struct attrib_type at_showitem; /* show this potion's description */ extern void register_resources(void); extern void init_resources(void); +extern void init_itemtypes(void); extern void register_item_give(int (*foo) (struct unit *, struct unit *, const struct item_type *, int, struct order *), const char * name); extern void register_item_use(int (*foo) (struct unit *, const struct item_type *, int, struct order *), const char * name); diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index d59f3de89..a06545919 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -265,7 +265,7 @@ report_items(const item * items, item * result, int size, const unit * owner, co report_item(owner, itm, viewer, NULL, &ic, NULL, false); if (ic && *ic) { - for (ishow = result; ishow!=result+n; ishow=ishow->next) { + for (ishow = result; ishow!=result+n; ++ishow) { const char * sc; if (ishow->type==itm->type) sc = ic; @@ -277,6 +277,7 @@ report_items(const item * items, item * result, int size, const unit * owner, co } if (ishow==result+n) { if (n==size) { + log_error(("too many items to report, increase buffer size.\n")); return -1; } result[n].number = itm->number; diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 3fc22dfb3..50c55540d 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -135,7 +135,7 @@ extern int report_action(struct region * r, struct unit * actor, struct message extern const char * combatstatus[]; #define GR_PLURAL 0x01 /* grammar: plural */ -#define MAX_INVENTORY 64 /* maimum number of different items in an inventory */ +#define MAX_INVENTORY 128 /* maimum number of different items in an inventory */ #define MAX_RAWMATERIALS 8 /* maximum kinds of raw materials in a regions */ #ifdef __cplusplus diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 01d4d3960..faa74fb53 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -1170,6 +1170,7 @@ parse_resources(xmlDocPtr doc) /* make sure old items (used in requirements) are available */ init_resources(); + init_itemtypes(); return 0; } diff --git a/src/eressea.vcproj b/src/eressea.vcproj index d059173c0..4a228ac58 100644 --- a/src/eressea.vcproj +++ b/src/eressea.vcproj @@ -277,27 +277,6 @@ /> - - - - - - - - - diff --git a/src/eressea/server.c b/src/eressea/server.c index 192876491..49ad5c205 100644 --- a/src/eressea/server.c +++ b/src/eressea/server.c @@ -247,7 +247,6 @@ game_init(void) init_archetypes(); init_attributes(); - init_itemtypes(); init_gmcmd(); #if INFOCMD_MODULE @@ -550,15 +549,14 @@ my_lua_error(lua_State * L) return 1; } -static dictionary * inifile; 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); - game_name = iniparser_getstring(d, "eressea:game", game_name); lomem = iniparser_getint(d, "eressea:lomem", lomem)?1:0; memdebug = iniparser_getint(d, "eressea:memcheck", memdebug); @@ -573,13 +571,16 @@ load_inifile(const char * filename) luafile = iniparser_getstring(d, "eressea:load", luafile); g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir); - /* editor settings */ - force_color = iniparser_getint(d, "editor:color", force_color); - 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); } - inifile = d; + global.inifile = d; } static void @@ -639,7 +640,7 @@ main(int argc, char *argv[]) int i; char * lc_ctype; char * lc_numeric; - lua_State * L = lua_init(); + lua_State * L; static int write_csv = 0; setup_signal_handler(); @@ -652,8 +653,9 @@ main(int argc, char *argv[]) if (lc_ctype) lc_ctype = strdup(lc_ctype); if (lc_numeric) lc_numeric = strdup(lc_numeric); - global.vm_state = L; 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" @@ -703,7 +705,7 @@ main(int argc, char *argv[]) free(lc_ctype); free(lc_numeric); - if (inifile) iniparser_free(inifile); + if (global.inifile) iniparser_free(global.inifile); return 0; } diff --git a/src/eressea/tolua/bindings.c b/src/eressea/tolua/bindings.c index 82c1d7098..4c02edb5b 100644 --- a/src/eressea/tolua/bindings.c +++ b/src/eressea/tolua/bindings.c @@ -59,6 +59,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #include @@ -896,6 +897,22 @@ tolua_write_spells(lua_State* L) return 0; } +static int +tolua_get_locales(lua_State *L) +{ + const struct locale * lang; + int i = 0, n = 0; + + for (lang = locales;lang;lang = nextlocale(lang)) ++n; + lua_createtable(L, n, 0); + + for (lang = locales;lang;lang = nextlocale(lang)) { + tolua_pushstring(L, TOLUA_CAST locale_name(lang)); + lua_rawseti(L, -2, ++i); + } + return 1; +} + static int tolua_get_spell_text(lua_State *L) { @@ -968,6 +985,29 @@ int tolua_process_produce(lua_State* L) { return 0; } +static void +parse_inifile(lua_State* L, dictionary * d, const char * section) +{ + int i; + size_t len = strlen(section); + for (i=0;i!=d->n;++i) { + const char * key = d->key[i]; + + if (strncmp(section, key, len)==0 && key[len]==':') { + const char * str_value = d->val[i]; + char * endp; + double num_value = strtod(str_value, &endp); + lua_pushstring(L, key + len + 1); + if (*endp) { + tolua_pushstring(L, str_value); + } else { + tolua_pushnumber(L, num_value); + } + lua_rawset(L,-3); + } + } +} + int tolua_eressea_open(lua_State* L) { @@ -1013,8 +1053,15 @@ tolua_eressea_open(lua_State* L) } tolua_endmodule(L); - tolua_function(L, TOLUA_CAST "get_region_by_id", tolua_get_region_byid); + tolua_module(L, TOLUA_CAST "config", 1); + tolua_beginmodule(L, TOLUA_CAST "config"); + { + parse_inifile(L, global.inifile, "config"); + tolua_variable(L, TOLUA_CAST "locales", &tolua_get_locales, 0); + } + tolua_endmodule(L); + tolua_function(L, TOLUA_CAST "get_region_by_id", tolua_get_region_byid); tolua_function(L, TOLUA_CAST "get_faction", tolua_get_faction); tolua_function(L, TOLUA_CAST "get_unit", tolua_get_unit); tolua_function(L, TOLUA_CAST "get_alliance", tolua_get_alliance); diff --git a/src/scripts/default.lua b/src/scripts/default.lua index 921a3bc7e..94dd9a222 100644 --- a/src/scripts/default.lua +++ b/src/scripts/default.lua @@ -1,3 +1,38 @@ +function change_locales(localechange) + for loc, flist in pairs(localechange) do + for index, name in pairs(flist) do + f = get_faction(atoi36(name)) + if f ~= nil then + f.locale = loc + print("LOCALECHANGE ", f, loc) + end + end + end +end + +function dbupdate() + update_scores() + edb = db.open(basepath.."/eressea.db") + if edb~=nil then + edb:update_factions() + edb:update_scores() + else + print("could no open "..basepath.."/eressea.db") + end +end + +function nmr_check(maxnmrs) + local nmrs = get_nmrs(1) + if nmrs >= maxnmrs then + print("Shit. More than " .. maxnmrs .. " factions with 1 NMR (" .. nmrs .. ")") + write_summary() + write_game("aborted.dat") + return -1 + end + print (nmrs .. " Factions with 1 NMR") + return 0 +end + function open_game(turn) file = "" .. get_turn() if read_game(file .. ".dat", "binary")~=0 then diff --git a/src/scripts/e3a/config-test.lua b/src/scripts/e3a/config-test.lua deleted file mode 100644 index 67bb64082..000000000 --- a/src/scripts/e3a/config-test.lua +++ /dev/null @@ -1 +0,0 @@ -maxnmrs = 500 diff --git a/src/scripts/e3a/main.lua b/src/scripts/e3a/main.lua new file mode 100644 index 000000000..494e2643b --- /dev/null +++ b/src/scripts/e3a/main.lua @@ -0,0 +1,63 @@ +require "multis" + +function process(orders) + local confirmed_multis = { "odin" } + local suspected_multis = { } + + if open_game(get_turn())~=0 then + print("could not read game") + return -1 + end + init_summary() + + -- kill multi-players (external script) + kill_multis(confirmed_multis, false) + mark_multis(suspected_multis, false) + + -- run the turn: + if read_orders(orders) ~= 0 then + print("could not read " .. orders) + return -1 + end + + -- plan_monsters() + local mon = get_faction(666) + if mon ~= nil then + mon.lastturn = get_turn() + end + + if nmr_check(maxnmrs or 30)~=0 then + return -1 + end + + process_orders() + if xmas2009~=nil then + xmas2009() + end + + -- create new monsters: + spawn_dragons() + spawn_undead() + -- spawn_braineaters(0.25) + -- spawn_ents() + + kill_nonstarters() + -- post-turn updates: + update_guards() + update_scores() + + local localechange = { de = { "ii" } } + change_locales(localechange) + + -- use newfactions file to place out new players + -- autoseed(basepath .. "/newfactions", false) + + write_files(config.locales) + + file = "" .. get_turn() .. ".dat" + if write_game(file, "binary")~=0 then + print("could not write game") + return -1 + end + return 0 +end diff --git a/src/scripts/e3a/modules.lua b/src/scripts/e3a/modules.lua new file mode 100644 index 000000000..b21735765 --- /dev/null +++ b/src/scripts/e3a/modules.lua @@ -0,0 +1,2 @@ +require "e3a.xmas2009" +require "e3a.rules" diff --git a/src/scripts/e3a/multi.lua b/src/scripts/e3a/multi.lua deleted file mode 100644 index 6f2da87cc..000000000 --- a/src/scripts/e3a/multi.lua +++ /dev/null @@ -1,21 +0,0 @@ -function mark_multi(f) - f.password = "doppelspieler" - f.email = "doppelspieler@eressea.de" - f.banner = "Diese Partei steht wegen vermuteten Doppelspiels unter Beobachtung." - for u in f.units do - u.race_name = "toad" - if u.building~=nil then - local found = False - for u2 in u.region.units do - if u2.faction.id~=u.faction.id then - found = true - break - end - end - if not found then - u.region.terrain_name = "firewall" - u.region:set_flag(2) -- RF_BLOCKED - end - end - end -end diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index 0a5b14073..6bfddabf0 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -1,51 +1,3 @@ --- the locales that this gameworld supports. -local locales = { "de", "en" } - -function loadscript(name) - local script = scriptpath .. "/" .. name - print("- loading " .. script) - if pcall(dofile, script)==0 then - print("Could not load " .. script) - end -end - -function change_locales() - -- local localechange = { } - local localechange = { de = { "rtph" } } - - for loc, flist in pairs(localechange) do - for index, name in pairs(flist) do - f = get_faction(atoi36(name)) - if f ~= nil then - f.locale = loc - print("LOCALECHANGE ", f, loc) - end - end - end -end - -function load_scripts() - scripts = { - "spells.lua", - "extensions.lua", - "familiars.lua", - "eressea/eternath.lua", - "eressea/wedding-jadee.lua", - "eressea/ponnuki.lua", - "eressea/items.lua", - "eressea/10years.lua", - "eressea/xmas2004.lua", - "eressea/xmas2005.lua", - "eressea/xmas2006.lua", - "eressea/embassy.lua", - "eressea/tunnels.lua", - "eressea/ents.lua" - } - for index, value in pairs(scripts) do - loadscript(value) - end -end - function process(orders) -- initialize starting equipment for new players if open_game==nil then @@ -59,9 +11,6 @@ function process(orders) end init_summary() - -- kill multi-players (external script) - -- loadscript("eressea/multis.lua") - -- run the turn: if read_orders(orders) ~= 0 then print("could not read " .. orders) @@ -107,16 +56,3 @@ function process(orders) return -1 end end - --- --- main body of script --- - --- orderfile: contains the name of the orders. -load_scripts() -if orderfile==nil then - print "you must specify an orderfile" -else - process(orderfile) -end - diff --git a/src/scripts/eressea/eternath.lua b/src/scripts/eressea/eternath.lua index 1220e82a8..c421d3cce 100644 --- a/src/scripts/eressea/eternath.lua +++ b/src/scripts/eressea/eternath.lua @@ -1,6 +1,4 @@ -if gate_travel==nil then - loadscript("gates.lua") -end +require "gates" local function eternath_exchange(b1, b2, size) local units1 = gate_units(b1, size) diff --git a/src/scripts/eressea/main.lua b/src/scripts/eressea/main.lua new file mode 100644 index 000000000..5a2fc0677 --- /dev/null +++ b/src/scripts/eressea/main.lua @@ -0,0 +1,54 @@ +require "multis" + +function process(orders) + local confirmed_multis = { } + local suspected_multis = { } + + if open_game(get_turn())~=0 then + print("could not read game") + return -1 + end + init_summary() + + -- kill multi-players (external script) + kill_multis(confirmed_multis, false) + mark_multis(suspected_multis, false) + + -- run the turn: + if read_orders(orders) ~= 0 then + print("could not read " .. orders) + return -1 + end + + plan_monsters() + + if nmr_check(maxnmrs or 80)~=0 then + return -1 + end + + process_orders() + + -- create new monsters: + spawn_dragons() + spawn_undead() + spawn_braineaters(0.25) + spawn_ents() + + -- post-turn updates: + update_xmas2006() + update_embassies() + update_guards() + update_scores() + + local localechange = { de = { "ii" } } + change_locales(localechange) + + write_files(config.locales) + + file = "" .. get_turn() .. ".dat" + if write_game(file, "binary")~=0 then + print("could not write game") + return -1 + end + return 0 +end diff --git a/src/scripts/eressea/modules.lua b/src/scripts/eressea/modules.lua new file mode 100644 index 000000000..35788a6b8 --- /dev/null +++ b/src/scripts/eressea/modules.lua @@ -0,0 +1,12 @@ +require "gates" +require "eressea.eternath" +require "eressea.wedding-jadee" +require "eressea.ponnuki" +require "eressea.items" +-- require "eressea.10years" +require "eressea.xmas2004" +require "eressea.xmas2005" +require "eressea.xmas2006" +require "eressea.embassy" +require "eressea.tunnels" +require "eressea.ents" diff --git a/src/scripts/eressea/multis.lua b/src/scripts/eressea/multis.lua deleted file mode 100644 index 4838170c6..000000000 --- a/src/scripts/eressea/multis.lua +++ /dev/null @@ -1,82 +0,0 @@ -local function email_multis() - local multis = { - ["u9bx"]="Tachlaar@web.de", - ["7Lwz"]="Tachlaar@web.de", - ["ddr"]="Tachlaar@web.de", - ["myrd"]="Tachlaar@web.de", - ["2a4v"]="Samurai_krieger@web.de", - ["7oiw"]="Samurai_krieger@web.de", - ["brud"]="Samurai_krieger@web.de", - ["bzcm"]="Samurai_krieger@web.de", - ["crow"]="Samurai_krieger@web.de", - ["dino"]="Samurai_krieger@web.de", - ["fynd"]="Samurai_krieger@web.de", - ["Leer"]="Samurai_krieger@web.de", - ["moos"]="Samurai_krieger@web.de", - ["ogcL"]="Samurai_krieger@web.de", - ["paty"]="Samurai_krieger@web.de", - ["rd"]="Samurai_krieger@web.de", - ["seee"]="Samurai_krieger@web.de", - ["szem"]="Samurai_krieger@web.de", - ["uebL"]="Samurai_krieger@web.de", - ["uvzp"]="Samurai_krieger@web.de", - ["wzLp"]="Samurai_krieger@web.de", - ["ziwe"]="Samurai_krieger@web.de" - } - local k - local v - for k, info in pairs(multis) do - local f = get_faction(atoi36(k)) - if f~=nil then - print("- marking " .. tostring(f) .. " as a multi-player.") - f.email = v - f.password = "" - f.info = info - else - print("- could not find faction " .. k) - end - end -end - -local function kill_multis() - local multis = { - ["u9bx"]="Doppelspiel-Partei von Tachlaar@web.de", - ["7Lwz"]="Doppelspiel-Partei von Tachlaar@web.de", - ["ddr"]="Doppelspiel-Partei von Tachlaar@web.de", - ["myrd"]="Doppelspiel-Partei von Tachlaar@web.de", - ["2a4v"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["7oiw"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["brud"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["bzcm"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["crow"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["dino"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["fynd"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["Leer"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["moos"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["ogcL"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["paty"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["rd"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["seee"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["szem"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["uebL"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["uvzp"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["wzLp"]="Doppelspiel-Partei von Samurai_krieger@web.de", - ["ziwe"]="Doppelspiel-Partei von Samurai_krieger@web.de" - } - local k - local v - for k, info in pairs(multis) do - local f = get_faction(atoi36(k)) - if f~=nil then - print("- marking " .. tostring(f) .. " as a multi-player.") - f.email = "doppelspieler@eressea.de" - f.password = "" - f.info = info - else - print("- could not find faction " .. k) - end - end -end - -print("killing multi-players") -email_multis() diff --git a/src/scripts/familiars.lua b/src/scripts/familiars.lua deleted file mode 100644 index 5b99da3a8..000000000 --- a/src/scripts/familiars.lua +++ /dev/null @@ -1,3 +0,0 @@ -function initfamiliar_lynx(u) - print("a lynx is born ;-)") -end diff --git a/src/scripts/init-e3a.lua b/src/scripts/init.lua similarity index 70% rename from src/scripts/init-e3a.lua rename to src/scripts/init.lua index 08963035e..9bd1e5d86 100644 --- a/src/scripts/init-e3a.lua +++ b/src/scripts/init.lua @@ -1,6 +1,4 @@ -require "e3a.xmas2009" -require "e3a.rules" -require "e3a.multi" +require(config.game .. ".modules") require "default" require "spells" require "extensions" @@ -28,16 +26,8 @@ function run_tests() end function run_turn() - require "run-e3a" + require(config.game .. ".main") - -- the locales that this gameworld supports. - local locales = { "de", "en" } - local confirmed_multis = { - } - local suspected_multis = { - "odin" - } - local turn = get_turn() if turn==0 then turn = read_turn() @@ -46,7 +36,7 @@ function run_turn() orderfile = orderfile or basepath .. '/orders.' .. turn print("executing turn " .. get_turn() .. " with " .. orderfile) - local result = process(orderfile, confirmed_multis, suspected_multis, locales) + local result = process(orderfile) if result==0 then dbupdate() end diff --git a/src/scripts/multis.lua b/src/scripts/multis.lua new file mode 100644 index 000000000..ad0b77783 --- /dev/null +++ b/src/scripts/multis.lua @@ -0,0 +1,101 @@ +function kill_nonstarters() + for f in factions() do + if f.lastturn==1 then + kill_faction(f, true) + end + end +end + +function kill_multis(multis, destructive) + for idx, fno in ipairs(multis) do + local f = get_faction(fno) + if f~=nil and f.email=="doppelspieler@eressea.de" then + kill_faction(f, destructive) + end + end +end + +function mark_multis(multis, block) + if multis~=nil then + for idx, fno in ipairs(multis) do + local f = get_faction(fno) + if f~=nil and f.email~="doppelspieler@eressea.de" then + print("* multi-player " .. tostring(f)) + mark_multi(f, block) + end + end + end +end + +-- destroy a faction +-- destructive: kill all of its buildings and the home region, too. + +function kill_faction(f, destructive) + for u in f.units do + local r = u.region + local b = u.building + unit.destroy(u) + if destructive and b~=nil then + building.destroy(b) + local nuke = true + for v in r.units do + if v.faction.id~=f.id then + -- print("cannot nuke: " .. tostring(v.faction)) + nuke = false + break + end + end + r.terrain_name = nil + if nuke and num_oceans(r)<=1 then + -- print("nuke!") + r.terrain = "ocean" + else + -- print("cannot nuke: > 1 oceans") + r.terrain = "glacier" + r.peasants = 10 + r:set_resource("money", 100) + b = building.create(r, "monument") + b.size = 1 + b.name = "Memento Mori" + b.info = "Eine kleine " .. translate("race::" .. f.race .."_x") .. "-Statue erinnert hier an ein verschwundenes Volk" + end + end + end + faction.destroy(f) +end + +local function mark_multi(f, block) + f.password = "doppelspieler" + f.email = "doppelspieler@eressea.de" + f.banner = "Diese Partei steht wegen vermuteten Doppelspiels unter Beobachtung." + for u in f.units do + u.race_name = "toad" + if block and u.building~=nil then + local found = false + for u2 in u.region.units do + if u2.faction.id~=u.faction.id then + found = true + break + end + end + if not found then + u.region.terrain_name = "firewall" + u.region:set_flag(2) -- RF_BLOCKED + end + end + end +end + +local function num_oceans(r) + local oceans = 0 + local p = r:next(5) + for d = 0,5 do + local n = r:next(d) + if p.terrain~="ocean" and n.terrain=="ocean" then + oceans = oceans +1 + end + p = n + end + return oceans +end + diff --git a/src/scripts/run-e3a.lua b/src/scripts/run-e3a.lua deleted file mode 100644 index 4879817d8..000000000 --- a/src/scripts/run-e3a.lua +++ /dev/null @@ -1,208 +0,0 @@ -function num_oceans(r) - local oceans = 0 - local p = r:next(5) - for d = 0,5 do - local n = r:next(d) - if p.terrain~="ocean" and n.terrain=="ocean" then - oceans = oceans +1 - end - p = n - end - return oceans -end - --- destroy a faction and all of its buildings. --- destroy the home region, too -function kill_faction(f) - for u in f.units do - local r = u.region - local b = u.building - unit.destroy(u) - if b~=nil then - building.destroy(b) - local nuke = true - for v in r.units do - if v.faction.id~=f.id then - -- print("cannot nuke: " .. tostring(v.faction)) - nuke = false - break - end - end - r.terrain_name = nil - if nuke and num_oceans(r)<=1 then - -- print("nuke!") - r.terrain = "ocean" - else - -- print("cannot nuke: > 1 oceans") - r.terrain = "glacier" - r.peasants = 10 - r:set_resource("money", 100) - b = building.create(r, "monument") - b.size = 1 - b.name = "Memento Mori" - b.info = "Eine kleine " .. translate("race::" .. f.race .."_x") .. "-Statue erinnert hier an ein verschwundenes Volk" - end - end - end - faction.destroy(f) -end - -function kill_nonstarters() - for f in factions() do - if f.lastturn==1 then - kill_faction(f) - end - end -end - -function kill_multis(multis) - for idx, fno in ipairs(multis) do - local f = get_faction(fno) - if f~=nil and f.email=="doppelspieler@eressea.de" then - kill_faction(f) - end - end -end - -function mark_multis(multis) - if multis~=nil then - for idx, fno in ipairs(multis) do - local f = get_faction(fno) - if f~=nil and f.email~="doppelspieler@eressea.de" then - print("* multi-player " .. tostring(f)) - mark_multi(f) - end - end - end -end - -function loadscript(name) - local script = scriptpath .. "/" .. name - print("- loading " .. script) - if pcall(dofile, script)==0 then - print("Could not load " .. script) - end -end - -function change_locales() - -- local localechange = { } - local localechange = { de = { "rtph" } } - - for loc, flist in pairs(localechange) do - for index, name in pairs(flist) do - f = get_faction(atoi36(name)) - if f ~= nil then - f.locale = loc - print("LOCALECHANGE ", f, loc) - end - end - end -end - -function best_scores(n) - local f, numf, top - - numf = 0 - top = { } - for f in factions() do - numf = numf + 1 - local r = 0 - local score = f.score - for i = 1,n do - if top[i]==nil then - top[i] = f - break - end - if top[i].score= maxnmrs then - print("Shit. More than " .. maxnmrs .. " factions with 1 NMR (" .. nmrs .. ")") - write_summary() - write_game("aborted.dat") - return -1 - end - print (nmrs .. " Factions with 1 NMR") - - process_orders() - if xmas2009~=nil then - xmas2009() - end - - -- create new monsters: - spawn_dragons() - spawn_undead() - -- spawn_braineaters(0.25) - -- spawn_ents() - - kill_nonstarters() - -- post-turn updates: - update_guards() - update_scores() - - change_locales() - - -- use newfactions file to place out new players - -- autoseed(basepath .. "/newfactions", false) - - write_files(locales) - write_statistics() - - file = "" .. get_turn() .. ".dat" - if write_game(file, "binary")~=0 then - print("could not write game") - return -1 - end - return 0 -end - --- --- main body of script --- -function dbupdate() - update_scores() - edb = db.open(basepath.."/eressea.db") - edb:update_factions() - edb:update_scores() -end diff --git a/src/scripts/run-tests.lua b/src/scripts/run-tests.lua deleted file mode 100644 index e9bad42a9..000000000 --- a/src/scripts/run-tests.lua +++ /dev/null @@ -1,233 +0,0 @@ --- -*- coding: utf-8 -*- - -function test_locales() - local skills = { "", "herb", "kraut", "Kräute", "Kraeut", "k", "kra", "MAGIE" } - for k,v in pairs(skills) do - str = test.loc_skill("de", v) - io.stdout:write(v, "\t", tostring(str), " ", tostring(get_string("de", "skill::" .. tostring(str))), "\n") - end - return 0 -end - -function loadscript(name) - local script = scriptpath .. "/" .. name - print("- loading " .. script) - if pcall(dofile, script)==0 then - print("Could not load " .. script) - end -end - -function run_scripts() - scripts = { - "spells.lua", - "extensions.lua", - "familiars.lua", - } - for index, value in pairs(scripts) do - loadscript(value) - end -end ---test_locales() - -function run_turn() - plan_monsters() - process_orders() - spawn_dragons() - spawn_undead() - spawn_braineaters(0.25) - autoseed(basepath .. "/newfactions", false) -end - - -function test_free() - read_game("571.dat", "binary") - read_orders("orders.571") - run_turn() - free_game() - read_game("570.dat", "binary") - read_orders("orders.570") - run_turn() - free_game() -end - -function test_reorder() - r = region.create(0, 0, "plain") - f = faction.create("enno@ix.de", "orc", "de") - s1 = add_ship(r, "boat") - s1.size = 1 - s2 = add_ship(r, "boat") - s2.size = 2 - s3 = add_ship(r, "boat") - s3.size = 3 - b1 = add_building(r, "portal") - b1.size = 1 - b2 = add_building(r, "portal") - b2.size = 2 - b3 = add_building(r, "portal") - b3.size = 3 - u = unit.create(f, r) - u.number = 1 - u.name = "a" - u = unit.create(f, r) - u.number = 1 - u.name = "b" - u.ship = s3 - u = unit.create(f, r) - u.number = 1 - u.name = "c" - u.building = b1 - u = unit.create(f, r) - u.number = 1 - u.name = "d" - u.ship = s2 - u = unit.create(f, r) - u.name = "e" - u.number = 1 - u.building = b1 - u = unit.create(f, r) - u.name = "f" - u.number = 1 - u.building = b3 - u = unit.create(f, r) - u.name = "g" - u.number = 1 - u.ship = s2 - u = unit.create(f, r) - u.name = "h" - u.number = 1 - u.building = b2 - u = unit.create(f, r) - u.name = "i" - u.number = 1 - u = unit.create(f, r) - u.name = "j" - u.number = 1 - u.building = b1 - u = unit.create(f, r) - u.name = "k" - u.number = 1 - u.ship = s1 - test.reorder_units(r) - for u in r.units do - print(u, u.building, u.ship) - end - io.stdin:read("*line") -end - -function test_hse() - read_game("50.dat", "binary") - f = get_faction(atoi36("8h7f")) - f.options = f.options + 8192 - init_reports() - write_report(f) -end - -function test_xml() - read_game("572.dat", "binary") - init_reports() - - f = get_faction(atoi36("ioen")) - f.options = f.options + 8192 - write_report(f) - - f = get_faction(atoi36("a")) - f.options = f.options + 8192 - write_report(f) - - f = get_faction(atoi36("777")) - f.options = f.options + 8192 - write_report(f) -end - -function test_realloc() - local t1 = os.clock() - read_game("571.4.dat", "binary") - print(os.clock() - t1) - free_game() - print(os.clock() - t1) - -- and again - local t2 = os.clock() - read_game("571.4.dat", "binary") - print(os.clock() - t2) - free_game() - print(os.clock() - t2) -end - -function test_bmark() - local t1 = os.clock() - read_game("566.dat", "binary") - print(os.clock() - t1) -end - -function test_md5() - read_game("571.dat", "binary") - -- read_orders("orders.571") - run_turn() - local i = test.rng_int() - print(i) - write_game("572.txt." .. i, "text") - -- 648583167 - io.stdin:read("*line") -end - -function test_287() - read_game("287", "text") - write_game("287.dat", "binary") -end - -function tunnel_action(b, param) - local r = nil - print("Tunnel from " .. tostring(b) .. " [" .. param .. "]") - - if tonumber(param)~=nil then - r = get_region_by_id(tonumber(param)) - end - if r~=nil then - local units = tunnel_travelers(b) - for key, u in pairs(units) do - local rto = r - if r==nil then - rto = get_target(param) - end - if rto~=nil then - u.region = rto - print(" - teleported " .. tostring(u) .. " to " .. tostring(rto)) - end - end - end - return 1 -- return 0 to destroy -end - -function action(b, param) - print(b) - print(param) - return 1 -end - -function test_tunnels() - r = region.create(0, 0, "glacier") - b = add_building(r, "portal") - b:add_action("tunnel_action", "tnnL") - r2 = region.create(5, 5, "plain") - r2:set_key("tnnL", true) - process_orders() -end - -loadscript("default.lua") -run_scripts() --- go --- test_free() --- test_bmark() --- test_realloc() -test_xml() --- test_hse() --- test_reorder() --- test_tunnels() --- test_md5() --- test_287() --- io.stdin:read("*line") --- text: 50.574 --- bin0: 19.547 --- bin1: 18.953 --- bin1: 18.313 --- bin2: 17.938 diff --git a/src/scripts/setup.lua b/src/scripts/setup.lua new file mode 100644 index 000000000..1681d36ce --- /dev/null +++ b/src/scripts/setup.lua @@ -0,0 +1,16 @@ +local srcpath = config.source_dir +local paths = { 'lunit/?.lua','external/lunit/?.lua','scripts/?.lua';'scripts/?' } + +tests = {'common', config.game} +for idx, test in pairs(tests) do + tests[idx] = srcpath .. '/scripts/tests/' .. test .. '.lua' +end + +for idx, path in pairs(paths) do + package.path = srcpath .. '/' .. path .. ';' .. package.path +end + +read_xml(srcpath .. '/res/' .. config.game .. '.xml') + +require "config-test" +require "init" diff --git a/src/scripts/tests/common.lua b/src/scripts/tests/common.lua index 4228aa0b1..3c4679ba7 100644 --- a/src/scripts/tests/common.lua +++ b/src/scripts/tests/common.lua @@ -92,14 +92,14 @@ function test_blessedharvest_lasts_n_turn() local m = 0 local p = 100 - for i=1,level+1 do + for i=1,level+2 do process_orders() local income = p * 12 p = r:get_resource("peasant") income = income - p * 10 m = m + income - -- print(i, m, p, r:get_resource("money")) - if (i>level) then + print(i, m, p, r:get_resource("money")) + if (i>level+1) then assert_not_equal(m, r:get_resource("money")) else assert_equal(m, r:get_resource("money"))