]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/teamplay.qh
Rename Team_*ControlPoints functions to Team_*OwnedItems so they can be used without...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qh
index 71b73b240fde3785c4b03eed1aca6b9ca6c0fa7c..a94b247a8a64150d78ba6c1ca52200ff16b70350 100644 (file)
@@ -1,7 +1,22 @@
 #pragma once
 
-string cache_mutatormsg;
-string cache_lastmutatormsg;
+int autocvar_teamplay_mode;
+
+bool autocvar_g_changeteam_banned;
+bool autocvar_teamplay_lockonrestart;
+
+bool autocvar_g_balance_teams;
+bool autocvar_g_balance_teams_prevent_imbalance;
+
+string autocvar_g_forced_team_otherwise;
+
+bool lockteams;
+
+.int team_forced; // can be a team number to force a team, or 0 for default action, or -1 for forced spectator
+
+// ========================== Global teams API ================================
+
+void Team_InitTeams();
 
 /// \brief Returns the global team entity at the given index.
 /// \param[in] index Index of the team.
@@ -14,156 +29,313 @@ entity Team_GetTeamFromIndex(int index);
 /// \return Global team entity that corresponds to the given TEAM_NUM value.
 entity Team_GetTeam(int team_num);
 
+// ========================= Team specific API ================================
+
 /// \brief Returns the score of the team.
-/// \param[in] team_ Team entity.
+/// \param[in] team_ent Team entity.
 /// \return Score of the team.
-float Team_GetTeamScore(entity team_);
+float Team_GetTeamScore(entity team_ent);
 
 /// \brief Sets the score of the team.
-/// \param[in,out] team_ Team entity.
+/// \param[in,out] team_ent Team entity.
 /// \param[in] score Score to set.
-void Team_SetTeamScore(entity team_, float score);
+void Team_SetTeamScore(entity team_ent, float score);
 
-/// \brief Checks whether the player can join teams according to global
-/// configuration and mutator settings.
-/// \param[in] for_whom Player to check for. Pass NULL for global rules.
-/// \note This function sets various internal variables and is required to be
-/// called before several other functions.
-void CheckAllowedTeams(entity for_whom);
+/// \brief Returns the number of alive players in a team.
+/// \param[in] team_ent Team entity.
+/// \return Number of alive players in a team.
+int Team_GetNumberOfAlivePlayers(entity team_ent);
 
-/// \brief Returns the bitmask of allowed teams.
-/// \return Bitmask of allowed teams.
-/// \note You need to call CheckAllowedTeams before calling this function.
-int GetAllowedTeams();
+/// \brief Sets the number of alive players in a team.
+/// \param[in,out] team_ent Team entity.
+/// \param[in] number Number of players to set.
+void Team_SetNumberOfAlivePlayers(entity team_ent, int number);
 
-/// \brief Returns whether the team is allowed.
-/// \param[in] team_ Team entity.
-/// \return True if team is allowed, false otherwise.
-/// \note You need to call CheckAllowedTeams before calling this function.
-bool Team_IsAllowed(entity team_);
+/// \brief Returns the winner team.
+/// \return Winner team or 0 if 2 or more teams have alive players or -1 if no team has any alive players.
+int Team_GetWinnerAliveTeam();
 
-/// \brief Counts the number of players and various other information about
-/// each team.
-/// \param[in] ignore Player to ignore. This is useful if you plan to switch the
-/// player's team. Pass NULL for global information.
-/// \note You need to call CheckAllowedTeams before calling this function.
-/// \note This function sets many internal variables and is required to be
-/// called before several other functions.
-void GetTeamCounts(entity ignore);
+/// \brief Returns the number of alive teams.
+/// \return Number of alive teams.
+int Team_GetNumberOfAliveTeams();
 
-/// \brief Returns the number of players (both humans and bots) in a team.
-/// \param[in] team_ Team entity.
-/// \return Number of player (both humans and bots) in a team.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-int Team_GetNumberOfPlayers(entity team_);
+/// \brief Returns the winner team.
+/// \param[in] min_owned_items Minimum number of items the winner team must have.
+/// \return Winner team or 0 if 2 or more teams own items or -1 if no team own any items.
+int Team_GetWinnerTeam_WIthOwnedItems(int min_owned_items);
 
-/// \brief Returns the number of bots in a team.
-/// \param[in] team_ Team entity.
-/// \return Number of bots in a team.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-int Team_GetNumberOfBots(entity team_);
-
-/// \brief Returns the human with the lowest score in a team or NULL if there is
-/// none.
-/// \param[in] team_ Team entity.
-/// \return Human with the lowest score in a team or NULL if there is none.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-entity Team_GetLowestHuman(entity team_);
+/// \brief Returns the number of items owned by a team.
+/// \param[in] team_ent Team entity.
+/// \return Number of items owned by a team.
+int Team_GetNumberOfOwnedItems(entity team_ent);
 
