Rewrote the gates, and used them for hse05

This commit is contained in:
Enno Rehling 2005-01-07 23:48:11 +00:00
parent fa9d731fc5
commit f56a7d8ae7
5 changed files with 50 additions and 33 deletions

View File

@ -1,31 +1,13 @@
if gate_exchange==nil then
if gate_travel==nil then
dofile("gates.lua")
end
local 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
local function eternath_exchange(b1, b2, size)
local units1 = eternath_travellers(b1, size)
local units2 = eternath_travellers(b2, size)
local units1 = gate_units(b1, size)
local units2 = gate_units(b2, size)
gate_exchange(b1, units1, b2, units2)
gate_travel(b2, units1)
gate_travel(b1, units2)
end
function eternathgate_action(b)

View File

@ -1,12 +1,27 @@
function gate_exchange(b1, units1, b2, units2)
function gate_travel(b, units)
-- 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
for u in units do
u.region = b.region
u.building = b
end
end
function gate_units(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

View File

@ -1,5 +1,6 @@
function run_scripts()
scripts = {
"hse05-portals.lua"
}
for index in scripts do
local script = scriptpath .. "/" .. scripts[index]

View File

@ -0,0 +1,18 @@
if gate_travel==nil then
dofile("gates.lua")
end
buildings = {}
function portal_exchange(b1, param)
b2 = buildings[param]
if buildings[param] == nil then
buildings[param] = b1
else
u1 = gate_units(b1, 100)
u2 = gate_units(b2, 100)
gate_travel(b1, u2)
gate_travel(b2, u1)
end
return 1
end

View File

@ -2,7 +2,7 @@
-- used on the jadee/wildente wedding island. the two _action functions
-- are used as age() functions for a building_action with b:addaction("name")
if gate_exchange==nil then
if gate_travel==nil then
dofile("gates.lua")
end
@ -24,7 +24,8 @@ local function wedding_exchange(b1, b2)
local units1 = wedding_travellers(b1)
local units2 = wedding_travellers(b2)
gate_exchange(b1, units1, b2, units2)
gate_travel(b2, units1)
gate_travel(b1, units2)
end
function hellgate_action(b)