]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Survival: Updated to new autobalance API.
authorLyberta <lyberta@lyberta.net>
Mon, 9 Apr 2018 01:35:41 +0000 (04:35 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 9 Apr 2018 01:35:41 +0000 (04:35 +0300)
qcsrc/common/gamemodes/gamemode/survival/sv_survival.qc

index 049087998b908441d278d65f068d0daf23088573..fa07ce62417edc681a31d53d6530b8045bc3320c 100644 (file)
@@ -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)
 {