// File: /workspace/github_c_makefile_star2_O1/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 0x288ad(%rip), %rax     # 0x69ec0
movq (%rax), %rax
xorps %xmm0, %xmm0
cmpeqss 0x20(%rax), %xmm0
movss %xmm0, 0x10(%rsp)
leaq 0x4(%rdi), %rsi
movd 0x128f3(%rip), %xmm0    # 0x53f24
xorl %edi, %edi
movq %rsi, 0x28(%rsp)
callq 0x19880
testq %rax, %rax
je 0x418f8
movq %rax, %r15
movd 0x10(%rsp), %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leal (%rax,%rax,4), %eax
addl $0x5, %eax
movq %rax, 0x10(%rsp)
leaq 0x1c(%rsp), %r12
movq 0x27f93(%rip), %r14     # 0x69600
leaq 0x90(%rsp), %rbp
cmpq %rbx, %r15
je 0x418d7
cmpq 0x110(%rbx), %r15
je 0x418d7
cmpl $0x0, 0x27c(%r15)
je 0x418d7
testb $0x4, 0xc8(%r15)
jne 0x416ae
cmpq $0x0, 0x58(%r15)
je 0x41818
leaq 0xe4(%r15), %rdi
leaq 0xfc(%r15), %rsi
movss 0x13d40(%rip), %xmm0    # 0x55404
leaq 0x30(%rsp), %rdx
callq 0x19770
movss 0x30(%rsp), %xmm0
movss 0x34(%rsp), %xmm1
subss 0x4(%rbx), %xmm0
movss %xmm0, 0x1c(%rsp)
subss 0x8(%rbx), %xmm1
movss %xmm1, 0x20(%rsp)
movss 0x38(%rsp), %xmm0
subss 0xc(%rbx), %xmm0
movss %xmm0, 0x24(%rsp)
movq %r12, %rdi
callq 0x18390
movss 0x4(%rbx), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x8(%rbx), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%rbx), %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x4(%rsp), %r13
movq %r13, %rdi
movd 0x127f2(%rip), %xmm0    # 0x53f2c
movq %r12, %rsi
leaq 0x3c(%rsp), %rdx
callq 0x19770
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), %rdi
testq %rdi, %rdi
je 0x41890
cmpl $0x0, 0x27c(%rdi)
je 0x417d1
testb $0x4, 0x11c(%rdi)
jne 0x417d1
movq 0x110(%rbx), %rdx
cmpq %rdx, %rdi
je 0x417d1
movq %rbx, %rsi
movq %r12, %rcx
leaq 0x54(%rsp), %r8
movq 0x27faa(%rip), %r9      # 0x69768
pushq $0xc
pushq $0x4
pushq $0x1
pushq 0x28(%rsp)
callq 0x190f0
addq $0x20, %rsp
movq 0x88(%rsp), %r9
testb $0x4, 0xc8(%r9)
jne 0x417ea
cmpq $0x0, 0x58(%r9)
je 0x41838
movd 0x54(%rsp), %xmm0
movd %xmm0, 0x4(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
subq $0x8, %rsp
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
jmp 0x41760
movq 0x138(%r15), %rdi
leaq 0x179f6(%rip), %rsi     # 0x5921c
callq 0x18b20
testl %eax, %eax
jne 0x418d7
jmp 0x416ae
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 0x28(%rsp), %r13
movq %r13, %rdi
callq *0xf0(%r14)
leaq 0x54(%rsp), %rdi
callq *0xf0(%r14)
movq %r13, %rdi
leaq 0x1c(%rsp), %r12
movl $0x1, %esi
callq *0xb0(%r14)
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movd 0x1263d(%rip), %xmm0    # 0x53f24
callq 0x19880
movq %rax, %r15
testq %rax, %rax
jne 0x41675
movq 0x284a1(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
addss 0x12984(%rip), %xmm0    # 0x54290
movss %xmm0, 0x200(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq