X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fteamplay.qc;h=d434571011d1eaea0b93a29d5fec62b42b24f42a;hb=1c61b2c73d8e23c5a052c89c406e29938ff623e0;hp=d16bb781b821998383b8be8460745309cb7b4783;hpb=a4d5506edce8f5c53243f5312da3ae10677a2edd;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index d16bb781b..d43457101 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -190,28 +190,38 @@ void SetPlayerColors(entity pl, float _color) } } -void SetPlayerTeam(entity pl, float t, float s, float noprint) +bool SetPlayerTeamSimple(entity player, int teamnum) { - float _color; - - if(t == 4) - _color = NUM_TEAM_4 - 1; - else if(t == 3) - _color = NUM_TEAM_3 - 1; - else if(t == 2) - _color = NUM_TEAM_2 - 1; - else - _color = NUM_TEAM_1 - 1; - - SetPlayerColors(pl,_color); - - if(t != s) { - LogTeamchange(pl.playerid, pl.team, 3); // log manual team join - - if(!noprint) - bprint(pl.netname, "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n"); + if (player.team == teamnum) + { + return true; } + if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, Team_TeamToNumber( + player.team), Team_TeamToNumber(teamnum)) == true) + { + // Mutator has blocked team change. + return false; + } + int oldteam = player.team; + SetPlayerColors(player, teamnum - 1); + MUTATOR_CALLHOOK(Player_ChangedTeam, player, oldteam, player.team); + return true; +} +void SetPlayerTeam(entity pl, float t, float s, float noprint) +{ + if (t == s) + { + return; + } + float teamnum = Team_NumberToTeam(t); + SetPlayerTeamSimple(pl, teamnum); + LogTeamchange(pl.playerid, pl.team, 3); // log manual team join + if (noprint) + { + return; + } + bprint(playername(pl, false), "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n"); } // set c1...c4 to show what teams are allowed @@ -224,7 +234,7 @@ void CheckAllowedTeams (entity for_whom) string teament_name = string_null; - bool mutator_returnvalue = MUTATOR_CALLHOOK(CheckAllowedTeams, teams_mask, teament_name); + bool mutator_returnvalue = MUTATOR_CALLHOOK(CheckAllowedTeams, teams_mask, teament_name, for_whom); teams_mask = M_ARGV(0, float); teament_name = M_ARGV(1, string); @@ -522,18 +532,20 @@ float FindSmallestTeam(entity pl, float ignore_pl) int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) { - float smallest, selectedteam; - // don't join a team if we're not playing a team game - if(!teamplay) + if (!teamplay) + { return 0; + } // find out what teams are available CheckAllowedTeams(this); + float selectedteam; + // if we don't care what team he ends up on, put him on whatever team he entered as. // if he's not on a valid team, then let other code put him on the smallest team - if(!forcebestteam) + if (!forcebestteam) { if( c1 >= 0 && this.team == NUM_TEAM_1) selectedteam = this.team; @@ -546,11 +558,11 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) else selectedteam = -1; - if(selectedteam > 0) + if (selectedteam > 0) { - if(!only_return_best) + if (!only_return_best) { - SetPlayerColors(this, selectedteam - 1); + SetPlayerTeamSimple(this, selectedteam); // when JoinBestTeam is called by client.qc/ClientKill_Now_TeamChange the players team is -1 and thus skipped // when JoinBestTeam is called by client.qc/ClientConnect the player_id is 0 the log attempt is rejected @@ -561,39 +573,31 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) // otherwise end up on the smallest team (handled below) } - smallest = FindSmallestTeam(this, true); + float bestteam = FindSmallestTeam(this, true); + MUTATOR_CALLHOOK(JoinBestTeam, this, bestteam); + bestteam = M_ARGV(1, float); - if(!only_return_best && !this.bot_forced_team) + if (only_return_best || this.bot_forced_team) + { + return bestteam; + } + bestteam = Team_NumberToTeam(bestteam); + if (bestteam != -1) { TeamchangeFrags(this); - if(smallest == 1) - { - SetPlayerColors(this, NUM_TEAM_1 - 1); - } - else if(smallest == 2) - { - SetPlayerColors(this, NUM_TEAM_2 - 1); - } - else if(smallest == 3) - { - SetPlayerColors(this, NUM_TEAM_3 - 1); - } - else if(smallest == 4) - { - SetPlayerColors(this, NUM_TEAM_4 - 1); - } - else - { - error("smallest team: invalid team\n"); - } - - LogTeamchange(this.playerid, this.team, 2); // log auto join - - if(!IS_DEAD(this)) - Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); + SetPlayerTeamSimple(this, bestteam); } - - return smallest; + else + { + error("JoinBestTeam: invalid team\n"); + } + LogTeamchange(this.playerid, this.team, 2); // log auto join + if (!IS_DEAD(this) && (MUTATOR_CALLHOOK(Player_ChangeTeamKill, this) == + false)) + { + Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); + } + return bestteam; } //void() ctf_playerchanged; @@ -645,7 +649,6 @@ void SV_ChangeTeam(entity this, float _color) // not changing teams if(scolor == dcolor) { - //bprint("same team change\n"); SetPlayerTeam(this, dteam, steam, true); return; } @@ -674,16 +677,18 @@ void SV_ChangeTeam(entity this, float _color) TeamchangeFrags(this); } - MUTATOR_CALLHOOK(Player_ChangeTeam, this, steam, dteam); - SetPlayerTeam(this, dteam, steam, !IS_CLIENT(this)); - if(IS_PLAYER(this) && steam != dteam) + if(!IS_PLAYER(this) || (steam == dteam)) { - // kill player when changing teams - if(!IS_DEAD(this)) - Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); + return; } + // kill player when changing teams + if(IS_DEAD(this) || (MUTATOR_CALLHOOK(Player_ChangeTeamKill, this) == true)) + { + return; + } + Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); } void ShufflePlayerOutOfTeam (float source_team) @@ -818,7 +823,10 @@ void ShufflePlayerOutOfTeam (float source_team) TeamchangeFrags(selected); SetPlayerTeam(selected, smallestteam, source_team, false); - if(!IS_DEAD(selected)) - Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0'); + if (IS_DEAD(selected) || MUTATOR_CALLHOOK(Player_ChangeTeamKill, selected) == true) + { + return; + } + Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0'); Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team); }