2021-02-28 17:15:33 +01:00
|
|
|
print("package.path", package.path)
|
2021-02-22 01:53:01 +01:00
|
|
|
require 'eressea.path'
|
|
|
|
|
2014-07-26 22:52:25 +02:00
|
|
|
function nmr_check(maxnmrs)
|
|
|
|
local nmrs = get_nmrs(1)
|
2017-07-16 11:24:16 +02:00
|
|
|
if nmrs > maxnmrs then
|
2014-07-26 22:52:25 +02:00
|
|
|
eressea.log.error("Shit. More than " .. maxnmrs .. " factions with 1 NMR (" .. nmrs .. ")")
|
|
|
|
write_summary()
|
|
|
|
return -1
|
|
|
|
end
|
|
|
|
print (nmrs .. " Factions with 1 NMR")
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function open_game(turn)
|
|
|
|
file = "" .. get_turn()
|
|
|
|
return eressea.read_game(file .. ".dat")
|
|
|
|
end
|
|
|
|
|
|
|
|
function callbacks(rules, name, ...)
|
|
|
|
for k, v in pairs(rules) do
|
|
|
|
if 'table' == type(v) then
|
|
|
|
cb = v[name]
|
|
|
|
if 'function' == type(cb) then
|
|
|
|
cb(...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function write_emails(locales)
|
|
|
|
local files = {}
|
|
|
|
local key
|
|
|
|
local locale
|
|
|
|
local file
|
|
|
|
for key, locale in pairs(locales) do
|
|
|
|
files[locale] = io.open(config.basepath .. "/emails." .. locale, "w")
|
|
|
|
end
|
|
|
|
|
|
|
|
local faction
|
|
|
|
for faction in factions() do
|
|
|
|
if faction.email~="" then
|
|
|
|
files[faction.locale]:write(faction.email .. "\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for key, file in pairs(files) do
|
|
|
|
file:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-10 14:12:38 +01:00
|
|
|
local function join_path(a, b)
|
|
|
|
if a then return a .. '/' .. b end
|
|
|
|
return b
|
|
|
|
end
|
|
|
|
|
2014-07-26 22:52:25 +02:00
|
|
|
local function write_addresses()
|
|
|
|
local file
|
|
|
|
local faction
|
|
|
|
|
2016-02-10 14:12:38 +01:00
|
|
|
file = io.open(join_path(config.basepath, "adressen"), "w")
|
2014-07-26 22:52:25 +02:00
|
|
|
for faction in factions() do
|
|
|
|
-- print(faction.id .. " - " .. faction.locale)
|
|
|
|
file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.info .. "\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
file:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function write_aliases()
|
|
|
|
local file
|
|
|
|
local faction
|
|
|
|
|
2016-02-10 14:12:38 +01:00
|
|
|
file = io.open(join_path(config.basepath, "aliases"), "w")
|
2014-07-26 22:52:25 +02:00
|
|
|
for faction in factions() do
|
|
|
|
local unit
|
|
|
|
if faction.email ~= "" then
|
|
|
|
file:write("partei-" .. itoa36(faction.id) .. ": " .. faction.email .. "\n")
|
|
|
|
for unit in faction.units do
|
|
|
|
file:write("einheit-" .. itoa36(unit.id) .. ": " .. faction.email .. "\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
file:close()
|
|
|
|
end
|
|
|
|
|
2016-02-10 14:12:38 +01:00
|
|
|
local function write_htpasswd()
|
|
|
|
local out = io.open(join_path(config.basepath, "htpasswd"), "w")
|
|
|
|
if out then
|
|
|
|
for f in factions() do
|
|
|
|
if f.password then
|
|
|
|
out:write(itoa36(f.id) .. ":" .. f.password .. "\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
out:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-26 22:52:25 +02:00
|
|
|
local function write_files(locales)
|
2019-07-30 15:26:15 +02:00
|
|
|
write_reports()
|
|
|
|
write_summary()
|
2018-09-25 19:15:03 +02:00
|
|
|
write_database()
|
2016-02-10 14:12:38 +01:00
|
|
|
write_passwords()
|
2018-09-26 20:21:56 +02:00
|
|
|
write_htpasswd()
|
2014-07-26 22:52:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function write_scores()
|
|
|
|
local scores = {}
|
|
|
|
for r in regions() do
|
|
|
|
f = r.owner
|
|
|
|
if f~=nil then
|
|
|
|
value = scores[f.id]
|
|
|
|
if value==nil then value=0 end
|
|
|
|
value = value + r:get_resource("money")/100
|
|
|
|
scores[f.id] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for f in factions() do
|
|
|
|
score=scores[f.id]
|
|
|
|
if score==nil then score=0 end
|
|
|
|
print(math.floor(score)..":"..f.name..":"..itoa36(f.id))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function process(rules, orders)
|
2015-04-04 08:55:58 +02:00
|
|
|
local confirmed_multis = { }
|
|
|
|
local suspected_multis = { }
|
2014-07-26 22:52:25 +02:00
|
|
|
|
2015-04-04 08:55:58 +02:00
|
|
|
if open_game(get_turn())~=0 then
|
|
|
|
eressea.log.error("could not read game")
|
|
|
|
return -1
|
|
|
|
end
|
2014-07-26 22:52:25 +02:00
|
|
|
|
2017-06-11 17:06:13 +02:00
|
|
|
turn_begin()
|
2020-01-07 19:24:10 +01:00
|
|
|
-- create orders for monsters:
|
|
|
|
plan_monsters()
|
|
|
|
-- read orders for players:
|
2017-02-12 06:24:25 +01:00
|
|
|
if eressea.read_orders(orders) ~= 0 then
|
2015-04-04 08:55:58 +02:00
|
|
|
print("could not read " .. orders)
|
|
|
|
return -1
|
|
|
|
end
|
2014-07-26 22:52:25 +02:00
|
|
|
|
2015-04-04 08:55:58 +02:00
|
|
|
if nmr_check(config.maxnmrs or 80)~=0 then
|
|
|
|
return -1
|
|
|
|
end
|
2017-06-18 12:23:19 +02:00
|
|
|
callbacks(rules, 'init')
|
2020-01-07 19:24:10 +01:00
|
|
|
|
|
|
|
-- run the turn:
|
2017-06-11 17:06:13 +02:00
|
|
|
turn_process()
|
2017-06-18 12:23:19 +02:00
|
|
|
callbacks(rules, 'update')
|
|
|
|
turn_end() -- ageing, etc.
|
2014-12-11 12:19:04 +01:00
|
|
|
|
2015-04-04 08:55:58 +02:00
|
|
|
write_files(config.locales)
|
2018-01-26 17:56:24 +01:00
|
|
|
update_scores()
|
2014-07-26 22:52:25 +02:00
|
|
|
|
2015-04-04 08:55:58 +02:00
|
|
|
file = '' .. get_turn() .. '.dat'
|
|
|
|
if eressea.write_game(file)~=0 then
|
|
|
|
eressea.log.error("could not write game")
|
|
|
|
return -1
|
|
|
|
end
|
|
|
|
return 0
|
2014-07-26 22:52:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function run_turn(rules)
|
2015-04-04 08:55:58 +02:00
|
|
|
local turn = get_turn()
|
|
|
|
if turn<0 then
|
|
|
|
turn = read_turn()
|
|
|
|
set_turn(turn)
|
|
|
|
end
|
2014-07-26 22:52:25 +02:00
|
|
|
|
2015-04-04 08:55:58 +02:00
|
|
|
orderfile = orderfile or config.basepath .. '/orders.' .. turn
|
|
|
|
eressea.log.debug("executing turn " .. get_turn() .. " with " .. orderfile .. " with rules=" .. config.rules)
|
|
|
|
local result = process(rules, orderfile)
|
|
|
|
return result
|
2014-07-26 22:52:25 +02:00
|
|
|
end
|
|
|
|
|
2014-12-11 12:19:04 +01:00
|
|
|
function file_exists(name)
|
|
|
|
local f=io.open(name,"r")
|
2015-04-04 08:55:58 +02:00
|
|
|
if not f then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
io.close(f)
|
|
|
|
return true
|
2014-12-11 12:19:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if file_exists('execute.lock') then
|
|
|
|
eressea.log.error("Lockfile exists, aborting.")
|
|
|
|
assert(false)
|
|
|
|
end
|
|
|
|
|
2018-05-15 06:58:07 +02:00
|
|
|
math.randomseed(rng.random())
|
|
|
|
|
2014-08-03 20:37:05 +02:00
|
|
|
require 'eressea'
|
2014-08-12 22:54:55 +02:00
|
|
|
require 'eressea.xmlconf' -- read xml data
|
|
|
|
|
2014-12-11 12:19:04 +01:00
|
|
|
local rules = {}
|
|
|
|
if config.rules then
|
|
|
|
rules = require('eressea.' .. config.rules)
|
|
|
|
eressea.log.info('loaded ' .. #rules .. ' modules for ' .. config.rules)
|
|
|
|
else
|
|
|
|
eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r')
|
|
|
|
end
|
2014-07-26 22:52:25 +02:00
|
|
|
run_turn(rules)
|