// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x6a587
jmp 0x6aaf2
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x110(%rcx), %rax
jne 0x6a59d
jmp 0x6aaf2
movq -0x8(%rbp), %rax
cmpq $0x0, 0x480(%rax)
je 0x6a5c1
movq -0x8(%rbp), %rax
movq 0x480(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x6a5c1
jmp 0x6aaf2
cmpq $0x0, -0x10(%rbp)
je 0x6a672
movq -0x10(%rbp), %rax
movq 0x138(%rax), %rdi
leaq 0x858d(%rip), %rsi      # 0x72b6b
callq 0x18bf0
cmpl $0x0, %eax
je 0x6a672
movq -0x10(%rbp), %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18e40
cmpl $0x0, %eax
jne 0x6a672
movq -0x10(%rbp), %rax
movq 0x138(%rax), %rdi
leaq 0xaab7(%rip), %rsi      # 0x750c8
callq 0x18bf0
cmpl $0x0, %eax
je 0x6a672
movq -0x10(%rbp), %rax
movq 0x138(%rax), %rdi
leaq 0xa38b(%rip), %rsi      # 0x749b8
movl $0x4, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x6a672
movq -0x10(%rbp), %rax
movq 0x138(%rax), %rdi
leaq 0xd4c8(%rip), %rsi      # 0x77b16
movl $0x9, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x6a672
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rdi
callq 0x18690
jmp 0x6aaf2
cmpq $0x0, -0x20(%rbp)
je 0x6a688
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x6a6c5
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x6a6b8
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
cmpl 0x1100(%rcx), %eax
je 0x6a6c5
movq -0x10(%rbp), %rax
cmpl $0x0, 0x260(%rax)
je 0x6a6da
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rdi
callq 0x18690
jmp 0x6aaf2
movq -0x8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x1c8(%rax)
movq -0x8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x1c4(%rax)
movq -0x8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x1c0(%rax)
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x6a74c
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0xf40(%rax)
jne 0x6a733
jmp 0x6a733
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq 0x58(%rax), %rax
movl $0x2, 0xf40(%rax)
movq 0x18405(%rip), %rax     # 0x82b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x6a772
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0x6a96d
movq -0x8(%rbp), %rax
movq 0x480(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x6a87b
movq 0x18612(%rip), %rax     # 0x82da0
movl (%rax), %eax
movl $0x7, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x6a876
movq 0x185f8(%rip), %rax     # 0x82da0
movslq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x488(%rcx), %rax
je 0x6a876
movq -0x10(%rbp), %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18e40
cmpl $0x0, %eax
je 0x6a813
movq 0x17e2a(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq 0xd333(%rip), %rdi      # 0x77b20
movq 0x17e0c(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0x40(%rbp), %rdi
movl %eax, %edx
movq -0x38(%rbp), %rax
xorl %esi, %esi
movss 0x56e1(%rip), %xmm1     # 0x6feec
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq *%rax
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rdx
movq -0x8(%rbp), %rcx
addq $0x1c0, %rcx            # imm = 0x1C0
movq -0x8(%rbp), %r8
addq $0x4, %r8
movq -0x18(%rbp), %r9
movl $0x1, (%rsp)
movl $0x1, 0x8(%rsp)
movl $0x4, 0x10(%rsp)
movl $0x3c, 0x18(%rsp)
callq 0x192c0
movq 0x18538(%rip), %rax     # 0x82da0
movslq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x488(%rax)
jmp 0x6a96b
movq -0x10(%rbp), %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18e40
cmpl $0x0, %eax
je 0x6a8d4
movq 0x17d6b(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0xd291(%rip), %rdi      # 0x77b3d
movq 0x17d4d(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0x50(%rbp), %rdi
movl %eax, %edx
movq -0x48(%rbp), %rax
xorl %esi, %esi
movss 0x5622(%rip), %xmm1     # 0x6feec
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq *%rax
jmp 0x6a91d
movq 0x17d25(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0xd264(%rip), %rdi      # 0x77b56
movq 0x17d07(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0x60(%rbp), %rdi
movl %eax, %edx
movq -0x58(%rbp), %rax
xorl %esi, %esi
movss 0x5b70(%rip), %xmm0     # 0x70480
movss 0x55d4(%rip), %xmm1     # 0x6feec
xorps %xmm2, %xmm2
callq *%rax
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rdx
movq -0x8(%rbp), %rcx
addq $0x1c0, %rcx            # imm = 0x1C0
movq -0x8(%rbp), %r8
addq $0x4, %r8
movq -0x18(%rbp), %r9
movl $0x8, (%rsp)
movl $0x8, 0x8(%rsp)
movl $0x4, 0x10(%rsp)
movl $0x3c, 0x18(%rsp)
callq 0x192c0
jmp 0x6a96d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x260(%rax)
je 0x6a98f
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rdi
callq 0x18690
jmp 0x6aaf2
movq -0x8(%rbp), %rax
cmpq $0x0, 0x480(%rax)
jne 0x6aa68
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x480(%rax)
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x480(%rax), %rax
subss 0xe4(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x480(%rax), %rax
subss 0xe8(%rax), %xmm0
movss %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x480(%rax), %rax
subss 0xec(%rax), %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x2c(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x490(%rax)
movss -0x28(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x494(%rax)
movss -0x24(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x498(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0x108(%rax)
movq 0x17ba5(%rip), %rax     # 0x82600
movq 0x90(%rax), %rax
movq -0x8(%rbp), %rdi
callq *%rax
movl $0x3, %edi
movq 0x17b8c(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movl $0x2, %edi
movq 0x17b7a(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movq 0x17b6d(%rip), %rax     # 0x82600
movq 0xf0(%rax), %rax
movq -0x8(%rbp), %rdi
addq $0x4, %rdi
callq *%rax
cmpq $0x0, -0x18(%rbp)
jne 0x6aac1
movq 0x17cb6(%rip), %rdi     # 0x82768
movq 0x17b47(%rip), %rax     # 0x82600
callq *0xf8(%rax)
jmp 0x6aad5
movq 0x17b38(%rip), %rax     # 0x82600
movq 0xf8(%rax), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq 0x17b24(%rip), %rax     # 0x82600
movq 0xb0(%rax), %rax
movq -0x8(%rbp), %rdi
addq $0x4, %rdi
movl $0x2, %esi
callq *%rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)