]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/teamplay.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qc
index c26a0b16550ac51062a40c742468d5f93f214076..1cfdbf4a0538da331630210cdfbc92a4ef4333ec 100644 (file)
@@ -35,7 +35,7 @@ const int TEAM_NOT_ALLOWED = -1;
 .int m_num_players; ///< Number of players (both humans and bots) in a team.
 .int m_num_bots; ///< Number of bots in a team.
 .int m_num_players_alive; ///< Number of alive players in a team.
-.int m_num_control_points; ///< Number of control points owned by a team.
+.int m_num_owned_items; ///< Number of items owned by a team.
 
 string autocvar_g_forced_team_red;
 string autocvar_g_forced_team_blue;
@@ -58,7 +58,7 @@ entity Team_GetTeamFromIndex(int index)
 {
        if (!Team_IsValidIndex(index))
        {
-               LOG_FATALF("Team_GetTeamFromIndex: Index is invalid: %f", index);
+               LOG_FATALF("Index is invalid: %f", index);
        }
        return g_team_entities[index - 1];
 }
@@ -67,7 +67,7 @@ entity Team_GetTeam(int team_num)
 {
        if (!Team_IsValidTeam(team_num))
        {
-               LOG_FATALF("Team_GetTeam: Value is invalid: %f", team_num);
+               LOG_FATALF("Value is invalid: %f", team_num);
        }
        return g_team_entities[Team_TeamToIndex(team_num) - 1];
 }
@@ -92,6 +92,21 @@ void Team_SetNumberOfAlivePlayers(entity team_ent, int number)
        team_ent.m_num_players_alive = number;
 }
 
+int Team_GetWinnerAliveTeam()
+{
+       int winner = 0;
+       for (int i = 0; i < NUM_TEAMS; ++i)
+       {
+               if (g_team_entities[i].m_num_players_alive > 0)
+               {
+                       if (winner)
+                               return 0;
+                       winner = Team_IndexToTeam(i + 1);
+               }
+       }
+       return (winner ? winner : -1);
+}
+
 int Team_GetNumberOfAliveTeams()
 {
        int result = 0;
@@ -105,22 +120,37 @@ int Team_GetNumberOfAliveTeams()
        return result;
 }
 
-int Team_GetNumberOfControlPoints(entity team_ent)
+int Team_GetWinnerTeam_WithOwnedItems(int min_control_points)
 {
-       return team_ent.m_num_control_points;
+       int winner = 0;
+       for (int i = 0; i < NUM_TEAMS; ++i)
+       {
+               if (g_team_entities[i].m_num_owned_items >= min_control_points)
+               {
+                       if (winner)
+                               return 0;
+                       winner = Team_IndexToTeam(i + 1);
+               }
+       }
+       return (winner ? winner : -1);
 }
 
-void Team_SetNumberOfControlPoints(entity team_ent, int number)
+int Team_GetNumberOfOwnedItems(entity team_ent)
 {
-       team_ent.m_num_control_points = number;
+       return team_ent.m_num_owned_items;
 }
 
