Avoid landing-dances when issuing mixed full/empty aircraft RTB orders.
This commit is contained in:
@@ -19,10 +19,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public class HeliReturnToBase : Activity
|
public class HeliReturnToBase : Activity
|
||||||
{
|
{
|
||||||
readonly Aircraft heli;
|
readonly Aircraft heli;
|
||||||
|
readonly bool alwaysLand;
|
||||||
|
|
||||||
public HeliReturnToBase(Actor self)
|
public HeliReturnToBase(Actor self, bool alwaysLand = true)
|
||||||
{
|
{
|
||||||
heli = self.Trait<Aircraft>();
|
heli = self.Trait<Aircraft>();
|
||||||
|
this.alwaysLand = alwaysLand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Actor ChooseHelipad(Actor self)
|
public Actor ChooseHelipad(Actor self)
|
||||||
@@ -68,11 +70,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
heli.MakeReservation(dest);
|
|
||||||
|
|
||||||
var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault();
|
var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault();
|
||||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
||||||
|
|
||||||
|
if (ShouldLandAtBuilding(self, dest))
|
||||||
|
{
|
||||||
|
heli.MakeReservation(dest);
|
||||||
|
|
||||||
return ActivityUtils.SequenceActivities(
|
return ActivityUtils.SequenceActivities(
|
||||||
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
||||||
new Turn(self, initialFacing),
|
new Turn(self, initialFacing),
|
||||||
@@ -80,5 +84,22 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
new ResupplyAircraft(self),
|
new ResupplyAircraft(self),
|
||||||
NextActivity);
|
NextActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ActivityUtils.SequenceActivities(
|
||||||
|
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
||||||
|
NextActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShouldLandAtBuilding(Actor self, Actor dest)
|
||||||
|
{
|
||||||
|
if (alwaysLand)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (heli.Info.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return heli.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>()
|
||||||
|
.Any(p => !p.Info.SelfReloads && !p.FullAmmo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
readonly Aircraft plane;
|
readonly Aircraft plane;
|
||||||
readonly AircraftInfo planeInfo;
|
readonly AircraftInfo planeInfo;
|
||||||
|
readonly bool alwaysLand;
|
||||||
bool isCalculated;
|
bool isCalculated;
|
||||||
Actor dest;
|
Actor dest;
|
||||||
WPos w1, w2, w3;
|
WPos w1, w2, w3;
|
||||||
|
|
||||||
public ReturnToBase(Actor self, Actor dest = null)
|
public ReturnToBase(Actor self, Actor dest = null, bool alwaysLand = true)
|
||||||
{
|
{
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
|
this.alwaysLand = alwaysLand;
|
||||||
plane = self.Trait<Aircraft>();
|
plane = self.Trait<Aircraft>();
|
||||||
planeInfo = self.Info.TraitInfo<AircraftInfo>();
|
planeInfo = self.Info.TraitInfo<AircraftInfo>();
|
||||||
}
|
}
|
||||||
@@ -51,8 +53,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (dest == null)
|
if (dest == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
plane.MakeReservation(dest);
|
|
||||||
|
|
||||||
var landPos = dest.CenterPosition;
|
var landPos = dest.CenterPosition;
|
||||||
var altitude = planeInfo.CruiseAltitude.Length;
|
var altitude = planeInfo.CruiseAltitude.Length;
|
||||||
|
|
||||||
@@ -94,6 +94,18 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
isCalculated = true;
|
isCalculated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ShouldLandAtBuilding(Actor self, Actor dest)
|
||||||
|
{
|
||||||
|
if (alwaysLand)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (planeInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return planeInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>()
|
||||||
|
.Any(p => !p.Info.SelfReloads && !p.FullAmmo());
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceled || self.IsDead)
|
if (IsCanceled || self.IsDead)
|
||||||
@@ -128,8 +140,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// Fix a problem when the airplane is send to resupply near the airport
|
// Fix a problem when the airplane is send to resupply near the airport
|
||||||
landingProcedures.Add(new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)));
|
landingProcedures.Add(new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)));
|
||||||
|
|
||||||
|
if (ShouldLandAtBuilding(self, dest))
|
||||||
|
{
|
||||||
|
plane.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));
|
||||||
|
}
|
||||||
|
|
||||||
landingProcedures.Add(NextActivity);
|
landingProcedures.Add(NextActivity);
|
||||||
|
|
||||||
return ActivityUtils.SequenceActivities(landingProcedures.ToArray());
|
return ActivityUtils.SequenceActivities(landingProcedures.ToArray());
|
||||||
|
|||||||
@@ -618,9 +618,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
UnReserve();
|
UnReserve();
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
if (IsPlane)
|
if (IsPlane)
|
||||||
self.QueueActivity(new ReturnToBase(self));
|
self.QueueActivity(new ReturnToBase(self, null, false));
|
||||||
else
|
else
|
||||||
self.QueueActivity(new HeliReturnToBase(self));
|
self.QueueActivity(new HeliReturnToBase(self, false));
|
||||||
|
|
||||||
self.QueueActivity(new ResupplyAircraft(self));
|
self.QueueActivity(new ResupplyAircraft(self));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user