From 02be188d14d409daf2fc9956fe452599e17daaf6 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Thu, 3 Sep 2015 12:47:36 +0300 Subject: [PATCH] Add ActorExts.ClosestCell() --- OpenRA.Mods.Common/ActorExts.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/ActorExts.cs b/OpenRA.Mods.Common/ActorExts.cs index 3d3633758c..651a2ba6f3 100644 --- a/OpenRA.Mods.Common/ActorExts.cs +++ b/OpenRA.Mods.Common/ActorExts.cs @@ -118,7 +118,8 @@ namespace OpenRA.Mods.Common NotifyBlocker(self, positions.SelectMany(p => self.World.ActorMap.GetUnitsAt(p))); } - public static bool CanHarvestAt(this Actor self, CPos pos, ResourceLayer resLayer, HarvesterInfo harvInfo, ResourceClaimLayer territory) + public static bool CanHarvestAt(this Actor self, CPos pos, ResourceLayer resLayer, HarvesterInfo harvInfo, + ResourceClaimLayer territory) { var resType = resLayer.GetResource(pos); if (resType == null) @@ -138,5 +139,10 @@ namespace OpenRA.Mods.Common return true; } + + public static CPos ClosestCell(this Actor self, IEnumerable cells) + { + return cells.MinByOrDefault(c => (self.Location - c).LengthSquared); + } } }