diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index da5fe24388..23014489e8 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc new FacingInit(64) }); - a.QueueActivity(Fly.ToCell(self.Location + new CVec(9, 0))); + a.QueueActivity(new Fly(a, Target.FromCell(self.Location + new CVec(9, 0)))); a.QueueActivity(new Land(Target.FromActor(self))); a.QueueActivity(new CallFunc(() => { @@ -71,7 +71,8 @@ namespace OpenRA.Mods.Cnc self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit)); Sound.PlayNotification(self.Owner, "Speech", (Info as ProductionAirdropInfo).ReadyAudio, self.Owner.Country.Race); })); - a.QueueActivity(Fly.ToCell(endPos)); + + a.QueueActivity(new Fly(a, Target.FromCell(endPos))); a.QueueActivity(new RemoveSelf()); }); diff --git a/OpenRA.Mods.RA/Air/Fly.cs b/OpenRA.Mods.RA/Air/Fly.cs index 8ab14c0426..3dc05ccf67 100755 --- a/OpenRA.Mods.RA/Air/Fly.cs +++ b/OpenRA.Mods.RA/Air/Fly.cs @@ -16,8 +16,13 @@ namespace OpenRA.Mods.RA.Air public class Fly : Activity { readonly WPos pos; + readonly Plane plane; - Fly(WPos pos) { this.pos = pos; } + public Fly(Actor self, Target t) + { + plane = self.Trait(); + pos = t.CenterPosition; + } public static void FlyToward(Actor self, Plane plane, int desiredFacing, WRange desiredAltitude) { @@ -36,9 +41,6 @@ namespace OpenRA.Mods.RA.Air plane.SetPosition(self, plane.CenterPosition + move); } - public static Fly ToPos(WPos pos) { return new Fly(pos); } - public static Fly ToCell(CPos pos) { return new Fly(pos.CenterPosition); } - public override Activity Tick(Actor self) { if (IsCanceled) @@ -49,7 +51,6 @@ namespace OpenRA.Mods.RA.Air if (d.HorizontalLengthSquared < 91022) return NextActivity; - var plane = self.Trait(); var desiredFacing = Util.GetFacing(d, plane.Facing); // Don't turn until we've reached the cruise altitude diff --git a/OpenRA.Mods.RA/Air/FlyAttack.cs b/OpenRA.Mods.RA/Air/FlyAttack.cs index cb8ea4eea5..703a98ae8c 100755 --- a/OpenRA.Mods.RA/Air/FlyAttack.cs +++ b/OpenRA.Mods.RA/Air/FlyAttack.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Air if (IsCanceled) return NextActivity; - inner = Util.SequenceActivities(Fly.ToPos(target.CenterPosition), new FlyTimed(50)); + inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(50)); } inner = Util.RunActivity(self, inner); diff --git a/OpenRA.Mods.RA/Air/Plane.cs b/OpenRA.Mods.RA/Air/Plane.cs index f3cd5bb047..d74032880b 100755 --- a/OpenRA.Mods.RA/Air/Plane.cs +++ b/OpenRA.Mods.RA/Air/Plane.cs @@ -24,10 +24,12 @@ namespace OpenRA.Mods.RA.Air { public readonly PlaneInfo Info; [Sync] public WPos RTBPathHash; + Actor self; public Plane(ActorInitializer init, PlaneInfo info) : base(init, info) { + self = init.self; Info = info; } @@ -48,10 +50,11 @@ namespace OpenRA.Mods.RA.Air { UnReserve(); - var target = self.World.ClampToWorld(order.TargetLocation); - self.SetTargetLine(Target.FromCell(target), Color.Green); + var cell = self.World.ClampToWorld(order.TargetLocation); + var t = Target.FromCell(cell); + self.SetTargetLine(t, Color.Green); self.CancelActivity(); - self.QueueActivity(Fly.ToCell(target)); + self.QueueActivity(new Fly(self, t)); self.QueueActivity(new FlyCircle()); } else if (order.OrderString == "Enter") @@ -89,9 +92,9 @@ namespace OpenRA.Mods.RA.Air } } - public Activity MoveTo(CPos cell, int nearEnough) { return Fly.ToCell(cell); } - public Activity MoveTo(CPos cell, Actor ignoredActor) { return Fly.ToCell(cell); } - public Activity MoveWithinRange(Target target, WRange range) { return Fly.ToPos(target.CenterPosition); } + public Activity MoveTo(CPos cell, int nearEnough) { return new Fly(self, Target.FromCell(cell)); } + public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Fly(self, Target.FromCell(cell)); } + public Activity MoveWithinRange(Target target, WRange range) { return new Fly(self, target); } public CPos NearestMoveableCell(CPos cell) { return cell; } } } diff --git a/OpenRA.Mods.RA/Air/ReturnOnIdle.cs b/OpenRA.Mods.RA/Air/ReturnOnIdle.cs index 3b9ca48beb..c3e749dfbc 100755 --- a/OpenRA.Mods.RA/Air/ReturnOnIdle.cs +++ b/OpenRA.Mods.RA/Air/ReturnOnIdle.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Air return; } - self.QueueActivity(Fly.ToCell(someBuilding.Location)); + self.QueueActivity(new Fly(self, Target.FromActor(someBuilding))); self.QueueActivity(new FlyCircle()); } } diff --git a/OpenRA.Mods.RA/Air/ReturnToBase.cs b/OpenRA.Mods.RA/Air/ReturnToBase.cs index 69886209f5..9e241793ea 100755 --- a/OpenRA.Mods.RA/Air/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Air/ReturnToBase.cs @@ -110,15 +110,15 @@ namespace OpenRA.Mods.RA.Air self.CancelActivity(); if (nearestAfld != null) - return Util.SequenceActivities(Fly.ToCell(nearestAfld.Location), new FlyCircle()); + return Util.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle()); else return new FlyCircle(); } return Util.SequenceActivities( - Fly.ToPos(w1), - Fly.ToPos(w2), - Fly.ToPos(w3), + new Fly(self, Target.FromPos(w1)), + new Fly(self, Target.FromPos(w2)), + new Fly(self, Target.FromPos(w3)), new Land(Target.FromActor(dest)), NextActivity); } diff --git a/OpenRA.Mods.RA/Missions/DesertShellmapScript.cs b/OpenRA.Mods.RA/Missions/DesertShellmapScript.cs index 0dbdd64376..297f925690 100644 --- a/OpenRA.Mods.RA/Missions/DesertShellmapScript.cs +++ b/OpenRA.Mods.RA/Missions/DesertShellmapScript.cs @@ -206,7 +206,7 @@ namespace OpenRA.Mods.RA.Missions new FacingInit(Traits.Util.GetFacing(waypoints[1] - waypoints[0], 0)) }); foreach (var waypoint in waypoints) - m.QueueActivity(Fly.ToCell(waypoint)); + m.QueueActivity(new Fly(m, Target.FromCell(waypoint))); m.QueueActivity(new RemoveSelf()); } diff --git a/OpenRA.Mods.RA/Missions/MissionUtils.cs b/OpenRA.Mods.RA/Missions/MissionUtils.cs index f72c571e0d..9083eb54e3 100644 --- a/OpenRA.Mods.RA/Missions/MissionUtils.cs +++ b/OpenRA.Mods.RA/Missions/MissionUtils.cs @@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA.Missions }); badger.Trait().SetTarget(location.CenterPosition); - badger.QueueActivity(Fly.ToCell(location)); + badger.QueueActivity(new Fly(badger, Target.FromCell(location))); badger.QueueActivity(new FlyOffMap()); badger.QueueActivity(new RemoveSelf()); } diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs index 9c52a48dde..8f6b45605a 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs @@ -263,7 +263,7 @@ namespace OpenRA.Mods.RA.Scripting [LuaGlobal] public void FlyToPos(Actor actor, WPos pos) { - actor.QueueActivity(Fly.ToPos(pos)); + actor.QueueActivity(new Fly(actor, Target.FromPos(pos))); } [LuaGlobal] diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index 9ff9f55ee8..35a484a28f 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA if (flare != null) a.QueueActivity(new CallFunc(() => flare.Destroy())); - a.QueueActivity(Fly.ToPos(finishEdge + spawnOffset)); + a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset))); a.QueueActivity(new RemoveSelf()); } }); diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index 791cdf9c5f..722a504613 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA }); plane.CancelActivity(); - plane.QueueActivity(Fly.ToCell(order.TargetLocation)); + plane.QueueActivity(new Fly(plane, Target.FromCell(order.TargetLocation))); plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w => { var camera = w.CreateActor("camera", new TypeDictionary