X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fserver%2Fteamplay.qh;h=776a80d329cf91d5917f1af4e1ba7275eb18a731;hb=becfb70a12d8a13efec7ed3760533da6858916c1;hp=00a1ed5bb2202c8d20bf6bad080f05b97d4898c7;hpb=ada6591c533a7d47237096f9a56cccbd1b2ae1c0;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index 00a1ed5bb..776a80d32 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -1,71 +1,264 @@ #pragma once -string cache_mutatormsg; -string cache_lastmutatormsg; +bool lockteams; -// client counts for each team -//float c1, c2, c3, c4; -// # of bots on those teams -float numbotsteam1; -float numbotsteam2; -float numbotsteam3; -float numbotsteam4; -entity lowestplayerteam1; -entity lowestplayerteam2; -entity lowestplayerteam3; -entity lowestplayerteam4; -entity lowestbotteam1; -entity lowestbotteam2; -entity lowestbotteam3; -entity lowestbotteam4; +// ========================== Global teams API ================================ -int redowned, blueowned, yellowowned, pinkowned; +/// \brief Returns the global team entity at the given index. +/// \param[in] index Index of the team. +/// \return Global team entity at the given index. +entity Team_GetTeamFromIndex(int index); -//float audit_teams_time; +/// \brief Returns the global team entity that corresponds to the given TEAM_NUM +/// value. +/// \param[in] team_num Team value. See TEAM_NUM constants. +/// \return Global team entity that corresponds to the given TEAM_NUM value. +entity Team_GetTeam(int team_num); -void TeamchangeFrags(entity e); +// ========================= Team specific API ================================ -void LogTeamchange(float player_id, float team_number, float type); +/// \brief Returns the score of the team. +/// \param[in] team_ent Team entity. +/// \return Score of the team. +float Team_GetTeamScore(entity team_ent); -void default_delayedinit(entity this); +/// \brief Sets the score of the team. +/// \param[in,out] team_ent Team entity. +/// \param[in] score Score to set. +void Team_SetTeamScore(entity team_ent, float score); -void ActivateTeamplay(); +/// \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); -void InitGameplayMode(); +/// \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); -string GetClientVersionMessage(entity this); +/// \brief Returns the number of alive teams. +/// \return Number of alive teams. +int Team_GetNumberOfAliveTeams(); -string getwelcomemessage(entity this); +/// \brief Returns the number of control points owned by a team. +/// \param[in] team_ent Team entity. +/// \return Number of control points owned by a team. +int Team_GetNumberOfControlPoints(entity team_ent); -void SetPlayerColors(entity pl, float _color); +/// \brief Sets the number of control points owned by a team. +/// \param[in,out] team_ent Team entity. +/// \param[in] number Number of control points to set. +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. +int Team_GetNumberOfTeamsWithControlPoints(); + +// ======================= Entity specific API ================================ + +void setcolor(entity this, int clr); + +/// \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); + +/// \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); + +/// \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 Sets the team of the player using its index. +/// \param[in,out] player Player to adjust. +/// \param[in] index Index of the team to set. +/// \return True if team switch was successful, false otherwise. +bool Player_SetTeamIndex(entity player, int index); /// \brief Sets the team of the player. /// \param[in,out] player Player to adjust. -/// \param[in] teamnum Team number to set. See TEAM_NUM constants. +/// \param[in] team_index Index of the team to set. +/// \param[in] type ??? /// \return True if team switch was successful, false otherwise. -bool SetPlayerTeamSimple(entity player, int teamnum); +bool SetPlayerTeam(entity player, int team_index, int type); -void SetPlayerTeam(entity pl, float t, float s, float noprint); +/// \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); -// set c1...c4 to show what teams are allowed -void CheckAllowedTeams (entity for_whom); +/// \brief Kills player as a result of team change. +/// \param[in,out] player Player to kill. +void KillPlayerForTeamChange(entity player); -float PlayerValue(entity p); +enum +{ + TEAM_CHANGE_AUTO = 2, + TEAM_CHANGE_MANUAL = 3, + TEAM_CHANGE_SPECTATOR = 4 +}; -// c1...c4 should be set to -1 (not allowed) or 0 (allowed). -// teams that are allowed will now have their player counts stored in c1...c4 -void GetTeamCounts(entity ignore); +void LogTeamchange(float player_id, float team_number, int type); -float TeamSmallerEqThanTeam(float ta, float tb, entity e); +// ========================= Team balance API ================================= -// returns # of smallest team (1, 2, 3, 4) -// NOTE: Assumes CheckAllowedTeams has already been called! -float FindSmallestTeam(entity pl, float ignore_pl); +/// \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); -int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam); +/// \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); -//void() ctf_playerchanged; +/// \brief Returns the bitmask of allowed teams. +/// \param[in] balance Team balance entity. +/// \return Bitmask of allowed teams. +int TeamBalance_GetAllowedTeams(entity balance); -void ShufflePlayerOutOfTeam (float source_team); +/// \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); -void setcolor(entity this, int clr); +/// \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 TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player); + +/// \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); + +void TeamBalance_JoinBestTeam(entity this); + +/// \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 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 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 Switches a bot from one team to another if teams are not balanced. +/// \param[in] source_team_index Index of the team to switch from. +/// \param[in] destination_team_index Index of the team to switch to. +void TeamBalance_AutoBalanceBots(int source_team_index, + int destination_team_index); + +// ============================ Internal API ================================== + +/// \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 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);