rename RangeSquard to LengthSquared

This commit is contained in:
Matthias Mailänder
2015-07-09 21:13:54 +02:00
parent cae889fb67
commit 56e9bcd96e
15 changed files with 18 additions and 18 deletions

View File

@@ -146,7 +146,7 @@ namespace OpenRA.Traits
return false; return false;
// Target ranges are calculated in 2D, so ignore height differences // 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() public override string ToString()

View File

@@ -132,7 +132,7 @@ namespace OpenRA.Traits
var oldActors = currentActors; var oldActors = currentActors;
var delta = new WVec(Range, Range, WDist.Zero); var delta = new WVec(Range, Range, WDist.Zero);
currentActors = am.ActorsInBox(Position - delta, Position + delta) currentActors = am.ActorsInBox(Position - delta, Position + delta)
.Where(a => (a.CenterPosition - Position).HorizontalLengthSquared < Range.RangeSquared) .Where(a => (a.CenterPosition - Position).HorizontalLengthSquared < Range.LengthSquared)
.ToList(); .ToList();
var entered = currentActors.Except(oldActors); var entered = currentActors.Except(oldActors);

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Traits
public static IEnumerable<CPos> CellsInRange(Map map, WPos pos, WDist range) public static IEnumerable<CPos> CellsInRange(Map map, WPos pos, WDist range)
{ {
var r = (range.Length + 1023) / 1024; var r = (range.Length + 1023) / 1024;
var limit = range.RangeSquared; var limit = range.LengthSquared;
var cell = map.CellContaining(pos); var cell = map.CellContaining(pos);
foreach (var c in map.FindTilesInCircle(cell, r, true)) foreach (var c in map.FindTilesInCircle(cell, r, true))

View File

@@ -23,7 +23,7 @@ namespace OpenRA
public struct WDist : IComparable, IComparable<WDist>, IEquatable<WDist>, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding public struct WDist : IComparable, IComparable<WDist>, IEquatable<WDist>, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding
{ {
public readonly int Length; 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 WDist(int r) { Length = r; }
public static readonly WDist Zero = new WDist(0); public static readonly WDist Zero = new WDist(0);

View File

@@ -37,7 +37,7 @@ namespace OpenRA
// Target ranges are calculated in 2D, so ignore height differences // Target ranges are calculated in 2D, so ignore height differences
var vec = new WVec(r, r, WDist.Zero); var vec = new WVec(r, r, WDist.Zero);
return world.ActorMap.ActorsInBox(origin - vec, origin + vec).Where( return world.ActorMap.ActorsInBox(origin - vec, origin + vec).Where(
a => (a.CenterPosition - origin).HorizontalLengthSquared <= r.RangeSquared); a => (a.CenterPosition - origin).HorizontalLengthSquared <= r.LengthSquared);
} }
} }

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
var diff = new WVec(radius, radius, WDist.Zero); var diff = new WVec(radius, radius, WDist.Zero);
var candidates = self.World.ActorMap.ActorsInBox(self.CenterPosition - diff, self.CenterPosition + diff) 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(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) if (preferenceFilters != null)
foreach (var filter in preferenceFilters) foreach (var filter in preferenceFilters)
{ {

View File

@@ -48,8 +48,8 @@ namespace OpenRA.Mods.Common.Activities
var maxCells = (maxRange.Length + 1023) / 1024; var maxCells = (maxRange.Length + 1023) / 1024;
var minCells = minRange.Length / 1024; var minCells = minRange.Length / 1024;
var outerSq = maxRange.RangeSquared; var outerSq = maxRange.LengthSquared;
var innerSq = minRange.RangeSquared; var innerSq = minRange.LengthSquared;
var center = Target.CenterPosition; var center = Target.CenterPosition;
return map.FindTilesInAnnulus(targetPosition, minCells + 1, maxCells).Where(c => return map.FindTilesInAnnulus(targetPosition, minCells + 1, maxCells).Where(c =>

View File

@@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Effects
var cell = world.Map.CellContaining(pos); var cell = world.Map.CellContaining(pos);
var shouldExplode = (pos.Z < 0) // Hit the ground 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.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel
|| (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksProjectiles>())) // Hit a wall or other blocking obstacle || (info.Blockable && world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksProjectiles>())) // Hit a wall or other blocking obstacle
|| !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below. || !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below.

View File

@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits
var d = self.CenterPosition - other.CenterPosition; var d = self.CenterPosition - other.CenterPosition;
var distSq = d.HorizontalLengthSquared; var distSq = d.HorizontalLengthSquared;
if (distSq > info.IdealSeparation.RangeSquared) if (distSq > info.IdealSeparation.LengthSquared)
return WVec.Zero; return WVec.Zero;
if (distSq < 1) if (distSq < 1)

View File

@@ -268,7 +268,7 @@ namespace OpenRA.Mods.Common.Traits
if (modifiers.HasModifier(TargetModifiers.ForceAttack)) if (modifiers.HasModifier(TargetModifiers.ForceAttack))
{ {
var targetRange = (self.World.Map.CenterOfCell(location) - self.CenterPosition).HorizontalLengthSquared; var targetRange = (self.World.Map.CenterOfCell(location) - self.CenterPosition).HorizontalLengthSquared;
if (targetRange > ab.GetMaximumRange().RangeSquared) if (targetRange > ab.GetMaximumRange().LengthSquared)
cursor = ab.Info.OutsideRangeCursor; cursor = ab.Info.OutsideRangeCursor;
return true; return true;

View File

@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
var targetCell = self.World.Map.CellContaining(target.CenterPosition); 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; return;
transport.RequestTransport(targetCell, nextActivity); transport.RequestTransport(targetCell, nextActivity);

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
public void UnitProducedByOther(Actor self, Actor producer, Actor produced) public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
{ {
// Work around for actors produced within the region not triggering until the second tick // 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]; var stance = self.Owner.Stances[produced.Owner];
if (!info.ValidStances.HasFlag(stance)) if (!info.ValidStances.HasFlag(stance))

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits
// Select only the tiles that are within range from the requested SubCell // Select only the tiles that are within range from the requested SubCell
// This assumes that the SubCell does not change during the path traversal // This assumes that the SubCell does not change during the path traversal
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Length / 1024 + 1) 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)); && 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 // See if there is any cell within range that does not involve a cross-domain request

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Warheads
continue; continue;
// If the impact position is within any actor's health radius, we have a direct hit // 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; return true;
} }

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.D2k.Traits
public void RequestTransport(CPos destination, Activity afterLandActivity) public void RequestTransport(CPos destination, Activity afterLandActivity)
{ {
var destPos = self.World.Map.CenterOfCell(destination); 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 WantsTransport = false; // Be sure to cancel any pending transports
return; return;
@@ -122,7 +122,7 @@ namespace OpenRA.Mods.D2k.Traits
return false; return false;
var destPos = self.World.Map.CenterOfCell(Destination); 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); MovementCancelled(self);
return false; return false;
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.D2k.Traits
// Last change to change our mind... // Last change to change our mind...
var destPos = self.World.Map.CenterOfCell(Destination); 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); MovementCancelled(self);
return false; return false;