Avoid landing-dances when issuing mixed full/empty aircraft RTB orders.

This commit is contained in:
Paul Chote
2016-09-18 14:11:29 +01:00
parent 2d00a24855
commit eeaa461311
3 changed files with 53 additions and 13 deletions

View File

@@ -19,10 +19,12 @@ namespace OpenRA.Mods.Common.Activities
public class HeliReturnToBase : Activity
{
readonly Aircraft heli;
readonly bool alwaysLand;
public HeliReturnToBase(Actor self)
public HeliReturnToBase(Actor self, bool alwaysLand = true)
{
heli = self.Trait<Aircraft>();
this.alwaysLand = alwaysLand;
}
public Actor ChooseHelipad(Actor self)
@@ -68,17 +70,36 @@ namespace OpenRA.Mods.Common.Activities
}
}
heli.MakeReservation(dest);
var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault();
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
if (ShouldLandAtBuilding(self, dest))
{
heli.MakeReservation(dest);
return ActivityUtils.SequenceActivities(
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
new Turn(self, initialFacing),
new HeliLand(self, false),
new ResupplyAircraft(self),
NextActivity);
}
return ActivityUtils.SequenceActivities(
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
new Turn(self, initialFacing),
new HeliLand(self, false),
new ResupplyAircraft(self),
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());
}
}
}