Rename FindUnitsInCircle -> FindActorsInCircle.

This commit is contained in:
Paul Chote
2013-07-20 13:54:11 +12:00
parent e6865c5996
commit 800acdbdf2
10 changed files with 20 additions and 20 deletions

View File

@@ -55,7 +55,7 @@ namespace OpenRA
return actors.OrderBy(a => (a.CenterPosition - pos).LengthSquared).FirstOrDefault(); return actors.OrderBy(a => (a.CenterPosition - pos).LengthSquared).FirstOrDefault();
} }
public static IEnumerable<Actor> FindUnitsInCircle(this World world, WPos origin, WRange r) public static IEnumerable<Actor> FindActorsInCircle(this World world, WPos origin, WRange r)
{ {
using (new PerfSample("FindUnitsInCircle")) using (new PerfSample("FindUnitsInCircle"))
{ {

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2012 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Cnc.Missions
IEnumerable<Actor> UnitsNearActor(Actor actor, int range) IEnumerable<Actor> UnitsNearActor(Actor actor, int range)
{ {
return world.FindUnitsInCircle(actor.CenterPosition, WRange.FromCells(range)) return world.FindActorsInCircle(actor.CenterPosition, WRange.FromCells(range))
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait<IMove>() && !a.Owner.NonCombatant); .Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait<IMove>() && !a.Owner.NonCombatant);
} }

View File

@@ -168,7 +168,7 @@ namespace OpenRA.Mods.RA.AI
if (owner.IsEmpty) return false; if (owner.IsEmpty) return false;
var u = owner.units.Random(owner.random); var u = owner.units.Random(owner.random);
var units = owner.world.FindUnitsInCircle(u.CenterPosition, WRange.FromCells(dangerRadius)).ToList(); var units = owner.world.FindActorsInCircle(u.CenterPosition, WRange.FromCells(dangerRadius)).ToList();
var ownBaseBuildingAround = units.Where(unit => unit.Owner == owner.bot.p && unit.HasTrait<Building>()).ToList(); var ownBaseBuildingAround = units.Where(unit => unit.Owner == owner.bot.p && unit.HasTrait<Building>()).ToList();
if (ownBaseBuildingAround.Count > 0) return false; if (ownBaseBuildingAround.Count > 0) return false;
@@ -325,7 +325,7 @@ namespace OpenRA.Mods.RA.AI
protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget) protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget)
{ {
detectedEnemyTarget = null; detectedEnemyTarget = null;
var unitsAroundPos = owner.world.FindUnitsInCircle(loc, WRange.FromCells(dangerRadius)) var unitsAroundPos = owner.world.FindActorsInCircle(loc, WRange.FromCells(dangerRadius))
.Where(unit => owner.bot.p.Stances[unit.Owner] == Stance.Enemy).ToList(); .Where(unit => owner.bot.p.Stances[unit.Owner] == Stance.Enemy).ToList();
int missileUnitsCount = 0; int missileUnitsCount = 0;
@@ -509,7 +509,7 @@ namespace OpenRA.Mods.RA.AI
owner.Target = t; owner.Target = t;
} }
var enemyUnits = owner.world.FindUnitsInCircle(owner.Target.CenterPosition, WRange.FromCells(10)) var enemyUnits = owner.world.FindActorsInCircle(owner.Target.CenterPosition, WRange.FromCells(10))
.Where(unit => owner.bot.p.Stances[unit.Owner] == Stance.Enemy).ToList(); .Where(unit => owner.bot.p.Stances[unit.Owner] == Stance.Enemy).ToList();
if (enemyUnits.Any()) if (enemyUnits.Any())
@@ -554,7 +554,7 @@ namespace OpenRA.Mods.RA.AI
Actor leader = owner.units.ClosestTo(owner.Target.CenterPosition); Actor leader = owner.units.ClosestTo(owner.Target.CenterPosition);
if (leader == null) if (leader == null)
return; return;
var ownUnits = owner.world.FindUnitsInCircle(leader.CenterPosition, WRange.FromCells(owner.units.Count) / 3) var ownUnits = owner.world.FindActorsInCircle(leader.CenterPosition, WRange.FromCells(owner.units.Count) / 3)
.Where(a => a.Owner == owner.units.FirstOrDefault().Owner && owner.units.Contains(a)).ToList(); .Where(a => a.Owner == owner.units.FirstOrDefault().Owner && owner.units.Contains(a)).ToList();
if (ownUnits.Count < owner.units.Count) if (ownUnits.Count < owner.units.Count)
{ {
@@ -564,7 +564,7 @@ namespace OpenRA.Mods.RA.AI
} }
else else
{ {
var enemys = owner.world.FindUnitsInCircle(leader.CenterPosition, WRange.FromCells(12)) var enemys = owner.world.FindActorsInCircle(leader.CenterPosition, WRange.FromCells(12))
.Where(a1 => !a1.Destroyed && !a1.IsDead()).ToList(); .Where(a1 => !a1.Destroyed && !a1.IsDead()).ToList();
var enemynearby = enemys.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy).ToList(); var enemynearby = enemys.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy).ToList();
if (enemynearby.Any()) if (enemynearby.Any())
@@ -1037,7 +1037,7 @@ namespace OpenRA.Mods.RA.AI
internal Actor FindClosestEnemy(WPos pos, WRange radius) internal Actor FindClosestEnemy(WPos pos, WRange radius)
{ {
var enemyUnits = world.FindUnitsInCircle(pos, radius) var enemyUnits = world.FindActorsInCircle(pos, radius)
.Where(unit => p.Stances[unit.Owner] == Stance.Enemy && .Where(unit => p.Stances[unit.Owner] == Stance.Enemy &&
!unit.HasTrait<Husk>() && unit.HasTrait<ITargetable>()).ToList(); !unit.HasTrait<Husk>() && unit.HasTrait<ITargetable>()).ToList();
@@ -1194,7 +1194,7 @@ namespace OpenRA.Mods.RA.AI
if (!allEnemyBaseBuilder.Any() || (ownUnits.Count < Info.SquadSize)) return; if (!allEnemyBaseBuilder.Any() || (ownUnits.Count < Info.SquadSize)) return;
foreach (var b in allEnemyBaseBuilder) foreach (var b in allEnemyBaseBuilder)
{ {
var enemys = world.FindUnitsInCircle(b.CenterPosition, WRange.FromCells(15)) var enemys = world.FindActorsInCircle(b.CenterPosition, WRange.FromCells(15))
.Where(unit => p.Stances[unit.Owner] == Stance.Enemy && unit.HasTrait<AttackBase>()).ToList(); .Where(unit => p.Stances[unit.Owner] == Stance.Enemy && unit.HasTrait<AttackBase>()).ToList();
rushFuzzy.CalculateFuzzy(ownUnits, enemys); rushFuzzy.CalculateFuzzy(ownUnits, enemys);
@@ -1223,7 +1223,7 @@ namespace OpenRA.Mods.RA.AI
protectSq.Target = attacker; protectSq.Target = attacker;
if (protectSq.IsEmpty) if (protectSq.IsEmpty)
{ {
var ownUnits = world.FindUnitsInCircle(baseCenter.CenterPosition, WRange.FromCells(15)) var ownUnits = world.FindActorsInCircle(baseCenter.CenterPosition, WRange.FromCells(15))
.Where(unit => unit.Owner == p && !unit.HasTrait<Building>() .Where(unit => unit.Owner == p && !unit.HasTrait<Building>()
&& unit.HasTrait<AttackBase>()).ToList(); && unit.HasTrait<AttackBase>()).ToList();
foreach (var a in ownUnits) foreach (var a in ownUnits)
@@ -1340,7 +1340,7 @@ namespace OpenRA.Mods.RA.AI
for (int j = 0; j < y; j += radiusOfPower * 2) for (int j = 0; j < y; j += radiusOfPower * 2)
{ {
CPos pos = new CPos(i, j); CPos pos = new CPos(i, j);
var targets = world.FindUnitsInCircle(pos.CenterPosition, WRange.FromCells(radiusOfPower)).ToList(); var targets = world.FindActorsInCircle(pos.CenterPosition, WRange.FromCells(radiusOfPower)).ToList();
var enemys = targets.Where(unit => p.Stances[unit.Owner] == Stance.Enemy).ToList(); var enemys = targets.Where(unit => p.Stances[unit.Owner] == Stance.Enemy).ToList();
var ally = targets.Where(unit => p.Stances[unit.Owner] == Stance.Ally || unit.Owner == p).ToList(); var ally = targets.Where(unit => p.Stances[unit.Owner] == Stance.Ally || unit.Owner == p).ToList();

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Activities
// TODO: calculate weapons ranges of units and factor those in instead of hard-coding 8. // TODO: calculate weapons ranges of units and factor those in instead of hard-coding 8.
var path = self.World.WorldActor.Trait<PathFinder>().FindPath( var path = self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.Search(self.World, mobileInfo, self, true) PathSearch.Search(self.World, mobileInfo, self, true)
.WithCustomCost(loc => self.World.FindUnitsInCircle(loc.CenterPosition, WRange.FromCells(8)) .WithCustomCost(loc => self.World.FindActorsInCircle(loc.CenterPosition, WRange.FromCells(8))
.Where (u => !u.Destroyed && self.Owner.Stances[u.Owner] == Stance.Enemy) .Where (u => !u.Destroyed && self.Owner.Stances[u.Owner] == Stance.Enemy)
.Sum(u => Math.Max(0, 64 - (loc - u.Location).LengthSquared))) .Sum(u => Math.Max(0, 64 - (loc - u.Location).LengthSquared)))
.WithHeuristic(loc => .WithHeuristic(loc =>

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Air
if (Altitude <= 0) return; if (Altitude <= 0) return;
var separation = new WRange(Info.IdealSeparation * 1024 / Game.CellSize); var separation = new WRange(Info.IdealSeparation * 1024 / Game.CellSize);
var otherHelis = self.World.FindUnitsInCircle(self.CenterPosition, separation) var otherHelis = self.World.FindActorsInCircle(self.CenterPosition, separation)
.Where(a => a.HasTrait<Helicopter>()); .Where(a => a.HasTrait<Helicopter>());
var f = otherHelis var f = otherHelis

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA
public void TickIdle(Actor self) public void TickIdle(Actor self)
{ {
var attack = self.Trait<AttackBase>(); var attack = self.Trait<AttackBase>();
var inRange = self.World.FindUnitsInCircle(self.CenterPosition, attack.GetMaximumRange()); var inRange = self.World.FindActorsInCircle(self.CenterPosition, attack.GetMaximumRange());
var target = inRange var target = inRange
.Where(a => a != self && a.AppearsFriendlyTo(self)) .Where(a => a != self && a.AppearsFriendlyTo(self))

View File

@@ -119,7 +119,7 @@ namespace OpenRA.Mods.RA
Actor ChooseTarget(Actor self, WRange range) Actor ChooseTarget(Actor self, WRange range)
{ {
nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval); nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval);
var inRange = self.World.FindUnitsInCircle(self.CenterPosition, range); var inRange = self.World.FindActorsInCircle(self.CenterPosition, range);
if (self.Owner.HasFogVisibility()) if (self.Owner.HasFogVisibility())
{ {

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.RA
{ {
var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2); var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2);
var range = new WRange((int)maxSpread * 1024 / Game.CellSize); var range = new WRange((int)maxSpread * 1024 / Game.CellSize);
var hitActors = world.FindUnitsInCircle(args.dest.ToWPos(0), range); var hitActors = world.FindActorsInCircle(args.dest.ToWPos(0), range);
foreach (var victim in hitActors) foreach (var victim in hitActors)
{ {

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Missions
{ {
public static IEnumerable<Actor> FindAliveCombatantActorsInCircle(this World world, WPos location, WRange range) public static IEnumerable<Actor> FindAliveCombatantActorsInCircle(this World world, WPos location, WRange range)
{ {
return world.FindUnitsInCircle(location, range) return world.FindActorsInCircle(location, range)
.Where(u => u.IsInWorld && u != world.WorldActor && !u.IsDead() && !u.Owner.NonCombatant); .Where(u => u.IsInWorld && u != world.WorldActor && !u.IsDead() && !u.Owner.NonCombatant);
} }
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Missions
public static IEnumerable<Actor> FindAliveNonCombatantActorsInCircle(this World world, WPos location, WRange range) public static IEnumerable<Actor> FindAliveNonCombatantActorsInCircle(this World world, WPos location, WRange range)
{ {
return world.FindUnitsInCircle(location, range) return world.FindActorsInCircle(location, range)
.Where(u => u.IsInWorld && u != world.WorldActor && !u.IsDead() && u.Owner.NonCombatant); .Where(u => u.IsInWorld && u != world.WorldActor && !u.IsDead() && u.Owner.NonCombatant);
} }

View File

@@ -109,7 +109,7 @@ namespace OpenRA.Mods.RA
IEnumerable<Actor> UnitsInRange() IEnumerable<Actor> UnitsInRange()
{ {
return Self.World.FindUnitsInCircle(Self.CenterPosition, WRange.FromCells(Info.Range)) return Self.World.FindActorsInCircle(Self.CenterPosition, WRange.FromCells(Info.Range))
.Where(a => a.IsInWorld && a != Self && !a.Destroyed) .Where(a => a.IsInWorld && a != Self && !a.Destroyed)
.Where(a => !a.Owner.NonCombatant); .Where(a => !a.Owner.NonCombatant);
} }