Generalize *ReturnToBase trait caching naming

Makes both copying changes as well as a potential future activity merger a little easier.
This commit is contained in:
reaperrr
2017-11-13 23:03:48 +01:00
committed by reaperrr
parent bd569c9ae2
commit 96032d1953
2 changed files with 29 additions and 29 deletions

View File

@@ -18,14 +18,14 @@ namespace OpenRA.Mods.Common.Activities
{ {
public class HeliReturnToBase : Activity public class HeliReturnToBase : Activity
{ {
readonly Aircraft heli; readonly Aircraft aircraft;
readonly bool alwaysLand; readonly bool alwaysLand;
readonly bool abortOnResupply; readonly bool abortOnResupply;
Actor dest; Actor dest;
public HeliReturnToBase(Actor self, bool abortOnResupply, Actor dest = null, bool alwaysLand = true) public HeliReturnToBase(Actor self, bool abortOnResupply, Actor dest = null, bool alwaysLand = true)
{ {
heli = self.Trait<Aircraft>(); aircraft = self.Trait<Aircraft>();
this.alwaysLand = alwaysLand; this.alwaysLand = alwaysLand;
this.abortOnResupply = abortOnResupply; this.abortOnResupply = abortOnResupply;
this.dest = dest; this.dest = dest;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
public Actor ChooseHelipad(Actor self, bool unreservedOnly) 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 return self.World.Actors.Where(a => a.Owner == self.Owner
&& rearmBuildings.Contains(a.Info.Name) && rearmBuildings.Contains(a.Info.Name)
&& (!unreservedOnly || !Reservable.IsReserved(a))) && (!unreservedOnly || !Reservable.IsReserved(a)))
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
{ {
// Refuse to take off if it would land immediately again. // Refuse to take off if it would land immediately again.
// Special case: Don't kill other deploy hotkey activities. // Special case: Don't kill other deploy hotkey activities.
if (heli.ForceLanding) if (aircraft.ForceLanding)
return NextActivity; return NextActivity;
if (IsCanceled) if (IsCanceled)
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Activities
if (dest == null || dest.IsDead || Reservable.IsReserved(dest)) if (dest == null || dest.IsDead || Reservable.IsReserved(dest))
dest = ChooseHelipad(self, true); dest = ChooseHelipad(self, true);
var initialFacing = heli.Info.InitialFacing; var initialFacing = aircraft.Info.InitialFacing;
if (dest == null || dest.IsDead) 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) // 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. // 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 ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true));
return 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; return null;
else else
{ {
var distanceFromHelipad = (nearestHpad.CenterPosition - self.CenterPosition).HorizontalLength; 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 no pad is available, move near one and wait
if (distanceFromHelipad > distanceLength) if (distanceFromHelipad > distanceLength)
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities
var target = Target.FromPos(nearestHpad.CenterPosition + randomPosition); 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; return this;
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Activities
if (ShouldLandAtBuilding(self, dest)) if (ShouldLandAtBuilding(self, dest))
{ {
heli.MakeReservation(dest); aircraft.MakeReservation(dest);
return ActivityUtils.SequenceActivities( return ActivityUtils.SequenceActivities(
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)), new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
@@ -114,10 +114,10 @@ namespace OpenRA.Mods.Common.Activities
if (alwaysLand) if (alwaysLand)
return true; 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 true;
return heli.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>() return aircraft.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>()
.Any(p => !p.AutoReloads && !p.FullAmmo()); .Any(p => !p.AutoReloads && !p.FullAmmo());
} }
} }

View File

@@ -20,8 +20,8 @@ namespace OpenRA.Mods.Common.Activities
{ {
public class ReturnToBase : Activity public class ReturnToBase : Activity
{ {
readonly Aircraft plane; readonly Aircraft aircraft;
readonly AircraftInfo planeInfo; readonly AircraftInfo aircraftInfo;
readonly bool alwaysLand; readonly bool alwaysLand;
readonly bool abortOnResupply; readonly bool abortOnResupply;
bool isCalculated; bool isCalculated;
@@ -33,8 +33,8 @@ namespace OpenRA.Mods.Common.Activities
this.dest = dest; this.dest = dest;
this.alwaysLand = alwaysLand; this.alwaysLand = alwaysLand;
this.abortOnResupply = abortOnResupply; this.abortOnResupply = abortOnResupply;
plane = self.Trait<Aircraft>(); aircraft = self.Trait<Aircraft>();
planeInfo = self.Info.TraitInfo<AircraftInfo>(); aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
} }
public static Actor ChooseAirfield(Actor self, bool unreservedOnly) public static Actor ChooseAirfield(Actor self, bool unreservedOnly)
@@ -56,20 +56,20 @@ namespace OpenRA.Mods.Common.Activities
return; return;
var landPos = dest.CenterPosition; var landPos = dest.CenterPosition;
var altitude = planeInfo.CruiseAltitude.Length; var altitude = aircraftInfo.CruiseAltitude.Length;
// Distance required for descent. // Distance required for descent.
var landDistance = altitude * 1024 / planeInfo.MaximumPitch.Tan(); var landDistance = altitude * 1024 / aircraftInfo.MaximumPitch.Tan();
// Land towards the east // Land towards the east
var approachStart = landPos + new WVec(-landDistance, 0, altitude); var approachStart = landPos + new WVec(-landDistance, 0, altitude);
// Add 10% to the turning radius to ensure we have enough room // 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); var turnRadius = CalculateTurnRadius(speed);
// Find the center of the turning circles for clockwise and counterclockwise turns // 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); var fwd = -new WVec(angle.Sin(), angle.Cos(), 0);
// Work out whether we should turn clockwise or counter-clockwise for approach // Work out whether we should turn clockwise or counter-clockwise for approach
@@ -101,10 +101,10 @@ namespace OpenRA.Mods.Common.Activities
if (alwaysLand) if (alwaysLand)
return true; 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 true;
return planeInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>() return aircraftInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>()
.Any(p => !p.AutoReloads && !p.FullAmmo()); .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. // Refuse to take off if it would land immediately again.
// Special case: Don't kill other deploy hotkey activities. // Special case: Don't kill other deploy hotkey activities.
if (plane.ForceLanding) if (aircraft.ForceLanding)
return NextActivity; return NextActivity;
if (IsCanceled || self.IsDead) if (IsCanceled || self.IsDead)
@@ -127,8 +127,8 @@ namespace OpenRA.Mods.Common.Activities
if (nearestAfld != null) if (nearestAfld != null)
return ActivityUtils.SequenceActivities( return ActivityUtils.SequenceActivities(
new Fly(self, Target.FromActor(nearestAfld), WDist.Zero, plane.Info.WaitDistanceFromResupplyBase), new Fly(self, Target.FromActor(nearestAfld), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase),
new FlyCircle(self, plane.Info.NumberOfTicksToVerifyAvailableAirport), new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport),
this); this);
else else
{ {
@@ -140,7 +140,7 @@ namespace OpenRA.Mods.Common.Activities
List<Activity> landingProcedures = new List<Activity>(); List<Activity> landingProcedures = new List<Activity>();
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(w1), WDist.Zero, new WDist(turnRadius * 3)));
landingProcedures.Add(new Fly(self, Target.FromPos(w2))); landingProcedures.Add(new Fly(self, Target.FromPos(w2)));
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Activities
if (ShouldLandAtBuilding(self, dest)) if (ShouldLandAtBuilding(self, dest))
{ {
plane.MakeReservation(dest); aircraft.MakeReservation(dest);
landingProcedures.Add(new Land(self, Target.FromActor(dest))); landingProcedures.Add(new Land(self, Target.FromActor(dest)));
landingProcedures.Add(new ResupplyAircraft(self)); landingProcedures.Add(new ResupplyAircraft(self));
@@ -164,7 +164,7 @@ namespace OpenRA.Mods.Common.Activities
int CalculateTurnRadius(int speed) int CalculateTurnRadius(int speed)
{ {
return 45 * speed / planeInfo.TurnSpeed; return 45 * speed / aircraftInfo.TurnSpeed;
} }
} }
} }