indentation

This commit is contained in:
Enno Rehling 2021-03-19 23:30:34 +01:00
parent 3548722a58
commit 842b37a5a2
1 changed files with 75 additions and 75 deletions

View File

@ -16,15 +16,15 @@ function open_game(turn)
return eressea.read_game(file .. ".dat") return eressea.read_game(file .. ".dat")
end end
function callbacks(rules, name, ...) local function callbacks(rules, name, ...)
for k, v in pairs(rules) do for k, v in pairs(rules) do
if 'table' == type(v) then if 'table' == type(v) then
cb = v[name] cb = v[name]
if 'function' == type(cb) then if 'function' == type(cb) then
cb(...) cb(...)
end end
end end
end end
end end
local function write_emails(locales) local function write_emails(locales)
@ -49,8 +49,8 @@ local function write_emails(locales)
end end
local function join_path(a, b) local function join_path(a, b)
if a then return a .. '/' .. b end if a then return a .. '/' .. b end
return b return b
end end
local function write_addresses() local function write_addresses()
@ -85,23 +85,23 @@ local function write_aliases()
end end
local function write_htpasswd() local function write_htpasswd()
local out = io.open(join_path(config.basepath, "htpasswd"), "w") local out = io.open(join_path(config.basepath, "htpasswd"), "w")
if out then if out then
for f in factions() do for f in factions() do
if f.password then if f.password then
out:write(itoa36(f.id) .. ":" .. f.password .. "\n") out:write(itoa36(f.id) .. ":" .. f.password .. "\n")
end end
end
out:close()
end end
out:close()
end
end end
local function write_files(locales) local function write_files(locales)
write_reports() write_reports()
write_summary() write_summary()
write_database() write_database()
write_passwords() write_passwords()
write_htpasswd() write_htpasswd()
end end
local function write_scores() local function write_scores()
@ -123,69 +123,69 @@ local function write_scores()
end end
function process(rules, orders) function process(rules, orders)
local confirmed_multis = { } local confirmed_multis = { }
local suspected_multis = { } local suspected_multis = { }
if open_game(get_turn())~=0 then if open_game(get_turn())~=0 then
eressea.log.error("could not read game") eressea.log.error("could not read game")
return -1 return -1
end end
turn_begin() turn_begin()
-- create orders for monsters: -- create orders for monsters:
plan_monsters() plan_monsters()
-- read orders for players: -- read orders for players:
if eressea.read_orders(orders) ~= 0 then if eressea.read_orders(orders) ~= 0 then
print("could not read " .. orders) print("could not read " .. orders)
return -1 return -1
end end
if nmr_check(config.maxnmrs or 80)~=0 then if nmr_check(config.maxnmrs or 80)~=0 then
return -1 return -1
end end
callbacks(rules, 'init') callbacks(rules, 'init')
-- run the turn: -- run the turn:
turn_process() turn_process()
callbacks(rules, 'update') callbacks(rules, 'update')
turn_end() -- ageing, etc. turn_end() -- ageing, etc.
write_files(config.locales) write_files(config.locales)
update_scores() update_scores()
file = '' .. get_turn() .. '.dat' file = '' .. get_turn() .. '.dat'
if eressea.write_game(file)~=0 then if eressea.write_game(file)~=0 then
eressea.log.error("could not write game") eressea.log.error("could not write game")
return -1 return -1
end end
return 0 return 0
end end
function run_turn(rules) function run_turn(rules)
local turn = get_turn() local turn = get_turn()
if turn<0 then if turn<0 then
turn = read_turn() turn = read_turn()
set_turn(turn) set_turn(turn)
end end
orderfile = orderfile or config.basepath .. '/orders.' .. turn orderfile = orderfile or config.basepath .. '/orders.' .. turn
eressea.log.debug("executing turn " .. get_turn() .. " with " .. orderfile .. " with rules=" .. config.rules) eressea.log.debug("executing turn " .. get_turn() .. " with " .. orderfile .. " with rules=" .. config.rules)
local result = process(rules, orderfile) local result = process(rules, orderfile)
return result return result
end end
function file_exists(name) function file_exists(name)
local f=io.open(name,"r") local f=io.open(name,"r")
if not f then if not f then
return false return false
end end
io.close(f) io.close(f)
return true return true
end end
if file_exists('execute.lock') then if file_exists('execute.lock') then
eressea.log.error("Lockfile exists, aborting.") eressea.log.error("Lockfile exists, aborting.")
assert(false) assert(false)
end end
math.randomseed(rng.random()) math.randomseed(rng.random())
@ -195,9 +195,9 @@ require 'eressea.xmlconf' -- read xml data
local rules = {} local rules = {}
if config.rules then if config.rules then
rules = require('eressea.' .. config.rules) rules = require('eressea.' .. config.rules)
eressea.log.info('loaded ' .. #rules .. ' modules for ' .. config.rules) eressea.log.info('loaded ' .. #rules .. ' modules for ' .. config.rules)
else else
eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r') eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r')
end end
run_turn(rules) run_turn(rules)