lowestbotdestinationteam, 100000, DEATH_TEAMCHANGE.m_id,
lowestbotdestinationteam.origin, '0 0 0');
}
-
-void ShufflePlayerOutOfTeam (float source_team)
-{
- float smallestteam, smallestteam_count, steam;
- float lowest_bot_score, lowest_player_score;
- entity lowest_bot, lowest_player, selected;
-
- smallestteam = 0;
- smallestteam_count = 999999999;
-
- if(c1 >= 0 && c1 < smallestteam_count)
- {
- smallestteam = 1;
- smallestteam_count = c1;
- }
- if(c2 >= 0 && c2 < smallestteam_count)
- {
- smallestteam = 2;
- smallestteam_count = c2;
- }
- if(c3 >= 0 && c3 < smallestteam_count)
- {
- smallestteam = 3;
- smallestteam_count = c3;
- }
- if(c4 >= 0 && c4 < smallestteam_count)
- {
- smallestteam = 4;
- smallestteam_count = c4;
- }
-
- if(!smallestteam)
- {
- bprint("warning: no smallest team\n");
- return;
- }
-
- if(source_team == 1)
- steam = NUM_TEAM_1;
- else if(source_team == 2)
- steam = NUM_TEAM_2;
- else if(source_team == 3)
- steam = NUM_TEAM_3;
- else // if(source_team == 4)
- steam = NUM_TEAM_4;
-
- lowest_bot = NULL;
- lowest_bot_score = 999999999;
- lowest_player = NULL;
- lowest_player_score = 999999999;
-
- // find the lowest-scoring player & bot of that team
- FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, LAMBDA(
- if(it.isbot)
- {
- if(it.totalfrags < lowest_bot_score)
- {
- lowest_bot = it;
- lowest_bot_score = it.totalfrags;
- }
- }
- else
- {
- if(it.totalfrags < lowest_player_score)
- {
- lowest_player = it;
- lowest_player_score = it.totalfrags;
- }
- }
- ));
-
- // prefers to move a bot...
- if(lowest_bot != NULL)
- selected = lowest_bot;
- // but it will move a player if it has to
- else
- selected = lowest_player;
- // don't do anything if it couldn't find anyone
- if(!selected)
- {
- bprint("warning: couldn't find a player to move from team\n");
- return;
- }
-
- // smallest team gains a member
- if(smallestteam == 1)
- {
- c1 = c1 + 1;
- }
- else if(smallestteam == 2)
- {
- c2 = c2 + 1;
- }
- else if(smallestteam == 3)
- {
- c3 = c3 + 1;
- }
- else if(smallestteam == 4)
- {
- c4 = c4 + 1;
- }
- else
- {
- bprint("warning: destination team invalid\n");
- return;
- }
- // source team loses a member
- if(source_team == 1)
- {
- c1 = c1 + 1;
- }
- else if(source_team == 2)
- {
- c2 = c2 + 2;
- }
- else if(source_team == 3)
- {
- c3 = c3 + 3;
- }
- else if(source_team == 4)
- {
- c4 = c4 + 4;
- }
- else
- {
- bprint("warning: source team invalid\n");
- return;
- }
-
- // move the player to the new team
- TeamchangeFrags(selected);
- if (!SetPlayerTeam(selected, smallestteam, source_team, false))
- {
- return;
- }
- if (IS_DEAD(selected) || MUTATOR_CALLHOOK(Player_ChangeTeamKill, selected) == true)
- {
- return;
- }
- Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
- Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);
-}