Add Map.FindActorsInCircle and ...InBox, plus related shortcuts
This commit is contained in:
@@ -330,5 +330,17 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
return mapActors[actorName];
|
return mapActors[actorName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[LuaGlobal]
|
||||||
|
public Actor[] FindActorsInBox(WPos topLeft, WPos bottomRight)
|
||||||
|
{
|
||||||
|
return world.FindActorsInBox(topLeft, bottomRight).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
[LuaGlobal]
|
||||||
|
public Actor[] FindActorsInCircle(WPos location, WRange radius)
|
||||||
|
{
|
||||||
|
return world.FindActorsInCircle(location, radius).ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,48 @@ Map.GetNamedActor = function(actorName)
|
|||||||
return Internal.GetNamedActor(actorName)
|
return Internal.GetNamedActor(actorName)
|
||||||
end
|
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)
|
CPos.New = function(x, y)
|
||||||
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user