// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x10, %rsp
movq 0x4e66e(%rip), %rdi     # 0x9a080
cmpl $0x1, 0x118(%rdi)
jne 0x4ba3c
movq 0x1e37e(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
addss 0x84c5(%rip), %xmm0     # 0x53ef4
movss %xmm0, 0x1dc(%rdi)
jmp 0x4bf65
movl 0x30c(%rdi), %r14d
movq 0x4e63e(%rip), %rax     # 0x9a088
movl 0xee8(%rax), %ebp
movl %r14d, 0xee8(%rax)
movq 0x1e342(%rip), %r15     # 0x69da0
cvtsi2ssl (%r15), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0xf0c(%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xf10(%rax), %xmm0
movss %xmm0, 0x8(%rsp)
testl %ebp, %ebp
sete %al
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4bb14
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x18ef0
movq 0x4e5d7(%rip), %rbx     # 0x9a080
movl 0x308(%rbx), %eax
testb $0x8, %al
jne 0x4bac0
testb $0x30, %al
je 0x4baf0
leaq 0xe06a(%rip), %rdi      # 0x59b28
jmp 0x4bac7
leaq 0xfe75(%rip), %rdi      # 0x5b93c
movq 0x1db32(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
callq *0x48(%rax)
movss 0x844b(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x4, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x4e589(%rip), %rax     # 0x9a080
orl $0x8, 0x11c(%rax)
movss 0x4(%r15), %xmm0
addss 0xb0f4(%rip), %xmm0     # 0x56c00
movss %xmm0, 0x248(%rax)
testl %r14d, %r14d
setne %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
jne 0x4bb7a
movq 0x4e556(%rip), %rdi     # 0x9a080
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x18ef0
movq 0x1dac4(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
movq 0x4e539(%rip), %rbx     # 0x9a080
leaq 0xdfed(%rip), %rdi      # 0x59b3b
callq *0x48(%rax)
movss 0x83cf(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x4, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x4e50d(%rip), %rax     # 0x9a080
andl $-0x9, 0x11c(%rax)
cmpl $0x3, %ebp
setne %al
cmpl $0x3, %r14d
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4bbc5
movq 0x1da6b(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
movq 0x4e4e0(%rip), %rbx     # 0x9a080
leaq 0xdfa8(%rip), %rdi      # 0x59b4f
callq *0x48(%rax)
movss 0x8376(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x4, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
cmpl $0x3, %ebp
sete %al
cmpl $0x3, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4bc78
movq 0x4e49c(%rip), %rbx     # 0x9a080
movss 0x1dc(%rbx), %xmm0
movss 0x4(%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x4bc3b
movq 0x1da02(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
leaq 0xdefd(%rip), %rdi      # 0x59b06
callq *0x48(%rax)
movss 0x8314(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x4e452(%rip), %rdi     # 0x9a080
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x18ef0
jmp 0x4bc78
addss 0xfcad(%rip), %xmm1     # 0x5b8f0
ucomiss %xmm0, %xmm1
jbe 0x4bc78
movq 0x1d9b1(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
leaq 0xdebd(%rip), %rdi      # 0x59b17
callq *0x48(%rax)
movss 0x82c3(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
cmpl $0x3, %r14d
jne 0x4bde9
movss 0xc(%rsp), %xmm0
ucomiss 0x4(%rsp), %xmm0
ja 0x4bca0
movss 0x8(%rsp), %xmm0
ucomiss 0x4(%rsp), %xmm0
jbe 0x4bd4f
movss 0x4(%r15), %xmm0
addss 0x8266(%rip), %xmm0     # 0x53f14
movq 0x4e3cb(%rip), %rbx     # 0x9a080
movss %xmm0, 0x1dc(%rbx)
movq 0x4e3c4(%rip), %rax     # 0x9a088
xorps %xmm0, %xmm0
cvtsi2ssl (%r15), %xmm0
movss 0xf0c(%rax), %xmm1
subss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
imull $0xc28f5c29, %ecx, %ecx # imm = 0xC28F5C29
addl $0x51eb851, %ecx        # imm = 0x51EB851
cmpl $0xa3d70a2, %ecx        # imm = 0xA3D70A2
ja 0x4bd4f
cmpl $0x0, 0xeec(%rax)
movq 0x1d902(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
leaq 0xde59(%rip), %rcx      # 0x59b62
leaq 0xde67(%rip), %rdi      # 0x59b77
cmoveq %rcx, %rdi
callq *0x48(%rax)
movss 0x8209(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x4e352(%rip), %rax     # 0x9a088
xorl $0x1, 0xeec(%rax)
movq 0x4e33c(%rip), %rdi     # 0x9a080
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x18ef0
movq 0x4e32a(%rip), %rbx     # 0x9a080
movss 0x4(%r15), %xmm0
ucomiss 0x1dc(%rbx), %xmm0
jbe 0x4be10
movq 0x58(%rbx), %rcx
ucomiss 0xee4(%rcx), %xmm0
jbe 0x4be10
movl 0x254(%rbx), %eax
testl %eax, %eax
jle 0x4be10
addss 0x8198(%rip), %xmm0     # 0x53f28
movss %xmm0, 0xee4(%rcx)
movl 0x280(%rbx), %ecx
leal 0x2(%rcx), %edx
cmpl $0xe, %ecx
movl $0xf, %ecx
cmovll %edx, %ecx
movl %ecx, 0x280(%rbx)
cmpl %ecx, %eax
jle 0x4bf72
callq 0x19a20
movq 0x1d83a(%rip), %rcx     # 0x69600
movq 0x20(%rcx), %r12
movq 0x48(%rcx), %rcx
movq 0x4e2ab(%rip), %rbx     # 0x9a080
testb $0x1, %al
jne 0x4bf89
leaq 0xdbdc(%rip), %rdi      # 0x599c0
jmp 0x4bf90
movss 0x4(%r15), %xmm0
addss 0x80fd(%rip), %xmm0     # 0x53ef4
movq 0x4e282(%rip), %rax     # 0x9a080
movss %xmm0, 0x1dc(%rax)
movl $0x2, 0x280(%rax)
testl %r14d, %r14d
je 0x4bf65
movq 0x4e260(%rip), %rax     # 0x9a080
movl 0x308(%rax), %ecx
testb $0x18, %cl
je 0x4bf65
testb $0x8, %cl
je 0x4bf1a
cmpl $0x0, 0x254(%rax)
jle 0x4bed2
movss 0x4(%r15), %xmm0
ucomiss 0x244(%rax), %xmm0
jb 0x4bed2
xorps %xmm0, %xmm0
cvtsi2ssl (%r15), %xmm0
movq 0x4e225(%rip), %rax     # 0x9a088
ucomiss 0xf08(%rax), %xmm0
jbe 0x4bed2
callq 0x19a20
testb $0x1, %al
movq 0x1d786(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
movq 0x4e1fb(%rip), %rbx     # 0x9a080
leaq 0xfae6(%rip), %rcx      # 0x5b972
leaq 0xface(%rip), %rdi      # 0x5b961
cmoveq %rcx, %rdi
callq *0x48(%rax)
movss 0x8086(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movss 0x806b(%rip), %xmm0     # 0x53f28
addss 0x4(%r15), %xmm0
movq 0x4e1b6(%rip), %rax     # 0x9a080
movss %xmm0, 0x244(%rax)
movq 0x4e1a7(%rip), %rdi     # 0x9a080
leaq 0x4(%rdi), %r8
movss 0x8(%rsp), %xmm0
ucomiss 0x4(%rsp), %xmm0
movq 0x1d669(%rip), %rax     # 0x69558
movq (%rax), %rdx
leal (%r14,%r14,2), %eax
cmoval %r14d, %eax
xorl %r10d, %r10d
movq 0x1d864(%rip), %rcx     # 0x69768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x13
pushq %r10
pushq %r10
pushq %rax
callq 0x190f0
addq $0x20, %rsp
movq 0x4e15f(%rip), %rdi     # 0x9a080
testb $0x10, 0x308(%rdi)
je 0x4bf65
movss 0x8(%rsp), %xmm0
ucomiss 0x4(%rsp), %xmm0
ja 0x4bf65
movq 0x1d61a(%rip), %rax     # 0x69558
movq (%rax), %rdx
leaq 0x4(%rdi), %r8
xorl %eax, %eax
movq 0x1d81a(%rip), %rcx     # 0x69768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x12
pushq %rax
pushq %rax
pushq %r14
callq 0x190f0
addq $0x30, %rsp
jmp 0x4bf69
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x1d687(%rip), %rax     # 0x69600
movq 0x20(%rax), %r12
leaq 0xf9cb(%rip), %rdi      # 0x5b94f
callq *0x48(%rax)
jmp 0x4bf92
leaq 0xda25(%rip), %rdi      # 0x599b5
callq *%rcx
movss 0x7f8e(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movss 0x4(%r15), %xmm0
movq 0x4e0c6(%rip), %rdi     # 0x9a080
movss %xmm0, 0x244(%rdi)
movq 0x1d58f(%rip), %rax     # 0x69558
movq (%rax), %rdx
leaq 0x4(%rdi), %r8
movl 0x280(%rdi), %eax
movq 0x1d78b(%rip), %rcx     # 0x69768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x11
pushq $0x2
pushq $0x0
pushq %rax
callq 0x190f0
addq $0x20, %rsp
jmp 0x4be10