// File: /workspace/github_c_makefile_star2_O3/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 0x4e3a0(%rip), %rbx     # 0x99080
cmpl $0x1, 0x118(%rbx)
jne 0x4ad0a
movq 0x1e0b0(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x81f7(%rip), %xmm0     # 0x52ef4
movss %xmm0, 0x1dc(%rbx)
jmp 0x4b2db
movl 0x30c(%rbx), %r14d
movq 0x4e370(%rip), %rax     # 0x99088
movl 0xee8(%rax), %ebp
movl %r14d, 0xee8(%rax)
movq 0x1e074(%rip), %r15     # 0x68da0
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 0x4ad95
leaq 0x4(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x18ef0
movq 0x4e306(%rip), %rbx     # 0x99080
movl 0x308(%rbx), %eax
testb $0x8, %al
jne 0x4ae03
testb $0x30, %al
je 0x4ae33
leaq 0xdfa9(%rip), %rdi      # 0x58d3c
jmp 0x4ae0a
testl %r14d, %r14d
setne %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
jne 0x4ae57
leaq 0x4(%rbx), %rsi
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x18ef0
movq 0x1d840(%rip), %rax     # 0x68600
movq 0x20(%rax), %r13
movq 0x4e2b5(%rip), %rbx     # 0x99080
leaq 0xdf7d(%rip), %rdi      # 0x58d4f
callq *0x48(%rax)
movss 0x814b(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x4, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r13
movq 0x4e289(%rip), %rbx     # 0x99080
andl $-0x9, 0x11c(%rbx)
jmp 0x4aea1
leaq 0xfe62(%rip), %rdi      # 0x5ac6c
movq 0x1d7ef(%rip), %rax     # 0x68600
movq 0x20(%rax), %r12
callq *0x48(%rax)
movss 0x8108(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x4, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x4e246(%rip), %rbx     # 0x99080
orl $0x8, 0x11c(%rbx)
movss 0x4(%r15), %xmm0
addss 0xae05(%rip), %xmm0     # 0x55c54
movss %xmm0, 0x248(%rbx)
cmpl $0x3, %ebp
setne %al
cmpl $0x3, %r14d
sete %r12b
andb %r12b, %al
cmpb $0x1, %al
jne 0x4aea1
movq 0x1d78d(%rip), %rax     # 0x68600
movq 0x20(%rax), %r12
leaq 0xdee5(%rip), %rdi      # 0x58d63
callq *0x48(%rax)
movss 0x809f(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x4, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
jmp 0x4af56
cmpl $0x3, %ebp
sete %al
cmpl $0x3, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4af4d
movss 0x1dc(%rbx), %xmm0
movss 0x4(%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x4af10
movq 0x1d72d(%rip), %rax     # 0x68600
movq 0x20(%rax), %r13
leaq 0xde3c(%rip), %rdi      # 0x58d1a
callq *0x48(%rax)
movss 0x803f(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r13
movq 0x4e17d(%rip), %rdi     # 0x99080
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x18ef0
jmp 0x4af4d
addss 0xfd00(%rip), %xmm1     # 0x5ac18
ucomiss %xmm0, %xmm1
jbe 0x4af4d
movq 0x1d6dc(%rip), %rax     # 0x68600
movq 0x20(%rax), %r13
leaq 0xddfc(%rip), %rdi      # 0x58d2b
callq *0x48(%rax)
movss 0x7fee(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r13
testb %r12b, %r12b
je 0x4b0be
movss 0xc(%rsp), %xmm1
movss 0x14(%rsp), %xmm0
ucomiss %xmm1, %xmm0
movq 0x4e114(%rip), %rbx     # 0x99080
movss 0x4(%r15), %xmm0
ja 0x4af83
movss 0x10(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x4b03c
movss 0x7f89(%rip), %xmm1     # 0x52f14
addss %xmm0, %xmm1
movss %xmm1, 0x1dc(%rbx)
movq 0x4e0ea(%rip), %rax     # 0x99088
xorps %xmm1, %xmm1
cvtsi2ssl (%r15), %xmm1
movss 0xf0c(%rax), %xmm2
subss %xmm1, %xmm2
cvttss2si %xmm2, %ecx
imull $0xc28f5c29, %ecx, %ecx # imm = 0xC28F5C29
addl $0x51eb851, %ecx        # imm = 0x51EB851
cmpl $0xa3d70a2, %ecx        # imm = 0xA3D70A2
ja 0x4b036
cmpl $0x0, 0xeec(%rax)
movq 0x1d628(%rip), %rax     # 0x68600
movq 0x20(%rax), %r12
leaq 0xdd93(%rip), %rcx      # 0x58d76
leaq 0xdda1(%rip), %rdi      # 0x58d8b
cmoveq %rcx, %rdi
callq *0x48(%rax)
movss 0x7f2f(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movq 0x4e078(%rip), %rax     # 0x99088
xorl $0x1, 0xeec(%rax)
movq 0x4e062(%rip), %rdi     # 0x99080
leaq 0x4(%rdi), %rsi
xorl %edx, %edx
callq 0x18ef0
movq 0x4e050(%rip), %rbx     # 0x99080
movss 0x4(%r15), %xmm0
movss 0xc(%rsp), %xmm1
ucomiss 0x1dc(%rbx), %xmm0
jbe 0x4b171
movq 0x58(%rbx), %rcx
ucomiss 0xee4(%rcx), %xmm0
jbe 0x4b171
movl 0x254(%rbx), %eax
testl %eax, %eax
jle 0x4b171
addss 0x7eb8(%rip), %xmm0     # 0x52f28
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 0x4b0ea
callq 0x19a10
movq 0x1d55e(%rip), %rcx     # 0x68600
movq 0x20(%rcx), %r12
movq 0x48(%rcx), %rcx
movq 0x4dfcf(%rip), %rbx     # 0x99080
testb $0x1, %al
jne 0x4b101
leaq 0xdb18(%rip), %rdi      # 0x58bd4
jmp 0x4b108
movss 0x4(%r15), %xmm0
addss 0x7e28(%rip), %xmm0     # 0x52ef4
movq 0x4dfad(%rip), %rax     # 0x99080
movss %xmm0, 0x1dc(%rax)
movl $0x2, 0x280(%rax)
jmp 0x4b16b
movq 0x1d50f(%rip), %rax     # 0x68600
movq 0x20(%rax), %r12
leaq 0xfb83(%rip), %rdi      # 0x5ac7f
callq *0x48(%rax)
jmp 0x4b10a
leaq 0xdac1(%rip), %rdi      # 0x58bc9
callq *%rcx
movss 0x7e16(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movss 0x4(%r15), %xmm0
movq 0x4df4e(%rip), %rdi     # 0x99080
movss %xmm0, 0x244(%rdi)
movq 0x1d417(%rip), %rax     # 0x68558
movq (%rax), %rdx
leaq 0x4(%rdi), %r8
movl 0x280(%rdi), %eax
movq 0x1d613(%rip), %rcx     # 0x68768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x11
pushq $0x2
pushq $0x0
pushq %rax
callq 0x190f0
addq $0x20, %rsp
movss 0xc(%rsp), %xmm1
testl %r14d, %r14d
je 0x4b2db
movq 0x4deff(%rip), %rdi     # 0x99080
movl 0x308(%rdi), %eax
testb $0x18, %al
je 0x4b2db
testb $0x8, %al
je 0x4b29e
cmpl $0x0, 0x254(%rdi)
jle 0x4b23b
movss 0x4(%r15), %xmm0
ucomiss 0x244(%rdi), %xmm0
jb 0x4b23b
xorps %xmm0, %xmm0
cvtsi2ssl (%r15), %xmm0
movq 0x4dec2(%rip), %rax     # 0x99088
ucomiss 0xf08(%rax), %xmm0
jbe 0x4b23b
callq 0x19a10
testb $0x1, %al
movq 0x1d423(%rip), %rax     # 0x68600
movq 0x20(%rax), %r12
movq 0x4de98(%rip), %rbx     # 0x99080
leaq 0xfab3(%rip), %rcx      # 0x5aca2
leaq 0xfa9b(%rip), %rdi      # 0x5ac91
cmoveq %rcx, %rdi
callq *0x48(%rax)
movss 0x7d23(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r12
movss 0xc(%rsp), %xmm1
movss 0x7d02(%rip), %xmm0     # 0x52f28
addss 0x4(%r15), %xmm0
movq 0x4de4d(%rip), %rdi     # 0x99080
movss %xmm0, 0x244(%rdi)
leaq 0x4(%rdi), %r8
movss 0x10(%rsp), %xmm0
ucomiss %xmm1, %xmm0
movq 0x1d309(%rip), %rax     # 0x68558
movq (%rax), %rdx
jbe 0x4b267
xorl %eax, %eax
movq 0x1d50b(%rip), %rcx     # 0x68768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x13
jmp 0x4b2cc
leal (%r14,%r14,2), %eax
xorl %r10d, %r10d
movq 0x1d4f3(%rip), %rcx     # 0x68768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x13
pushq %r10
pushq %r10
pushq %rax
callq 0x190f0
movss 0x2c(%rsp), %xmm1
addq $0x20, %rsp
movq 0x4dde8(%rip), %rdi     # 0x99080
movl 0x308(%rdi), %eax
testb $0x10, %al
je 0x4b2db
movss 0x10(%rsp), %xmm0
ucomiss %xmm1, %xmm0
ja 0x4b2db
movq 0x1d2a4(%rip), %rax     # 0x68558
movq (%rax), %rdx
leaq 0x4(%rdi), %r8
xorl %eax, %eax
movq 0x1d4a4(%rip), %rcx     # 0x68768
movq %rdx, %rsi
movq %rcx, %r9
pushq $0x12
pushq %rax
pushq %rax
pushq %r14
callq 0x190f0
addq $0x38, %rsp
jmp 0x4b2df
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq