Simplify shroud range checks.

This commit is contained in:
Paul Chote
2014-06-20 15:45:36 +12:00
parent 2a466d08c3
commit fd4d3b40d0
2 changed files with 8 additions and 11 deletions

View File

@@ -633,12 +633,12 @@ namespace OpenRA
if (range >= TilesByDistance.Length)
throw new InvalidOperationException("FindTilesInCircle supports queries for only <= {0}".F(MaxTilesInCircleRange));
for(var i = 0; i <= range; i++)
for (var i = 0; i <= range; i++)
{
foreach(var offset in TilesByDistance[i])
foreach (var offset in TilesByDistance[i])
{
var t = offset + center;
if (Bounds.Contains(t.X, t.Y))
if (IsInMap(t))
yield return t;
}
}

View File

@@ -66,15 +66,12 @@ namespace OpenRA.Traits
static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius)
{
var r = (radius.Range + 1023) / 1024;
var min = (position - new CVec(r, r)).Clamp(world.Map.Bounds);
var max = (position + new CVec(r, r)).Clamp(world.Map.Bounds);
var circleArea = radius.Range * radius.Range;
var limit = radius.Range * radius.Range;
var pos = position.CenterPosition;
for (var j = min.Y; j <= max.Y; j++)
for (var i = min.X; i <= max.X; i++)
if (circleArea >= (new CPos(i, j).CenterPosition - pos).LengthSquared)
yield return new CPos(i, j);
foreach (var cell in world.Map.FindTilesInCircle(position, r))
if ((cell.CenterPosition - pos).HorizontalLengthSquared <= limit)
yield return cell;
}
void AddVisibility(Actor a)