Recalculate visibility during moves too.

This commit is contained in:
Paul Chote
2019-08-17 10:51:13 +01:00
committed by abcdefg30
parent 76d1447a91
commit d5f42c0628

View File

@@ -22,6 +22,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("If >= 0, prevent cells that are this much higher than the actor from being revealed.")]
public readonly int MaxHeightDelta = -1;
[Desc("If > 0, force visibility to be recalculated if the unit moves within a cell by more than this distance.")]
public readonly WDist MoveRecalculationThreshold = new WDist(256);
[Desc("Possible values are CenterPosition (measure range from the center) and ",
"Footprint (measure range from the footprint)")]
public readonly VisibilityType Type = VisibilityType.Footprint;
@@ -43,6 +46,7 @@ namespace OpenRA.Mods.Common.Traits
protected bool CachedTraitDisabled { get; private set; }
bool dirty;
WPos cachedPos;
protected abstract void AddCellsToPlayerShroud(Actor self, Player player, PPos[] uv);
protected abstract void RemoveCellsFromPlayerShroud(Actor self, Player player);
@@ -89,6 +93,10 @@ namespace OpenRA.Mods.Common.Traits
var projectedLocation = self.World.Map.CellContaining(projectedPos);
var traitDisabled = IsTraitDisabled;
var range = Range;
var pos = self.CenterPosition;
if (Info.MoveRecalculationThreshold.Length > 0 && (pos - cachedPos).LengthSquared > Info.MoveRecalculationThreshold.LengthSquared)
dirty = true;
if (!dirty && cachedLocation == projectedLocation && cachedRange == range && traitDisabled == CachedTraitDisabled)
return;
@@ -96,6 +104,7 @@ namespace OpenRA.Mods.Common.Traits
cachedRange = range;
cachedLocation = projectedLocation;
CachedTraitDisabled = traitDisabled;
cachedPos = pos;
dirty = false;
var cells = ProjectedCells(self);