Merge pull request #4530 from obrakmann/lua
Added a few Lua functions, attempt 2
This commit is contained in:
@@ -180,3 +180,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
@@ -47,8 +47,8 @@ Actor.Teleport = function(actor, location)
|
||||
actor:QueueActivity(OpenRA.New("SimpleTeleport", { location }))
|
||||
end
|
||||
|
||||
Actor.AttackMove = function(actor, location)
|
||||
Internal.AttackMove(actor, location)
|
||||
Actor.AttackMove = function(actor, location, nearEnough)
|
||||
Internal.AttackMove(actor, location, nearEnough or 0)
|
||||
end
|
||||
|
||||
Actor.HeliFly = function(actor, position)
|
||||
@@ -178,3 +178,25 @@ 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.Patrol = function(actor, waypoints, wait, loop)
|
||||
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
|
||||
|
||||
Actor.PatrolUntil = function(actor, waypoints, wait, func)
|
||||
if func == nil then error("No function specified", 2) end
|
||||
Actor.Patrol(actor, waypoints, wait, false)
|
||||
if not func(actor) then
|
||||
Actor.CallFunc(actor, function() Actor.PatrolUntil(actor, waypoints, wait, func) end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,48 @@ Map.GetNamedActor = function(actorName)
|
||||
return Internal.GetNamedActor(actorName)
|
||||
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
|
||||
|
||||
CPos.New = function(x, y)
|
||||
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
||||
end
|
||||
|
||||
@@ -10,6 +10,7 @@ OpenRA.New = function(className, args)
|
||||
end
|
||||
|
||||
OpenRA.RunAfterDelay = function(delay, func)
|
||||
if func == nil then error("No function specified", 2) end
|
||||
Internal.RunAfterDelay(delay, func)
|
||||
end
|
||||
|
||||
@@ -42,7 +43,11 @@ OpenRA.SetWinState = function(player, winState)
|
||||
end
|
||||
|
||||
OpenRA.GetRandomInteger = function(low, high)
|
||||
return Internal.GetRandomInteger(low, high)
|
||||
if high <= low then
|
||||
return low
|
||||
else
|
||||
return Internal.GetRandomInteger(low, high)
|
||||
end
|
||||
end
|
||||
|
||||
OpenRA.TakeOre = function(player, amount)
|
||||
|
||||
17
mods/common/lua/production.lua
Normal file
17
mods/common/lua/production.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
Production = { }
|
||||
|
||||
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.SetRallyPoint = function(factory, location)
|
||||
Actor.Trait(factory, "RallyPoint").rallyPoint = location.Location
|
||||
end
|
||||
|
||||
Production.SetPrimaryBuilding = function(factory)
|
||||
Actor.Trait(factory, "PrimaryBuilding"):SetPrimaryProducer(factory, true)
|
||||
end
|
||||
@@ -12,24 +12,22 @@ Team.New = function(actors)
|
||||
end
|
||||
|
||||
Team.AddActorEventHandlers = function(team)
|
||||
for i, actor in ipairs(team.Actors) do
|
||||
Team.Do(team, function(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
|
||||
end)
|
||||
end
|
||||
|
||||
Team.InvokeHandlers = function(event)
|
||||
for i, handler in ipairs(event) do
|
||||
handler()
|
||||
end
|
||||
Utils.Do(event, function(handler) handler() end)
|
||||
end
|
||||
|
||||
Team.AllAreDead = function(team)
|
||||
@@ -58,4 +56,12 @@ end
|
||||
|
||||
Team.Do = function(team, func)
|
||||
Utils.Do(team.Actors, func)
|
||||
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
|
||||
|
||||
@@ -74,4 +74,13 @@ end
|
||||
|
||||
Utils.TableToArray = function(luaTable)
|
||||
return Internal.TableToArray(luaTable)
|
||||
end
|
||||
end
|
||||
|
||||
Utils.Seconds = function(seconds)
|
||||
local TicksPerSecond = 25
|
||||
return seconds * TicksPerSecond
|
||||
end
|
||||
|
||||
Utils.Minutes = function(minutes)
|
||||
return Utils.Seconds(minutes * 60)
|
||||
end
|
||||
|
||||
@@ -161,3 +161,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
@@ -177,3 +177,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
@@ -199,3 +199,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
Reference in New Issue
Block a user