diff --git a/mods/ra/lua/reinforcements.lua b/mods/ra/lua/reinforcements.lua index 7f3046d6e1..b5f42f0b94 100644 --- a/mods/ra/lua/reinforcements.lua +++ b/mods/ra/lua/reinforcements.lua @@ -38,6 +38,27 @@ Reinforcements.PerformHelicopterExtraction = function(owner, helicopterName, pas return heli end +Reinforcements.PerformInsertion = function(owner, vehicleName, passengerNames, enterPath, exitPath) + local facing = { 0, "Int32" } + if #enterPath > 1 then + facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" } + end + local vehicle = Actor.Create(vehicleName, { Owner = owner, Location = enterPath[1], Facing = facing }) + local cargo = Actor.Trait(vehicle, "Cargo") + local passengers = { } + for i, passengerName in ipairs(passengerNames) do + local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner }) + passengers[i] = passenger + cargo:Load(vehicle, passenger) + end + Utils.Do(Utils.Skip(enterPath, 1), function(l) Actor.ScriptedMove(vehicle, l) end) + Actor.UnloadCargo(vehicle, true) + Actor.Wait(vehicle, 25) + Utils.Do(exitPath, function(l) Actor.ScriptedMove(vehicle, l) end) + Actor.RemoveSelf(vehicle) + return vehicle, passengers +end + Reinforcements.Reinforce = function(owner, reinforcementNames, enterLocation, rallyPointLocation, interval, onCreateFunc) local facing = { Map.GetFacing(CPos.op_Subtraction(rallyPointLocation, enterLocation), 0), "Int32" } local reinforcements = { } diff --git a/mods/ra/lua/team.lua b/mods/ra/lua/team.lua index f81fed4bcc..6d41af2d23 100644 --- a/mods/ra/lua/team.lua +++ b/mods/ra/lua/team.lua @@ -57,5 +57,5 @@ Team.Contains = function(team, actor) end Team.Do = function(team, func) - Utils.ForEach(team.Actors, func) + Utils.Do(team.Actors, func) end \ No newline at end of file diff --git a/mods/ra/lua/utils.lua b/mods/ra/lua/utils.lua index 9a486d88dc..eab8cbe6d7 100644 --- a/mods/ra/lua/utils.lua +++ b/mods/ra/lua/utils.lua @@ -56,12 +56,22 @@ Utils.Any = function(array, func) return false end -Utils.ForEach = function(array, func) +Utils.Do = function(array, func) for i, item in ipairs(array) do func(item) end end +Utils.Skip = function(array, n) + local ret = { } + for i, item in ipairs(array) do + if i > n then + table.insert(ret, item) + end + end + return ret +end + Utils.TableToArray = function(luaTable) return Internal.TableToArray(luaTable) end \ No newline at end of file