From 96032d195366e0f58c8a1f422d782cb36928a527 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 13 Nov 2017 23:03:48 +0100 Subject: [PATCH] Generalize *ReturnToBase trait caching naming Makes both copying changes as well as a potential future activity merger a little easier. --- .../Activities/Air/HeliReturnToBase.cs | 26 +++++++-------- .../Activities/Air/ReturnToBase.cs | 32 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs index c0718334b5..385469e69f 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs @@ -18,14 +18,14 @@ namespace OpenRA.Mods.Common.Activities { public class HeliReturnToBase : Activity { - readonly Aircraft heli; + readonly Aircraft aircraft; readonly bool alwaysLand; readonly bool abortOnResupply; Actor dest; public HeliReturnToBase(Actor self, bool abortOnResupply, Actor dest = null, bool alwaysLand = true) { - heli = self.Trait(); + aircraft = self.Trait(); this.alwaysLand = alwaysLand; this.abortOnResupply = abortOnResupply; this.dest = dest; @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities public Actor ChooseHelipad(Actor self, bool unreservedOnly) { - var rearmBuildings = heli.Info.RearmBuildings; + var rearmBuildings = aircraft.Info.RearmBuildings; return self.World.Actors.Where(a => a.Owner == self.Owner && rearmBuildings.Contains(a.Info.Name) && (!unreservedOnly || !Reservable.IsReserved(a))) @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities { // Refuse to take off if it would land immediately again. // Special case: Don't kill other deploy hotkey activities. - if (heli.ForceLanding) + if (aircraft.ForceLanding) return NextActivity; if (IsCanceled) @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Activities if (dest == null || dest.IsDead || Reservable.IsReserved(dest)) dest = ChooseHelipad(self, true); - var initialFacing = heli.Info.InitialFacing; + var initialFacing = aircraft.Info.InitialFacing; if (dest == null || dest.IsDead) { @@ -61,19 +61,19 @@ namespace OpenRA.Mods.Common.Activities // If a heli was told to return and there's no (available) RearmBuilding, going to the probable next queued activity (HeliAttack) // would be pointless (due to lack of ammo), and possibly even lead to an infinite loop due to HeliAttack.cs:L79. - if (nearestHpad == null && heli.Info.LandWhenIdle) + if (nearestHpad == null && aircraft.Info.LandWhenIdle) { - if (heli.Info.TurnToLand) + if (aircraft.Info.TurnToLand) return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true)); return new HeliLand(self, true); } - else if (nearestHpad == null && !heli.Info.LandWhenIdle) + else if (nearestHpad == null && !aircraft.Info.LandWhenIdle) return null; else { var distanceFromHelipad = (nearestHpad.CenterPosition - self.CenterPosition).HorizontalLength; - var distanceLength = heli.Info.WaitDistanceFromResupplyBase.Length; + var distanceLength = aircraft.Info.WaitDistanceFromResupplyBase.Length; // If no pad is available, move near one and wait if (distanceFromHelipad > distanceLength) @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities var target = Target.FromPos(nearestHpad.CenterPosition + randomPosition); - return ActivityUtils.SequenceActivities(new HeliFly(self, target, WDist.Zero, heli.Info.WaitDistanceFromResupplyBase), this); + return ActivityUtils.SequenceActivities(new HeliFly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase), this); } return this; @@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Activities if (ShouldLandAtBuilding(self, dest)) { - heli.MakeReservation(dest); + aircraft.MakeReservation(dest); return ActivityUtils.SequenceActivities( new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)), @@ -114,10 +114,10 @@ namespace OpenRA.Mods.Common.Activities if (alwaysLand) return true; - if (heli.Info.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) + if (aircraft.Info.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) return true; - return heli.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing() + return aircraft.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing() .Any(p => !p.AutoReloads && !p.FullAmmo()); } } diff --git a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs index 44d6c4036d..e9371c6697 100644 --- a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs @@ -20,8 +20,8 @@ namespace OpenRA.Mods.Common.Activities { public class ReturnToBase : Activity { - readonly Aircraft plane; - readonly AircraftInfo planeInfo; + readonly Aircraft aircraft; + readonly AircraftInfo aircraftInfo; readonly bool alwaysLand; readonly bool abortOnResupply; bool isCalculated; @@ -33,8 +33,8 @@ namespace OpenRA.Mods.Common.Activities this.dest = dest; this.alwaysLand = alwaysLand; this.abortOnResupply = abortOnResupply; - plane = self.Trait(); - planeInfo = self.Info.TraitInfo(); + aircraft = self.Trait(); + aircraftInfo = self.Info.TraitInfo(); } public static Actor ChooseAirfield(Actor self, bool unreservedOnly) @@ -56,20 +56,20 @@ namespace OpenRA.Mods.Common.Activities return; var landPos = dest.CenterPosition; - var altitude = planeInfo.CruiseAltitude.Length; + var altitude = aircraftInfo.CruiseAltitude.Length; // Distance required for descent. - var landDistance = altitude * 1024 / planeInfo.MaximumPitch.Tan(); + var landDistance = altitude * 1024 / aircraftInfo.MaximumPitch.Tan(); // Land towards the east var approachStart = landPos + new WVec(-landDistance, 0, altitude); // Add 10% to the turning radius to ensure we have enough room - var speed = plane.MovementSpeed * 32 / 35; + var speed = aircraft.MovementSpeed * 32 / 35; var turnRadius = CalculateTurnRadius(speed); // Find the center of the turning circles for clockwise and counterclockwise turns - var angle = WAngle.FromFacing(plane.Facing); + var angle = WAngle.FromFacing(aircraft.Facing); var fwd = -new WVec(angle.Sin(), angle.Cos(), 0); // Work out whether we should turn clockwise or counter-clockwise for approach @@ -101,10 +101,10 @@ namespace OpenRA.Mods.Common.Activities if (alwaysLand) return true; - if (planeInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) + if (aircraftInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) return true; - return planeInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing() + return aircraftInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing() .Any(p => !p.AutoReloads && !p.FullAmmo()); } @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Activities { // Refuse to take off if it would land immediately again. // Special case: Don't kill other deploy hotkey activities. - if (plane.ForceLanding) + if (aircraft.ForceLanding) return NextActivity; if (IsCanceled || self.IsDead) @@ -127,8 +127,8 @@ namespace OpenRA.Mods.Common.Activities if (nearestAfld != null) return ActivityUtils.SequenceActivities( - new Fly(self, Target.FromActor(nearestAfld), WDist.Zero, plane.Info.WaitDistanceFromResupplyBase), - new FlyCircle(self, plane.Info.NumberOfTicksToVerifyAvailableAirport), + new Fly(self, Target.FromActor(nearestAfld), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase), + new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport), this); else { @@ -140,7 +140,7 @@ namespace OpenRA.Mods.Common.Activities List landingProcedures = new List(); - var turnRadius = CalculateTurnRadius(planeInfo.Speed); + var turnRadius = CalculateTurnRadius(aircraftInfo.Speed); landingProcedures.Add(new Fly(self, Target.FromPos(w1), WDist.Zero, new WDist(turnRadius * 3))); landingProcedures.Add(new Fly(self, Target.FromPos(w2))); @@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Activities if (ShouldLandAtBuilding(self, dest)) { - plane.MakeReservation(dest); + aircraft.MakeReservation(dest); landingProcedures.Add(new Land(self, Target.FromActor(dest))); landingProcedures.Add(new ResupplyAircraft(self)); @@ -164,7 +164,7 @@ namespace OpenRA.Mods.Common.Activities int CalculateTurnRadius(int speed) { - return 45 * speed / planeInfo.TurnSpeed; + return 45 * speed / aircraftInfo.TurnSpeed; } } }