// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: hook_touch
void hook_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
	vec3_t dest;

	if (!other)
		return;

	if (other == self->owner)
		return; //we hit ourselves, ignore us

	if (self->hook_target && self->hook_target != other) // Already have a target... ignore this new target
		return;

	if (other &&
		(strcmp(other->classname, "bodyque") != 0) &&
		(!ctf_validateplayer(other, CTF_TEAM_ANYTEAM)) && 
		(strcmp(other->classname, "worldspawn") != 0) &&
		(strncmp(other->classname, "func", 4) != 0) &&
		(strncmp(other->classname, "info_flag", 9) != 0)
		)
	{
		ctf_hook_abort(self->owner);
		return;
	}

	//else we hit something else
//	self->s.sound = gi.soundindex ("weapons/grapple/grpull.wav");
//this works, but sounds bad

	// Abort the hook if:
	// [a] we hit the sky
	// [b] we hit a teammate
	// [c] we hit a dead guy
	if ((surf && (surf->flags & SURF_SKY)) ||
		((other->client) && (self->owner->client->ctf.teamnum == other->client->ctf.teamnum)) ||
		other->deadflag)
	{
		ctf_hook_abort(self->owner);
		return;
	}

	VectorClear (self->velocity);

	if (self->owner->client)
	{
		//PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
		if (self->owner->client->hookstate == 1) // Have we just hit?
		{
//			gi.sound(self, CHAN_AUTO, gi.soundindex("weapons/grapple/ghit.wav"), 1, ATTN_NORM, 0);
			//gi.sound(self->owner, CHAN_AUTO, gi.soundindex("weapons/grapple/grpull.wav"), 1, ATTN_NORM, 0);
		}
		self->owner->client->hookstate = 2;
	}

	if (! ((int)ctfflags->value & CTF_NO_GRAP_DAMAGE) || (!other->client)) //surt, no damage if server says so
	{
		if (self->hook_target == other) 
		{
			if ( (level.framenum % 7) == 0 && (level.framenum != self->hook_lastframe) )
			{
				if (ctf_validateplayer(other,CTF_TEAM_ANYTEAM)) //noise for hitting players
					gi.sound(self, CHAN_AUTO, gi.soundindex("weapons/grapple/gkilling.wav"), 1, ATTN_NORM, 0);
				//every 1.5 seconds
				T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, 1, 1, DAMAGE_ENERGY, MOD_CTF_GRAPPLE); //damage, knockback
				self->hook_lastframe = level.framenum;
			}
		}
		else 
		{
			if (ctf_validateplayer(other,CTF_TEAM_ANYTEAM)) //noise for hitting players
				gi.sound(self, CHAN_AUTO, gi.soundindex("weapons/grapple/ghit.wav"), 1, ATTN_NORM, 0);
			else
				gi.sound(self, CHAN_AUTO, gi.soundindex("weapons/grapple/ghitwall.wav"), 0.8f, ATTN_NORM, 0);
			
			// Bonus damage for first hit
			T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, 8, 8, DAMAGE_ENERGY, MOD_CTF_GRAPPLE); //damage, knockback
		}
	}
	
	if (other->deadflag)
	{
		ctf_hook_abort(self->owner);
		return;
	}

		
	if (!self->hook_target)
	{
		self->hook_target = other;
		VectorSubtract(self->s.origin, self->hook_target->absmin, dest);
		VectorCopy(dest, self->hook_offset);
		self->solid = SOLID_TRIGGER;
		gi.linkentity(self);
	}

	gi.WriteByte (svc_temp_entity);
	gi.WriteByte (TE_BLASTER);
	gi.WritePosition (self->s.origin);
	if (!plane)
		gi.WriteDir (vec3_origin);
	else
		gi.WriteDir (plane->normal);
	gi.multicast (self->s.origin, MULTICAST_PVS);	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x4af1b
