// File: lotuskip[P]yuxtapa/server/cmds.cpp
// Function: shuffle_teams()
void shuffle_teams()
{
	// Gather the players who are currently playing, and kill them all:
	list<list<Player>::iterator> playing_players;
	list<Player>::iterator it;
	for(it = cur_players.begin(); it != cur_players.end(); ++it)
	{
		if(it->team != T_SPEC)
		{
			it->own_vp->move_watchers();
			if(!intermission)
			{
				Game::del_owneds(it);
				if(it->is_alive())
					kill_player(it);
				it->own_vp->clear_memory();
			}
			playing_players.push_back(it);
		}
	}

	playing_players.sort(pl_level_cmp);

	char ch, num;
	e_Team t;
	num_players[T_GREEN] = num_players[T_PURPLE] = 0;
	while(!playing_players.empty())
	{
		if(playing_players.size() == 1)
		{
			++num_players[(playing_players.front()->team = e_Team(random()%2))];
			break; // done
		}
		// else
		if(playing_players.size() == 2)
			num = 1;
		else
			num = 1 + random()%2; // 1 or 2
		t = e_Team(random()%2);
		for(ch = 0; ch < num; ++ch)
		{
			playing_players.front()->team = t;
			++num_players[t];
			playing_players.pop_front();
		}
		t = (t == T_GREEN) ? T_PURPLE : T_GREEN;
		for(ch = 0; ch < num; ++ch)
		{
			playing_players.front()->team = t;
			++num_players[t];
			playing_players.pop_front();
			// This can happen if there's an odd number of players:
			if(playing_players.empty())
				break;
		}
	} // while playing_players not empty
	
	Network::to_chat("The teams have been shuffled!");
	Game::construct_team_msgs(cur_players.end());
	Game::send_team_upds(cur_players.end());
	for(it = cur_players.begin(); it != cur_players.end(); ++it)
		Game::send_state_change(it);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
leaq -0x18(%rbp), %rdi
callq 0x5d950
leaq -0x20(%rbp), %rdi
callq 0x1b010
leaq 0x335bc(%rip), %rdi     # 0x90230
callq 0x1b360
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0x335a4(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b100
testb $0x1, %al
jne 0x5ccab
jmp 0x5cd81
leaq -0x20(%rbp), %rdi
callq 0x1b050
cmpl $0x2, 0xac(%rax)
je 0x5cd71
leaq -0x20(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rdi
callq 0x42870
jmp 0x5ccd8
leaq 0x30851(%rip), %rax     # 0x8d530
testb $0x1, (%rax)
jne 0x5cd60
leaq -0x48(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x18a20
movq -0x48(%rbp), %rdi
callq 0x3c230
jmp 0x5ccfc
leaq -0x20(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21cd0
movb %al, -0xb9(%rbp)
jmp 0x5cd15
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0x5cd21
jmp 0x5cd47
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x546a0
jmp 0x5cd34
jmp 0x5cd47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5d0b8
leaq -0x20(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rdi
callq 0x40f20
jmp 0x5cd5e
jmp 0x5cd60
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x5d970
jmp 0x5cd6f
jmp 0x5cd71
jmp 0x5cd73
leaq -0x20(%rbp), %rdi
callq 0x1b3c0
jmp 0x5cc85
leaq 0x648(%rip), %rsi       # 0x5d3d0
leaq -0x18(%rbp), %rdi
callq 0x5d9b0
jmp 0x5cd93
leaq 0x345f7(%rip), %rax     # 0x91391
movb $0x0, 0x1(%rax)
leaq 0x345ec(%rip), %rax     # 0x91391
movb $0x0, (%rax)
leaq -0x18(%rbp), %rdi
callq 0x5ddc0
xorb $-0x1, %al
testb $0x1, %al
jne 0x5cdbc
jmp 0x5cf58
leaq -0x18(%rbp), %rdi
callq 0x5dde0
cmpq $0x1, %rax
jne 0x5ce22
callq 0x5270
movl $0x2, %ecx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0xc0(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5de10
movq %rax, %rdi
callq 0x1b050
movq %rax, %rcx
movl -0xc0(%rbp), %eax
movl %eax, 0xac(%rcx)
movl %eax, %eax
movl %eax, %ecx
leaq 0x34584(%rip), %rax     # 0x91391
movb (%rax,%rcx), %dl
addb $0x1, %dl
leaq 0x34577(%rip), %rax     # 0x91391
movb %dl, (%rax,%rcx)
jmp 0x5cf58
leaq -0x18(%rbp), %rdi
callq 0x5dde0
cmpq $0x2, %rax
jne 0x5ce37
movb $0x1, -0x52(%rbp)
jmp 0x5ce4f
callq 0x5270
movl $0x2, %ecx
cqto
idivq %rcx
addq $0x1, %rdx
movb %dl, %al
movb %al, -0x52(%rbp)
callq 0x5270
movl $0x2, %ecx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x58(%rbp)
movb $0x0, -0x51(%rbp)
movsbl -0x51(%rbp), %eax
movsbl -0x52(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5cec8
movl -0x58(%rbp), %eax
movl %eax, -0xc4(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5de10
movq %rax, %rdi
callq 0x1b050
movl -0xc4(%rbp), %ecx
movl %ecx, 0xac(%rax)
movl -0x58(%rbp), %eax
movl %eax, %ecx
leaq 0x344ec(%rip), %rax     # 0x91391
movb (%rax,%rcx), %dl
addb $0x1, %dl
leaq 0x344df(%rip), %rax     # 0x91391
movb %dl, (%rax,%rcx)
leaq -0x18(%rbp), %rdi
callq 0x5de40
movb -0x51(%rbp), %al
addb $0x1, %al
movb %al, -0x51(%rbp)
jmp 0x5ce67
movl -0x58(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x58(%rbp)
movb $0x0, -0x51(%rbp)
movsbl -0x51(%rbp), %eax
movsbl -0x52(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5cf53
movl -0x58(%rbp), %eax
movl %eax, -0xc8(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x5de10
movq %rax, %rdi
callq 0x1b050
movl -0xc8(%rbp), %ecx
movl %ecx, 0xac(%rax)
movl -0x58(%rbp), %eax
movl %eax, %ecx
leaq 0x34474(%rip), %rax     # 0x91391
movb (%rax,%rcx), %dl
addb $0x1, %dl
leaq 0x34467(%rip), %rax     # 0x91391
movb %dl, (%rax,%rcx)
leaq -0x18(%rbp), %rdi
callq 0x5de40
leaq -0x18(%rbp), %rdi
callq 0x5ddc0
testb $0x1, %al
jne 0x5cf45
jmp 0x5cf47
jmp 0x5cf53
jmp 0x5cf49
movb -0x51(%rbp), %al
addb $0x1, %al
movb %al, -0x51(%rbp)
jmp 0x5cedf
jmp 0x5cda8
leaq -0x79(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x5930
movq -0xd0(%rbp), %rdx
leaq 0xfa8e(%rip), %rsi      # 0x6ca04
leaq -0x78(%rbp), %rdi
callq 0x18880
jmp 0x5cf81
leaq -0x78(%rbp), %rdi
callq 0x1acd0
jmp 0x5cf8c
leaq -0x78(%rbp), %rdi
callq 0x5a48
leaq -0x79(%rbp), %rdi
callq 0x5590
leaq 0x3328b(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x18a20
movq -0x88(%rbp), %rdi
callq 0x367a0
jmp 0x5cfd2
leaq 0x33257(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x18a20
movq -0x98(%rbp), %rdi
callq 0x36ce0
jmp 0x5d006
leaq 0x33223(%rip), %rdi     # 0x90230
callq 0x1b360
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0x33205(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0xb0(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1b100
testb $0x1, %al
jne 0x5d04d
jmp 0x5d0a6
leaq -0xb8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x18a20
movq -0xb8(%rbp), %rdi
callq 0x3b290
jmp 0x5d06b
jmp 0x5d06d
leaq -0x20(%rbp), %rdi
callq 0x1b3c0
jmp 0x5d024
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5d09b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5a48
leaq -0x79(%rbp), %rdi
callq 0x5590
jmp 0x5d0b8
leaq -0x18(%rbp), %rdi
callq 0x5de70
addq $0xd0, %rsp
popq %rbp
retq
leaq -0x18(%rbp), %rdi
callq 0x5de70
movq -0x38(%rbp), %rdi
callq 0x5920
nopw (%rax,%rax)