1 string cache_mutatormsg;
2 string cache_lastmutatormsg;
4 // client counts for each team
6 // # of bots on those teams
7 float cb1, cb2, cb3, cb4;
9 float audit_teams_time;
11 float IsTeamBalanceForced()
13 if(intermission_running)
14 return 0; // no rebalancing whatsoever please
17 if(cvar("g_campaign"))
19 if(!cvar("g_balance_teams_force"))
24 void TeamchangeFrags(entity e)
29 vector TeamColor(float teem)
34 return '1 0.0625 0.0625';
36 return '0.0625 0.0625 1';
46 string TeamName(float t)
48 return strcat(Team_ColorName(t), " Team");
50 string ColoredTeamName(float t)
52 return strcat(Team_ColorCode(t), Team_ColorName(t), " Team^7");
54 string TeamNoName(float t)
56 // fixme: Search for team entities and get their .netname's!
65 return "Neutral Team";
70 void runematch_init();
74 void LogTeamchange(entity pl)
77 if(!cvar("sv_eventlog"))
81 str = strcat(":team:", ftos(pl.playerid), ":");
82 str = strcat(str, ftos(pl.team));
88 cvar_set("g_dm", ftos(g_dm));
89 cvar_set("g_tdm", ftos(g_tdm));
90 cvar_set("g_domination", ftos(g_domination));
91 cvar_set("g_ctf", ftos(g_ctf));
92 cvar_set("g_runematch", ftos(g_runematch));
93 cvar_set("g_lms", ftos(g_lms));
94 cvar_set("g_arena", ftos(g_arena));
95 cvar_set("g_keyhunt", ftos(g_keyhunt));
96 cvar_set("g_assault", ftos(g_assault));
97 cvar_set("g_onslaught", ftos(g_onslaught));
98 cvar_set("g_race", ftos(g_race));
108 prev = cvar("gamecfg");
109 for(i = 0; i < 2; ++i)
111 found += (g_dm = (!found && (prev != GAME_DEATHMATCH) && cvar("g_dm")));
112 found += (g_tdm = (!found && (prev != GAME_TEAM_DEATHMATCH) && cvar("g_tdm")));
113 found += (g_domination = (!found && (prev != GAME_DOMINATION) && cvar("g_domination")));
114 found += (g_ctf = (!found && (prev != GAME_CTF) && cvar("g_ctf")));
115 found += (g_runematch = (!found && (prev != GAME_RUNEMATCH) && cvar("g_runematch")));
116 found += (g_lms = (!found && (prev != GAME_LMS) && cvar("g_lms")));
117 found += (g_arena = (!found && (prev != GAME_ARENA) && cvar("g_arena")));
118 found += (g_keyhunt = (!found && (prev != GAME_KEYHUNT) && cvar("g_keyhunt")));
119 found += (g_assault = (!found && (prev != GAME_ASSAULT) && cvar("g_assault")));
120 found += (g_onslaught = (!found && (prev != GAME_ONSLAUGHT) && cvar("g_onslaught")));
121 found += (g_race = (!found && (prev != GAME_RACE) && cvar("g_race")));
126 prev = -1; // second attempt takes place WITHOUT prev set
132 if(g_dm && cvar("deathmatch_force_teamplay"))
141 void default_delayedinit()
143 if(!scores_initialized)
144 ScoreRules_generic();
147 void ActivateTeamplay()
149 float teamplay_default;
150 teamplay_default = cvar("teamplay_default");
153 teamplay = teamplay_default;
156 cvar_set("teamplay", ftos(teamplay));
161 void InitGameplayMode()
163 float fraglimit_override, timelimit_override;
168 cvar_set("teamplay", "0");
170 // make sure only ONE type is selected
174 // find out good world mins/maxs bounds, either the static bounds found by looking for solid, or the mapinfo specified bounds
179 MapInfo_LoadMapSettings(mapname);
181 if not(cvar_value_issafe(world.fog))
183 print("The current map contains a potentially harmful fog setting, ignored\n");
184 world.fog = string_null;
186 if(MapInfo_Map_fog != "")
187 if(MapInfo_Map_fog == "none")
188 world.fog = string_null;
190 world.fog = strzone(MapInfo_Map_fog);
191 clientstuff = strzone(MapInfo_Map_clientstuff);
192 MapInfo_ClearTemps();
194 // in case mapinfo switched the type
197 // set both here, gamemode can override it later
198 timelimit_override = cvar("timelimit_override");
199 fraglimit_override = cvar("fraglimit_override");
203 game = GAME_DEATHMATCH;
204 gamemode_name = "Deathmatch";
209 game = GAME_TEAM_DEATHMATCH;
210 gamemode_name = "Team Deathmatch";
217 game = GAME_DOMINATION;
218 gamemode_name = "Domination";
220 fraglimit_override = cvar("g_domination_point_limit");
227 gamemode_name = "Capture the Flag";
229 if(cvar("g_campaign"))
232 g_ctf_win_mode = cvar("g_ctf_win_mode");
233 g_ctf_ignore_frags = cvar("g_ctf_ignore_frags");
234 if(g_ctf_win_mode == 2)
235 fraglimit_override = cvar("g_ctf_capture_limit");
237 fraglimit_override = cvar("capturelimit_override");
243 game = GAME_RUNEMATCH;
244 gamemode_name = "Rune Match";
245 if(cvar("deathmatch_force_teamplay"))
247 fraglimit_override = cvar("g_runematch_point_limit");
254 gamemode_name = "Last Man Standing";
255 fraglimit_override = cvar("g_lms_lives_override");
256 if(fraglimit_override == 0)
257 fraglimit_override = -1;
258 lms_lowest_lives = 9999;
266 gamemode_name = "Arena";
267 fraglimit_override = cvar("g_arena_point_limit");
268 maxspawned = cvar("g_arena_maxspawned");
271 arena_roundbased = cvar("g_arena_roundbased");
277 gamemode_name = "Key Hunt";
279 fraglimit_override = cvar("g_keyhunt_point_limit");
286 gamemode_name = "Assault";
288 ScoreRules_assault();
293 game = GAME_ONSLAUGHT;
294 gamemode_name = "Onslaught";
301 gamemode_name = "Race";
302 g_race_qualifying = cvar("g_race_qualifying");
304 if(cvar("g_race_teams"))
306 g_race_qualifying = 0; // not supported!
308 race_teams = bound(2, cvar("g_race_teams"), 4);
313 if(g_race_qualifying == 1)
314 fraglimit_override = 0;
316 fraglimit_override = cvar("g_race_laps_limit");
318 if(g_race_qualifying)
319 independent_players = 1;
327 // save it (for the next startup)
328 cvar_set("gamecfg", ftos(game));
330 cache_mutatormsg = strzone("");
331 cache_lastmutatormsg = strzone("");
333 // enforce the server's universal frag/time limits
334 if(!cvar("g_campaign"))
336 if(fraglimit_override >= 0)
337 cvar_set("fraglimit", ftos(fraglimit_override));
338 if(timelimit_override >= 0)
339 cvar_set("timelimit", ftos(timelimit_override));
342 if(g_race && g_race_qualifying == 2)
344 race_fraglimit = cvar("fraglimit");
345 cvar_set("fraglimit", "0");
348 InitializeEntity(world, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK);
351 string GetClientVersionMessage() {
352 local string versionmsg;
353 if (self.version_mismatch) {
354 if(self.version < cvar("gameversion")) {
355 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
357 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
360 versionmsg = "^2client version and server version are compatible.^8";
366 void PrintWelcomeMessage(entity pl)
368 string s, modifications, motd;
370 if(self.cvar_scr_centertime == 0) return;
371 if((time - self.jointime) > cvar("welcome_message_time")
372 && !self.BUTTON_INFO)
375 if( !(timeoutStatus >= 1 || (time < game_starttime) ) ) { //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
376 if(self.welcomemessage_time > time) return;
377 self.welcomemessage_time = time + self.cvar_scr_centertime * 0.6;
380 if(cvar("g_campaign"))
382 centerprint(pl, campaign_message);
386 //TODO GreEn`mArine: make the timeout-messages clientside as well (just like the ready restart countdown)!
387 if(!self.BUTTON_INFO)
389 // TODO get rid of this too
390 local string specString;
391 specString = NEWLINES;
392 //if(time < game_starttime) //also show the countdown when being a spectator
393 // specString = strcat(specString, "\n\n^1Game starts in ", ftos(ceil(game_starttime - time)), " seconds^7");
395 if (timeoutStatus != 0)
396 specString = strcat(specString, "\n\n", getTimeoutText(1));
399 if(!self.BUTTON_INFO && self.classname == "player")
403 return centerprint_atprio(self, CENTERPRIO_SPAM, specString);
409 modifications = strcat(modifications, ", MinstaGib");
411 modifications = strcat(modifications, ", NixNex");
413 modifications = strcat(modifications, ", ", g_weaponarena_list, " Arena");
414 if(cvar("sv_gravity") < 800)
415 modifications = strcat(modifications, ", Low gravity");
417 modifications = strcat(modifications, ", Cloaked");
419 modifications = strcat(modifications, ", Steps");
421 modifications = strcat(modifications, ", Hook");
422 if(g_laserguided_missile)
423 modifications = strcat(modifications, ", LG missiles");
425 modifications = strcat(modifications, ", Midair");
427 modifications = strcat(modifications, ", Vampire");
429 modifications = strcat(modifications, ", Pinata");
431 modifications = strcat(modifications, ", Weapons stay");
433 modifications = strcat(modifications, ", Bloodloss");
434 modifications = substring(modifications, 2, strlen(modifications) - 2);
436 local string versionmessage;
437 versionmessage = GetClientVersionMessage();
439 s = strcat(s, NEWLINES, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
440 s = strcat(s, "^8\n\nmatch type is ^1", gamemode_name, "^8\n");
442 if(modifications != "")
443 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
445 if(timeoutStatus != 0)
446 s = strcat(s, "\n\n", getTimeoutText(1));
448 if (g_grappling_hook)
449 s = strcat(s, "\n\n^3grappling hook^8 is enabled, press 'e' to use it\n");
451 if(cache_lastmutatormsg != cvar_string("g_mutatormsg"))
453 if(cache_lastmutatormsg)
454 strunzone(cache_lastmutatormsg);
456 strunzone(cache_mutatormsg);
457 cache_lastmutatormsg = strzone(cvar_string("g_mutatormsg"));
458 cache_mutatormsg = strzone(cache_lastmutatormsg);
461 if (cache_mutatormsg != "") {
462 s = strcat(s, "\n\n^8special gameplay tips: ^7", cache_mutatormsg);
465 motd = cvar_string("sv_motd");
467 s = strcat(s, "\n\n^8MOTD: ^7", strreplace("\\n", "\n", motd));
475 void SetPlayerColors(entity pl, float _color)
479 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
481 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
482 pl.clientcolors = 16*cl + cl;*/
485 pants = _color & 0x0F;
486 shirt = _color & 0xF0;
490 setcolor(pl, 16*pants + pants);
492 setcolor(pl, shirt + pants);
496 void SetPlayerTeam(entity pl, float t, float s, float noprint)
501 _color = COLOR_TEAM4 - 1;
503 _color = COLOR_TEAM3 - 1;
505 _color = COLOR_TEAM2 - 1;
507 _color = COLOR_TEAM1 - 1;
509 SetPlayerColors(pl,_color);
511 if(!noprint && t != s)
513 //bprint(pl.netname, " has changed to ", TeamNoName(t), "\n");
514 bprint(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n");
526 // set c1...c4 to show what teams are allowed
527 void CheckAllowedTeams (entity for_whom)
536 c1 = c2 = c3 = c4 = -1;
537 cb1 = cb2 = cb3 = cb4 = 0;
539 // onslaught is special
542 head = findchain(classname, "onslaught_generator");
545 if (head.team == COLOR_TEAM1) c1 = 0;
546 if (head.team == COLOR_TEAM2) c2 = 0;
547 if (head.team == COLOR_TEAM3) c3 = 0;
548 if (head.team == COLOR_TEAM4) c4 = 0;
555 teament_name = "dom_team";
557 teament_name = "ctf_team";
559 teament_name = "tdm_team";
562 c1 = c2 = 0; // Assault always has 2 teams
567 // cover anything else by treating it like tdm with no teams spawned
573 dm = cvar("g_tdm_teams");
575 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
579 c1 = c2 = c3 = c4 = 0;
592 // first find out what teams are allowed
593 head = find(world, classname, teament_name);
596 if(!(g_domination && head.netname == ""))
598 if(head.team == COLOR_TEAM1)
602 if(head.team == COLOR_TEAM2)
606 if(head.team == COLOR_TEAM3)
610 if(head.team == COLOR_TEAM4)
615 head = find(head, classname, teament_name);
620 if(cvar("bot_vs_human") > 0)
623 if(clienttype(for_whom) == CLIENTTYPE_BOT)
628 else if(cvar("bot_vs_human") < 0)
631 if(clienttype(for_whom) == CLIENTTYPE_BOT)
639 float PlayerValue(entity p)
641 if(IsTeamBalanceForced() == 1)
646 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
647 // teams that are allowed will now have their player counts stored in c1...c4
648 void GetTeamCounts(entity ignore)
652 // now count how many players are on each team already
654 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
655 // also remember the lowest-scoring player
657 FOR_EACH_PLAYER(head)
659 if(head != ignore)// && head.netname != "")
661 value = PlayerValue(head);
662 if(clienttype(head) == CLIENTTYPE_BOT)
666 if(head.team == COLOR_TEAM1)
674 if(head.team == COLOR_TEAM2)
682 if(head.team == COLOR_TEAM3)
690 if(head.team == COLOR_TEAM4)
702 // returns # of smallest team (1, 2, 3, 4)
703 // NOTE: Assumes CheckAllowedTeams has already been called!
704 float FindSmallestTeam(entity pl, float ignore_pl)
706 float totalteams, smallestteam, smallestteam_count, smallestteam_score, balance_type;
709 // find out what teams are available
710 //CheckAllowedTeams();
712 // make sure there are at least 2 teams to join
714 totalteams = totalteams + 1;
716 totalteams = totalteams + 1;
718 totalteams = totalteams + 1;
720 totalteams = totalteams + 1;
722 if(cvar("bot_vs_human"))
728 error("Too few teams available for domination\n");
730 error("Too few teams available for ctf\n");
732 error("Too few teams available for key hunt\n");
734 error("Too few teams available for team deathmatch\n");
737 // count how many players are in each team
741 GetTeamCounts(world);
743 // c1...c4 now have counts of each team
744 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
747 smallestteam_count = 999999999;
748 smallestteam_score = 999999999;
750 // 2 gives priority to what team you're already on, 1 goes in order
751 // 2 doesn't seem to work though...
755 //if(pl.classname != "player")
756 if(clienttype(pl) != CLIENTTYPE_BOT)
758 c1 -= cb1 * 255.0/256;
759 c2 -= cb2 * 255.0/256;
760 c3 -= cb3 * 255.0/256;
761 c4 -= cb4 * 255.0/256;
764 if(balance_type == 1)
766 if(c1 >= 0 && (c1 < smallestteam_count || (c1 <= smallestteam_count && team1_score < smallestteam_score)))
769 smallestteam_count = c1;
770 smallestteam_score = team1_score;
772 if(c2 >= 0 && (c2 < smallestteam_count || (c2 <= smallestteam_count && team2_score < smallestteam_score)))
775 smallestteam_count = c2;
776 smallestteam_score = team2_score;
778 if(c3 >= 0 && (c3 < smallestteam_count || (c3 <= smallestteam_count && team3_score < smallestteam_score)))
781 smallestteam_count = c3;
782 smallestteam_score = team3_score;
784 if(c4 >= 0 && (c4 < smallestteam_count || (c4 <= smallestteam_count && team4_score < smallestteam_score)))
787 smallestteam_count = c4;
788 smallestteam_score = team4_score;
793 if(c1 >= 0 && (c1 < smallestteam_count ||
794 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
797 smallestteam_count = c1;
799 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
800 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
803 smallestteam_count = c2;
805 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
806 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
809 smallestteam_count = c3;
811 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
812 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
815 smallestteam_count = c4;
822 float JoinBestTeam(entity pl, float only_return_best, float forcebestteam)
824 float smallest, selectedteam;
826 // don't join a team if we're not playing a team game
830 // find out what teams are available
831 CheckAllowedTeams(pl);
836 if(cvar("g_domination_default_teams") < 3)
838 if(cvar("g_domination_default_teams") < 4)
842 // if we don't care what team he ends up on, put him on whatever team he entered as.
843 // if he's not on a valid team, then let other code put him on the smallest team
846 if( c1 >= 0 && pl.team == COLOR_TEAM1)
847 selectedteam = pl.team;
848 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
849 selectedteam = pl.team;
850 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
851 selectedteam = pl.team;
852 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
853 selectedteam = pl.team;
858 if(!only_return_best)
860 SetPlayerColors(pl, selectedteam - 1);
865 // otherwise end up on the smallest team (handled below)
868 smallest = FindSmallestTeam(pl, TRUE);
871 if(!only_return_best)
873 TeamchangeFrags(self);
876 SetPlayerColors(pl, COLOR_TEAM1 - 1);
878 else if(smallest == 2)
880 SetPlayerColors(pl, COLOR_TEAM2 - 1);
882 else if(smallest == 3)
884 SetPlayerColors(pl, COLOR_TEAM3 - 1);
886 else if(smallest == 4)
888 SetPlayerColors(pl, COLOR_TEAM4 - 1);
892 error("smallest team: invalid team\n");
895 if(pl.deadflag == DEAD_NO)
896 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
902 //void() ctf_playerchanged;
903 void SV_ChangeTeam(float _color)
905 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
907 // in normal deathmatch we can just apply the color and we're done
909 SetPlayerColors(self, _color);
913 scolor = self.clientcolors & 0x0F;
914 dcolor = _color & 0x0F;
916 if(scolor == COLOR_TEAM1 - 1)
918 else if(scolor == COLOR_TEAM2 - 1)
920 else if(scolor == COLOR_TEAM3 - 1)
922 else // if(scolor == COLOR_TEAM4 - 1)
924 if(dcolor == COLOR_TEAM1 - 1)
926 else if(dcolor == COLOR_TEAM2 - 1)
928 else if(dcolor == COLOR_TEAM3 - 1)
930 else // if(dcolor == COLOR_TEAM4 - 1)
933 CheckAllowedTeams(self);
935 if(dteam == 1 && c1 < 0) dteam = 4;
936 if(dteam == 4 && c4 < 0) dteam = 3;
937 if(dteam == 3 && c3 < 0) dteam = 2;
938 if(dteam == 2 && c2 < 0) dteam = 1;
940 // not changing teams
943 //bprint("same team change\n");
944 SetPlayerTeam(self, dteam, steam, TRUE);
948 if(cvar("g_campaign"))
950 sprint(self, "Team changes not allowed\n");
951 return; // changing teams is not allowed
954 if(cvar("g_changeteam_banned") && self.wasplayer)
956 sprint(self, "Team changes not allowed\n");
960 if(cvar("g_balance_teams_prevent_imbalance"))
962 // only allow changing to a smaller or equal size team
964 // find out what teams are available
965 //CheckAllowedTeams();
966 // count how many players on each team
967 GetTeamCounts(world);
970 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
975 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
980 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
985 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
992 sprint(self, "Cannot change to an invalid team\n");
998 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
1000 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
1002 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
1004 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
1007 if(scount) // started at a valid, nonempty team
1009 // check if we're trying to change to a larger team that doens't have bots to swap with
1010 if(dcount >= scount && dbotcount <= 0)
1012 sprint(self, "Cannot change to a larger team\n");
1013 return; // can't change to a larger team
1018 // bprint("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n");
1020 if(self.classname == "player" && steam != dteam)
1022 // reduce frags during a team change
1023 TeamchangeFrags(self);
1026 SetPlayerTeam(self, dteam, steam, FALSE);
1028 if(self.classname == "player" && steam != dteam)
1030 // kill player when changing teams
1031 if(self.deadflag == DEAD_NO)
1032 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
1034 //ctf_playerchanged();
1037 void ShufflePlayerOutOfTeam (float source_team)
1039 float smallestteam, smallestteam_count, steam;
1040 float lowest_bot_score, lowest_player_score;
1041 entity head, lowest_bot, lowest_player, selected;
1044 smallestteam_count = 999999999;
1046 if(c1 >= 0 && c1 < smallestteam_count)
1049 smallestteam_count = c1;
1051 if(c2 >= 0 && c2 < smallestteam_count)
1054 smallestteam_count = c2;
1056 if(c3 >= 0 && c3 < smallestteam_count)
1059 smallestteam_count = c3;
1061 if(c4 >= 0 && c4 < smallestteam_count)
1064 smallestteam_count = c4;
1069 bprint("warning: no smallest team\n");
1073 if(source_team == 1)
1074 steam = COLOR_TEAM1;
1075 else if(source_team == 2)
1076 steam = COLOR_TEAM2;
1077 else if(source_team == 3)
1078 steam = COLOR_TEAM3;
1079 else if(source_team == 4)
1080 steam = COLOR_TEAM4;
1083 lowest_bot_score = 999999999;
1084 lowest_player = world;
1085 lowest_player_score = 999999999;
1087 // find the lowest-scoring player & bot of that team
1088 FOR_EACH_PLAYER(head)
1090 if(head.team == steam)
1094 if(head.totalfrags < lowest_bot_score)
1097 lowest_bot_score = head.totalfrags;
1102 if(head.totalfrags < lowest_player_score)
1104 lowest_player = head;
1105 lowest_player_score = head.totalfrags;
1111 // prefers to move a bot...
1112 if(lowest_bot != world)
1113 selected = lowest_bot;
1114 // but it will move a player if it has to
1116 selected = lowest_player;
1117 // don't do anything if it couldn't find anyone
1120 bprint("warning: couldn't find a player to move from team\n");
1124 // smallest team gains a member
1125 if(smallestteam == 1)
1129 else if(smallestteam == 2)
1133 else if(smallestteam == 3)
1137 else if(smallestteam == 4)
1143 bprint("warning: destination team invalid\n");
1146 // source team loses a member
1147 if(source_team == 1)
1151 else if(source_team == 2)
1155 else if(source_team == 3)
1159 else if(source_team == 4)
1165 bprint("warning: source team invalid\n");
1169 // move the player to the new team
1170 TeamchangeFrags(selected);
1171 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1173 if(selected.deadflag == DEAD_NO)
1174 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1175 centerprint(selected, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(selected.team)));
1178 void CauseRebalance(float source_team, float howmany_toomany)
1180 if(IsTeamBalanceForced() == 1)
1182 bprint("Rebalancing Teams\n");
1183 ShufflePlayerOutOfTeam(source_team);
1187 // part of g_balance_teams_force
1188 // occasionally perform an audit of the teams to make
1189 // sure they're more or less balanced in player count.
1192 float numplayers, numteams, smallest, toomany;
1194 balance = IsTeamBalanceForced();
1198 if(audit_teams_time > time)
1201 audit_teams_time = time + 4 + random();
1203 // bprint("Auditing teams\n");
1205 CheckAllowedTeams(world);
1206 GetTeamCounts(world);
1209 numteams = numplayers = smallest = 0;
1212 numteams = numteams + 1;
1213 numplayers = numplayers + c1;
1218 numteams = numteams + 1;
1219 numplayers = numplayers + c2;
1225 numteams = numteams + 1;
1226 numplayers = numplayers + c3;
1232 numteams = numteams + 1;
1233 numplayers = numplayers + c4;
1239 return; // no players to move around
1241 return; // don't bother shuffling if for some reason there aren't any teams
1243 toomany = smallest + 1;
1245 if(c1 && c1 > toomany)
1246 CauseRebalance(1, c1 - toomany);
1247 if(c2 && c2 > toomany)
1248 CauseRebalance(2, c2 - toomany);
1249 if(c3 && c3 > toomany)
1250 CauseRebalance(3, c3 - toomany);
1251 if(c4 && c4 > toomany)
1252 CauseRebalance(4, c4 - toomany);
1254 // if teams are still unbalanced, balance them further in the next audit,
1255 // which will happen sooner (keep doing rapid audits until things are in order)
1256 audit_teams_time = time + 0.7 + random()*0.3;
1259 // code from here on is just to support maps that don't have team entities
1260 void tdm_spawnteam (string teamname, float teamcolor)
1264 e.classname = "tdm_team";
1265 e.netname = teamname;
1270 // spawn some default teams if the map is not set up for tdm
1271 void tdm_spawnteams()
1275 numteams = cvar("g_tdm_teams");
1277 tdm_spawnteam("Red", COLOR_TEAM1-1);
1278 tdm_spawnteam("Blue", COLOR_TEAM2-1);
1280 tdm_spawnteam("Yellow", COLOR_TEAM3-1);
1282 tdm_spawnteam("Pink", COLOR_TEAM4-1);
1285 void tdm_delayedinit()
1287 // if no teams are found, spawn defaults
1288 if (find(world, classname, "tdm_team") == world)
1294 InitializeEntity(world, tdm_delayedinit, INITPRIO_GAMETYPE);