Skip to content

Commit

Permalink
Tweak visibility; hopefully allows targeting of detected units
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Aug 14, 2010
1 parent 7f19188 commit 230d59f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Game/Graphics/Minimap.cs
Expand Up @@ -122,7 +122,7 @@ public static Bitmap ActorsBitmap(World world)

foreach (var t in world.Queries.WithTraitMultiple<IRadarSignature>())
{
if (!t.Actor.IsVisible())
if (!t.Actor.IsVisible(world.LocalPlayer))
continue;

var color = t.Trait.RadarSignatureColor(t.Actor);
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Traits/TraitsInterfaces.cs
Expand Up @@ -58,7 +58,7 @@ public interface IRadarSignature
Color RadarSignatureColor(Actor self);
}

public interface IVisibilityModifier { bool IsVisible(Actor self); }
public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); }
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IOccupySpace
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs
Expand Up @@ -174,7 +174,7 @@ public void GotoNextBase()
IEnumerable<Actor> SelectActorsInBox(World world, float2 a, float2 b)
{
return world.FindUnits(a, b)
.Where( x => x.HasTrait<Selectable>() && x.IsVisible() )
.Where( x => x.HasTrait<Selectable>() && x.IsVisible(world.LocalPlayer) )
.GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().Priority : 0)
.OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() )
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Widgets/WorldTooltipWidget.cs
Expand Up @@ -44,7 +44,7 @@ public override void DrawInner(World world)
}

var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault();
if (actor == null || !actor.IsVisible())
if (actor == null || !actor.IsVisible(world.LocalPlayer))
return;

var text = actor.Info.Traits.Contains<ValuedInfo>()
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Game/WorldUtils.cs
Expand Up @@ -40,7 +40,7 @@ public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Ac
public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation)
{
var loc = mouseLocation + Game.viewport.Location;
return FindUnits(world, loc, loc).Where(a => a.IsVisible());
return FindUnits(world, loc, loc).Where(a => a.IsVisible(world.LocalPlayer));
}

public static IEnumerable<Actor> FindUnits(this World world, float2 a, float2 b)
Expand Down Expand Up @@ -101,7 +101,7 @@ public static bool CanPlaceBuilding(this World world, string name, BuildingInfo
world.IsCellBuildable(t, building.WaterBound, toIgnore));
}

public static bool IsVisible(this Actor a) /* must never be relied on in synced code! */
public static bool IsVisible(this Actor a, Player byPlayer) /* must never be relied on in synced code! */
{
if (a.World.LocalPlayer != null && a.World.LocalPlayer.Shroud.Disabled)
return true;
Expand All @@ -110,7 +110,7 @@ public static bool CanPlaceBuilding(this World world, string name, BuildingInfo
if (!Shroud.GetVisOrigins(a).Any(o => a.World.Map.IsInMap(o) && shroud.exploredCells[o.X, o.Y])) // covered by shroud
return false;

if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a)))
if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a, byPlayer)))
return false;

return true;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.RA/InvisibleToOthers.cs
Expand Up @@ -18,9 +18,9 @@ class InvisibleToOthersInfo : TraitInfo<InvisibleToOthers> { }

class InvisibleToOthers : IRenderModifier, IVisibilityModifier, IRadarColorModifier
{
public bool IsVisible(Actor self)
public bool IsVisible(Actor self, Player byPlayer)
{
return self.Owner == self.World.LocalPlayer;
return self.Owner == byPlayer;
}

public Color RadarColorOverride(Actor self)
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs
Expand Up @@ -29,17 +29,17 @@ public FrozenUnderFog(Actor self)
shroud = self.World.WorldActor.Trait<Shroud>();
}

public bool IsVisible(Actor self)
public bool IsVisible(Actor self, Player byPlayer)
{
return self.World.LocalPlayer == null
|| self.Owner == self.World.LocalPlayer
|| self.Owner == byPlayer
|| self.World.LocalPlayer.Shroud.Disabled
|| Shroud.GetVisOrigins(self).Any(o => self.World.Map.IsInMap(o) && shroud.visibleCells[o.X, o.Y] != 0);
}

public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
if (IsVisible(self))
if (IsVisible(self, self.World.LocalPlayer))
cache = r.ToArray();

return cache;
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs
Expand Up @@ -27,18 +27,18 @@ public HiddenUnderFog(Actor self)
shroud = self.World.WorldActor.Trait<Shroud>();
}

public bool IsVisible(Actor self)
public bool IsVisible(Actor self, Player byPlayer)
{
return self.World.LocalPlayer == null
|| self.Owner == self.World.LocalPlayer
|| self.Owner == byPlayer
|| self.World.LocalPlayer.Shroud.Disabled
|| shroud.visibleCells[self.Location.X, self.Location.Y] > 0;
}

static Renderable[] Nothing = { };
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
return IsVisible(self) ? r : Nothing;
return IsVisible(self, self.World.LocalPlayer) ? r : Nothing;
}
}
}

0 comments on commit 230d59f

Please sign in to comment.