1 float GAME_DEATHMATCH = 1;
2 float GAME_TEAM_DEATHMATCH = 2;
3 float GAME_DOMINATION = 3;
5 float GAME_RUNEMATCH = 5;
9 // client counts for each team
11 // # of bots on those teams
12 float cb1, cb2, cb3, cb4;
14 float g_domination, g_ctf, g_tdm;
16 float audit_teams_time;
18 float() IsTeamBalanceForced = {
19 if(cvar("g_campaign"))
21 if(!cvar("g_balance_teams_force"))
28 void TeamchangeFrags(entity e)
30 if(e.classname == "player")
32 // reduce frags during a team change
33 DistributeFragsAmongTeam(e, (e.clientcolors & 0x0F) + 1, 1 - cvar("g_changeteam_fragtransfer") / 100);
37 string TeamName(float t)
39 // fixme: Search for team entities and get their .netname's!
48 return "Neutral Team";
50 string ColoredTeamName(float t)
52 // fixme: Search for team entities and get their .netname's!
54 return "^1Red Team^7";
56 return "^4Blue Team^7";
58 return "^6Pink Team^7";
60 return "^3Yellow Team^7";
61 return "Neutral Team";
63 string TeamNoName(float t)
65 // fixme: Search for team entities and get their .netname's!
74 return "Neutral Team";
79 void runematch_init();
82 void(entity pl) LogTeamchange =
85 if(!cvar("sv_eventlog"))
89 str = strcat(":team:", ftos(pl.playerid), ":");
90 str = strcat(str, ftos(pl.team));
91 GameLogEcho(str, FALSE);
96 cvar_set("g_tdm", "0");
97 cvar_set("g_domination", "0");
98 cvar_set("g_ctf", "0");
99 cvar_set("g_runematch", "0");
100 cvar_set("g_lms", "0");
101 cvar_set("g_arena", "0");
102 cvar_set("teamplay", "0");
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, padding;
312 /*if(self.welcomemessage_time > time)
314 self.welcomemessage_time = time + 0.8; */
316 if(self.cvar_scr_centertime == 0) return;
317 if(self.welcomemessage_time > time) return;
318 self.welcomemessage_time = time + self.cvar_scr_centertime * 0.6;
320 if(cvar("g_campaign"))
322 centerprint(pl, campaign_message);
326 if(self.classname == "observer")
328 if(cvar("g_lms") && self.frags <= 0 && self.frags > -666)
329 return centerprint(self, strcat(newlines, "^1You have no more lives left\nwait for next round\n\n\n^7press attack to spectate other players"));
330 else if(cvar("g_lms") && self.frags == -666)
331 return centerprint(self, strcat(newlines, "^1Match has already begun\nwait for next round\n\n\n^7press attack to spectate other players"));
333 else if(self.classname == "spectator")
335 if ((cvar("g_lms") && self.frags < 1) || cvar("g_arena"))
336 return centerprint(self, strcat(newlines, "spectating ", self.enemy.netname, "\n\n\n^7press attack for next player\npress attack2 for free fly mode"));
338 return centerprint(self, 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"));
342 if(cvar("g_minstagib"))
343 mutator = "^2Minstagib ^1";
344 else if(cvar("g_instagib"))
345 mutator = "^2Instagib ^1";
346 else if(cvar("g_rocketarena"))
347 mutator = "^2Rocketarena ^1";
348 else if(cvar("g_nixnex"))
349 mutator = "^2No Items Nexuiz ^1";
351 if(cvar("g_midair")) {
352 // to protect against unheedingly made changes
354 modifications = strcat(modifications, ", ");
356 modifications = "midair";
358 if(cvar("g_vampire")) {
360 modifications = strcat(modifications, ", ");
362 modifications = strcat(modifications, "vampire");
364 if(cvar("g_laserguided_missile")) {
366 modifications = strcat(modifications, ", ");
368 modifications = strcat(modifications, "laser-guided-missiles");
371 local string versionmessage;
372 versionmessage = GetClientVersionMessage(self.version);
374 s = strcat(s, newlines, "This is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
375 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
377 if(modifications != "")
378 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
380 if((self.classname == "observer" || self.classname == "spectator") && self.version == cvar("gameversion")) {
382 s = strcat(s,"^7\n\n\npress jump to play\npress attack to spectate other players\n\n");
383 else if(player_count < 2 && arena_roundbased)
385 s = strcat(s, "\n\n\n^1waiting for second player to start match^7\n\n");
389 s = strcat(s, "\n\n\n");
391 s = strcat(s, "^7current champion is: ", champion.netname, "\n\n");
392 s = strcat(s,"^7press attack to spectate other players\n\n");
399 if (cvar("g_grappling_hook"))
400 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
402 if (cvar_string("_mutatormsg") != "") {
403 s = strcat(s, "\n\n^8special gameplay tips: ^7", cvar_string("_mutatormsg"));
406 if (cvar_string("_motd") != "") {
407 s = strcat(s, "\n\n^8MOTD: ^7", cvar_string("_motd"));
411 if(cvar("fraglimit"))
414 if(cvar("timelimit"))
417 s = strcat(s, "\n^8frag limit: ^7", cvar_string("fraglimit"), padding);
419 if(cvar("timelimit"))
420 s = strcat(s, "\n^8time limit: ^7", cvar_string("timelimit"), " minutes");
431 void SetPlayerColors(entity pl, float _color)
435 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
437 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
438 pl.clientcolors = 16*cl + cl;*/
441 pants = _color & 0x0F;
442 shirt = _color & 0xF0;
446 setcolor(pl, 16*pants + pants);
448 setcolor(pl, shirt + pants);
452 void SetPlayerTeam(entity pl, float t, float s, float noprint)
457 _color = COLOR_TEAM4 - 1;
459 _color = COLOR_TEAM3 - 1;
461 _color = COLOR_TEAM2 - 1;
463 _color = COLOR_TEAM1 - 1;
465 SetPlayerColors(pl,_color);
467 if(!noprint && t != s)
469 //bprint(strcat(pl.netname, " has changed to ", TeamNoName(t), "\n"));
470 bprint(strcat(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"));
482 // set c1...c4 to show what teams are allowed
483 void CheckAllowedTeams ()
492 c1 = c2 = c3 = c4 = -1;
493 cb1 = cb2 = cb3 = cb4 = 0;
496 teament_name = "dom_team";
498 teament_name = "ctf_team";
500 teament_name = "tdm_team";
503 // cover anything else by treating it like tdm with no teams spawned
504 dm = cvar("g_tdm_teams");
506 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
510 c1 = c2 = c3 = c4 = 0;
523 // first find out what teams are allowed
524 head = find(world, classname, teament_name);
527 if(!(g_domination && head.netname == ""))
529 if(head.team == COLOR_TEAM1)
533 if(head.team == COLOR_TEAM2)
537 if(head.team == COLOR_TEAM3)
541 if(head.team == COLOR_TEAM4)
546 head = find(head, classname, teament_name);
550 float PlayerValue(entity p)
552 if(IsTeamBalanceForced())
557 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
558 // teams that are allowed will now have their player counts stored in c1...c4
559 void GetTeamCounts(entity ignore)
563 // now count how many players are on each team already
565 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
566 // also remember the lowest-scoring player
568 head = find(world, classname, "player");
571 if(head != ignore)// && head.netname != "")
573 value = PlayerValue(head);
574 if(head.team == COLOR_TEAM1)
582 if(head.team == COLOR_TEAM2)
590 if(head.team == COLOR_TEAM3)
598 if(head.team == COLOR_TEAM4)
607 head = find(head, classname, "player");
611 // returns # of smallest team (1, 2, 3, 4)
612 // NOTE: Assumes CheckAllowedTeams has already been called!
613 float FindSmallestTeam(entity pl, float ignore_pl)
615 float totalteams, smallestteam, smallestteam_count, smallestteam_score, balance_type;
618 // find out what teams are available
619 //CheckAllowedTeams();
621 // make sure there are at least 2 teams to join
623 totalteams = totalteams + 1;
625 totalteams = totalteams + 1;
627 totalteams = totalteams + 1;
629 totalteams = totalteams + 1;
634 error("Too few teams available for domination\n");
636 error("Too few teams available for ctf\n");
638 error("Too few teams available for team deathmatch\n");
642 // count how many players are in each team
646 GetTeamCounts(world);
648 // c1...c4 now have counts of each team
649 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
652 smallestteam_count = 999999999;
653 smallestteam_score = 999999999;
655 // 2 gives priority to what team you're already on, 1 goes in order
656 // 2 doesn't seem to work though...
659 if(balance_type == 1)
661 if(c1 >= 0 && (c1 < smallestteam_count || (c1 <= smallestteam_count && team1_score < smallestteam_score)))
664 smallestteam_count = c1;
665 smallestteam_score = team1_score;
667 if(c2 >= 0 && (c2 < smallestteam_count || (c2 <= smallestteam_count && team2_score < smallestteam_score)))
670 smallestteam_count = c2;
671 smallestteam_score = team2_score;
673 if(c3 >= 0 && (c3 < smallestteam_count || (c3 <= smallestteam_count && team3_score < smallestteam_score)))
676 smallestteam_count = c3;
677 smallestteam_score = team3_score;
679 if(c4 >= 0 && (c4 < smallestteam_count || (c4 <= smallestteam_count && team4_score < smallestteam_score)))
682 smallestteam_count = c4;
683 smallestteam_score = team4_score;
688 if(c1 >= 0 && (c1 < smallestteam_count ||
689 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
692 smallestteam_count = c1;
694 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
695 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
698 smallestteam_count = c2;
700 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
701 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
704 smallestteam_count = c3;
706 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
707 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
710 smallestteam_count = c4;
717 float JoinBestTeam(entity pl, float only_return_best)
719 float smallest, selectedteam;
721 // don't join a team if we're not playing a team game
722 if(!cvar("teamplay") && !g_domination && !g_ctf)
725 // find out what teams are available
728 if(cvar("g_domination"))
730 if(cvar("g_domination_default_teams") < 3)
732 if(cvar("g_domination_default_teams") < 4)
736 // if we don't care what team he ends up on, put him on whatever team he entered as.
737 // if he's not on a valid team, then let other code put him on the smallest team
738 if(!cvar("g_campaign") && !cvar("g_balance_teams") && !cvar("g_balance_teams_force"))
740 if( c1 >= 0 && pl.team == COLOR_TEAM1)
741 selectedteam = pl.team;
742 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
743 selectedteam = pl.team;
744 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
745 selectedteam = pl.team;
746 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
747 selectedteam = pl.team;
752 if(!only_return_best)
754 SetPlayerColors(pl, selectedteam - 1);
759 // otherwise end up on the smallest team (handled below)
762 smallest = FindSmallestTeam(pl, TRUE);
765 if(!only_return_best)
767 TeamchangeFrags(self);
770 SetPlayerColors(pl, COLOR_TEAM1 - 1);
772 else if(smallest == 2)
774 SetPlayerColors(pl, COLOR_TEAM2 - 1);
776 else if(smallest == 3)
778 SetPlayerColors(pl, COLOR_TEAM3 - 1);
780 else if(smallest == 4)
782 SetPlayerColors(pl, COLOR_TEAM4 - 1);
786 error("smallest team: invalid team\n");
789 if(pl.deadflag == DEAD_NO)
790 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
797 void SV_ChangeTeam(float _color)
799 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
801 // in normal deathmatch we can just apply the color and we're done
802 if(!cvar("teamplay")) {
803 SetPlayerColors(self, _color);
807 scolor = self.clientcolors & 0x0F;
808 dcolor = _color & 0x0F;
810 if(scolor == COLOR_TEAM1 - 1)
812 else if(scolor == COLOR_TEAM2 - 1)
814 else if(scolor == COLOR_TEAM3 - 1)
816 else if(scolor == COLOR_TEAM4 - 1)
818 if(dcolor == COLOR_TEAM1 - 1)
820 else if(dcolor == COLOR_TEAM2 - 1)
822 else if(dcolor == COLOR_TEAM3 - 1)
824 else if(dcolor == COLOR_TEAM4 - 1)
827 // remap invalid teams in dom & ctf
829 if(cvar("g_ctf") && dteam == 3)
831 else if(cvar("g_ctf") && dteam == 4)
833 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 3) || (cvar("g_tdm") && cvar("g_tdm_teams") < 3))
840 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 4) || (cvar("g_tdm") && cvar("g_tdm_teams") < 4))
848 if(dteam == 3 && c3 < 0)
850 if(dteam == 4 && c4 < 0)
853 // not changing teams
856 //bprint("same team change\n");
857 SetPlayerTeam(self, dteam, steam, TRUE);
863 if(cvar("g_campaign") || cvar("g_changeteam_banned"))
865 sprint(self, "Team changes not allowed\n");
866 return; // changing teams is not allowed
869 if(!cvar("g_campaign") && cvar("g_balance_teams_prevent_imbalance"))
871 // only allow changing to a smaller or equal size team
873 // find out what teams are available
875 // count how many players on each team
876 GetTeamCounts(world);
879 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
884 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
889 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
894 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
901 sprint(self, "Cannot change to an invalid team\n");
907 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
909 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
911 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
913 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
916 if(scount) // started at a valid, nonempty team
918 // check if we're trying to change to a larger team that doens't have bots to swap with
919 if(dcount >= scount && dbotcount <= 0)
921 sprint(self, "Cannot change to a larger team\n");
922 return; // can't change to a larger team
928 // bprint(strcat("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"));
930 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
932 // reduce frags during a team change
933 TeamchangeFrags(self);
936 SetPlayerTeam(self, dteam, steam, FALSE);
938 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
940 // kill player when changing teams
941 if(self.deadflag == DEAD_NO)
942 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
946 void ShufflePlayerOutOfTeam (float source_team)
948 float smallestteam, smallestteam_count, steam;
949 float lowest_bot_score, lowest_player_score;
950 entity head, lowest_bot, lowest_player, selected;
954 smallestteam_count = 999999999;
956 if(c1 >= 0 && c1 < smallestteam_count)
959 smallestteam_count = c1;
961 if(c2 >= 0 && c2 < smallestteam_count)
964 smallestteam_count = c2;
966 if(c3 >= 0 && c3 < smallestteam_count)
969 smallestteam_count = c3;
971 if(c4 >= 0 && c4 < smallestteam_count)
974 smallestteam_count = c4;
979 bprint("warning: no smallest team\n");
985 else if(source_team == 2)
987 else if(source_team == 3)
989 else if(source_team == 4)
993 lowest_bot_score = 999999999;
994 lowest_player = world;
995 lowest_player_score = 999999999;
997 // find the lowest-scoring player & bot of that team
998 head = find(world, classname, "player");
1001 if(head.team == steam)
1005 if(head.frags < lowest_bot_score)
1008 lowest_bot_score = head.frags;
1013 if(head.frags < lowest_player_score)
1015 lowest_player = head;
1016 lowest_player_score = head.frags;
1020 head = find(head, classname, "player");
1023 // prefers to move a bot...
1024 if(lowest_bot != world)
1025 selected = lowest_bot;
1026 // but it will move a player if it has to
1028 selected = lowest_player;
1029 // don't do anything if it couldn't find anyone
1032 bprint("warning: couldn't find a player to move from team\n");
1036 // smallest team gains a member
1037 if(smallestteam == 1)
1041 else if(smallestteam == 2)
1045 else if(smallestteam == 3)
1049 else if(smallestteam == 4)
1055 bprint("warning: destination team invalid\n");
1058 // source team loses a member
1059 if(source_team == 1)
1063 else if(source_team == 2)
1067 else if(source_team == 3)
1071 else if(source_team == 4)
1077 bprint("warning: source team invalid\n");
1081 // move the player to the new team
1082 TeamchangeFrags(selected);
1083 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
1085 if(selected.deadflag == DEAD_NO)
1086 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
1087 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
1088 if (selected.team == 5)
1089 m = strcat(m, "^1Red Team");
1090 else if (selected.team == 14)
1091 m = strcat(m, "^4Blue Team");
1092 else if (selected.team == 10)
1093 m = strcat(m, "^6Pink Team");
1094 else if (selected.team == 13)
1095 m = strcat(m, "^3Yellow Team");
1096 centerprint(selected, m);
1099 // part of g_balance_teams_force
1100 // occasionally perform an audit of the teams to make
1101 // sure they're more or less balanced in player count.
1104 float numplayers, numteams, average;
1105 if(!IsTeamBalanceForced())
1108 if(audit_teams_time > time)
1111 audit_teams_time = time + 4 + random();
1113 // bprint("Auditing teams\n");
1115 CheckAllowedTeams();
1116 GetTeamCounts(world);
1119 numteams = numplayers = 0;
1122 numteams = numteams + 1;
1123 numplayers = numplayers + c1;
1127 numteams = numteams + 1;
1128 numplayers = numplayers + c2;
1132 numteams = numteams + 1;
1133 numplayers = numplayers + c3;
1137 numteams = numteams + 1;
1138 numplayers = numplayers + c4;
1142 return; // no players to move around
1144 return; // don't bother shuffling if for some reason there aren't any teams
1146 average = (numplayers / numteams) + 1;
1149 return; // that's weird...
1151 if(c1 && c1 > average)
1153 bprint("Rebalancing Teams\n");
1154 //bprint("Shuffle from team 1\n");
1155 ShufflePlayerOutOfTeam(1);
1157 if(c2 && c2 > average)
1159 bprint("Rebalancing Teams\n");
1160 //bprint("Shuffle from team 2\n");
1161 ShufflePlayerOutOfTeam(2);
1163 if(c3 && c3 > average)
1165 bprint("Rebalancing Teams\n");
1166 //bprint("Shuffle from team 3\n");
1167 ShufflePlayerOutOfTeam(3);
1169 if(c4 && c4 > average)
1171 bprint("Rebalancing Teams\n");
1172 //bprint("Shuffle from team 4\n");
1173 ShufflePlayerOutOfTeam(4);
1176 // if teams are still unbalanced, balance them further in the next audit,
1177 // which will happen sooner (keep doing rapid audits until things are in order)
1178 audit_teams_time = time + 0.7 + random()*0.3;
1183 /*void(entity e, float first) UpdateTeamScore =
1188 WriteByte (MSG_ALL, SVC_UPDATENAME);
1189 WriteByte (MSG_ALL, clientno);
1190 WriteString (MSG_ALL, e.netname);
1192 WriteByte (MSG_ALL, SVC_UPDATECOLORS);
1193 WriteByte (MSG_ALL, clientno);
1194 WriteByte (MSG_ALL, e.b_shirt * 16 + who.b_pants);
1197 WriteByte (MSG_ALL, SVC_UPDATEFRAGS);
1198 WriteByte (MSG_ALL, clientno);
1199 WriteShort (MSG_ALL, e.frags + 10000);
1205 // code from here on is just to support maps that don't have team entities
1206 void tdm_spawnteam (string teamname, float teamcolor)
1210 e.classname = "tdm_team";
1211 e.netname = teamname;
1216 // spawn some default teams if the map is not set up for tdm
1217 void() tdm_spawnteams =
1221 numteams = cvar("g_tdm_teams");
1223 tdm_spawnteam("Red", 4);
1224 tdm_spawnteam("Blue", 13);
1227 void() tdm_delayedinit =
1229 self.think = SUB_Remove;
1230 self.nextthink = time;
1231 // if no teams are found, spawn defaults
1232 if (find(world, classname, "tdm_team") == world)
1240 e.think = tdm_delayedinit;
1241 e.nextthink = time + 0.1;