From d907296f4e2b9c8cc729fba8b426cc53b7568bcd Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 12 Mar 2016 21:18:48 +0100 Subject: [PATCH 1/2] Make the SpawnMapActors field in MapGlobal.cs readonly --- OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs index 7f6c4fa2ca..0a90f3c191 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs @@ -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) { From cec2821f130be26651432a4ec31dd54f3957f52e Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 12 Mar 2016 21:45:47 +0100 Subject: [PATCH 2/2] Add a ClosestEdgeCell and a ClosestMatchingEdgeCell function to lua --- OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs index 0a90f3c191..d01db21056 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs @@ -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) {