Eternath-Questenskript

This commit is contained in:
Enno Rehling 2004-07-13 11:48:16 +00:00
parent 3b29df22e7
commit d853ae12a4
3 changed files with 68 additions and 19 deletions

View File

@ -61,7 +61,11 @@ end
-- main body of script
--
scripts = { "ponnuki.lua", "wedding-jadee.lua" }
scripts = {
"wedding-jadee.lua",
"eternath.lua",
"ponnuki.lua"
}
-- orderfile: contains the name of the orders.
if orderfile==nil then

44
src/scripts/eternath.lua Normal file
View File

@ -0,0 +1,44 @@
function eternath_travellers(b, maxsize)
local size = maxsize
local units = {}
local u
local first = true
for u in b.units do
if first then
first = false
else
if u.number<=size and u.weight<=u.capacity then
units[u] = u
size = size - u.number
end
end
end
return units
end
function eternath_exchange(b1, b2)
-- identify everyone who is travelling, first:
local units1 = eternath_travellers(b1, 10)
local units2 = eternath_travellers(b2, 10)
-- we've found which units we want to exchange, now swap them:
local u
for u in units1 do
u.region = b2.region
u.building = b2
end
for u in units2 do
u.region = b1.region
u.building = b1
end
end
function eternathgate_action(b)
if eternathgate == nil then
eternathgate = b
else
eternath_exchange(eternathgate, b)
end
return 1
end

View File

@ -5,27 +5,28 @@
hellgate = nil
peacegate = nil
function gate_exchange(b1, b2)
local units1 = {}
local units2 = {}
function wedding_travellers(b)
local units = {}
for u in b.units do
if u:get_flag("wdgt") then
units[u] = u
end
end
return units
end
function wedding_exchange(b1, b2)
local units1 = wedding_travellers(b1)
local units2 = wedding_travellers(b2)
-- we've found which units we want to exchange, now swap them:
local u
for u in b1.units do
if u:get_flag("wdgt") then
units1[u.no] = u
end
end
for u in b2.units do
if u:get_flag("wdgt") then
units2[u.no] = u
end
end
for id in units1 do
u = units1[id]
for u in units1 do
u.region = b2.region
u.building = b2
end
for id in units2 do
u = units2[id]
for u in units2 do
u.region = b1.region
u.building = b1
end
@ -35,7 +36,7 @@ function hellgate_action(b)
if hellgate == nil then
hellgate = b
else
gate_exchange(hellgate, b)
wedding_exchange(hellgate, b)
end
return 1
end