From 9a19e21cd546a5122523799d80f33e560404a65a Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Tue, 4 Aug 2026 14:10:02 -0300 Subject: [PATCH] prefer happy path to recursion with double execution there's no return after recursion, so the tail of the function runs twice --- Strategic/Strategic Movement.cpp | 48 +++++++++++++++----------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/Strategic/Strategic Movement.cpp b/Strategic/Strategic Movement.cpp index 9e8c241bf..eec250229 100644 --- a/Strategic/Strategic Movement.cpp +++ b/Strategic/Strategic Movement.cpp @@ -4628,33 +4628,31 @@ void RetreatGroupToPreviousSector( GROUP *pGroup ) Assert( pGroup ); AssertMsg( !pGroup->fBetweenSectors, "Can't retreat a group when between sectors!" ); - if( pGroup->ubPrevX != 16 || pGroup->ubPrevY != 16 ) - { //Group has a previous sector - pGroup->ubNextX = pGroup->ubPrevX; - pGroup->ubNextY = pGroup->ubPrevY; - - //Determine the correct direction. - dx = pGroup->ubNextX - pGroup->ubSectorX; - dy = pGroup->ubNextY - pGroup->ubSectorY; - if( dy == -1 && !dx ) - ubDirection = NORTH_STRATEGIC_MOVE; - else if( dx == 1 && !dy ) - ubDirection = EAST_STRATEGIC_MOVE; - else if( dy == 1 && !dx ) - ubDirection = SOUTH_STRATEGIC_MOVE; - else if( dx == -1 && !dy ) - ubDirection = WEST_STRATEGIC_MOVE; - else - { - - AssertMsg( 0, String("Player group attempting illegal retreat from %c%d to %c%d.", - pGroup->ubSectorY+'A'-1, pGroup->ubSectorX, pGroup->ubNextY+'A'-1, pGroup->ubNextX ) ); - } + if (pGroup->ubPrevX == 16 && pGroup->ubPrevY == 16) + { + //Group doesn't have a previous sector. Create one. + CalculateGroupRetreatSector(pGroup); } + + pGroup->ubNextX = pGroup->ubPrevX; + pGroup->ubNextY = pGroup->ubPrevY; + + //Determine the correct direction. + dx = pGroup->ubNextX - pGroup->ubSectorX; + dy = pGroup->ubNextY - pGroup->ubSectorY; + if( dy == -1 && !dx ) + ubDirection = NORTH_STRATEGIC_MOVE; + else if( dx == 1 && !dy ) + ubDirection = EAST_STRATEGIC_MOVE; + else if( dy == 1 && !dx ) + ubDirection = SOUTH_STRATEGIC_MOVE; + else if( dx == -1 && !dy ) + ubDirection = WEST_STRATEGIC_MOVE; else - { //Group doesn't have a previous sector. Create one, then recurse - CalculateGroupRetreatSector( pGroup ); - RetreatGroupToPreviousSector( pGroup ); + { + + AssertMsg( 0, String("Player group attempting illegal retreat from %c%d to %c%d.", + pGroup->ubSectorY+'A'-1, pGroup->ubSectorX, pGroup->ubNextY+'A'-1, pGroup->ubNextX ) ); } //Calc time to get to next waypoint...