// File: /workspace/github_c_makefile_star2_O1/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 0x4a7fc
testb $0x10, 0x11c(%rbx)
jne 0x4a7fc
movq 0x1f5c0(%rip), %rdx     # 0x69da0
cvtsi2ssl (%rdx), %xmm0
ucomiss 0xf08(%r15), %xmm0
jb 0x4a7fc
movzwl %cx, %ecx
orl $0x2, %ecx
movw %cx, 0x96(%r15)
addl %eax, %ebp
addl 0xe5c(%r15), %ebp
je 0x4ac84
cmpl $0x2, 0xef8(%r15)
jg 0x4a8b6
cmpl $0xff, 0x28(%rbx)
jne 0x4a8b6
movl $0x3, 0xef8(%r15)
testb $0x1, 0x10(%r15)
jne 0x4a87c
movl 0x4f816(%rip), %eax     # 0x9a054
movl %eax, %ecx
incl %ecx
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
imulq %rcx, %rdx
shrq $0x21, %rdx
leal (%rdx,%rdx,2), %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x4f7f6(%rip)     # 0x9a054
cmpl $0x2, %eax
je 0x4a890
cmpl $0x1, %eax
jne 0x4a8a4
movl $0x39, 0x38(%rbx)
movl $0x3d, 0xef4(%r15)
jmp 0x4a8b6
movl $0xa8, 0x38(%rbx)
movl $0xac, 0xef4(%r15)
jmp 0x4a8b6
movl $0x3d, 0x38(%rbx)
movl $0x41, 0xef4(%r15)
jmp 0x4a8b6
movl $0x35, 0x38(%rbx)
movl $0x39, 0xef4(%r15)
cmpl $0xb, %ebp
movl $0xa, %r14d
cmovgel %ebp, %r14d
movq 0x1f4d6(%rip), %r12     # 0x69da0
movss 0x4(%r12), %xmm0
ucomiss 0x244(%rbx), %xmm0
jbe 0x4a99a
testb $0x10, 0x11c(%rbx)
jne 0x4a99a
xorps %xmm0, %xmm0
cvtsi2ssl (%r12), %xmm0
ucomiss 0xf08(%r15), %xmm0
jb 0x4a99a
callq 0x19a20
andl $0x1, %eax
incl %eax
xorps %xmm0, %xmm0
cvtss2sd 0x4(%r12), %xmm0
addsd 0xdec2(%rip), %xmm0     # 0x587e0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x244(%rbx)
movl 0x254(%rbx), %ecx
movl $0x19, %esi
cmpl $0x19, %ecx
jl 0x4a954
movl $0x32, %esi
cmpl $0x32, %ecx
jl 0x4a954
cmpl $0x4b, %ecx
movl $0x4b, %ecx
movl $0x64, %esi
cmovll %ecx, %esi
movq 0x1eca5(%rip), %rcx     # 0x69600
movq 0x20(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x48(%rcx), %r13
leaq 0x10f99(%rip), %rdi     # 0x5b908
movl %eax, %edx
xorl %eax, %eax
callq 0x19340
movq %rax, %rdi
callq *%r13
movss 0x95a2(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
xorps %xmm1, %xmm1
ucomiss 0xea8(%r15), %xmm1
jbe 0x4a9ba
movl $0x0, 0xea8(%r15)
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtss2sd 0xea8(%r15), %xmm0
movsd 0x10eb3(%rip), %xmm1    # 0x5b888
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0xc1af(%rip), %xmm2     # 0x56ba8
ucomisd %xmm1, %xmm2
jbe 0x4aa07
movss 0xc4cd(%rip), %xmm0     # 0x56ed4
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
ucomisd 0x10e7a(%rip), %xmm1    # 0x5b890
jbe 0x4aa20
movss 0x10e90(%rip), %xmm0    # 0x5b8b0
leaq 0xe58(%r15), %r13
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
movss %xmm0, 0xea8(%r15)
movl $0x0, 0x1c(%rsp)
movq $0x0, 0x14(%rsp)
movl 0xe5c(%r15), %eax
testl %eax, %eax
movss %xmm1, 0x8(%rsp)
je 0x4aa7e
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x243bd(%rip), %rsi     # 0x6ee28
leaq 0x14(%rsp), %rdi
movq %rdi, %rdx
callq 0x19770
movss 0x8(%rsp), %xmm1
movl (%r13), %eax
testl %eax, %eax
je 0x4aaab
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x2439c(%rip), %rsi     # 0x6ee34
leaq 0x14(%rsp), %rdi
movq %rdi, %rdx
callq 0x19770
movss 0x8(%rsp), %xmm1
movl 0xe60(%r15), %eax
testl %eax, %eax
je 0x4aad5
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x24378(%rip), %rsi     # 0x6ee40
leaq 0x14(%rsp), %rdi
movq %rdi, %rdx
callq 0x19770
movss 0x14(%rsp), %xmm0
movss %xmm0, 0xeb0(%r15)
movss 0x18(%rsp), %xmm0
movss %xmm0, 0xeb4(%r15)
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0xeb8(%r15)
movl 0xe64(%r15), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
jae 0x4ac7c
movl 0x254(%rbx), %ecx
testl %ecx, %ecx
jle 0x4ac7c
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
mulss 0xc38a(%rip), %xmm0     # 0x56ec4
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm2
mulsd 0xc035(%rip), %xmm2     # 0x56b88
ucomisd %xmm1, %xmm2
jbe 0x4ab60
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movss 0x10d4c(%rip), %xmm1    # 0x5b8b4
minss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movss 0xe68(%r15), %xmm0
subss 0x4(%rbx), %xmm0
leaq 0x14(%rsp), %r14
movss %xmm0, (%r14)
movss 0xe6c(%r15), %xmm0
subss 0x8(%rbx), %xmm0
movss %xmm0, 0x4(%r14)
movss 0xe70(%r15), %xmm0
subss 0xc(%rbx), %xmm0
movss %xmm0, 0x8(%r14)
movq %r14, %rdi
callq 0x18390
movss (%r14), %xmm0
movss 0x4(%r14), %xmm1
movss 0x4f47f(%rip), %xmm2    # 0x9a04c
mulss %xmm1, %xmm2
movss 0x4f46f(%rip), %xmm3    # 0x9a048
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x8(%r14), %xmm2
movss 0x4f461(%rip), %xmm4    # 0x9a050
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
movss 0x8(%rsp), %xmm5
mulss %xmm5, %xmm4
xorps %xmm3, %xmm3
cvtss2sd %xmm4, %xmm3
movsd 0xbf90(%rip), %xmm4     # 0x56ba0
mulsd %xmm4, %xmm3
cvtsd2ss %xmm3, %xmm3
movss %xmm3, 0xe94(%r15)
mulss 0x4f433(%rip), %xmm1    # 0x9a05c
mulss 0x4f427(%rip), %xmm0    # 0x9a058
addss %xmm1, %xmm0
mulss 0x4f423(%rip), %xmm2    # 0x9a060
addss %xmm0, %xmm2
xorps 0xbfc8(%rip), %xmm2     # 0x56c10
mulss %xmm5, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
mulsd %xmm4, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe98(%r15)
movss 0x4(%r12), %xmm0
addss 0xa791(%rip), %xmm0     # 0x55404
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