Skip to content

Commit

Permalink
Fix infinite loop in HeliReturnToBase
Browse files Browse the repository at this point in the history
This can happen if HeliAttack tells the heli to return to base when the player doesn't have any of the RearmBuildings available, because the activity queues itself after the HRTB, and the latter will, after a forced land, then queue back HeliAttack, which then immediately queues back HRTB and so on.

Instead, we now assume that if there is no base to return to, going to NextActivity is pointless and don't queue NextActivity.
RTB was likely ordered by HeliAttack due to lack of ammo, so resuming the attack would be pointless.
  • Loading branch information
reaperrr committed Mar 22, 2018
1 parent b383b9a commit 24f44ba
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs
Expand Up @@ -59,8 +59,17 @@ public override Activity Tick(Actor self)
{
var nearestHpad = ChooseHelipad(self, false);

if (nearestHpad == null)
return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity);
// 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 (heli.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)
return null;
else
{
var distanceFromHelipad = (nearestHpad.CenterPosition - self.CenterPosition).HorizontalLength;
Expand Down

0 comments on commit 24f44ba

Please sign in to comment.