Tweak shroud revealing logic

The per-actor visibility now tracks all cells
inside the map area (including those outside the
currently visible bounds), but the shroud/fog is
only cleared if the cell is inside the currently
visible bounds.
This commit is contained in:
Paul Chote
2015-06-11 22:00:49 +01:00
parent 6e052d19d9
commit da3abb4e2e
2 changed files with 19 additions and 6 deletions

View File

@@ -870,7 +870,7 @@ namespace OpenRA
// it rounds the actual distance up to the next integer so that this call
// will return any cells that intersect with the requested range circle.
// The returned positions are sorted by distance from the center.
public IEnumerable<CPos> FindTilesInAnnulus(CPos center, int minRange, int maxRange)
public IEnumerable<CPos> FindTilesInAnnulus(CPos center, int minRange, int maxRange, bool allowOutsideBounds = false)
{
if (maxRange < minRange)
throw new ArgumentOutOfRangeException("maxRange", "Maximum range is less than the minimum range.");
@@ -878,20 +878,24 @@ namespace OpenRA
if (maxRange > TilesByDistance.Length)
throw new ArgumentOutOfRangeException("maxRange", "The requested range ({0}) exceeds the maximum allowed ({1})".F(maxRange, MaxTilesInCircleRange));
Func<CPos, bool> valid = Contains;
if (allowOutsideBounds)
valid = MapTiles.Value.Contains;
for (var i = minRange; i <= maxRange; i++)
{
foreach (var offset in TilesByDistance[i])
{
var t = offset + center;
if (Contains(t))
if (valid(t))
yield return t;
}
}
}
public IEnumerable<CPos> FindTilesInCircle(CPos center, int maxRange)
public IEnumerable<CPos> FindTilesInCircle(CPos center, int maxRange, bool allowOutsideBounds = false)
{
return FindTilesInAnnulus(center, 0, maxRange);
return FindTilesInAnnulus(center, 0, maxRange, allowOutsideBounds);
}
}
}

View File

@@ -112,7 +112,7 @@ namespace OpenRA.Traits
var limit = radius.RangeSquared;
var pos = map.CenterOfCell(position);
foreach (var cell in map.FindTilesInCircle(position, r))
foreach (var cell in map.FindTilesInCircle(position, r, true))
if ((map.CenterOfCell(cell) - pos).HorizontalLengthSquared <= limit)
yield return cell;
}
@@ -129,6 +129,11 @@ namespace OpenRA.Traits
foreach (var c in visible)
{
var uv = c.ToMPos(map);
// Force cells outside the visible bounds invisible
if (!map.Contains(uv))
continue;
visibleCount[uv]++;
explored[uv] = true;
}
@@ -147,7 +152,11 @@ namespace OpenRA.Traits
return;
foreach (var c in visible)
visibleCount[c.ToMPos(map)]--;
{
// Cells outside the visible bounds don't increment visibleCount
if (map.Contains(c))
visibleCount[c.ToMPos(map)]--;
}
visibility.Remove(a);
Invalidate(visible);