From cbd1a08b104b3e2597eb8482e6a9d5adbcf4c4ab Mon Sep 17 00:00:00 2001 From: Lyberta Date: Fri, 9 Mar 2018 16:35:00 +0300 Subject: [PATCH] Renamed team conversion functions. --- qcsrc/common/effects/all.inc | 2 +- .../gamemodes/gamemode/nexball/nexball.qc | 2 +- .../gamemode/onslaught/sv_onslaught.qc | 2 +- qcsrc/common/teams.qh | 44 +++++++++++++------ qcsrc/server/bot/default/bot.qc | 2 +- qcsrc/server/command/cmd.qc | 2 +- qcsrc/server/command/sv_cmd.qc | 4 +- qcsrc/server/g_world.qc | 4 +- .../mutators/mutator/gamemode_domination.qc | 2 +- qcsrc/server/teamplay.qc | 30 ++++++------- 10 files changed, 55 insertions(+), 39 deletions(-) diff --git a/qcsrc/common/effects/all.inc b/qcsrc/common/effects/all.inc index 6439a49bb..2114bdd65 100644 --- a/qcsrc/common/effects/all.inc +++ b/qcsrc/common/effects/all.inc @@ -258,6 +258,6 @@ entity EFFECT_ROCKETMINSTA_LASER(int teamid) case NUM_TEAM_4: e = EFFECT_ROCKETMINSTA_LASER_PINK; break; default: e = EFFECT_ROCKETMINSTA_LASER_NEUTRAL; break; } - if (particleeffectnum(e) < 0 || Team_TeamToNumber(teamid) == -1) { e = EFFECT_TR_NEXUIZPLASMA; } + if (particleeffectnum(e) < 0 || Team_TeamToIndex(teamid) == -1) { e = EFFECT_TR_NEXUIZPLASMA; } return e; } diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index e4b755fc4..f208c1512 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -635,7 +635,7 @@ void SpawnGoal(entity this) EXACTTRIGGER_INIT; - if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1) + if(this.team != GOAL_OUT && Team_IsValidTeam(this.team)) { entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE); wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0'); diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc index 8fc4d89c4..2536af659 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc @@ -1929,7 +1929,7 @@ MUTATOR_HOOKFUNCTION(ons, TeamBalance_CheckAllowedTeams) { if (Team_IsValidTeam(tmp_entity.team)) { - M_ARGV(0, float) |= BIT(Team_TeamToNumber(tmp_entity.team) - 1); + M_ARGV(0, float) |= Team_TeamToBit(tmp_entity.team); } } diff --git a/qcsrc/common/teams.qh b/qcsrc/common/teams.qh index 1b03540dd..88666db0e 100644 --- a/qcsrc/common/teams.qh +++ b/qcsrc/common/teams.qh @@ -127,12 +127,12 @@ float Team_ColorToTeam(string team_color) return -1; } -/// \brief Returns whether team is valid. -/// \param[in] team_ Team to check. +/// \brief Returns whether team value is valid. +/// \param[in] team_num Team to check. /// \return True if team is valid, false otherwise. -bool Team_IsValidTeam(int team_) +bool Team_IsValidTeam(int team_num) { - switch (team_) + switch (team_num) { case NUM_TEAM_1: case NUM_TEAM_2: @@ -163,32 +163,48 @@ bool Team_IsValidIndex(int index) return false; } -float Team_NumberToTeam(float number) +/// \brief Converts team index into team value. +/// \param[in] index Team index to convert. +/// \return Team value. +int Team_IndexToTeam(int index) { - switch(number) + switch (index) { case 1: return NUM_TEAM_1; case 2: return NUM_TEAM_2; case 3: return NUM_TEAM_3; case 4: return NUM_TEAM_4; } - return -1; } -float Team_TeamToNumber(float teamid) +/// \brief Converts team value into team index. +/// \param[in] team_ Team value to convert. +/// \return Team index. +int Team_TeamToIndex(int team_) { - switch(teamid) + switch (team_) { case NUM_TEAM_1: return 1; case NUM_TEAM_2: return 2; case NUM_TEAM_3: return 3; case NUM_TEAM_4: return 4; } - return -1; } +/// \brief Converts team value into bit value that is used in team bitmasks. +/// \param[in] team_num Team value to convert. +/// \return Team bit. +int Team_TeamToBit(int team_num) +{ + if (!Team_IsValidTeam(team_num)) + { + return 0; + } + return BIT(Team_TeamToIndex(team_num) - 1); +} + /// \brief Converts team index into bit value that is used in team bitmasks. /// \param[in] index Team index to convert. /// \return Team bit. @@ -199,8 +215,8 @@ int Team_IndexToBit(int index) // legacy aliases for shitty code -#define TeamByColor(teamid) (Team_TeamToNumber(teamid) - 1) -#define ColorByTeam(number) Team_NumberToTeam(number + 1) +#define TeamByColor(teamid) (Team_TeamToIndex(teamid) - 1) +#define ColorByTeam(number) Team_IndexToTeam(number + 1) // useful aliases #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid)) @@ -213,8 +229,8 @@ int Team_IndexToBit(int index) #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7") #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7") -#define Team_NumberToFullName(number) Team_FullName(Team_NumberToTeam(number)) -#define Team_NumberToColoredFullName(number) Team_ColoredFullName(Team_NumberToTeam(number)) +#define Team_IndexToFullName(index) Team_FullName(Team_IndexToTeam(index)) +#define Team_IndexToColoredFullName(index) Team_ColoredFullName(Team_IndexToTeam(index)) // replace these flags in a string with the strings provided #define TCR(input,type,team) strreplace("^TC", COL_TEAM_##team, strreplace("^TT", strtoupper(type##_TEAM_##team), input)) diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index 3ce03694c..667fb2b3d 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -468,7 +468,7 @@ void bot_removefromlargestteam() if (Team_IsValidTeam(it.team)) { thiscount = TeamBalance_GetNumberOfPlayers(balance, - Team_TeamToNumber(it.team)); + Team_TeamToIndex(it.team)); } if(thiscount > bestcount) diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index af228f729..3be9fe0dd 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -396,7 +396,7 @@ void ClientCommand_selectteam(entity caller, float request, float argc) { entity balance = TeamBalance_CheckAllowedTeams(caller); TeamBalance_GetTeamCounts(balance, caller); - if ((Team_IndexToBit(Team_TeamToNumber(selection)) & + if ((Team_IndexToBit(Team_TeamToIndex(selection)) & TeamBalance_FindBestTeams(balance, caller, false)) == 0) { Send_Notification(NOTIF_ONE, caller, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM); diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 9d8c901db..aac321039 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1074,7 +1074,7 @@ void GameCommand_moveplayer(float request, float argc) else if (team_id == 0) // auto team { balance = TeamBalance_CheckAllowedTeams(client); - team_id = Team_NumberToTeam(TeamBalance_FindBestTeam(balance, client, false)); + team_id = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false)); } else { @@ -1421,7 +1421,7 @@ void GameCommand_shuffleteams(float request) int team_index = 0; FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || it.caplayer, { - int target_team_number = Team_NumberToTeam(team_index + 1); + int target_team_number = Team_IndexToTeam(team_index + 1); if (it.team != target_team_number) MoveToTeam(it, target_team_number, 6); team_index = (team_index + 1) % number_of_teams; }); diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 4777524f0..b0a033391 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -1693,7 +1693,7 @@ float WinningCondition_Scores(float limit, float leadlimit) for (int i = 1; i < 5; ++i) { Team_SetTeamScore(Team_GetTeamFromIndex(i), - TeamScore_GetCompareValue(Team_NumberToTeam(i))); + TeamScore_GetCompareValue(Team_IndexToTeam(i))); } } @@ -1819,7 +1819,7 @@ float WinningCondition_RanOutOfSpawns() { continue; } - TeamScore_AddToTeam(Team_NumberToTeam(j), i, -1000); + TeamScore_AddToTeam(Team_IndexToTeam(j), i, -1000); } } diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qc b/qcsrc/server/mutators/mutator/gamemode_domination.qc index dec8ac5a9..7febaed8a 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qc +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qc @@ -428,7 +428,7 @@ MUTATOR_HOOKFUNCTION(dom, TeamBalance_CheckAllowedTeams) { if (Team_IsValidTeam(head.team)) { - M_ARGV(0, float) |= BIT(Team_TeamToNumber(head.team) - 1); + M_ARGV(0, float) |= Team_TeamToBit(head.team); } } diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 3b3156559..d239ec32d 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -62,7 +62,7 @@ entity Team_GetTeam(int team_num) { LOG_FATALF("Team_GetTeam: Value is invalid: %f", team_num); } - return g_team_entities[Team_TeamToNumber(team_num) - 1]; + return g_team_entities[Team_TeamToIndex(team_num) - 1]; } float Team_GetTeamScore(entity team_) @@ -263,8 +263,8 @@ bool SetPlayerTeamSimple(entity player, int team_num) SetPlayerColors(player, team_num - 1); return true; } - if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, Team_TeamToNumber( - player.team), Team_TeamToNumber(team_num)) == true) + if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, Team_TeamToIndex( + player.team), Team_TeamToIndex(team_num)) == true) { // Mutator has blocked team change. return false; @@ -278,7 +278,7 @@ bool SetPlayerTeamSimple(entity player, int team_num) bool SetPlayerTeam(entity player, int destination_team_index, int source_team_index, bool no_print) { - int team_num = Team_NumberToTeam(destination_team_index); + int team_num = Team_IndexToTeam(destination_team_index); if (!SetPlayerTeamSimple(player, team_num)) { return false; @@ -289,8 +289,8 @@ bool SetPlayerTeam(entity player, int destination_team_index, return true; } bprint(playername(player, false), "^7 has changed from ", - Team_NumberToColoredFullName(source_team_index), "^7 to ", - Team_NumberToColoredFullName(destination_team_index), "\n"); + Team_IndexToColoredFullName(source_team_index), "^7 to ", + Team_IndexToColoredFullName(destination_team_index), "\n"); return true; } @@ -424,7 +424,7 @@ entity TeamBalance_CheckAllowedTeams(entity for_whom) // if player has a forced team, ONLY allow that one for (int i = 1; i <= NUM_TEAMS; ++i) { - if (for_whom.team_forced == Team_NumberToTeam(i) && + if (for_whom.team_forced == Team_IndexToTeam(i) && TeamBalance_IsTeamAllowedInternal(balance, i)) { TeamBalance_BanTeamsExcept(balance, i); @@ -508,7 +508,7 @@ void TeamBalance_GetTeamCounts(entity balance, entity ignore) entity team_ = TeamBalance_GetTeamFromIndex(balance, i); if (TeamBalanceTeam_IsAllowed(team_)) { - MUTATOR_CALLHOOK(TeamBalance_GetTeamCount, Team_NumberToTeam(i), + MUTATOR_CALLHOOK(TeamBalance_GetTeamCount, Team_IndexToTeam(i), ignore, team_.m_num_players, team_.m_num_bots, team_.m_lowest_human, team_.m_lowest_bot); team_.m_num_players = M_ARGV(2, float); @@ -719,7 +719,7 @@ void TeamBalance_JoinBestTeam(entity this, bool force_best_team) for (int i = 1; i <= NUM_TEAMS; ++i) { if (TeamBalance_IsTeamAllowedInternal(balance, i) && (this.team == - Team_NumberToTeam(i))) + Team_IndexToTeam(i))) { selected_team_num = this.team; break; @@ -741,8 +741,8 @@ void TeamBalance_JoinBestTeam(entity this, bool force_best_team) return; } int best_team_index = TeamBalance_FindBestTeam(balance, this, true); - int best_team_num = Team_NumberToTeam(best_team_index); - int old_team_index = Team_TeamToNumber(this.team); + int best_team_num = Team_IndexToTeam(best_team_index); + int old_team_index = Team_TeamToIndex(this.team); TeamchangeFrags(this); SetPlayerTeamSimple(this, best_team_num); LogTeamchange(this.playerid, this.team, 2); // log auto join @@ -828,7 +828,7 @@ void TeamBalance_AutoBalanceBots(entity balance, int source_team_index, return; } SetPlayerTeamSimple(destination_team.m_lowest_bot, - Team_NumberToTeam(source_team_index)); + Team_IndexToTeam(source_team_index)); KillPlayerForTeamChange(destination_team.m_lowest_bot); } @@ -860,7 +860,7 @@ entity TeamBalance_GetTeamFromIndex(entity balance, int index) entity TeamBalance_GetTeam(entity balance, int team_num) { - return TeamBalance_GetTeamFromIndex(balance, Team_TeamToNumber(team_num)); + return TeamBalance_GetTeamFromIndex(balance, Team_TeamToIndex(team_num)); } bool TeamBalanceTeam_IsAllowed(entity team_) @@ -952,8 +952,8 @@ void SV_ChangeTeam(entity this, float _color) source_color = this.clientcolors & 0x0F; destination_color = _color & 0x0F; - source_team_index = Team_TeamToNumber(source_color + 1); - destination_team_index = Team_TeamToNumber(destination_color + 1); + source_team_index = Team_TeamToIndex(source_color + 1); + destination_team_index = Team_TeamToIndex(destination_color + 1); if (destination_team_index == -1) { -- 2.39.2