Simplify shroud range checks.
This commit is contained in:
@@ -633,12 +633,12 @@ namespace OpenRA
|
|||||||
if (range >= TilesByDistance.Length)
|
if (range >= TilesByDistance.Length)
|
||||||
throw new InvalidOperationException("FindTilesInCircle supports queries for only <= {0}".F(MaxTilesInCircleRange));
|
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;
|
var t = offset + center;
|
||||||
if (Bounds.Contains(t.X, t.Y))
|
if (IsInMap(t))
|
||||||
yield return t;
|
yield return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,15 +66,12 @@ namespace OpenRA.Traits
|
|||||||
static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius)
|
static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius)
|
||||||
{
|
{
|
||||||
var r = (radius.Range + 1023) / 1024;
|
var r = (radius.Range + 1023) / 1024;
|
||||||
var min = (position - new CVec(r, r)).Clamp(world.Map.Bounds);
|
var limit = radius.Range * radius.Range;
|
||||||
var max = (position + new CVec(r, r)).Clamp(world.Map.Bounds);
|
|
||||||
|
|
||||||
var circleArea = radius.Range * radius.Range;
|
|
||||||
var pos = position.CenterPosition;
|
var pos = position.CenterPosition;
|
||||||
for (var j = min.Y; j <= max.Y; j++)
|
|
||||||
for (var i = min.X; i <= max.X; i++)
|
foreach (var cell in world.Map.FindTilesInCircle(position, r))
|
||||||
if (circleArea >= (new CPos(i, j).CenterPosition - pos).LengthSquared)
|
if ((cell.CenterPosition - pos).HorizontalLengthSquared <= limit)
|
||||||
yield return new CPos(i, j);
|
yield return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddVisibility(Actor a)
|
void AddVisibility(Actor a)
|
||||||
|
|||||||
Reference in New Issue
Block a user