diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index 02632ff99..fb3ddbd85 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -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 diff --git a/src/scripts/eternath.lua b/src/scripts/eternath.lua new file mode 100644 index 000000000..475387285 --- /dev/null +++ b/src/scripts/eternath.lua @@ -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 diff --git a/src/scripts/wedding-jadee.lua b/src/scripts/wedding-jadee.lua index 71791cc97..ec0501ed9 100644 --- a/src/scripts/wedding-jadee.lua +++ b/src/scripts/wedding-jadee.lua @@ -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