Remove IFogVisibilityModifier.

This commit is contained in:
Paul Chote
2017-10-05 17:54:14 +01:00
committed by reaperrr
parent 4dba9f5b88
commit 47634b25f9
6 changed files with 14 additions and 43 deletions

View File

@@ -61,7 +61,6 @@ namespace OpenRA
public Shroud Shroud; public Shroud Shroud;
public World World { get; private set; } public World World { get; private set; }
readonly IFogVisibilityModifier[] fogVisibilities;
readonly StanceColors stanceColors; readonly StanceColors stanceColors;
static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true) static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
@@ -134,8 +133,6 @@ namespace OpenRA
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
Shroud = PlayerActor.Trait<Shroud>(); Shroud = PlayerActor.Trait<Shroud>();
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray();
// Enable the bot logic on the host // Enable the bot logic on the host
IsBot = BotType != null; IsBot = BotType != null;
if (IsBot && Game.IsHost) if (IsBot && Game.IsHost)
@@ -172,28 +169,9 @@ namespace OpenRA
public bool CanTargetActor(Actor a) public bool CanTargetActor(Actor a)
{ {
// PERF: Avoid LINQ.
if (HasFogVisibility)
foreach (var fogVisibility in fogVisibilities)
if (fogVisibility.IsVisible(a))
return true;
return CanViewActor(a); return CanViewActor(a);
} }
public bool HasFogVisibility
{
get
{
// PERF: Avoid LINQ.
foreach (var fogVisibility in fogVisibilities)
if (fogVisibility.HasFogVisibility())
return true;
return false;
}
}
public Color PlayerStanceColor(Actor a) public Color PlayerStanceColor(Actor a)
{ {
var player = a.World.RenderPlayer ?? a.World.LocalPlayer; var player = a.World.RenderPlayer ?? a.World.LocalPlayer;

View File

@@ -190,12 +190,6 @@ namespace OpenRA.Traits
public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); } public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); }
public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); } public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); }
public interface IFogVisibilityModifier
{
bool IsVisible(Actor actor);
bool HasFogVisibility();
}
public interface IOccupySpaceInfo : ITraitInfoInterface public interface IOccupySpaceInfo : ITraitInfoInterface
{ {
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any);

View File

@@ -11,8 +11,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Effects;
using OpenRA.Mods.Cnc.Effects;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
@@ -26,7 +24,7 @@ namespace OpenRA.Mods.Cnc.Traits
interface IOnGpsRefreshed { void OnGpsRefresh(Actor self, Player player); } interface IOnGpsRefreshed { void OnGpsRefresh(Actor self, Player player); }
class GpsWatcher : ISync, IFogVisibilityModifier class GpsWatcher : ISync, IPreventsShroudReset
{ {
[Sync] public bool Launched { get; private set; } [Sync] public bool Launched { get; private set; }
[Sync] public bool GrantedAllies { get; private set; } [Sync] public bool GrantedAllies { get; private set; }
@@ -92,20 +90,11 @@ namespace OpenRA.Mods.Cnc.Traits
tp.Trait.OnGpsRefresh(tp.Actor, owner); tp.Trait.OnGpsRefresh(tp.Actor, owner);
} }
public bool HasFogVisibility() bool IPreventsShroudReset.PreventShroudReset(Actor self)
{ {
return Granted || GrantedAllies; return Granted || GrantedAllies;
} }
public bool IsVisible(Actor actor)
{
var gpsDot = actor.TraitOrDefault<GpsDot>();
if (gpsDot == null)
return false;
return gpsDot.IsDotVisible(owner);
}
public void RegisterForOnGpsRefreshed(Actor actor, IOnGpsRefreshed toBeNotified) public void RegisterForOnGpsRefreshed(Actor actor, IOnGpsRefreshed toBeNotified)
{ {
notifyOnRefresh.Add(new TraitPair<IOnGpsRefreshed>(actor, toBeNotified)); notifyOnRefresh.Add(new TraitPair<IOnGpsRefreshed>(actor, toBeNotified));

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
@@ -22,7 +23,9 @@ namespace OpenRA.Mods.Cnc.Traits
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud); infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);
if (!self.Owner.HasFogVisibility) var preventReset = self.Owner.PlayerActor.TraitsImplementing<IPreventsShroudReset>()
.Any(p => p.PreventShroudReset(self));
if (!preventReset)
self.Owner.Shroud.ResetExploration(); self.Owner.Shroud.ResetExploration();
} }
} }

View File

@@ -9,6 +9,8 @@
*/ */
#endregion #endregion
using System.Linq;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Hides the entire map in shroud.")] [Desc("Hides the entire map in shroud.")]
@@ -33,7 +35,9 @@ namespace OpenRA.Mods.Common.Traits
public override int GetSelectionShares(Actor collector) public override int GetSelectionShares(Actor collector)
{ {
// Don't hide the map if the shroud is force-revealed // Don't hide the map if the shroud is force-revealed
if (collector.Owner.HasFogVisibility || collector.Owner.Shroud.ExploreMapEnabled) var preventReset = collector.Owner.PlayerActor.TraitsImplementing<IPreventsShroudReset>()
.Any(p => p.PreventShroudReset(collector.Owner.PlayerActor));
if (preventReset || collector.Owner.Shroud.ExploreMapEnabled)
return 0; return 0;
return base.GetSelectionShares(collector); return base.GetSelectionShares(collector);

View File

@@ -382,4 +382,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
IEnumerable<Pair<CPos, SubCell>> TargetableCells(); IEnumerable<Pair<CPos, SubCell>> TargetableCells();
} }
[RequireExplicitImplementation]
public interface IPreventsShroudReset { bool PreventShroudReset(Actor self); }
} }