From f23985ac0f8f3f6cd9d164074ee6109aca67369b Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:09:25 -0700 Subject: [PATCH] Prevent repair droids refusing to retreat Repair droids that have the "Accept Retreating Units" suborder enabled now ignore other repair units when retreating. This prevents traffic jams when clusters of these units are attacked and then "retreat" to each other. Repair droids with the suborder disabled still retreat to units with the suborder enabled. --- src/order.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/order.cpp b/src/order.cpp index a5168d247da..0248df4f901 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -3349,25 +3349,33 @@ static inline RtrBestResult decideWhereToRepairAndBalance(DROID *psDroid) } } - // one of these lists is empty when on mission - DROID* psdroidList = apsDroidLists[psDroid->player] != nullptr ? apsDroidLists[psDroid->player] : mission.apsDroidLists[psDroid->player]; - for (DROID* psCurr = psdroidList; psCurr != nullptr; psCurr = psCurr->psNext) + // If we are repair droid ourselves that accept retreating units, don't consider + // other repairs droids. Since this would cause traffic jams if we are attacked amongst + // other accepting repair droids. Thus causing chaos as repair units simply clump up + // instead of actually retreating. + if (!((psDroid->droidType == DROID_REPAIR || psDroid->droidType == DROID_CYBORG_REPAIR) + && secondaryGetState(psDroid, DSO_ACCEPT_RETREP))) { - // Accept any repair droids that accept retreating units - if ((psCurr->droidType == DROID_REPAIR || psCurr->droidType == DROID_CYBORG_REPAIR) - && secondaryGetState(psCurr, DSO_ACCEPT_RETREP)) + // one of these lists is empty when on mission + DROID* psdroidList = apsDroidLists[psDroid->player] != nullptr ? apsDroidLists[psDroid->player] : mission.apsDroidLists[psDroid->player]; + for (DROID* psCurr = psdroidList; psCurr != nullptr; psCurr = psCurr->psNext) { - thisDistToRepair = droidSqDist(psDroid, psCurr); - if (thisDistToRepair <= 0) - { - continue; // unreachable - } - vDroidPos.push_back(psCurr->pos); - vDroid.push_back(psCurr); - if (bestDistToRepairDroid > thisDistToRepair) + // Accept any repair droids that accept retreating units + if ((psCurr->droidType == DROID_REPAIR || psCurr->droidType == DROID_CYBORG_REPAIR) + && secondaryGetState(psCurr, DSO_ACCEPT_RETREP)) { - bestDistToRepairDroid = thisDistToRepair; - bestDroidPos = psCurr->pos; + thisDistToRepair = droidSqDist(psDroid, psCurr); + if (thisDistToRepair <= 0) + { + continue; // unreachable + } + vDroidPos.push_back(psCurr->pos); + vDroid.push_back(psCurr); + if (bestDistToRepairDroid > thisDistToRepair) + { + bestDistToRepairDroid = thisDistToRepair; + bestDroidPos = psCurr->pos; + } } } }