X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fteamplay.qh;h=33f9d02d7e6b01da87c6dd86e6217b3ab546aa95;hb=1a372e06c983260b7dbecd6af83f5af78bb945e7;hp=444c25d3c494120fd7f573f72ba77d086b5cd709;hpb=b9d5c8d9237626af62c8dd05005af562e5aa33be;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index 444c25d3c..33f9d02d7 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -1,5 +1,13 @@ #pragma once +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; + bool lockteams; // ========================== Global teams API ================================ @@ -18,38 +26,38 @@ 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 Returns the number of alive players in a team. -/// \param[in] team_ Team entity. +/// \param[in] team_ent Team entity. /// \return Number of alive players in a team. -int Team_GetNumberOfAlivePlayers(entity team_); +int Team_GetNumberOfAlivePlayers(entity team_ent); /// \brief Sets the number of alive players in a team. -/// \param[in,out] team_ Team entity. +/// \param[in,out] team_ent Team entity. /// \param[in] number Number of players to set. -void Team_SetNumberOfAlivePlayers(entity team_, int number); +void Team_SetNumberOfAlivePlayers(entity team_ent, int number); /// \brief Returns the number of alive teams. /// \return Number of alive teams. int Team_GetNumberOfAliveTeams(); /// \brief Returns the number of control points owned by a team. -/// \param[in] team_ Team entity. +/// \param[in] team_ent Team entity. /// \return Number of control points owned by a team. -int Team_GetNumberOfControlPoints(entity team_); +int Team_GetNumberOfControlPoints(entity team_ent); /// \brief Sets the number of control points owned by a team. -/// \param[in,out] team_ Team entity. +/// \param[in,out] team_ent Team entity. /// \param[in] number Number of control points to set. -void Team_SetNumberOfControlPoints(entity team_, int number); +void Team_SetNumberOfControlPoints(entity team_ent, int number); /// \brief Returns the number of teams that own control points. /// \return Number of teams that own control points. @@ -71,7 +79,8 @@ int Entity_GetTeamIndex(entity this); /// \brief Returns the team entity of the given entity. /// \param[in] this Entity to check. -/// \return Team entity of the given entity. +/// \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); @@ -82,14 +91,24 @@ void SetPlayerColors(entity player, float _color); /// \return True if team switch was successful, false otherwise. 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 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. @@ -98,28 +117,45 @@ bool SetPlayerTeam(entity player, int destination_team_index, /// \return True on success, false otherwise. bool MoveToTeam(entity client, int team_index, int type); -/// \brief Kills player as a result of team change. -/// \param[in,out] player Player to kill. -void KillPlayerForTeamChange(entity player); - enum { - TEAM_CHANGE_CONNECT = 1, - TEAM_CHANGE_AUTO = 2, - TEAM_CHANGE_MANUAL = 3, - TEAM_CHANGE_SPECTATOR = 4, - TEAM_CHANGE_AUTO_RELAXED = 99 + TEAM_FORCE_SPECTATOR = -1, ///< Force the player to spectator team. + TEAM_FORCE_DEFAULT = 0 ///< Don't force any team. }; -void LogTeamchange(float player_id, float team_number, int type); +/// \brief Returns whether player has real forced team. Spectator team is +/// ignored. +/// \param[in] player Player to check. +/// \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 -/// must be manually destroyed by calling TeamBalance_Destroy. +/// 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. @@ -176,8 +212,6 @@ int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player); /// function. int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score); -void TeamBalance_JoinBestTeam(entity this, bool force_best_team); - /// \brief Describes the result of comparing teams. enum { @@ -199,17 +233,34 @@ enum int TeamBalance_CompareTeams(entity balance, 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. +/// \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] 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 TeamBalance_AutoBalanceBots(entity balance, int source_team_index, - int destination_team_index); +/// \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. @@ -239,39 +290,23 @@ entity TeamBalance_GetTeamFromIndex(entity balance, int index); entity TeamBalance_GetTeam(entity balance, int team_num); /// \brief Returns whether the team is allowed. -/// \param[in] team_ Team entity. +/// \param[in] team_ent Team entity. /// \return True if team is allowed, false otherwise. -bool TeamBalanceTeam_IsAllowed(entity team_); +bool TeamBalanceTeam_IsAllowed(entity team_ent); /// \brief Returns the number of players (both humans and bots) in a team. -/// \param[in] team_ Team entity. +/// \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_); +int TeamBalanceTeam_GetNumberOfPlayers(entity team_ent); /// \brief Returns the number of bots in a team. -/// \param[in] team_ Team entity. +/// \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_); - -/// \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 TeamBalance_GetTeamCounts before calling this -/// function. -entity TeamBalanceTeam_GetLowestHuman(entity team_); - -/// \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 TeamBalance_GetTeamCounts before calling this -/// function. -entity TeamBalanceTeam_GetLowestBot(entity team_); +int TeamBalanceTeam_GetNumberOfBots(entity team_ent); /// \brief Compares two teams for the purposes of game balance. /// \param[in] team_a First team. @@ -283,3 +318,9 @@ entity TeamBalanceTeam_GetLowestBot(entity team_); /// function. int TeamBalance_CompareTeamsInternal(entity team_a, entity team_index_b, entity player, bool use_score); + +/// \brief Called when the player connects or when they change their color with +/// the "color" command. +/// \param[in,out] player Player that requested a new color. +/// \param[in] new_color Requested color. +void SV_ChangeTeam(entity player, int new_color);