Tweak FrozenActorLayer queries:

- FrozenActorsInRegion now filters for valid and (optionally) visible FAs
- Add new FrozenActorsInCircle to mirror World.FindActorsInCircle.

The first change means that SupportPowerDecision now correctly ignores
FrozenActors that the AI has not discovered.
This commit is contained in:
Paul Chote
2018-11-28 21:00:11 +00:00
committed by Oliver Brakmann
parent 3e490e5843
commit 8eeb6d68e7
2 changed files with 20 additions and 4 deletions

View File

@@ -323,11 +323,28 @@ namespace OpenRA.Traits
return fa;
}
public IEnumerable<FrozenActor> FrozenActorsInRegion(CellRegion region)
public IEnumerable<FrozenActor> FrozenActorsInRegion(CellRegion region, bool onlyVisible = true)
{
var tl = region.TopLeft;
var br = region.BottomRight;
return partitionedFrozenActorIds.InBox(Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y)).Select(FromID);
return partitionedFrozenActorIds.InBox(Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y))
.Select(FromID)
.Where(fa => fa.IsValid && (!onlyVisible || fa.Visible));
}
public IEnumerable<FrozenActor> FrozenActorsInCircle(World world, WPos origin, WDist r, bool onlyVisible = true)
{
var centerCell = world.Map.CellContaining(origin);
var cellRange = (r.Length + 1023) / 1024;
var tl = centerCell - new CVec(cellRange, cellRange);
var br = centerCell + new CVec(cellRange, cellRange);
// Target ranges are calculated in 2D, so ignore height differences
return partitionedFrozenActorIds.InBox(Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y))
.Select(FromID)
.Where(fa => fa.IsValid &&
(!onlyVisible || fa.Visible) &&
(fa.CenterPosition - origin).HorizontalLengthSquared <= r.LengthSquared);
}
}
}

View File

@@ -81,7 +81,6 @@ namespace OpenRA.Mods.Common.Traits
// IsValid check filters out Frozen Actors that have not initizialized their Owner
foreach (var scrutinized in checkFrozen)
if (scrutinized.IsValid)
answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy);
}