// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x168, -0x1c(%rbp)     # imm = 0x168
jge 0xb6f5
cvtsi2ssl -0x1c(%rbp), %xmm0
movss 0xda9b(%rip), %xmm1     # 0x18de4
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x20c0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
cvtsi2ssl -0x1c(%rbp), %xmm0
movss 0xda78(%rip), %xmm1     # 0x18de4
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x2210
movq -0x40(%rbp), %rax
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
cvtsi2ssl (%rax), %xmm0
movss 0xda4e(%rip), %xmm1     # 0x18de0
addss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
cvtsi2ssl 0x4(%rax), %xmm0
movss 0xda38(%rip), %xmm1     # 0x18de0
addss %xmm1, %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0xb6dd
movss 0xda0e(%rip), %xmm0     # 0x18dd8
ucomiss -0x30(%rbp), %xmm0
jb 0xb6dd
movss 0xda00(%rip), %xmm0     # 0x18ddc
ucomiss -0x2c(%rbp), %xmm0
jb 0xb6dd
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0xb6dd
cmpl $0x0, -0x24(%rbp)
jne 0xb6dd
movl $0x0, -0x20(%rbp)
movq -0x40(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x14(%rcx), %eax
jge 0xb6db
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
cvttss2si -0x2c(%rbp), %ecx
cmpl %ecx, %eax
jne 0xb59c
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
cvttss2si -0x30(%rbp), %ecx
cmpl %ecx, %eax
jne 0xb59c
movq -0x40(%rbp), %rax
movl $0x1, -0x24(%rbp)
movl 0x14(%rax), %eax
shll %eax
movl %eax, -0x44(%rbp)
callq 0x21e0
movl $0x4, %ecx
cltd
idivl %ecx
movl -0x44(%rbp), %eax
addl %edx, %eax
addl $0x2, %eax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jle 0xb4b3
movl -0x28(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x18(%rax)
movl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
cmpl $0x2, 0x20(%rax)
jne 0xb597
callq 0x21e0
movl $0x5, %ecx
cltd
idivl %ecx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x18(%rax)
callq 0x21e0
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x2, %edx
jne 0xb513
movq -0x8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0xb503
movq -0x8(%rbp), %rax
movl $0x2, 0x34(%rax)
jmp 0xb50e
movq -0x8(%rbp), %rax
movl $0x2, 0x30(%rax)
jmp 0xb595
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
je 0xb527
movq -0x8(%rbp), %rax
cmpl $0x2, 0x34(%rax)
jne 0xb593
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
movl %eax, -0x48(%rbp)
callq 0x21e0
movl $0x3, %ecx
cltd
idivl %ecx
movl -0x48(%rbp), %eax
addl %edx, %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movl %ecx, %eax
negl %eax
cmovnsl %eax, %ecx
movl -0x28(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x18(%rax)
movl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x10(%rax)
jmp 0xb595
jmp 0xb597
jmp 0xb6db
movq -0x18(%rbp), %rax
cvttss2si -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
cvttss2si -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x6, (%rax)
jne 0xb5cb
jmp 0xb6db
movq -0x18(%rbp), %rax
cvttss2si -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
cvttss2si -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
jne 0xb6ad
movl -0x28(%rbp), %edx
movq -0x18(%rbp), %rax
cvttss2si -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
cvttss2si -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
cvttss2si -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
cvttss2si -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
jg 0xb6ab
movq -0x18(%rbp), %rax
cvttss2si -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
cvttss2si -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x14(%rax)
movq -0x18(%rbp), %rax
cvttss2si -0x2c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
cvttss2si -0x30(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
jmp 0xb6db
jmp 0xb6af
movss -0x34(%rbp), %xmm0
addss -0x2c(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x38(%rbp), %xmm0
addss -0x30(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xb408
jmp 0xb6dd
cmpl $0x1, -0x24(%rbp)
jne 0xb6e5
jmp 0xb6f5
jmp 0xb6e7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xb32f
movl -0x28(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop