diff --git a/OpenRA.Game/Traits/Target.cs b/OpenRA.Game/Traits/Target.cs index ecb11793ae..d5261e04fa 100644 --- a/OpenRA.Game/Traits/Target.cs +++ b/OpenRA.Game/Traits/Target.cs @@ -146,7 +146,7 @@ namespace OpenRA.Traits return false; // Target ranges are calculated in 2D, so ignore height differences - return Positions.Any(t => (t - origin).HorizontalLengthSquared <= range.RangeSquared); + return Positions.Any(t => (t - origin).HorizontalLengthSquared <= range.LengthSquared); } public override string ToString() diff --git a/OpenRA.Game/Traits/World/ActorMap.cs b/OpenRA.Game/Traits/World/ActorMap.cs index c5ef9b9b1a..b90a987052 100644 --- a/OpenRA.Game/Traits/World/ActorMap.cs +++ b/OpenRA.Game/Traits/World/ActorMap.cs @@ -132,7 +132,7 @@ namespace OpenRA.Traits var oldActors = currentActors; var delta = new WVec(Range, Range, WDist.Zero); currentActors = am.ActorsInBox(Position - delta, Position + delta) - .Where(a => (a.CenterPosition - Position).HorizontalLengthSquared < Range.RangeSquared) + .Where(a => (a.CenterPosition - Position).HorizontalLengthSquared < Range.LengthSquared) .ToList(); var entered = currentActors.Except(oldActors); diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 62e4d1ac4c..e54a8d6685 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -75,7 +75,7 @@ namespace OpenRA.Traits public static IEnumerable CellsInRange(Map map, WPos pos, WDist range) { var r = (range.Length + 1023) / 1024; - var limit = range.RangeSquared; + var limit = range.LengthSquared; var cell = map.CellContaining(pos); foreach (var c in map.FindTilesInCircle(cell, r, true)) diff --git a/OpenRA.Game/WDist.cs b/OpenRA.Game/WDist.cs index 2b80ca9b27..ab4f0f1c9e 100644 --- a/OpenRA.Game/WDist.cs +++ b/OpenRA.Game/WDist.cs @@ -23,7 +23,7 @@ namespace OpenRA public struct WDist : IComparable, IComparable, IEquatable, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding { public readonly int Length; - public long RangeSquared { get { return (long)Length * (long)Length; } } + public long LengthSquared { get { return (long)Length * (long)Length; } } public WDist(int r) { Length = r; } public static readonly WDist Zero = new WDist(0); diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index e251dc9258..89758ed662 100644 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -37,7 +37,7 @@ namespace OpenRA // Target ranges are calculated in 2D, so ignore height differences var vec = new WVec(r, r, WDist.Zero); return world.ActorMap.ActorsInBox(origin - vec, origin + vec).Where( - a => (a.CenterPosition - origin).HorizontalLengthSquared <= r.RangeSquared); + a => (a.CenterPosition - origin).HorizontalLengthSquared <= r.LengthSquared); } } diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs index b17e5e7d6e..71e4ac94ad 100644 --- a/OpenRA.Mods.Common/Activities/Enter.cs +++ b/OpenRA.Mods.Common/Activities/Enter.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities var diff = new WVec(radius, radius, WDist.Zero); var candidates = self.World.ActorMap.ActorsInBox(self.CenterPosition - diff, self.CenterPosition + diff) .Where(primaryFilter).Select(a => new { Actor = a, Ls = (self.CenterPosition - a.CenterPosition).HorizontalLengthSquared }) - .Where(p => p.Ls <= radius.RangeSquared).OrderBy(p => p.Ls).Select(p => p.Actor); + .Where(p => p.Ls <= radius.LengthSquared).OrderBy(p => p.Ls).Select(p => p.Actor); if (preferenceFilters != null) foreach (var filter in preferenceFilters) { diff --git a/OpenRA.Mods.Common/Activities/Move/MoveWithinRange.cs b/OpenRA.Mods.Common/Activities/Move/MoveWithinRange.cs index b0f47e7cc5..a9e6074b78 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveWithinRange.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveWithinRange.cs @@ -48,8 +48,8 @@ namespace OpenRA.Mods.Common.Activities var maxCells = (maxRange.Length + 1023) / 1024; var minCells = minRange.Length / 1024; - var outerSq = maxRange.RangeSquared; - var innerSq = minRange.RangeSquared; + var outerSq = maxRange.LengthSquared; + var innerSq = minRange.LengthSquared; var center = Target.CenterPosition; return map.FindTilesInAnnulus(targetPosition, minCells + 1, maxCells).Where(c => diff --git a/OpenRA.Mods.Common/Effects/Missile.cs b/OpenRA.Mods.Common/Effects/Missile.cs index 170688f28f..903e1a1b88 100644 --- a/OpenRA.Mods.Common/Effects/Missile.cs +++ b/OpenRA.Mods.Common/Effects/Missile.cs @@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Effects var cell = world.Map.CellContaining(pos); var shouldExplode = (pos.Z < 0) // Hit the ground - || (dist.LengthSquared < info.CloseEnough.RangeSquared) // Within range + || (dist.LengthSquared < info.CloseEnough.LengthSquared) // Within range || (info.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel || (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait())) // Hit a wall or other blocking obstacle || !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below. diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 8b95f28bfb..c666ba3e31 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits var d = self.CenterPosition - other.CenterPosition; var distSq = d.HorizontalLengthSquared; - if (distSq > info.IdealSeparation.RangeSquared) + if (distSq > info.IdealSeparation.LengthSquared) return WVec.Zero; if (distSq < 1) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 74e6b7b610..7930675bfc 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -268,7 +268,7 @@ namespace OpenRA.Mods.Common.Traits if (modifiers.HasModifier(TargetModifiers.ForceAttack)) { var targetRange = (self.World.Map.CenterOfCell(location) - self.CenterPosition).HorizontalLengthSquared; - if (targetRange > ab.GetMaximumRange().RangeSquared) + if (targetRange > ab.GetMaximumRange().LengthSquared) cursor = ab.Info.OutsideRangeCursor; return true; diff --git a/OpenRA.Mods.Common/Traits/Repairable.cs b/OpenRA.Mods.Common/Traits/Repairable.cs index a0b25009c7..8210da205d 100644 --- a/OpenRA.Mods.Common/Traits/Repairable.cs +++ b/OpenRA.Mods.Common/Traits/Repairable.cs @@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits return; var targetCell = self.World.Map.CellContaining(target.CenterPosition); - if ((self.CenterPosition - target.CenterPosition).LengthSquared < transport.MinimumDistance.RangeSquared) + if ((self.CenterPosition - target.CenterPosition).LengthSquared < transport.MinimumDistance.LengthSquared) return; transport.RequestTransport(targetCell, nextActivity); diff --git a/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs b/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs index 2d38a009f2..c55c761f19 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs @@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits public void UnitProducedByOther(Actor self, Actor producer, Actor produced) { // Work around for actors produced within the region not triggering until the second tick - if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= info.Range.RangeSquared) + if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= info.Range.LengthSquared) { var stance = self.Owner.Stances[produced.Owner]; if (!info.ValidStances.HasFlag(stance)) diff --git a/OpenRA.Mods.Common/Traits/World/PathFinder.cs b/OpenRA.Mods.Common/Traits/World/PathFinder.cs index 5441302e6c..25d96aea35 100644 --- a/OpenRA.Mods.Common/Traits/World/PathFinder.cs +++ b/OpenRA.Mods.Common/Traits/World/PathFinder.cs @@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits // Select only the tiles that are within range from the requested SubCell // This assumes that the SubCell does not change during the path traversal var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Length / 1024 + 1) - .Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= range.RangeSquared + .Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= range.LengthSquared && mi.CanEnterCell(self.World as World, self as Actor, t)); // See if there is any cell within range that does not involve a cross-domain request diff --git a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs index 610f9a8eeb..2000363551 100644 --- a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs @@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Warheads continue; // If the impact position is within any actor's health radius, we have a direct hit - if ((unit.CenterPosition - pos).LengthSquared <= healthInfo.Radius.RangeSquared) + if ((unit.CenterPosition - pos).LengthSquared <= healthInfo.Radius.LengthSquared) return true; } diff --git a/OpenRA.Mods.D2k/Traits/Carryable.cs b/OpenRA.Mods.D2k/Traits/Carryable.cs index c2f6c31bc3..2915cb9cee 100644 --- a/OpenRA.Mods.D2k/Traits/Carryable.cs +++ b/OpenRA.Mods.D2k/Traits/Carryable.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.D2k.Traits public void RequestTransport(CPos destination, Activity afterLandActivity) { var destPos = self.World.Map.CenterOfCell(destination); - if (destination == CPos.Zero || (self.CenterPosition - destPos).LengthSquared < info.MinDistance.RangeSquared) + if (destination == CPos.Zero || (self.CenterPosition - destPos).LengthSquared < info.MinDistance.LengthSquared) { WantsTransport = false; // Be sure to cancel any pending transports return; @@ -122,7 +122,7 @@ namespace OpenRA.Mods.D2k.Traits return false; var destPos = self.World.Map.CenterOfCell(Destination); - if ((self.CenterPosition - destPos).LengthSquared < info.MinDistance.RangeSquared) + if ((self.CenterPosition - destPos).LengthSquared < info.MinDistance.LengthSquared) { MovementCancelled(self); return false; @@ -150,7 +150,7 @@ namespace OpenRA.Mods.D2k.Traits // Last change to change our mind... var destPos = self.World.Map.CenterOfCell(Destination); - if ((self.CenterPosition - destPos).LengthSquared < info.MinDistance.RangeSquared) + if ((self.CenterPosition - destPos).LengthSquared < info.MinDistance.LengthSquared) { MovementCancelled(self); return false;