Rename ActorMap *UnitsAt* occurences to *ActorsAt*
These enumerate actors in general, not just mobile actors (which the term 'unit' usually refers to).
This commit is contained in:
@@ -119,7 +119,7 @@ namespace OpenRA.Orders
|
||||
.Select(x => new { Trait = trait, Order = x }))
|
||||
.OrderByDescending(x => x.Order.OrderPriority))
|
||||
{
|
||||
var actorsAt = self.World.ActorMap.GetUnitsAt(self.World.Map.CellContaining(target.CenterPosition)).ToList();
|
||||
var actorsAt = self.World.ActorMap.GetActorsAt(self.World.Map.CellContaining(target.CenterPosition)).ToList();
|
||||
|
||||
var modifiers = TargetModifiers.None;
|
||||
if (mi.Modifiers.HasModifier(Modifiers.Ctrl))
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Traits
|
||||
return;
|
||||
|
||||
var oldActors = currentActors;
|
||||
currentActors = Footprint.SelectMany(actorMap.GetUnitsAt).ToList();
|
||||
currentActors = Footprint.SelectMany(actorMap.GetActorsAt).ToList();
|
||||
|
||||
var entered = currentActors.Except(oldActors);
|
||||
var exited = oldActors.Except(currentActors);
|
||||
@@ -187,10 +187,10 @@ namespace OpenRA.Traits
|
||||
actorShouldBeRemoved = removeActorPosition.Contains;
|
||||
}
|
||||
|
||||
sealed class UnitsAtEnumerator : IEnumerator<Actor>
|
||||
sealed class ActorsAtEnumerator : IEnumerator<Actor>
|
||||
{
|
||||
InfluenceNode node;
|
||||
public UnitsAtEnumerator(InfluenceNode node) { this.node = node; }
|
||||
public ActorsAtEnumerator(InfluenceNode node) { this.node = node; }
|
||||
public void Reset() { throw new NotSupportedException(); }
|
||||
public Actor Current { get; private set; }
|
||||
object IEnumerator.Current { get { return Current; } }
|
||||
@@ -209,23 +209,23 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
sealed class UnitsAtEnumerable : IEnumerable<Actor>
|
||||
sealed class ActorsAtEnumerable : IEnumerable<Actor>
|
||||
{
|
||||
readonly InfluenceNode node;
|
||||
public UnitsAtEnumerable(InfluenceNode node) { this.node = node; }
|
||||
public IEnumerator<Actor> GetEnumerator() { return new UnitsAtEnumerator(node); }
|
||||
public ActorsAtEnumerable(InfluenceNode node) { this.node = node; }
|
||||
public IEnumerator<Actor> GetEnumerator() { return new ActorsAtEnumerator(node); }
|
||||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> GetUnitsAt(CPos a)
|
||||
public IEnumerable<Actor> GetActorsAt(CPos a)
|
||||
{
|
||||
var uv = a.ToMPos(map);
|
||||
if (!influence.Contains(uv))
|
||||
return Enumerable.Empty<Actor>();
|
||||
return new UnitsAtEnumerable(influence[uv]);
|
||||
return new ActorsAtEnumerable(influence[uv]);
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub)
|
||||
public IEnumerable<Actor> GetActorsAt(CPos a, SubCell sub)
|
||||
{
|
||||
var uv = a.ToMPos(map);
|
||||
if (!influence.Contains(uv))
|
||||
@@ -243,14 +243,14 @@ namespace OpenRA.Traits
|
||||
|
||||
public SubCell FreeSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, bool checkTransient = true)
|
||||
{
|
||||
if (preferredSubCell > SubCell.Any && !AnyUnitsAt(cell, preferredSubCell, checkTransient))
|
||||
if (preferredSubCell > SubCell.Any && !AnyActorsAt(cell, preferredSubCell, checkTransient))
|
||||
return preferredSubCell;
|
||||
|
||||
if (!AnyUnitsAt(cell))
|
||||
if (!AnyActorsAt(cell))
|
||||
return map.DefaultSubCell;
|
||||
|
||||
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
||||
if (i != (int)preferredSubCell && !AnyUnitsAt(cell, (SubCell)i, checkTransient))
|
||||
if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkTransient))
|
||||
return (SubCell)i;
|
||||
|
||||
return SubCell.Invalid;
|
||||
@@ -258,20 +258,20 @@ namespace OpenRA.Traits
|
||||
|
||||
public SubCell FreeSubCell(CPos cell, SubCell preferredSubCell, Func<Actor, bool> checkIfBlocker)
|
||||
{
|
||||
if (preferredSubCell > SubCell.Any && !AnyUnitsAt(cell, preferredSubCell, checkIfBlocker))
|
||||
if (preferredSubCell > SubCell.Any && !AnyActorsAt(cell, preferredSubCell, checkIfBlocker))
|
||||
return preferredSubCell;
|
||||
|
||||
if (!AnyUnitsAt(cell))
|
||||
if (!AnyActorsAt(cell))
|
||||
return map.DefaultSubCell;
|
||||
|
||||
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
||||
if (i != (int)preferredSubCell && !AnyUnitsAt(cell, (SubCell)i, checkIfBlocker))
|
||||
if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkIfBlocker))
|
||||
return (SubCell)i;
|
||||
return SubCell.Invalid;
|
||||
}
|
||||
|
||||
// NOTE: always includes transients with influence
|
||||
public bool AnyUnitsAt(CPos a)
|
||||
public bool AnyActorsAt(CPos a)
|
||||
{
|
||||
var uv = a.ToMPos(map);
|
||||
if (!influence.Contains(uv))
|
||||
@@ -281,7 +281,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
// NOTE: can not check aircraft
|
||||
public bool AnyUnitsAt(CPos a, SubCell sub, bool checkTransient = true)
|
||||
public bool AnyActorsAt(CPos a, SubCell sub, bool checkTransient = true)
|
||||
{
|
||||
var uv = a.ToMPos(map);
|
||||
if (!influence.Contains(uv))
|
||||
@@ -305,7 +305,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
// NOTE: can not check aircraft
|
||||
public bool AnyUnitsAt(CPos a, SubCell sub, Func<Actor, bool> withCondition)
|
||||
public bool AnyActorsAt(CPos a, SubCell sub, Func<Actor, bool> withCondition)
|
||||
{
|
||||
var uv = a.ToMPos(map);
|
||||
if (!influence.Contains(uv))
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
continue;
|
||||
|
||||
// HACK to check if we are on the helipad/airfield/etc.
|
||||
var hostBuilding = self.World.ActorMap.GetUnitsAt(self.Location)
|
||||
var hostBuilding = self.World.ActorMap.GetActorsAt(self.Location)
|
||||
.FirstOrDefault(a => a.Info.HasTraitInfo<BuildingInfo>());
|
||||
|
||||
if (hostBuilding == null || !hostBuilding.IsInWorld)
|
||||
|
||||
@@ -110,12 +110,12 @@ namespace OpenRA.Mods.Common
|
||||
|
||||
public static void NotifyBlocker(this Actor self, CPos position)
|
||||
{
|
||||
NotifyBlocker(self, self.World.ActorMap.GetUnitsAt(position));
|
||||
NotifyBlocker(self, self.World.ActorMap.GetActorsAt(position));
|
||||
}
|
||||
|
||||
public static void NotifyBlocker(this Actor self, IEnumerable<CPos> positions)
|
||||
{
|
||||
NotifyBlocker(self, positions.SelectMany(p => self.World.ActorMap.GetUnitsAt(p)));
|
||||
NotifyBlocker(self, positions.SelectMany(p => self.World.ActorMap.GetActorsAt(p)));
|
||||
}
|
||||
|
||||
public static bool CanHarvestAt(this Actor self, CPos pos, ResourceLayer resLayer, HarvesterInfo harvInfo,
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
var neightborTiles = Util.ExpandFootprint(allTiles, true).Except(allTiles)
|
||||
.Where(world.Map.Contains).ToList();
|
||||
|
||||
var blockers = allTiles.SelectMany(world.ActorMap.GetUnitsAt)
|
||||
var blockers = allTiles.SelectMany(world.ActorMap.GetActorsAt)
|
||||
.Where(a => a.Owner == producer.Owner && a.IsIdle)
|
||||
.Select(a => new TraitPair<Mobile> { Actor = a, Trait = a.TraitOrDefault<Mobile>() });
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.World.Map.DistanceAboveTerrain(CenterPosition).Length != 0)
|
||||
return null; // not on the ground.
|
||||
|
||||
return self.World.ActorMap.GetUnitsAt(self.Location)
|
||||
return self.World.ActorMap.GetActorsAt(self.Location)
|
||||
.FirstOrDefault(a => a.Info.HasTraitInfo<ReservableInfo>());
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!self.World.Map.Contains(cell))
|
||||
return false;
|
||||
|
||||
if (self.World.ActorMap.AnyUnitsAt(cell))
|
||||
if (self.World.ActorMap.AnyActorsAt(cell))
|
||||
return false;
|
||||
|
||||
var type = self.World.Map.GetTerrainInfo(cell).Type;
|
||||
@@ -445,7 +445,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanEnterTargetNow(Actor self, Target target)
|
||||
{
|
||||
if (target.Positions.Any(p => self.World.ActorMap.GetUnitsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != target.Actor)))
|
||||
if (target.Positions.Any(p => self.World.ActorMap.GetActorsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != target.Actor)))
|
||||
return false;
|
||||
|
||||
var res = target.Actor.TraitOrDefault<Reservable>();
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static bool AnyBlockingActorAt(World world, WPos pos)
|
||||
{
|
||||
return world.ActorMap.GetUnitsAt(world.Map.CellContaining(pos))
|
||||
return world.ActorMap.GetActorsAt(world.Map.CellContaining(pos))
|
||||
.Any(a => a.TraitsImplementing<BlocksProjectiles>().Any(Exts.IsTraitEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void KillUnitsOnBridge()
|
||||
{
|
||||
foreach (var c in footprint.Keys)
|
||||
foreach (var a in self.World.ActorMap.GetUnitsAt(c))
|
||||
foreach (var a in self.World.ActorMap.GetActorsAt(c))
|
||||
if (a.Info.HasTraitInfo<IPositionableInfo>() && !a.Trait<IPositionable>().CanEnterCell(c))
|
||||
a.Kill(self);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (buildingAtPos == null)
|
||||
{
|
||||
var unitsAtPos = world.ActorMap.GetUnitsAt(pos).Where(a => a.IsInWorld
|
||||
var unitsAtPos = world.ActorMap.GetActorsAt(pos).Where(a => a.IsInWorld
|
||||
&& (a.Owner == p || (allyBuildRadius && a.Owner.Stances[p] == Stance.Ally))
|
||||
&& a.Info.HasTraitInfo<GivesBuildableAreaInfo>());
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
|
||||
return false;
|
||||
|
||||
if (!bi.AllowInvalidPlacement && world.ActorMap.GetUnitsAt(cell).Any(a => a != toIgnore))
|
||||
if (!bi.AllowInvalidPlacement && world.ActorMap.GetActorsAt(cell).Any(a => a != toIgnore))
|
||||
return false;
|
||||
|
||||
var tile = world.Map.MapTiles.Value[cell];
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void OnLanded()
|
||||
{
|
||||
// Check whether the crate landed on anything
|
||||
var landedOn = self.World.ActorMap.GetUnitsAt(self.Location)
|
||||
var landedOn = self.World.ActorMap.GetActorsAt(self.Location)
|
||||
.Where(a => a != self);
|
||||
|
||||
if (!landedOn.Any())
|
||||
@@ -177,7 +177,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!checkTransientActors)
|
||||
return SubCell.FullCell;
|
||||
|
||||
return !self.World.ActorMap.GetUnitsAt(cell)
|
||||
return !self.World.ActorMap.GetActorsAt(cell)
|
||||
.Where(x => x != ignoreActor)
|
||||
.Any() ? SubCell.FullCell : SubCell.Invalid;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!checkTransientActors)
|
||||
return SubCell.FullCell;
|
||||
|
||||
return self.World.ActorMap.GetUnitsAt(cell)
|
||||
return self.World.ActorMap.GetActorsAt(cell)
|
||||
.All(x => x == ignoreActor) ? SubCell.FullCell : SubCell.Invalid;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
|
||||
return true;
|
||||
|
||||
foreach (var otherActor in world.ActorMap.GetUnitsAt(cell))
|
||||
foreach (var otherActor in world.ActorMap.GetActorsAt(cell))
|
||||
if (IsBlockedBy(self, otherActor, ignoreActor, check))
|
||||
return false;
|
||||
|
||||
@@ -283,13 +283,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Func<Actor, bool> checkTransient = otherActor => IsBlockedBy(self, otherActor, ignoreActor, check);
|
||||
|
||||
if (!SharesCell)
|
||||
return world.ActorMap.AnyUnitsAt(cell, SubCell.FullCell, checkTransient) ? SubCell.Invalid : SubCell.FullCell;
|
||||
return world.ActorMap.AnyActorsAt(cell, SubCell.FullCell, checkTransient) ? SubCell.Invalid : SubCell.FullCell;
|
||||
|
||||
return world.ActorMap.FreeSubCell(cell, preferredSubCell, checkTransient);
|
||||
}
|
||||
|
||||
if (!SharesCell)
|
||||
return world.ActorMap.AnyUnitsAt(cell, SubCell.FullCell) ? SubCell.Invalid : SubCell.FullCell;
|
||||
return world.ActorMap.AnyActorsAt(cell, SubCell.FullCell) ? SubCell.Invalid : SubCell.FullCell;
|
||||
|
||||
return world.ActorMap.FreeSubCell(cell, preferredSubCell);
|
||||
}
|
||||
@@ -581,7 +581,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.CenterPosition.Z != 0)
|
||||
return;
|
||||
|
||||
var crushables = self.World.ActorMap.GetUnitsAt(ToCell).Where(a => a != self)
|
||||
var crushables = self.World.ActorMap.GetActorsAt(ToCell).Where(a => a != self)
|
||||
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner)));
|
||||
foreach (var crushable in crushables)
|
||||
crushable.WarnCrush(self);
|
||||
@@ -593,7 +593,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!self.IsAtGroundLevel())
|
||||
return;
|
||||
|
||||
var crushables = self.World.ActorMap.GetUnitsAt(ToCell).Where(a => a != self)
|
||||
var crushables = self.World.ActorMap.GetActorsAt(ToCell).Where(a => a != self)
|
||||
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(c => c.CrushableBy(Info.Crushes, self.Owner)));
|
||||
foreach (var crushable in crushables)
|
||||
crushable.OnCrush(self);
|
||||
@@ -664,7 +664,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else
|
||||
{
|
||||
var cellInfo = notStupidCells
|
||||
.SelectMany(c => self.World.ActorMap.GetUnitsAt(c)
|
||||
.SelectMany(c => self.World.ActorMap.GetActorsAt(c)
|
||||
.Where(a => a.IsIdle && a.Info.HasTraitInfo<MobileInfo>()),
|
||||
(c, a) => new { Cell = c, Actor = a })
|
||||
.RandomOrDefault(self.World.SharedRandom);
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (desiredFrame > 0 && !self.World.ActorMap.GetUnitsAt(openExit).Any(a => a != self))
|
||||
if (desiredFrame > 0 && !self.World.ActorMap.GetActorsAt(openExit).Any(a => a != self))
|
||||
desiredFrame = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Update connection to neighbours
|
||||
var adjacentActors = CVec.Directions.SelectMany(dir =>
|
||||
self.World.ActorMap.GetUnitsAt(self.Location + dir));
|
||||
self.World.ActorMap.GetActorsAt(self.Location + dir));
|
||||
|
||||
adjacent = 0;
|
||||
foreach (var a in adjacentActors)
|
||||
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
static void UpdateNeighbours(Actor self)
|
||||
{
|
||||
var adjacentActors = CVec.Directions.SelectMany(dir =>
|
||||
self.World.ActorMap.GetUnitsAt(self.Location + dir))
|
||||
self.World.ActorMap.GetActorsAt(self.Location + dir))
|
||||
.Select(a => a.TraitOrDefault<WithWallSpriteBody>())
|
||||
.Where(a => a != null);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var tiles = Self.World.Map.FindTilesInCircle(xy, range);
|
||||
var units = new List<Actor>();
|
||||
foreach (var t in tiles)
|
||||
units.AddRange(Self.World.ActorMap.GetUnitsAt(t));
|
||||
units.AddRange(Self.World.ActorMap.GetActorsAt(t));
|
||||
|
||||
return units.Distinct().Where(a =>
|
||||
{
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Don't drop on any actors
|
||||
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(p) != null
|
||||
|| self.World.ActorMap.GetUnitsAt(p).Any())
|
||||
|| self.World.ActorMap.GetActorsAt(p).Any())
|
||||
continue;
|
||||
|
||||
return p;
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!rt.Info.AllowedTerrainTypes.Contains(world.Map.GetTerrainInfo(cell).Type))
|
||||
return false;
|
||||
|
||||
if (!rt.Info.AllowUnderActors && world.ActorMap.AnyUnitsAt(cell))
|
||||
if (!rt.Info.AllowUnderActors && world.ActorMap.AnyActorsAt(cell))
|
||||
return false;
|
||||
|
||||
if (!rt.Info.AllowUnderBuildings && buildingInfluence.GetBuildingAt(cell) != null)
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
|
||||
public static bool GetDirectHit(World world, CPos cell, WPos pos)
|
||||
{
|
||||
foreach (var unit in world.ActorMap.GetUnitsAt(cell))
|
||||
foreach (var unit in world.ActorMap.GetActorsAt(cell))
|
||||
{
|
||||
var healthInfo = unit.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
if (healthInfo == null)
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.D2k.Activities
|
||||
if ((location - targetLocation).Length > NearEnough)
|
||||
return false;
|
||||
|
||||
var lunch = worm.World.ActorMap.GetUnitsAt(targetLocation)
|
||||
var lunch = worm.World.ActorMap.GetActorsAt(targetLocation)
|
||||
.Where(t => !t.Equals(worm) && weapon.IsValidAgainst(t, worm));
|
||||
|
||||
if (!lunch.Any())
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
static bool ShouldLayMine(Actor self, CPos p)
|
||||
{
|
||||
// If there is no unit (other than me) here, we want to place a mine here
|
||||
return self.World.ActorMap.GetUnitsAt(p).All(a => a == self);
|
||||
return self.World.ActorMap.GetActorsAt(p).All(a => a == self);
|
||||
}
|
||||
|
||||
void LayMine(Actor self)
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
mobile.FinishedMoving(self);
|
||||
mobile.IsMoving = false;
|
||||
|
||||
self.World.ActorMap.GetUnitsAt(mobile.ToCell, mobile.ToSubCell)
|
||||
self.World.ActorMap.GetActorsAt(mobile.ToCell, mobile.ToSubCell)
|
||||
.Except(new[] { self }).Where(t => weapon.IsValidAgainst(t, self))
|
||||
.Do(t => t.Kill(self));
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
var tiles = Self.World.Map.FindTilesInCircle(xy, range);
|
||||
var units = new HashSet<Actor>();
|
||||
foreach (var t in tiles)
|
||||
units.UnionWith(Self.World.ActorMap.GetUnitsAt(t));
|
||||
units.UnionWith(Self.World.ActorMap.GetActorsAt(t));
|
||||
|
||||
return units.Where(a => a.Info.HasTraitInfo<ChronoshiftableInfo>() &&
|
||||
!a.TraitsImplementing<IPreventsTeleport>().Any(condition => condition.PreventsTeleport(a)));
|
||||
|
||||
Reference in New Issue
Block a user