// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %r9, 0x40(%rsp)
movl %r8d, 0x2c(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
movl 0xb4(%rsp), %edx
movl 0xb8(%rsp), %eax
decl 0x1c(%rsi)
pushq $-0x1
popq %r9
xorl %r8d, %r8d
leal -0x71(%rcx), %esi
pushq $0x1
popq %rdi
cmpl $0x7, %esi
ja 0xa942
leaq 0x49b4(%rip), %rcx      # 0xf2e4
movslq (%rcx,%rsi,4), %rsi
addq %rcx, %rsi
jmpq *%rsi
xorl %r9d, %r9d
pushq $-0x1
popq %r8
jmp 0xa970
cmpl $0x61, %ecx
je 0xa969
cmpl $0x64, %ecx
je 0xa961
cmpl $0x65, %ecx
je 0xa964
jmp 0xa970
movl %edi, %r8d
jmp 0xa95c
pushq $-0x1
popq %r8
movl %edi, %r9d
jmp 0xa970
xorl %r9d, %r9d
movl %edi, %r8d
jmp 0xa970
pushq $-0x1
popq %r8
movl %r8d, %r9d
leaq 0x3c(%rsp), %rcx
andl $0x0, (%rcx)
movq 0xe0(%rsp), %rbx
leal (%r9,%rdx), %r13d
leal (%r8,%rax), %r14d
leal (%r9,%rdx), %ecx
addl $-0x4, %ecx
movl %ecx, 0x14(%rsp)
leal -0x4(%r8,%rax), %eax
movl %eax, 0x10(%rsp)
movq %r9, 0x58(%rsp)
negl %r9d
movq %r8, 0x60(%rsp)
negl %r8d
movl $0x0, 0x18(%rsp)
movl $0x0, 0x4(%rsp)
movq %r9, 0x50(%rsp)
movq %r8, 0x48(%rsp)
leal 0x1(%r13), %eax
movl %eax, 0x38(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0x34(%rsp)
leal (%r9,%r13), %eax
incl %eax
movl %eax, 0x30(%rsp)
leal (%r14,%r8), %r15d
incl %r15d
movslq %r13d, %rax
movslq %r14d, %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq 0x20(%rsp), %rax
imulq $0x1c, %rcx, %rbp
addq %rax, %rbp
movb $0x1, %cl
testb $0x1, %cl
je 0xab60
movl 0x18(%rsp), %eax
cmpl 0x20(%r12), %eax
jge 0xab60
movq %rbx, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x11c0
movq %rbx, %rdi
movl 0x38(%rsp), %esi
movl 0x34(%rsp), %edx
leaq 0x273f(%rip), %rcx      # 0xd17a
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x1060
movq %rbx, %rdi
movl 0x30(%rsp), %esi
movl %r15d, %edx
leaq 0x30a8(%rip), %rcx      # 0xdb0a
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x1100
cmpl $0x0, 0xc(%rbp)
jle 0xaae9
movq 0x8(%rsp), %rdi
movl %r13d, %esi
movl %r14d, %edx
movl 0x2c(%rsp), %ecx
callq 0x4f9a
movb $0x1, %cl
testl %eax, %eax
js 0xaa02
movl 0x10(%r12), %edx
movl %eax, %eax
imulq $0x38, %rax, %rax
xorl %ecx, %ecx
movq 0x8(%rsp), %rsi
subl %edx, 0x8(%rsi,%rax)
jg 0xaa02
addq 0x8(%rsp), %rax
movl 0x20(%rax), %eax
cmpl $0x2, %eax
je 0xab0e
xorl %ecx, %ecx
pushq $0x1
popq %rdx
movl %edx, 0x4(%rsp)
cmpl $0x1, %eax
jne 0xaa02
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
movq 0x40(%rsp), %rcx
movl (%rcx), %eax
addl %edx, %eax
addl $0x5, %eax
jmp 0xab25
cmpl $0x2, (%rbp)
jne 0xab35
movq 0x20(%rsp), %rdi
movl %r13d, %esi
movl %r14d, %edx
movq %r12, %rcx
leaq 0x3c(%rsp), %r8
callq 0x8091
xorl %ecx, %ecx
jmp 0xaa02
callq 0x11d0
cltd
pushq $0xf
popq %rcx
idivl %ecx
movq 0x40(%rsp), %rcx
movl (%rcx), %eax
addl %edx, %eax
addl $0x7, %eax
movl %eax, (%rcx)
xorl %ecx, %ecx
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
jmp 0xaa02
incl 0x18(%rsp)
movq 0x58(%rsp), %rcx
addl %ecx, %r13d
movq 0x60(%rsp), %rax
addl %eax, %r14d
addl %ecx, 0x14(%rsp)
addl %eax, 0x10(%rsp)
movq 0x50(%rsp), %r9
movq 0x48(%rsp), %r8
jmp 0xa9c6
leal -0x4(%r13), %eax
addl $0x4, %r13d
leal -0x4(%r14), %ecx
addl $0x4, %r14d
movslq %ecx, %rcx
movq %rcx, 0x8(%rsp)
movslq %r14d, %r14
movslq %eax, %r15
movslq %r13d, %rax
movq %rax, 0x18(%rsp)
movslq 0x14(%rsp), %rax
imulq $0xe38, %rax, %rax      # imm = 0xE38
movslq 0x10(%rsp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rax, %rcx
movq 0x20(%rsp), %rax
leaq (%rax,%rcx), %rbx
addq $0x4, %rbx
pushq $0x4
popq %rbp
cmpq 0x18(%rsp), %r15
jge 0xabec
movq %rbx, %r13
movq 0x8(%rsp), %r12
cmpq %r14, %r12
jge 0xabe0
callq 0x11d0
cltd
idivl %ebp
cmpl $0x2, %edx
jg 0xabd7
movl $0x1, (%r13)
incq %r12
addq $0x1c, %r13
jmp 0xabbd
incq %r15
addq $0xe38, %rbx            # imm = 0xE38
jmp 0xabae
movl 0x4(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq