From 7b88452fcf89698c87e73f95722ad7d03a8da66e Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sun, 2 Apr 2017 18:04:23 +0300 Subject: [PATCH] Survival: Better autobalance. --- .../mutators/mutator/gamemode_survival.qc | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/qcsrc/server/mutators/mutator/gamemode_survival.qc b/qcsrc/server/mutators/mutator/gamemode_survival.qc index 38d3cf6da..5b138c588 100644 --- a/qcsrc/server/mutators/mutator/gamemode_survival.qc +++ b/qcsrc/server/mutators/mutator/gamemode_survival.qc @@ -1436,6 +1436,37 @@ MUTATOR_HOOKFUNCTION(surv, CheckAllowedTeams, CBC_ORDER_EXCLUSIVE) M_ARGV(0, float) = teambits; } +/// \brief Hook that determines the best team for the player to join. +MUTATOR_HOOKFUNCTION(surv, JoinBestTeam, CBC_ORDER_EXCLUSIVE) +{ + entity player = M_ARGV(0, entity); + if (IS_BOT_CLIENT(player)) + { + return; + } + int numattackerhumans = surv_numattackerhumans; + int numdefenderhumans = surv_numdefenderhumans; + if (player.team == surv_attackerteam) + { + --numattackerhumans; + } + else if (player.team == surv_defenderteam) + { + --numdefenderhumans; + } + if (numattackerhumans < numdefenderhumans) + { + M_ARGV(1, float) = Team_TeamToNumber(surv_attackerteam); + return; + } + if (numattackerhumans > numdefenderhumans) + { + M_ARGV(1, float) = Team_TeamToNumber(surv_defenderteam); + return; + } + M_ARGV(1, float) = floor(random() * 2) + 1; +} + /// \brief Hook that is called when player has changed the team. MUTATOR_HOOKFUNCTION(surv, Player_ChangedTeam) { -- 2.39.5