rename WRange to WDist
This commit is contained in:
@@ -243,10 +243,10 @@ namespace OpenRA
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType == typeof(WRange))
|
||||
else if (fieldType == typeof(WDist))
|
||||
{
|
||||
WRange res;
|
||||
if (WRange.TryParse(value, out res))
|
||||
WDist res;
|
||||
if (WDist.TryParse(value, out res))
|
||||
return res;
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
@@ -258,8 +258,8 @@ namespace OpenRA
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
WRange rx, ry, rz;
|
||||
if (WRange.TryParse(parts[0], out rx) && WRange.TryParse(parts[1], out ry) && WRange.TryParse(parts[2], out rz))
|
||||
WDist rx, ry, rz;
|
||||
if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
|
||||
return new WVec(rx, ry, rz);
|
||||
}
|
||||
}
|
||||
@@ -279,8 +279,8 @@ namespace OpenRA
|
||||
|
||||
for (var i = 0; i < vecs.Length; ++i)
|
||||
{
|
||||
WRange rx, ry, rz;
|
||||
if (WRange.TryParse(parts[3 * i], out rx) && WRange.TryParse(parts[3 * i + 1], out ry) && WRange.TryParse(parts[3 * i + 2], out rz))
|
||||
WDist rx, ry, rz;
|
||||
if (WDist.TryParse(parts[3 * i], out rx) && WDist.TryParse(parts[3 * i + 1], out ry) && WDist.TryParse(parts[3 * i + 2], out rz))
|
||||
vecs[i] = new WVec(rx, ry, rz);
|
||||
}
|
||||
|
||||
@@ -296,8 +296,8 @@ namespace OpenRA
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
WRange rx, ry, rz;
|
||||
if (WRange.TryParse(parts[0], out rx) && WRange.TryParse(parts[1], out ry) && WRange.TryParse(parts[2], out rz))
|
||||
WDist rx, ry, rz;
|
||||
if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
|
||||
return new WPos(rx, ry, rz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.GameRules
|
||||
public sealed class WeaponInfo
|
||||
{
|
||||
[Desc("The maximum range the weapon can fire.")]
|
||||
public readonly WRange Range = WRange.Zero;
|
||||
public readonly WDist Range = WDist.Zero;
|
||||
|
||||
[Desc("The sound played when the weapon is fired.")]
|
||||
public readonly string[] Report = null;
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.GameRules
|
||||
public readonly int BurstDelay = 5;
|
||||
|
||||
[Desc("The minimum range the weapon can fire.")]
|
||||
public readonly WRange MinRange = WRange.Zero;
|
||||
public readonly WDist MinRange = WDist.Zero;
|
||||
|
||||
[FieldLoader.LoadUsing("LoadProjectile")]
|
||||
public readonly IProjectileInfo Projectile;
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace OpenRA.Graphics
|
||||
new SelectionBarsRenderable(unit).Render(this);
|
||||
}
|
||||
|
||||
public void DrawRangeCircle(WPos pos, WRange range, Color c)
|
||||
public void DrawRangeCircle(WPos pos, WDist range, Color c)
|
||||
{
|
||||
var offset = new WVec(range.Range, 0, 0);
|
||||
for (var i = 0; i < 32; i++)
|
||||
|
||||
@@ -841,13 +841,13 @@ namespace OpenRA
|
||||
return new MPos(x, y).ToCPos(this);
|
||||
}
|
||||
|
||||
public WRange DistanceToEdge(WPos pos, WVec dir)
|
||||
public WDist DistanceToEdge(WPos pos, WVec dir)
|
||||
{
|
||||
var tl = CenterOfCell(CellsInsideBounds.TopLeft) - new WVec(512, 512, 0);
|
||||
var br = CenterOfCell(CellsInsideBounds.BottomRight) + new WVec(511, 511, 0);
|
||||
var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X;
|
||||
var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y;
|
||||
return new WRange(Math.Min(x, y) * dir.Length);
|
||||
return new WDist(Math.Min(x, y) * dir.Length);
|
||||
}
|
||||
|
||||
static readonly CVec[][] TilesByDistance = InitTilesByDistance(MaxTilesInCircleRange);
|
||||
|
||||
@@ -305,8 +305,8 @@
|
||||
<Compile Include="CPos.cs" />
|
||||
<Compile Include="CVec.cs" />
|
||||
<Compile Include="WAngle.cs" />
|
||||
<Compile Include="WDist.cs" />
|
||||
<Compile Include="WPos.cs" />
|
||||
<Compile Include="WRange.cs" />
|
||||
<Compile Include="WRot.cs" />
|
||||
<Compile Include="WVec.cs" />
|
||||
<Compile Include="Primitives\TypeDictionary.cs" />
|
||||
|
||||
2
OpenRA.Game/Sync.cs
Executable file → Normal file
2
OpenRA.Game/Sync.cs
Executable file → Normal file
@@ -36,7 +36,7 @@ namespace OpenRA
|
||||
{ typeof(int2), ((Func<int2, int>)HashInt2).Method },
|
||||
{ typeof(CPos), ((Func<CPos, int>)HashCPos).Method },
|
||||
{ typeof(CVec), ((Func<CVec, int>)HashCVec).Method },
|
||||
{ typeof(WRange), ((Func<WRange, int>)Hash<WRange>).Method },
|
||||
{ typeof(WDist), ((Func<WDist, int>)Hash<WDist>).Method },
|
||||
{ typeof(WPos), ((Func<WPos, int>)Hash<WPos>).Method },
|
||||
{ typeof(WVec), ((Func<WVec, int>)Hash<WVec>).Method },
|
||||
{ typeof(WAngle), ((Func<WAngle, int>)Hash<WAngle>).Method },
|
||||
|
||||
2
OpenRA.Game/Traits/Health.cs
Executable file → Normal file
2
OpenRA.Game/Traits/Health.cs
Executable file → Normal file
@@ -18,7 +18,7 @@ namespace OpenRA.Traits
|
||||
public readonly int HP = 0;
|
||||
|
||||
[Desc("Physical size of the unit used for damage calculations. Impacts within this radius apply full damage.")]
|
||||
public readonly WRange Radius = new WRange(426);
|
||||
public readonly WDist Radius = new WDist(426);
|
||||
|
||||
[Desc("Trigger interfaces such as AnnounceOnKill?")]
|
||||
public readonly bool NotifyAppliedDamage = true;
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInRange(WPos origin, WRange range)
|
||||
public bool IsInRange(WPos origin, WDist range)
|
||||
{
|
||||
if (Type == TargetType.Invalid)
|
||||
return false;
|
||||
|
||||
@@ -234,9 +234,9 @@ namespace OpenRA.Traits
|
||||
{
|
||||
Activity MoveTo(CPos cell, int nearEnough);
|
||||
Activity MoveTo(CPos cell, Actor ignoredActor);
|
||||
Activity MoveWithinRange(Target target, WRange range);
|
||||
Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange);
|
||||
Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange);
|
||||
Activity MoveWithinRange(Target target, WDist range);
|
||||
Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange);
|
||||
Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange);
|
||||
Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any);
|
||||
Activity MoveToTarget(Actor self, Target target);
|
||||
Activity MoveIntoTarget(Actor self, Target target);
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public readonly int Id;
|
||||
public WPos Position { get; private set; }
|
||||
public WRange Range { get; private set; }
|
||||
public WDist Range { get; private set; }
|
||||
|
||||
public WPos TopLeft { get; private set; }
|
||||
public WPos BottomRight { get; private set; }
|
||||
@@ -102,7 +102,7 @@ namespace OpenRA.Traits
|
||||
|
||||
IEnumerable<Actor> currentActors = Enumerable.Empty<Actor>();
|
||||
|
||||
public ProximityTrigger(int id, WPos pos, WRange range, Action<Actor> onActorEntered, Action<Actor> onActorExited)
|
||||
public ProximityTrigger(int id, WPos pos, WDist range, Action<Actor> onActorEntered, Action<Actor> onActorExited)
|
||||
{
|
||||
Id = id;
|
||||
|
||||
@@ -112,12 +112,12 @@ namespace OpenRA.Traits
|
||||
Update(pos, range);
|
||||
}
|
||||
|
||||
public void Update(WPos newPos, WRange newRange)
|
||||
public void Update(WPos newPos, WDist newRange)
|
||||
{
|
||||
Position = newPos;
|
||||
Range = newRange;
|
||||
|
||||
var offset = new WVec(newRange, newRange, WRange.Zero);
|
||||
var offset = new WVec(newRange, newRange, WDist.Zero);
|
||||
TopLeft = newPos - offset;
|
||||
BottomRight = newPos + offset;
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Traits
|
||||
return;
|
||||
|
||||
var oldActors = currentActors;
|
||||
var delta = new WVec(Range, Range, WRange.Zero);
|
||||
var delta = new WVec(Range, Range, WDist.Zero);
|
||||
currentActors = am.ActorsInBox(Position - delta, Position + delta)
|
||||
.Where(a => (a.CenterPosition - Position).HorizontalLengthSquared < Range.RangeSquared)
|
||||
.ToList();
|
||||
@@ -407,7 +407,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public int AddProximityTrigger(WPos pos, WRange range, Action<Actor> onEntry, Action<Actor> onExit)
|
||||
public int AddProximityTrigger(WPos pos, WDist range, Action<Actor> onEntry, Action<Actor> onExit)
|
||||
{
|
||||
var id = nextTriggerId++;
|
||||
var t = new ProximityTrigger(id, pos, range, onEntry, onExit);
|
||||
@@ -431,7 +431,7 @@ namespace OpenRA.Traits
|
||||
t.Dispose();
|
||||
}
|
||||
|
||||
public void UpdateProximityTrigger(int id, WPos newPos, WRange newRange)
|
||||
public void UpdateProximityTrigger(int id, WPos newPos, WDist newRange)
|
||||
{
|
||||
ProximityTrigger t;
|
||||
if (!proximityTriggers.TryGetValue(id, out t))
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA.Traits
|
||||
Hash += 1;
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> CellsInRange(Map map, WPos pos, WRange range)
|
||||
public static IEnumerable<CPos> CellsInRange(Map map, WPos pos, WDist range)
|
||||
{
|
||||
var r = (range.Range + 1023) / 1024;
|
||||
var limit = range.RangeSquared;
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Traits
|
||||
yield return c;
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> CellsInRange(Map map, CPos cell, WRange range)
|
||||
public static IEnumerable<CPos> CellsInRange(Map map, CPos cell, WDist range)
|
||||
{
|
||||
return CellsInRange(map, map.CenterOfCell(cell), range);
|
||||
}
|
||||
|
||||
@@ -20,43 +20,43 @@ namespace OpenRA
|
||||
/// <summary>
|
||||
/// 1d world distance - 1024 units = 1 cell.
|
||||
/// </summary>
|
||||
public struct WRange : IComparable, IComparable<WRange>, IEquatable<WRange>, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding
|
||||
public struct WDist : IComparable, IComparable<WDist>, IEquatable<WDist>, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding
|
||||
{
|
||||
public readonly int Range;
|
||||
public long RangeSquared { get { return (long)Range * (long)Range; } }
|
||||
|
||||
public WRange(int r) { Range = r; }
|
||||
public static readonly WRange Zero = new WRange(0);
|
||||
public static WRange FromCells(int cells) { return new WRange(1024 * cells); }
|
||||
public WDist(int r) { Range = r; }
|
||||
public static readonly WDist Zero = new WDist(0);
|
||||
public static WDist FromCells(int cells) { return new WDist(1024 * cells); }
|
||||
|
||||
public static WRange operator +(WRange a, WRange b) { return new WRange(a.Range + b.Range); }
|
||||
public static WRange operator -(WRange a, WRange b) { return new WRange(a.Range - b.Range); }
|
||||
public static WRange operator -(WRange a) { return new WRange(-a.Range); }
|
||||
public static WRange operator /(WRange a, int b) { return new WRange(a.Range / b); }
|
||||
public static WRange operator *(WRange a, int b) { return new WRange(a.Range * b); }
|
||||
public static WRange operator *(int a, WRange b) { return new WRange(a * b.Range); }
|
||||
public static bool operator <(WRange a, WRange b) { return a.Range < b.Range; }
|
||||
public static bool operator >(WRange a, WRange b) { return a.Range > b.Range; }
|
||||
public static bool operator <=(WRange a, WRange b) { return a.Range <= b.Range; }
|
||||
public static bool operator >=(WRange a, WRange b) { return a.Range >= b.Range; }
|
||||
public static WDist operator +(WDist a, WDist b) { return new WDist(a.Range + b.Range); }
|
||||
public static WDist operator -(WDist a, WDist b) { return new WDist(a.Range - b.Range); }
|
||||
public static WDist operator -(WDist a) { return new WDist(-a.Range); }
|
||||
public static WDist operator /(WDist a, int b) { return new WDist(a.Range / b); }
|
||||
public static WDist operator *(WDist a, int b) { return new WDist(a.Range * b); }
|
||||
public static WDist operator *(int a, WDist b) { return new WDist(a * b.Range); }
|
||||
public static bool operator <(WDist a, WDist b) { return a.Range < b.Range; }
|
||||
public static bool operator >(WDist a, WDist b) { return a.Range > b.Range; }
|
||||
public static bool operator <=(WDist a, WDist b) { return a.Range <= b.Range; }
|
||||
public static bool operator >=(WDist a, WDist b) { return a.Range >= b.Range; }
|
||||
|
||||
public static bool operator ==(WRange me, WRange other) { return me.Range == other.Range; }
|
||||
public static bool operator !=(WRange me, WRange other) { return !(me == other); }
|
||||
public static bool operator ==(WDist me, WDist other) { return me.Range == other.Range; }
|
||||
public static bool operator !=(WDist me, WDist other) { return !(me == other); }
|
||||
|
||||
// Sampled a N-sample probability density function in the range [-1024..1024]
|
||||
// 1 sample produces a rectangular probability
|
||||
// 2 samples produces a triangular probability
|
||||
// ...
|
||||
// N samples approximates a true gaussian
|
||||
public static WRange FromPDF(MersenneTwister r, int samples)
|
||||
public static WDist FromPDF(MersenneTwister r, int samples)
|
||||
{
|
||||
return new WRange(Exts.MakeArray(samples, _ => r.Next(-1024, 1024))
|
||||
return new WDist(Exts.MakeArray(samples, _ => r.Next(-1024, 1024))
|
||||
.Sum() / samples);
|
||||
}
|
||||
|
||||
public static bool TryParse(string s, out WRange result)
|
||||
public static bool TryParse(string s, out WDist result)
|
||||
{
|
||||
result = WRange.Zero;
|
||||
result = WDist.Zero;
|
||||
|
||||
if (string.IsNullOrEmpty(s))
|
||||
return false;
|
||||
@@ -84,32 +84,32 @@ namespace OpenRA
|
||||
if (cell < 0)
|
||||
subcell = -subcell;
|
||||
|
||||
result = new WRange(1024 * cell + subcell);
|
||||
result = new WDist(1024 * cell + subcell);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode() { return Range.GetHashCode(); }
|
||||
|
||||
public bool Equals(WRange other) { return other == this; }
|
||||
public override bool Equals(object obj) { return obj is WRange && Equals((WRange)obj); }
|
||||
public bool Equals(WDist other) { return other == this; }
|
||||
public override bool Equals(object obj) { return obj is WDist && Equals((WDist)obj); }
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (!(obj is WRange))
|
||||
if (!(obj is WDist))
|
||||
return 1;
|
||||
return Range.CompareTo(((WRange)obj).Range);
|
||||
return Range.CompareTo(((WDist)obj).Range);
|
||||
}
|
||||
|
||||
public int CompareTo(WRange other) { return Range.CompareTo(other.Range); }
|
||||
public int CompareTo(WDist other) { return Range.CompareTo(other.Range); }
|
||||
|
||||
public override string ToString() { return Range.ToString(); }
|
||||
|
||||
#region Scripting interface
|
||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||
{
|
||||
WRange a;
|
||||
WRange b;
|
||||
if (!left.TryGetClrValue<WRange>(out a) || !right.TryGetClrValue<WRange>(out b))
|
||||
WDist a;
|
||||
WDist b;
|
||||
if (!left.TryGetClrValue<WDist>(out a) || !right.TryGetClrValue<WDist>(out b))
|
||||
throw new LuaException("Attempted to call WRange.Add(WRange, WRange) with invalid arguments.");
|
||||
|
||||
return new LuaCustomClrObject(a + b);
|
||||
@@ -117,9 +117,9 @@ namespace OpenRA
|
||||
|
||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||
{
|
||||
WRange a;
|
||||
WRange b;
|
||||
if (!left.TryGetClrValue<WRange>(out a) || !right.TryGetClrValue<WRange>(out b))
|
||||
WDist a;
|
||||
WDist b;
|
||||
if (!left.TryGetClrValue<WDist>(out a) || !right.TryGetClrValue<WDist>(out b))
|
||||
throw new LuaException("Attempted to call WRange.Subtract(WRange, WRange) with invalid arguments.");
|
||||
|
||||
return new LuaCustomClrObject(a - b);
|
||||
@@ -127,9 +127,9 @@ namespace OpenRA
|
||||
|
||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||
{
|
||||
WRange a;
|
||||
WRange b;
|
||||
if (!left.TryGetClrValue<WRange>(out a) || !right.TryGetClrValue<WRange>(out b))
|
||||
WDist a;
|
||||
WDist b;
|
||||
if (!left.TryGetClrValue<WDist>(out a) || !right.TryGetClrValue<WDist>(out b))
|
||||
throw new LuaException("Attempted to call WRange.Equals(WRange, WRange) with invalid arguments.");
|
||||
|
||||
return a == b;
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA
|
||||
public readonly int X, Y, Z;
|
||||
|
||||
public WPos(int x, int y, int z) { X = x; Y = y; Z = z; }
|
||||
public WPos(WRange x, WRange y, WRange z) { X = x.Range; Y = y.Range; Z = z.Range; }
|
||||
public WPos(WDist x, WDist y, WDist z) { X = x.Range; Y = y.Range; Z = z.Range; }
|
||||
|
||||
public static readonly WPos Zero = new WPos(0, 0, 0);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA
|
||||
public readonly int X, Y, Z;
|
||||
|
||||
public WVec(int x, int y, int z) { X = x; Y = y; Z = z; }
|
||||
public WVec(WRange x, WRange y, WRange z) { X = x.Range; Y = y.Range; Z = z.Range; }
|
||||
public WVec(WDist x, WDist y, WDist z) { X = x.Range; Y = y.Range; Z = z.Range; }
|
||||
|
||||
public static readonly WVec Zero = new WVec(0, 0, 0);
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA
|
||||
// N samples approximates a true gaussian
|
||||
public static WVec FromPDF(MersenneTwister r, int samples)
|
||||
{
|
||||
return new WVec(WRange.FromPDF(r, samples), WRange.FromPDF(r, samples), WRange.Zero);
|
||||
return new WVec(WDist.FromPDF(r, samples), WDist.FromPDF(r, samples), WDist.Zero);
|
||||
}
|
||||
|
||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
|
||||
|
||||
@@ -30,12 +30,12 @@ namespace OpenRA
|
||||
return actors.MinByOrDefault(a => (a.CenterPosition - pos).LengthSquared);
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> FindActorsInCircle(this World world, WPos origin, WRange r)
|
||||
public static IEnumerable<Actor> FindActorsInCircle(this World world, WPos origin, WDist r)
|
||||
{
|
||||
using (new PerfSample("FindUnitsInCircle"))
|
||||
{
|
||||
// Target ranges are calculated in 2D, so ignore height differences
|
||||
var vec = new WVec(r, r, WRange.Zero);
|
||||
var vec = new WVec(r, r, WDist.Zero);
|
||||
return world.ActorMap.ActorsInBox(origin - vec, origin + vec).Where(
|
||||
a => (a.CenterPosition - origin).HorizontalLengthSquared <= r.RangeSquared);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user