]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Survival: Better autobalance.
authorLyberta <lyberta@lyberta.net>
Sun, 2 Apr 2017 15:04:23 +0000 (18:04 +0300)
committerLyberta <lyberta@lyberta.net>
Sun, 2 Apr 2017 15:04:23 +0000 (18:04 +0300)
qcsrc/server/mutators/mutator/gamemode_survival.qc

index 38d3cf6da3d0a75909f30b4f442f261544012d11..5b138c588bb1eb32b34b35ebe99c5c0b7e847e24 100644 (file)
@@ -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)
 {