// File: /workspace/github_c_makefile_star2_O3/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:
movq 0x426bb(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
movq 0x41fe7(%rip), %rax     # 0x686d8
movss (%rax), %xmm1
addss 0x2cb97(%rip), %xmm1    # 0x53294
ucomiss %xmm1, %xmm0
jbe 0x26837
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x41eec(%rip), %r15     # 0x68600
leaq 0x2dab2(%rip), %rsi     # 0x541cd
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq *(%r15)
movq 0x41f7a(%rip), %rax     # 0x686a8
movl $0x0, (%rax)
xorl %edi, %edi
xorl %esi, %esi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
callq 0x19170
movl $0x0, %ebp
movl $0x0, %r14d
testq %rax, %rax
je 0x2678b
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x58(%rax), %rcx
movl 0x1108(%rcx), %ecx
testb $0x40, %cl
jne 0x26771
testb %cl, %cl
js 0x26775
incl %r14d
jmp 0x26777
incl %ebx
jmp 0x26777
incl %ebp
movq %rax, %rdi
xorl %esi, %esi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
callq 0x19170
testq %rax, %rax
jne 0x26759
leaq 0x2da53(%rip), %rsi     # 0x541e5
movl $0x2, %edi
movl %ebx, %edx
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq *(%r15)
addl %ebx, %ebp
cmpl $0x1, %ebp
ja 0x267bd
leaq 0x2da5e(%rip), %rsi     # 0x5420f
movl $0x2, %edi
xorl %eax, %eax
callq *(%r15)
jmp 0x26823
imull $0x64, %ebx, %eax
xorl %edx, %edx
divl %ebp
shrl %ebp
cmpl %edx, %ebp
adcl $0x0, %eax
cmpl $0x4b, %eax
jb 0x267f1
movq 0x427f9(%rip), %rcx     # 0x68fd0
movl (%rcx), %ecx
testb $0x1, %cl
jne 0x2680b
testb $0x2, %cl
jne 0x26838
testb $0x4, %cl
je 0x26823
leaq 0x2dae0(%rip), %rsi     # 0x542cf
jmp 0x2683f
movl $0x64, %edx
subl %eax, %edx
leaq 0x2db04(%rip), %rsi     # 0x54303
movl $0x2, %edi
xorl %eax, %eax
callq *(%r15)
jmp 0x26823
leaq 0x2da2c(%rip), %rsi     # 0x5423e
movl $0x2, %edi
movl %eax, %edx
xorl %eax, %eax
callq *(%r15)
callq 0x188c0
movq 0x427a6(%rip), %rax     # 0x68fd0
andb $-0x8, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2da33(%rip), %rsi     # 0x54272
movl $0x2, %edi
movl %eax, %edx
xorl %eax, %eax
callq *(%r15)
leaq 0x2da54(%rip), %rsi     # 0x542a6
jmp 0x267b1