From 9572376de057072afc067a73164638b57a5010a9 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 24 Aug 2016 16:59:34 +0100 Subject: [PATCH 1/2] Remove hardcoded constants from ProductionAirdrop. --- .../Traits/Buildings/ProductionAirdrop.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs index f444d8b6e9..49a79fa8a7 100644 --- a/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs @@ -31,17 +31,25 @@ namespace OpenRA.Mods.Cnc.Traits class ProductionAirdrop : Production { + readonly ProductionAirdropInfo info; public ProductionAirdrop(ActorInitializer init, ProductionAirdropInfo info) - : base(init, info) { } + : base(init, info) + { + this.info = info; + } public override bool Produce(Actor self, ActorInfo producee, string factionVariant) { var owner = self.Owner; + var aircraftInfo = self.World.Map.Rules.Actors[info.ActorType].TraitInfo(); + + // WDist required to take off or land + var landDistance = aircraftInfo.CruiseAltitude.Length * 1024 / aircraftInfo.MaximumPitch.Tan(); // Start a fixed distance away: the width of the map. // This makes the production timing independent of spawnpoint var startPos = self.Location + new CVec(owner.World.Map.Bounds.Width, 0); - var endPos = new CPos(owner.World.Map.Bounds.Left - 5, self.Location.Y); + var endPos = new CPos(owner.World.Map.Bounds.Left - 2 * landDistance / 1024, self.Location.Y); // Assume a single exit point for simplicity var exit = self.Info.TraitInfos().First(); @@ -49,23 +57,19 @@ namespace OpenRA.Mods.Cnc.Traits foreach (var tower in self.TraitsImplementing()) tower.IncomingDelivery(self); - var info = (ProductionAirdropInfo)Info; - var actorType = info.ActorType; - owner.World.AddFrameEndTask(w => { if (!self.IsInWorld || self.IsDead) return; - var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo().CruiseAltitude; - var actor = w.CreateActor(actorType, new TypeDictionary + var actor = w.CreateActor(info.ActorType, new TypeDictionary { - new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WDist.Zero, WDist.Zero, altitude)), + new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WDist.Zero, WDist.Zero, aircraftInfo.CruiseAltitude)), new OwnerInit(owner), new FacingInit(64) }); - actor.QueueActivity(new Fly(actor, Target.FromCell(w, self.Location + new CVec(12, 0)))); + actor.QueueActivity(new Fly(actor, Target.FromPos(self.CenterPosition + new WVec(landDistance, 0, 0)))); actor.QueueActivity(new Land(actor, Target.FromActor(self))); actor.QueueActivity(new CallFunc(() => { From 06ca8b6cf2e382d178d0eaa17c94c5d1cd23410c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 24 Aug 2016 17:20:07 +0100 Subject: [PATCH 2/2] Remove hardcoded constant from Fly. --- OpenRA.Mods.Common/Activities/Air/Fly.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index 69f22e6700..906f44acde 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -66,9 +66,11 @@ namespace OpenRA.Mods.Common.Activities if (insideMaxRange && !insideMinRange) return NextActivity; - // Close enough (ported from old code which checked length against sqrt(50) px) var d = target.CenterPosition - self.CenterPosition; - if (d.HorizontalLengthSquared < 91022) + + // The next move would overshoot, so consider it close enough + var move = plane.FlyStep(plane.Facing); + if (d.HorizontalLengthSquared < move.HorizontalLengthSquared) return NextActivity; // Don't turn until we've reached the cruise altitude