// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/p_view.c
// Function: P_WorldEffects
void P_WorldEffects (void)
{
	qboolean	breather;
	qboolean	envirosuit;
	int			waterlevel, old_waterlevel;

	if (current_player->movetype == MOVETYPE_NOCLIP)
	{
		current_player->air_finished = level.time + 12;	// don't need air
		return;
	}

	waterlevel = current_player->waterlevel;
	old_waterlevel = current_client->old_waterlevel;
	current_client->old_waterlevel = waterlevel;

	breather = current_client->breather_framenum > level.framenum;
	envirosuit = current_client->enviro_framenum > level.framenum;

	//
	// if just entered a water volume, play a sound
	//
	if (!old_waterlevel && waterlevel)
	{
		PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
		if (current_player->watertype & CONTENTS_LAVA)
			gi.sound (current_player, CHAN_BODY, gi.soundindex("player/lava_in.wav"), 1, ATTN_NORM, 0);
		else if (current_player->watertype & CONTENTS_SLIME)
			gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
		else if (current_player->watertype & CONTENTS_WATER)
			gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
		current_player->flags |= FL_INWATER;

		// clear damage_debounce, so the pain sound will play immediately
		current_player->damage_debounce_time = level.time - 1;
	}

	//
	// if just completely exited a water volume, play a sound
	//
	if (old_waterlevel && ! waterlevel)
	{
		PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
		gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
		current_player->flags &= ~FL_INWATER;
	}

	//
	// check for head just going under water
	//
	if (old_waterlevel != 3 && waterlevel == 3)
	{
		gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_un.wav"), 1, ATTN_NORM, 0);
	}

	//
	// check for head just coming out of water
	//
	if (old_waterlevel == 3 && waterlevel != 3)
	{
		if (current_player->air_finished < level.time)
		{	// gasp for air
			gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/gasp1.wav"), 1, ATTN_NORM, 0);
			PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
		}
		else  if (current_player->air_finished < level.time + 11)
		{	// just break surface
			gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/gasp2.wav"), 1, ATTN_NORM, 0);
		}
	}

	//
	// check for drowning
	//
	if (waterlevel == 3)
	{
		// breather or envirosuit give air
		if (breather || envirosuit)
		{
			current_player->air_finished = level.time + 10;

			if (((int)(current_client->breather_framenum - level.framenum) % 25) == 0)
			{
				if (!current_client->breather_sound)
					gi.sound (current_player, CHAN_AUTO, gi.soundindex("player/u_breath1.wav"), 1, ATTN_NORM, 0);
				else
					gi.sound (current_player, CHAN_AUTO, gi.soundindex("player/u_breath2.wav"), 1, ATTN_NORM, 0);
				current_client->breather_sound ^= 1;
				PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
				//FIXME: release a bubble?
			}
		}

		// if out of air, start drowning
		if (current_player->air_finished < level.time)
		{	// drown!
			if (current_player->client->next_drown_time < level.time 
				&& current_player->health > 0)
			{
				current_player->client->next_drown_time = level.time + 1;

				// take more damage the longer underwater
				current_player->dmg += 2;
				if (current_player->dmg > 15)
					current_player->dmg = 15;

				// play a gurp sound instead of a normal pain sound
				if (current_player->health <= current_player->dmg)
					gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/drown1.wav"), 1, ATTN_NORM, 0);
				else if (rand()&1)
					gi.sound (current_player, CHAN_VOICE, gi.soundindex("*gurp1.wav"), 1, ATTN_NORM, 0);
				else
					gi.sound (current_player, CHAN_VOICE, gi.soundindex("*gurp2.wav"), 1, ATTN_NORM, 0);

				current_player->pain_debounce_time = level.time;

				T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, current_player->dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
			}
		}
	}
	else
	{
		current_player->air_finished = level.time + 12;
		current_player->dmg = 2;
	}

	//
	// check for sizzle damage
	//
	if (waterlevel && (current_player->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) )
	{
		if (current_player->watertype & CONTENTS_LAVA)
		{
			if (current_player->health > 0
				&& current_player->pain_debounce_time <= level.time
				&& current_client->invincible_framenum < level.framenum)
			{
				if (rand()&1)
					gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/burn1.wav"), 1, ATTN_NORM, 0);
				else
					gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/burn2.wav"), 1, ATTN_NORM, 0);
				current_player->pain_debounce_time = level.time + 1;
			}

			if (envirosuit)	// take 1/3 damage with envirosuit
				T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1*waterlevel, 0, 0, MOD_LAVA);
			else
				T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 3*waterlevel, 0, 0, MOD_LAVA);
		}

		if (current_player->watertype & CONTENTS_SLIME)
		{
			if (!envirosuit)
			{	// no damage from slime with envirosuit
				T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1*waterlevel, 0, 0, MOD_SLIME);
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x504ed(%rip), %rbx     # 0x97180
cmpl $0x1, 0x118(%rbx)
jne 0x46cbd
movq 0x200fd(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
addss 0x8244(%rip), %xmm0     # 0x4eef4
movss %xmm0, 0x1dc(%rbx)
jmp 0x47252
movl 0x30c(%rbx), %r14d
movq 0x504bd(%rip), %rax     # 0x97188
movl 0xee8(%rax), %ebp
movl %r14d, 0xee8(%rax)
movq 0x200c1(%rip), %r15     # 0x66da0
cvtsi2ssl (%r15), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xf0c(%rax), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0xf10(%rax), %xmm0
movss %xmm0, 0x10(%rsp)
testl %ebp, %ebp
sete %al
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x46d48
leaq 0x4(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x19010
movq 0x50453(%rip), %rbx     # 0x97180
movl 0x308(%rbx), %eax
testb $0x8, %al
jne 0x46db4
testb $0x30, %al
je 0x46de2
leaq 0xdfd6(%rip), %rdi      # 0x54d1c
jmp 0x46dbb
testl %r14d, %r14d
setne %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
jne 0x46e06
leaq 0x4(%rbx), %rsi
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x19010
movq 0x1f88d(%rip), %rax     # 0x66600
movq 0x20(%rax), %r13
movq 0x50402(%rip), %rbx     # 0x97180
leaq 0xdfaa(%rip), %rdi      # 0x54d2f
callq *0x48(%rax)
pushq $0x4
popq %rsi
movss 0x8195(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r13
movq 0x503d8(%rip), %rbx     # 0x97180
andl $-0x9, 0x11c(%rbx)
jmp 0x46e4e
leaq 0xfe71(%rip), %rdi      # 0x56c2c
movq 0x1f83e(%rip), %rax     # 0x66600
movq 0x20(%rax), %r12
callq *0x48(%rax)
pushq $0x4
popq %rsi
movss 0x8154(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x50397(%rip), %rbx     # 0x97180
orl $0x8, 0x11c(%rbx)
movss 0x4(%r15), %xmm0
addss 0xae36(%rip), %xmm0     # 0x51c34
movss %xmm0, 0x248(%rbx)
cmpl $0x3, %ebp
setne %al
cmpl $0x3, %r14d
sete %r12b
andb %r12b, %al
cmpb $0x1, %al
jne 0x46e4e
movq 0x1f7de(%rip), %rax     # 0x66600
movq 0x20(%rax), %r12
leaq 0xdf16(%rip), %rdi      # 0x54d43
callq *0x48(%rax)
pushq $0x4
popq %rsi
movss 0x80ed(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
jmp 0x46eff
cmpl $0x3, %ebp
sete %al
cmpl $0x3, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x46ef6
movss 0x1dc(%rbx), %xmm0
movss 0x4(%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x46ebb
movq 0x1f780(%rip), %rax     # 0x66600
movq 0x20(%rax), %r13
leaq 0xde6f(%rip), %rdi      # 0x54cfa
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x808f(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r13
movq 0x502d2(%rip), %rdi     # 0x97180
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x19010
jmp 0x46ef6
addss 0xfd15(%rip), %xmm1     # 0x56bd8
ucomiss %xmm0, %xmm1
jbe 0x46ef6
movq 0x1f731(%rip), %rax     # 0x66600
movq 0x20(%rax), %r13
leaq 0xde31(%rip), %rdi      # 0x54d0b
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x8040(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r13
testb %r12b, %r12b
je 0x47058
movss 0xc(%rsp), %xmm1
movss 0x14(%rsp), %xmm0
ucomiss %xmm1, %xmm0
movq 0x5026b(%rip), %rbx     # 0x97180
movss 0x4(%r15), %xmm0
ja 0x46f2c
movss 0x10(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x46fd8
movss 0x7fe0(%rip), %xmm1     # 0x4ef14
addss %xmm0, %xmm1
movss %xmm1, 0x1dc(%rbx)
movq 0x50241(%rip), %rcx     # 0x97188
movss 0xf0c(%rcx), %xmm1
cvtsi2ssl (%r15), %xmm2
subss %xmm2, %xmm1
cvttss2si %xmm1, %eax
pushq $0x19
popq %rsi
cltd
idivl %esi
testl %edx, %edx
jne 0x46fd2
cmpl $0x0, 0xeec(%rcx)
movq 0x1f68c(%rip), %rax     # 0x66600
movq 0x20(%rax), %r12
leaq 0xddd7(%rip), %rcx      # 0x54d56
leaq 0xdde5(%rip), %rdi      # 0x54d6b
cmoveq %rcx, %rdi
callq *0x48(%rax)
movss 0x7f93(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x501dc(%rip), %rax     # 0x97188
xorl $0x1, 0xeec(%rax)
movq 0x501c6(%rip), %rdi     # 0x97180
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x19010
movq 0x501b4(%rip), %rbx     # 0x97180
movss 0x4(%r15), %xmm0
movss 0xc(%rsp), %xmm1
ucomiss 0x1dc(%rbx), %xmm0
jbe 0x47106
movq 0x58(%rbx), %rcx
ucomiss 0xee4(%rcx), %xmm0
jbe 0x47106
movl 0x254(%rbx), %eax
testl %eax, %eax
jle 0x47106
addss 0x7f1c(%rip), %xmm0     # 0x4ef28
movss %xmm0, 0xee4(%rcx)
movl 0x280(%rbx), %ecx
leal 0x2(%rcx), %edx
cmpl $0xe, %ecx
pushq $0xf
popq %rcx
cmovll %edx, %ecx
movl %ecx, 0x280(%rbx)
cmpl %ecx, %eax
jle 0x47081
callq 0x19bf0
movq 0x1f5c4(%rip), %rcx     # 0x66600
movq 0x20(%rcx), %r12
movq 0x48(%rcx), %rcx
movq 0x50135(%rip), %rbx     # 0x97180
testb $0x1, %al
jne 0x47098
leaq 0xdb5e(%rip), %rdi      # 0x54bb4
jmp 0x4709f
movss 0x4(%r15), %xmm0
addss 0x7e8e(%rip), %xmm0     # 0x4eef4
movq 0x50113(%rip), %rax     # 0x97180
movss %xmm0, 0x1dc(%rax)
movl $0x2, 0x280(%rax)
jmp 0x47100
movq 0x1f578(%rip), %rax     # 0x66600
movq 0x20(%rax), %r12
leaq 0xfbac(%rip), %rdi      # 0x56c3f
callq *0x48(%rax)
jmp 0x470a1
leaq 0xdb0a(%rip), %rdi      # 0x54ba9
callq *%rcx
pushq $0x2
popq %rsi
movss 0x7e7c(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movss 0x4(%r15), %xmm0
movq 0x500b9(%rip), %rdi     # 0x97180
movss %xmm0, 0x244(%rdi)
movq 0x1f482(%rip), %rax     # 0x66558
movq (%rax), %rdx
leaq 0x4(%rdi), %r8
movl 0x280(%rdi), %eax
movq 0x1f67e(%rip), %rcx     # 0x66768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x11
pushq $0x2
pushq $0x0
pushq %rax
callq 0x19260
addq $0x20, %rsp
movss 0xc(%rsp), %xmm1
testl %r14d, %r14d
je 0x47252
movq 0x5006a(%rip), %rdi     # 0x97180
movl 0x308(%rdi), %eax
testb $0x18, %al
je 0x47252
testb $0x8, %al
je 0x47209
cmpl $0x0, 0x254(%rdi)
jle 0x471c7
movss 0x4(%r15), %xmm0
ucomiss 0x244(%rdi), %xmm0
jb 0x471c7
cvtsi2ssl (%r15), %xmm0
movq 0x50034(%rip), %rax     # 0x97188
ucomiss 0xf08(%rax), %xmm0
jbe 0x471c7
callq 0x19bf0
testb $0x1, %al
movq 0x1f495(%rip), %rax     # 0x66600
movq 0x20(%rax), %r12
movq 0x5000a(%rip), %rbx     # 0x97180
leaq 0xfae5(%rip), %rcx      # 0x56c62
leaq 0xfacd(%rip), %rdi      # 0x56c51
cmoveq %rcx, %rdi
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x7d92(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movss 0xc(%rsp), %xmm1
movss 0x7d76(%rip), %xmm0     # 0x4ef28
addss 0x4(%r15), %xmm0
movq 0x4ffc1(%rip), %rdi     # 0x97180
movss %xmm0, 0x244(%rdi)
leaq 0x4(%rdi), %r8
movss 0x10(%rsp), %xmm0
ucomiss %xmm1, %xmm0
movq 0x1f37d(%rip), %rax     # 0x66558
movq (%rax), %rdx
leal (%r14,%r14,2), %eax
cmoval %r14d, %eax
movq 0x1f57b(%rip), %rcx     # 0x66768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x13
pushq $0x0
pushq $0x0
pushq %rax
callq 0x19260
movss 0x2c(%rsp), %xmm1
addq $0x20, %rsp
movq 0x4ff70(%rip), %rdi     # 0x97180
testb $0x10, 0x308(%rdi)
je 0x47252
movss 0x10(%rsp), %xmm0
ucomiss %xmm1, %xmm0
ja 0x47252
movq 0x1f32d(%rip), %rax     # 0x66558
movq (%rax), %rdx
leaq 0x4(%rdi), %r8
movq 0x1f52f(%rip), %rcx     # 0x66768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x12
pushq $0x0
pushq $0x0
pushq %r14
callq 0x19260
addq $0x38, %rsp
jmp 0x47256
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq