From: terencehill Date: Wed, 24 Mar 2021 21:57:26 +0000 (+0100) Subject: GameCommand_moveplayer: reduce code indentation X-Git-Tag: xonotic-v0.8.5~488 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=0281c2b5d52f4e702e8a66da93d13bd3896d06c8 GameCommand_moveplayer: reduce code indentation --- diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 81ef50aeda..2abd4c6d5c 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1003,98 +1003,90 @@ void GameCommand_moveplayer(int request, int argc) if (accepted <= 0) { LOG_INFO("moveplayer: ", GetClientErrorString(accepted, t), (targets ? ", skipping to next player.\n" : ".")); - continue; } - - // Where are we putting this player? - if (destination == "spectator") + else if (destination == "spectator") { + string pl_name = playername(client.netname, client.team, false); if (!IS_SPEC(client) && !IS_OBSERVER(client)) { if (client.caplayer) client.caplayer = 0; PutObserverInServer(client); - successful = strcat(successful, (successful ? ", " : ""), playername(client.netname, client.team, false)); + successful = strcat(successful, (successful ? ", " : ""), pl_name); } else { - LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client.netname, client.team, false), ") is already spectating."); + LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already spectating."); } - continue; } else { - if (!IS_SPEC(client) && !IS_OBSERVER(client)) + string pl_name = playername(client.netname, client.team, false); + if (IS_SPEC(client) || IS_OBSERVER(client)) { - if (teamplay) - { - // set up - string pl_name = playername(client.netname, client.team, false); - int save = Player_GetForcedTeamIndex(client); - Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT); - - // find the team to move the player to - int team_num = Team_ColorToTeam(destination); - entity balance; - if (team_num == client.team) // already on the destination team - { - // keep the forcing undone - LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), (targets ? "^7, skipping to next player.\n" : "^7.")); - continue; - } - else if (team_num == 0) // auto team - { - balance = TeamBalance_CheckAllowedTeams(client); - team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false)); - } - else - { - balance = TeamBalance_CheckAllowedTeams(client); - } - Player_SetForcedTeamIndex(client, save); + // well technically we could, but should we allow that? :P + LOG_INFO("Can't change teams if the player isn't in the game."); + return; + } + if (!teamplay) + { + LOG_INFO("Can't change teams when currently not playing a team game."); + return; + } - // Check to see if the destination team is even available - int team_id = Team_TeamToIndex(team_num); - if (team_id == -1) - { - LOG_INFO("Sorry, can't move player here if team ", destination, " doesn't exist."); - TeamBalance_Destroy(balance); - return; - } - if (!TeamBalance_IsTeamAllowed(balance, team_id)) - { - LOG_INFOF("Sorry, can't move player to %s team if it doesn't exist.", destination); - TeamBalance_Destroy(balance); - return; - } - TeamBalance_Destroy(balance); + // set up + int save = Player_GetForcedTeamIndex(client); + Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT); - // If so, lets continue and finally move the player - Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT); - if (MoveToTeam(client, team_id, 6)) - { - successful = strcat(successful, (successful ? ", " : ""), pl_name); - LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7."); - } - else - { - LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", pl_name, ")"); - } - continue; - } - else - { - LOG_INFO("Can't change teams when currently not playing a team game."); - return; - } + // find the team to move the player to + int team_num = Team_ColorToTeam(destination); + entity balance; + if (team_num == client.team) // already on the destination team + { + // keep the forcing undone + LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), (targets ? "^7, skipping to next player.\n" : "^7.")); + continue; + } + else if (team_num == 0) // auto team + { + balance = TeamBalance_CheckAllowedTeams(client); + team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false)); } else { - LOG_INFO("Can't change teams if the player isn't in the game."); // well technically we could, but should we allow that? :P + balance = TeamBalance_CheckAllowedTeams(client); + } + Player_SetForcedTeamIndex(client, save); + + // Check to see if the destination team is even available + int team_id = Team_TeamToIndex(team_num); + if (team_id == -1) + { + LOG_INFO("Sorry, can't move player here if team ", destination, " doesn't exist."); + TeamBalance_Destroy(balance); + return; + } + if (!TeamBalance_IsTeamAllowed(balance, team_id)) + { + LOG_INFOF("Sorry, can't move player to %s team if it doesn't exist.", destination); + TeamBalance_Destroy(balance); return; } + TeamBalance_Destroy(balance); + + // If so, lets continue and finally move the player + Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT); + if (MoveToTeam(client, team_id, 6)) + { + successful = strcat(successful, (successful ? ", " : ""), pl_name); + LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7."); + } + else + { + LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", pl_name, ")"); + } } - } + } // loop end if (successful) bprint("Successfully moved players ", successful, " to destination ", destination, ".\n"); else LOG_INFO("No players given (", original_targets, ") are able to move.");