// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/g_ctffunc.c
// Function: ctf_spawnflag
qboolean ctf_spawnflag(int teamnum)
{
	edict_t		*ent = NULL; // MJD Uninitialized
	edict_t         *spot;

	if (!deathmatch->value)
		return false;

	if ((int)ctfflags->value & CTF_FLAGS_NOFLAGS)
		return false;

	// Check if the flags already exist

	if (teamnum == CTF_TEAM_RED  && !redflag) // RED FLAG
	{	
		spot = G_Find (NULL, FOFS(classname), "info_flag_red");
		if (!spot)
		{
			spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
			if (spot)
				spot = ctf_findflagposition(spot);

			if (!spot)
				spot = G_Find (NULL, FOFS(classname), "info_player_start");


			// Make the spawn point glow
			if (spot)
			{
				spot->classname = "info_flag_red";
				spot->s.effects |= EF_COLOR_SHELL;
				spot->s.renderfx |= RF_SHELL_RED;
			}
			else // No spawn location found -- we will fail
				return false;
		}
		
		ent = G_Spawn();
		ent->classname = ED_NewString ("flag");
		ED_CallSpawn(ent);
		
		// Model support for flags
		ent->model = "players/male/flag1.md2";
		// Model support for flags
		
		VectorCopy (spot->s.origin, ent->s.origin);
		VectorCopy (spot->s.origin, ent->homeposition);
		VectorCopy (spot->s.angles, ent->s.angles);
		VectorCopy (spot->s.angles, ent->homeangles);
		//ent->s.effects |= EF_COLOR_SHELL | EF_FLAG1;
		//ent->s.renderfx |= RF_SHELL_RED;
		ent->s.effects = EF_FLAG1;
		// Paril
		if (flag_init->value)
			ent->s.frame = 173;
		else
			ent->s.frame = 0;
		// Paril
		redflag = ent;
	}
	else if (teamnum == CTF_TEAM_BLUE && !blueflag) // BLUE FLAG
	{
		spot = G_Find (NULL, FOFS(classname), "info_flag_blue");
		if (!spot)
		{
			spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
			if (spot)
			{
				spot = ctf_findflagposition(spot);
				spot = ctf_findflagposition(spot);
			}

			if (!spot)
				spot = G_Find (NULL, FOFS(classname), "target_changelevel");

			// Make the spawn point glow
			if (spot)
			{
				spot->classname = "info_flag_blue";
				spot->s.effects |= EF_COLOR_SHELL;
				spot->s.renderfx |= RF_SHELL_BLUE;
			}
			else // No spawn location found -- we will fail
				return false;
		}

		ent = G_Spawn();
		ent->classname = ED_NewString ("flag");
		ED_CallSpawn(ent);
		// Model support for flags
		ent->model = "players/male/flag2.md2";
		// Model support for flags

		
		VectorCopy (spot->s.origin, ent->s.origin);
		VectorCopy (spot->s.origin, ent->homeposition);
		VectorCopy (spot->s.angles, ent->s.angles);
		VectorCopy (spot->s.angles, ent->homeangles);
		//ent->s.effects |= EF_COLOR_SHELL | EF_FLAG2;
		//ent->s.renderfx |= RF_SHELL_BLUE;
		ent->s.effects = EF_FLAG2;
		// Paril
		if (flag_init->value)
			ent->s.frame = 173;
		else
			ent->s.frame = 0;
		// Paril
		blueflag = ent;
	}


	//ent->model = "players/male/test.md2";

	if (ent)
	{
		//common
		ent->flagteam = teamnum; // passed as parameter
		gi.setmodel (ent, ent->model);
		ent->takedamage = DAMAGE_NO; //no damage on flags
		ent->dontfree = 1;
		ctf_resetflagandplayer (ent, NULL);
		ent->solid = SOLID_TRIGGER;
		gi.linkentity(ent); //make it touchable
		ent->movetype = MOVETYPE_TOSS;
		ctf_ResetFlagProps(ent);
		ctf_deletespawnpointsnearflag(ent);
	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x47e70(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorl %r12d, %r12d
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1f069
jnp 0x1f359
movq 0x47ae8(%rip), %rax     # 0x66b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0x8, %eax
jb 0x1f359
movl %edi, %ebx
pushq $0x1
popq %rax
cmpl $0x1, %edi
jne 0x1f0c9
movq 0x47765(%rip), %r13     # 0x667f8
cmpq $0x0, (%r13)
jne 0x1f0c9
leaq 0x2feaf(%rip), %r14     # 0x4ef50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x195e0
testq %rax, %rax
je 0x1f113
movq %rax, %r15
movl $0x40000, %ebp          # imm = 0x40000
leaq 0x304a7(%rip), %r12     # 0x4f56b
jmp 0x1f202
cmpl $0x2, %ebx
jne 0x1f10b
movq 0x4778b(%rip), %r13     # 0x66860
cmpq $0x0, (%r13)
jne 0x1f10b
leaq 0x2fe7b(%rip), %r14     # 0x4ef5e
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x195e0
testq %rax, %rax
je 0x1f174
movq %rax, %r15
movl $0x80000, %ebp          # imm = 0x80000
leaq 0x3048f(%rip), %r12     # 0x4f595
jmp 0x1f202
movl %eax, %r12d
jmp 0x1f359
leaq 0x30428(%rip), %rdx     # 0x4f542
xorl %r12d, %r12d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
testq %rax, %rax
je 0x1f13b
movq %rax, %rdi
callq 0x18c50
testq %rax, %rax
jne 0x1f157
leaq 0x30417(%rip), %rdx     # 0x4f559
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
testq %rax, %rax
je 0x1f359
movq %rax, %r15
movq 0x47697(%rip), %r13     # 0x667f8
movl $0x40000, %ebp          # imm = 0x40000
leaq 0x303fe(%rip), %r12     # 0x4f56b
movl $0x400, %eax            # imm = 0x400
jmp 0x1f1db
leaq 0x303c7(%rip), %rdx     # 0x4f542
xorl %r12d, %r12d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
testq %rax, %rax
je 0x1f1a4
movq %rax, %rdi
callq 0x18c50
movq %rax, %rdi
callq 0x18c50
testq %rax, %rax
jne 0x1f1c0
leaq 0x303d7(%rip), %rdx     # 0x4f582
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
testq %rax, %rax
je 0x1f359
movq %rax, %r15
movq 0x47696(%rip), %r13     # 0x66860
movl $0x80000, %ebp          # imm = 0x80000
leaq 0x303bf(%rip), %r12     # 0x4f595
movl $0x1000, %eax           # imm = 0x1000
movq %r14, 0x138(%r15)
movq 0x40(%r15), %xmm0
movd %eax, %xmm1
movdqa 0x302bc(%rip), %xmm2    # 0x4f4b0
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
por %xmm0, %xmm2
movq %xmm2, 0x40(%r15)
callq 0x198d0
movq %rax, %r14
leaq 0x37cea(%rip), %rdi     # 0x56efb
callq 0x18280
movq %rax, 0x138(%r14)
movq %r14, %rdi
callq 0x194a0
movq %r12, 0x120(%r14)
movss 0x4(%r15), %xmm0
movss %xmm0, 0x4(%r14)
movss 0x8(%r15), %xmm0
movss %xmm0, 0x8(%r14)
movss 0xc(%r15), %xmm0
movss %xmm0, 0xc(%r14)
movss 0x4(%r15), %xmm0
movss %xmm0, 0x460(%r14)
movss 0x8(%r15), %xmm0
movss %xmm0, 0x464(%r14)
movss 0xc(%r15), %xmm0
movss %xmm0, 0x468(%r14)
movss 0x10(%r15), %xmm0
movss %xmm0, 0x10(%r14)
movss 0x14(%r15), %xmm0
movss %xmm0, 0x14(%r14)
movss 0x18(%r15), %xmm0
movss %xmm0, 0x18(%r14)
movss 0x10(%r15), %xmm0
movss %xmm0, 0x46c(%r14)
movss 0x14(%r15), %xmm0
movss %xmm0, 0x470(%r14)
movss 0x18(%r15), %xmm0
movss %xmm0, 0x474(%r14)
movl %ebp, 0x40(%r14)
movq 0x4754f(%rip), %rax     # 0x66828
movq (%rax), %rax
xorl %ecx, %ecx
xorps %xmm0, %xmm0
ucomiss 0x20(%rax), %xmm0
movl $0xad, %eax
cmovnel %eax, %ecx
cmovpl %eax, %ecx
movl %ecx, 0x38(%r14)
movq %r14, (%r13)
movl %ebx, 0x47c(%r14)
movq 0x472fa(%rip), %rbx     # 0x66600
movq %r14, %rdi
movq %r12, %rsi
callq *0x58(%rbx)
andl $0x0, 0x27c(%r14)
pushq $0x1
popq %rbp
movl %ebp, 0x49c(%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x191d0
movl %ebp, 0x108(%r14)
movq %r14, %rdi
callq *0x90(%rbx)
movl $0x7, 0x118(%r14)
movq %r14, %rdi
callq 0x185c0
movq %r14, %rdi
callq 0x191c0
movl %ebp, %r12d
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq