From 20c4d3ef6148c4e1c357bfce16b4afb00bfec703 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 30 Mar 2010 19:07:12 +1300 Subject: [PATCH] #37 enemy actors can be selected under shroud --- OpenRA.Game/Traits/World/Shroud.cs | 2 +- OpenRA.Game/WorldUtils.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 8cdb4c9b36..8d670afb13 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -84,7 +84,7 @@ namespace OpenRA.Traits Dirty(); } - static IEnumerable GetVisOrigins(Actor a) + public static IEnumerable GetVisOrigins(Actor a) { if (a.Info.Traits.Contains()) { diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 8be9c2d19f..c80efb66a3 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -117,7 +117,7 @@ namespace OpenRA public static IEnumerable SelectActorsInBox(this World world, float2 a, float2 b) { return world.FindUnits(a, b) - .Where( x => x.traits.Contains() ) + .Where( x => x.traits.Contains() && x.IsVisible() ) .GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get().Priority : 0) .OrderByDescending(g => g.Key) .Select( g => g.AsEnumerable() ) @@ -138,6 +138,14 @@ namespace OpenRA building.WaterBound, toIgnore)); } + public static bool IsVisible(this Actor a) + { + var shroud = a.World.WorldActor.traits.Get(); + return a.traits.Contains() + ? Shroud.GetVisOrigins(a).Any(o => shroud.visibleCells[o.X, o.Y] > 0) + : Shroud.GetVisOrigins(a).Any(o => shroud.exploredCells[o.X, o.Y]); + } + public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft) { var buildingMaxBounds = bi.Dimensions;