-/// \brief Returns the bot with the lowest score in a team or NULL if there is
-/// none.
-/// \param[in] team_ Team entity.
-/// \return Bot with the lowest score in a team or NULL if there is none.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-entity Team_GetLowestBot(entity team_);
+/// \brief Sets the number of items owned by a team.
+/// \param[in,out] team_ent Team entity.
+/// \param[in] number Number of items to set.
+void Team_SetNumberOfOwnedItems(entity team_ent, int number);
 
-int redowned, blueowned, yellowowned, pinkowned;
+/// \brief Returns the number of teams that own items.
+/// \return Number of teams that own items.
+int Team_GetNumberOfTeamsWithOwnedItems();
 
-void TeamchangeFrags(entity e);
+// ======================= Entity specific API ================================
 
-void LogTeamchange(float player_id, float team_number, float type);
-
-void default_delayedinit(entity this);
+void setcolor(entity this, int clr);
 
-void InitGameplayMode();
+/// \brief Returns whether the given entity belongs to a valid team.
+/// \param[in] this Entity to check.
+/// \return True if entity belongs to a valid team, false otherwise.
+bool Entity_HasValidTeam(entity this);
 
-string GetClientVersionMessage(entity this);
+/// \brief Returns the team index of the given entity.
+/// \param[in] this Entity to check.
+/// \return Team index of the entity.
+int Entity_GetTeamIndex(entity this);
 
-string getwelcomemessage(entity this);
-
-void setcolor(entity this, int clr);
+/// \brief Returns the team entity of the given entity.
+/// \param[in] this Entity to check.
+/// \return Team entity of the given entity or NULL if the entity doesn't belong
+/// to any team.
+entity Entity_GetTeam(entity this);
 
 void SetPlayerColors(entity player, float _color);
 
-/// \brief Kills player as a result of team change.
-/// \param[in,out] player Player to kill.
-void KillPlayerForTeamChange(entity player);
-
-/// \brief Sets the team of the player.
+/// \brief Sets the team of the player using its index.
 /// \param[in,out] player Player to adjust.
-/// \param[in] team_num Team number to set. See TEAM_NUM constants.
+/// \param[in] index Index of the team to set.
 /// \return True if team switch was successful, false otherwise.
-bool SetPlayerTeamSimple(entity player, int team_num);
+bool Player_SetTeamIndex(entity player, int index);
+
+enum
+{
+       TEAM_CHANGE_AUTO = 2, ///< The team was selected by autobalance.
+       TEAM_CHANGE_MANUAL = 3, ///< Player has manually selected their team.
+       TEAM_CHANGE_SPECTATOR = 4 ///< Player is joining spectators. //TODO: Remove?
+};
 
 /// \brief Sets the team of the player.
 /// \param[in,out] player Player to adjust.
-/// \param[in] destination_team_index Index of the team to set.
-/// \param[in] source_team_index Previous index of the team of the player.
-/// \param[in] no_print Whether to print this event to players' console.
+/// \param[in] team_index Index of the team to set.
+/// \param[in] type Type of the team change. See TEAM_CHANGE constants.
 /// \return True if team switch was successful, false otherwise.
-bool SetPlayerTeam(entity player, int destination_team_index,
-       int source_team_index, bool no_print);
+bool SetPlayerTeam(entity player, int team_index, int type);
 
-/// \brief Returns the bitmask of the teams that will make the game most
-/// balanced if the player joins any of them.
+/// \brief Sets the team of the player with all sanity checks.
+/// \param[in,out] player Player to adjust.
+/// \param[in] team_index Index of the team to set.
+void Player_SetTeamIndexChecked(entity player, int team_index);
+
+/// \brief Moves player to the specified team.
+/// \param[in,out] client Client to move.
+/// \param[in] team_index Index of the team.
+/// \param[in] type ???
+/// \return True on success, false otherwise.
+bool MoveToTeam(entity client, int team_index, int type);
+
+enum
+{
+       TEAM_FORCE_SPECTATOR = -1, ///< Force the player to spectator team.
+       TEAM_FORCE_DEFAULT = 0 ///< Don't force any team.
+};
+
+/// \brief Returns whether player has real forced team. Spectator team is
+/// ignored.
 /// \param[in] player Player to check.
