From 89fd889cf4d9f96017c6493717da13853ed0d183 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 7 Jul 2013 10:30:09 +1200 Subject: [PATCH] Convert Target positions to world coords. --- OpenRA.Game/Traits/Target.cs | 13 +++++++------ OpenRA.Mods.RA/Buildings/Building.cs | 2 +- OpenRA.Mods.RA/Combat.cs | 2 +- OpenRA.Mods.RA/Missions/Allies04Script.cs | 2 +- OpenRA.Mods.RA/Move/Drag.cs | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/Traits/Target.cs b/OpenRA.Game/Traits/Target.cs index 43a8efec68..fa9424d47f 100644 --- a/OpenRA.Game/Traits/Target.cs +++ b/OpenRA.Game/Traits/Target.cs @@ -19,7 +19,7 @@ namespace OpenRA.Traits public static readonly Target[] NoTargets = {}; Actor actor; - PPos pos; + WPos pos; bool valid; int generation; @@ -32,8 +32,9 @@ namespace OpenRA.Traits generation = a.Generation, }; } - public static Target FromPos(PPos p) { return new Target { pos = p, valid = true }; } - public static Target FromCell(CPos c) { return new Target { pos = Util.CenterOfCell(c), valid = true }; } + public static Target FromPos(WPos p) { return new Target { pos = p, valid = true }; } + public static Target FromPos(PPos p) { return new Target { pos = p.ToWPos(0), valid = true }; } + public static Target FromCell(CPos c) { return new Target { pos = c.CenterPosition, valid = true }; } public static Target FromOrder(Order o) { return o.TargetActor != null @@ -44,7 +45,7 @@ namespace OpenRA.Traits public static readonly Target None = new Target(); public bool IsValid { get { return valid && (actor == null || (actor.IsInWorld && !actor.IsDead() && actor.Generation == generation)); } } - public PPos PxPosition { get { return IsActor ? actor.Trait().PxPosition : pos; } } + public PPos PxPosition { get { return IsActor ? actor.Trait().PxPosition : PPos.FromWPos(pos); } } public PPos CenterLocation { get { return PxPosition; } } // Representative position - see Positions for the full set of targetable positions. @@ -55,7 +56,7 @@ namespace OpenRA.Traits if (!IsValid) throw new InvalidOperationException("Attempting to query the position of an invalid Target"); - return actor != null ? actor.CenterPosition : pos.ToWPos(0); + return actor != null ? actor.CenterPosition : pos; } } @@ -69,7 +70,7 @@ namespace OpenRA.Traits return NoPositions; if (actor == null) - return new []{pos.ToWPos(0)}; + return new []{pos}; var targetable = actor.TraitOrDefault(); if (targetable == null) diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index dbe8fda472..057523555e 100755 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Buildings continue; // Range is counted from the center of the actor, not from each cell. - var target = Target.FromPos(bp.Actor.CenterLocation); + var target = Target.FromPos(bp.Actor.CenterPosition); if (target.IsInRange(center, WRange.FromCells(bp.Trait.Info.Range))) return bp.Actor; } diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 82190f8310..390ab54a65 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -150,7 +150,7 @@ namespace OpenRA.Mods.RA srcAltitude = altitude, destAltitude = altitude, firedBy = attacker, - target = Target.FromPos(pxPos), + target = Target.FromPos(pos), weapon = Rules.Weapons[weapontype.ToLowerInvariant()], facing = 0 }; diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index d89c7085e2..ba65084906 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -125,7 +125,7 @@ namespace OpenRA.Mods.RA.Missions if (world.FrameNumber == frameInfiltrated + 1500 * 12 && !bridgeTank.IsDead() && bridgeTank.IsInWorld && !bridge.IsDead()) { - bridgeTank.QueueActivity(new Attack(Target.FromPos(bridge.CenterLocation), WRange.FromCells(4))); + bridgeTank.QueueActivity(new Attack(Target.FromPos(bridge.CenterPosition), WRange.FromCells(4))); attackingBridge = true; } if (attackingBridge && bridge.IsDead()) diff --git a/OpenRA.Mods.RA/Move/Drag.cs b/OpenRA.Mods.RA/Move/Drag.cs index abfaf89392..307f71b5ee 100755 --- a/OpenRA.Mods.RA/Move/Drag.cs +++ b/OpenRA.Mods.RA/Move/Drag.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Move public override IEnumerable GetTargets( Actor self ) { - yield return Target.FromPos(PPos.FromWPos(end)); + yield return Target.FromPos(end); } // Cannot be cancelled