From: Lyberta Date: Mon, 9 Apr 2018 01:35:41 +0000 (+0300) Subject: Survival: Updated to new autobalance API. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bb23524f541a5c56b9a055070bb4c0d86e6db9e6;p=xonotic%2Fxonotic-data.pk3dir.git Survival: Updated to new autobalance API. --- diff --git a/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc b/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc index 049087998..fa07ce624 100644 --- a/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc +++ b/qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc @@ -1660,36 +1660,6 @@ MUTATOR_HOOKFUNCTION(surv, TeamBalance_GetTeamCount, CBC_ORDER_EXCLUSIVE) --M_ARGV(3, float); } } - entity lowest_player = NULL; - float lowest_player_score = FLOAT_MAX; - entity lowest_bot = NULL; - float lowest_bot_score = FLOAT_MAX; - FOREACH_CLIENT(Surv_IsPlayerAttacker(it) && (it.surv_role == - SURVIVAL_ROLE_PLAYER), - { - if (it == ignore) - { - continue; - } - if (IS_BOT_CLIENT(it)) - { - float temp_score = PlayerScore_Get(it, SP_SCORE); - if (temp_score < lowest_bot_score) - { - lowest_bot = it; - lowest_bot_score = temp_score; - continue; - } - } - float temp_score = PlayerScore_Get(it, SP_SCORE); - if (temp_score < lowest_player_score) - { - lowest_player = it; - lowest_player_score = temp_score; - } - }); - M_ARGV(4, entity) = lowest_player; - M_ARGV(5, entity) = lowest_bot; break; } case surv_defender_team: @@ -1704,35 +1674,6 @@ MUTATOR_HOOKFUNCTION(surv, TeamBalance_GetTeamCount, CBC_ORDER_EXCLUSIVE) --M_ARGV(3, float); } } - entity lowest_player = NULL; - float lowest_player_score = FLOAT_MAX; - entity lowest_bot = NULL; - float lowest_bot_score = FLOAT_MAX; - FOREACH_CLIENT(Surv_IsPlayerDefender(it), - { - if (it == ignore) - { - continue; - } - if (IS_BOT_CLIENT(it)) - { - float temp_score = PlayerScore_Get(it, SP_SCORE); - if (temp_score < lowest_bot_score) - { - lowest_bot = it; - lowest_bot_score = temp_score; - continue; - } - } - float temp_score = PlayerScore_Get(it, SP_SCORE); - if (temp_score < lowest_player_score) - { - lowest_player = it; - lowest_player_score = temp_score; - } - }); - M_ARGV(4, entity) = lowest_player; - M_ARGV(5, entity) = lowest_bot; break; } } @@ -1775,6 +1716,52 @@ MUTATOR_HOOKFUNCTION(surv, TeamBalance_FindBestTeams, CBC_ORDER_EXCLUSIVE) return true; } +/// \brief Hook that determines players to switch during autobalance. +MUTATOR_HOOKFUNCTION(surv, TeamBalance_GetPlayerForTeamSwitch, + CBC_ORDER_EXCLUSIVE) +{ + int source_team_index = M_ARGV(0, int); + bool is_bot = M_ARGV(2, bool); + entity lowest_player = NULL; + switch (source_team_index) + { + case surv_attacker_team: + { + float lowest_score = FLOAT_MAX; + FOREACH_CLIENT(Surv_IsPlayerAttacker(it) && (it.surv_role == + SURVIVAL_ROLE_PLAYER) && (IS_BOT_CLIENT(it) == is_bot), + { + float temp_score = PlayerScore_Get(it, SP_SCORE); + if (temp_score >= lowest_score) + { + continue; + } + lowest_player = it; + lowest_score = temp_score; + }); + break; + } + case surv_defender_team: + { + float lowest_score = FLOAT_MAX; + FOREACH_CLIENT(Surv_IsPlayerDefender(it) && (IS_BOT_CLIENT(it) == + is_bot), + { + float temp_score = PlayerScore_Get(it, SP_SCORE); + if (temp_score >= lowest_score) + { + continue; + } + lowest_player = it; + lowest_score = temp_score; + }); + break; + } + } + M_ARGV(3, entity) = lowest_player; + return true; +} + /// \brief Hook that is called when player has changed the team. MUTATOR_HOOKFUNCTION(surv, Player_ChangedTeam) {