// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/plasma.c
// Function: Weapon_PLASMA_Generic
void Weapon_PLASMA_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
{
int		n;

	if(ent->client->quad_framenum > level.framenum)
		quadmeister = true;
	else
		quadmeister = false;

	// VWep animations screw up corpses
	if(ent->deadflag || ent->s.modelindex != 255)
		return;

	//bat
	ent->client->isfiring = 0;


	if (ent->client->weaponstate == WEAPON_DROPPING)
	{
		if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST)
		{
			ChangeWeapon (ent);
			return;
		}
		else if ((FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe) == 4)
		{
			ent->client->anim_priority = ANIM_REVERSE;
			if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
			{
				ent->s.frame = FRAME_crpain4+1;
				ent->client->anim_end = FRAME_crpain1;
			}
			else
			{
				ent->s.frame = FRAME_pain304+1;
				ent->client->anim_end = FRAME_pain301;
				
			}
		}

		ent->client->ps.gunframe++;
		return;
	}

	if (ent->client->weaponstate == WEAPON_ACTIVATING)
	{
		if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST)
		{
			ent->client->weaponstate = WEAPON_READY;
			ent->client->ps.gunframe = FRAME_IDLE_FIRST;
			
			//-bat
			if(ent->client->plasma_mode)
				gi.cprintf(ent, PRINT_HIGH, "bounce plasma\n");
			else
				gi.cprintf(ent, PRINT_HIGH, "spread plasma\n");

			return;
		}

		ent->client->ps.gunframe++;
		return;
	}

	if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING))
	{
		ent->client->weaponstate = WEAPON_DROPPING;
		ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;

		if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4)
		{
			ent->client->anim_priority = ANIM_REVERSE;
			if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
			{
				ent->s.frame = FRAME_crpain4+1;
				ent->client->anim_end = FRAME_crpain1;
			}
			else
			{
				ent->s.frame = FRAME_pain304+1;
				ent->client->anim_end = FRAME_pain301;
				
			}
		}
		return;
	}

	if (ent->client->weaponstate == WEAPON_READY)
	{
		if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
		{
			ent->client->latched_buttons &= ~BUTTON_ATTACK;
			if ((!ent->client->ammo_index) || 
				( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity))
			{
				ent->client->ps.gunframe = FRAME_FIRE_FIRST;
				ent->client->weaponstate = WEAPON_FIRING;

				// start the animation
				ent->client->anim_priority = ANIM_ATTACK;
				if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
				{
					ent->s.frame = FRAME_crattak1-1;
					ent->client->anim_end = FRAME_crattak9;
				}
				else
				{
					ent->s.frame = FRAME_attack1-1;
					ent->client->anim_end = FRAME_attack8;
				}
			}
			else
			{
				if (level.time >= ent->pain_debounce_time)
				{
					gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
					ent->pain_debounce_time = level.time + 1;
				}
				NoAmmoWeaponChange (ent);
			}
		}
		else
		{
			if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
			{
				ent->client->ps.gunframe = FRAME_IDLE_FIRST;
				return;
			}

			if (pause_frames)
			{
				for (n = 0; pause_frames[n]; n++)
				{
					if (ent->client->ps.gunframe == pause_frames[n])
					{
						if (rand()&15)
							return;
					}
				}
			}

			if ( ent->client->ps.gunframe == 35 )
			gi.sound(ent,CHAN_WEAPON,
			  gi.soundindex(PLASMA_SOUND_VENT), 1, ATTN_NORM,0 );

			ent->client->ps.gunframe++;
			return;
		}
	}

	if (ent->client->weaponstate == WEAPON_FIRING)
	{
		for (n = 0; fire_frames[n]; n++)
		{
			if (ent->client->ps.gunframe == fire_frames[n])
			{
				//bat
				if(ent->client->quad_framenum > level.framenum)
					gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage3.wav"), 1, ATTN_NORM, 0);

				
				//bat
				ent->client->isfiring = 1;
				fire (ent);
				break;
			}
		}

		if (!fire_frames[n])
			ent->client->ps.gunframe++;

		if (ent->client->ps.gunframe == FRAME_IDLE_FIRST+1)
			ent->client->weaponstate = WEAPON_READY;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rdi, %rbx
movq 0x48(%rsp), %r12
movq 0x40(%rsp), %r15
movq 0x58(%rdi), %rax
movss 0xf04(%rax), %xmm0
movq 0x4443b(%rip), %r13     # 0x66da0
cvtsi2ssl (%r13), %xmm1
xorl %edx, %edx
ucomiss %xmm1, %xmm0
seta %dl
movq 0x43cf6(%rip), %rdi     # 0x66670
movl %edx, (%rdi)
cmpl $0x0, 0x260(%rbx)
jne 0x22a9b
cmpl $0xff, 0x28(%rbx)
jne 0x22a9b
andl $0x0, 0xf70(%rax)
movl 0xe78(%rax), %edx
cmpl $0x1, %edx
je 0x229cf
cmpl $0x2, %edx
jne 0x22a0a
movl 0x5c(%rax), %ecx
subl %ecx, %r8d
jne 0x22a63
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18800
movl 0x5c(%rax), %ecx
cmpl %esi, %ecx
jne 0x22a96
andl $0x0, 0xe78(%rax)
incl %ebp
movl %ebp, 0x5c(%rax)
cmpl $0x0, 0xf3c(%rax)
movq 0x43c0c(%rip), %rax     # 0x66600
movq 0x10(%rax), %rcx
je 0x22ab9
leaq 0x2d2e6(%rip), %rdx     # 0x4fceb
jmp 0x22ac0
movq %r9, %r14
cmpl $0x3, %edx
je 0x22aaa
cmpq $0x0, 0xe50(%rax)
je 0x22aaa
movl $0x2, 0xe78(%rax)
incl %ecx
movl %ecx, 0x5c(%rax)
subl %ecx, %r8d
cmpl $0x3, %r8d
jg 0x22a9b
movl $0x6, 0xef8(%rax)
testb $0x1, 0x10(%rax)
jne 0x22afe
movl $0x42, 0x38(%rbx)
movl $0x3e, 0xef4(%rax)
jmp 0x22a9b
cmpl $0x4, %r8d
jne 0x22a96
movl $0x6, 0xef8(%rax)
testb $0x1, 0x10(%rax)
pushq $0x42
popq %rdx
movl $0xad, %esi
cmovel %edx, %esi
pushq $0x3e
popq %rdx
movl $0xa9, %edi
cmovel %edx, %edi
movl %esi, 0x38(%rbx)
movl %edi, 0xef4(%rax)
incl %ecx
movl %ecx, 0x5c(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %edx, %edx
je 0x22ad8
cmpl $0x3, %edx
je 0x22bdf
jmp 0x22a9b
leaq 0x2d23a(%rip), %rdx     # 0x4fcfa
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
movl 0xe44(%rax), %edx
movl 0xe3c(%rax), %edi
orl %edx, %edi
testb $0x1, %dil
jne 0x22b11
movl 0x5c(%rax), %edx
cmpl %ecx, %edx
jne 0x22c73
incl %ebp
movl %ebp, 0x5c(%rax)
jmp 0x22a9b
movl $0xad, 0x38(%rbx)
movl $0xa9, 0xef4(%rax)
jmp 0x22a9b
andl $-0x2, %edx
movl %edx, 0xe44(%rax)
movslq 0xe38(%rax), %rcx
testq %rcx, %rcx
je 0x22ba3
movl 0x318(%rax,%rcx,4), %ecx
movq 0x730(%rax), %rdx
cmpl 0x5c(%rdx), %ecx
jge 0x22ba3
movss 0x4(%r13), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x22b8c
movq 0x43ab1(%rip), %rax     # 0x66600
movq 0x20(%rax), %r14
leaq 0x2d1d5(%rip), %rdi     # 0x4fd2f
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x2c3c0(%rip), %xmm0    # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movss 0x2c3aa(%rip), %xmm0    # 0x4ef28
addss 0x4(%r13), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
callq 0x19430
movq 0x58(%rbx), %rax
movl 0xe78(%rax), %edx
jmp 0x22aae
incl %esi
movl %esi, 0x5c(%rax)
movl $0x3, 0xe78(%rax)
movl $0x4, 0xef8(%rax)
testb $0x1, 0x10(%rax)
pushq $0x2d
popq %rcx
movl $0x9f, %edx
cmovel %ecx, %edx
pushq $0x35
popq %rcx
movl $0xa8, %esi
cmovel %ecx, %esi
movl %edx, 0x38(%rbx)
movl %esi, 0xef4(%rax)
movl (%r15), %ecx
testl %ecx, %ecx
je 0x22c54
addq $0x4, %r15
cmpl %ecx, 0x5c(%rax)
jne 0x22bdf
cvtsi2ssl (%r13), %xmm0
movss 0xf04(%rax), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x22c34
movq 0x439f7(%rip), %rax     # 0x66600
movq 0x20(%rax), %r14
leaq 0x2ff9d(%rip), %rdi     # 0x52bb1
callq *0x48(%rax)
pushq $0x3
popq %rsi
movss 0x2c306(%rip), %xmm0    # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movq 0x58(%rbx), %rax
movl $0x1, 0xf70(%rax)
movq %rbx, %rdi
callq *%r12
cmpl $0x0, -0x4(%r15)
movq 0x58(%rbx), %rax
je 0x22c54
movl 0x5c(%rax), %ecx
jmp 0x22c5c
movl 0x5c(%rax), %ecx
incl %ecx
movl %ecx, 0x5c(%rax)
addl $0x2, %ebp
cmpl %ebp, %ecx
jne 0x22a9b
andl $0x0, 0xe78(%rax)
jmp 0x22a9b
testq %r14, %r14
je 0x22c9d
movl (%r14), %ecx
movq 0x58(%rbx), %rax
movl 0x5c(%rax), %edx
testl %ecx, %ecx
je 0x22c9d
cmpl %ecx, %edx
jne 0x22c97
callq 0x19bf0
testb $0xf, %al
jne 0x22a9b
addq $0x4, %r14
jmp 0x22c78
cmpl $0x23, %edx
jne 0x22cd7
movq 0x43957(%rip), %rax     # 0x66600
movq 0x20(%rax), %r14
leaq 0x2d08e(%rip), %rdi     # 0x4fd42
callq *0x48(%rax)
pushq $0x1
popq %rsi
movss 0x2c266(%rip), %xmm0    # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movq 0x58(%rbx), %rax
movl 0x5c(%rax), %edx
incl %edx
movl %edx, 0x5c(%rax)
jmp 0x22a9b
nopl (%rax)