diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index a2785ed52c..d1eff1f7c8 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -162,16 +162,6 @@ namespace OpenRA return p == null || Stances[p] == Stance.Ally || (p.Spectating && !NonCombatant); } - public bool CanViewActor(Actor a) - { - return a.CanBeViewedByPlayer(this); - } - - public bool CanTargetActor(Actor a) - { - return CanViewActor(a); - } - public Color PlayerStanceColor(Actor a) { var player = a.World.RenderPlayer ?? a.World.LocalPlayer; diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 8127fe9ddb..8fb37a88ef 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -77,7 +77,7 @@ namespace OpenRA set { renderPlayer = value; } } - public bool FogObscures(Actor a) { return RenderPlayer != null && !RenderPlayer.CanViewActor(a); } + public bool FogObscures(Actor a) { return RenderPlayer != null && !a.CanBeViewedByPlayer(RenderPlayer); } public bool FogObscures(CPos p) { return RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(p); } public bool FogObscures(WPos pos) { return RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(pos); } public bool ShroudObscures(CPos p) { return RenderPlayer != null && !RenderPlayer.Shroud.IsExplored(p); } diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs index f3da501a94..b5da0eff0a 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs @@ -157,7 +157,7 @@ namespace OpenRA.Mods.Cnc.Traits var targetUnits = power.UnitsInRange(xy).Where(a => !world.FogObscures(a)); foreach (var unit in targetUnits) - if (manager.Self.Owner.CanTargetActor(unit)) + if (unit.CanBeViewedByPlayer(manager.Self.Owner)) yield return new SelectionBoxRenderable(unit, Color.Red); } @@ -250,7 +250,7 @@ namespace OpenRA.Mods.Cnc.Traits // Unit previews foreach (var unit in power.UnitsInRange(sourceLocation)) { - if (manager.Self.Owner.CanTargetActor(unit)) + if (unit.CanBeViewedByPlayer(manager.Self.Owner)) { var targetCell = unit.Location + (xy - sourceLocation); var canEnter = manager.Self.Owner.Shroud.IsExplored(targetCell) && @@ -260,13 +260,13 @@ namespace OpenRA.Mods.Cnc.Traits } var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation); - if (manager.Self.Owner.CanTargetActor(unit)) + if (unit.CanBeViewedByPlayer(manager.Self.Owner)) foreach (var r in unit.Render(wr)) yield return r.OffsetBy(offset); } foreach (var unit in power.UnitsInRange(sourceLocation)) - if (manager.Self.Owner.CanTargetActor(unit)) + if (unit.CanBeViewedByPlayer(manager.Self.Owner)) yield return new SelectionBoxRenderable(unit, Color.Red); } diff --git a/OpenRA.Mods.Common/AI/Squad.cs b/OpenRA.Mods.Common/AI/Squad.cs index ab7cc27195..c2c8548146 100644 --- a/OpenRA.Mods.Common/AI/Squad.cs +++ b/OpenRA.Mods.Common/AI/Squad.cs @@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.AI public bool IsTargetVisible { - get { return Bot.Player.PlayerActor.Owner.CanTargetActor(TargetActor); } + get { return TargetActor.CanBeViewedByPlayer(Bot.Player); } } public WPos CenterPosition { get { return Units.Select(u => u.CenterPosition).Average(); } } diff --git a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs index ef10750f20..74fc690899 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Activities var pos = self.CenterPosition; var targetPos = attackHeli.GetTargetPosition(pos, target); if (attackOnlyVisibleTargets && target.Type == TargetType.Actor && canHideUnderFog - && !self.Owner.CanTargetActor(target.Actor)) + && !target.Actor.CanBeViewedByPlayer(self.Owner)) { var newTarget = Target.FromCell(self.World, self.World.Map.CellContaining(targetPos)); diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index 07f444c676..f73f37b4b8 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -90,7 +90,9 @@ namespace OpenRA.Mods.Common.Activities // HACK: This would otherwise break targeting frozen actors // The problem is that Shroud.IsTargetable returns false (as it should) for // frozen actors, but we do want to explicitly target the underlying actor here. - if (!attack.Info.IgnoresVisibility && type == TargetType.Actor && !Target.Actor.Info.HasTraitInfo() && !self.Owner.CanTargetActor(Target.Actor)) + if (!attack.Info.IgnoresVisibility && type == TargetType.Actor + && !Target.Actor.Info.HasTraitInfo() + && !Target.Actor.CanBeViewedByPlayer(self.Owner)) return NextActivity; // Drop the target once none of the weapons are effective against it diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs index 3c6028119f..dd980004cf 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs @@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Activities // Target moved under the fog. Move to its last known position. if (Target.Type == TargetType.Actor && canHideUnderFog - && !self.Owner.CanTargetActor(Target.Actor)) + && !Target.Actor.CanBeViewedByPlayer(self.Owner)) { if (inner != null) inner.Cancel(self); diff --git a/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs index cf344d561c..b05f8fb51e 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Scripting if (!target.IsValidFor(Self)) Log.Write("lua", "{1} is an invalid target for {0}!", Self, targetActor); - if (!targetActor.Info.HasTraitInfo() && !Self.Owner.CanTargetActor(targetActor)) + if (!targetActor.Info.HasTraitInfo() && !targetActor.CanBeViewedByPlayer(Self.Owner)) Log.Write("lua", "{1} is not revealed for player {0}!", Self.Owner, targetActor); attackBase.AttackTarget(target, true, allowMove, forceAttack); diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 602a98e0b1..f5ed013e3c 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -300,7 +300,7 @@ namespace OpenRA.Mods.Common.Traits return true; }).ToList(); - if (!validPriorities.Any() || PreventsAutoTarget(self, actor) || !self.Owner.CanTargetActor(actor)) + if (!validPriorities.Any() || PreventsAutoTarget(self, actor) || !actor.CanBeViewedByPlayer(self.Owner)) continue; // Make sure that we can actually fire on the actor diff --git a/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs b/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs index d9afd6b88d..ea3a2c1540 100644 --- a/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs +++ b/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits continue; // The actor is not currently visible - if (!self.Owner.CanViewActor(actor.Actor)) + if (!actor.Actor.CanBeViewedByPlayer(self.Owner)) continue; visibleActorIds.Add(actor.Actor.ActorID);