Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent repair droids refusing to retreat #3402

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
Loading