From 3069bbfa7d662725d824549e8ceed3807a55e414 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 19 Mar 2018 01:52:08 +0100 Subject: [PATCH] Fix infinite loop in HeliReturnToBase 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. --- .../Activities/Air/HeliReturnToBase.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs index 253770ed6a..c0718334b5 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs @@ -59,8 +59,17 @@ namespace OpenRA.Mods.Common.Activities { 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;