6 #include "scores_rules.qh"
10 #include "command/vote.qh"
12 #include "mutators/_mod.qh"
14 #include "../common/deathtypes/all.qh"
15 #include "../common/gamemodes/_mod.qh"
16 #include "../common/teams.qh"
18 void TeamchangeFrags(entity e)
23 void LogTeamchange(float player_id, float team_number, float type)
25 if(!autocvar_sv_eventlog)
31 GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
34 void default_delayedinit(entity this)
36 if(!scores_initialized)
40 void ActivateTeamplay()
42 serverflags |= SERVERFLAG_TEAMPLAY;
44 cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies.
47 void InitGameplayMode()
51 // find out good world mins/maxs bounds, either the static bounds found by looking for solid, or the mapinfo specified bounds
55 // currently, NetRadiant's limit is 131072 qu for each side
56 // distance from one corner of a 131072qu cube to the opposite corner is approx. 227023 qu
57 // set the distance according to map size but don't go over the limit to avoid issues with float precision
58 // in case somebody makes extremely large maps
59 max_shot_distance = min(230000, vlen(world.maxs - world.mins));
61 MapInfo_LoadMapSettings(mapname);
62 serverflags &= ~SERVERFLAG_TEAMPLAY;
64 cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies.
66 if (!cvar_value_issafe(world.fog))
68 LOG_INFO("The current map contains a potentially harmful fog setting, ignored\n");
69 world.fog = string_null;
71 if(MapInfo_Map_fog != "")
72 if(MapInfo_Map_fog == "none")
73 world.fog = string_null;
75 world.fog = strzone(MapInfo_Map_fog);
76 clientstuff = strzone(MapInfo_Map_clientstuff);
80 gamemode_name = MapInfo_Type_ToText(MapInfo_LoadedGametype);
82 cache_mutatormsg = strzone("");
83 cache_lastmutatormsg = strzone("");
85 InitializeEntity(NULL, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK);
88 string GetClientVersionMessage(entity this)
90 if (CS(this).version_mismatch) {
91 if(CS(this).version < autocvar_gameversion) {
92 return strcat("This is Xonotic ", autocvar_g_xonoticversion,
93 "\n^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8");
95 return strcat("This is Xonotic ", autocvar_g_xonoticversion,
96 "\n^3This server is using an outdated Xonotic version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8");
99 return strcat("Welcome to Xonotic ", autocvar_g_xonoticversion);
103 string getwelcomemessage(entity this)
105 MUTATOR_CALLHOOK(BuildMutatorsPrettyString, "");
106 string modifications = M_ARGV(0, string);
110 if(g_weaponarena_random)
111 modifications = strcat(modifications, ", ", ftos(g_weaponarena_random), " of ", g_weaponarena_list, " Arena");
113 modifications = strcat(modifications, ", ", g_weaponarena_list, " Arena");
115 else if(cvar("g_balance_blaster_weaponstartoverride") == 0)
116 modifications = strcat(modifications, ", No start weapons");
117 if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity")))
118 modifications = strcat(modifications, ", Low gravity");
119 if(g_weapon_stay && !g_cts)
120 modifications = strcat(modifications, ", Weapons stay");
122 modifications = strcat(modifications, ", Jet pack");
123 if(autocvar_g_powerups == 0)
124 modifications = strcat(modifications, ", No powerups");
125 if(autocvar_g_powerups > 0)
126 modifications = strcat(modifications, ", Powerups");
127 modifications = substring(modifications, 2, strlen(modifications) - 2);
129 string versionmessage = GetClientVersionMessage(this);
130 string s = strcat(versionmessage, "^8\n^8\nmatch type is ^1", gamemode_name, "^8\n");
132 if(modifications != "")
133 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
135 if(cache_lastmutatormsg != autocvar_g_mutatormsg)
137 if(cache_lastmutatormsg)
138 strunzone(cache_lastmutatormsg);
140 strunzone(cache_mutatormsg);
141 cache_lastmutatormsg = strzone(autocvar_g_mutatormsg);
142 cache_mutatormsg = strzone(cache_lastmutatormsg);
145 if (cache_mutatormsg != "") {
146 s = strcat(s, "\n\n^8special gameplay tips: ^7", cache_mutatormsg);
149 string mutator_msg = "";
150 MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg);
151 mutator_msg = M_ARGV(0, string);
153 s = strcat(s, mutator_msg); // trust that the mutator will do proper formatting
155 string motd = autocvar_sv_motd;
157 s = strcat(s, "\n\n^8MOTD: ^7", strreplace("\\n", "\n", motd));
162 void setcolor(entity this, int clr)
165 this.clientcolors = clr;
166 this.team = (clr & 15) + 1;
168 builtin_setcolor(this, clr);
172 void SetPlayerColors(entity player, float _color)
174 float pants = _color & 0x0F;
175 float shirt = _color & 0xF0;
178 setcolor(player, 16 * pants + pants);
182 setcolor(player, shirt + pants);
186 bool SetPlayerTeamSimple(entity player, int teamnum)
188 if (player.team == teamnum)
190 // This is important when players join the game and one of their color
191 // matches the team color while other doesn't. For example [BOT]Lion.
192 SetPlayerColors(player, teamnum - 1);
195 if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, Team_TeamToNumber(
196 player.team), Team_TeamToNumber(teamnum)) == true)
198 // Mutator has blocked team change.
201 int oldteam = player.team;
202 SetPlayerColors(player, teamnum - 1);
203 MUTATOR_CALLHOOK(Player_ChangedTeam, player, oldteam, player.team);
207 bool SetPlayerTeam(entity player, int destinationteam, int sourceteam, bool noprint)
209 int teamnum = Team_NumberToTeam(destinationteam);
210 if (!SetPlayerTeamSimple(player, teamnum))
214 LogTeamchange(player.playerid, player.team, 3); // log manual team join
219 bprint(playername(player, false), "^7 has changed from ", Team_NumberToColoredFullName(sourceteam), "^7 to ", Team_NumberToColoredFullName(destinationteam), "\n");
223 // set c1...c4 to show what teams are allowed
224 void CheckAllowedTeams (entity for_whom)
228 c1 = c2 = c3 = c4 = -1;
229 numbotsteam1 = numbotsteam2 = numbotsteam3 = numbotsteam4 = 0;
231 string teament_name = string_null;
233 bool mutator_returnvalue = MUTATOR_CALLHOOK(CheckAllowedTeams, teams_mask, teament_name, for_whom);
234 teams_mask = M_ARGV(0, float);
235 teament_name = M_ARGV(1, string);
237 if(!mutator_returnvalue)
239 if(teams_mask & BIT(0)) c1 = 0;
240 if(teams_mask & BIT(1)) c2 = 0;
241 if(teams_mask & BIT(2)) c3 = 0;
242 if(teams_mask & BIT(3)) c4 = 0;
245 // find out what teams are allowed if necessary
248 entity head = find(NULL, classname, teament_name);
253 case NUM_TEAM_1: c1 = 0; break;
254 case NUM_TEAM_2: c2 = 0; break;
255 case NUM_TEAM_3: c3 = 0; break;
256 case NUM_TEAM_4: c4 = 0; break;
259 head = find(head, classname, teament_name);
263 // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
264 if(AvailableTeams() == 2)
265 if(autocvar_bot_vs_human && for_whom)
267 if(autocvar_bot_vs_human > 0)
269 // find last team available
271 if(IS_BOT_CLIENT(for_whom))
273 if(c4 >= 0) { c3 = c2 = c1 = -1; }
274 else if(c3 >= 0) { c4 = c2 = c1 = -1; }
275 else { c4 = c3 = c1 = -1; }
276 // no further cases, we know at least 2 teams exist
280 if(c1 >= 0) { c2 = c3 = c4 = -1; }
281 else if(c2 >= 0) { c1 = c3 = c4 = -1; }
282 else { c1 = c2 = c4 = -1; }
283 // no further cases, bots have one of the teams
288 // find first team available
290 if(IS_BOT_CLIENT(for_whom))
292 if(c1 >= 0) { c2 = c3 = c4 = -1; }
293 else if(c2 >= 0) { c1 = c3 = c4 = -1; }
294 else { c1 = c2 = c4 = -1; }
295 // no further cases, we know at least 2 teams exist
299 if(c4 >= 0) { c3 = c2 = c1 = -1; }
300 else if(c3 >= 0) { c4 = c2 = c1 = -1; }
301 else { c4 = c3 = c1 = -1; }
302 // no further cases, bots have one of the teams
310 // if player has a forced team, ONLY allow that one
311 if(for_whom.team_forced == NUM_TEAM_1 && c1 >= 0)
313 else if(for_whom.team_forced == NUM_TEAM_2 && c2 >= 0)
315 else if(for_whom.team_forced == NUM_TEAM_3 && c3 >= 0)
317 else if(for_whom.team_forced == NUM_TEAM_4 && c4 >= 0)
321 float PlayerValue(entity p)
324 // FIXME: it always returns 1...
327 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
328 // teams that are allowed will now have their player counts stored in c1...c4
329 void GetTeamCounts(entity ignore)
331 if (MUTATOR_CALLHOOK(GetTeamCounts) == true)
335 MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_1, ignore, c1, numbotsteam1,
336 lowesthumanteam1, lowestbotteam1);
337 c1 = M_ARGV(2, float);
338 numbotsteam1 = M_ARGV(3, float);
339 lowesthumanteam1 = M_ARGV(4, entity);
340 lowestbotteam1 = M_ARGV(5, entity);
344 MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_2, ignore, c2, numbotsteam2,
345 lowesthumanteam2, lowestbotteam2);
346 c2 = M_ARGV(2, float);
347 numbotsteam2 = M_ARGV(3, float);
348 lowesthumanteam2 = M_ARGV(4, entity);
349 lowestbotteam2 = M_ARGV(5, entity);
353 MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_3, ignore, c3, numbotsteam3,
354 lowesthumanteam3, lowestbotteam3);
355 c3 = M_ARGV(2, float);
356 numbotsteam3 = M_ARGV(3, float);
357 lowesthumanteam3 = M_ARGV(4, entity);
358 lowestbotteam3 = M_ARGV(5, entity);
362 MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_4, ignore, c4, numbotsteam4,
363 lowesthumanteam4, lowestbotteam4);
364 c4 = M_ARGV(2, float);
365 numbotsteam4 = M_ARGV(3, float);
366 lowesthumanteam4 = M_ARGV(4, entity);
367 lowestbotteam4 = M_ARGV(5, entity);
373 // now count how many players are on each team already
374 float lowesthumanscore1 = FLOAT_MAX;
375 float lowestbotscore1 = FLOAT_MAX;
376 float lowesthumanscore2 = FLOAT_MAX;
377 float lowestbotscore2 = FLOAT_MAX;
378 float lowesthumanscore3 = FLOAT_MAX;
379 float lowestbotscore3 = FLOAT_MAX;
380 float lowesthumanscore4 = FLOAT_MAX;
381 float lowestbotscore4 = FLOAT_MAX;
385 if (IS_PLAYER(it) || it.caplayer)
389 else if (it.team_forced > 0)
391 t = it.team_forced; // reserve the spot
401 value = PlayerValue(it);
402 if (IS_BOT_CLIENT(it))
423 numbotsteam1 += bvalue;
424 float tempscore = PlayerScore_Get(it, SP_SCORE);
427 if (tempscore < lowesthumanscore1)
429 lowesthumanteam1 = it;
430 lowesthumanscore1 = tempscore;
434 if (tempscore < lowestbotscore1)
437 lowestbotscore1 = tempscore;
448 numbotsteam2 += bvalue;
449 float tempscore = PlayerScore_Get(it, SP_SCORE);
452 if (tempscore < lowesthumanscore2)
454 lowesthumanteam2 = it;
455 lowesthumanscore2 = tempscore;
459 if (tempscore < lowestbotscore2)
462 lowestbotscore2 = tempscore;
473 numbotsteam3 += bvalue;
474 float tempscore = PlayerScore_Get(it, SP_SCORE);
477 if (tempscore < lowesthumanscore3)
479 lowesthumanteam3 = it;
480 lowesthumanscore3 = tempscore;
484 if (tempscore < lowestbotscore3)
487 lowestbotscore3 = tempscore;
498 numbotsteam4 += bvalue;
499 float tempscore = PlayerScore_Get(it, SP_SCORE);
502 if (tempscore < lowesthumanscore4)
504 lowesthumanteam4 = it;
505 lowesthumanscore4 = tempscore;
509 if (tempscore < lowestbotscore4)
512 lowestbotscore4 = tempscore;
520 // if the player who has a forced team has not joined yet, reserve the spot
521 if(autocvar_g_campaign)
523 switch(autocvar_g_campaign_forceteam)
525 case 1: if(c1 == numbotsteam1) ++c1; break;
526 case 2: if(c2 == numbotsteam2) ++c2; break;
527 case 3: if(c3 == numbotsteam3) ++c3; break;
528 case 4: if(c4 == numbotsteam4) ++c4; break;
533 bool IsTeamSmallerThanTeam(int teama, int teamb, entity e, bool usescore)
540 // we assume that CheckAllowedTeams and GetTeamCounts have already been called
541 float numplayersteama = -1, numplayersteamb = -1;
542 float numbotsteama = 0, numbotsteamb = 0;
543 float scoreteama = 0, scoreteamb = 0;
547 case 1: numplayersteama = c1; numbotsteama = numbotsteam1; scoreteama = team1_score; break;
548 case 2: numplayersteama = c2; numbotsteama = numbotsteam2; scoreteama = team2_score; break;
549 case 3: numplayersteama = c3; numbotsteama = numbotsteam3; scoreteama = team3_score; break;
550 case 4: numplayersteama = c4; numbotsteama = numbotsteam4; scoreteama = team4_score; break;
554 case 1: numplayersteamb = c1; numbotsteamb = numbotsteam1; scoreteamb = team1_score; break;
555 case 2: numplayersteamb = c2; numbotsteamb = numbotsteam2; scoreteamb = team2_score; break;
556 case 3: numplayersteamb = c3; numbotsteamb = numbotsteam3; scoreteamb = team3_score; break;
557 case 4: numplayersteamb = c4; numbotsteamb = numbotsteam4; scoreteamb = team4_score; break;
561 if (numplayersteama < 0 || numplayersteamb < 0)
564 if ((IS_REAL_CLIENT(e) && bots_would_leave))
566 numplayersteama -= numbotsteama;
567 numplayersteamb -= numbotsteamb;
571 return numplayersteama < numplayersteamb;
573 if (numplayersteama < numplayersteamb)
577 if (numplayersteama > numplayersteamb)
581 return scoreteama < scoreteamb;
584 bool IsTeamEqualToTeam(int teama, int teamb, entity e, bool usescore)
591 // we assume that CheckAllowedTeams and GetTeamCounts have already been called
592 float numplayersteama = -1, numplayersteamb = -1;
593 float numbotsteama = 0, numbotsteamb = 0;
594 float scoreteama = 0, scoreteamb = 0;
598 case 1: numplayersteama = c1; numbotsteama = numbotsteam1; scoreteama = team1_score; break;
599 case 2: numplayersteama = c2; numbotsteama = numbotsteam2; scoreteama = team2_score; break;
600 case 3: numplayersteama = c3; numbotsteama = numbotsteam3; scoreteama = team3_score; break;
601 case 4: numplayersteama = c4; numbotsteama = numbotsteam4; scoreteama = team4_score; break;
605 case 1: numplayersteamb = c1; numbotsteamb = numbotsteam1; scoreteamb = team1_score; break;
606 case 2: numplayersteamb = c2; numbotsteamb = numbotsteam2; scoreteamb = team2_score; break;
607 case 3: numplayersteamb = c3; numbotsteamb = numbotsteam3; scoreteamb = team3_score; break;
608 case 4: numplayersteamb = c4; numbotsteamb = numbotsteam4; scoreteamb = team4_score; break;
612 if (numplayersteama < 0 || numplayersteamb < 0)
615 if ((IS_REAL_CLIENT(e) && bots_would_leave))
617 numplayersteama -= numbotsteama;
618 numplayersteamb -= numbotsteamb;
622 return numplayersteama == numplayersteamb;
624 if (numplayersteama < numplayersteamb)
628 if (numplayersteama > numplayersteamb)
632 return scoreteama == scoreteamb;
635 int FindBestTeams(entity player, bool usescore)
637 if (MUTATOR_CALLHOOK(FindBestTeams, player) == true)
639 return M_ARGV(1, float);
642 int previousteam = 0;
650 if (previousteam == 0)
655 else if (IsTeamSmallerThanTeam(2, previousteam, player, usescore))
660 else if (IsTeamEqualToTeam(2, previousteam, player, usescore))
668 if (previousteam == 0)
673 else if (IsTeamSmallerThanTeam(3, previousteam, player, usescore))
678 else if (IsTeamEqualToTeam(3, previousteam, player, usescore))
686 if (previousteam == 0)
690 else if (IsTeamSmallerThanTeam(4, previousteam, player, usescore))
694 else if (IsTeamEqualToTeam(4, previousteam, player, usescore))
702 // returns # of smallest team (1, 2, 3, 4)
703 // NOTE: Assumes CheckAllowedTeams has already been called!
704 float FindSmallestTeam(entity player, float ignore_player)
706 // count how many players are in each team
709 GetTeamCounts(player);
715 int teambits = FindBestTeams(player, true);
718 error(sprintf("No teams available for %s\n", MapInfo_Type_ToString(MapInfo_CurrentGametype())));
720 RandomSelection_Init();
721 if ((teambits & BIT(0)) != 0)
723 RandomSelection_AddFloat(1, 1, 1);
725 if ((teambits & BIT(1)) != 0)
727 RandomSelection_AddFloat(2, 1, 1);
729 if ((teambits & BIT(2)) != 0)
731 RandomSelection_AddFloat(3, 1, 1);
733 if ((teambits & BIT(3)) != 0)
735 RandomSelection_AddFloat(4, 1, 1);
737 return RandomSelection_chosen_float;
740 int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
742 // don't join a team if we're not playing a team game
748 // find out what teams are available
749 CheckAllowedTeams(this);
753 // if we don't care what team he ends up on, put him on whatever team he entered as.
754 // if he's not on a valid team, then let other code put him on the smallest team
757 if( c1 >= 0 && this.team == NUM_TEAM_1)
758 selectedteam = this.team;
759 else if(c2 >= 0 && this.team == NUM_TEAM_2)
760 selectedteam = this.team;
761 else if(c3 >= 0 && this.team == NUM_TEAM_3)
762 selectedteam = this.team;
763 else if(c4 >= 0 && this.team == NUM_TEAM_4)
764 selectedteam = this.team;
768 if (selectedteam > 0)
770 if (!only_return_best)
772 SetPlayerTeamSimple(this, selectedteam);
774 // when JoinBestTeam is called by client.qc/ClientKill_Now_TeamChange the players team is -1 and thus skipped
775 // when JoinBestTeam is called by client.qc/ClientConnect the player_id is 0 the log attempt is rejected
776 LogTeamchange(this.playerid, this.team, 99);
780 // otherwise end up on the smallest team (handled below)
783 float bestteam = FindSmallestTeam(this, true);
784 if (only_return_best || this.bot_forced_team)
788 bestteam = Team_NumberToTeam(bestteam);
791 error("JoinBestTeam: invalid team\n");
793 int oldteam = Team_TeamToNumber(this.team);
794 TeamchangeFrags(this);
795 SetPlayerTeamSimple(this, bestteam);
796 LogTeamchange(this.playerid, this.team, 2); // log auto join
797 if (!IS_BOT_CLIENT(this))
799 AutoBalanceBots(oldteam, Team_TeamToNumber(bestteam));
801 if (!IS_DEAD(this) && (MUTATOR_CALLHOOK(Player_ChangeTeamKill, this) ==
804 Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
809 void SV_ChangeTeam(entity this, float _color)
811 float sourcecolor, destinationcolor, sourceteam, destinationteam;
813 // in normal deathmatch we can just apply the color and we're done
815 SetPlayerColors(this, _color);
819 // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
820 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CONNECTING, this.netname);
827 sourcecolor = this.clientcolors & 0x0F;
828 destinationcolor = _color & 0x0F;
830 sourceteam = Team_TeamToNumber(sourcecolor + 1);
831 destinationteam = Team_TeamToNumber(destinationcolor + 1);
833 CheckAllowedTeams(this);
835 if (destinationteam == 1 && c1 < 0) destinationteam = 4;
836 if (destinationteam == 4 && c4 < 0) destinationteam = 3;
837 if (destinationteam == 3 && c3 < 0) destinationteam = 2;
838 if (destinationteam == 2 && c2 < 0) destinationteam = 1;
840 // not changing teams
841 if (sourcecolor == destinationcolor)
843 SetPlayerTeam(this, destinationteam, sourceteam, true);
847 if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && CS(this).wasplayer)) {
848 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED);
849 return; // changing teams is not allowed
852 // autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless
853 if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
856 if ((BIT(destinationteam - 1) & FindBestTeams(this, false)) == 0)
858 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
862 if(IS_PLAYER(this) && sourceteam != destinationteam)
864 // reduce frags during a team change
865 TeamchangeFrags(this);
867 if (!SetPlayerTeam(this, destinationteam, sourceteam, !IS_CLIENT(this)))
871 AutoBalanceBots(sourceteam, destinationteam);
872 if (!IS_PLAYER(this) || (sourceteam == destinationteam))
876 // kill player when changing teams
877 if (IS_DEAD(this) || (MUTATOR_CALLHOOK(Player_ChangeTeamKill, this) == true))
881 Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
884 void AutoBalanceBots(int sourceteam, int destinationteam)
886 if ((sourceteam == -1) || (destinationteam == -1))
890 if (!autocvar_g_balance_teams ||
891 !autocvar_g_balance_teams_prevent_imbalance)
895 int numplayerssourceteam = 0;
896 int numplayersdestinationteam = 0;
897 entity lowestbotdestinationteam = NULL;
902 numplayerssourceteam = c1;
907 numplayerssourceteam = c2;
912 numplayerssourceteam = c3;
917 numplayerssourceteam = c4;
921 switch (destinationteam)
925 numplayersdestinationteam = c1;
926 lowestbotdestinationteam = lowestbotteam1;
931 numplayersdestinationteam = c2;
932 lowestbotdestinationteam = lowestbotteam2;
937 numplayersdestinationteam = c3;
938 lowestbotdestinationteam = lowestbotteam3;
943 numplayersdestinationteam = c4;
944 lowestbotdestinationteam = lowestbotteam4;
948 if ((numplayersdestinationteam <= numplayerssourceteam) ||
949 (lowestbotdestinationteam == NULL))
953 SetPlayerTeamSimple(lowestbotdestinationteam, Team_NumberToTeam(sourceteam));
954 if (IS_DEAD(lowestbotdestinationteam) || (MUTATOR_CALLHOOK(
955 Player_ChangeTeamKill, lowestbotdestinationteam) == true))
959 Damage(lowestbotdestinationteam, lowestbotdestinationteam,
960 lowestbotdestinationteam, 100000, DEATH_TEAMCHANGE.m_id,
961 lowestbotdestinationteam.origin, '0 0 0');
964 void ShufflePlayerOutOfTeam (float source_team)
966 float smallestteam, smallestteam_count, steam;
967 float lowest_bot_score, lowest_player_score;
968 entity lowest_bot, lowest_player, selected;
971 smallestteam_count = 999999999;
973 if(c1 >= 0 && c1 < smallestteam_count)
976 smallestteam_count = c1;
978 if(c2 >= 0 && c2 < smallestteam_count)
981 smallestteam_count = c2;
983 if(c3 >= 0 && c3 < smallestteam_count)
986 smallestteam_count = c3;
988 if(c4 >= 0 && c4 < smallestteam_count)
991 smallestteam_count = c4;
996 bprint("warning: no smallest team\n");
1000 if(source_team == 1)
1002 else if(source_team == 2)
1004 else if(source_team == 3)
1006 else // if(source_team == 4)
1010 lowest_bot_score = 999999999;
1011 lowest_player = NULL;
1012 lowest_player_score = 999999999;
1014 // find the lowest-scoring player & bot of that team
1015 FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, LAMBDA(
1018 if(it.totalfrags < lowest_bot_score)
1021 lowest_bot_score = it.totalfrags;
1026 if(it.totalfrags < lowest_player_score)
1029 lowest_player_score = it.totalfrags;
1034 // prefers to move a bot...
1035 if(lowest_bot != NULL)
1036 selected = lowest_bot;
1037 // but it will move a player if it has to
1039 selected = lowest_player;
1040 // don't do anything if it couldn't find anyone
1043 bprint("warning: couldn't find a player to move from team\n");
1047 // smallest team gains a member
1048 if(smallestteam == 1)
1052 else if(smallestteam == 2)
1056 else if(smallestteam == 3)
1060 else if(smallestteam == 4)
1066 bprint("warning: destination team invalid\n");
1069 // source team loses a member
1070 if(source_team == 1)
1074 else if(source_team == 2)
1078 else if(source_team == 3)
1082 else if(source_team == 4)
1088 bprint("warning: source team invalid\n");
1092 // move the player to the new team
1093 TeamchangeFrags(selected);
1094 if (!SetPlayerTeam(selected, smallestteam, source_team, false))
1098 if (IS_DEAD(selected) || MUTATOR_CALLHOOK(Player_ChangeTeamKill, selected) == true)
1102 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
1103 Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);