2 string cache_mutatormsg;
4 string cache_lastmutatormsg;
6 // client counts for each team
8 // # of bots on those teams
9 float cb1, cb2, cb3, cb4;
11 float audit_teams_time;
13 float IsTeamBalanceForced()
15 if(intermission_running)
16 return 0; // no rebalancing whatsoever please
19 if(cvar("g_campaign"))
21 if(!cvar("g_balance_teams_force"))
26 void TeamchangeFrags(entity e)
31 vector TeamColor(float teem)
36 return '1 0.0625 0.0625';
38 return '0.0625 0.0625 1';
48 string TeamName(float t)
50 return strcat(Team_ColorName(t), " Team");
52 string ColoredTeamName(float t)
54 return strcat(Team_ColorCode(t), Team_ColorName(t), " Team^7");
56 string TeamNoName(float t)
58 // fixme: Search for team entities and get their .netname's!
67 return "Neutral Team";
72 void runematch_init();
76 void LogTeamchange(entity pl)
79 if(!cvar("sv_eventlog"))
83 str = strcat(":team:", ftos(pl.playerid), ":");
84 str = strcat(str, ftos(pl.team));
90 cvar_set("g_dm", ftos(g_dm));
91 cvar_set("g_tdm", ftos(g_tdm));
92 cvar_set("g_domination", ftos(g_domination));
93 cvar_set("g_ctf", ftos(g_ctf));
94 cvar_set("g_runematch", ftos(g_runematch));
95 cvar_set("g_lms", ftos(g_lms));
96 cvar_set("g_arena", ftos(g_arena));
97 cvar_set("g_keyhunt", ftos(g_keyhunt));
98 cvar_set("g_assault", ftos(g_assault));
99 cvar_set("g_onslaught", ftos(g_onslaught));
100 cvar_set("g_race", ftos(g_race));
110 prev = cvar("gamecfg");
111 for(i = 0; i < 2; ++i)
113 found += (g_dm = (!found && (prev != GAME_DEATHMATCH) && cvar("g_dm")));
114 found += (g_tdm = (!found && (prev != GAME_TEAM_DEATHMATCH) && cvar("g_tdm")));
115 found += (g_domination = (!found && (prev != GAME_DOMINATION) && cvar("g_domination")));
116 found += (g_ctf = (!found && (prev != GAME_CTF) && cvar("g_ctf")));
117 found += (g_runematch = (!found && (prev != GAME_RUNEMATCH) && cvar("g_runematch")));
118 found += (g_lms = (!found && (prev != GAME_LMS) && cvar("g_lms")));
119 found += (g_arena = (!found && (prev != GAME_ARENA) && cvar("g_arena")));
120 found += (g_keyhunt = (!found && (prev != GAME_KEYHUNT) && cvar("g_keyhunt")));
121 found += (g_assault = (!found && (prev != GAME_ASSAULT) && cvar("g_assault")));
122 found += (g_onslaught = (!found && (prev != GAME_ONSLAUGHT) && cvar("g_onslaught")));
123 found += (g_race = (!found && (prev != GAME_RACE) && cvar("g_race")));
128 prev = -1; // second attempt takes place WITHOUT prev set
134 if(g_dm && cvar("deathmatch_force_teamplay"))
143 void default_delayedinit()
145 if(!scores_initialized)
146 ScoreRules_generic();
149 void ActivateTeamplay()
151 float teamplay_default;
152 teamplay_default = cvar("teamplay_default");
155 cvar_set("teamplay", ftos(teamplay_default));
157 cvar_set("teamplay", "3");
162 void InitGameplayMode()
164 float fraglimit_override, timelimit_override;
169 cvar_set("teamplay", "0");
171 // make sure only ONE type is selected
175 MapInfo_LoadMapSettings(mapname);
176 clientstuff = strzone(MapInfo_Map_clientstuff);
177 MapInfo_ClearTemps();
179 // in case mapinfo switched the type
182 // set both here, gamemode can override it later
183 timelimit_override = cvar("timelimit_override");
184 fraglimit_override = cvar("fraglimit_override");
188 game = GAME_DEATHMATCH;
189 gamemode_name = "Deathmatch";
194 game = GAME_TEAM_DEATHMATCH;
195 gamemode_name = "Team Deathmatch";
202 game = GAME_DOMINATION;
203 gamemode_name = "Domination";
205 fraglimit_override = cvar("g_domination_point_limit");
212 gamemode_name = "Capture the Flag";
214 g_ctf_win_mode = cvar("g_ctf_win_mode");
215 if(g_ctf_win_mode == 2)
216 fraglimit_override = cvar("g_ctf_capture_limit");
218 fraglimit_override = cvar("capturelimit_override");
224 game = GAME_RUNEMATCH;
225 gamemode_name = "Rune Match";
226 if(cvar("deathmatch_force_teamplay"))
228 fraglimit_override = cvar("g_runematch_point_limit");
235 gamemode_name = "Last Man Standing";
236 fraglimit_override = cvar("g_lms_lives_override");
237 if(fraglimit_override == 0)
238 fraglimit_override = -1;
239 lms_lowest_lives = 9999;
247 gamemode_name = "Arena";
248 fraglimit_override = cvar("g_arena_point_limit");
249 maxspawned = cvar("g_arena_maxspawned");
252 arena_roundbased = cvar("g_arena_roundbased");
258 gamemode_name = "Key Hunt";
260 fraglimit_override = cvar("g_keyhunt_point_limit");
267 gamemode_name = "Assault";
273 game = GAME_ONSLAUGHT;
274 gamemode_name = "Onslaught";
282 gamemode_name = "Race";
283 g_race_qualifying = cvar("g_race_qualifying");
285 // In campaign, only this mode makes sense...
286 if(cvar("g_campaign"))
287 g_race_qualifying = 1;
289 if(cvar("g_race_teams"))
291 g_race_qualifying = 0; // not supported!
293 race_teams = bound(2, cvar("g_race_teams"), 4);
298 if(g_race_qualifying == 1)
299 fraglimit_override = 0;
301 fraglimit_override = cvar("g_race_laps_limit");
303 if(g_race_qualifying)
304 independent_players = 1;
309 // save it (for the next startup)
310 cvar_set("gamecfg", ftos(game));
312 cache_mutatormsg = strzone("");
313 cache_motd = strzone("");
314 cache_lastmutatormsg = strzone("");
315 cache_lastmotd = strzone("");
317 // enforce the server's universal frag/time limits
318 if(!cvar("g_campaign"))
320 if(fraglimit_override >= 0)
321 cvar_set("fraglimit", ftos(fraglimit_override));
322 if(timelimit_override >= 0)
323 cvar_set("timelimit", ftos(timelimit_override));
326 if(g_race && g_race_qualifying == 2)
328 race_fraglimit = cvar("fraglimit");
329 cvar_set("fraglimit", "0");
332 InitializeEntity(world, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK);
335 string GetClientVersionMessage() {
336 local string versionmsg;
337 if (self.version_mismatch) {
338 if(self.version < cvar("gameversion")) {
339 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
341 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
344 versionmsg = "^2client version and server version are compatible.^8";
350 void PrintWelcomeMessage(entity pl)
352 string s, mutator, modifications;
354 /*if(self.welcomemessage_time > time)
356 self.welcomemessage_time = time + 0.8; */
358 if(self.cvar_scr_centertime == 0) return;
359 if( !(timeoutStatus >= 1 || (time < restart_countdown) ) ) { //really print the WelcomeMessage to the player every frame when timeout-seconds are shown or the game is restarted, to make sure that the shown number is accurate
360 if(self.welcomemessage_time > time) return;
361 self.welcomemessage_time = time + self.cvar_scr_centertime * 0.6;
364 if(cvar("g_campaign"))
366 centerprint(pl, campaign_message);
370 if(!self.BUTTON_INFO)
372 // TODO get rid of this too
373 local string specString;
374 specString = NEWLINES;
375 if(time < restart_countdown) //also show the countdown when being a spectator
376 specString = strcat(specString, "\n\n^1Game starts in ", ftos(restartAnnouncer.cnt + 1), " seconds^7");
377 else if (timeoutStatus != 0)
378 specString = strcat(specString, "\n\n", getTimeoutText(1));
381 return centerprint_atprio(self, CENTERPRIO_SPAM, specString);
385 mutator = "^2Minstagib ^1";
386 else if(g_rocketarena)
387 mutator = "^2Rocketarena ^1";
389 mutator = "^2No Items Nexuiz ^1";
392 // to protect against unheedingly made changes
394 modifications = strcat(modifications, ", ");
396 modifications = "midair";
400 modifications = strcat(modifications, ", ");
402 modifications = strcat(modifications, "vampire");
404 if(g_laserguided_missile) {
406 modifications = strcat(modifications, ", ");
408 modifications = strcat(modifications, "laser-guided-missiles");
412 modifications = strcat(modifications, ", ");
414 modifications = strcat(modifications, "Tournament");
417 local string versionmessage;
418 versionmessage = GetClientVersionMessage();
420 s = strcat(s, NEWLINES, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
421 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
423 if(modifications != "")
424 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
427 if(!tourneyInMatchStage)
428 s = strcat(s, "\n^8The game is currently in ^3warmup-stage ^8!\n");
430 s = strcat(s, "\n^8The game is currently in ^3match-stage ^8!\n");
433 if(time < restart_countdown)
434 s = strcat(s, "\n^1Game starts in ", ftos(restartAnnouncer.cnt + 1), " seconds^7");
436 if(timeoutStatus != 0)
437 s = strcat(s, "\n\n", getTimeoutText(1));
439 if (g_grappling_hook)
440 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
442 if(cache_lastmutatormsg != cvar_string("g_mutatormsg"))
444 if(cache_lastmutatormsg)
445 strunzone(cache_lastmutatormsg);
447 strunzone(cache_mutatormsg);
448 cache_lastmutatormsg = strzone(cvar_string("g_mutatormsg"));
449 cache_mutatormsg = strzone(wordwrap(cache_lastmutatormsg, 50));
452 if (cache_mutatormsg != "") {
453 s = strcat(s, "\n\n^8special gameplay tips: ^7", cache_mutatormsg);
456 if(cache_lastmotd != cvar_string("sv_motd"))
459 strunzone(cache_lastmotd);
461 strunzone(cache_motd);
462 cache_lastmotd = strzone(cvar_string("sv_motd"));
463 cache_motd = strzone(wordwrap(cache_lastmotd, 50));
466 if (cache_motd != "") {
467 s = strcat(s, "\n\n^8MOTD: ^7", cache_motd);
476 void SetPlayerColors(entity pl, float _color)
480 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
482 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
483 pl.clientcolors = 16*cl + cl;*/
486 pants = _color & 0x0F;
487 shirt = _color & 0xF0;
491 setcolor(pl, 16*pants + pants);
493 setcolor(pl, shirt + pants);
497 void SetPlayerTeam(entity pl, float t, float s, float noprint)
502 _color = COLOR_TEAM4 - 1;
504 _color = COLOR_TEAM3 - 1;
506 _color = COLOR_TEAM2 - 1;
508 _color = COLOR_TEAM1 - 1;
510 SetPlayerColors(pl,_color);
512 if(!noprint && t != s)
514 //bprint(pl.netname, " has changed to ", TeamNoName(t), "\n");
515 bprint(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n");
527 // set c1...c4 to show what teams are allowed
528 void CheckAllowedTeams (entity for_whom)
537 c1 = c2 = c3 = c4 = -1;
538 cb1 = cb2 = cb3 = cb4 = 0;
540 // onslaught is special
543 head = findchain(classname, "onslaught_generator");
546 if (head.team == COLOR_TEAM1) c1 = 0;
547 if (head.team == COLOR_TEAM2) c2 = 0;
548 if (head.team == COLOR_TEAM3) c3 = 0;
549 if (head.team == COLOR_TEAM4) c4 = 0;
556 teament_name = "dom_team";
558 teament_name = "ctf_team";
560 teament_name = "tdm_team";
563 c1 = c2 = 0; // Assault always has 2 teams
568 // cover anything else by treating it like tdm with no teams spawned
574 dm = cvar("g_tdm_teams");
576 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
580 c1 = c2 = c3 = c4 = 0;
593 // first find out what teams are allowed
594 head = find(world, classname, teament_name);
597 if(!(g_domination && head.netname == ""))
599 if(head.team == COLOR_TEAM1)
603 if(head.team == COLOR_TEAM2)
607 if(head.team == COLOR_TEAM3)
611 if(head.team == COLOR_TEAM4)
616 head = find(head, classname, teament_name);
621 if(cvar("bot_vs_human") > 0)
624 if(clienttype(for_whom) == CLIENTTYPE_BOT)
629 else if(cvar("bot_vs_human") < 0)
632 if(clienttype(for_whom) == CLIENTTYPE_BOT)
640 float PlayerValue(entity p)
642 if(IsTeamBalanceForced() == 1)
647 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
648 // teams that are allowed will now have their player counts stored in c1...c4
649 void GetTeamCounts(entity ignore)
653 // now count how many players are on each team already
655 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
656 // also remember the lowest-scoring player
658 FOR_EACH_PLAYER(head)
660 if(head != ignore)// && head.netname != "")
662 value = PlayerValue(head);
663 if(clienttype(head) == CLIENTTYPE_BOT)
667 if(head.team == COLOR_TEAM1)
675 if(head.team == COLOR_TEAM2)
683 if(head.team == COLOR_TEAM3)
691 if(head.team == COLOR_TEAM4)
703 // returns # of smallest team (1, 2, 3, 4)
704 // NOTE: Assumes CheckAllowedTeams has already been called!
705 float FindSmallestTeam(entity pl, float ignore_pl)
707 float totalteams, smallestteam, smallestteam_count, smallestteam_score, balance_type;
710 // find out what teams are available
711 //CheckAllowedTeams();
713 // make sure there are at least 2 teams to join
715 totalteams = totalteams + 1;
717 totalteams = totalteams + 1;
719 totalteams = totalteams + 1;
721 totalteams = totalteams + 1;
723 if(cvar("bot_vs_human"))
729 error("Too few teams available for domination\n");
731 error("Too few teams available for ctf\n");
733 error("Too few teams available for key hunt\n");
735 error("Too few teams available for team deathmatch\n");
738 // count how many players are in each team
742 GetTeamCounts(world);
744 // c1...c4 now have counts of each team
745 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
748 smallestteam_count = 999999999;
749 smallestteam_score = 999999999;
751 // 2 gives priority to what team you're already on, 1 goes in order
752 // 2 doesn't seem to work though...
756 //if(pl.classname != "player")
757 if(clienttype(pl) != CLIENTTYPE_BOT)
759 c1 -= cb1 * 255.0/256;
760 c2 -= cb2 * 255.0/256;
761 c3 -= cb3 * 255.0/256;
762 c4 -= cb4 * 255.0/256;
765 if(balance_type == 1)
767 if(c1 >= 0 && (c1 < smallestteam_count || (c1 <= smallestteam_count && team1_score < smallestteam_score)))
770 smallestteam_count = c1;
771 smallestteam_score = team1_score;
773 if(c2 >= 0 && (c2 < smallestteam_count || (c2 <= smallestteam_count && team2_score < smallestteam_score)))
776 smallestteam_count = c2;
777 smallestteam_score = team2_score;
779 if(c3 >= 0 && (c3 < smallestteam_count || (c3 <= smallestteam_count && team3_score < smallestteam_score)))
782 smallestteam_count = c3;
783 smallestteam_score = team3_score;
785 if(c4 >= 0 && (c4 < smallestteam_count || (c4 <= smallestteam_count && team4_score < smallestteam_score)))
788 smallestteam_count = c4;
789 smallestteam_score = team4_score;
794 if(c1 >= 0 && (c1 < smallestteam_count ||
795 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
798 smallestteam_count = c1;
800 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
801 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
804 smallestteam_count = c2;
806 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
807 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
810 smallestteam_count = c3;
812 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
813 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
816 smallestteam_count = c4;
823 float JoinBestTeam(entity pl, float only_return_best, float forcebestteam)
825 float smallest, selectedteam;
827 // don't join a team if we're not playing a team game
828 if(!cvar("teamplay") && !g_domination && !g_ctf && !g_keyhunt)
831 // find out what teams are available
832 CheckAllowedTeams(pl);
837 if(cvar("g_domination_default_teams") < 3)
839 if(cvar("g_domination_default_teams") < 4)
843 // if we don't care what team he ends up on, put him on whatever team he entered as.
844 // if he's not on a valid team, then let other code put him on the smallest team
847 if( c1 >= 0 && pl.team == COLOR_TEAM1)
848 selectedteam = pl.team;
849 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
850 selectedteam = pl.team;
851 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
852 selectedteam = pl.team;
853 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
854 selectedteam = pl.team;
859 if(!only_return_best)
861 SetPlayerColors(pl, selectedteam - 1);
866 // otherwise end up on the smallest team (handled below)
869 smallest = FindSmallestTeam(pl, TRUE);
872 if(!only_return_best)
874 TeamchangeFrags(self);
877 SetPlayerColors(pl, COLOR_TEAM1 - 1);
879 else if(smallest == 2)
881 SetPlayerColors(pl, COLOR_TEAM2 - 1);
883 else if(smallest == 3)
885 SetPlayerColors(pl, COLOR_TEAM3 - 1);
887 else if(smallest == 4)
889 SetPlayerColors(pl, COLOR_TEAM4 - 1);
893 error("smallest team: invalid team\n");
896 if(pl.deadflag == DEAD_NO)
897 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
903 //void() ctf_playerchanged;
904 void SV_ChangeTeam(float _color)
906 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
908 // in normal deathmatch we can just apply the color and we're done
909 if(!cvar("teamplay")) {
910 SetPlayerColors(self, _color);
914 scolor = self.clientcolors & 0x0F;
915 dcolor = _color & 0x0F;
917 if(scolor == COLOR_TEAM1 - 1)
919 else if(scolor == COLOR_TEAM2 - 1)
921 else if(scolor == COLOR_TEAM3 - 1)
923 else if(scolor == COLOR_TEAM4 - 1)
925 if(dcolor == COLOR_TEAM1 - 1)
927 else if(dcolor == COLOR_TEAM2 - 1)
929 else if(dcolor == COLOR_TEAM3 - 1)
931 else if(dcolor == COLOR_TEAM4 - 1)
934 CheckAllowedTeams(self);
936 if(dteam == 1 && c1 < 0) dteam = 4;
937 if(dteam == 4 && c4 < 0) dteam = 3;
938 if(dteam == 3 && c3 < 0) dteam = 2;
939 if(dteam == 2 && c2 < 0) dteam = 1;
941 // not changing teams
944 //bprint("same team change\n");
945 SetPlayerTeam(self, dteam, steam, TRUE);
951 if(cvar("g_campaign") || cvar("g_changeteam_banned"))
953 sprint(self, "Team changes not allowed\n");
954 return; // changing teams is not allowed
957 if(!cvar("g_campaign") && cvar("g_balance_teams_prevent_imbalance"))
959 // only allow changing to a smaller or equal size team
961 // find out what teams are available
962 //CheckAllowedTeams();
963 // count how many players on each team
964 GetTeamCounts(world);
967 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
972 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
977 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
982 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
989 sprint(self, "Cannot change to an invalid team\n");
995 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
997 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
999 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
1001 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
1004 if(scount) // started at a valid, nonempty team
1006 // check if we're trying to change to a larger team that doens't have bots to swap with
1007 if(dcount >= scount && dbotcount <= 0)
1009 sprint(self, "Cannot change to a larger team\n");
1010 return; // can't change to a larger team
1016 // bprint("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n");
1018 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
1020 // reduce frags during a team change
1021 TeamchangeFrags(self);
1024 SetPlayerTeam(self, dteam, steam, FALSE);
1026 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
1028 // kill player when changing teams
1029 if(self.deadflag == DEAD_NO)
1030 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
1032 //ctf_playerchanged();
1035 void ShufflePlayerOutOfTeam (float source_team)
1037 float smallestteam, smallestteam_count, steam;
1038 float lowest_bot_score, lowest_player_score;
1039 entity head, lowest_bot, lowest_player, selected;
1042 smallestteam_count = 999999999;
1044 if(c1 >= 0 && c1 < smallestteam_count)
1047 smallestteam_count = c1;
1049 if(c2 >= 0 && c2 < smallestteam_count)
1052 smallestteam_count = c2;
1054 if(c3 >= 0 && c3 < smallestteam_count)
1057 smallestteam_count = c3;
1059 if(c4 >= 0 && c4 < smallestteam_count)
1062 smallestteam_count = c4;
1067 bprint("warning: no smallest team\n");
1071 if(source_team == 1)
1072 steam = COLOR_TEAM1;
1073 else if(source_team == 2)
1074 steam = COLOR_TEAM2;
1075 else if(source_team == 3)
1076 steam = COLOR_TEAM3;
1077 else if(source_team == 4)
1078 steam = COLOR_TEAM4;
1081 lowest_bot_score = 999999999;
1082 lowest_player = world;
1083 lowest_player_score = 999999999;
1085 // find the lowest-scoring player & bot of that team
1086 FOR_EACH_PLAYER(head)
1088 if(head.team == steam)
1092 if(head.totalfrags < lowest_bot_score)
1095 lowest_bot_score = head.totalfrags;
1100 if(head.totalfrags < lowest_player_score)
1102 lowest_player = head;
1103 lowest_player_score = head.totalfrags;
1109 // prefers to move a bot...
1110 if(lowest_bot != world)
1111 selected = lowest_bot;
1112 // but it will move a player if it has to
1114 selected = lowest_player;
1115 // don't do anything if it couldn't find anyone
1118 bprint("warning: couldn't find a player to move from team\n");
1122 // smallest team gains a member
1123 if(smallestteam == 1)
1127 else if(smallestteam == 2)
1131 else if(smallestteam == 3)
1135 else if(smallestteam == 4)
1141 bprint("warning: destination team invalid\n");
1144 // source team loses a member
1145 if(source_team == 1)
1149 else if(source_team == 2)
1153 else if(source_team == 3)
1157 else if(source_team == 4)
1163 bprint("warning: source team invalid\n");
1167 // move the player to the new team
1168 TeamchangeFrags(selected);
1169 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1171 if(selected.deadflag == DEAD_NO)
1172 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1173 centerprint(selected, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(selected.team)));
1176 float lastRebalanceInfo;
1177 void CauseRebalance(float source_team, float howmany_toomany)
1182 if(IsTeamBalanceForced() == 1)
1184 bprint("Rebalancing Teams\n");
1185 ShufflePlayerOutOfTeam(source_team);
1189 if(howmany_toomany < cvar("g_balance_teams_complain"))
1191 if(time < lastRebalanceInfo + 90)
1193 lastRebalanceInfo = time;
1194 if(source_team == 1)
1195 steam = COLOR_TEAM1;
1196 else if(source_team == 2)
1197 steam = COLOR_TEAM2;
1198 else if(source_team == 3)
1199 steam = COLOR_TEAM3;
1200 else if(source_team == 4)
1201 steam = COLOR_TEAM4;
1202 print("Team ", ftos(source_team), " too large, complaining.\n");
1203 FOR_EACH_REALPLAYER(head)
1205 if(head.team == steam)
1207 sprint(head, "\{1}\{13}^3SERVER NOTICE:^7 One of you please change teams!\n");
1208 centerprint_atprio(head, CENTERPRIO_REBALANCE, "^3SERVER NOTICE:\n\n^7Someone of you please change teams!");
1214 // part of g_balance_teams_force
1215 // occasionally perform an audit of the teams to make
1216 // sure they're more or less balanced in player count.
1219 float numplayers, numteams, smallest, toomany;
1221 balance = IsTeamBalanceForced();
1225 if(audit_teams_time > time)
1228 audit_teams_time = time + 4 + random();
1230 // bprint("Auditing teams\n");
1232 CheckAllowedTeams(world);
1233 GetTeamCounts(world);
1236 numteams = numplayers = smallest = 0;
1239 numteams = numteams + 1;
1240 numplayers = numplayers + c1;
1245 numteams = numteams + 1;
1246 numplayers = numplayers + c2;
1252 numteams = numteams + 1;
1253 numplayers = numplayers + c3;
1259 numteams = numteams + 1;
1260 numplayers = numplayers + c4;
1266 return; // no players to move around
1268 return; // don't bother shuffling if for some reason there aren't any teams
1270 toomany = smallest + 1;
1272 if(c1 && c1 > toomany)
1273 CauseRebalance(1, c1 - toomany);
1274 if(c2 && c2 > toomany)
1275 CauseRebalance(2, c2 - toomany);
1276 if(c3 && c3 > toomany)
1277 CauseRebalance(3, c3 - toomany);
1278 if(c4 && c4 > toomany)
1279 CauseRebalance(4, c4 - toomany);
1281 // if teams are still unbalanced, balance them further in the next audit,
1282 // which will happen sooner (keep doing rapid audits until things are in order)
1283 audit_teams_time = time + 0.7 + random()*0.3;
1288 // code from here on is just to support maps that don't have team entities
1289 void tdm_spawnteam (string teamname, float teamcolor)
1293 e.classname = "tdm_team";
1294 e.netname = teamname;
1299 // spawn some default teams if the map is not set up for tdm
1300 void tdm_spawnteams()
1304 numteams = cvar("g_tdm_teams");
1306 tdm_spawnteam("Red", COLOR_TEAM1-1);
1307 tdm_spawnteam("Blue", COLOR_TEAM2-1);
1309 tdm_spawnteam("Yellow", COLOR_TEAM3-1);
1311 tdm_spawnteam("Pink", COLOR_TEAM4-1);
1314 void tdm_delayedinit()
1316 // if no teams are found, spawn defaults
1317 if (find(world, classname, "tdm_team") == world)
1323 InitializeEntity(world, tdm_delayedinit, INITPRIO_GAMETYPE);