// File: /workspace/github_c_makefile_star2_O1/S01den[P]Lost_CavernRL/player.c
// Function: burn
int burn(Map map[LONGUEUR][LARGEUR],Weapons *weaponHold,Ennemy ennemies[], char dir, Player player, int nbrEnnemies, int *components,WINDOW *screen)
{
	int ret = 0;
	int x, y = 0;
	int posX = player.x;
	int posY = player.y;

	weaponHold->state--;
	
	switch(dir)
	{
		case 'z':
			x = -1;
			y = 0;
			break;
		case 's':
			x = 1;
			y = 0;
			break;
		case 'q':
			x = 0;
			y = -1;
			break;
		case 'd':
			x = 0;
			y = 1;
			break;
		case 'a':
			x = -1;
			y = -1;
			break;
		case 'e':
			x = -1;
			y = 1;
			break;
		case 'w':
			x = 1;
			y = -1;
			break;
		case 'x':
			x = 1;
			y = 1;
			break;
	}

	int hit = 0;
	int turn = 0;
	int animationDelay = 0;
	int noGem = 0; // you must pick a gem with contact weapons

	posX += x;
	posY += y;

	while(hit == 0 && turn < weaponHold->range)
	{
		animationDelay = 0;

		wattron(screen,COLOR_PAIR(203));
		mvwprintw(screen,posX+1,posY+1,"o");
		wattroff(screen,COLOR_PAIR(203));
		mvwprintw(screen,posX+1-x,posY+1-y,".");
		wrefresh(screen);
		while(animationDelay < 30000000)
		{
			animationDelay++;
		}

		if(map[posX][posY].typeEnnemy > 0)
		{
			int ennemySeenIndice = testEnnemyOnPos(ennemies,posX,posY,nbrEnnemies);
			if(ennemySeenIndice >= 0)
			{
				ennemies[ennemySeenIndice].life -= weaponHold->degat;

				if(ennemies[ennemySeenIndice].life <= 0)
				{
					ret = 1;
					if(ennemies[ennemySeenIndice].type == 1)
					{
						int compWin = rand()%10+5;
						*components += compWin;	
					}
					else if(ennemies[ennemySeenIndice].type == 2)
					{
						int compWin = rand()%15+7;
						*components += compWin;	
					}
				}

				hit = 1;
			}
		}
		else if(map[posX][posY].content == WALL)
		{
			destroyWall(map, posX, posY, weaponHold, &noGem);
			hit = 1;
		}
		else
		{
			turn++;
			posX += x;
			posY += y;
		}
	}

	int i, j = 0;
	for(i = posX-4; i < posX+4; i++)
	{
		for(j = posY-4; j < posY+4; j++)
		{
			if(rand()%4 < 3)
				map[i][j].effect = 1;
		}
	}

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x30(%rsp)
movl %r8d, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r12
movl 0x94(%rsp), %r14d
movl 0x98(%rsp), %r15d
decl 0x1c(%rsi)
movq %rdi, 0x10(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
cmpl $0x70, %ecx
jle 0xbf08
addl $-0x71, %ecx
cmpl $0x7, %ecx
ja 0xbf38
leaq 0x5349(%rip), %rax      # 0x11244
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %esi, %esi
jmp 0xbf1e
cmpl $0x61, %ecx
je 0xbf1e
cmpl $0x64, %ecx
je 0xbf31
cmpl $0x65, %ecx
je 0xbf33
jmp 0xbf38
movl $0x1, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0xbf38
movl $0x1, %edx
movl $0x1, %esi
jmp 0xbf38
xorl %esi, %esi
movl $0x1, %edx
movq 0xc0(%rsp), %rbp
leaq 0x2c(%rsp), %rax
movl $0x0, (%rax)
addl %esi, %r14d
addl %edx, %r15d
movl %esi, 0x20(%rsp)
movl %esi, %eax
negl %eax
movq %rax, 0x18(%rsp)
movl %edx, 0x24(%rsp)
movl %edx, %eax
negl %eax
movq %rax, 0x40(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
movq 0x38(%rsp), %rbx
cmpl 0x20(%r12), %r13d
jge 0xc0fc
movq %rbp, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x11c0
leal 0x1(%r14), %esi
leal 0x1(%r15), %edx
movq %rbp, %rdi
leaq 0x31d3(%rip), %rcx      # 0xf17a
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x1060
movq 0x18(%rsp), %rax
leal (%r14,%rax), %esi
incl %esi
movq 0x40(%rsp), %rax
leal (%r15,%rax), %edx
incl %edx
movq %rbp, %rdi
leaq 0x3b2d(%rip), %rcx      # 0xfb0a
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
callq 0x1100
movslq %r14d, %rax
movslq %r15d, %rdx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq 0x10(%rsp), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
cmpl $0x0, 0xc(%rax,%rcx)
jle 0xc08b
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movl 0x28(%rsp), %ecx
callq 0x57a3
testl %eax, %eax
js 0xc0ba
movl 0x10(%r12), %ecx
movl %eax, %eax
imulq $0x38, %rax, %rax
subl %ecx, 0x8(%rbx,%rax)
jg 0xc0f2
addq %rbx, %rax
movl 0x20(%rax), %eax
movl $0x1, 0xc(%rsp)
cmpl $0x2, %eax
je 0xc0be
cmpl $0x1, %eax
jne 0xc0f2
callq 0x11d0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movq 0x30(%rsp), %rdx
movl (%rdx), %ecx
addl %ecx, %eax
addl $0x5, %eax
jmp 0xc0f0
addq %rcx, %rax
cmpl $0x2, (%rax)
jne 0xc0ad
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movq %r12, %rcx
leaq 0x2c(%rsp), %r8
callq 0x91e2
jmp 0xc0f2
incl %r13d
addl 0x20(%rsp), %r14d
addl 0x24(%rsp), %r15d
movb $0x1, %al
jmp 0xc0f4
callq 0x11d0
cltq
imulq $-0x77777777, %rax, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x3, %ecx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movq 0x30(%rsp), %rdx
movl (%rdx), %ecx
addl %ecx, %eax
addl $0x7, %eax
movl %eax, (%rdx)
xorl %eax, %eax
testb %al, %al
jne 0xbf7b
leal -0x4(%r14), %eax
leal -0x4(%r15), %ecx
movslq %ecx, %rcx
movslq %eax, %rbx
addl $0x3, %r15d
movslq %r15d, %r15
addl $0x3, %r14d
movslq %r14d, %rax
movq %rax, 0x18(%rsp)
leaq -0x1(%rcx), %r14
imulq $0xe38, %rbx, %rax      # imm = 0xE38
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
addq %rax, %rdx
movq 0x10(%rsp), %rax
leaq (%rax,%rdx), %r13
addq $0x4, %r13
movq %r13, %rbp
movq %r14, %r12
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cmpl $0x2, %eax
jg 0xc167
movl $0x1, (%rbp)
incq %r12
addq $0x1c, %rbp
cmpq %r15, %r12
jl 0xc149
leaq 0x1(%rbx), %rax
addq $0xe38, %r13            # imm = 0xE38
cmpq 0x18(%rsp), %rbx
movq %rax, %rbx
jl 0xc143
movl 0xc(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq