// File: /workspace/github_c_makefile_star2_O1/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 0x434cb(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
movq 0x42df7(%rip), %rax     # 0x696d8
movss (%rax), %xmm1
addss 0x2d9a7(%rip), %xmm1    # 0x54294
ucomiss %xmm1, %xmm0
jbe 0x26a27
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x42cfc(%rip), %r15     # 0x69600
leaq 0x2e8c6(%rip), %rsi     # 0x551d1
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq *(%r15)
movq 0x42d8a(%rip), %rax     # 0x696a8
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 0x2697b
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x58(%rax), %rcx
movl 0x1108(%rcx), %ecx
testb $0x40, %cl
jne 0x26961
testb %cl, %cl
js 0x26965
incl %r14d
jmp 0x26967
incl %ebx
jmp 0x26967
incl %ebp
movq %rax, %rdi
xorl %esi, %esi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
callq 0x19170
testq %rax, %rax
jne 0x26949
leaq 0x2e867(%rip), %rsi     # 0x551e9
movl $0x2, %edi
movl %ebx, %edx
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq *(%r15)
addl %ebx, %ebp
cmpl $0x1, %ebp
ja 0x269ad
leaq 0x2e872(%rip), %rsi     # 0x55213
movl $0x2, %edi
xorl %eax, %eax
callq *(%r15)
jmp 0x26a13
imull $0x64, %ebx, %eax
xorl %edx, %edx
divl %ebp
shrl %ebp
cmpl %edx, %ebp
adcl $0x0, %eax
cmpl $0x4b, %eax
jb 0x269e1
movq 0x43609(%rip), %rcx     # 0x69fd0
movl (%rcx), %ecx
testb $0x1, %cl
jne 0x269fb
testb $0x2, %cl
jne 0x26a28
testb $0x4, %cl
je 0x26a13
leaq 0x2e8f4(%rip), %rsi     # 0x552d3
jmp 0x26a2f
movl $0x64, %edx
subl %eax, %edx
leaq 0x2e918(%rip), %rsi     # 0x55307
movl $0x2, %edi
xorl %eax, %eax
callq *(%r15)
jmp 0x26a13
leaq 0x2e840(%rip), %rsi     # 0x55242
movl $0x2, %edi
movl %eax, %edx
xorl %eax, %eax
callq *(%r15)
callq 0x188c0
movq 0x435b6(%rip), %rax     # 0x69fd0
andb $-0x8, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2e847(%rip), %rsi     # 0x55276
movl $0x2, %edi
movl %eax, %edx
xorl %eax, %eax
callq *(%r15)
leaq 0x2e868(%rip), %rsi     # 0x552aa
jmp 0x269a1