// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_weapon.c
// Function: bfg_think
void bfg_think (edict_t *self)
{
	edict_t	*ent;
	edict_t	*ignore;
	vec3_t	point;
	vec3_t	dir;
	vec3_t	start;
	vec3_t	end;
	int		dmg;
	trace_t	tr;

	if (deathmatch->value)
		dmg = 5;
	else
		dmg = 10;

#ifdef WEAP_BALANCE_OK	
	if ((int)ctfflags->value & CTF_WEAP_BALANCE)
		dmg = 3; //don't burn the players so hard
#endif

	ent = NULL;
	while ((ent = findradius(ent, self->s.origin, 256)) != NULL)
	{
		if (ent == self)
			continue;

		if (ent == self->owner)
			continue;

		if (!ent->takedamage)
			continue;

		if (!(ent->svflags & SVF_MONSTER) && (!ent->client) && (strcmp(ent->classname, "misc_explobox") != 0))
			continue;

		VectorMA (ent->absmin, 0.5, ent->size, point);

		VectorSubtract (point, self->s.origin, dir);
		VectorNormalize (dir);

		ignore = self;
		VectorCopy (self->s.origin, start);
		VectorMA (start, 2048, dir, end);
		while(1)
		{
			tr = gi.trace (start, NULL, NULL, end, ignore, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);

			if (!tr.ent)
				break;

			// hurt it if we can
			if ((tr.ent->takedamage) && !(tr.ent->flags & FL_IMMUNE_LASER) && (tr.ent != self->owner))
				T_Damage (tr.ent, self, self->owner, dir, tr.endpos, vec3_origin, dmg, 1, DAMAGE_ENERGY, MOD_BFG_LASER);

			// if we hit something that's not a monster or player we're done
			if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
			{
				gi.WriteByte (svc_temp_entity);
				gi.WriteByte (TE_LASER_SPARKS);
				gi.WriteByte (4);
				gi.WritePosition (tr.endpos);
				gi.WriteDir (tr.plane.normal);
				gi.WriteByte (self->s.skinnum);
				gi.multicast (tr.endpos, MULTICAST_PVS);
				break;
			}

			ignore = tr.ent;
			VectorCopy (tr.endpos, start);
		}

		gi.WriteByte (svc_temp_entity);
		gi.WriteByte (TE_BFG_LASER);
		gi.WritePosition (self->s.origin);
		gi.WritePosition (tr.endpos);
		gi.multicast (self->s.origin, MULTICAST_PHS);
	}

	self->nextthink = level.time + FRAMETIME;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
movq 0x28199(%rip), %rax     # 0x68ec0
movq (%rax), %rax
xorps %xmm0, %xmm0
cmpeqss 0x20(%rax), %xmm0
movss %xmm0, (%rsp)
leaq 0x4(%rdi), %rsi
movd 0x121e0(%rip), %xmm0    # 0x52f24
xorl %edi, %edi
movq %rsi, 0x18(%rsp)
callq 0x19870
testq %rax, %rax
je 0x40ff6
movq %rax, %r15
movd (%rsp), %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leal (%rax,%rax,4), %eax
addl $0x5, %eax
movq %rax, (%rsp)
leaq 0x20(%rsp), %r12
movq 0x27882(%rip), %r14     # 0x68600
leaq 0x90(%rsp), %rbp
cmpq %rbx, %r15
je 0x40fd5
cmpq 0x110(%rbx), %r15
je 0x40fd5
cmpl $0x0, 0x27c(%r15)
je 0x40fd5
testb $0x4, 0xc8(%r15)
jne 0x40dbf
cmpq $0x0, 0x58(%r15)
je 0x40f16
leaq 0xe4(%r15), %rdi
leaq 0xfc(%r15), %rsi
movss 0x1362b(%rip), %xmm0    # 0x54400
leaq 0x30(%rsp), %rdx
callq 0x19760
movsd 0x30(%rsp), %xmm0
movsd 0x4(%rbx), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, 0x20(%rsp)
movss 0x38(%rsp), %xmm0
subss 0xc(%rbx), %xmm0
movss %xmm0, 0x28(%rsp)
movq %r12, %rdi
callq 0x18390
movsd 0x4(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movss 0xc(%rbx), %xmm0
movss %xmm0, 0x10(%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movd 0x120fb(%rip), %xmm0    # 0x52f2c
movq %r12, %rsi
leaq 0x3c(%rsp), %rdx
callq 0x19760
subq $0x8, %rsp
movq %rbp, %rdi
movq %r13, %rsi
leaq 0x44(%rsp), %r13
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %rbx, %r9
pushq $0x6000001              # imm = 0x6000001
callq *0x60(%r14)
addq $0x10, %rsp
movl $0x9, %ecx
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x88(%rsp), %r9
testq %r9, %r9
je 0x40f8e
cmpl $0x0, 0x27c(%r9)
je 0x40ed5
testb $0x4, 0x11c(%r9)
jne 0x40ed5
movq 0x110(%rbx), %rdx
cmpq %rdx, %r9
je 0x40ed5
movq %r9, %rdi
movq %rbx, %rsi
movq %r12, %rcx
leaq 0x54(%rsp), %r8
movq 0x278ae(%rip), %r9      # 0x68768
pushq $0xc
pushq $0x4
pushq $0x1
pushq 0x18(%rsp)
callq 0x190f0
addq $0x20, %rsp
movq 0x88(%rsp), %r9
testb $0x4, 0xc8(%r9)
jne 0x40ee6
cmpq $0x0, 0x58(%r9)
je 0x40f36
movsd 0x54(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movd 0x5c(%rsp), %xmm0
movd %xmm0, 0x10(%rsp)
subq $0x8, %rsp
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
jmp 0x40e57
movq 0x138(%r15), %rdi
leaq 0x1750c(%rip), %rsi     # 0x58430
callq 0x18b20
testl %eax, %eax
jne 0x40fd5
jmp 0x40dbf
movl $0x3, %edi
callq *0xc8(%r14)
movl $0xf, %edi
callq *0xc8(%r14)
movl $0x4, %edi
callq *0xc8(%r14)
leaq 0x54(%rsp), %r12
movq %r12, %rdi
callq *0xf0(%r14)
leaq 0x60(%rsp), %rdi
callq *0xf8(%r14)
movl 0x3c(%rbx), %edi
callq *0xc8(%r14)
movq %r12, %rdi
movl $0x2, %esi
callq *0xb0(%r14)
movl $0x3, %edi
callq *0xc8(%r14)
movl $0x17, %edi
callq *0xc8(%r14)
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq *0xf0(%r14)
leaq 0x54(%rsp), %rdi
callq *0xf0(%r14)
movq %r13, %rdi
leaq 0x20(%rsp), %r12
movl $0x1, %esi
callq *0xb0(%r14)
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movd 0x11f3f(%rip), %xmm0    # 0x52f24
callq 0x19870
movq %rax, %r15
testq %rax, %rax
jne 0x40d86
movq 0x27da3(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x12286(%rip), %xmm0    # 0x53290
movss %xmm0, 0x200(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq