// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %r8d, 0x4(%rsp)
movl 0x84(%rsp), %r14d
movl 0x88(%rsp), %r15d
movq %rsi, 0x8(%rsp)
decl 0x1c(%rsi)
movq %rdi, 0x10(%rsp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
cmpl $0x70, %ecx
jle 0xc01b
addl $-0x71, %ecx
cmpl $0x7, %ecx
ja 0xc04b
leaq 0x5316(%rip), %rax      # 0x11324
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %edi, %edi
jmp 0xc031
cmpl $0x61, %ecx
je 0xc031
cmpl $0x64, %ecx
je 0xc044
cmpl $0x65, %ecx
je 0xc046
jmp 0xc04b
movl $0x1, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
jmp 0xc04b
movl $0x1, %esi
movl $0x1, %edi
jmp 0xc04b
xorl %edi, %edi
movl $0x1, %esi
movl $0x0, 0x24(%rsp)
addl %edi, %r14d
addl %esi, %r15d
movq 0x8(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jle 0xc1d4
movq %rdx, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq 0xb0(%rsp), %r12
movl %edi, 0x1c(%rsp)
movl %edi, %r13d
negl %r13d
movl %esi, 0x20(%rsp)
movl %esi, %ebx
negl %ebx
xorl %ebp, %ebp
movq %r12, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x11c0
leal 0x1(%r14), %esi
leal 0x1(%r15), %edx
movq %r12, %rdi
leaq 0x310b(%rip), %rcx      # 0xf1ba
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x1060
leal (%r14,%r13), %esi
incl %esi
leal (%r15,%rbx), %edx
incl %edx
movq %r12, %rdi
leaq 0x3a6f(%rip), %rcx      # 0xfb4a
xorl %eax, %eax
callq 0x1070
movq %r12, %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 0xc128
movq 0x30(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movl 0x4(%rsp), %ecx
callq 0x5820
testl %eax, %eax
js 0xc140
jmp 0xc153
addq %rcx, %rax
cmpl $0x2, (%rax)
je 0xc1ba
incl %ebp
addl 0x1c(%rsp), %r14d
addl 0x20(%rsp), %r15d
movq 0x8(%rsp), %rax
cmpl 0x20(%rax), %ebp
jl 0xc08e
jmp 0xc1d4
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %ecx
movl %eax, %eax
imulq $0x38, %rax, %rax
movq 0x30(%rsp), %rdx
subl %ecx, 0x8(%rdx,%rax)
jg 0xc1d4
addq %rax, %rdx
movl 0x20(%rdx), %eax
cmpl $0x2, %eax
je 0xc27c
movl $0x1, 0x4(%rsp)
cmpl $0x1, %eax
movq 0x28(%rsp), %rbx
jne 0xc1dc
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
movl (%rbx), %ecx
addl %ecx, %eax
addl $0x5, %eax
movl %eax, (%rbx)
jmp 0xc1dc
leaq 0x24(%rsp), %r8
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movq 0x8(%rsp), %rcx
callq 0x929c
movl $0x0, 0x4(%rsp)
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, 0x8(%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), %rbp
addq $0x4, %rbp
movq %rbp, %r13
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 0xc248
movl $0x1, (%r13)
incq %r12
addq $0x1c, %r13
cmpq %r15, %r12
jl 0xc229
leaq 0x1(%rbx), %rax
addq $0xe38, %rbp            # imm = 0xE38
cmpq 0x8(%rsp), %rbx
movq %rax, %rbx
jl 0xc223
movl 0x4(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x4(%rsp)
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 0x28(%rsp), %rdx
movl (%rdx), %ecx
addl %ecx, %eax
addl $0x7, %eax
movl %eax, (%rdx)
jmp 0xc1dc