X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fserver%2Fteamplay.qc;h=43aa4a26bd24e61d362d64dce55f33090ee88c9a;hb=3cfa3eaf6856fe76f7fd8c945fbfab2e9e28014c;hp=92cd8ebccedede1cfabe53bbb3211cb31df71890;hpb=acf114225f94bed609c10c74e1bb1277d28a7419;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 92cd8ebcc..43aa4a26b 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -37,21 +37,20 @@ void default_delayedinit(entity this) ScoreRules_generic(); } -void ActivateTeamplay() -{ - serverflags |= SERVERFLAG_TEAMPLAY; - teamplay = 1; - cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. -} - void InitGameplayMode() { VoteReset(); // find out good world mins/maxs bounds, either the static bounds found by looking for solid, or the mapinfo specified bounds get_mi_min_max(1); - world.mins = mi_min; - world.maxs = mi_max; + // assign reflectively to avoid "assignment to world" warning + int done = 0; for (int i = 0, n = numentityfields(); i < n; ++i) { + string k = entityfieldname(i); vector v = (k == "mins") ? mi_min : (k == "maxs") ? mi_max : '0 0 0'; + if (v) { + putentityfieldstring(i, world, sprintf("%v", v)); + if (++done == 2) break; + } + } // currently, NetRadiant's limit is 131072 qu for each side // distance from one corner of a 131072qu cube to the opposite corner is approx. 227023 qu // set the distance according to map size but don't go over the limit to avoid issues with float precision @@ -59,13 +58,11 @@ void InitGameplayMode() max_shot_distance = min(230000, vlen(world.maxs - world.mins)); MapInfo_LoadMapSettings(mapname); - serverflags &= ~SERVERFLAG_TEAMPLAY; - teamplay = 0; - cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies. + GameRules_teams(false); if (!cvar_value_issafe(world.fog)) { - LOG_INFO("The current map contains a potentially harmful fog setting, ignored\n"); + LOG_INFO("The current map contains a potentially harmful fog setting, ignored"); world.fog = string_null; } if(MapInfo_Map_fog != "") @@ -134,12 +131,8 @@ string getwelcomemessage(entity this) if(cache_lastmutatormsg != autocvar_g_mutatormsg) { - if(cache_lastmutatormsg) - strunzone(cache_lastmutatormsg); - if(cache_mutatormsg) - strunzone(cache_mutatormsg); - cache_lastmutatormsg = strzone(autocvar_g_mutatormsg); - cache_mutatormsg = strzone(cache_lastmutatormsg); + strcpy(cache_lastmutatormsg, autocvar_g_mutatormsg); + strcpy(cache_mutatormsg, cache_lastmutatormsg); } if (cache_mutatormsg != "") { @@ -193,7 +186,7 @@ void KillPlayerForTeamChange(entity player) { return; } - Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, player.origin, + Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, DMG_NOWEP, player.origin, '0 0 0'); } @@ -548,6 +541,14 @@ void GetTeamCounts(entity ignore) bool IsTeamSmallerThanTeam(int team_a, int team_b, entity player, bool use_score) { + if (!Team_IsValidNumber(team_a)) + { + LOG_FATALF("IsTeamSmallerThanTeam: team_a is invalid: %f", team_a); + } + if (!Team_IsValidNumber(team_b)) + { + LOG_FATALF("IsTeamSmallerThanTeam: team_b is invalid: %f", team_b); + } if (team_a == team_b) { return false; @@ -645,6 +646,14 @@ bool IsTeamSmallerThanTeam(int team_a, int team_b, entity player, bool IsTeamEqualToTeam(int team_a, int team_b, entity player, bool use_score) { + if (!Team_IsValidNumber(team_a)) + { + LOG_FATALF("IsTeamEqualToTeam: team_a is invalid: %f", team_a); + } + if (!Team_IsValidNumber(team_b)) + { + LOG_FATALF("IsTeamEqualToTeam: team_b is invalid: %f", team_b); + } if (team_a == team_b) { return true; @@ -840,54 +849,56 @@ int FindSmallestTeam(entity player, float ignore_player) return RandomSelection_chosen_float; } -int JoinBestTeam(entity this, bool only_return_best, bool force_best_team) +void JoinBestTeam(entity this, bool force_best_team) { // don't join a team if we're not playing a team game if (!teamplay) { - return 0; + return; } // find out what teams are available CheckAllowedTeams(this); - int selected_team; - - // 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 we don't care what team they end up on, put them on whatever team they entered as. + // if they're not on a valid team, then let other code put them on the smallest team if (!force_best_team) { - if( c1 >= 0 && this.team == NUM_TEAM_1) + int selected_team; + if ((c1 >= 0) && (this.team == NUM_TEAM_1)) + { selected_team = this.team; - else if(c2 >= 0 && this.team == NUM_TEAM_2) + } + else if ((c2 >= 0) && (this.team == NUM_TEAM_2)) + { selected_team = this.team; - else if(c3 >= 0 && this.team == NUM_TEAM_3) + } + else if ((c3 >= 0) && (this.team == NUM_TEAM_3)) + { selected_team = this.team; - else if(c4 >= 0 && this.team == NUM_TEAM_4) + } + else if ((c4 >= 0) && (this.team == NUM_TEAM_4)) + { selected_team = this.team; + } else + { selected_team = -1; + } if (selected_team > 0) { - if (!only_return_best) - { - SetPlayerTeamSimple(this, selected_team); - - // 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 - LogTeamchange(this.playerid, this.team, 99); - } - return selected_team; + SetPlayerTeamSimple(this, selected_team); + LogTeamchange(this.playerid, this.team, 99); + return; } - // otherwise end up on the smallest team (handled below) } - - int best_team = FindSmallestTeam(this, true); - if (only_return_best || this.bot_forced_team) + // otherwise end up on the smallest team (handled below) + if (this.bot_forced_team) { - return best_team; + return; } + int best_team = FindSmallestTeam(this, true); best_team = Team_NumberToTeam(best_team); if (best_team == -1) { @@ -897,12 +908,11 @@ int JoinBestTeam(entity this, bool only_return_best, bool force_best_team) TeamchangeFrags(this); SetPlayerTeamSimple(this, best_team); LogTeamchange(this.playerid, this.team, 2); // log auto join - if (!IS_BOT_CLIENT(this)) + if ((old_team != -1) && !IS_BOT_CLIENT(this)) { AutoBalanceBots(old_team, Team_TeamToNumber(best_team)); } KillPlayerForTeamChange(this); - return best_team; } void SV_ChangeTeam(entity this, float _color) @@ -929,6 +939,11 @@ void SV_ChangeTeam(entity this, float _color) source_team = Team_TeamToNumber(source_color + 1); destination_team = Team_TeamToNumber(destination_color + 1); + if (destination_team == -1) + { + return; + } + CheckAllowedTeams(this); if (destination_team == 1 && c1 < 0) destination_team = 4; @@ -977,8 +992,15 @@ void SV_ChangeTeam(entity this, float _color) void AutoBalanceBots(int source_team, int destination_team) { - if ((source_team == -1) || (destination_team == -1)) + if (!Team_IsValidNumber(source_team)) + { + LOG_WARNF("AutoBalanceBots: Source team is invalid: %f", source_team); + return; + } + if (!Team_IsValidNumber(destination_team)) { + LOG_WARNF("AutoBalanceBots: Destination team is invalid: %f", + destination_team); return; } if (!autocvar_g_balance_teams || @@ -1012,6 +1034,10 @@ void AutoBalanceBots(int source_team, int destination_team) break; } } + if (num_players_source_team < 0) + { + return; + } switch (destination_team) { case 1: