don't leak information about actors under fog etc

This commit is contained in:
Chris Forbes
2010-04-18 17:36:24 +12:00
parent 720f475060
commit 1f3f25de87
2 changed files with 18 additions and 11 deletions

View File

@@ -20,7 +20,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace OpenRA.Traits.Render namespace OpenRA.Traits
{ {
class HiddenUnderFogInfo : ITraitInfo class HiddenUnderFogInfo : ITraitInfo
{ {
@@ -36,13 +36,17 @@ namespace OpenRA.Traits.Render
shroud = self.World.WorldActor.traits.Get<Shroud>(); shroud = self.World.WorldActor.traits.Get<Shroud>();
} }
public bool IsVisible(Actor self)
{
return self.World.LocalPlayer == null
|| self.Owner == self.World.LocalPlayer
|| shroud.visibleCells[self.Location.X, self.Location.Y] > 0;
}
static Renderable[] Nothing = { }; static Renderable[] Nothing = { };
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
if (self.World.LocalPlayer == null || self.Owner == self.World.LocalPlayer || shroud.visibleCells[self.Location.X, self.Location.Y] > 0) return IsVisible(self) ? r : Nothing;
return r;
else
return Nothing;
} }
} }
} }

View File

@@ -81,7 +81,7 @@ namespace OpenRA
public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation) public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation)
{ {
var loc = mouseLocation + Game.viewport.Location; var loc = mouseLocation + Game.viewport.Location;
return FindUnits(world, loc, loc); return FindUnits(world, loc, loc).Where(a => a.IsVisible());
} }
public static IEnumerable<Actor> FindUnits(this World world, float2 a, float2 b) public static IEnumerable<Actor> FindUnits(this World world, float2 a, float2 b)
@@ -147,15 +147,18 @@ namespace OpenRA
public static bool IsVisible(this Actor a) public static bool IsVisible(this Actor a)
{ {
var shroud = a.World.WorldActor.traits.Get<Shroud>(); var shroud = a.World.WorldActor.traits.Get<Shroud>();
return a.traits.Contains<Unit>() if (!Shroud.GetVisOrigins(a).Any(o => shroud.exploredCells[o.X, o.Y])) // covered by shroud
? Shroud.GetVisOrigins(a).Any(o => shroud.visibleCells[o.X, o.Y] > 0) return false;
: Shroud.GetVisOrigins(a).Any(o => shroud.exploredCells[o.X, o.Y]);
var huf = a.traits.GetOrDefault<HiddenUnderFog>(); // hidden under fog
if (huf != null && !huf.IsVisible(a))
return false;
return true;
} }
public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft) public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft)
{ {
var buildingMaxBounds = bi.Dimensions; var buildingMaxBounds = bi.Dimensions;
if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() ) if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() )
buildingMaxBounds.Y += 1; buildingMaxBounds.Y += 1;