Skip to content

Commit

Permalink
Sort -> SortPredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyShorokhov committed Dec 15, 2023
1 parent 370781b commit 01e64de
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5395,27 +5395,26 @@ void CHalfLifeMultiplay::GiveDefuserToRandomPlayer()

candidates.AddToTail(pPlayer);
}

// randomly shuffle the list; this will keep the selection random in case of ties
for (int i = 0; i < candidates.Count(); i++) {
SWAP(candidates[i], candidates[RANDOM_LONG(0, candidates.Count() - 1)]);
}

// now sort the shuffled list into subgroups
candidates.Sort([](CBasePlayer *const *left, CBasePlayer *const *right) -> int {
// should we prioritize humans over bots?
if (cv_bot_defer_to_human.value != 0.0f)
{
if ((*left)->IsBot() && !(*right)->IsBot())
return 1;

if (!(*left)->IsBot() && (*right)->IsBot())
return -1;
}
candidates.SortPredicate([](const CBasePlayer &pl1, const CBasePlayer &pl2) {
// should we prioritize humans over bots?
if (cv_bot_defer_to_human.value != 0.0f)
{
if (pl1.IsBot() && !pl2.IsBot())
return true;

return 0;
if (!pl1.IsBot() && pl2.IsBot())
return false;
}
);

return true;
});

// give defusers to the first N candidates
for (int i = 0; i < iDefusersToGive && i < candidates.Count(); ++i)
Expand Down

0 comments on commit 01e64de

Please sign in to comment.