// File: /workspace/github_c_makefile_star2_O2/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 0x427a4(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
movq 0x420d0(%rip), %rax     # 0x666d8
movss (%rax), %xmm1
addss 0x2ac80(%rip), %xmm1    # 0x4f294
ucomiss %xmm1, %xmm0
jbe 0x24733
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x41fd4(%rip), %r12     # 0x66600
leaq 0x2bb9a(%rip), %rsi     # 0x501cd
xorl %ebx, %ebx
pushq $0x2
popq %rdi
xorl %eax, %eax
callq *(%r12)
movq 0x42063(%rip), %rax     # 0x666a8
andl $0x0, (%rax)
pushq $-0x4
popq %r14
xorl %edi, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x192e0
xorl %ebp, %ebp
xorl %r15d, %r15d
testq %rax, %rax
je 0x2468f
movq 0x58(%rax), %rcx
movl 0x1108(%rcx), %ecx
testb $0x40, %cl
jne 0x2467a
testb %cl, %cl
js 0x2467e
incl %r15d
jmp 0x24680
incl %ebx
jmp 0x24680
incl %ebp
movq %rax, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x192e0
jmp 0x2465d
leaq 0x2bb4f(%rip), %rsi     # 0x501e5
pushq $0x2
popq %rdi
movl %ebx, %edx
movl %ebp, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq *(%r12)
addl %ebx, %ebp
cmpl $0x1, %ebp
ja 0x246bf
leaq 0x2bb5b(%rip), %rsi     # 0x5020f
pushq $0x2
popq %rdi
xorl %eax, %eax
callq *(%r12)
jmp 0x24721
imull $0x64, %ebx, %eax
xorl %edx, %edx
divl %ebp
shrl %ebp
cmpl %edx, %ebp
adcl $0x0, %eax
cmpl $0x4b, %eax
jb 0x246f3
movq 0x428f7(%rip), %rcx     # 0x66fd0
movl (%rcx), %ecx
testb $0x1, %cl
jne 0x2470a
testb $0x2, %cl
jne 0x24734
testb $0x4, %cl
je 0x24721
leaq 0x2bbde(%rip), %rsi     # 0x502cf
jmp 0x2473b
pushq $0x64
popq %rdx
subl %eax, %edx
leaq 0x2bc04(%rip), %rsi     # 0x50303
pushq $0x2
popq %rdi
xorl %eax, %eax
callq *(%r12)
jmp 0x24721
leaq 0x2bb2d(%rip), %rsi     # 0x5023e
pushq $0x2
popq %rdi
movl %eax, %edx
xorl %eax, %eax
callq *(%r12)
callq 0x18920
movq 0x428a8(%rip), %rax     # 0x66fd0
andb $-0x8, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2bb37(%rip), %rsi     # 0x50272
pushq $0x2
popq %rbx
movl %ebx, %edi
movl %eax, %edx
xorl %eax, %eax
callq *(%r12)
leaq 0x2bb57(%rip), %rsi     # 0x502a6
movl %ebx, %edi
jmp 0x246b7