Make AffectsShroud and derivatives upgradable
This commit is contained in:
@@ -14,30 +14,29 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public abstract class AffectsShroudInfo : ITraitInfo
|
||||
public abstract class AffectsShroudInfo : UpgradableTraitInfo
|
||||
{
|
||||
public readonly WDist Range = WDist.Zero;
|
||||
|
||||
[Desc("Possible values are CenterPosition (measure range from the center) and ",
|
||||
"Footprint (measure range from the footprint)")]
|
||||
public readonly VisibilityType Type = VisibilityType.Footprint;
|
||||
|
||||
public abstract object Create(ActorInitializer init);
|
||||
}
|
||||
|
||||
public abstract class AffectsShroud : ITick, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
public abstract class AffectsShroud : UpgradableTrait<AffectsShroudInfo>, ITick, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
{
|
||||
static readonly PPos[] NoCells = { };
|
||||
|
||||
readonly AffectsShroudInfo info;
|
||||
[Sync] CPos cachedLocation;
|
||||
[Sync] bool cachedDisabled;
|
||||
[Sync] bool cachedTraitDisabled;
|
||||
|
||||
protected abstract void AddCellsToPlayerShroud(Actor self, Player player, PPos[] uv);
|
||||
protected abstract void RemoveCellsFromPlayerShroud(Actor self, Player player);
|
||||
protected virtual bool IsDisabled(Actor self) { return false; }
|
||||
|
||||
public AffectsShroud(Actor self, AffectsShroudInfo info) { this.info = info; }
|
||||
public AffectsShroud(Actor self, AffectsShroudInfo info)
|
||||
: base(info) { }
|
||||
|
||||
PPos[] ProjectedCells(Actor self)
|
||||
{
|
||||
@@ -46,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (range == WDist.Zero)
|
||||
return NoCells;
|
||||
|
||||
if (info.Type == VisibilityType.Footprint)
|
||||
if (Info.Type == VisibilityType.Footprint)
|
||||
return self.OccupiesSpace.OccupiedCells()
|
||||
.SelectMany(kv => Shroud.ProjectedCellsInRange(map, kv.First, range))
|
||||
.Distinct().ToArray();
|
||||
@@ -64,12 +63,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var projectedPos = centerPosition - new WVec(0, centerPosition.Z, centerPosition.Z);
|
||||
var projectedLocation = self.World.Map.CellContaining(projectedPos);
|
||||
var disabled = IsDisabled(self);
|
||||
var traitDisabled = IsTraitDisabled;
|
||||
|
||||
if (cachedLocation == projectedLocation && cachedDisabled == disabled)
|
||||
if (cachedLocation == projectedLocation && traitDisabled == cachedTraitDisabled && cachedDisabled == disabled)
|
||||
return;
|
||||
|
||||
cachedLocation = projectedLocation;
|
||||
cachedDisabled = disabled;
|
||||
cachedTraitDisabled = traitDisabled;
|
||||
|
||||
var cells = ProjectedCells(self);
|
||||
foreach (var p in self.World.Players)
|
||||
@@ -85,7 +86,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var projectedPos = centerPosition - new WVec(0, centerPosition.Z, centerPosition.Z);
|
||||
cachedLocation = self.World.Map.CellContaining(projectedPos);
|
||||
cachedDisabled = IsDisabled(self);
|
||||
cachedTraitDisabled = IsTraitDisabled;
|
||||
var cells = ProjectedCells(self);
|
||||
|
||||
foreach (var p in self.World.Players)
|
||||
AddCellsToPlayerShroud(self, p, cells);
|
||||
}
|
||||
@@ -96,6 +99,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
RemoveCellsFromPlayerShroud(self, p);
|
||||
}
|
||||
|
||||
public WDist Range { get { return cachedDisabled ? WDist.Zero : info.Range; } }
|
||||
public WDist Range { get { return (cachedDisabled || cachedTraitDisabled) ? WDist.Zero : Info.Range; } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user