// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: Weapon_Hook_Fire
void Weapon_Hook_Fire (edict_t *ent)
{
	vec3_t	offset, mins, maxs, start, forward, right, dir;
	float		*v;
	int speed;
	vec3_t	dest;

	v = tv(-15,-15,-15);
	_VectorCopy (v, mins);
	v = tv(15,15,15);
	_VectorCopy (v, maxs);

	ent->client->isfiring = 0; // We are only "firing" when we start

	if (ent->client->hookstate == 0)
	{
		VectorCopy(ent->client->v_angle, ent->client->hookangle);
	}

	// Set out ending point to our starting point
	AngleVectors (ent->client->v_angle, forward, right, NULL);
	VectorSet(offset, 8, 8, ent->viewheight-8);
	P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
	
	switch (ent->client->hookstate)
	{
	case 0: // Starting
		VectorScale (forward, -2, ent->client->kick_origin);
		ent->client->kick_angles[0] = -1;
		ent->client->hookstate++;
		ent->client->isfiring = 1;

		ent->client->hook = fire_hook (ent, start, forward, GRAPPLE_FIRE_HOOK_SPEED);

		//-bat.  Let's see this right away!
		Draw_Hook(ent, start, ent->client->hook->s.origin);

	case 1: // Moving out
		if (ent->client->hook)
			Draw_Hook(ent, start, ent->client->hook->s.origin);
		break;
	case 2: // Pulling us to the hook
		if (ent->client->hook)
		{
			if (ent->client->hook->hook_target)
			{
//				if ( 
//					(!ent->client->hook->hook_target->s.origin[0] == 0) && 
//					(!ent->client->hook->hook_target->s.origin[1] == 0) && 
//					(!ent->client->hook->hook_target->s.origin[2] == 0)
//					)
//						VectorCopy(ent->client->hook->hook_target->s.origin, ent->client->hook->s.origin);
				//surt test code
				VectorAdd(ent->client->hook->hook_target->absmin, ent->client->hook->hook_offset, dest);
				VectorCopy(dest, ent->client->hook->s.origin);

			}
			Draw_Hook(ent, start, ent->client->hook->s.origin);
			VectorSubtract(ent->client->hook->s.origin, start, dir);
			speed = VectorLength(dir);

			if (!ent->client->hooklength)
				ent->client->hooklength = speed;

			//sprintf(message, "Speed %i, length %i\n", speed, ent->client->hooklength);
			//ctf_SafePrint(ent, PRINT_HIGH, message);

			ent->client->hooklength = speed;
			VectorNormalize(dir);

			if (speed > 120)
			{
#ifdef WEAP_BALANCE_OK	
				if ((int)ctfflags->value & CTF_WEAP_BALANCE)
					VectorScale(dir, GRAPPLE_PULL_BALANCED_SPEED, dir);
				else
					VectorScale(dir, GRAPPLE_PULL_SPEED, dir);
#else
	   			VectorScale(dir, GRAPPLE_PULL_SPEED, dir);
#endif
				SV_AddGravity (ent); // Add gravity
			}
			else if (speed > 100)
			{
				VectorScale(dir, speed*5, dir);
			}
			else if (speed > 80)
			{
				VectorScale(dir, speed*4, dir);
			}
			else if (speed > 40)
			{
				VectorScale(dir, speed*3, dir);
			}
			else if (speed > 20)
			{
				VectorScale(dir, speed*2, dir);
			}
			else if (speed > 10)
			{
				VectorScale(dir, speed*1, dir);
			}

			VectorCopy (dir, ent->velocity);
			VectorCopy (ent->velocity, ent->client->oldvelocity); // This prevents falling damage

			//ctf_SafePrint(ent, PRINT_HIGH, "Hook in state 2\n");
		}
		else
			ent->client->hookstate = 0;
		break;
	default: //bug
		ctf_hook_abort(ent);
		break;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
movss 0x3da7(%rip), %xmm0     # 0x54440
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x19510
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x199e0
movss 0x3d8b(%rip), %xmm0     # 0x54444
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x19510
leaq 0x3c(%rsp), %rsi
movq %rax, %rdi
callq 0x199e0
movq 0x58(%rbx), %rdi
movl $0x0, 0xf70(%rdi)
cmpl $0x0, 0xf40(%rdi)
jne 0x50706
movss 0xebc(%rdi), %xmm0
movss %xmm0, 0xf50(%rdi)
movq 0xec0(%rdi), %rax
movq %rax, 0xf54(%rdi)
addq $0xebc, %rdi            # imm = 0xEBC
leaq 0x24(%rsp), %r14
leaq 0x30(%rsp), %r15
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x183a0
movabsq $0x4100000041000000, %rax # imm = 0x4100000041000000
leaq 0x54(%rsp), %rdx
movq %rax, (%rdx)
movl 0x278(%rbx), %eax
addl $-0x8, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x8(%rdx)
movq 0x58(%rbx), %rdi
leaq 0x4(%rbx), %rsi
leaq 0x18(%rsp), %r9
movq %r14, %rcx
movq %r15, %r8
callq 0x4dde7
movq 0x58(%rbx), %rsi
movl 0xf40(%rsi), %eax
cmpl $0x2, %eax
je 0x50819
cmpl $0x1, %eax
je 0x507ef
testl %eax, %eax
jne 0x5091a
addq $0xe88, %rsi            # imm = 0xE88
leaq 0x24(%rsp), %r14
movss 0x4c79(%rip), %xmm0     # 0x55410
movq %r14, %rdi
callq 0x189d0
movq 0x58(%rbx), %rax
movl $0xbf800000, 0xe7c(%rax) # imm = 0xBF800000
incl 0xf40(%rax)
movl $0x1, 0xf70(%rax)
leaq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl $0x320, %ecx            # imm = 0x320
callq 0x19680
movq 0x58(%rbx), %rcx
movq %rax, 0xf60(%rcx)
leaq 0x4(%rax), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x18a70
movq 0x58(%rbx), %rax
movq 0xf60(%rax), %rdx
testq %rdx, %rdx
je 0x509be
addq $0x4, %rdx
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x18a70
jmp 0x509be
movq 0xf60(%rsi), %rdx
testq %rdx, %rdx
je 0x50927
movq 0x480(%rdx), %rax
testq %rax, %rax
je 0x50874
movss 0xe4(%rax), %xmm0
movss 0xe8(%rax), %xmm1
addss 0x490(%rdx), %xmm0
addss 0x494(%rdx), %xmm1
movss 0xec(%rax), %xmm2
addss 0x498(%rdx), %xmm2
movss %xmm0, 0x4(%rdx)
movss %xmm1, 0x8(%rdx)
movss %xmm2, 0xc(%rdx)
addq $0x4, %rdx
leaq 0x18(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18a70
movq 0x58(%rbx), %rax
movq 0xf60(%rax), %rax
movss 0x4(%rax), %xmm0
subss (%r14), %xmm0
leaq 0xc(%rsp), %rdi
movss %xmm0, (%rdi)
movss 0x8(%rax), %xmm0
subss 0x4(%r14), %xmm0
movss %xmm0, 0x4(%rdi)
movss 0xc(%rax), %xmm0
subss 0x8(%r14), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x192e0
cvttss2si %xmm0, %r14d
movq 0x58(%rbx), %rax
cmpl $0x0, 0xf5c(%rax)
jne 0x508e4
movl %r14d, 0xf5c(%rax)
movl %r14d, 0xf5c(%rax)
leaq 0xc(%rsp), %rdi
callq 0x18390
cmpl $0x79, %r14d
jl 0x50936
movss 0x39a5(%rip), %xmm0     # 0x542a8
leaq 0xc(%rsp), %rdi
movq %rdi, %rsi
callq 0x189d0
movq %rbx, %rdi
callq 0x189c0
jmp 0x50968
movq %rbx, %rdi
callq 0x18630
jmp 0x509be
movl $0x0, 0xf40(%rsi)
jmp 0x509be
cmpl $0x65, %r14d
jl 0x50949
leal (%r14,%r14,4), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
jmp 0x5095b
cmpl $0x51, %r14d
jl 0x509c8
shll $0x2, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
leaq 0xc(%rsp), %rdi
movq %rdi, %rsi
callq 0x189d0
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x1c0(%rbx)
movss 0x10(%rsp), %xmm1
movss %xmm1, 0x1c4(%rbx)
movss 0x14(%rsp), %xmm1
movss %xmm1, 0x1c8(%rbx)
movq 0x58(%rbx), %rax
movss %xmm0, 0xed8(%rax)
movss 0x1c4(%rbx), %xmm0
movss %xmm0, 0xedc(%rax)
movss 0x1c8(%rbx), %xmm0
movss %xmm0, 0xee0(%rax)
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq
cmpl $0x29, %r14d
jl 0x509d7
leal (%r14,%r14,2), %eax
jmp 0x50940
cmpl $0x15, %r14d
jl 0x509e5
addl %r14d, %r14d
jmp 0x50953
cmpl $0xb, %r14d
jge 0x50953
jmp 0x50968