-/// \param[in] use_score Whether to take into account team scores.
-/// \return Bitmask of the teams that will make the game most balanced if the
-/// player joins any of them.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-int FindBestTeamsForBalance(entity player, bool use_score);
+/// \return True if player has real forced team, false otherwise.
+bool Player_HasRealForcedTeam(entity player);
+
+/// \brief Returns the index of the forced team of the given player.
+/// \param[in] player Player to check.
+/// \return Index of the forced team.
+int Player_GetForcedTeamIndex(entity player);
+
+/// \brief Sets the index of the forced team of the given player.
+/// \param[in,out] player Player to adjust.
+/// \param[in] team_index Index of the team to set.
+void Player_SetForcedTeamIndex(entity player, int team_index);
+
+/// \brief Determines the forced team of the player using current global config.
+/// \param[in,out] player Player to adjust.
+void Player_DetermineForcedTeam(entity player);
+
+// ========================= Team balance API =================================
+
+/// \brief Assigns the given player to a team that will make the game most
+/// balanced.
+/// \param[in,out] player Player to assign.
+void TeamBalance_JoinBestTeam(entity player);
+
+/// \brief Checks whether the player can join teams according to global
+/// configuration and mutator settings.
+/// \param[in] for_whom Player to check for. Pass NULL for global rules.
+/// \return Team balance entity that holds information about teams. This entity
+/// will be automatically destroyed on the next frame but you are encouraged to
+/// manually destroy it by calling TeamBalance_Destroy for performance reasons.
+entity TeamBalance_CheckAllowedTeams(entity for_whom);
+
+/// \brief Destroy the team balance entity.
+/// \param[in,out] balance Team balance entity to destroy.
+/// \note Team balance entity is allowed to be NULL.
+void TeamBalance_Destroy(entity balance);
+
+/// \brief Returns the bitmask of allowed teams.
+/// \param[in] balance Team balance entity.
+/// \return Bitmask of allowed teams.
+int TeamBalance_GetAllowedTeams(entity balance);
+
+/// \brief Returns whether the team change to the specified team is allowed.
+/// \param[in] balance Team balance entity.
+/// \param[in] index Index of the team.
+/// \return True if team change to the specified team is allowed, false
+/// otherwise.
+bool TeamBalance_IsTeamAllowed(entity balance, int index);
+
+/// \brief Counts the number of players and various other information about
+/// each team.
+/// \param[in,out] balance Team balance entity.
+/// \param[in] ignore Player to ignore. This is useful if you plan to switch the
+/// player's team. Pass NULL for global information.
+/// \note This function updates the internal state of the team balance entity.
+void TeamBalance_GetTeamCounts(entity balance, entity ignore);
+
+/// \brief Returns the number of players (both humans and bots) in a team.
+/// \param[in] balance Team balance entity.
+/// \param[in] index Index of the team.
+/// \return Number of player (both humans and bots) in a team.
+/// \note You need to call TeamBalance_GetTeamCounts before calling this
+/// function.
+int TeamBalance_GetNumberOfPlayers(entity balance, int index);
 
 /// \brief Finds the team that will make the game most balanced if the player
 /// joins it.
+/// \param[in] balance Team balance entity.
 /// \param[in] player Player to check.
 /// \param[in] ignore_player ???
 /// \return Index of the team that will make the game most balanced if the
 /// player joins it. If there are several equally good teams available, the
 /// function will pick a random one.
-int FindBestTeamForBalance(entity player, float ignore_player);
+int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player);
 
-void JoinBestTeamForBalance(entity this, bool force_best_team);
+/// \brief Returns the bitmask of the teams that will make the game most
+/// balanced if the player joins any of them.
+/// \param[in] balance Team balance entity.
+/// \param[in] player Player to check.
+/// \param[in] use_score Whether to take into account team scores.
+/// \return Bitmask of the teams that will make the game most balanced if the
+/// player joins any of them.
+/// \note You need to call TeamBalance_GetTeamCounts before calling this
+/// function.
+int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score);
+
+/// \brief Describes the result of comparing teams.
+enum
+{
+       TEAMS_COMPARE_INVALID, ///< One or both teams are invalid.
+       TEAMS_COMPARE_LESS, ///< First team is less than the second one.
+       TEAMS_COMPARE_EQUAL, ///< Both teams are equal.
+       TEAMS_COMPARE_GREATER ///< First team the greater than the second one.
+};
 
-/// \brief Returns whether one team is smaller than the other.
+/// \brief Compares two teams for the purposes of game balance.
+/// \param[in] balance Team balance entity.
 /// \param[in] team_index_a Index of the first team.
 /// \param[in] team_index_b Index of the second team.
 /// \param[in] player Player to check.
 /// \param[in] use_score Whether to take into account team scores.
-/// \return True if first team is smaller than the second one, false otherwise.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-bool IsTeamSmallerThanTeam(int team_index_a, int team_index_b, entity player,
-       bool use_score);
+/// \return TEAMS_COMPARE value. See above.
+/// \note You need to call TeamBalance_GetTeamCounts before calling this
+/// function.
+int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
+       entity player, bool use_score);
 
-/// \brief Returns whether one team is equal to the other.
-/// \param[in] team_index_a Index of the first team.
-/// \param[in] team_index_b Index of the second team.
+/// \brief Switches a bot from one team to another if teams are not balanced.
+void TeamBalance_AutoBalanceBots();
+
+/// \brief Returns the index of the team with most players that is contained in
+/// the given bitmask of teams.
+/// \param[in] balance Team balance entity.
+/// \param[in] teams Bitmask of teams to search in.
+/// \return Index of the team with most players.
+int TeamBalance_GetLargestTeamIndex(entity balance, int teams);
+
+/// \brief Returns the player who is the most suitable for switching between
+/// the given teams.
+/// \param[in] source_team_index Index of the team to search in.
+/// \param[in] destination_team_index Index of the team to switch to.
+/// \param[in] is_bot True to search for bot, false for human.
+/// \return Player who is the most suitable for switching between the given
+/// teams or NULL if not found.
+entity TeamBalance_GetPlayerForTeamSwitch(int source_team_index,
+       int destination_team_index, bool is_bot);
+
+// ============================ Internal API ==================================
+
+void LogTeamChange(float player_id, float team_number, int type);
+
+/// \brief Kills player as a result of team change.
+/// \param[in,out] player Player to kill.
+void KillPlayerForTeamChange(entity player);
+
+/// \brief Returns whether the team change to the specified team is allowed.
+/// \param[in] balance Team balance entity.
+/// \param[in] index Index of the team.
+/// \return True if team change to the specified team is allowed, false
+/// otherwise.
+/// \note This function bypasses all the sanity checks.
+bool TeamBalance_IsTeamAllowedInternal(entity balance, int index);
+
+/// \brief Bans team change to all teams except the given one.
+/// \param[in,out] balance Team balance entity.
+/// \param[in] index Index of the team.
+void TeamBalance_BanTeamsExcept(entity balance, int index);
+
+/// \brief Returns the team entity of the team balance entity at the given
+/// index.
+/// \param[in] balance Team balance entity.
+/// \param[in] index Index of the team.
+/// \return Team entity of the team balance entity at the given index.
+entity TeamBalance_GetTeamFromIndex(entity balance, int index);
+
+/// \brief Returns the team entity of the team balance entity that corresponds
+/// to the given TEAM_NUM value.
+/// \param[in] balance Team balance entity.
+/// \param[in] team_num Team value. See TEAM_NUM constants.
+/// \return Team entity of the team balance entity that corresponds to the given
+/// TEAM_NUM value.
+entity TeamBalance_GetTeam(entity balance, int team_num);
+
+/// \brief Returns whether the team is allowed.
+/// \param[in] team_ent Team entity.
+/// \return True if team is allowed, false otherwise.
+bool TeamBalanceTeam_IsAllowed(entity team_ent);
+
+/// \brief Returns the number of players (both humans and bots) in a team.
+/// \param[in] team_ent Team entity.
+/// \return Number of player (both humans and bots) in a team.
+/// \note You need to call TeamBalance_GetTeamCounts before calling this
+/// function.
+int TeamBalanceTeam_GetNumberOfPlayers(entity team_ent);
+
+/// \brief Returns the number of bots in a team.
+/// \param[in] team_ent Team entity.
+/// \return Number of bots in a team.
+/// \note You need to call TeamBalance_GetTeamCounts before calling this
+/// function.
+int TeamBalanceTeam_GetNumberOfBots(entity team_ent);
+
+/// \brief Compares two teams for the purposes of game balance.
+/// \param[in] team_a First team.
+/// \param[in] team_b Second team.
 /// \param[in] player Player to check.
 /// \param[in] use_score Whether to take into account team scores.
-/// \return True if first team is equal to the second one, false otherwise.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-bool IsTeamEqualToTeam(int team_index_a, int team_index_b, entity player,
-       bool use_score);
-
-/// \brief Auto balances bots in teams after the player has changed team.
-/// \param[in] source_team_index Previous index of the team of the player.
-/// \param[in] destination_team_index Current index of the team of the player.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-void AutoBalanceBots(int source_team_index, int destination_team_index);
+/// \return TEAMS_COMPARE value. See above.
+/// \note You need to call TeamBalance_GetTeamCounts before calling this
+/// function.
+int TeamBalance_CompareTeamsInternal(entity team_a, entity team_index_b,
+       entity player, bool use_score);
+
+/// \brief Called when the player changes color with the "color" command.
+/// Note that the "color" command is always called early on player connection
+/// \param[in,out] player Player that requested a new color.
+/// \param[in] new_color Requested color.
+void SV_ChangeTeam(entity player, int new_color);