-int Team_GetNumberOfTeamsWithControlPoints()
+void Team_SetNumberOfOwnedItems(entity team_ent, int number)
+{
+       team_ent.m_num_owned_items = number;
+}
+
+int Team_GetNumberOfTeamsWithOwnedItems()
 {
        int result = 0;
        for (int i = 0; i < NUM_TEAMS; ++i)
        {
-               if (g_team_entities[i].m_num_control_points > 0)
+               if (g_team_entities[i].m_num_owned_items > 0)
                {
                        ++result;
                }
@@ -130,7 +160,7 @@ int Team_GetNumberOfTeamsWithControlPoints()
 
 void setcolor(entity this, int clr)
 {
-#if 0
+#if 1
        this.clientcolors = clr;
        this.team = (clr & 15) + 1;
 #else
@@ -216,8 +246,7 @@ bool SetPlayerTeam(entity player, int team_index, int type)
        if (team_index != old_team_index)
        {
                KillPlayerForTeamChange(player);
-               PlayerScore_Clear(player);
-               CS(player).parm_idlesince = time;
+               PlayerScore_Clear(player); // works only in game modes without teams
 
                if (!IS_BOT_CLIENT(player))
                        TeamBalance_AutoBalanceBots();
@@ -332,7 +361,7 @@ void Player_SetForcedTeamIndex(entity player, int team_index)
                {
                        if (!Team_IsValidIndex(team_index))
                        {
-                               LOG_FATAL("Player_SetForcedTeamIndex: Invalid team index.");
+                               LOG_FATAL("Invalid team index.");
                        }
                        else
                        {
@@ -498,7 +527,7 @@ entity TeamBalance_CheckAllowedTeams(entity for_whom)
        }
 
        // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
-       if (autocvar_bot_vs_human && AvailableTeams() == 2 && for_whom)
+       if (autocvar_bot_vs_human && AVAILABLE_TEAMS == 2 && for_whom)
        {
                if (autocvar_bot_vs_human > 0)
                {
@@ -611,12 +640,11 @@ int TeamBalance_GetAllowedTeams(entity balance)
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_GetAllowedTeams: Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
        {
-               LOG_FATAL("TeamBalance_GetAllowedTeams: "
-                       "Team balance entity is not initialized.");
+               LOG_FATAL("Team balance entity is not initialized.");
        }
        int result = 0;
        for (int i = 1; i <= NUM_TEAMS; ++i)
@@ -633,16 +661,15 @@ bool TeamBalance_IsTeamAllowed(entity balance, int index)
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_IsTeamAllowed: Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
        {
-               LOG_FATAL("TeamBalance_IsTeamAllowed: "
-                       "Team balance entity is not initialized.");
+               LOG_FATAL("Team balance entity is not initialized.");
        }
        if (!Team_IsValidIndex(index))
        {
-               LOG_FATALF("TeamBalance_IsTeamAllowed: Team index is invalid: %f",
+               LOG_FATALF("Team index is invalid: %f",
                        index);
        }
        return TeamBalance_IsTeamAllowedInternal(balance, index);
@@ -652,12 +679,11 @@ void TeamBalance_GetTeamCounts(entity balance, entity ignore)
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_GetTeamCounts: Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
        {
-               LOG_FATAL("TeamBalance_GetTeamCounts: "
-                       "Team balance entity is not initialized.");
+               LOG_FATAL("Team balance entity is not initialized.");
        }
        if (MUTATOR_CALLHOOK(TeamBalance_GetTeamCounts) == true)
        {
@@ -684,7 +710,7 @@ void TeamBalance_GetTeamCounts(entity balance, entity ignore)
                        }
                        int team_num;
                        // TODO: Reconsider when the player is truly on the team.
-                       if (IS_CLIENT(it) || (it.caplayer))
+                       if (IS_CLIENT(it) || INGAME(it))
                        {
                                team_num = it.team;
                        }
@@ -734,18 +760,15 @@ int TeamBalance_GetNumberOfPlayers(entity balance, int index)
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
-                       "Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
        {
-               LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
-                       "TeamBalance_GetTeamCounts has not been called.");
+               LOG_FATAL("TeamBalance_GetTeamCounts has not been called.");
        }
        if (!Team_IsValidIndex(index))
        {
-               LOG_FATALF("TeamBalance_GetNumberOfPlayers: Team index is invalid: %f",
-                       index);
+               LOG_FATALF("Team index is invalid: %f", index);
        }
        return balance.m_team_balance_team[index - 1].m_num_players;
 }
@@ -754,12 +777,11 @@ int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player)
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_FindBestTeam: Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
        {
-               LOG_FATAL("TeamBalance_FindBestTeam: "
-                       "Team balance entity is not initialized.");
+               LOG_FATAL("Team balance entity is not initialized.");
        }
        // count how many players are in each team
        if (ignore_player)
@@ -773,8 +795,7 @@ int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player)
        int team_bits = TeamBalance_FindBestTeams(balance, player, true);
        if (team_bits == 0)
        {
-               LOG_FATALF("TeamBalance_FindBestTeam: No teams available for %s\n",
-                       MapInfo_Type_ToString(MapInfo_CurrentGametype()));
+               LOG_FATALF("No teams available for %s\n", GetGametype());
        }
        RandomSelection_Init();
        for (int i = 1; i <= NUM_TEAMS; ++i)
@@ -791,12 +812,11 @@ int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score)
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_FindBestTeams: Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
        {
-               LOG_FATAL("TeamBalance_FindBestTeams: "
-                       "TeamBalance_GetTeamCounts has not been called.");
+               LOG_FATAL("TeamBalance_GetTeamCounts has not been called.");
        }
        if (MUTATOR_CALLHOOK(TeamBalance_FindBestTeams, player) == true)
        {
@@ -838,21 +858,20 @@ int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
 {
        if (balance == NULL)
        {
-               LOG_FATAL("TeamBalance_CompareTeams: Team balance entity is NULL.");
+               LOG_FATAL("Team balance entity is NULL.");
        }
        if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
        {
-               LOG_FATAL("TeamBalance_CompareTeams: "
-                       "TeamBalance_GetTeamCounts has not been called.");
+               LOG_FATAL("TeamBalance_GetTeamCounts has not been called.");
        }
        if (!Team_IsValidIndex(team_index_a))
        {
-               LOG_FATALF("TeamBalance_CompareTeams: team_index_a is invalid: %f",
+               LOG_FATALF("team_index_a is invalid: %f",
                        team_index_a);
        }
        if (!Team_IsValidIndex(team_index_b))
        {
-               LOG_FATALF("TeamBalance_CompareTeams: team_index_b is invalid: %f",
+               LOG_FATALF("team_index_b is invalid: %f",
                        team_index_b);
        }
        if (team_index_a == team_index_b)
@@ -1051,7 +1070,7 @@ entity TeamBalance_GetTeamFromIndex(entity balance, int index)
 {
        if (!Team_IsValidIndex(index))
        {
-               LOG_FATALF("TeamBalance_GetTeamFromIndex: Index is invalid: %f", index);
+               LOG_FATALF("Index is invalid: %f", index);
        }
        return balance.m_team_balance_team[index - 1];
 }