X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fteamplay.qc;h=b8f2f3ac8746ea4e02daae0936833d2086954699;hb=c1fc567698f48fbfa3866c7a93406edad4823a1f;hp=cfadcf69966712b98c79f74372ac2f2e9bbc3fd7;hpb=9bc87b511c6daf711937735365adf93db767752d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index cfadcf699..0ba1e7c84 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -6,72 +6,14 @@ float c1, c2, c3, c4; // # of bots on those teams float cb1, cb2, cb3, cb4; -float audit_teams_time; - -float IsTeamBalanceForced() -{ - if(intermission_running) - return 0; // no rebalancing whatsoever please - if(!teamplay) - return 0; - if(autocvar_g_campaign) - return 0; - if(autocvar_bot_vs_human && (c3==-1 && c4==-1)) - return 0; - if(!autocvar_g_balance_teams_force) - return -1; - return 1; -} +//float audit_teams_time; void TeamchangeFrags(entity e) { PlayerScore_Clear(e); } -vector TeamColor(float teem) -{ - switch(teem) - { - case COLOR_TEAM1: - return '1 0.0625 0.0625'; - case COLOR_TEAM2: - return '0.0625 0.0625 1'; - case COLOR_TEAM3: - return '1 1 0.0625'; - case COLOR_TEAM4: - return '1 0.0625 1'; - default: - return '1 1 1'; - } -} - -string TeamName(float t) -{ - return strcat(Team_ColorName(t), " Team"); -} -string ColoredTeamName(float t) -{ - return strcat(Team_ColorCode(t), Team_ColorName(t), " Team^7"); -} -string TeamNoName(float t) -{ - // fixme: Search for team entities and get their .netname's! - if(t == 1) - return "Red Team"; - if(t == 2) - return "Blue Team"; - if(t == 3) - return "Yellow Team"; - if(t == 4) - return "Pink Team"; - return "Neutral Team"; -} - -void dom_init(); -void ctf_init(); -void runematch_init(); void tdm_init(); -void nb_init(); void entcs_init(); void LogTeamchange(float player_id, float team_number, float type) @@ -132,15 +74,14 @@ void InitGameplayMode() timelimit_override = autocvar_timelimit_override; fraglimit_override = autocvar_fraglimit_override; leadlimit_override = autocvar_leadlimit_override; + gamemode_name = MapInfo_Type_ToText(MapInfo_LoadedGametype); if(g_dm) { - gamemode_name = "Deathmatch"; } if(g_tdm) { - gamemode_name = "Team Deathmatch"; ActivateTeamplay(); tdm_init(); if(autocvar_g_tdm_team_spawns) @@ -149,77 +90,48 @@ void InitGameplayMode() if(g_domination) { - gamemode_name = "Domination"; ActivateTeamplay(); fraglimit_override = autocvar_g_domination_point_limit; leadlimit_override = autocvar_g_domination_point_leadlimit; - dom_init(); + MUTATOR_ADD(gamemode_domination); have_team_spawns = -1; // request team spawns } if(g_ctf) { - gamemode_name = "Capture the Flag"; ActivateTeamplay(); - g_ctf_ignore_frags = autocvar_g_ctf_ignore_frags; - if(g_ctf_win_mode == 2) - { - fraglimit_override = autocvar_g_ctf_capture_limit; - leadlimit_override = autocvar_g_ctf_capture_leadlimit; - } - else - { - fraglimit_override = autocvar_capturelimit_override; - leadlimit_override = autocvar_captureleadlimit_override; - } - ctf_init(); + fraglimit_override = autocvar_capturelimit_override; + leadlimit_override = autocvar_captureleadlimit_override; + MUTATOR_ADD(gamemode_ctf); have_team_spawns = -1; // request team spawns } - if(g_runematch) - { - gamemode_name = "Rune Match"; - // ActivateTeamplay(); - fraglimit_override = autocvar_g_runematch_point_limit; - leadlimit_override = autocvar_g_runematch_point_leadlimit; - runematch_init(); - } - if(g_lms) { - gamemode_name = "Last Man Standing"; fraglimit_override = autocvar_g_lms_lives_override; leadlimit_override = 0; // not supported by LMS if(fraglimit_override == 0) fraglimit_override = -1; - lms_lowest_lives = 9999; - lms_next_place = 0; - ScoreRules_lms(); + MUTATOR_ADD(gamemode_lms); } if(g_arena) { - gamemode_name = "Arena"; fraglimit_override = autocvar_g_arena_point_limit; leadlimit_override = autocvar_g_arena_point_leadlimit; - maxspawned = autocvar_g_arena_maxspawned; - if(maxspawned < 2) - maxspawned = 2; - arena_roundbased = autocvar_g_arena_roundbased; + MUTATOR_ADD(gamemode_arena); } if(g_ca) { - gamemode_name = "Clan Arena"; ActivateTeamplay(); fraglimit_override = autocvar_g_ca_point_limit; leadlimit_override = autocvar_g_ca_point_leadlimit; - precache_sound("ctf/red_capture.wav"); - precache_sound("ctf/blue_capture.wav"); + MUTATOR_ADD(gamemode_ca); } + if(g_keyhunt) { - gamemode_name = "Key Hunt"; ActivateTeamplay(); fraglimit_override = autocvar_g_keyhunt_point_limit; leadlimit_override = autocvar_g_keyhunt_point_leadlimit; @@ -228,7 +140,6 @@ void InitGameplayMode() if(g_freezetag) { - gamemode_name = "Freeze Tag"; ActivateTeamplay(); fraglimit_override = autocvar_g_freezetag_point_limit; leadlimit_override = autocvar_g_freezetag_point_leadlimit; @@ -237,22 +148,20 @@ void InitGameplayMode() if(g_assault) { - gamemode_name = "Assault"; ActivateTeamplay(); - ScoreRules_assault(); + MUTATOR_ADD(gamemode_assault); have_team_spawns = -1; // request team spawns } if(g_onslaught) { - gamemode_name = "Onslaught"; ActivateTeamplay(); have_team_spawns = -1; // request team spawns + MUTATOR_ADD(gamemode_onslaught); } if(g_race) { - gamemode_name = "Race"; if(autocvar_g_race_teams) { @@ -270,7 +179,6 @@ void InitGameplayMode() if(g_cts) { - gamemode_name = "CTS"; g_race_qualifying = 1; fraglimit_override = 0; leadlimit_override = 0; @@ -278,17 +186,15 @@ void InitGameplayMode() if(g_nexball) { - gamemode_name = "Nexball"; - fraglimit_override = autocvar_g_nexball_goallimit; - leadlimit_override = autocvar_g_nexball_goalleadlimit; - ActivateTeamplay(); - nb_init(); - have_team_spawns = -1; // request team spawns + fraglimit_override = autocvar_g_nexball_goallimit; + leadlimit_override = autocvar_g_nexball_goalleadlimit; + ActivateTeamplay(); + have_team_spawns = -1; // request team spawns + MUTATOR_ADD(gamemode_nexball); } - + if(g_keepaway) { - gamemode_name = "Keepaway"; MUTATOR_ADD(gamemode_keepaway); } @@ -364,9 +270,7 @@ string getwelcomemessage(void) ret_string = ""; MUTATOR_CALLHOOK(BuildMutatorsPrettyString); modifications = ret_string; - - if(g_minstagib) - modifications = strcat(modifications, ", MinstaGib"); + if(g_weaponarena) { if(g_weaponarena_random) @@ -457,13 +361,13 @@ void SetPlayerTeam(entity pl, float t, float s, float noprint) float _color; if(t == 4) - _color = COLOR_TEAM4 - 1; + _color = NUM_TEAM_4 - 1; else if(t == 3) - _color = COLOR_TEAM3 - 1; + _color = NUM_TEAM_3 - 1; else if(t == 2) - _color = COLOR_TEAM2 - 1; + _color = NUM_TEAM_2 - 1; else - _color = COLOR_TEAM1 - 1; + _color = NUM_TEAM_1 - 1; SetPlayerColors(pl,_color); @@ -471,7 +375,7 @@ void SetPlayerTeam(entity pl, float t, float s, float noprint) LogTeamchange(pl.playerid, pl.team, 3); // log manual team join if(!noprint) - bprint(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"); + bprint(pl.netname, "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n"); } } @@ -486,16 +390,17 @@ void CheckAllowedTeams (entity for_whom) c1 = c2 = c3 = c4 = -1; cb1 = cb2 = cb3 = cb4 = 0; + teament_name = string_null; if(g_onslaught) { // onslaught is special head = findchain(classname, "onslaught_generator"); while (head) { - if (head.team == COLOR_TEAM1) c1 = 0; - if (head.team == COLOR_TEAM2) c2 = 0; - if (head.team == COLOR_TEAM3) c3 = 0; - if (head.team == COLOR_TEAM4) c4 = 0; + if (head.team == NUM_TEAM_1) c1 = 0; + if (head.team == NUM_TEAM_2) c2 = 0; + if (head.team == NUM_TEAM_3) c3 = 0; + if (head.team == NUM_TEAM_4) c4 = 0; head = head.chain; } } @@ -537,13 +442,13 @@ void CheckAllowedTeams (entity for_whom) { if(!(g_domination && head.netname == "")) { - if(head.team == COLOR_TEAM1) + if(head.team == NUM_TEAM_1) c1 = 0; - else if(head.team == COLOR_TEAM2) + else if(head.team == NUM_TEAM_2) c2 = 0; - else if(head.team == COLOR_TEAM3) + else if(head.team == NUM_TEAM_3) c3 = 0; - else if(head.team == COLOR_TEAM4) + else if(head.team == NUM_TEAM_4) c4 = 0; } head = find(head, classname, teament_name); @@ -557,7 +462,7 @@ void CheckAllowedTeams (entity for_whom) if(autocvar_bot_vs_human > 0) { // bots are all blue - if(clienttype(for_whom) == CLIENTTYPE_BOT) + if(IS_BOT_CLIENT(for_whom)) c1 = c3 = c4 = -1; else c2 = -1; @@ -565,7 +470,7 @@ void CheckAllowedTeams (entity for_whom) else { // bots are all red - if(clienttype(for_whom) == CLIENTTYPE_BOT) + if(IS_BOT_CLIENT(for_whom)) c2 = c3 = c4 = -1; else c1 = -1; @@ -573,20 +478,18 @@ void CheckAllowedTeams (entity for_whom) } // if player has a forced team, ONLY allow that one - if(self.team_forced == COLOR_TEAM1 && c1 >= 0) + if(self.team_forced == NUM_TEAM_1 && c1 >= 0) c2 = c3 = c4 = -1; - else if(self.team_forced == COLOR_TEAM2 && c2 >= 0) + else if(self.team_forced == NUM_TEAM_2 && c2 >= 0) c1 = c3 = c4 = -1; - else if(self.team_forced == COLOR_TEAM3 && c3 >= 0) + else if(self.team_forced == NUM_TEAM_3 && c3 >= 0) c1 = c2 = c4 = -1; - else if(self.team_forced == COLOR_TEAM4 && c4 >= 0) + else if(self.team_forced == NUM_TEAM_4 && c4 >= 0) c1 = c2 = c3 = -1; } float PlayerValue(entity p) { - if(IsTeamBalanceForced() == 1) - return 1; return 1; // FIXME: it always returns 1... } @@ -605,7 +508,7 @@ void GetTeamCounts(entity ignore) FOR_EACH_CLIENT(head) { float t; - if(head.classname == "player") + if(IS_PLAYER(head)) t = head.team; else if(head.team_forced > 0) t = head.team_forced; // reserve the spot @@ -614,11 +517,11 @@ void GetTeamCounts(entity ignore) if(head != ignore)// && head.netname != "") { value = PlayerValue(head); - if(clienttype(head) == CLIENTTYPE_BOT) + if(IS_BOT_CLIENT(head)) bvalue = value; else bvalue = 0; - if(t == COLOR_TEAM1) + if(t == NUM_TEAM_1) { if(c1 >= 0) { @@ -626,7 +529,7 @@ void GetTeamCounts(entity ignore) cb1 = cb1 + bvalue; } } - if(t == COLOR_TEAM2) + if(t == NUM_TEAM_2) { if(c2 >= 0) { @@ -634,7 +537,7 @@ void GetTeamCounts(entity ignore) cb2 = cb2 + bvalue; } } - if(t == COLOR_TEAM3) + if(t == NUM_TEAM_3) { if(c3 >= 0) { @@ -642,7 +545,7 @@ void GetTeamCounts(entity ignore) cb3 = cb3 + bvalue; } } - if(t == COLOR_TEAM4) + if(t == NUM_TEAM_4) { if(c4 >= 0) { @@ -666,11 +569,73 @@ void GetTeamCounts(entity ignore) } } +float TeamSmallerEqThanTeam(float ta, float tb, entity e) +{ + // we assume that CheckAllowedTeams and GetTeamCounts have already been called + float f; + float ca = -1, cb = -1, cba = 0, cbb = 0, sa = 0, sb = 0; + + switch(ta) + { + case 1: ca = c1; cba = cb1; sa = team1_score; break; + case 2: ca = c2; cba = cb2; sa = team2_score; break; + case 3: ca = c3; cba = cb3; sa = team3_score; break; + case 4: ca = c4; cba = cb4; sa = team4_score; break; + } + switch(tb) + { + case 1: cb = c1; cbb = cb1; sb = team1_score; break; + case 2: cb = c2; cbb = cb2; sb = team2_score; break; + case 3: cb = c3; cbb = cb3; sb = team3_score; break; + case 4: cb = c4; cbb = cb4; sb = team4_score; break; + } + + // invalid + if(ca < 0 || cb < 0) + return FALSE; + + // equal + if(ta == tb) + return TRUE; + + if(IS_REAL_CLIENT(e)) + { + if(bots_would_leave) + { + ca -= cba * 0.999; + cb -= cbb * 0.999; + } + } + + // keep teams alive (teams of size 0 always count as smaller, ignoring score) + if(ca < 1) + if(cb >= 1) + return TRUE; + if(ca >= 1) + if(cb < 1) + return FALSE; + + // first, normalize + f = max(ca, cb, 1); + ca /= f; + cb /= f; + f = max(sa, sb, 1); + sa /= f; + sb /= f; + + // the more we're at the end of the match, the more take scores into account + f = bound(0, game_completion_ratio * autocvar_g_balance_teams_scorefactor, 1); + ca += (sa - ca) * f; + cb += (sb - cb) * f; + + return ca <= cb; +} + // returns # of smallest team (1, 2, 3, 4) // NOTE: Assumes CheckAllowedTeams has already been called! float FindSmallestTeam(entity pl, float ignore_pl) { - float totalteams, balance_type, maxc; + float totalteams, t; totalteams = 0; // find out what teams are available @@ -691,7 +656,7 @@ float FindSmallestTeam(entity pl, float ignore_pl) if(totalteams <= 1) { - if(autocvar_g_campaign && pl && clienttype(pl) == CLIENTTYPE_REAL) + if(autocvar_g_campaign && pl && IS_REAL_CLIENT(pl)) return 1; // special case for campaign and player joining else if(g_domination) error("Too few teams available for domination\n"); @@ -711,49 +676,26 @@ float FindSmallestTeam(entity pl, float ignore_pl) else GetTeamCounts(world); - // c1...c4 now have counts of each team - // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker - - // 2 gives priority to what team you're already on, 1 goes in order - // 2 doesn't seem to work though... - balance_type = 1; - - if(bots_would_leave) - //if(pl.classname != "player") - if(clienttype(pl) != CLIENTTYPE_BOT) - { - c1 -= cb1 * 255.0/256.0; - c2 -= cb2 * 255.0/256.0; - c3 -= cb3 * 255.0/256.0; - c4 -= cb4 * 255.0/256.0; - } - maxc = max4(c1, c2, c3, c4); - RandomSelection_Init(); - if(balance_type == 1) - { - // 1: use team count, then score (note: can only use 8 significant bits of score) - if(c1 >= 0) RandomSelection_Add(world, 1, string_null, 1, (maxc - c1) + float2range01(-team1_score) / 256.0); - if(c2 >= 0) RandomSelection_Add(world, 2, string_null, 1, (maxc - c2) + float2range01(-team2_score) / 256.0); - if(c3 >= 0) RandomSelection_Add(world, 3, string_null, 1, (maxc - c3) + float2range01(-team3_score) / 256.0); - if(c4 >= 0) RandomSelection_Add(world, 4, string_null, 1, (maxc - c4) + float2range01(-team4_score) / 256.0); - } - else if(balance_type == 2) - { - // 1: use team count, if equal prefer own team - if(c1 >= 0) RandomSelection_Add(world, 1, string_null, 1, (maxc - c1) + (self.team == COLOR_TEAM1) / 512.0); - if(c2 >= 0) RandomSelection_Add(world, 2, string_null, 1, (maxc - c1) + (self.team == COLOR_TEAM2) / 512.0); - if(c3 >= 0) RandomSelection_Add(world, 3, string_null, 1, (maxc - c1) + (self.team == COLOR_TEAM3) / 512.0); - if(c4 >= 0) RandomSelection_Add(world, 4, string_null, 1, (maxc - c1) + (self.team == COLOR_TEAM4) / 512.0); - } - else if(balance_type == 3) - { - // 1: use team count, then score, if equal prefer own team (probably fails due to float accuracy problems) - if(c1 >= 0) RandomSelection_Add(world, 1, string_null, 1, (maxc - c1) + float2range01(-team1_score + 0.5 * (self.team == COLOR_TEAM1)) / 256.0); - if(c2 >= 0) RandomSelection_Add(world, 2, string_null, 1, (maxc - c2) + float2range01(-team2_score + 0.5 * (self.team == COLOR_TEAM2)) / 256.0); - if(c3 >= 0) RandomSelection_Add(world, 3, string_null, 1, (maxc - c3) + float2range01(-team3_score + 0.5 * (self.team == COLOR_TEAM3)) / 256.0); - if(c4 >= 0) RandomSelection_Add(world, 4, string_null, 1, (maxc - c4) + float2range01(-team4_score + 0.5 * (self.team == COLOR_TEAM4)) / 256.0); - } + + t = 1; + if(TeamSmallerEqThanTeam(2, t, pl)) + t = 2; + if(TeamSmallerEqThanTeam(3, t, pl)) + t = 3; + if(TeamSmallerEqThanTeam(4, t, pl)) + t = 4; + + // now t is the minimum, or A minimum! + if(t == 1 || TeamSmallerEqThanTeam(1, t, pl)) + RandomSelection_Add(world, 1, string_null, 1, 1); + if(t == 2 || TeamSmallerEqThanTeam(2, t, pl)) + RandomSelection_Add(world, 2, string_null, 1, 1); + if(t == 3 || TeamSmallerEqThanTeam(3, t, pl)) + RandomSelection_Add(world, 3, string_null, 1, 1); + if(t == 4 || TeamSmallerEqThanTeam(4, t, pl)) + RandomSelection_Add(world, 4, string_null, 1, 1); + return RandomSelection_chosen_float; } @@ -772,13 +714,13 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) // if he's not on a valid team, then let other code put him on the smallest team if(!forcebestteam) { - if( c1 >= 0 && pl.team == COLOR_TEAM1) + if( c1 >= 0 && pl.team == NUM_TEAM_1) selectedteam = pl.team; - else if(c2 >= 0 && pl.team == COLOR_TEAM2) + else if(c2 >= 0 && pl.team == NUM_TEAM_2) selectedteam = pl.team; - else if(c3 >= 0 && pl.team == COLOR_TEAM3) + else if(c3 >= 0 && pl.team == NUM_TEAM_3) selectedteam = pl.team; - else if(c4 >= 0 && pl.team == COLOR_TEAM4) + else if(c4 >= 0 && pl.team == NUM_TEAM_4) selectedteam = pl.team; else selectedteam = -1; @@ -805,19 +747,19 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) TeamchangeFrags(self); if(smallest == 1) { - SetPlayerColors(pl, COLOR_TEAM1 - 1); + SetPlayerColors(pl, NUM_TEAM_1 - 1); } else if(smallest == 2) { - SetPlayerColors(pl, COLOR_TEAM2 - 1); + SetPlayerColors(pl, NUM_TEAM_2 - 1); } else if(smallest == 3) { - SetPlayerColors(pl, COLOR_TEAM3 - 1); + SetPlayerColors(pl, NUM_TEAM_3 - 1); } else if(smallest == 4) { - SetPlayerColors(pl, COLOR_TEAM4 - 1); + SetPlayerColors(pl, NUM_TEAM_4 - 1); } else { @@ -836,7 +778,7 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) //void() ctf_playerchanged; void SV_ChangeTeam(float _color) { - float scolor, dcolor, steam, dteam, dbotcount, scount, dcount; + float scolor, dcolor, steam, dteam; //, dbotcount, scount, dcount; // in normal deathmatch we can just apply the color and we're done if(!teamplay) { @@ -847,21 +789,21 @@ void SV_ChangeTeam(float _color) scolor = self.clientcolors & 0x0F; dcolor = _color & 0x0F; - if(scolor == COLOR_TEAM1 - 1) + if(scolor == NUM_TEAM_1 - 1) steam = 1; - else if(scolor == COLOR_TEAM2 - 1) + else if(scolor == NUM_TEAM_2 - 1) steam = 2; - else if(scolor == COLOR_TEAM3 - 1) + else if(scolor == NUM_TEAM_3 - 1) steam = 3; - else // if(scolor == COLOR_TEAM4 - 1) + else // if(scolor == NUM_TEAM_4 - 1) steam = 4; - if(dcolor == COLOR_TEAM1 - 1) + if(dcolor == NUM_TEAM_1 - 1) dteam = 1; - else if(dcolor == COLOR_TEAM2 - 1) + else if(dcolor == NUM_TEAM_2 - 1) dteam = 2; - else if(dcolor == COLOR_TEAM3 - 1) + else if(dcolor == NUM_TEAM_3 - 1) dteam = 3; - else // if(dcolor == COLOR_TEAM4 - 1) + else // if(dcolor == NUM_TEAM_4 - 1) dteam = 4; CheckAllowedTeams(self); @@ -884,67 +826,20 @@ void SV_ChangeTeam(float _color) return; // changing teams is not allowed } - if(autocvar_g_balance_teams_prevent_imbalance) + // autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless + if(autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance) { - // only allow changing to a smaller or equal size team - - // find out what teams are available - //CheckAllowedTeams(); - // count how many players on each team - GetTeamCounts(world); - - // get desired team - if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1) - { - dcount = c1; - dbotcount = cb1; - } - else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1) - { - dcount = c2; - dbotcount = cb2; - } - else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1) + GetTeamCounts(self); + if(!TeamSmallerEqThanTeam(dteam, steam, self)) { - dcount = c3; - dbotcount = cb3; - } - else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1) - { - dcount = c4; - dbotcount = cb4; - } - else - { - sprint(self, "Cannot change to an invalid team\n"); - + sprint(self, "Cannot change to a larger/better/shinier team\n"); return; } - - // get starting team - if(steam == 1)//scolor == COLOR_TEAM1 - 1) - scount = c1; - else if(steam == 2)//scolor == COLOR_TEAM2 - 1) - scount = c2; - else if(steam == 3)//scolor == COLOR_TEAM3 - 1) - scount = c3; - else if(steam == 4)//scolor == COLOR_TEAM4 - 1) - scount = c4; - - if(scount) // started at a valid, nonempty team - { - // check if we're trying to change to a larger team that doens't have bots to swap with - if(dcount >= scount && dbotcount <= 0) - { - sprint(self, "Cannot change to a larger team\n"); - return; // can't change to a larger team - } - } } // bprint("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"); - if(self.classname == "player" && steam != dteam) + if(IS_PLAYER(self) && steam != dteam) { // reduce frags during a team change TeamchangeFrags(self); @@ -952,13 +847,12 @@ void SV_ChangeTeam(float _color) SetPlayerTeam(self, dteam, steam, FALSE); - if(self.classname == "player" && steam != dteam) + if(IS_PLAYER(self) && steam != dteam) { // kill player when changing teams if(self.deadflag == DEAD_NO) Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0'); } - //ctf_playerchanged(); } void ShufflePlayerOutOfTeam (float source_team) @@ -998,13 +892,13 @@ void ShufflePlayerOutOfTeam (float source_team) } if(source_team == 1) - steam = COLOR_TEAM1; + steam = NUM_TEAM_1; else if(source_team == 2) - steam = COLOR_TEAM2; + steam = NUM_TEAM_2; else if(source_team == 3) - steam = COLOR_TEAM3; - else if(source_team == 4) - steam = COLOR_TEAM4; + steam = NUM_TEAM_3; + else // if(source_team == 4) + steam = NUM_TEAM_4; lowest_bot = world; lowest_bot_score = 999999999; @@ -1099,88 +993,7 @@ void ShufflePlayerOutOfTeam (float source_team) if(selected.deadflag == DEAD_NO) Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0'); - centerprint(selected, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(selected.team))); -} - -void CauseRebalance(float source_team, float howmany_toomany) -{ - if(IsTeamBalanceForced() == 1) - { - bprint("Rebalancing Teams\n"); - ShufflePlayerOutOfTeam(source_team); - } -} - -// part of g_balance_teams_force -// occasionally perform an audit of the teams to make -// sure they're more or less balanced in player count. -void AuditTeams() -{ - float numplayers, numteams, smallest, toomany; - float balance; - balance = IsTeamBalanceForced(); - if(balance == 0) - return; - - if(audit_teams_time > time) - return; - - audit_teams_time = time + 4 + random(); - -// bprint("Auditing teams\n"); - - CheckAllowedTeams(world); - GetTeamCounts(world); - - - numteams = numplayers = smallest = 0; - if(c1 >= 0) - { - numteams = numteams + 1; - numplayers = numplayers + c1; - smallest = c1; - } - if(c2 >= 0) - { - numteams = numteams + 1; - numplayers = numplayers + c2; - if(c2 < smallest) - smallest = c2; - } - if(c3 >= 0) - { - numteams = numteams + 1; - numplayers = numplayers + c3; - if(c3 < smallest) - smallest = c3; - } - if(c4 >= 0) - { - numteams = numteams + 1; - numplayers = numplayers + c4; - if(c4 < smallest) - smallest = c4; - } - - if(numplayers <= 0) - return; // no players to move around - if(numteams < 2) - return; // don't bother shuffling if for some reason there aren't any teams - - toomany = smallest + 1; - - if(c1 && c1 > toomany) - CauseRebalance(1, c1 - toomany); - if(c2 && c2 > toomany) - CauseRebalance(2, c2 - toomany); - if(c3 && c3 > toomany) - CauseRebalance(3, c3 - toomany); - if(c4 && c4 > toomany) - CauseRebalance(4, c4 - toomany); - - // if teams are still unbalanced, balance them further in the next audit, - // which will happen sooner (keep doing rapid audits until things are in order) - audit_teams_time = time + 0.7 + random()*0.3; + centerprint(selected, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", Team_ColoredFullName(selected.team))); } // code from here on is just to support maps that don't have team entities @@ -1204,12 +1017,12 @@ void tdm_spawnteams() numteams = autocvar_g_tdm_teams; numteams = bound(2, numteams, 4); - tdm_spawnteam("Red", COLOR_TEAM1-1); - tdm_spawnteam("Blue", COLOR_TEAM2-1); + tdm_spawnteam("Red", NUM_TEAM_1-1); + tdm_spawnteam("Blue", NUM_TEAM_2-1); if(numteams >= 3) - tdm_spawnteam("Yellow", COLOR_TEAM3-1); + tdm_spawnteam("Yellow", NUM_TEAM_3-1); if(numteams >= 4) - tdm_spawnteam("Pink", COLOR_TEAM4-1); + tdm_spawnteam("Pink", NUM_TEAM_4-1); } void tdm_delayedinit()