// File: /workspace/github_c_makefile_star2_O3/S01den[P]Lost_CavernRL/ennemy.c
// Function: blastHit
int blastHit(Ennemy enemy, Player *player, Armor *armor, Map map[LONGUEUR][LARGEUR])
{
	int angle = 0;
	int c = 0;
	int hit = 0;
	int degats = 0;

	float ox;
	float oy;
	float k = 0, l = 0;

	for(angle = 0; angle < 360; angle++)
	{
		k = cos((float)angle*0.01745f); // 1° = 0.01745 rad puisque 360° = 2pi rad
		l = sin((float)angle*0.01745f);
		ox = (float)enemy.x+0.5f;
		oy = (float)enemy.y+0.5f;

		if(oy >= 0 && oy <= LARGEUR && ox <= LONGUEUR && ox >= 0 && hit == 0)
		{
			for(c = 0; c < enemy.agility; c++)
			{
				if(player->x == (int)ox && player->y == (int)oy)
				{
					hit = 1;
					degats = enemy.agility*2 +rand()%4+2 - abs(armor->resistance);
					if(degats > 0)
					{
						armor->state -= degats/3;
						player->life -= degats/2;
					}
					if(enemy.type == 2)
					{	
						armor->state -= rand()%5;
						if(rand()%10 == 2)
						{
							if(player->state != 0)
								player->state2 = 2;
							else
								player->state = 2;
						}
						else if(player->state == 2 || player->state2 == 2)
						{
							degats = enemy.agility*2 + rand()%3+1;
							degats -= abs(armor->resistance);
							armor->state -= degats/3;
							player->life -= degats/2;							
						}
					}

					break;
				}
				if(map[(int)ox][(int)oy].content == DOOR)
				{
					break;
				}
				else if(map[(int)ox][(int)oy].content == WALL)
				{
					map[(int)ox][(int)oy].resistance -= degats;
					if(map[(int)ox][(int)oy].resistance <= 0)
					{
						map[(int)ox][(int)oy].resistance = 0;
						map[(int)ox][(int)oy].content = FLOOR;
					}
					break;
				}
				
				ox+=k;
				oy+=l;
			}			
		}

		if(hit == 1)
			break;
	}

	return degats;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x70(%rsp), %rdx
movsd (%rdx), %xmm0
cvtdq2ps %xmm0, %xmm4
addps 0x9387(%rip), %xmm4     # 0xff40
movaps %xmm4, %xmm0
shufps $0x55, %xmm4, %xmm0     # xmm0 = xmm0[1,1],xmm4[1,1]
movss 0x9368(%rip), %xmm1     # 0xff30
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
cmpnleps %xmm0, %xmm3
cmpnleps %xmm1, %xmm0
orps %xmm3, %xmm0
movd %xmm0, %eax
cmpnleps %xmm4, %xmm2
movss 0x934b(%rip), %xmm0     # 0xff34
movaps %xmm4, 0x10(%rsp)
movaps %xmm4, %xmm1
cmpnleps %xmm0, %xmm1
orps %xmm2, %xmm1
movd %xmm1, %ecx
orl %eax, %ecx
movl 0x14(%rdx), %r12d
testl %r12d, %r12d
setle %bpl
orb %cl, %bpl
xorl %r14d, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
mulss 0x9319(%rip), %xmm0     # 0xff38
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x10c0
movaps %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x1200
testb $0x1, %bpl
jne 0x6cbc
movapd 0x20(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
cvtpd2ps %xmm1, %xmm0
movl 0x14(%rbx), %eax
movl %r12d, %ecx
movaps 0x10(%rsp), %xmm1
cvttss2si %xmm1, %edx
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
cvttss2si %xmm2, %esi
cmpl %edx, %eax
jne 0x6c75
cmpl %esi, 0x18(%rbx)
je 0x6cd3
movslq %edx, %rdx
movslq %esi, %rdi
imulq $0xe38, %rdx, %rdx      # imm = 0xE38
addq %r15, %rdx
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdi, %rsi
movl (%rdx,%rsi), %edi
cmpl $0x6, %edi
je 0x6cbc
cmpl $0x2, %edi
je 0x6ca6
addps %xmm0, %xmm1
decl %ecx
jne 0x6c5d
jmp 0x6cbc
addq %rsi, %rdx
cmpl $0x0, 0x14(%rdx)
jg 0x6cbc
movl $0x0, 0x14(%rdx)
movl $0x1, (%rdx)
incl %r14d
cmpl $0x168, %r14d           # imm = 0x168
jne 0x6c0f
xorl %ebp, %ebp
jmp 0x6df8
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
movl 0x14(%r13), %ecx
movl %ecx, %edx
negl %edx
leal (%rax,%r12,2), %eax
cmovnsl %ecx, %edx
leal (%rdx,%rax), %ebp
addl $0x2, %ebp
testl %ebp, %ebp
jle 0x6d18
movl %ebp, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rax, %rcx
shrq $0x21, %rcx
subl %ecx, 0x18(%r13)
movl %ebp, %eax
shrl %eax
subl %eax, 0x10(%rbx)
leaq 0x70(%rsp), %rax
cmpl $0x2, 0x20(%rax)
jne 0x6df8
callq 0x11d0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %eax, %ecx
addl %ecx, 0x18(%r13)
callq 0x11d0
movslq %eax, %rcx
imulq $0x66666667, %rcx, %rax # imm = 0x66666667
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rax
addl %edx, %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
subl %eax, %ecx
movl 0x30(%rbx), %eax
cmpl $0x2, %ecx
jne 0x6d83
testl %eax, %eax
je 0x6df1
movl $0x2, 0x34(%rbx)
jmp 0x6df8
cmpl $0x2, %eax
je 0x6d8e
cmpl $0x2, 0x34(%rbx)
jne 0x6df8
addl %r12d, %r12d
callq 0x11d0
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
addl %r12d, %eax
movl 0x14(%r13), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %ecx, %edx
leal (%rdx,%rax), %ebp
incl %ebp
movslq %ebp, %rcx
imulq $0x55555555, %rcx, %rsi # imm = 0x55555555
shrq $0x20, %rsi
subl %ecx, %esi
movl %esi, %edi
shrl $0x1f, %edi
sarl %esi
addl %edi, %esi
addl %esi, 0x18(%r13)
addl %edx, %eax
shrl $0x1f, %ecx
addl %ecx, %eax
incl %eax
sarl %eax
subl %eax, 0x10(%rbx)
jmp 0x6df8
movl $0x2, 0x30(%rbx)
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq