// File: /workspace/github_c_makefile_star2_O2/S01den[P]Lost_CavernRL/player.c
// Function: shotLine
int shotLine(Map map[LONGUEUR][LARGEUR],Weapons *weaponHold, Ennemy ennemies[], char dir, Player player, int nbrEnnemies, int *components)
{
	int x, y = 0;
	int posX = player.x;
	int posY = player.y;
	int noGem = 0; // you must pick a gem with contact weapons

	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 ret = 0;

	while(hit == 0 && turn < weaponHold->range)
	{
		if(map[posX][posY].typeEnnemy > 0 && rand()%101 <= weaponHold->efficiency)
		{
			int ennemySeenIndice = testEnnemyOnPos(ennemies,posX,posY,nbrEnnemies);
			if(ennemySeenIndice >= 0)
			{
				ennemies[ennemySeenIndice].life -= abs(weaponHold->degat+player.agility/4);
				if(weaponHold->indice == 1) // darts random effect
				{
					if(rand()%4 == 0)
					{
						if(rand()%2 == 1)
						{
							ennemies[ennemySeenIndice].effect = 1;
						}
						else
						{
							ennemies[ennemySeenIndice].effect = 2;
						}
					}
				}
				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;
		}

	}

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x20(%rsp)
movl %r8d, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %r15
movq %rdi, 0x30(%rsp)
leaq 0x70(%rsp), %rax
movl 0x14(%rax), %r13d
movl 0x18(%rax), %ebx
andl $0x0, 0x1c(%rsp)
decl 0x1c(%rsi)
pushq $-0x1
popq %rdi
leal -0x71(%rcx), %edx
pushq $0x1
popq %rsi
cmpl $0x7, %edx
ja 0xa711
leaq 0x4bcd(%rip), %rcx      # 0xf2c4
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movl $0x0, 0xc(%rsp)
pushq $-0x1
popq %rcx
movl %ecx, 0x8(%rsp)
jmp 0xa76a
cmpl $0x61, %ecx
je 0xa751
cmpl $0x64, %ecx
je 0xa743
cmpl $0x65, %ecx
movl %edi, 0xc(%rsp)
je 0xa74b
jmp 0xa762
movl $0x0, 0x8(%rsp)
jmp 0xa73d
movl %esi, 0x8(%rsp)
jmp 0xa73d
pushq $-0x1
popq %rcx
movl %ecx, 0x8(%rsp)
movl %esi, 0xc(%rsp)
jmp 0xa76a
movl $0x0, 0xc(%rsp)
movl %esi, 0x8(%rsp)
jmp 0xa76a
pushq $-0x1
popq %rcx
movl %ecx, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
jmp 0xa76a
movl %edi, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl 0x24(%rax), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
movl %eax, 0x14(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x10(%rsp)
movslq %r13d, %rax
movslq %ebx, %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq 0x30(%rsp), %rax
imulq $0x1c, %rcx, %r12
addq %rax, %r12
movb $0x1, %cl
testb $0x1, %cl
je 0xa8ce
cmpl 0x20(%r15), %ebp
jge 0xa8ce
cmpl $0x0, 0xc(%r12)
jle 0xa7c8
callq 0x11d0
cltd
pushq $0x65
popq %rcx
idivl %ecx
cmpl 0x14(%r15), %edx
jle 0xa7ee
cmpl $0x2, (%r12)
jne 0xa8be
movq 0x30(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
movq %r15, %rcx
leaq 0x1c(%rsp), %r8
callq 0x8091
xorl %ecx, %ecx
jmp 0xa79c
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
movl 0x18(%rsp), %ecx
callq 0x4f9a
movb $0x1, %cl
testl %eax, %eax
js 0xa79c
movl 0x10(%r15), %ecx
addl 0x14(%rsp), %ecx
movl %eax, %eax
imulq $0x38, %rax, %rdx
movl %ecx, %eax
negl %eax
cmovnsl %ecx, %eax
movq 0x28(%rsp), %rcx
addl 0x8(%rcx,%rdx), %eax
leaq (%rcx,%rdx), %r14
movl %eax, 0x8(%rcx,%rdx)
cmpl $0x1, 0x2c(%r15)
jne 0xa859
callq 0x11d0
testb $0x3, %al
jne 0xa855
callq 0x11d0
andl $0x80000001, %eax       # imm = 0x80000001
xorl %ecx, %ecx
cmpl $0x1, %eax
setne %cl
incl %ecx
movl %ecx, 0x24(%r14)
movl 0x8(%r14), %eax
xorl %ecx, %ecx
testl %eax, %eax
jg 0xa79c
movl 0x20(%r14), %eax
cmpl $0x2, %eax
je 0xa897
xorl %ecx, %ecx
pushq $0x1
popq %rdx
movl %edx, 0x10(%rsp)
cmpl $0x1, %eax
jne 0xa79c
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
movq 0x20(%rsp), %rcx
movl (%rcx), %eax
addl %edx, %eax
addl $0x5, %eax
jmp 0xa8ae
callq 0x11d0
cltd
pushq $0xf
popq %rcx
idivl %ecx
movq 0x20(%rsp), %rcx
movl (%rcx), %eax
addl %edx, %eax
addl $0x7, %eax
movl %eax, (%rcx)
xorl %ecx, %ecx
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
jmp 0xa79c
incl %ebp
addl 0xc(%rsp), %r13d
addl 0x8(%rsp), %ebx
jmp 0xa781
movl 0x10(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq