1 float GAME_DEATHMATCH = 1;
2 float GAME_TEAM_DEATHMATCH = 2;
3 float GAME_DOMINATION = 3;
5 float GAME_RUNEMATCH = 5;
10 // client counts for each team
12 // # of bots on those teams
13 float cb1, cb2, cb3, cb4;
15 float g_domination, g_ctf, g_tdm;
17 float audit_teams_time;
19 void TeamchangeFrags(entity e)
21 if(e.classname == "player")
23 // reduce frags during a team change
24 DistributeFragsAmongTeam(e, (e.clientcolors & 0x0F) + 1, 1 - cvar("g_changeteam_fragtransfer") / 100);
28 string TeamName(float t)
30 // fixme: Search for team entities and get their .netname's!
39 return "Neutral Team";
41 string ColoredTeamName(float t)
43 // fixme: Search for team entities and get their .netname's!
45 return "^1Red Team^7";
47 return "^4Blue Team^7";
49 return "^6Pink Team^7";
51 return "^3Yellow Team^7";
52 return "Neutral Team";
54 string TeamNoName(float t)
56 // fixme: Search for team entities and get their .netname's!
65 return "Neutral Team";
70 void runematch_init();
73 void(entity pl) LogTeamchange =
76 if(!cvar("sv_eventlog"))
80 str = strcat(":team:", ftos(pl.playerid), ":");
81 str = strcat(str, ftos(pl.team));
82 GameLogEcho(str, FALSE);
87 cvar_set("g_tdm", "0");
88 cvar_set("g_domination", "0");
89 cvar_set("g_ctf", "0");
90 cvar_set("g_runematch", "0");
91 cvar_set("g_lms", "0");
92 cvar_set("g_arena", "0");
93 cvar_set("teamplay", "0");
96 void ActivateTeamplay()
98 float teamplay_default;
99 teamplay_default = cvar("teamplay_default");
102 cvar_set("teamplay", ftos(teamplay_default));
104 cvar_set("teamplay", "3");
107 void InitGameplayMode()
109 float fraglimit_override, timelimit_override;
113 game = cvar ("gamecfg"); // load game options
115 // game cvars get reset before map changes
116 // then map's cfg sets them as desired
118 // FIXME: also set a message or game mode name to print to players when the join
120 // set both here, gamemode can override it later
121 timelimit_override = cvar("timelimit_override");
122 fraglimit_override = cvar("fraglimit_override");
124 if(game == GAME_DOMINATION || cvar("g_domination"))
127 game = GAME_DOMINATION;
128 cvar_set("g_domination", "1");
132 fraglimit_override = cvar("g_domination_point_limit");
134 gamemode_name = "Domination";
137 else if(game == GAME_CTF || cvar("g_ctf"))
141 cvar_set("g_ctf", "1");
145 fraglimit_override = cvar("g_ctf_capture_limit");
147 gamemode_name = "Capture the Flag";
150 else if((game == GAME_RUNEMATCH || cvar("g_runematch")) && !cvar("g_minstagib"))
152 game = GAME_RUNEMATCH;
153 cvar_set("g_runematch", "1");
155 if(cvar("deathmatch_force_teamplay"))
158 fraglimit_override = cvar("g_runematch_point_limit");
160 gamemode_name = "Rune Match";
166 else if(game == GAME_DEATHMATCH || game == GAME_TEAM_DEATHMATCH || cvar("g_tdm"))
168 if(!cvar("deathmatch"))
169 cvar_set("deathmatch", "1");
172 if(game == GAME_TEAM_DEATHMATCH || cvar("g_tdm") || cvar("deathmatch_force_teamplay"))
175 game = GAME_TEAM_DEATHMATCH;
176 gamemode_name = "Team Deathmatch";
179 cvar_set("g_tdm", "1");
184 game = GAME_DEATHMATCH;
185 gamemode_name = "Deathmatch";
189 fraglimit_override = cvar("fraglimit_override");
191 else if(game == GAME_LMS || cvar("g_lms"))
195 cvar_set("g_lms", "1");
196 fraglimit_override = cvar("g_lms_lives_override");
197 if(fraglimit_override == 0)
198 fraglimit_override = -1;
199 gamemode_name = "Last Man Standing";
201 lms_lowest_lives = 999;
203 else if(game == GAME_ARENA || cvar("g_arena"))
207 cvar_set("g_arena", "1");
208 fraglimit_override = cvar("g_arena_point_limit");
209 maxspawned = cvar("g_arena_maxspawned");
212 arena_roundbased = cvar("g_arena_roundbased");
213 gamemode_name = "Arena";
218 // we can only assume...
220 gamemode_name = "Deathmatch";
223 /* else if(game == GAME_TEAM_DEATHMATCH)
225 if(!cvar("deathmatch"))
226 cvar_set("deathmatch", "1");
228 //if(!cvar("teamplay"))
229 // cvar_set("teamplay", "3");
232 fraglimit_override = cvar("fraglimit_override");
235 // enforce the server's universal frag/time limits
236 if(!cvar("g_campaign"))
238 if(fraglimit_override >= 0)
239 cvar_set("fraglimit", ftos(fraglimit_override));
240 if(timelimit_override >= 0)
241 cvar_set("timelimit", ftos(timelimit_override));
244 if (game == GAME_DOMINATION)//cvar("g_domination"))
246 else if (game == GAME_CTF)//cvar("g_ctf"))
248 else if (game == GAME_RUNEMATCH)//cvar("g_runematch"))
250 else if (game == GAME_TEAM_DEATHMATCH)//cvar("g_runematch"))
253 // those mutators rule each other out
254 if(cvar("g_minstagib"))
256 cvar_set("g_instagib", "0");
257 cvar_set("g_rocketarena", "0");
259 if(cvar("g_instagib"))
261 cvar_set("g_minstagib", "0");
262 cvar_set("g_rocketarena", "0");
264 if(cvar("g_rocketarena"))
266 cvar_set("g_instagib", "0");
267 cvar_set("g_minstagib", "0");
270 registercvar("_motd", "");
271 registercvar("_mutatormsg", "");
272 cvar_set("_motd", wordwrap(cvar_string("sv_motd"), 50));
273 cvar_set("_mutatormsg", wordwrap(cvar_string("g_mutatormsg"), 50));
275 g_domination = cvar("g_domination");
276 g_ctf = cvar("g_ctf");
277 g_tdm = cvar("g_tdm");
280 string GetClientVersionMessage(float v) {
281 local string versionmsg;
283 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";
284 // either that or someone wants to be funny
285 } else if (v != cvar("gameversion")) {
286 if(v < cvar("gameversion")) {
287 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
289 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
292 versionmsg = "^2client version and server version are compatible.^8";
294 return strzone(versionmsg);
299 void PrintWelcomeMessage(entity pl)
301 string s, mutator, modifications, padding;
303 /*if(self.welcomemessage_time < time)
305 if(self.welcomemessage_time2 > time)
307 self.welcomemessage_time2 = time + 0.8; */
309 if(self.classname == "observer")
311 if(cvar("g_lms") && self.frags <= 0 && self.frags > -666)
312 return centermsg_setall(strcat(newlines, "^1You have no more lives left\nwait for next round\n\n\n^7press attack to spectate other players"));
313 else if(cvar("g_lms") && self.frags == -666)
314 return centermsg_setall(strcat(newlines, "^1Match has already begun\nwait for next round\n\n\n^7press attack to spectate other players"));
316 else if(self.classname == "spectator")
318 if ((cvar("g_lms") && self.frags < 1) || cvar("g_arena"))
319 return centermsg_setall(strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press attack for next player\npress attack2 for free fly mode"));
321 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"));
325 if(self.welcomemessage_time2 > time) return;
326 self.welcomemessage_time2 = time + 1.0;
328 if(cvar("g_campaign"))
330 centermsg_setallfor(pl, campaign_message);
334 if(cvar("g_minstagib"))
335 mutator = "^2Minstagib ^1";
336 else if(cvar("g_instagib"))
337 mutator = "^2Instagib ^1";
338 else if(cvar("g_rocketarena"))
339 mutator = "^2Rocketarena ^1";
340 else if(cvar("g_nixnex"))
341 mutator = "^2No Items Nexuiz ^1";
343 if(cvar("g_midair")) {
344 // to protect against unheedingly made changes
346 modifications = strcat(modifications, ", ");
348 modifications = "midair";
350 if(cvar("g_vampire")) {
352 modifications = strcat(modifications, ", ");
354 modifications = strcat(modifications, "vampire");
356 if(cvar("g_laserguided_missile")) {
358 modifications = strcat(modifications, ", ");
360 modifications = strcat(modifications, "laser-guided-missiles");
363 local string versionmessage;
364 versionmessage = GetClientVersionMessage(self.version);
366 s = strcat(s, newlines, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
367 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
369 if(modifications != "")
370 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
372 if((self.classname == "observer" || self.classname == "spectator") && self.version == cvar("gameversion")) {
374 s = strcat(s,"^7\n\n\npress jump to play\npress attack to spectate other players\n\n");
375 else if(player_count < 2 && arena_roundbased)
377 s = strcat(s, "\n\n\n^1waiting for second player to start match^7\n\n");
381 s = strcat(s, "\n\n\n");
383 s = strcat(s, "^7current champion is: ", champion.netname, "\n\n");
384 s = strcat(s,"^7press attack to spectate other players\n\n");
391 if (cvar("g_grappling_hook"))
392 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
394 if (cvar_string("_mutatormsg") != "") {
395 s = strcat(s, "\n\n^8special gameplay tips: ^7", cvar_string("_mutatormsg"));
398 if (cvar_string("_motd") != "") {
399 s = strcat(s, "\n\n^8MOTD: ^7", cvar_string("_motd"));
403 if(cvar("fraglimit"))
406 if(cvar("timelimit"))
409 s = strcat(s, "\n^8frag limit: ^7", cvar_string("fraglimit"), padding);
411 if(cvar("timelimit"))
412 s = strcat(s, "\n^8time limit: ^7", cvar_string("timelimit"), " minutes");
416 centermsg_setallfor(pl, s);
423 void SetPlayerColors(entity pl, float _color)
427 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
429 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
430 pl.clientcolors = 16*cl + cl;*/
433 pants = _color & 0x0F;
434 shirt = _color & 0xF0;
438 setcolor(pl, 16*pants + pants);
440 setcolor(pl, shirt + pants);
444 void SetPlayerTeam(entity pl, float t, float s, float noprint)
449 _color = COLOR_TEAM4 - 1;
451 _color = COLOR_TEAM3 - 1;
453 _color = COLOR_TEAM2 - 1;
455 _color = COLOR_TEAM1 - 1;
457 SetPlayerColors(pl,_color);
459 if(!noprint && t != s)
461 //bprint(strcat(pl.netname, " has changed to ", TeamNoName(t), "\n"));
462 bprint(strcat(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"));
474 // set c1...c4 to show what teams are allowed
475 void CheckAllowedTeams ()
484 c1 = c2 = c3 = c4 = -1;
485 cb1 = cb2 = cb3 = cb4 = 0;
488 teament_name = "dom_team";
490 teament_name = "ctf_team";
492 teament_name = "tdm_team";
495 // cover anything else by treating it like tdm with no teams spawned
496 dm = cvar("g_tdm_teams");
498 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
502 c1 = c2 = c3 = c4 = 0;
515 // first find out what teams are allowed
516 head = find(world, classname, teament_name);
519 if(!(g_domination && head.netname == ""))
521 if(head.team == COLOR_TEAM1)
525 if(head.team == COLOR_TEAM2)
529 if(head.team == COLOR_TEAM3)
533 if(head.team == COLOR_TEAM4)
538 head = find(head, classname, teament_name);
542 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
543 // teams that are allowed will now have their player counts stored in c1...c4
544 void GetTeamCounts(entity ignore)
547 // now count how many players are on each team already
549 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
550 // also remember the lowest-scoring player
552 head = find(world, classname, "player");
555 if(head != ignore)// && head.netname != "")
557 if(head.team == COLOR_TEAM1)
565 if(head.team == COLOR_TEAM2)
573 if(head.team == COLOR_TEAM3)
581 if(head.team == COLOR_TEAM4)
590 head = find(head, classname, "player");
594 // returns # of smallest team (1, 2, 3, 4)
595 // NOTE: Assumes CheckAllowedTeams has already been called!
596 float FindSmallestTeam(entity pl, float ignore_pl)
598 float totalteams, smallestteam, smallestteam_count, smallestteam_score, balance_type;
601 // find out what teams are available
602 //CheckAllowedTeams();
604 // make sure there are at least 2 teams to join
606 totalteams = totalteams + 1;
608 totalteams = totalteams + 1;
610 totalteams = totalteams + 1;
612 totalteams = totalteams + 1;
617 error("Too few teams available for domination\n");
619 error("Too few teams available for ctf\n");
621 error("Too few teams available for team deathmatch\n");
625 // count how many players are in each team
629 GetTeamCounts(world);
631 // c1...c4 now have counts of each team
632 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
635 smallestteam_count = 999999999;
636 smallestteam_score = 999999999;
638 // 2 gives priority to what team you're already on, 1 goes in order
639 // 2 doesn't seem to work though...
642 if(balance_type == 1)
644 if(c1 >= 0 && (c1 < smallestteam_count || (c1 <= smallestteam_count && team1_score < smallestteam_score)))
647 smallestteam_count = c1;
648 smallestteam_score = team1_score;
650 if(c2 >= 0 && (c2 < smallestteam_count || (c2 <= smallestteam_count && team2_score < smallestteam_score)))
653 smallestteam_count = c2;
654 smallestteam_score = team2_score;
656 if(c3 >= 0 && (c3 < smallestteam_count || (c3 <= smallestteam_count && team3_score < smallestteam_score)))
659 smallestteam_count = c3;
660 smallestteam_score = team3_score;
662 if(c4 >= 0 && (c4 < smallestteam_count || (c4 <= smallestteam_count && team4_score < smallestteam_score)))
665 smallestteam_count = c4;
666 smallestteam_score = team4_score;
671 if(c1 >= 0 && (c1 < smallestteam_count ||
672 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
675 smallestteam_count = c1;
677 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
678 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
681 smallestteam_count = c2;
683 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
684 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
687 smallestteam_count = c3;
689 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
690 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
693 smallestteam_count = c4;
700 float JoinBestTeam(entity pl, float only_return_best)
702 float smallest, selectedteam;
704 // don't join a team if we're not playing a team game
705 if(!cvar("teamplay") && !g_domination && !g_ctf)
708 // find out what teams are available
711 if(cvar("g_domination"))
713 if(cvar("g_domination_default_teams") < 3)
715 if(cvar("g_domination_default_teams") < 4)
719 // if we don't care what team he ends up on, put him on whatever team he entered as.
720 // if he's not on a valid team, then let other code put him on the smallest team
721 if(!cvar("g_campaign") && !cvar("g_balance_teams") && !cvar("g_balance_teams_force"))
723 if( c1 >= 0 && pl.team == COLOR_TEAM1)
724 selectedteam = pl.team;
725 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
726 selectedteam = pl.team;
727 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
728 selectedteam = pl.team;
729 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
730 selectedteam = pl.team;
735 if(!only_return_best)
737 SetPlayerColors(pl, selectedteam - 1);
742 // otherwise end up on the smallest team (handled below)
745 smallest = FindSmallestTeam(pl, TRUE);
748 if(!only_return_best)
750 TeamchangeFrags(self);
753 SetPlayerColors(pl, COLOR_TEAM1 - 1);
755 else if(smallest == 2)
757 SetPlayerColors(pl, COLOR_TEAM2 - 1);
759 else if(smallest == 3)
761 SetPlayerColors(pl, COLOR_TEAM3 - 1);
763 else if(smallest == 4)
765 SetPlayerColors(pl, COLOR_TEAM4 - 1);
769 error("smallest team: invalid team\n");
772 if(pl.deadflag == DEAD_NO)
773 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
780 void SV_ChangeTeam(float _color)
782 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
784 // in normal deathmatch we can just apply the color and we're done
785 if(!cvar("teamplay")) {
786 SetPlayerColors(self, _color);
790 scolor = self.clientcolors & 0x0F;
791 dcolor = _color & 0x0F;
793 if(scolor == COLOR_TEAM1 - 1)
795 else if(scolor == COLOR_TEAM2 - 1)
797 else if(scolor == COLOR_TEAM3 - 1)
799 else if(scolor == COLOR_TEAM4 - 1)
801 if(dcolor == COLOR_TEAM1 - 1)
803 else if(dcolor == COLOR_TEAM2 - 1)
805 else if(dcolor == COLOR_TEAM3 - 1)
807 else if(dcolor == COLOR_TEAM4 - 1)
810 // remap invalid teams in dom & ctf
812 if(cvar("g_ctf") && dteam == 3)
814 else if(cvar("g_ctf") && dteam == 4)
816 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 3) || (cvar("g_tdm") && cvar("g_tdm_teams") < 3))
823 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 4) || (cvar("g_tdm") && cvar("g_tdm_teams") < 4))
831 if(dteam == 3 && c3 < 0)
833 if(dteam == 4 && c4 < 0)
836 // not changing teams
839 //bprint("same team change\n");
840 SetPlayerTeam(self, dteam, steam, TRUE);
846 if(cvar("g_campaign") || cvar("g_changeteam_banned"))
848 sprint(self, "Team changes not allowed\n");
849 return; // changing teams is not allowed
852 if(!cvar("g_campaign") && cvar("g_balance_teams_prevent_imbalance"))
854 // only allow changing to a smaller or equal size team
856 // find out what teams are available
858 // count how many players on each team
859 GetTeamCounts(world);
862 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
867 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
872 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
877 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
884 sprint(self, "Cannot change to an invalid team\n");
890 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
892 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
894 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
896 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
899 if(scount) // started at a valid, nonempty team
901 // check if we're trying to change to a larger team that doens't have bots to swap with
902 if(dcount >= scount && dbotcount <= 0)
904 sprint(self, "Cannot change to a larger team\n");
905 return; // can't change to a larger team
911 // bprint(strcat("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"));
913 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
915 // reduce frags during a team change
916 TeamchangeFrags(self);
919 SetPlayerTeam(self, dteam, steam, FALSE);
921 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
923 // kill player when changing teams
924 if(self.deadflag == DEAD_NO)
925 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
929 void ShufflePlayerOutOfTeam (float source_team)
931 float smallestteam, smallestteam_count, steam;
932 float lowest_bot_score, lowest_player_score;
933 entity head, lowest_bot, lowest_player, selected;
936 smallestteam_count = 999999999;
938 if(c1 >= 0 && c1 < smallestteam_count)
941 smallestteam_count = c1;
943 if(c2 >= 0 && c2 < smallestteam_count)
946 smallestteam_count = c2;
948 if(c3 >= 0 && c3 < smallestteam_count)
951 smallestteam_count = c3;
953 if(c4 >= 0 && c4 < smallestteam_count)
956 smallestteam_count = c4;
961 bprint("warning: no smallest team\n");
967 else if(source_team == 2)
969 else if(source_team == 3)
971 else if(source_team == 4)
975 lowest_bot_score = 999999999;
976 lowest_player = world;
977 lowest_player_score = 999999999;
979 // find the lowest-scoring player & bot of that team
980 head = find(world, classname, "player");
983 if(head.team == steam)
987 if(head.frags < lowest_bot_score)
990 lowest_bot_score = head.frags;
995 if(head.frags < lowest_player_score)
997 lowest_player = head;
998 lowest_player_score = head.frags;
1002 head = find(head, classname, "player");
1005 // prefers to move a bot...
1006 if(lowest_bot != world)
1007 selected = lowest_bot;
1008 // but it will move a player if it has to
1010 selected = lowest_player;
1011 // don't do anything if it couldn't find anyone
1014 bprint("warning: couldn't find a player to move from team\n");
1018 // smallest team gains a member
1019 if(smallestteam == 1)
1023 else if(smallestteam == 2)
1027 else if(smallestteam == 3)
1031 else if(smallestteam == 4)
1037 bprint("warning: destination team invalid\n");
1040 // source team loses a member
1041 if(source_team == 1)
1045 else if(source_team == 2)
1049 else if(source_team == 3)
1053 else if(source_team == 4)
1059 bprint("warning: source team invalid\n");
1063 // move the player to the new team
1064 TeamchangeFrags(selected);
1065 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1067 if(selected.deadflag == DEAD_NO)
1068 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1070 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
1071 if (selected.team == 5)
1072 m = strcat(m, "^1Red Team");
1073 else if (selected.team == 14)
1074 m = strcat(m, "^4Blue Team");
1075 else if (selected.team == 10)
1076 m = strcat(m, "^6Pink Team");
1077 else if (selected.team == 13)
1078 m = strcat(m, "^3Yellow Team");
1079 centerprint(selected, m);
1083 // part of g_balance_teams_force
1084 // occasionally perform an audit of the teams to make
1085 // sure they're more or less balanced in player count.
1088 float numplayers, numteams, average;
1089 if(cvar("g_campaign"))
1091 if(!cvar("g_balance_teams_force"))
1093 if(!cvar("teamplay"))
1096 if(audit_teams_time > time)
1099 audit_teams_time = time + 4 + random();
1101 // bprint("Auditing teams\n");
1103 CheckAllowedTeams();
1104 GetTeamCounts(world);
1107 numteams = numplayers = 0;
1110 numteams = numteams + 1;
1111 numplayers = numplayers + c1;
1115 numteams = numteams + 1;
1116 numplayers = numplayers + c2;
1120 numteams = numteams + 1;
1121 numplayers = numplayers + c3;
1125 numteams = numteams + 1;
1126 numplayers = numplayers + c4;
1130 return; // no players to move around
1132 return; // don't bother shuffling if for some reason there aren't any teams
1134 average = ceil(numplayers / numteams);
1137 return; // that's weird...
1139 if(c1 && c1 > average)
1141 bprint("Rebalancing Teams\n");
1142 //bprint("Shuffle from team 1\n");
1143 ShufflePlayerOutOfTeam(1);
1145 if(c2 && c2 > average)
1147 bprint("Rebalancing Teams\n");
1148 //bprint("Shuffle from team 2\n");
1149 ShufflePlayerOutOfTeam(2);
1151 if(c3 && c3 > average)
1153 bprint("Rebalancing Teams\n");
1154 //bprint("Shuffle from team 3\n");
1155 ShufflePlayerOutOfTeam(3);
1157 if(c4 && c4 > average)
1159 bprint("Rebalancing Teams\n");
1160 //bprint("Shuffle from team 4\n");
1161 ShufflePlayerOutOfTeam(4);
1164 // if teams are still unbalanced, balance them further in the next audit,
1165 // which will happen sooner (keep doing rapid audits until things are in order)
1166 audit_teams_time = time + 0.7 + random()*0.3;
1171 /*void(entity e, float first) UpdateTeamScore =
1176 WriteByte (MSG_ALL, SVC_UPDATENAME);
1177 WriteByte (MSG_ALL, clientno);
1178 WriteString (MSG_ALL, e.netname);
1180 WriteByte (MSG_ALL, SVC_UPDATECOLORS);
1181 WriteByte (MSG_ALL, clientno);
1182 WriteByte (MSG_ALL, e.b_shirt * 16 + who.b_pants);
1185 WriteByte (MSG_ALL, SVC_UPDATEFRAGS);
1186 WriteByte (MSG_ALL, clientno);
1187 WriteShort (MSG_ALL, e.frags + 10000);
1193 // code from here on is just to support maps that don't have team entities
1194 void tdm_spawnteam (string teamname, float teamcolor)
1198 e.classname = "tdm_team";
1199 e.netname = teamname;
1204 // spawn some default teams if the map is not set up for tdm
1205 void() tdm_spawnteams =
1209 numteams = cvar("g_tdm_teams");
1211 tdm_spawnteam("Red", 4);
1212 tdm_spawnteam("Blue", 13);
1215 void() tdm_delayedinit =
1217 self.think = SUB_Remove;
1218 self.nextthink = time;
1219 // if no teams are found, spawn defaults
1220 if (find(world, classname, "tdm_team") == world)
1228 e.think = tdm_delayedinit;
1229 e.nextthink = time + 0.1;