From: Lyberta Date: Sun, 2 Apr 2017 15:04:23 +0000 (+0300) Subject: Survival: Better autobalance. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7b88452fcf89698c87e73f95722ad7d03a8da66e;p=xonotic%2Fxonotic-data.pk3dir.git Survival: Better autobalance. --- 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) {