Merge pull request #10917 from abcdefg30/luaClosedCell
Add a ClosestEdgeCell and a ClosestMatchingEdgeCell function to lua
This commit is contained in:
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[ScriptGlobal("Map")]
|
||||
public class MapGlobal : ScriptGlobal
|
||||
{
|
||||
SpawnMapActors sma;
|
||||
readonly SpawnMapActors sma;
|
||||
public MapGlobal(ScriptContext context)
|
||||
: base(context)
|
||||
{
|
||||
@@ -78,6 +78,19 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
return Context.World.Map.ChooseRandomEdgeCell(Context.World.SharedRandom);
|
||||
}
|
||||
|
||||
[Desc("Returns the closest cell on the visible border of the map from the given cell.")]
|
||||
public CPos ClosestEdgeCell(CPos givenCell)
|
||||
{
|
||||
return Context.World.Map.ChooseClosestEdgeCell(givenCell);
|
||||
}
|
||||
|
||||
[Desc("Returns the first cell on the visible border of the map from the given cell,",
|
||||
"matching the filter function called as function(CPos cell).")]
|
||||
public CPos ClosestMatchingEdgeCell(CPos givenCell, LuaFunction filter)
|
||||
{
|
||||
return FilteredObjects(Context.World.Map.AllEdgeCells.OrderBy(c => (givenCell - c).Length), filter).FirstOrDefault();
|
||||
}
|
||||
|
||||
[Desc("Returns the center of a cell in world coordinates.")]
|
||||
public WPos CenterOfCell(CPos cell)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user