New script layout.

This commit is contained in:
Enno Rehling 2010-01-03 08:02:58 +00:00
parent 8a951e5817
commit 361fdc5186
25 changed files with 356 additions and 665 deletions

View File

@ -379,6 +379,7 @@ typedef struct settings {
void * vm_state; void * vm_state;
float producexpchance; float producexpchance;
int cookie; int cookie;
struct _dictionary_ * inifile;
struct global_functions { struct global_functions {
int (*wage)(const struct region *r, const struct faction * f, const struct race * rc, int in_turn); int (*wage)(const struct region *r, const struct faction * f, const struct race * rc, int in_turn);

View File

@ -338,6 +338,7 @@ extern struct attrib_type at_showitem; /* show this potion's description */
extern void register_resources(void); extern void register_resources(void);
extern void init_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_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); extern void register_item_use(int (*foo) (struct unit *, const struct item_type *, int, struct order *), const char * name);

View File

@ -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); report_item(owner, itm, viewer, NULL, &ic, NULL, false);
if (ic && *ic) { if (ic && *ic) {
for (ishow = result; ishow!=result+n; ishow=ishow->next) { for (ishow = result; ishow!=result+n; ++ishow) {
const char * sc; const char * sc;
if (ishow->type==itm->type) sc = ic; 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 (ishow==result+n) {
if (n==size) { if (n==size) {
log_error(("too many items to report, increase buffer size.\n"));
return -1; return -1;
} }
result[n].number = itm->number; result[n].number = itm->number;

View File

@ -135,7 +135,7 @@ extern int report_action(struct region * r, struct unit * actor, struct message
extern const char * combatstatus[]; extern const char * combatstatus[];
#define GR_PLURAL 0x01 /* grammar: plural */ #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 */ #define MAX_RAWMATERIALS 8 /* maximum kinds of raw materials in a regions */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1170,6 +1170,7 @@ parse_resources(xmlDocPtr doc)
/* make sure old items (used in requirements) are available */ /* make sure old items (used in requirements) are available */
init_resources(); init_resources();
init_itemtypes();
return 0; return 0;
} }

View File

@ -277,27 +277,6 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\scripts\init-e3a.lua"
>
</File>
<File
RelativePath=".\external\lunit\lunit.lua"
>
</File>
<File
RelativePath=".\scripts\run-e3a.lua"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="luac -o $(IntDir)/$(InputName).luac $(InputPath)&#x0D;&#x0A;"
Outputs="$(IntDir)/$(InputName).luac"
/>
</FileConfiguration>
</File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>

View File

@ -247,7 +247,6 @@ game_init(void)
init_archetypes(); init_archetypes();
init_attributes(); init_attributes();
init_itemtypes();
init_gmcmd(); init_gmcmd();
#if INFOCMD_MODULE #if INFOCMD_MODULE
@ -550,15 +549,14 @@ my_lua_error(lua_State * L)
return 1; return 1;
} }
static dictionary * inifile;
static void static void
load_inifile(const char * filename) load_inifile(const char * filename)
{ {
dictionary * d = iniparser_new(filename); dictionary * d = iniparser_new(filename);
if (d) { if (d) {
const char * str; const char * str;
g_basedir = iniparser_getstring(d, "eressea:base", g_basedir); 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; lomem = iniparser_getint(d, "eressea:lomem", lomem)?1:0;
memdebug = iniparser_getint(d, "eressea:memcheck", memdebug); memdebug = iniparser_getint(d, "eressea:memcheck", memdebug);
@ -573,13 +571,16 @@ load_inifile(const char * filename)
luafile = iniparser_getstring(d, "eressea:load", luafile); luafile = iniparser_getstring(d, "eressea:load", luafile);
g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir); 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"); str = iniparser_getstring(d, "eressea:locales", "de,en");
make_locales(str); 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 static void
@ -639,7 +640,7 @@ main(int argc, char *argv[])
int i; int i;
char * lc_ctype; char * lc_ctype;
char * lc_numeric; char * lc_numeric;
lua_State * L = lua_init(); lua_State * L;
static int write_csv = 0; static int write_csv = 0;
setup_signal_handler(); setup_signal_handler();
@ -652,8 +653,9 @@ main(int argc, char *argv[])
if (lc_ctype) lc_ctype = strdup(lc_ctype); if (lc_ctype) lc_ctype = strdup(lc_ctype);
if (lc_numeric) lc_numeric = strdup(lc_numeric); if (lc_numeric) lc_numeric = strdup(lc_numeric);
global.vm_state = L;
load_inifile("eressea.ini"); load_inifile("eressea.ini");
L = lua_init();
global.vm_state = L;
if (verbosity>=4) { if (verbosity>=4) {
printf("\n%s PBEM host\n" printf("\n%s PBEM host\n"
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\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_ctype);
free(lc_numeric); free(lc_numeric);
if (inifile) iniparser_free(inifile); if (global.inifile) iniparser_free(global.inifile);
return 0; return 0;
} }

View File

@ -59,6 +59,7 @@ without prior permission by the authors of Eressea.
#include <util/rng.h> #include <util/rng.h>
#include <util/storage.h> #include <util/storage.h>
#include <iniparser/iniparser.h>
#include <tolua.h> #include <tolua.h>
#include <lua.h> #include <lua.h>
@ -896,6 +897,22 @@ tolua_write_spells(lua_State* L)
return 0; 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 static int
tolua_get_spell_text(lua_State *L) tolua_get_spell_text(lua_State *L)
{ {
@ -968,6 +985,29 @@ int tolua_process_produce(lua_State* L) {
return 0; 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 int
tolua_eressea_open(lua_State* L) tolua_eressea_open(lua_State* L)
{ {
@ -1013,8 +1053,15 @@ tolua_eressea_open(lua_State* L)
} }
tolua_endmodule(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_faction", tolua_get_faction);
tolua_function(L, TOLUA_CAST "get_unit", tolua_get_unit); tolua_function(L, TOLUA_CAST "get_unit", tolua_get_unit);
tolua_function(L, TOLUA_CAST "get_alliance", tolua_get_alliance); tolua_function(L, TOLUA_CAST "get_alliance", tolua_get_alliance);

View File

@ -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) function open_game(turn)
file = "" .. get_turn() file = "" .. get_turn()
if read_game(file .. ".dat", "binary")~=0 then if read_game(file .. ".dat", "binary")~=0 then

View File

@ -1 +0,0 @@
maxnmrs = 500

63
src/scripts/e3a/main.lua Normal file
View File

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

View File

@ -0,0 +1,2 @@
require "e3a.xmas2009"
require "e3a.rules"

View File

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

View File

@ -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) function process(orders)
-- initialize starting equipment for new players -- initialize starting equipment for new players
if open_game==nil then if open_game==nil then
@ -59,9 +11,6 @@ function process(orders)
end end
init_summary() init_summary()
-- kill multi-players (external script)
-- loadscript("eressea/multis.lua")
-- run the turn: -- run the turn:
if read_orders(orders) ~= 0 then if read_orders(orders) ~= 0 then
print("could not read " .. orders) print("could not read " .. orders)
@ -107,16 +56,3 @@ function process(orders)
return -1 return -1
end end
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

View File

@ -1,6 +1,4 @@
if gate_travel==nil then require "gates"
loadscript("gates.lua")
end
local function eternath_exchange(b1, b2, size) local function eternath_exchange(b1, b2, size)
local units1 = gate_units(b1, size) local units1 = gate_units(b1, size)

View File

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

View File

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

View File

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

View File

@ -1,3 +0,0 @@
function initfamiliar_lynx(u)
print("a lynx is born ;-)")
end

View File

@ -1,6 +1,4 @@
require "e3a.xmas2009" require(config.game .. ".modules")
require "e3a.rules"
require "e3a.multi"
require "default" require "default"
require "spells" require "spells"
require "extensions" require "extensions"
@ -28,16 +26,8 @@ function run_tests()
end end
function run_turn() 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() local turn = get_turn()
if turn==0 then if turn==0 then
turn = read_turn() turn = read_turn()
@ -46,7 +36,7 @@ function run_turn()
orderfile = orderfile or basepath .. '/orders.' .. turn orderfile = orderfile or basepath .. '/orders.' .. turn
print("executing turn " .. get_turn() .. " with " .. orderfile) print("executing turn " .. get_turn() .. " with " .. orderfile)
local result = process(orderfile, confirmed_multis, suspected_multis, locales) local result = process(orderfile)
if result==0 then if result==0 then
dbupdate() dbupdate()
end end

101
src/scripts/multis.lua Normal file
View File

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

View File

@ -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<score then
for j = n,i+1,-1 do
top[j]=top[j-1]
end
top[i] = f
break
end
end
end
return top
end
function write_statistics()
end
function process(orders, confirmed_multis, suspected_multis, locales)
-- initialize starting equipment for new players
print(orders)
if open_game(get_turn())~=0 then
print("could not read game")
return -1
end
init_summary()
-- kill multi-players (external script)
-- loadscript("eressea/multis.lua")
kill_multis(confirmed_multis)
mark_multis(suspected_multis)
-- 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
local nmrs = get_nmrs(1)
-- nmrs = 0
maxnmrs = maxnmrs or 30
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")
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

View File

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

16
src/scripts/setup.lua Normal file
View File

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

View File

@ -92,14 +92,14 @@ function test_blessedharvest_lasts_n_turn()
local m = 0 local m = 0
local p = 100 local p = 100
for i=1,level+1 do for i=1,level+2 do
process_orders() process_orders()
local income = p * 12 local income = p * 12
p = r:get_resource("peasant") p = r:get_resource("peasant")
income = income - p * 10 income = income - p * 10
m = m + income m = m + income
-- print(i, m, p, r:get_resource("money")) print(i, m, p, r:get_resource("money"))
if (i>level) then if (i>level+1) then
assert_not_equal(m, r:get_resource("money")) assert_not_equal(m, r:get_resource("money"))
else else
assert_equal(m, r:get_resource("money")) assert_equal(m, r:get_resource("money"))