forked from github/server
4635c46ec2
- als dice_roll nach lua exportiert - equipment kann in inventories getan werden - region::land bekommt ein inventory - terraform legt equipment in neue regionen kingdoms: - neues terrain berge.
112 lines
2.2 KiB
Lua
112 lines
2.2 KiB
Lua
function loadscript(name)
|
|
local script = scriptpath .. "/" .. name
|
|
print("- loading " .. script)
|
|
if pcall(dofile, script)==0 then
|
|
print("Could not load " .. script)
|
|
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 update_resources()
|
|
-- remaining contents of region pool rots
|
|
-- wood falls from trees
|
|
local r
|
|
for r in regions() do
|
|
local item
|
|
for item in r.items do
|
|
local num = math.ceil(r:get_item(item)/2)
|
|
r:add_item(item, -num)
|
|
end
|
|
|
|
local wood = math.floor(r:get_resource("tree")/20)
|
|
if wood>0 then
|
|
r.add_item("log", wood)
|
|
end
|
|
end
|
|
end
|
|
|
|
function update_owners()
|
|
-- update the region's owners. currently uses the owner of
|
|
-- the largest castle.
|
|
local r
|
|
for r in regions() do
|
|
local lb = nil
|
|
for b in r.buildings do
|
|
if b.type=="castle" and (lb==nil or b.size>lb.size) then
|
|
lb = b
|
|
end
|
|
end
|
|
local u
|
|
if b ~=nil then
|
|
u = b.units()
|
|
if u~=nil and u.faction~=r.owner then
|
|
r.owner = u.faction
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function process(orders)
|
|
file = "" .. get_turn()
|
|
if read_game(file)~=0 then
|
|
print("could not read game")
|
|
return -1
|
|
end
|
|
init_summary()
|
|
|
|
-- run the turn:
|
|
read_orders(orders)
|
|
|
|
process_orders()
|
|
update_owners()
|
|
update_resources()
|
|
|
|
-- use newfactions file to place out new players
|
|
autoseed(basepath .. "/newfactions", true)
|
|
|
|
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
|
|
-- loadscript("spells.lua")
|
|
loadscript("extensions.lua")
|
|
loadscript("kingdoms/extensions.lua")
|
|
process(orderfile)
|
|
end
|
|
|