From e71001f4f8fe330b252627ad8300ca60c51da241 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 22 Aug 2019 01:32:55 +0200 Subject: [PATCH] Fix Resupply closeEnough bugs Fixes that - RepairableNear actors wouldn't move close enough - isCloseEnough would return 'true' even if the host is invalid. --- OpenRA.Mods.Common/Activities/Resupply.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Activities/Resupply.cs b/OpenRA.Mods.Common/Activities/Resupply.cs index cc5a81c8bf..566a941903 100644 --- a/OpenRA.Mods.Common/Activities/Resupply.cs +++ b/OpenRA.Mods.Common/Activities/Resupply.cs @@ -84,7 +84,20 @@ namespace OpenRA.Mods.Common.Activities } var isHostInvalid = host.Type != TargetType.Actor || !host.Actor.IsInWorld; - var isCloseEnough = closeEnough < WDist.Zero || (!isHostInvalid && (host.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= closeEnough.LengthSquared); + var isCloseEnough = false; + if (!isHostInvalid) + { + // Negative means there's no distance limit. + // If RepairableNear, use TargetablePositions instead of CenterPosition + // to ensure the actor moves close enough to the host. + // Otherwise check against host CenterPosition. + if (closeEnough < WDist.Zero) + isCloseEnough = true; + else if (repairableNear != null) + isCloseEnough = host.IsInRange(self.CenterPosition, closeEnough); + else + isCloseEnough = (host.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= closeEnough.LengthSquared; + } // This ensures transports are also cancelled when the host becomes invalid if (!IsCanceling && isHostInvalid)