// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/p_view.c
// Function: P_DamageFeedback
void P_DamageFeedback (edict_t *player)
{
	gclient_t	*client;
	float	side;
	float	realcount, count, kick;
	vec3_t	v;
	int		r, l;
	static	vec3_t	power_color = {0.0, 1.0, 0.0};
	static	vec3_t	acolor = {1.0, 1.0, 1.0};
	static	vec3_t	bcolor = {1.0, 0.0, 0.0};

	client = player->client;

	// flash the backgrounds behind the status numbers
	client->ps.stats[STAT_FLASHES] = 0;
	if (client->damage_blood)
		client->ps.stats[STAT_FLASHES] |= 1;
	if (client->damage_armor && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
		client->ps.stats[STAT_FLASHES] |= 2;

	// total points of damage shot at the player this frame
	count = (client->damage_blood + client->damage_armor + client->damage_parmor);
	if (count == 0)
		return;		// didn't take any damage

	// start a pain animation if still in the player model
	if (client->anim_priority < ANIM_PAIN && player->s.modelindex == 255)
	{
		static int		i;

		client->anim_priority = ANIM_PAIN;
		if (client->ps.pmove.pm_flags & PMF_DUCKED)
		{
			player->s.frame = FRAME_crpain1-1;
			client->anim_end = FRAME_crpain4;
		}
		else
		{
			i = (i+1)%3;
			switch (i)
			{
			case 0:
				player->s.frame = FRAME_pain101-1;
				client->anim_end = FRAME_pain104;
				break;
			case 1:
				player->s.frame = FRAME_pain201-1;
				client->anim_end = FRAME_pain204;
				break;
			case 2:
				player->s.frame = FRAME_pain301-1;
				client->anim_end = FRAME_pain304;
				break;
			}
		}
	}

	realcount = count;
	if (count < 10)
		count = 10;	// always make a visible effect

	// play an apropriate pain sound
	if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
	{
		r = 1 + (rand()&1);
		player->pain_debounce_time = level.time + 0.7;
		if (player->health < 25)
			l = 25;
		else if (player->health < 50)
			l = 50;
		else if (player->health < 75)
			l = 75;
		else
			l = 100;
		gi.sound (player, CHAN_VOICE, gi.soundindex(va("*pain%i_%i.wav", l, r)), 1, ATTN_NORM, 0);
	}

	// the total alpha of the blend is always proportional to count
	if (client->damage_alpha < 0)
		client->damage_alpha = 0;
	client->damage_alpha += count*0.01;
	if (client->damage_alpha < 0.2)
		client->damage_alpha = 0.2f;
	if (client->damage_alpha > 0.6)
		client->damage_alpha = 0.6f;		// don't go too saturated

	// the color of the blend will vary based on how much was absorbed
	// by different armors
	VectorClear (v);
	if (client->damage_parmor)
		VectorMA (v, (float)client->damage_parmor/realcount, power_color, v);
	if (client->damage_armor)
		VectorMA (v, (float)client->damage_armor/realcount,  acolor, v);
	if (client->damage_blood)
		VectorMA (v, (float)client->damage_blood/realcount,  bcolor, v);
	VectorCopy (v, client->damage_blend);


	//
	// calculate view angle kicks
	//
	kick = abs(client->damage_knockback);
	if (kick && player->health > 0)	// kick of 0 means no view adjust at all
	{
		kick = kick * 100 / player->health;

		if (kick < count*0.5)
			kick = count*0.5;
		if (kick > 50)
			kick = 50;

		VectorSubtract (client->damage_from, player->s.origin, v);
		VectorNormalize (v);
		
		side = DotProduct (v, right);
		client->v_dmg_roll = kick*side*0.3;
		
		side = -DotProduct (v, forward);
		client->v_dmg_pitch = kick*side*0.3;

		client->v_dmg_time = level.time + DAMAGE_TIME;
	}

	//
	// clear totals
	//
	client->damage_blood = 0;
	client->damage_armor = 0;
	client->damage_parmor = 0;
	client->damage_knockback = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x58(%rdi), %r15
movl 0xe58(%r15), %ebp
movl 0xe60(%r15), %eax
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movw %cx, 0x96(%r15)
testl %ebp, %ebp
je 0x45e0c
testb $0x10, 0x11c(%rbx)
jne 0x45e0c
movq 0x20fb0(%rip), %rdx     # 0x66da0
cvtsi2ssl (%rdx), %xmm0
ucomiss 0xf08(%r15), %xmm0
jb 0x45e0c
movzwl %cx, %ecx
orl $0x2, %ecx
movw %cx, 0x96(%r15)
addl %eax, %ebp
addl 0xe5c(%r15), %ebp
je 0x461e7
cmpl $0x2, 0xef8(%r15)
jg 0x45eb1
cmpl $0xff, 0x28(%rbx)
jne 0x45eb1
movl $0x3, 0xef8(%r15)
testb $0x1, 0x10(%r15)
jne 0x45e77
movl 0x5130a(%rip), %eax     # 0x97154
incl %eax
pushq $0x3
popq %rcx
xorl %edx, %edx
divl %ecx
movl %edx, 0x512fb(%rip)     # 0x97154
cmpl $0x2, %edx
je 0x45e8b
cmpl $0x1, %edx
jne 0x45e9f
movl $0x39, 0x38(%rbx)
movl $0x3d, 0xef4(%r15)
jmp 0x45eb1
movl $0xa8, 0x38(%rbx)
movl $0xac, 0xef4(%r15)
jmp 0x45eb1
movl $0x3d, 0x38(%rbx)
movl $0x41, 0xef4(%r15)
jmp 0x45eb1
movl $0x35, 0x38(%rbx)
movl $0x39, 0xef4(%r15)
cmpl $0xb, %ebp
pushq $0xa
popq %rax
cmovgel %ebp, %eax
cvtsi2ss %eax, %xmm1
movq 0x20edb(%rip), %r12     # 0x66da0
movss 0x4(%r12), %xmm0
ucomiss 0x244(%rbx), %xmm0
jbe 0x45f8e
testb $0x10, 0x11c(%rbx)
jne 0x45f8e
cvtsi2ssl (%r12), %xmm0
ucomiss 0xf08(%r15), %xmm0
jb 0x45f8e
movss %xmm1, 0x10(%rsp)
callq 0x19bf0
andl $0x1, %eax
cvtss2sd 0x4(%r12), %xmm0
addsd 0xdab9(%rip), %xmm0     # 0x539d0
cvtsd2ss %xmm0, %xmm0
incl %eax
movss %xmm0, 0x244(%rbx)
movl 0x254(%rbx), %ecx
cmpl $0x19, %ecx
jge 0x45f34
pushq $0x19
jmp 0x45f3b
cmpl $0x32, %ecx
jae 0x45f3e
pushq $0x32
popq %rsi
jmp 0x45f4a
cmpl $0x4b, %ecx
pushq $0x4b
popq %rcx
pushq $0x64
popq %rsi
cmovbl %ecx, %esi
movq 0x206af(%rip), %rcx     # 0x66600
movq 0x20(%rcx), %r14
movq 0x48(%rcx), %r13
leaq 0x10c98(%rip), %rdi     # 0x56bf8
movl %eax, %edx
xorl %eax, %eax
callq 0x194e0
movq %rax, %rdi
callq *%r13
pushq $0x2
popq %rsi
movss 0x8fae(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movss 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
maxss 0xea8(%r15), %xmm0
cvtss2sd %xmm1, %xmm2
cvtss2sd %xmm0, %xmm0
movsd 0x10bd6(%rip), %xmm1    # 0x56b80
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xbc28(%rip), %xmm2     # 0x51bf0
ucomisd %xmm1, %xmm2
jbe 0x45fd6
movss 0xbfd2(%rip), %xmm0     # 0x51fa8
cvtss2sd %xmm0, %xmm1
ucomisd 0x10ba6(%rip), %xmm1    # 0x56b88
jbe 0x45fec
movss 0x10bb4(%rip), %xmm0    # 0x56ba0
cvtsi2ss %ebp, %xmm1
movss %xmm0, 0xea8(%r15)
andl $0x0, 0x8(%rsp)
andq $0x0, (%rsp)
leaq 0xe58(%r15), %r13
movl 0xe5c(%r15), %eax
testl %eax, %eax
movss %xmm1, 0x10(%rsp)
je 0x4603b
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x25efe(%rip), %rsi     # 0x6bf28
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x19940
movss 0x10(%rsp), %xmm1
movl (%r13), %eax
testl %eax, %eax
je 0x46063
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x25ee2(%rip), %rsi     # 0x6bf34
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x19940
movss 0x10(%rsp), %xmm1
movl 0xe60(%r15), %eax
testl %eax, %eax
je 0x46088
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x25ec3(%rip), %rsi     # 0x6bf40
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x19940
movsd (%rsp), %xmm0
movsd %xmm0, 0xeb0(%r15)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0xeb8(%r15)
movl 0xe64(%r15), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
jae 0x461df
movl 0x254(%rbx), %ecx
testl %ecx, %ecx
jle 0x461df
cvtsi2ss %eax, %xmm0
cvtsi2ss %ecx, %xmm1
mulss 0xbb55(%rip), %xmm0     # 0x51c2c
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm2
mulsd 0xbae3(%rip), %xmm2     # 0x51bd0
ucomisd %xmm1, %xmm2
jbe 0x460f7
cvtsd2ss %xmm2, %xmm0
movss 0x10aa5(%rip), %xmm1    # 0x56ba4
minss %xmm0, %xmm1
movaps %xmm1, 0x10(%rsp)
movsd 0xe68(%r15), %xmm0
movsd 0x4(%rbx), %xmm1
subps %xmm1, %xmm0
movq %rsp, %r14
movlps %xmm0, (%r14)
movss 0xe70(%r15), %xmm0
subss 0xc(%rbx), %xmm0
movss %xmm0, 0x8(%r14)
movq %r14, %rdi
callq 0x183c0
movss (%r14), %xmm0
movss 0x4(%r14), %xmm1
movss 0x50ffd(%rip), %xmm2    # 0x9714c
mulss %xmm1, %xmm2
movss 0x50fed(%rip), %xmm3    # 0x97148
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x8(%r14), %xmm2
movss 0x50fdf(%rip), %xmm4    # 0x97150
mulss %xmm2, %xmm4
mulss 0x50fdf(%rip), %xmm1    # 0x9715c
mulss 0x50fd3(%rip), %xmm0    # 0x97158
mulss 0x50fd3(%rip), %xmm2    # 0x97160
addss %xmm1, %xmm0
addss %xmm0, %xmm2
xorps 0xbb14(%rip), %xmm2     # 0x51cb0
addss %xmm3, %xmm4
unpcklps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
movaps 0x10(%rsp), %xmm0
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
mulps %xmm4, %xmm0
cvtps2pd %xmm0, %xmm0
mulpd 0x10986(%rip), %xmm0    # 0x56b40
cvtpd2ps %xmm0, %xmm0
movlpd %xmm0, 0xe94(%r15)
movss 0x4(%r12), %xmm0
addss 0xa22a(%rip), %xmm0     # 0x50400
movss %xmm0, 0xe9c(%r15)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq