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 cvar_set("exit_cfg", "");
99 void ActivateTeamplay()
101 float teamplay_default;
102 teamplay_default = cvar("teamplay_default");
105 cvar_set("teamplay", ftos(teamplay_default));
107 cvar_set("teamplay", "3");
110 void InitGameplayMode()
112 float fraglimit_override, timelimit_override;
116 game = cvar ("gamecfg"); // load game options
118 // game cvars get reset before map changes
119 // then map's cfg sets them as desired
121 // FIXME: also set a message or game mode name to print to players when the join
123 // set both here, gamemode can override it later
124 timelimit_override = cvar("timelimit_override");
125 fraglimit_override = cvar("fraglimit_override");
127 if(game == GAME_DOMINATION || cvar("g_domination"))
130 game = GAME_DOMINATION;
131 cvar_set("g_domination", "1");
135 fraglimit_override = cvar("g_domination_point_limit");
137 gamemode_name = "Domination";
140 else if(game == GAME_CTF || cvar("g_ctf"))
144 cvar_set("g_ctf", "1");
148 fraglimit_override = cvar("g_ctf_capture_limit");
150 gamemode_name = "Capture the Flag";
153 else if((game == GAME_RUNEMATCH || cvar("g_runematch")) && !cvar("g_minstagib"))
155 game = GAME_RUNEMATCH;
156 cvar_set("g_runematch", "1");
158 if(cvar("deathmatch_force_teamplay"))
161 fraglimit_override = cvar("g_runematch_point_limit");
163 gamemode_name = "Rune Match";
169 else if(game == GAME_DEATHMATCH || game == GAME_TEAM_DEATHMATCH || cvar("g_tdm"))
171 if(!cvar("deathmatch"))
172 cvar_set("deathmatch", "1");
175 if(game == GAME_TEAM_DEATHMATCH || cvar("g_tdm") || cvar("deathmatch_force_teamplay"))
178 game = GAME_TEAM_DEATHMATCH;
179 gamemode_name = "Team Deathmatch";
182 cvar_set("g_tdm", "1");
187 game = GAME_DEATHMATCH;
188 gamemode_name = "Deathmatch";
192 fraglimit_override = cvar("fraglimit_override");
194 else if(game == GAME_LMS || cvar("g_lms"))
198 cvar_set("g_lms", "1");
199 fraglimit_override = cvar("g_lms_lives_override");
200 if(fraglimit_override == 0)
201 fraglimit_override = -1;
202 gamemode_name = "Last Man Standing";
204 lms_lowest_lives = 999;
206 else if(game == GAME_ARENA || cvar("g_arena"))
210 cvar_set("g_arena", "1");
211 fraglimit_override = cvar("g_arena_point_limit");
212 maxspawned = cvar("g_arena_maxspawned");
215 arena_roundbased = cvar("g_arena_roundbased");
216 gamemode_name = "Arena";
221 // we can only assume...
223 gamemode_name = "Deathmatch";
226 /* else if(game == GAME_TEAM_DEATHMATCH)
228 if(!cvar("deathmatch"))
229 cvar_set("deathmatch", "1");
231 //if(!cvar("teamplay"))
232 // cvar_set("teamplay", "3");
235 fraglimit_override = cvar("fraglimit_override");
238 // enforce the server's universal frag/time limits
239 if(!cvar("g_campaign"))
241 if(fraglimit_override >= 0)
242 cvar_set("fraglimit", ftos(fraglimit_override));
243 if(timelimit_override >= 0)
244 cvar_set("timelimit", ftos(timelimit_override));
247 if (game == GAME_DOMINATION)//cvar("g_domination"))
249 else if (game == GAME_CTF)//cvar("g_ctf"))
251 else if (game == GAME_RUNEMATCH)//cvar("g_runematch"))
253 else if (game == GAME_TEAM_DEATHMATCH)//cvar("g_runematch"))
256 // those mutators rule each other out
257 if(cvar("g_minstagib"))
259 cvar_set("g_instagib", "0");
260 cvar_set("g_rocketarena", "0");
262 if(cvar("g_instagib"))
264 cvar_set("g_minstagib", "0");
265 cvar_set("g_rocketarena", "0");
267 if(cvar("g_rocketarena"))
269 cvar_set("g_instagib", "0");
270 cvar_set("g_minstagib", "0");
273 registercvar("_motd", "");
274 registercvar("_mutatormsg", "");
275 cvar_set("_motd", wordwrap(cvar_string("sv_motd"), 50));
276 cvar_set("_mutatormsg", wordwrap(cvar_string("g_mutatormsg"), 50));
278 g_domination = cvar("g_domination");
279 g_ctf = cvar("g_ctf");
280 g_tdm = cvar("g_tdm");
283 string GetClientVersionMessage(float v) {
284 local string versionmsg;
286 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";
287 // either that or someone wants to be funny
288 } else if (v != cvar("gameversion")) {
289 if(v < cvar("gameversion")) {
290 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
292 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
295 versionmsg = "^2client version and server version are compatible.^8";
297 return strzone(versionmsg);
302 void PrintWelcomeMessage(entity pl)
304 string s, mutator, modifications, padding;
306 /*if(self.welcomemessage_time < time)
308 if(self.welcomemessage_time2 > time)
310 self.welcomemessage_time2 = time + 0.8; */
312 if(self.classname == "observer")
314 if(cvar("g_lms") && self.frags <= 0 && self.frags > -666)
315 return centermsg_setall(strcat(newlines, "^1You have no more lives left\nwait for next round\n\n\n^7press attack to spectate other players"));
316 else if(cvar("g_lms") && self.frags == -666)
317 return centermsg_setall(strcat(newlines, "^1Match has already begun\nwait for next round\n\n\n^7press attack to spectate other players"));
319 else if(self.classname == "spectator")
321 if ((cvar("g_lms") && self.frags < 1) || cvar("g_arena"))
322 return centermsg_setall(strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press attack for next player\npress attack2 for free fly mode"));
324 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"));
328 if(self.welcomemessage_time2 > time) return;
329 self.welcomemessage_time2 = time + 1.0;
331 if(cvar("g_campaign"))
333 centermsg_setallfor(pl, campaign_message);
337 if(cvar("g_minstagib"))
338 mutator = "^2Minstagib ^1";
339 else if(cvar("g_instagib"))
340 mutator = "^2Instagib ^1";
341 else if(cvar("g_rocketarena"))
342 mutator = "^2Rocketarena ^1";
343 else if(cvar("g_nixnex"))
344 mutator = "^2No Items Nexuiz ^1";
346 if(cvar("g_midair")) {
347 // to protect against unheedingly made changes
349 modifications = strcat(modifications, ", ");
351 modifications = "midair";
353 if(cvar("g_vampire")) {
355 modifications = strcat(modifications, ", ");
357 modifications = strcat(modifications, "vampire");
359 if(cvar("g_laserguided_missile")) {
361 modifications = strcat(modifications, ", ");
363 modifications = strcat(modifications, "laser-guided-missiles");
366 local string versionmessage;
367 versionmessage = GetClientVersionMessage(self.version);
369 s = strcat(s, newlines, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
370 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
372 if(modifications != "")
373 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
375 if((self.classname == "observer" || self.classname == "spectator") && self.version == cvar("gameversion")) {
377 s = strcat(s,"^7\n\n\npress jump to play\npress attack to spectate other players\n\n");
378 else if(player_count < 2 && arena_roundbased)
380 s = strcat(s, "\n\n\n^1waiting for second player to start match^7\n\n");
384 s = strcat(s, "\n\n\n");
386 s = strcat(s, "^7current champion is: ", champion.netname, "\n\n");
387 s = strcat(s,"^7press attack to spectate other players\n\n");
394 if (cvar("g_grappling_hook"))
395 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
397 if (cvar_string("_mutatormsg") != "") {
398 s = strcat(s, "\n\n^8special gameplay tips: ^7", cvar_string("_mutatormsg"));
401 if (cvar_string("_motd") != "") {
402 s = strcat(s, "\n\n^8MOTD: ^7", cvar_string("_motd"));
406 if(cvar("fraglimit"))
409 if(cvar("timelimit"))
412 s = strcat(s, "\n^8frag limit: ^7", cvar_string("fraglimit"), padding);
414 if(cvar("timelimit"))
415 s = strcat(s, "\n^8time limit: ^7", cvar_string("timelimit"), " minutes");
419 centermsg_setallfor(pl, s);
426 void SetPlayerColors(entity pl, float _color)
430 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
432 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
433 pl.clientcolors = 16*cl + cl;*/
436 pants = _color & 0x0F;
437 shirt = _color & 0xF0;
441 setcolor(pl, 16*pants + pants);
443 setcolor(pl, shirt + pants);
447 void SetPlayerTeam(entity pl, float t, float s, float noprint)
452 _color = COLOR_TEAM4 - 1;
454 _color = COLOR_TEAM3 - 1;
456 _color = COLOR_TEAM2 - 1;
458 _color = COLOR_TEAM1 - 1;
460 SetPlayerColors(pl,_color);
462 if(!noprint && t != s)
464 //bprint(strcat(pl.netname, " has changed to ", TeamNoName(t), "\n"));
465 bprint(strcat(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"));
477 // set c1...c4 to show what teams are allowed
478 void CheckAllowedTeams ()
487 c1 = c2 = c3 = c4 = -1;
488 cb1 = cb2 = cb3 = cb4 = 0;
491 teament_name = "dom_team";
493 teament_name = "ctf_team";
495 teament_name = "tdm_team";
498 // cover anything else by treating it like tdm with no teams spawned
499 dm = cvar("g_tdm_teams");
501 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
505 c1 = c2 = c3 = c4 = 0;
518 // first find out what teams are allowed
519 head = find(world, classname, teament_name);
522 if(!(g_domination && head.netname == ""))
524 if(head.team == COLOR_TEAM1)
528 if(head.team == COLOR_TEAM2)
532 if(head.team == COLOR_TEAM3)
536 if(head.team == COLOR_TEAM4)
541 head = find(head, classname, teament_name);
545 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
546 // teams that are allowed will now have their player counts stored in c1...c4
547 void GetTeamCounts(entity ignore)
550 // now count how many players are on each team already
552 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
553 // also remember the lowest-scoring player
555 head = find(world, classname, "player");
558 if(head != ignore)// && head.netname != "")
560 if(head.team == COLOR_TEAM1)
568 if(head.team == COLOR_TEAM2)
576 if(head.team == COLOR_TEAM3)
584 if(head.team == COLOR_TEAM4)
593 head = find(head, classname, "player");
597 // returns # of smallest team (1, 2, 3, 4)
598 // NOTE: Assumes CheckAllowedTeams has already been called!
599 float FindSmallestTeam(entity pl, float ignore_pl)
601 float totalteams, smallestteam, smallestteam_count, balance_type;
604 // find out what teams are available
605 //CheckAllowedTeams();
607 // make sure there are at least 2 teams to join
609 totalteams = totalteams + 1;
611 totalteams = totalteams + 1;
613 totalteams = totalteams + 1;
615 totalteams = totalteams + 1;
620 error("Too few teams available for domination\n");
622 error("Too few teams available for ctf\n");
624 error("Too few teams available for team deathmatch\n");
628 // count how many players are in each team
632 GetTeamCounts(world);
634 // c1...c4 now have counts of each team
635 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
638 smallestteam_count = 999;
640 // 2 gives priority to what team you're already on, 1 goes in order
641 // 2 doesn't seem to work though...
644 if(balance_type == 1)
646 if(c1 >= 0 && c1 < smallestteam_count)
649 smallestteam_count = c1;
651 if(c2 >= 0 && c2 < smallestteam_count)
654 smallestteam_count = c2;
656 if(c3 >= 0 && c3 < smallestteam_count)
659 smallestteam_count = c3;
661 if(c4 >= 0 && c4 < smallestteam_count)
664 smallestteam_count = c4;
669 if(c1 >= 0 && (c1 < smallestteam_count ||
670 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
673 smallestteam_count = c1;
675 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
676 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
679 smallestteam_count = c2;
681 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
682 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
685 smallestteam_count = c3;
687 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
688 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
691 smallestteam_count = c4;
698 float JoinBestTeam(entity pl, float only_return_best)
700 float smallest, selectedteam;
702 // don't join a team if we're not playing a team game
703 if(!cvar("teamplay") && !g_domination && !g_ctf)
706 // find out what teams are available
709 if(cvar("g_domination"))
711 if(cvar("g_domination_default_teams") < 3)
713 if(cvar("g_domination_default_teams") < 4)
717 // if we don't care what team he ends up on, put him on whatever team he entered as.
718 // if he's not on a valid team, then let other code put him on the smallest team
719 if(!cvar("g_campaign") && !cvar("g_balance_teams") && !cvar("g_balance_teams_force"))
721 if( c1 >= 0 && pl.team == COLOR_TEAM1)
722 selectedteam = pl.team;
723 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
724 selectedteam = pl.team;
725 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
726 selectedteam = pl.team;
727 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
728 selectedteam = pl.team;
733 if(!only_return_best)
735 SetPlayerColors(pl, selectedteam - 1);
740 // otherwise end up on the smallest team (handled below)
743 smallest = FindSmallestTeam(pl, TRUE);
746 if(!only_return_best)
748 TeamchangeFrags(self);
751 SetPlayerColors(pl, COLOR_TEAM1 - 1);
753 else if(smallest == 2)
755 SetPlayerColors(pl, COLOR_TEAM2 - 1);
757 else if(smallest == 3)
759 SetPlayerColors(pl, COLOR_TEAM3 - 1);
761 else if(smallest == 4)
763 SetPlayerColors(pl, COLOR_TEAM4 - 1);
767 error("smallest team: invalid team\n");
770 if(pl.deadflag == DEAD_NO)
771 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
778 void SV_ChangeTeam(float _color)
780 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
782 // in normal deathmatch we can just apply the color and we're done
783 if(!cvar("teamplay")) {
784 SetPlayerColors(self, _color);
788 scolor = self.clientcolors & 0x0F;
789 dcolor = _color & 0x0F;
791 if(scolor == COLOR_TEAM1 - 1)
793 else if(scolor == COLOR_TEAM2 - 1)
795 else if(scolor == COLOR_TEAM3 - 1)
797 else if(scolor == COLOR_TEAM4 - 1)
799 if(dcolor == COLOR_TEAM1 - 1)
801 else if(dcolor == COLOR_TEAM2 - 1)
803 else if(dcolor == COLOR_TEAM3 - 1)
805 else if(dcolor == COLOR_TEAM4 - 1)
808 // remap invalid teams in dom & ctf
810 if(cvar("g_ctf") && dteam == 3)
812 else if(cvar("g_ctf") && dteam == 4)
814 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 3) || (cvar("g_tdm") && cvar("g_tdm_teams") < 3))
821 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 4) || (cvar("g_tdm") && cvar("g_tdm_teams") < 4))
829 if(dteam == 3 && c3 < 0)
831 if(dteam == 4 && c4 < 0)
834 // not changing teams
837 //bprint("same team change\n");
838 SetPlayerTeam(self, dteam, steam, TRUE);
844 if(cvar("g_campaign") || cvar("g_changeteam_banned"))
846 sprint(self, "Team changes not allowed\n");
847 return; // changing teams is not allowed
850 if(!cvar("g_campaign") && cvar("g_balance_teams_prevent_imbalance"))
852 // only allow changing to a smaller or equal size team
854 // find out what teams are available
856 // count how many players on each team
857 GetTeamCounts(world);
860 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
865 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
870 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
875 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
882 sprint(self, "Cannot change to an invalid team\n");
888 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
890 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
892 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
894 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
897 if(scount) // started at a valid, nonempty team
899 // check if we're trying to change to a larger team that doens't have bots to swap with
900 if(dcount >= scount && dbotcount <= 0)
902 sprint(self, "Cannot change to a larger team\n");
903 return; // can't change to a larger team
909 // bprint(strcat("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"));
911 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
913 // reduce frags during a team change
914 TeamchangeFrags(self);
917 SetPlayerTeam(self, dteam, steam, FALSE);
919 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
921 // kill player when changing teams
922 if(self.deadflag == DEAD_NO)
923 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
927 void ShufflePlayerOutOfTeam (float source_team)
929 float smallestteam, smallestteam_count, steam;
930 float lowest_bot_score, lowest_player_score;
931 entity head, lowest_bot, lowest_player, selected;
934 smallestteam_count = 999;
936 if(c1 >= 0 && c1 < smallestteam_count)
939 smallestteam_count = c1;
941 if(c2 >= 0 && c2 < smallestteam_count)
944 smallestteam_count = c2;
946 if(c3 >= 0 && c3 < smallestteam_count)
949 smallestteam_count = c3;
951 if(c4 >= 0 && c4 < smallestteam_count)
954 smallestteam_count = c4;
959 bprint("warning: no smallest team\n");
965 else if(source_team == 2)
967 else if(source_team == 3)
969 else if(source_team == 4)
973 lowest_bot_score = 9999;
974 lowest_player = world;
975 lowest_player_score = 9999;
977 // find the lowest-scoring player & bot of that team
978 head = find(world, classname, "player");
981 if(head.team == steam)
985 if(head.frags < lowest_bot_score)
988 lowest_bot_score = head.frags;
993 if(head.frags < lowest_player_score)
995 lowest_player = head;
996 lowest_player_score = head.frags;
1000 head = find(head, classname, "player");
1003 // prefers to move a bot...
1004 if(lowest_bot != world)
1005 selected = lowest_bot;
1006 // but it will move a player if it has to
1008 selected = lowest_player;
1009 // don't do anything if it couldn't find anyone
1012 bprint("warning: couldn't find a player to move from team\n");
1016 // smallest team gains a member
1017 if(smallestteam == 1)
1021 else if(smallestteam == 2)
1025 else if(smallestteam == 3)
1029 else if(smallestteam == 4)
1035 bprint("warning: destination team invalid\n");
1038 // source team loses a member
1039 if(source_team == 1)
1043 else if(source_team == 2)
1047 else if(source_team == 3)
1051 else if(source_team == 4)
1057 bprint("warning: source team invalid\n");
1061 // move the player to the new team
1062 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1064 if(selected.deadflag == DEAD_NO)
1065 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1067 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
1068 if (selected.team == 5)
1069 m = strcat(m, "^1Red Team");
1070 else if (selected.team == 14)
1071 m = strcat(m, "^4Blue Team");
1072 else if (selected.team == 10)
1073 m = strcat(m, "^6Pink Team");
1074 else if (selected.team == 13)
1075 m = strcat(m, "^3Yellow Team");
1076 centerprint(selected, m);
1080 // part of g_balance_teams_force
1081 // occasionally perform an audit of the teams to make
1082 // sure they're more or less balanced in player count.
1085 float numplayers, numteams, average;
1086 if(cvar("g_campaign"))
1088 if(!cvar("g_balance_teams_force"))
1090 if(!cvar("teamplay"))
1093 if(audit_teams_time > time)
1096 audit_teams_time = time + 4 + random();
1098 // bprint("Auditing teams\n");
1100 CheckAllowedTeams();
1101 GetTeamCounts(world);
1104 numteams = numplayers = 0;
1107 numteams = numteams + 1;
1108 numplayers = numplayers + c1;
1112 numteams = numteams + 1;
1113 numplayers = numplayers + c2;
1117 numteams = numteams + 1;
1118 numplayers = numplayers + c3;
1122 numteams = numteams + 1;
1123 numplayers = numplayers + c4;
1127 return; // no players to move around
1129 return; // don't bother shuffling if for some reason there aren't any teams
1131 average = ceil(numplayers / numteams);
1134 return; // that's weird...
1136 if(c1 && c1 > average)
1138 bprint("Rebalancing Teams\n");
1139 //bprint("Shuffle from team 1\n");
1140 ShufflePlayerOutOfTeam(1);
1142 if(c2 && c2 > average)
1144 bprint("Rebalancing Teams\n");
1145 //bprint("Shuffle from team 2\n");
1146 ShufflePlayerOutOfTeam(2);
1148 if(c3 && c3 > average)
1150 bprint("Rebalancing Teams\n");
1151 //bprint("Shuffle from team 3\n");
1152 ShufflePlayerOutOfTeam(3);
1154 if(c4 && c4 > average)
1156 bprint("Rebalancing Teams\n");
1157 //bprint("Shuffle from team 4\n");
1158 ShufflePlayerOutOfTeam(4);
1161 // if teams are still unbalanced, balance them further in the next audit,
1162 // which will happen sooner (keep doing rapid audits until things are in order)
1163 audit_teams_time = time + 0.7 + random()*0.3;
1168 /*void(entity e, float first) UpdateTeamScore =
1173 WriteByte (MSG_ALL, SVC_UPDATENAME);
1174 WriteByte (MSG_ALL, clientno);
1175 WriteString (MSG_ALL, e.netname);
1177 WriteByte (MSG_ALL, SVC_UPDATECOLORS);
1178 WriteByte (MSG_ALL, clientno);
1179 WriteByte (MSG_ALL, e.b_shirt * 16 + who.b_pants);
1182 WriteByte (MSG_ALL, SVC_UPDATEFRAGS);
1183 WriteByte (MSG_ALL, clientno);
1184 WriteShort (MSG_ALL, e.frags + 10000);
1190 // code from here on is just to support maps that don't have team entities
1191 void tdm_spawnteam (string teamname, float teamcolor)
1195 e.classname = "tdm_team";
1196 e.netname = teamname;
1201 // spawn some default teams if the map is not set up for tdm
1202 void() tdm_spawnteams =
1206 numteams = cvar("g_tdm_teams");
1208 tdm_spawnteam("Red", 4);
1209 tdm_spawnteam("Blue", 13);
1212 void() tdm_delayedinit =
1214 self.think = SUB_Remove;
1215 self.nextthink = time;
1216 // if no teams are found, spawn defaults
1217 if (find(world, classname, "tdm_team") == world)
1225 e.think = tdm_delayedinit;
1226 e.nextthink = time + 0.1;