Add ActorExts.ClosestCell()

This commit is contained in:
Pavel Penev
2015-09-03 12:47:36 +03:00
parent 0ac0fed15c
commit 02be188d14

View File

@@ -118,7 +118,8 @@ namespace OpenRA.Mods.Common
NotifyBlocker(self, positions.SelectMany(p => self.World.ActorMap.GetUnitsAt(p))); 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); var resType = resLayer.GetResource(pos);
if (resType == null) if (resType == null)
@@ -138,5 +139,10 @@ namespace OpenRA.Mods.Common
return true; return true;
} }
public static CPos ClosestCell(this Actor self, IEnumerable<CPos> cells)
{
return cells.MinByOrDefault(c => (self.Location - c).LengthSquared);
}
} }
} }