Remove legacy Lua API.
This commit is contained in:
@@ -1,236 +0,0 @@
|
||||
Actor = { }
|
||||
|
||||
Actor.Create = function(name, init)
|
||||
if name == nil then error("No actor name specified", 2) end
|
||||
if init.Owner == nil then error("No actor owner specified", 2) end
|
||||
local td = OpenRA.New("TypeDictionary")
|
||||
local addToWorld = true
|
||||
for key, value in pairs(init) do
|
||||
if key == "AddToWorld" then
|
||||
addToWorld = value
|
||||
else
|
||||
td:Add(OpenRA.New(key .. "Init", { value }))
|
||||
end
|
||||
end
|
||||
return World:CreateActor(addToWorld, name, td)
|
||||
end
|
||||
|
||||
Actor.Turn = function(actor, facing)
|
||||
actor:QueueActivity(OpenRA.New("Turn", { actor, { facing, "Int32" } }))
|
||||
end
|
||||
|
||||
Actor.Move = function(actor, location)
|
||||
Actor.MoveNear(actor, location, 0)
|
||||
end
|
||||
|
||||
Actor.MoveNear = function(actor, location, nearEnough)
|
||||
actor:QueueActivity(OpenRA.New("Move", { actor, location, WRange.FromCells(nearEnough) }))
|
||||
end
|
||||
|
||||
Actor.ScriptedMove = function(actor, location)
|
||||
if Actor.HasTrait(actor, "Helicopter") then
|
||||
Internal.HeliFlyToPos(actor, Map.CenterOfCell(location))
|
||||
else
|
||||
actor:QueueActivity(OpenRA.New("Move", { actor, location }))
|
||||
end
|
||||
end
|
||||
|
||||
Actor.AfterMove = function(actor)
|
||||
local heli = Actor.TraitOrDefault(actor, "Helicopter")
|
||||
if heli ~= nil then
|
||||
Actor.Turn(actor, heli.Info.InitialFacing)
|
||||
Actor.HeliLand(actor, true)
|
||||
end
|
||||
end
|
||||
|
||||
Actor.Teleport = function(actor, location)
|
||||
actor:QueueActivity(OpenRA.New("SimpleTeleport", { location }))
|
||||
end
|
||||
|
||||
Actor.AttackMove = function(actor, location, nearEnough)
|
||||
Internal.AttackMove(actor, location, nearEnough or 0)
|
||||
end
|
||||
|
||||
Actor.HeliFly = function(actor, position)
|
||||
Internal.HeliFlyToPos(actor, position)
|
||||
end
|
||||
|
||||
Actor.HeliLand = function(actor, requireSpace)
|
||||
actor:QueueActivity(OpenRA.New("HeliLand", { requireSpace }))
|
||||
end
|
||||
|
||||
Actor.Fly = function(actor, position)
|
||||
Internal.FlyToPos(actor, position)
|
||||
end
|
||||
|
||||
Actor.FlyAttackActor = function(actor, targetActor)
|
||||
Internal.FlyAttackActor(actor, targetActor)
|
||||
end
|
||||
|
||||
Actor.FlyAttackCell = function(actor, location)
|
||||
Internal.FlyAttackCell(actor, location)
|
||||
end
|
||||
|
||||
Actor.FlyOffMap = function(actor)
|
||||
actor:QueueActivity(OpenRA.New("FlyOffMap"))
|
||||
end
|
||||
|
||||
Actor.Hunt = function(actor)
|
||||
if Actor.HasTrait(actor, "AttackBase") and Actor.HasTrait(actor, "IMove") then
|
||||
actor:QueueActivity(OpenRA.New("Hunt", { actor }))
|
||||
end
|
||||
end
|
||||
|
||||
Actor.CargoIsEmpty = function(actor)
|
||||
local cargo = Actor.TraitOrDefault(actor, "Cargo")
|
||||
return cargo == nil or cargo:IsEmpty(actor)
|
||||
end
|
||||
|
||||
Actor.UnloadCargo = function(actor, unloadAll)
|
||||
actor:QueueActivity(OpenRA.New("UnloadCargo", { actor, unloadAll }))
|
||||
end
|
||||
|
||||
Actor.Harvest = function(actor)
|
||||
actor:QueueActivity(OpenRA.New("FindResources"))
|
||||
end
|
||||
|
||||
Actor.Scatter = function(actor)
|
||||
local mobile = Actor.Trait(actor, "Mobile")
|
||||
mobile:Nudge(actor, actor, true)
|
||||
end
|
||||
|
||||
Actor.Wait = function(actor, period)
|
||||
actor:QueueActivity(OpenRA.New("Wait", { { period, "Int32" } }))
|
||||
end
|
||||
|
||||
Actor.WaitFor = function(actor, func)
|
||||
Internal.WaitFor(actor, func)
|
||||
end
|
||||
|
||||
Actor.CallFunc = function(actor, func)
|
||||
Internal.CallFunc(actor, func)
|
||||
end
|
||||
|
||||
Actor.DeployTransform = function(actor)
|
||||
Actor.CallFunc(actor, function()
|
||||
-- Queue the transform order
|
||||
Actor.Trait(actor, "Transforms"):DeployTransform(true)
|
||||
end)
|
||||
end
|
||||
|
||||
Actor.RemoveSelf = function(actor)
|
||||
actor:QueueActivity(OpenRA.New("RemoveSelf"))
|
||||
end
|
||||
|
||||
Actor.Stop = function(actor)
|
||||
actor:CancelActivity()
|
||||
end
|
||||
|
||||
Actor.IsDead = function(actor)
|
||||
return Internal.IsDead(actor)
|
||||
end
|
||||
|
||||
Actor.IsInWorld = function(actor)
|
||||
return actor.IsInWorld
|
||||
end
|
||||
|
||||
Actor.Owner = function(actor)
|
||||
return actor.Owner
|
||||
end
|
||||
|
||||
Actor.Facing = function(actor)
|
||||
return Actor.Trait(actor, "IFacing"):get_Facing()
|
||||
end
|
||||
|
||||
Actor.IsIdle = function(actor)
|
||||
return actor.IsIdle
|
||||
end
|
||||
|
||||
Actor.SetStance = function(actor, stance)
|
||||
Internal.SetUnitStance(actor, stance)
|
||||
end
|
||||
|
||||
Actor.RepairBuilding = function(actor)
|
||||
local rb = Actor.TraitOrDefault(actor, "RepairableBuilding")
|
||||
if rb ~= nil and not rb.RepairActive then
|
||||
rb:RepairBuilding(actor, Actor.Owner(actor))
|
||||
end
|
||||
end
|
||||
|
||||
Actor.OnDamaged = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnDamaged:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnKilled = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnKilled:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnAddedToWorld = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnAddedToWorld:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnRemovedFromWorld = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnRemovedFromWorld:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnCaptured = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnCaptured:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnIdle = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnIdle:Add(eh)
|
||||
end
|
||||
|
||||
Actor.OnProduced = function(actor, eh)
|
||||
Actor.Trait(actor, "LuaScriptEvents").OnProduced:Add(eh)
|
||||
end
|
||||
|
||||
Actor.ActorsWithTrait = function(className)
|
||||
local ret = { }
|
||||
for item in Utils.Enumerate(Internal.ActorsWithTrait(className)) do
|
||||
table.insert(ret, item.Actor)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Actor.HasTrait = function(actor, className)
|
||||
return Internal.HasTrait(actor, className)
|
||||
end
|
||||
|
||||
Actor.TraitOrDefault = function(actor, className)
|
||||
return Internal.TraitOrDefault(actor, className)
|
||||
end
|
||||
|
||||
Actor.Trait = function(actor, className)
|
||||
return Internal.Trait(actor, className)
|
||||
end
|
||||
|
||||
Actor.ReturnToBase = function(actor, airfield)
|
||||
actor:QueueActivity(OpenRA.New("ReturnToBase", { actor, airfield }))
|
||||
end
|
||||
|
||||
Actor.Guard = function(actor, target)
|
||||
Internal.Guard(actor, target)
|
||||
end
|
||||
|
||||
Actor.Patrol = function(actor, waypoints, wait, loop)
|
||||
if not Actor.IsDead(actor) then
|
||||
Utils.Do(waypoints, function(wpt)
|
||||
Actor.AttackMove(actor, wpt.Location, 3)
|
||||
Actor.Wait(actor, wait or 0)
|
||||
end)
|
||||
if loop or loop == nil then
|
||||
Actor.CallFunc(actor, function() Actor.Patrol(actor, waypoints, wait, loop) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Actor.PatrolUntil = function(actor, waypoints, wait, func)
|
||||
if func == nil then error("No function specified", 2) end
|
||||
if not Actor.IsDead(actor) then
|
||||
Actor.Patrol(actor, waypoints, wait, false)
|
||||
if not func(actor) then
|
||||
Actor.CallFunc(actor, function() Actor.PatrolUntil(actor, waypoints, wait, func) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,10 +0,0 @@
|
||||
Facing = { }
|
||||
|
||||
Facing.North = { 0, "Int32" }
|
||||
Facing.NorthWest = { 32, "Int32" }
|
||||
Facing.West = { 64, "Int32" }
|
||||
Facing.SouthWest = { 96, "Int32" }
|
||||
Facing.South = { 128, "Int32" }
|
||||
Facing.SouthEast = { 160, "Int32" }
|
||||
Facing.East = { 192, "Int32" }
|
||||
Facing.NorthEast = { 224, "Int32" }
|
||||
@@ -1,109 +0,0 @@
|
||||
Map = { }
|
||||
|
||||
Map.GetFacing = function(vec, currentFacing)
|
||||
return Internal.GetFacing(vec, currentFacing)
|
||||
end
|
||||
|
||||
Map.GetRandomCell = function()
|
||||
return Internal.GetRandomCell()
|
||||
end
|
||||
|
||||
Map.GetRandomEdgeCell = function()
|
||||
return Internal.GetRandomEdgeCell()
|
||||
end
|
||||
|
||||
Map.IsNamedActor = function(actor)
|
||||
return Internal.IsNamedActor(actor)
|
||||
end
|
||||
|
||||
Map.GetNamedActor = function(actorName)
|
||||
return Internal.GetNamedActor(actorName)
|
||||
end
|
||||
|
||||
Map.GetNamedActors = function()
|
||||
return Internal.GetNamedActors()
|
||||
end
|
||||
|
||||
Map.FindActorsInCircle = function(location, radius, func)
|
||||
local actors = Internal.FindActorsInCircle(location.CenterPosition, WRange.FromCells(radius))
|
||||
return Utils.EnumerableWhere(actors, func)
|
||||
end
|
||||
|
||||
Map.FindActorsInBox = function(topLeft, bottomRight, func)
|
||||
local actors = Internal.FindActorsInBox(topLeft.CenterPosition, bottomRight.CenterPosition)
|
||||
return Utils.EnumerableWhere(actors, func)
|
||||
end
|
||||
|
||||
Map.__FilterByTrait = function(a, player, trait)
|
||||
return Actor.Owner(a) == player and Actor.HasTrait(a, trait)
|
||||
end
|
||||
|
||||
Map.__FilterByTraitAndIdle = function(a, player, trait)
|
||||
return Map.__FilterByTrait(a, player, trait) and Actor.IsIdle(a)
|
||||
end
|
||||
|
||||
Map.FindUnitsInCircle = function(player, location, radius)
|
||||
return Map.FindActorsInCircle(location, radius, function(a) return Map.__FilterByTrait(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.FindUnitsInBox = function(player, topLeft, bottomRight)
|
||||
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTrait(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.FindStructuresInCircle = function(player, location, radius)
|
||||
return Map.FindActorsInCircle(location, radius, function(a) return Map.__FilterByTrait(a, player, "Building") end)
|
||||
end
|
||||
|
||||
Map.FindStructuresInBox = function(player, topLeft, bottomRight)
|
||||
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTrait(a, player, "Building") end)
|
||||
end
|
||||
|
||||
Map.FindIdleUnitsInCircle = function(player, location, radius)
|
||||
return Map.FindActorsInCircle(location, radius, function(a) return Map.__FilterByTraitAndIdle(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.FindIdleUnitsInBox = function(player, topLeft, bottomRight)
|
||||
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTraitAndIdle(a, player, "Mobile") end)
|
||||
end
|
||||
|
||||
Map.ExpandFootprint = function(cells, allowDiagonal)
|
||||
return Utils.EnumerableToTable(Internal.ExpandFootprint(cells, allowDiagonal))
|
||||
end
|
||||
|
||||
Map.CenterOfCell = function(position)
|
||||
return Internal.CenterOfCell(position)
|
||||
end
|
||||
|
||||
CPos.New = function(x, y)
|
||||
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
||||
end
|
||||
|
||||
WPos.New = function(x, y, z)
|
||||
if z == nil then
|
||||
z = 0
|
||||
end
|
||||
return OpenRA.New("WPos", { { x, "Int32" }, { y, "Int32" }, { z, "Int32" } })
|
||||
end
|
||||
|
||||
WPos.FromCPos = function(location)
|
||||
return WPos.New(location.X * 1024, location.Y * 1024, 0)
|
||||
end
|
||||
|
||||
CVec.New = function(x, y)
|
||||
return OpenRA.New("CVec", { { x, "Int32" }, { y, "Int32" } })
|
||||
end
|
||||
|
||||
WVec.New = function(x, y, z)
|
||||
if z == nil then
|
||||
z = 0
|
||||
end
|
||||
return OpenRA.New("WVec", { { x, "Int32" }, { y, "Int32" }, { z, "Int32" } })
|
||||
end
|
||||
|
||||
WRange.New = function(r)
|
||||
return OpenRA.New("WRange", { { r, "Int32" } })
|
||||
end
|
||||
|
||||
WRange.FromCells = function(cells)
|
||||
return WRange.New(cells * 1024)
|
||||
end
|
||||
@@ -1,20 +0,0 @@
|
||||
Media = { }
|
||||
|
||||
Media.PlaySpeechNotification = function(notification, player)
|
||||
Internal.PlaySpeechNotification(player, notification)
|
||||
end
|
||||
|
||||
Media.PlaySoundNotification = function(notification, player)
|
||||
Internal.PlaySoundNotification(player, notification)
|
||||
end
|
||||
|
||||
Media.PlayRandomMusic = function()
|
||||
Internal.PlayRandomMusic()
|
||||
end
|
||||
|
||||
Media.PlayMovieFullscreen = function(movie, onComplete)
|
||||
if onComplete == nil then
|
||||
onComplete = function() end
|
||||
end
|
||||
Internal.PlayMovieFullscreen(movie, onComplete)
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
Mission = { }
|
||||
|
||||
Mission.MissionOver = function(winners, losers, setWinStates)
|
||||
World:SetLocalPauseState(true)
|
||||
World:set_PauseStateLocked(true)
|
||||
if winners then
|
||||
for i, player in ipairs(winners) do
|
||||
Media.PlaySpeechNotification("Win", player)
|
||||
if setWinStates then
|
||||
OpenRA.SetWinState(player, "Won")
|
||||
end
|
||||
end
|
||||
end
|
||||
if losers then
|
||||
for i, player in ipairs(losers) do
|
||||
Media.PlaySpeechNotification("Lose", player)
|
||||
if setWinStates then
|
||||
OpenRA.SetWinState(player, "Lost")
|
||||
end
|
||||
end
|
||||
end
|
||||
Mission.MissionIsOver = true
|
||||
end
|
||||
|
||||
Mission.GetGroundAttackersOf = function(player)
|
||||
return Utils.Where(Actor.ActorsWithTrait("AttackBase"), function(actor)
|
||||
return not Actor.IsDead(actor) and Actor.IsInWorld(actor) and Actor.Owner(actor) == player and Actor.HasTrait(actor, "Mobile")
|
||||
end)
|
||||
end
|
||||
|
||||
Mission.TickTakeOre = function(player)
|
||||
OpenRA.TakeOre(player, 0.01 * OpenRA.GetOreCapacity(player) / 25)
|
||||
end
|
||||
|
||||
Mission.RequiredUnitsAreDestroyed = function(player)
|
||||
return Internal.RequiredUnitsAreDestroyed(player)
|
||||
end
|
||||
@@ -1,83 +0,0 @@
|
||||
print = Internal.Debug
|
||||
|
||||
OpenRA = { }
|
||||
|
||||
OpenRA.New = function(className, args)
|
||||
if args == nil then
|
||||
args = { }
|
||||
end
|
||||
return Internal.New(className, args)
|
||||
end
|
||||
|
||||
OpenRA.RunAfterDelay = function(delay, func)
|
||||
if func == nil then error("No function specified", 2) end
|
||||
Internal.RunAfterDelay(delay, func)
|
||||
end
|
||||
|
||||
OpenRA.SetViewportCenterPosition = function(position)
|
||||
WorldRenderer.Viewport:Center(position)
|
||||
end
|
||||
|
||||
OpenRA.GetViewportCenterPosition = function()
|
||||
return WorldRenderer.Viewport.CenterPosition
|
||||
end
|
||||
|
||||
OpenRA.GetDifficulty = function()
|
||||
return World.LobbyInfo.GlobalSettings.Difficulty
|
||||
end
|
||||
|
||||
OpenRA.IsSinglePlayer = function()
|
||||
return World.LobbyInfo:get_IsSinglePlayer()
|
||||
end
|
||||
|
||||
OpenRA.GetPlayer = function(internalName)
|
||||
return Utils.EnumerableFirstOrNil(World.Players, function(p) return p.InternalName == internalName end)
|
||||
end
|
||||
|
||||
OpenRA.GetPlayers = function(func)
|
||||
return Utils.EnumerableWhere(World.Players, func)
|
||||
end
|
||||
|
||||
OpenRA.SetWinState = function(player, winState)
|
||||
Internal.SetWinState(player, winState)
|
||||
end
|
||||
|
||||
OpenRA.GetRandomInteger = function(low, high)
|
||||
if high <= low then
|
||||
return low
|
||||
else
|
||||
return Internal.GetRandomInteger(low, high)
|
||||
end
|
||||
end
|
||||
|
||||
OpenRA.TakeOre = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):TakeResources(amount)
|
||||
end
|
||||
|
||||
OpenRA.TakeCash = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):TakeCash(amount)
|
||||
end
|
||||
|
||||
OpenRA.GiveOre = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):GiveResources(amount)
|
||||
end
|
||||
|
||||
OpenRA.GiveCash = function(player, amount)
|
||||
Actor.Trait(player.PlayerActor, "PlayerResources"):GiveCash(amount)
|
||||
end
|
||||
|
||||
OpenRA.CanGiveOre = function(player, amount)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources"):CanGiveResources(amount)
|
||||
end
|
||||
|
||||
OpenRA.GetOreCapacity = function(player)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources").ResourceCapacity
|
||||
end
|
||||
|
||||
OpenRA.GetOre = function(player)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources").Resources
|
||||
end
|
||||
|
||||
OpenRA.GetCash = function(player)
|
||||
return Actor.Trait(player.PlayerActor, "PlayerResources").Cash
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
Production = { }
|
||||
Production.EventHandlers = { }
|
||||
|
||||
Production.BuildWithSharedQueue = function(player, unit, amount)
|
||||
Internal.BuildWithSharedQueue(player, unit, amount or 1)
|
||||
end
|
||||
|
||||
Production.BuildWithPerFactoryQueue = function(factory, unit, amount)
|
||||
Internal.BuildWithPerFactoryQueue(factory, unit, amount or 1)
|
||||
end
|
||||
|
||||
Production.Build = function(factory, unit, amount)
|
||||
if Actor.HasTrait(factory, "ProductionQueue") then
|
||||
Production.BuildWithPerFactoryQueue(factory, unit, amount)
|
||||
elseif Actor.HasTrait(factory, "Production") then
|
||||
Production.SetPrimaryBuilding(factory)
|
||||
Production.BuildWithSharedQueue(Actor.Owner(factory), unit, amount)
|
||||
else
|
||||
error("Production.Build: not a factory")
|
||||
end
|
||||
end
|
||||
|
||||
Production.SharedQueueIsBusy = function(player, category)
|
||||
return Internal.SharedQueueIsBusy(player, category)
|
||||
end
|
||||
|
||||
Production.PerFactoryQueueIsBusy = function(factory)
|
||||
return Internal.PerFactoryQueueIsBusy(factory)
|
||||
end
|
||||
|
||||
Production.SetRallyPoint = function(factory, location)
|
||||
local srp = Actor.Trait(factory, "RallyPoint")
|
||||
if srp ~= nil then
|
||||
srp.Location = location.Location
|
||||
end
|
||||
end
|
||||
|
||||
Production.SetPrimaryBuilding = function(factory)
|
||||
local pb = Actor.TraitOrDefault(factory, "PrimaryBuilding")
|
||||
if pb ~= nil then
|
||||
pb:SetPrimaryProducer(factory, true)
|
||||
end
|
||||
end
|
||||
|
||||
Production.BuildTeamFromTemplate = function(player, template, func)
|
||||
local factories = { }
|
||||
Utils.Do(template, function(t) table.insert(factories, t[1]) end)
|
||||
|
||||
if Utils.Any(factories, Actor.IsDead) then
|
||||
return
|
||||
end
|
||||
|
||||
if Utils.Any(factories, function(fact) return Production.EventHandlers[fact] end) then
|
||||
OpenRA.RunAfterDelay(Utils.Seconds(10), function() Production.BuildTeamFromTemplate(player, template, func) end)
|
||||
return
|
||||
end
|
||||
|
||||
local team = Team.New({ })
|
||||
local teamSize = 0
|
||||
Utils.Do(template, function(t) teamSize = teamSize + #t[2] end)
|
||||
|
||||
local eventHandler = function(unit)
|
||||
Team.Add(team, unit)
|
||||
|
||||
if #team.Actors >= teamSize then
|
||||
func(team)
|
||||
Utils.Do(factories, function(factory)
|
||||
Production.EventHandlers[factory] = nil
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Utils.Do(factories, function(factory)
|
||||
Production.EventHandlers[factory] = eventHandler
|
||||
end)
|
||||
|
||||
Utils.Do(template, function(t)
|
||||
Utils.Do(t[2], function(unit)
|
||||
Production.Build(t[1], unit)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
Production.EventHandlers.Setup = function(player)
|
||||
Utils.Do(Actor.ActorsWithTrait("Production"), function(factory)
|
||||
if Actor.Owner(factory) == player then
|
||||
Actor.OnProduced(factory, function(fact, unit)
|
||||
if Production.EventHandlers[fact] then
|
||||
Production.EventHandlers[fact](unit)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -1,82 +0,0 @@
|
||||
Reinforcements = { }
|
||||
|
||||
Reinforcements.Insert = function(owner, transportName, passengerNames, enterPath, exitPath)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterPath[1]), WVec.New(0, 0, Rules.InitialAltitude(transportName)))
|
||||
local transport = Actor.Create(transportName, { Owner = owner, Location = enterPath[1], CenterPosition = center, Facing = facing })
|
||||
local cargo = Actor.Trait(transport, "Cargo")
|
||||
local passengers = { }
|
||||
|
||||
for i, passengerName in ipairs(passengerNames) do
|
||||
local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner })
|
||||
passengers[i] = passenger
|
||||
cargo:Load(transport, passenger)
|
||||
end
|
||||
|
||||
Utils.Do(Utils.Skip(enterPath, 1), function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.AfterMove(transport)
|
||||
Actor.UnloadCargo(transport, true)
|
||||
Actor.Wait(transport, 25)
|
||||
Utils.Do(exitPath, function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.RemoveSelf(transport)
|
||||
return transport, passengers
|
||||
end
|
||||
|
||||
Reinforcements.Extract = function(owner, transportName, passengerNames, enterPath, exitPath)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterPath[1]), WVec.New(0, 0, Rules.InitialAltitude(transportName)))
|
||||
local transport = Actor.Create(transportName, { Owner = owner, Location = enterPath[1], CenterPosition = center, Facing = facing })
|
||||
local cargo = Actor.Trait(transport, "Cargo")
|
||||
|
||||
Utils.Do(Utils.Skip(enterPath, 1), function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.AfterMove(transport)
|
||||
Actor.WaitFor(transport, function()
|
||||
return Utils.All(passengerNames, function(passenger) return cargo.Passengers:Contains(passenger) end)
|
||||
end)
|
||||
|
||||
Actor.Wait(transport, 125)
|
||||
Utils.Do(exitPath, function(l) Actor.ScriptedMove(transport, l) end)
|
||||
Actor.RemoveSelf(transport)
|
||||
return transport
|
||||
end
|
||||
|
||||
Reinforcements.Reinforce = function(owner, reinforcementNames, enterLocation, rallyPointLocation, interval, onCreateFunc)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(rallyPointLocation, enterLocation), 0), "Int32" }
|
||||
local reinforcements = { }
|
||||
for i, reinforcementName in ipairs(reinforcementNames) do
|
||||
local reinforcement = Actor.Create(reinforcementName, { AddToWorld = false, Owner = owner, Location = enterLocation, Facing = facing })
|
||||
reinforcements[i] = reinforcement
|
||||
OpenRA.RunAfterDelay((i - 1) * interval, function()
|
||||
World:Add(reinforcement)
|
||||
Actor.MoveNear(reinforcement, rallyPointLocation, 2)
|
||||
if onCreateFunc ~= nil then
|
||||
onCreateFunc(reinforcement)
|
||||
end
|
||||
end)
|
||||
end
|
||||
return reinforcements
|
||||
end
|
||||
|
||||
Reinforcements.ReinforceWithCargo = function(owner, actorName, path, cargoNames, actionFunc)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(path[2].Location, path[1].Location), 0), "Int32" }
|
||||
local center = WPos.op_Addition(path[1].CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(actorName)))
|
||||
local actor = Actor.Create(actorName, { Owner = owner, Location = path[1].Location, CenterPosition = center, Facing = facing })
|
||||
local cargo = Actor.TraitOrDefault(actor, "Cargo")
|
||||
local team = Team.New({})
|
||||
if cargo ~= nil and cargoNames ~= nil and #cargoNames > 0 then
|
||||
local passengers = { }
|
||||
|
||||
for i, cargoName in ipairs(cargoNames) do
|
||||
local passenger = Actor.Create(cargoName, { AddToWorld = false, Owner = owner })
|
||||
Team.Add(team, passenger)
|
||||
passengers[i] = passenger
|
||||
cargo:Load(actor, passenger)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Utils.Do(Utils.Skip(path, 1), function(waypoint) Actor.ScriptedMove(actor, waypoint.Location) end)
|
||||
|
||||
if actionFunc then actionFunc(actor, team) end
|
||||
return actor, team
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
Rules = { }
|
||||
|
||||
Rules.HasTraitInfo = function(actorType, className)
|
||||
return Internal.HasTraitInfo(actorType, className)
|
||||
end
|
||||
|
||||
Rules.TraitInfoOrDefault = function(actorType, className)
|
||||
return Internal.TraitInfoOrDefault(actorType, className)
|
||||
end
|
||||
|
||||
Rules.TraitInfo = function(actorType, className)
|
||||
return Internal.TraitInfo(actorType, className)
|
||||
end
|
||||
|
||||
Rules.InitialAltitude = function(actorType)
|
||||
local ai = Rules.TraitInfoOrDefault(actorType, "AircraftInfo")
|
||||
if ai ~= nil then
|
||||
return ai.CruiseAltitude.Range
|
||||
end
|
||||
return 0
|
||||
end
|
||||
@@ -1,44 +0,0 @@
|
||||
SupportPowers = { }
|
||||
|
||||
SupportPowers.Airstrike = function(owner, planeName, enterLocation, bombLocation)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(bombLocation, enterLocation), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterLocation), WVec.New(0, 0, Rules.InitialAltitude(planeName)))
|
||||
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, CenterPosition = center })
|
||||
local bombLoc = Map.CenterOfCell(bombLocation)
|
||||
Actor.Trait(plane, "AttackBomber"):SetTarget(bombLoc)
|
||||
Actor.Fly(plane, bombLoc)
|
||||
Actor.FlyOffMap(plane)
|
||||
Actor.RemoveSelf(plane)
|
||||
return plane
|
||||
end
|
||||
|
||||
SupportPowers.Paradrop = function(owner, planeName, passengerNames, enterLocation, dropLocation)
|
||||
local facing = { Map.GetFacing(CPos.op_Subtraction(dropLocation, enterLocation), 0), "Int32" }
|
||||
local center = WPos.op_Addition(Map.CenterOfCell(enterLocation), WVec.New(0, 0, Rules.InitialAltitude(planeName)))
|
||||
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, CenterPosition = center })
|
||||
Actor.Fly(plane, Map.CenterOfCell(dropLocation))
|
||||
Actor.Trait(plane, "ParaDrop"):SetLZ(dropLocation, true)
|
||||
Actor.FlyOffMap(plane)
|
||||
Actor.RemoveSelf(plane)
|
||||
local cargo = Actor.Trait(plane, "Cargo")
|
||||
local passengers = { }
|
||||
for i, passengerName in ipairs(passengerNames) do
|
||||
local passenger = Actor.Create(passengerName, { AddToWorld = false, Owner = owner })
|
||||
passengers[i] = passenger
|
||||
cargo:Load(plane, passenger)
|
||||
end
|
||||
return plane, passengers
|
||||
end
|
||||
|
||||
SupportPowers.Chronoshift = function(unitLocationPairs, chronosphere, duration, killCargo)
|
||||
duration = duration or -1
|
||||
killCargo = killCargo or true
|
||||
Utils.Do(unitLocationPairs, function(pair)
|
||||
local unit = pair[1]
|
||||
local cell = pair[2]
|
||||
local cs = Actor.TraitOrDefault(unit, "Chronoshiftable")
|
||||
if cs ~= nil and cs:CanChronoshiftTo(unit, cell) then
|
||||
cs:Teleport(unit, cell, duration, killCargo, chronosphere)
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -1,73 +0,0 @@
|
||||
Team = { }
|
||||
|
||||
Team.New = function(actors)
|
||||
local team = { }
|
||||
team.Actors = actors
|
||||
team.OnAllKilled = { }
|
||||
team.OnAnyKilled = { }
|
||||
team.OnAllRemovedFromWorld = { }
|
||||
team.OnAnyRemovedFromWorld = { }
|
||||
Team.Do(team, function(actor) Team.AddActorEventHandlers(team, actor) end)
|
||||
return team
|
||||
end
|
||||
|
||||
Team.Add = function(team, actor)
|
||||
table.insert(team.Actors, actor)
|
||||
Team.AddActorEventHandlers(team, actor)
|
||||
end
|
||||
|
||||
Team.AddActorEventHandlers = function(team, actor)
|
||||
Actor.OnKilled(actor, function()
|
||||
Team.InvokeHandlers(team.OnAnyKilled)
|
||||
if Team.AllAreDead(team) then Team.InvokeHandlers(team.OnAllKilled) end
|
||||
end)
|
||||
|
||||
Actor.OnRemovedFromWorld(actor, function()
|
||||
Team.InvokeHandlers(team.OnAnyRemovedFromWorld)
|
||||
if not Team.AnyAreInWorld(team) then Team.InvokeHandlers(team.OnAllRemovedFromWorld) end
|
||||
end)
|
||||
end
|
||||
|
||||
Team.InvokeHandlers = function(event)
|
||||
Utils.Do(event, function(handler) handler() end)
|
||||
end
|
||||
|
||||
Team.AllAreDead = function(team)
|
||||
return Utils.All(team.Actors, Actor.IsDead)
|
||||
end
|
||||
|
||||
Team.AnyAreDead = function(team)
|
||||
return Utils.Any(team.Actors, Actor.IsDead)
|
||||
end
|
||||
|
||||
Team.AllAreInWorld = function(team)
|
||||
return Utils.All(team.Actors, Actor.IsInWorld)
|
||||
end
|
||||
|
||||
Team.AnyAreInWorld = function(team)
|
||||
return Utils.Any(team.Actors, Actor.IsInWorld)
|
||||
end
|
||||
|
||||
Team.AddEventHandler = function(event, func)
|
||||
table.insert(event, func)
|
||||
end
|
||||
|
||||
Team.Contains = function(team, actor)
|
||||
return Utils.Any(team.Actors, function(a) return a == actor end)
|
||||
end
|
||||
|
||||
Team.Do = function(team, func)
|
||||
Utils.Do(team.Actors, function(actor)
|
||||
if not Actor.IsDead(actor) then
|
||||
func(actor)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Team.Patrol = function(team, waypoints, wait, loop)
|
||||
Team.Do(team, function(a) Actor.Patrol(a, waypoints, wait, loop) end)
|
||||
end
|
||||
|
||||
Team.PatrolUntil = function(team, waypoints, wait, func)
|
||||
Team.Do(team, function(a) Actor.PatrolUntil(a, waypoints, wait, func) end)
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
Utils = { }
|
||||
|
||||
Utils.Enumerate = function(netEnumerable)
|
||||
local enum = netEnumerable:GetEnumerator()
|
||||
return function()
|
||||
if enum:MoveNext() then
|
||||
return enum:get_Current()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Utils.EnumerableFirstOrNil = function(netEnumerable, func)
|
||||
for item in Utils.Enumerate(netEnumerable) do
|
||||
if func(item) then
|
||||
return item
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
Utils.EnumerableWhere = function(netEnumerable, func)
|
||||
local ret = { }
|
||||
for item in Utils.Enumerate(netEnumerable) do
|
||||
if func(item) then
|
||||
table.insert(ret, item)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.EnumerableToTable = function(netEnumerable, func)
|
||||
local ret = { }
|
||||
for item in Utils.Enumerate(netEnumerable) do
|
||||
table.insert(ret, item)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.Where = function(array, func)
|
||||
local ret = { }
|
||||
for i, item in ipairs(array) do
|
||||
if func(item) then
|
||||
table.insert(ret, item)
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Utils.All = function(array, func)
|
||||
for i, item in ipairs(array) do
|
||||
if not func(item) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Utils.Any = function(array, func)
|
||||
for i, item in ipairs(array) do
|
||||
if func(item) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Utils.Seconds = function(seconds)
|
||||
local TicksPerSecond = 25
|
||||
return seconds * TicksPerSecond
|
||||
end
|
||||
|
||||
Utils.Minutes = function(minutes)
|
||||
return Utils.Seconds(minutes * 60)
|
||||
end
|
||||
Reference in New Issue
Block a user