server/src/scripts/eressea.lua

114 lines
2.3 KiB
Lua
Raw Normal View History

2005-03-23 19:55:47 +01:00
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()
2005-09-09 00:25:56 +02:00
-- local localechange = { }
2005-10-09 21:52:21 +02:00
local localechange = { de = { "2xwr" } }
for loc, flist in localechange do
for index, name in flist do
f = get_faction(atoi36(name))
if f ~= nil then
f.locale = loc
print("LOCALECHANGE ", f, loc)
end
end
end
end
function run_scripts()
scripts = {
"spells.lua",
"extensions.lua",
"eternath.lua",
2005-03-23 19:55:47 +01:00
"wedding-jadee.lua",
"ponnuki.lua"
}
for index in scripts do
2005-03-23 19:55:47 +01:00
loadscript(scripts[index])
end
end
function write_emails()
local locales = { "de", "en" }
local files = {}
local key
for key in locales do
local locale = locales[key]
files[locale] = io.open(basepath .. "/emails." .. locale, "w")
end
local faction
for faction in factions() do
-- print(faction.id .. " - " .. faction.locale)
files[faction.locale]:write(faction.email .. "\n")
end
for key in files do
files[key]:close()
end
end
function process(orders)
-- initialize starting equipment for new players
equipment_setitem("new_faction", "conquesttoken", "1");
equipment_setitem("new_faction", "log", "30");
equipment_setitem("new_faction", "stone", "30");
equipment_setitem("new_faction", "money", "4200");
file = "" .. get_turn()
if read_game(file)~=0 then
print("could not read game")
return -1
end
init_summary()
2005-07-23 22:38:14 +02:00
-- kill multi-players (external script)
loadscript("eressea-multis.lua")
2005-07-23 22:38:14 +02:00
-- run the turn:
2005-04-24 23:54:57 +02:00
if read_orders(orders) ~= 0 then
print("could not read " .. orders)
return -1
end
run_scripts()
spawn_braineaters(0.25)
plan_monsters()
process_orders()
change_locales()
-- use newfactions file to place out new players
autoseed(basepath .. "/newfactions", false)
2005-03-13 11:05:51 +01:00
write_passwords()
write_reports()
write_emails()
write_summary()
file = "" .. get_turn()
if write_game(file)~=0 then
print("could not write game")
return -1
end
end
--
-- main body of script
--
-- orderfile: contains the name of the orders.
if orderfile==nil then
print "you must specify an orderfile"
else
process(orderfile)
end