From f56a7d8ae774fa65a44c6155c8d00ee923d75cdc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 7 Jan 2005 23:48:11 +0000 Subject: [PATCH] Rewrote the gates, and used them for hse05 --- src/scripts/eternath.lua | 28 +++++----------------------- src/scripts/gates.lua | 31 +++++++++++++++++++++++-------- src/scripts/hse05-01.lua | 1 + src/scripts/hse05-portals.lua | 18 ++++++++++++++++++ src/scripts/wedding-jadee.lua | 5 +++-- 5 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 src/scripts/hse05-portals.lua diff --git a/src/scripts/eternath.lua b/src/scripts/eternath.lua index f70e41a26..82cb2a32b 100644 --- a/src/scripts/eternath.lua +++ b/src/scripts/eternath.lua @@ -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) diff --git a/src/scripts/gates.lua b/src/scripts/gates.lua index 823d9dd79..1b6cc998b 100644 --- a/src/scripts/gates.lua +++ b/src/scripts/gates.lua @@ -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 diff --git a/src/scripts/hse05-01.lua b/src/scripts/hse05-01.lua index c020391d6..b3c5ae048 100644 --- a/src/scripts/hse05-01.lua +++ b/src/scripts/hse05-01.lua @@ -1,5 +1,6 @@ function run_scripts() scripts = { + "hse05-portals.lua" } for index in scripts do local script = scriptpath .. "/" .. scripts[index] diff --git a/src/scripts/hse05-portals.lua b/src/scripts/hse05-portals.lua new file mode 100644 index 000000000..e22a6ca3f --- /dev/null +++ b/src/scripts/hse05-portals.lua @@ -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 diff --git a/src/scripts/wedding-jadee.lua b/src/scripts/wedding-jadee.lua index 2f8f65df7..558ec0631 100644 --- a/src/scripts/wedding-jadee.lua +++ b/src/scripts/wedding-jadee.lua @@ -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)