Introduce IDefaultVisibility.
This commit is contained in:
@@ -17,17 +17,21 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("This actor will remain visible (but not updated visually) under fog, once discovered.")]
|
||||
public class FrozenUnderFogInfo : ITraitInfo, Requires<BuildingInfo>
|
||||
public class FrozenUnderFogInfo : ITraitInfo, Requires<BuildingInfo>, IDefaultVisibilityInfo
|
||||
{
|
||||
public readonly bool StartsRevealed = false;
|
||||
|
||||
[Desc("Players with these stances can always see the actor.")]
|
||||
public readonly Stance AlwaysVisibleStances = Stance.Ally;
|
||||
|
||||
public object Create(ActorInitializer init) { return new FrozenUnderFog(init, this); }
|
||||
}
|
||||
|
||||
public class FrozenUnderFog : IRenderModifier, IVisibilityModifier, ITick, ISync
|
||||
public class FrozenUnderFog : IRenderModifier, IDefaultVisibility, ITick, ISync
|
||||
{
|
||||
[Sync] public int VisibilityHash;
|
||||
|
||||
readonly FrozenUnderFogInfo info;
|
||||
readonly bool startsRevealed;
|
||||
readonly MPos[] footprint;
|
||||
|
||||
@@ -41,6 +45,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
// Spawned actors (e.g. building husks) shouldn't be revealed
|
||||
startsRevealed = info.StartsRevealed && !init.Contains<ParentActorInit>();
|
||||
var footprintCells = FootprintUtils.Tiles(init.Self).ToList();
|
||||
@@ -54,7 +60,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool IsVisible(Actor self, Player byPlayer)
|
||||
{
|
||||
return byPlayer == null || visible[byPlayer];
|
||||
if (byPlayer == null)
|
||||
return true;
|
||||
|
||||
var stance = self.Owner.Stances[byPlayer];
|
||||
return info.AlwaysVisibleStances.HasFlag(stance) || visible[byPlayer];
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
Reference in New Issue
Block a user