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 // 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. // will return any cells that intersect with the requested range circle.
// The returned positions are sorted by distance from the center. // 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) if (maxRange < minRange)
throw new ArgumentOutOfRangeException("maxRange", "Maximum range is less than the minimum range."); throw new ArgumentOutOfRangeException("maxRange", "Maximum range is less than the minimum range.");
@@ -878,20 +878,24 @@ namespace OpenRA
if (maxRange > TilesByDistance.Length) if (maxRange > TilesByDistance.Length)
throw new ArgumentOutOfRangeException("maxRange", "The requested range ({0}) exceeds the maximum allowed ({1})".F(maxRange, MaxTilesInCircleRange)); 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++) for (var i = minRange; i <= maxRange; i++)
{ {
foreach (var offset in TilesByDistance[i]) foreach (var offset in TilesByDistance[i])
{ {
var t = offset + center; var t = offset + center;
if (Contains(t)) if (valid(t))
yield return 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 limit = radius.RangeSquared;
var pos = map.CenterOfCell(position); 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) if ((map.CenterOfCell(cell) - pos).HorizontalLengthSquared <= limit)
yield return cell; yield return cell;
} }
@@ -129,6 +129,11 @@ namespace OpenRA.Traits
foreach (var c in visible) foreach (var c in visible)
{ {
var uv = c.ToMPos(map); var uv = c.ToMPos(map);
// Force cells outside the visible bounds invisible
if (!map.Contains(uv))
continue;
visibleCount[uv]++; visibleCount[uv]++;
explored[uv] = true; explored[uv] = true;
} }
@@ -147,7 +152,11 @@ namespace OpenRA.Traits
return; return;
foreach (var c in visible) foreach (var c in visible)
{
// Cells outside the visible bounds don't increment visibleCount
if (map.Contains(c))
visibleCount[c.ToMPos(map)]--; visibleCount[c.ToMPos(map)]--;
}
visibility.Remove(a); visibility.Remove(a);
Invalidate(visible); Invalidate(visible);