2007-08-08 09:43:24 +02:00
|
|
|
-- the locales that this gameworld supports.
|
|
|
|
local locales = { "de", "en" }
|
|
|
|
|
2005-11-26 00:32:56 +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
|
|
|
|
|
2005-12-11 10:58:17 +01:00
|
|
|
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
|
|
|
|
|
2005-11-26 00:32:56 +01:00
|
|
|
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
|
2005-11-26 02:31:35 +01:00
|
|
|
if b ~=nil then
|
|
|
|
u = b.units()
|
|
|
|
if u~=nil and u.faction~=r.owner then
|
|
|
|
r.owner = u.faction
|
|
|
|
end
|
2005-11-26 00:32:56 +01:00
|
|
|
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()
|
2005-12-11 10:58:17 +01:00
|
|
|
update_resources()
|
2005-11-26 00:32:56 +01:00
|
|
|
|
|
|
|
-- use newfactions file to place out new players
|
|
|
|
autoseed(basepath .. "/newfactions", true)
|
|
|
|
|
2007-08-08 09:43:24 +02:00
|
|
|
write_files(locales)
|
2005-11-26 00:32:56 +01:00
|
|
|
|
|
|
|
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
|
2007-08-08 09:43:24 +02:00
|
|
|
loadscript("default.lua")
|
2005-11-26 00:32:56 +01:00
|
|
|
loadscript("extensions.lua")
|
|
|
|
loadscript("kingdoms/extensions.lua")
|
|
|
|
process(orderfile)
|
|
|
|
end
|
|
|
|
|