// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_vote.c
// Function: Check_Vote
void Check_Vote(void)  //called from p_client.c
{
	edict_t * player = NULL;
	unsigned int total_votes = 0;
	unsigned int num_yes = 0;
	unsigned int num_no  = 0;
	unsigned int num_abstained = 0;
	unsigned int remainder = 0;
	unsigned int vote_result = 0;
	unsigned int midpoint = 0;

	//gi.bprintf(PRINT_HIGH,"%f : %f\n", level.time, VoteTime+30);  //for debugging purposes
	if (level.time > (VoteTime + 30)) // if the 30 seconds are up then process the votes.
	{
		gi.bprintf(PRINT_HIGH,"Vote session has ended\n");
		VoteStarted = false;

		//go in and check the ent->client->ctf.extra_flags of each player and tabulate the votes
		player = ctf_findplayer(NULL, NULL, CTF_TEAM_IGNORETEAM);
		while (player)
		{
			//gi.bprintf(PRINT_HIGH, "processing: %s --", player->client->pers.netname); //for debugging
			//grab vote, if any
			if (player->client->ctf.extra_flags & CTF_EXTRAFLAGS_VOTE_YES)
			{
				//gi.bprintf(PRINT_HIGH," voted YES\n"); //for debugging
				num_yes++;
			}
			else if (player->client->ctf.extra_flags & CTF_EXTRAFLAGS_VOTE_NO)
			{
				//gi.bprintf(PRINT_HIGH," voted NO\n");  //for debugging
				num_no++;
			}
			else
			{
				//gi.bprintf(PRINT_HIGH," abstained\n");  //for debugging
				num_abstained++;
			}
			player = ctf_findplayer(player, NULL, CTF_TEAM_IGNORETEAM);
		}
		
		gi.bprintf(PRINT_HIGH,"VOTE RESULT: YES:%d  NO:%d  Abstained:%d\n", num_yes, num_no, num_abstained);
		total_votes = num_yes + num_no;  //only those who voted will be counted
		if (total_votes < 2)
			gi.bprintf(PRINT_HIGH,"Vote Fails: you need at least 2 ballots cast!\n");
		else
		{
			vote_result = (num_yes * 100) / total_votes;
			remainder = (num_yes * 100) % total_votes;  //find the remainder of the integer division if there is one.
			midpoint = total_votes>>1;
			//gi.bprintf(PRINT_HIGH,"total_votes:%d  vote_result:%d  remainder:%d  midpoint:%d\n", total_votes, vote_result, remainder, midpoint); //for debugging
			if (remainder > midpoint) vote_result++;  //if the remainder is greater than 50% then round up by one.
			if (vote_result >= PERCENT_MAJORITY_REQUIRED)
			{
				if (VoteType & CTF_VOTETYPE_SKIP)
				{
					gi.bprintf(PRINT_HIGH,"Vote to skip level Passes with %d percent majority\n", vote_result);
					EndDMLevel();
				}
				else if (VoteType & CTF_VOTETYPE_GOTOMAP)
				{
					gi.bprintf(PRINT_HIGH,"Vote to goto level Passes with %d percent majority\n", vote_result);
					gi.bprintf(PRINT_HIGH,"Too bad this feature is not done yet :P\n");
				}
				else if (VoteType & CTF_VOTETYPE_REFPLAYER)
				{
					gi.bprintf(PRINT_HIGH,"Vote to ref player Passes with %d percent majority\n", vote_result);
					gi.bprintf(PRINT_HIGH,"Too bad this feature is not done yet :P\n");
				}
			}
			else
				gi.bprintf(PRINT_HIGH,"Vote Fails with %d percent majority\n", (100-vote_result));
		}
		VoteType &= ~CTF_VOTETYPE_SKIP;  //clear the vote modes
		VoteType &= ~CTF_VOTETYPE_GOTOMAP;
		VoteType &= ~CTF_VOTETYPE_REFPLAYER;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq $0x0, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq 0x578c8(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movss 0x44dab(%rip), %xmm1    # 0x70290
movq 0x571ec(%rip), %rax     # 0x826d8
addss (%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x2b758
movl $0x2, %edi
leaq 0x45cd0(%rip), %rsi     # 0x711d5
movq 0x570f4(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *(%rcx)
movq 0x57191(%rip), %rax     # 0x826a8
movl $0x0, (%rax)
xorl %eax, %eax
movl %eax, %esi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
movq %rsi, %rdi
callq 0x19340
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x2b5a0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1108(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x2b55a
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2b588
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1108(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x2b57d
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2b586
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2b588
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
callq 0x19340
movq %rax, -0x8(%rbp)
jmp 0x2b532
movq 0x57059(%rip), %rax     # 0x82600
movq (%rax), %r9
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl $0x2, %edi
leaq 0x45c2d(%rip), %rsi     # 0x711ed
movb $0x0, %al
callq *%r9
movl -0x10(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpl $0x2, -0xc(%rbp)
jae 0x2b5f0
movl $0x2, %edi
leaq 0x45c37(%rip), %rsi     # 0x71217
movq 0x57019(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *(%rcx)
jmp 0x2b719
imull $0x64, -0x10(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %eax, -0x20(%rbp)
imull $0x64, -0x10(%rbp), %eax
xorl %edx, %edx
divl -0xc(%rbp)
movl %edx, -0x1c(%rbp)
movl -0xc(%rbp), %eax
shrl %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jbe 0x2b621
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x4b, -0x20(%rbp)
jb 0x2b6f5
movq 0x5799e(%rip), %rax     # 0x82fd0
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b663
movq 0x56fbd(%rip), %rax     # 0x82600
movq (%rax), %rcx
movl -0x20(%rbp), %edx
movl $0x2, %edi
leaq 0x45bf1(%rip), %rsi     # 0x71246
movb $0x0, %al
callq *%rcx
callq 0x18940
jmp 0x2b6f3
movq 0x57966(%rip), %rax     # 0x82fd0
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x2b6aa
movq 0x56f85(%rip), %rax     # 0x82600
movq (%rax), %rcx
movl -0x20(%rbp), %edx
movl $0x2, %edi
leaq 0x45bed(%rip), %rsi     # 0x7127a
movb $0x0, %al
callq *%rcx
movl $0x2, %edi
leaq 0x45c11(%rip), %rsi     # 0x712ae
movq 0x56f5c(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *(%rcx)
jmp 0x2b6f1
movq 0x5791f(%rip), %rax     # 0x82fd0
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x2b6ef
movq 0x56f3e(%rip), %rax     # 0x82600
movq (%rax), %rcx
movl -0x20(%rbp), %edx
movl $0x2, %edi
leaq 0x45c03(%rip), %rsi     # 0x712d7
movb $0x0, %al
callq *%rcx
movl $0x2, %edi
leaq 0x45bca(%rip), %rsi     # 0x712ae
movq 0x56f15(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *(%rcx)
jmp 0x2b6f1
jmp 0x2b6f3
jmp 0x2b717
movq 0x56f04(%rip), %rax     # 0x82600
movq (%rax), %rcx
movl $0x64, %edx
subl -0x20(%rbp), %edx
movl $0x2, %edi
leaq 0x45bf8(%rip), %rsi     # 0x7130b
movb $0x0, %al
callq *%rcx
jmp 0x2b719
movq 0x578b0(%rip), %rax     # 0x82fd0
movl (%rax), %ecx
andl $-0x2, %ecx
movq 0x578a4(%rip), %rax     # 0x82fd0
movl %ecx, (%rax)
movq 0x5789b(%rip), %rax     # 0x82fd0
movl (%rax), %ecx
andl $-0x3, %ecx
movq 0x5788f(%rip), %rax     # 0x82fd0
movl %ecx, (%rax)
movq 0x57886(%rip), %rax     # 0x82fd0
movl (%rax), %ecx
andl $-0x5, %ecx
movq 0x5787a(%rip), %rax     # 0x82fd0
movl %ecx, (%rax)
addq $0x30, %rsp
popq %rbp
retq
nop