1 float COLOR_TEAM1 = 5; // red
2 float COLOR_TEAM2 = 14; // blue
3 float COLOR_TEAM3 = 10; // pink
4 float COLOR_TEAM4 = 13; // yellow
7 float GAME_DEATHMATCH = 1;
8 float GAME_TEAM_DEATHMATCH = 2;
9 float GAME_DOMINATION = 3;
11 float GAME_RUNEMATCH = 5;
16 // client counts for each team
18 // # of bots on those teams
19 float cb1, cb2, cb3, cb4;
21 float g_domination, g_ctf, g_tdm;
23 float audit_teams_time;
25 void TeamchangeFrags(entity e)
27 if(e.classname == "player")
29 // reduce frags during a team change
30 DistributeFragsAmongTeam(e, (e.clientcolors & 0x0F) + 1, 1 - cvar("g_changeteam_fragtransfer") / 100);
34 string TeamName(float t)
36 // fixme: Search for team entities and get their .netname's!
45 return "Neutral Team";
47 string ColoredTeamName(float t)
49 // fixme: Search for team entities and get their .netname's!
51 return "^1Red Team^7";
53 return "^4Blue Team^7";
55 return "^6Pink Team^7";
57 return "^3Yellow Team^7";
58 return "Neutral Team";
60 string TeamNoName(float t)
62 // fixme: Search for team entities and get their .netname's!
71 return "Neutral Team";
76 void runematch_init();
79 void(entity pl) LogTeamchange =
82 if(!cvar("sv_eventlog"))
86 str = strcat(":team:", ftos(pl.playerid), ":");
87 str = strcat(str, ftos(pl.team));
88 GameLogEcho(str, FALSE);
93 cvar_set("g_tdm", "0");
94 cvar_set("g_domination", "0");
95 cvar_set("g_ctf", "0");
96 cvar_set("g_runematch", "0");
97 cvar_set("g_lms", "0");
98 cvar_set("g_arena", "0");
99 cvar_set("teamplay", "0");
102 cvar_set("exit_cfg", "");
105 void ActivateTeamplay()
107 float teamplay_default;
108 teamplay_default = cvar("teamplay_default");
111 cvar_set("teamplay", ftos(teamplay_default));
113 cvar_set("teamplay", "3");
116 void InitGameplayMode()
118 float fraglimit_override, timelimit_override;
122 game = cvar ("gamecfg"); // load game options
124 // game cvars get reset before map changes
125 // then map's cfg sets them as desired
127 // FIXME: also set a message or game mode name to print to players when the join
129 // set both here, gamemode can override it later
130 timelimit_override = cvar("timelimit_override");
131 fraglimit_override = cvar("fraglimit_override");
133 if(game == GAME_DOMINATION || cvar("g_domination"))
136 game = GAME_DOMINATION;
137 cvar_set("g_domination", "1");
141 fraglimit_override = cvar("g_domination_point_limit");
143 gamemode_name = "Domination";
146 else if(game == GAME_CTF || cvar("g_ctf"))
150 cvar_set("g_ctf", "1");
154 fraglimit_override = cvar("g_ctf_capture_limit");
156 gamemode_name = "Capture the Flag";
159 else if((game == GAME_RUNEMATCH || cvar("g_runematch")) && !cvar("g_minstagib"))
161 game = GAME_RUNEMATCH;
162 cvar_set("g_runematch", "1");
164 if(cvar("deathmatch_force_teamplay"))
167 fraglimit_override = cvar("g_runematch_point_limit");
169 gamemode_name = "Rune Match";
175 else if(game == GAME_DEATHMATCH || game == GAME_TEAM_DEATHMATCH || cvar("g_tdm"))
177 if(!cvar("deathmatch"))
178 cvar_set("deathmatch", "1");
181 if(game == GAME_TEAM_DEATHMATCH || cvar("g_tdm") || cvar("deathmatch_force_teamplay"))
184 game = GAME_TEAM_DEATHMATCH;
185 gamemode_name = "Team Deathmatch";
188 cvar_set("g_tdm", "1");
193 game = GAME_DEATHMATCH;
194 gamemode_name = "Deathmatch";
198 fraglimit_override = cvar("fraglimit_override");
200 else if(game == GAME_LMS || cvar("g_lms"))
204 cvar_set("g_lms", "1");
205 fraglimit_override = cvar("g_lms_lives_override");
206 if(fraglimit_override == 0)
207 fraglimit_override = -1;
208 gamemode_name = "Last Man Standing";
210 lms_lowest_lives = 999;
212 else if(game == GAME_ARENA || cvar("g_arena"))
216 cvar_set("g_arena", "1");
217 fraglimit_override = cvar("g_arena_point_limit");
218 maxspawned = cvar("g_arena_maxspawned");
221 arena_roundbased = cvar("g_arena_roundbased");
222 gamemode_name = "Arena";
227 // we can only assume...
229 gamemode_name = "Deathmatch";
232 /* else if(game == GAME_TEAM_DEATHMATCH)
234 if(!cvar("deathmatch"))
235 cvar_set("deathmatch", "1");
237 //if(!cvar("teamplay"))
238 // cvar_set("teamplay", "3");
241 fraglimit_override = cvar("fraglimit_override");
244 // enforce the server's universal frag/time limits
245 if(!cvar("g_campaign"))
247 if(fraglimit_override >= 0)
248 cvar_set("fraglimit", ftos(fraglimit_override));
249 if(timelimit_override >= 0)
250 cvar_set("timelimit", ftos(timelimit_override));
253 if (game == GAME_DOMINATION)//cvar("g_domination"))
255 else if (game == GAME_CTF)//cvar("g_ctf"))
257 else if (game == GAME_RUNEMATCH)//cvar("g_runematch"))
259 else if (game == GAME_TEAM_DEATHMATCH)//cvar("g_runematch"))
262 // those mutators rule each other out
263 if(cvar("g_minstagib"))
265 cvar_set("g_instagib", "0");
266 cvar_set("g_rocketarena", "0");
268 if(cvar("g_instagib"))
270 cvar_set("g_minstagib", "0");
271 cvar_set("g_rocketarena", "0");
273 if(cvar("g_rocketarena"))
275 cvar_set("g_instagib", "0");
276 cvar_set("g_minstagib", "0");
279 registercvar("_motd", "");
280 registercvar("_mutatormsg", "");
281 cvar_set("_motd", wordwrap(cvar_string("sv_motd"), 50));
282 cvar_set("_mutatormsg", wordwrap(cvar_string("g_mutatormsg"), 50));
284 g_domination = cvar("g_domination");
285 g_ctf = cvar("g_ctf");
286 g_tdm = cvar("g_tdm");
289 string GetClientVersionMessage(float v) {
290 local string versionmsg;
292 versionmsg = "^1client is too old to get versioninfo.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nUPDATE!!! (http://www.nexuiz.com)^8";
293 // either that or someone wants to be funny
294 } else if (v != cvar("gameversion")) {
295 if(v < cvar("gameversion")) {
296 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
298 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
301 versionmsg = "^2client version and server version are compatible.^8";
303 return strzone(versionmsg);
308 void PrintWelcomeMessage(entity pl)
310 string s, mutator, modifications;
312 /*if(self.welcomemessage_time < time)
314 if(self.welcomemessage_time2 > time)
316 self.welcomemessage_time2 = time + 0.8; */
318 if(self.classname == "observer")
320 if(cvar("g_lms") && self.frags <= 0 && self.frags > -666)
321 return centermsg_setall(strcat(newlines, "^1You have no more lives left\nwait for next round\n\n\n^7press attack to spectate other players"));
322 else if(cvar("g_lms") && self.frags == -666)
323 return centermsg_setall(strcat(newlines, "^1Match has already begun\nwait for next round\n\n\n^7press attack to spectate other players"));
325 else if(self.classname == "spectator")
327 if ((cvar("g_lms") && self.frags < 1) || cvar("g_arena"))
328 return centermsg_setall(strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press attack for next player\npress attack2 for free fly mode"));
330 return centermsg_setall(strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press jump to play\n^7press attack for next player\npress attack2 for free fly mode"));
334 if(self.welcomemessage_time2 > time) return;
335 self.welcomemessage_time2 = time + 1.0;
337 if(cvar("g_campaign"))
339 centermsg_setallfor(pl, campaign_message);
343 if(cvar("g_minstagib"))
344 mutator = "^2Minstagib ^1";
345 else if(cvar("g_instagib"))
346 mutator = "^2Instagib ^1";
347 else if(cvar("g_rocketarena"))
348 mutator = "^2Rocketarena ^1";
349 else if(cvar("g_nixnex"))
350 mutator = "^2No Items Nexuiz ^1";
352 if(cvar("g_midair")) {
353 // to protect against unheedingly made changes
355 modifications = strcat(modifications, ", ");
357 modifications = "midair";
359 if(cvar("g_vampire")) {
361 modifications = strcat(modifications, ", ");
363 modifications = strcat(modifications, "vampire");
365 if(cvar("g_laserguided_missile")) {
367 modifications = strcat(modifications, ", ");
369 modifications = strcat(modifications, "laser-guided-missiles");
372 local string versionmessage;
373 versionmessage = GetClientVersionMessage(self.version);
375 s = strcat(s, newlines, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
376 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
378 if(modifications != "")
379 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
381 if((self.classname == "observer" || self.classname == "spectator") && self.version == cvar("gameversion")) {
383 s = strcat(s,"^7\n\n\npress jump to play\npress attack to spectate other players\n\n");
384 else if(player_count < 2 && arena_roundbased)
386 s = strcat(s, "\n\n\n^1waiting for second player to start match^7\n\n");
390 s = strcat(s, "\n\n\n");
392 s = strcat(s, "^7current champion is: ", champion.netname, "\n\n");
393 s = strcat(s,"^7press attack to spectate other players\n\n");
400 if (cvar("g_grappling_hook"))
401 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
403 if (cvar_string("_mutatormsg") != "") {
404 s = strcat(s, "\n\n^8special gameplay tips: ^7", cvar_string("_mutatormsg"));
407 if (cvar_string("_motd") != "") {
408 s = strcat(s, "\n\n^8MOTD: ^7", cvar_string("_motd"));
413 centermsg_setallfor(pl, s);
420 void SetPlayerColors(entity pl, float _color)
424 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
426 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
427 pl.clientcolors = 16*cl + cl;*/
430 pants = _color & 0x0F;
431 shirt = _color & 0xF0;
435 setcolor(pl, 16*pants + pants);
437 setcolor(pl, shirt + pants);
441 void SetPlayerTeam(entity pl, float t, float s, float noprint)
446 _color = COLOR_TEAM4 - 1;
448 _color = COLOR_TEAM3 - 1;
450 _color = COLOR_TEAM2 - 1;
452 _color = COLOR_TEAM1 - 1;
454 SetPlayerColors(pl,_color);
456 if(!noprint && t != s)
458 //bprint(strcat(pl.netname, " has changed to ", TeamNoName(t), "\n"));
459 bprint(strcat(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"));
471 // set c1...c4 to show what teams are allowed
472 void CheckAllowedTeams ()
481 c1 = c2 = c3 = c4 = -1;
482 cb1 = cb2 = cb3 = cb4 = 0;
485 teament_name = "dom_team";
487 teament_name = "ctf_team";
489 teament_name = "tdm_team";
492 // cover anything else by treating it like tdm with no teams spawned
493 dm = cvar("g_tdm_teams");
495 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
499 c1 = c2 = c3 = c4 = 0;
512 // first find out what teams are allowed
513 head = find(world, classname, teament_name);
516 if(!(g_domination && head.netname == ""))
518 if(head.team == COLOR_TEAM1)
522 if(head.team == COLOR_TEAM2)
526 if(head.team == COLOR_TEAM3)
530 if(head.team == COLOR_TEAM4)
535 head = find(head, classname, teament_name);
539 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
540 // teams that are allowed will now have their player counts stored in c1...c4
541 void GetTeamCounts(entity ignore)
544 // now count how many players are on each team already
546 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
547 // also remember the lowest-scoring player
549 head = find(world, classname, "player");
552 if(head != ignore)// && head.netname != "")
554 if(head.team == COLOR_TEAM1)
562 if(head.team == COLOR_TEAM2)
570 if(head.team == COLOR_TEAM3)
578 if(head.team == COLOR_TEAM4)
587 head = find(head, classname, "player");
591 // returns # of smallest team (1, 2, 3, 4)
592 // NOTE: Assumes CheckAllowedTeams has already been called!
593 float FindSmallestTeam(entity pl, float ignore_pl)
595 float totalteams, smallestteam, smallestteam_count, balance_type;
598 // find out what teams are available
599 //CheckAllowedTeams();
601 // make sure there are at least 2 teams to join
603 totalteams = totalteams + 1;
605 totalteams = totalteams + 1;
607 totalteams = totalteams + 1;
609 totalteams = totalteams + 1;
614 error("Too few teams available for domination\n");
616 error("Too few teams available for ctf\n");
618 error("Too few teams available for team deathmatch\n");
622 // count how many players are in each team
626 GetTeamCounts(world);
628 // c1...c4 now have counts of each team
629 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
632 smallestteam_count = 999;
634 // 2 gives priority to what team you're already on, 1 goes in order
635 // 2 doesn't seem to work though...
638 if(balance_type == 1)
640 if(c1 >= 0 && c1 < smallestteam_count)
643 smallestteam_count = c1;
645 if(c2 >= 0 && c2 < smallestteam_count)
648 smallestteam_count = c2;
650 if(c3 >= 0 && c3 < smallestteam_count)
653 smallestteam_count = c3;
655 if(c4 >= 0 && c4 < smallestteam_count)
658 smallestteam_count = c4;
663 if(c1 >= 0 && (c1 < smallestteam_count ||
664 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
667 smallestteam_count = c1;
669 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
670 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
673 smallestteam_count = c2;
675 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
676 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
679 smallestteam_count = c3;
681 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
682 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
685 smallestteam_count = c4;
692 float JoinBestTeam(entity pl, float only_return_best)
694 float smallest, selectedteam;
696 // don't join a team if we're not playing a team game
697 if(!cvar("teamplay") && !g_domination && !g_ctf)
700 // find out what teams are available
703 if(cvar("g_domination"))
705 if(cvar("g_domination_default_teams") < 3)
707 if(cvar("g_domination_default_teams") < 4)
711 // if we don't care what team he ends up on, put him on whatever team he entered as.
712 // if he's not on a valid team, then let other code put him on the smallest team
713 if(!cvar("g_campaign") && !cvar("g_balance_teams") && !cvar("g_balance_teams_force"))
715 if( c1 >= 0 && pl.team == COLOR_TEAM1)
716 selectedteam = pl.team;
717 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
718 selectedteam = pl.team;
719 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
720 selectedteam = pl.team;
721 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
722 selectedteam = pl.team;
727 if(!only_return_best)
729 SetPlayerColors(pl, selectedteam - 1);
734 // otherwise end up on the smallest team (handled below)
737 smallest = FindSmallestTeam(pl, TRUE);
740 if(!only_return_best)
742 TeamchangeFrags(self);
745 SetPlayerColors(pl, COLOR_TEAM1 - 1);
747 else if(smallest == 2)
749 SetPlayerColors(pl, COLOR_TEAM2 - 1);
751 else if(smallest == 3)
753 SetPlayerColors(pl, COLOR_TEAM3 - 1);
755 else if(smallest == 4)
757 SetPlayerColors(pl, COLOR_TEAM4 - 1);
761 error("smallest team: invalid team\n");
764 if(pl.deadflag == DEAD_NO)
765 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
772 void SV_ChangeTeam(float _color)
774 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
776 // in normal deathmatch we can just apply the color and we're done
777 if(!cvar("teamplay")) {
778 SetPlayerColors(self, _color);
782 scolor = self.clientcolors & 0x0F;
783 dcolor = _color & 0x0F;
785 if(scolor == COLOR_TEAM1 - 1)
787 else if(scolor == COLOR_TEAM2 - 1)
789 else if(scolor == COLOR_TEAM3 - 1)
791 else if(scolor == COLOR_TEAM4 - 1)
793 if(dcolor == COLOR_TEAM1 - 1)
795 else if(dcolor == COLOR_TEAM2 - 1)
797 else if(dcolor == COLOR_TEAM3 - 1)
799 else if(dcolor == COLOR_TEAM4 - 1)
802 // remap invalid teams in dom & ctf
804 if(cvar("g_ctf") && dteam == 3)
806 else if(cvar("g_ctf") && dteam == 4)
808 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 3) || (cvar("g_tdm") && cvar("g_tdm_teams") < 3))
815 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 4) || (cvar("g_tdm") && cvar("g_tdm_teams") < 4))
823 if(dteam == 3 && c3 < 0)
825 if(dteam == 4 && c4 < 0)
828 // not changing teams
831 //bprint("same team change\n");
832 SetPlayerTeam(self, dteam, steam, TRUE);
838 if(cvar("g_campaign") || cvar("g_changeteam_banned"))
840 sprint(self, "Team changes not allowed\n");
841 return; // changing teams is not allowed
844 if(!cvar("g_campaign") && cvar("g_balance_teams_prevent_imbalance"))
846 // only allow changing to a smaller or equal size team
848 // find out what teams are available
850 // count how many players on each team
851 GetTeamCounts(world);
854 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
859 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
864 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
869 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
876 sprint(self, "Cannot change to an invalid team\n");
882 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
884 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
886 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
888 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
891 if(scount) // started at a valid, nonempty team
893 // check if we're trying to change to a larger team that doens't have bots to swap with
894 if(dcount >= scount && dbotcount <= 0)
896 sprint(self, "Cannot change to a larger team\n");
897 return; // can't change to a larger team
903 // bprint(strcat("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"));
905 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
907 // reduce frags during a team change
908 TeamchangeFrags(self);
911 SetPlayerTeam(self, dteam, steam, FALSE);
913 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
915 // kill player when changing teams
916 if(self.deadflag == DEAD_NO)
917 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
921 void ShufflePlayerOutOfTeam (float source_team)
923 float smallestteam, smallestteam_count, steam;
924 float lowest_bot_score, lowest_player_score;
925 entity head, lowest_bot, lowest_player, selected;
929 smallestteam_count = 999;
931 if(c1 >= 0 && c1 < smallestteam_count)
934 smallestteam_count = c1;
936 if(c2 >= 0 && c2 < smallestteam_count)
939 smallestteam_count = c2;
941 if(c3 >= 0 && c3 < smallestteam_count)
944 smallestteam_count = c3;
946 if(c4 >= 0 && c4 < smallestteam_count)
949 smallestteam_count = c4;
954 bprint("warning: no smallest team\n");
960 else if(source_team == 2)
962 else if(source_team == 3)
964 else if(source_team == 4)
968 lowest_bot_score = 9999;
969 lowest_player = world;
970 lowest_player_score = 9999;
972 // find the lowest-scoring player & bot of that team
973 head = find(world, classname, "player");
976 if(head.team == steam)
980 if(head.frags < lowest_bot_score)
983 lowest_bot_score = head.frags;
988 if(head.frags < lowest_player_score)
990 lowest_player = head;
991 lowest_player_score = head.frags;
995 head = find(head, classname, "player");
998 // prefers to move a bot...
999 if(lowest_bot != world)
1000 selected = lowest_bot;
1001 // but it will move a player if it has to
1003 selected = lowest_player;
1004 // don't do anything if it couldn't find anyone
1007 bprint("warning: couldn't find a player to move from team\n");
1011 // smallest team gains a member
1012 if(smallestteam == 1)
1016 else if(smallestteam == 2)
1020 else if(smallestteam == 3)
1024 else if(smallestteam == 4)
1030 bprint("warning: destination team invalid\n");
1033 // source team loses a member
1034 if(source_team == 1)
1038 else if(source_team == 2)
1042 else if(source_team == 3)
1046 else if(source_team == 4)
1052 bprint("warning: source team invalid\n");
1056 // move the player to the new team
1057 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1059 if(selected.deadflag == DEAD_NO)
1060 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1062 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
1063 if (selected.team == 5)
1064 m = strcat(m, "^1Red Team");
1065 else if (selected.team == 14)
1066 m = strcat(m, "^4Blue Team");
1067 else if (selected.team == 10)
1068 m = strcat(m, "^6Pink Team");
1069 else if (selected.team == 13)
1070 m = strcat(m, "^3Yellow Team");
1071 centerprint(selected, m);
1075 // part of g_balance_teams_force
1076 // occasionally perform an audit of the teams to make
1077 // sure they're more or less balanced in player count.
1080 float numplayers, numteams, average;
1081 if(cvar("g_campaign"))
1083 if(!cvar("g_balance_teams_force"))
1085 if(!cvar("teamplay"))
1088 if(audit_teams_time > time)
1091 audit_teams_time = time + 4 + random();
1093 // bprint("Auditing teams\n");
1095 CheckAllowedTeams();
1096 GetTeamCounts(world);
1099 numteams = numplayers = 0;
1102 numteams = numteams + 1;
1103 numplayers = numplayers + c1;
1107 numteams = numteams + 1;
1108 numplayers = numplayers + c2;
1112 numteams = numteams + 1;
1113 numplayers = numplayers + c3;
1117 numteams = numteams + 1;
1118 numplayers = numplayers + c4;
1122 return; // no players to move around
1124 return; // don't bother shuffling if for some reason there aren't any teams
1126 average = ceil(numplayers / numteams);
1129 return; // that's weird...
1131 if(c1 && c1 > average)
1133 bprint("Rebalancing Teams\n");
1134 //bprint("Shuffle from team 1\n");
1135 ShufflePlayerOutOfTeam(1);
1137 if(c2 && c2 > average)
1139 bprint("Rebalancing Teams\n");
1140 //bprint("Shuffle from team 2\n");
1141 ShufflePlayerOutOfTeam(2);
1143 if(c3 && c3 > average)
1145 bprint("Rebalancing Teams\n");
1146 //bprint("Shuffle from team 3\n");
1147 ShufflePlayerOutOfTeam(3);
1149 if(c4 && c4 > average)
1151 bprint("Rebalancing Teams\n");
1152 //bprint("Shuffle from team 4\n");
1153 ShufflePlayerOutOfTeam(4);
1156 // if teams are still unbalanced, balance them further in the next audit,
1157 // which will happen sooner (keep doing rapid audits until things are in order)
1158 audit_teams_time = time + 0.7 + random()*0.3;
1163 /*void(entity e, float first) UpdateTeamScore =
1168 WriteByte (MSG_ALL, SVC_UPDATENAME);
1169 WriteByte (MSG_ALL, clientno);
1170 WriteString (MSG_ALL, e.netname);
1172 WriteByte (MSG_ALL, SVC_UPDATECOLORS);
1173 WriteByte (MSG_ALL, clientno);
1174 WriteByte (MSG_ALL, e.b_shirt * 16 + who.b_pants);
1177 WriteByte (MSG_ALL, SVC_UPDATEFRAGS);
1178 WriteByte (MSG_ALL, clientno);
1179 WriteShort (MSG_ALL, e.frags + 10000);
1185 // code from here on is just to support maps that don't have team entities
1186 void tdm_spawnteam (string teamname, float teamcolor)
1190 e.classname = "tdm_team";
1191 e.netname = teamname;
1196 // spawn some default teams if the map is not set up for tdm
1197 void() tdm_spawnteams =
1201 numteams = cvar("g_tdm_teams");
1203 tdm_spawnteam("Red", 4);
1204 tdm_spawnteam("Blue", 13);
1207 void() tdm_delayedinit =
1209 self.think = SUB_Remove;
1210 self.nextthink = time;
1211 // if no teams are found, spawn defaults
1212 if (find(world, classname, "tdm_team") == world)
1220 e.think = tdm_delayedinit;
1221 e.nextthink = time + 0.1;