movq %rsi, %r15
movq %rdi, %rbx
cmpq %rsi, 0x110(%rdi)
je 0x4af1b
movq %rcx, %r12
movq 0x480(%rbx), %rax
testq %rax, %rax
setne %cl
cmpq %r15, %rax
setne %al
testb %al, %cl
jne 0x4af1b
movq %rdx, %r14
movq 0x138(%r15), %rdi
leaq 0x6d2d(%rip), %rsi      # 0x51c13
callq 0x18bc0
testl %eax, %eax
je 0x4af02
pushq $-0x5
popq %rsi
movq %r15, %rdi
callq 0x18de0
testl %eax, %eax
je 0x4b03e
testq %r12, %r12
je 0x4af2a
testb $0x4, 0x10(%r12)
movq 0x110(%rbx), %rdi
je 0x4af31
jmp 0x4b135
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x110(%rbx), %rdi
movq 0x58(%r15), %rax
testq %rax, %rax
je 0x4af50
movq 0x58(%rdi), %rcx
movl 0x1100(%rcx), %ecx
cmpl 0x1100(%rax), %ecx
je 0x4b135
cmpl $0x0, 0x260(%r15)
jne 0x4b135
andl $0x0, 0x1c8(%rbx)
andq $0x0, 0x1c0(%rbx)
movq 0x58(%rdi), %rcx
testq %rcx, %rcx
je 0x4af80
movl $0x2, 0xf40(%rcx)
testq %rax, %rax
je 0x4af9d
movq 0x1bbcc(%rip), %rax     # 0x66b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x40, %eax
jne 0x4b124
leaq 0x1c0(%rbx), %r12
cmpq %r15, 0x480(%rbx)
je 0x4b095
pushq $-0x5
popq %rsi
movq %r15, %rdi
callq 0x18de0
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movq 0x1b636(%rip), %rax     # 0x66600
movq 0x20(%rax), %r13
leaq 0xbf61(%rip), %rdx      # 0x56f36
leaq 0xbf41(%rip), %rdi      # 0x56f1d
cmoveq %rdx, %rdi
leaq 0xbe91(%rip), %rdx      # 0x56e78
movss (%rdx,%rcx,4), %xmm0
movss %xmm0, 0x4(%rsp)
callq *0x48(%rax)
movss 0x3f2b(%rip), %xmm1     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movss 0x4(%rsp), %xmm0
callq *%r13
movq 0x110(%rbx), %rdx
leaq 0x4(%rbx), %r8
pushq $0x8
popq %rax
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r14, %r9
pushq $0x3c
pushq $0x4
pushq %rax
pushq %rax
callq 0x19260
addq $0x20, %rsp
jmp 0x4b124
movq 0x138(%r15), %r13
leaq 0x935c(%rip), %rsi      # 0x543a8
movq %r13, %rdi
callq 0x18bc0
testl %eax, %eax
je 0x4af02
leaq 0x8c4d(%rip), %rsi      # 0x53cb0
pushq $0x4
popq %rdx
movq %r13, %rdi
callq 0x18200
testl %eax, %eax
je 0x4af02
leaq 0xbe79(%rip), %rsi      # 0x56ef6
pushq $0x9
popq %rdx
movq %r13, %rdi
callq 0x18200
testl %eax, %eax
jne 0x4b12e
jmp 0x4af02
movq 0x1bd04(%rip), %r13     # 0x66da0
movslq (%r13), %rcx
pushq $0x7
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
testl %edx, %edx
jne 0x4b124
cmpq %rcx, 0x488(%rbx)
je 0x4b124
pushq $-0x5
popq %rsi
movq %r15, %rdi
callq 0x18de0
testl %eax, %eax
je 0x4b0f0
movq 0x1b535(%rip), %rax     # 0x66600
movq 0x20(%rax), %rbp
leaq 0xbe2a(%rip), %rdi      # 0x56f00
callq *0x48(%rax)
movss 0x3e47(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%rbp
movq 0x110(%rbx), %rdx
leaq 0x4(%rbx), %r8
pushq $0x1
popq %rax
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r14, %r9
pushq $0x3c
pushq $0x4
pushq %rax
pushq %rax
callq 0x19260
addq $0x20, %rsp
movslq (%r13), %rax
movq %rax, 0x488(%rbx)
cmpl $0x0, 0x260(%r15)
je 0x4b148
movq 0x110(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18670
cmpq $0x0, 0x480(%rbx)
jne 0x4b1a1
movq %r15, 0x480(%rbx)
movss 0xc(%rbx), %xmm0
subss 0xec(%r15), %xmm0
movsd 0x4(%rbx), %xmm1
movsd 0xe4(%r15), %xmm2
subps %xmm2, %xmm1
movlps %xmm1, 0x490(%rbx)
movss %xmm0, 0x498(%rbx)
movl $0x1, 0x108(%rbx)
movq 0x1b468(%rip), %rax     # 0x66600
movq %rbx, %rdi
callq *0x90(%rax)
movq 0x1b458(%rip), %r15     # 0x66600
pushq $0x3
popq %rdi
callq *0xc8(%r15)
pushq $0x2
popq %rbp
movl %ebp, %edi
callq *0xc8(%r15)
addq $0x4, %rbx
movq %rbx, %rdi
callq *0xf0(%r15)
testq %r14, %r14
jne 0x4b1d8
movq 0x1b590(%rip), %r14     # 0x66768
movq %r14, %rdi
callq *0xf8(%r15)
movq 0xb0(%r15), %rax
movq %rbx, %rdi
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax