// File: /workspace/github_c_makefile_star2_O1/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, 0x30(%rsp)
movq %rsi, %r15
leaq 0x70(%rsp), %rax
movl 0x14(%rax), %r12d
movl 0x18(%rax), %r13d
movl $0x0, 0x1c(%rsp)
decl 0x1c(%rsi)
movq %rdi, 0x28(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
cmpl $0x70, %ecx
jle 0xbca3
addl $-0x71, %ecx
cmpl $0x7, %ecx
ja 0xbcfa
leaq 0x5594(%rip), %rdx      # 0x11224
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x0, 0xc(%rsp)
jmp 0xbcbc
cmpl $0x61, %ecx
je 0xbcd8
cmpl $0x64, %ecx
je 0xbcea
cmpl $0x65, %ecx
je 0xbcf2
jmp 0xbcfa
movl $0x1, 0xc(%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
jmp 0xbcfa
movl $0x1, 0x8(%rsp)
movl $0x1, 0xc(%rsp)
jmp 0xbcfa
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
jmp 0xbcfa
movl $0x0, 0xc(%rsp)
movl $0x1, 0x8(%rsp)
movl 0x24(%rax), %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x2, %ecx
movl %ecx, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
xorl %ebp, %ebp
cmpl 0x20(%r15), %ebp
jge 0xbe95
movslq %r12d, %rax
movslq %r13d, %rcx
imulq $0xe38, %rax, %r14      # imm = 0xE38
addq 0x28(%rsp), %r14
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rbx
addq %rcx, %rbx
cmpl $0x0, 0xc(%r14,%rbx)
jle 0xbd6b
callq 0x11d0
cltq
imulq $0x288df0cb, %rax, %rcx # imm = 0x288DF0CB
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x24, %rcx
addl %edx, %ecx
imull $0x65, %ecx, %ecx
subl %ecx, %eax
cmpl 0x14(%r15), %eax
jle 0xbda2
addq %rbx, %r14
cmpl $0x2, (%r14)
jne 0xbd91
movq 0x28(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
movq %r15, %rcx
leaq 0x1c(%rsp), %r8
callq 0x91e2
jmp 0xbe8b
incl %ebp
addl 0xc(%rsp), %r12d
addl 0x8(%rsp), %r13d
jmp 0xbe53
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
movl 0x18(%rsp), %ecx
callq 0x57a3
testl %eax, %eax
js 0xbe53
movl 0x10(%r15), %ecx
addl 0x14(%rsp), %ecx
movl %eax, %eax
imulq $0x38, %rax, %rax
movl %ecx, %edx
negl %edx
cmovnsl %ecx, %edx
addl %edx, 0x8(%rbx,%rax)
leaq (%rbx,%rax), %r14
cmpl $0x1, 0x2c(%r15)
jne 0xbe06
callq 0x11d0
testb $0x3, %al
jne 0xbe06
callq 0x11d0
andl $0x80000001, %eax       # imm = 0x80000001
xorl %ecx, %ecx
cmpl $0x1, %eax
setne %cl
incl %ecx
movl %ecx, 0x24(%r14)
cmpl $0x0, 0x8(%r14)
jg 0xbe8b
movl 0x20(%r14), %eax
movl $0x1, 0x10(%rsp)
cmpl $0x2, %eax
je 0xbe57
cmpl $0x1, %eax
jne 0xbe8b
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 0x20(%rsp), %rdx
movl (%rdx), %ecx
addl %ecx, %eax
addl $0x5, %eax
jmp 0xbe89
movb $0x1, %al
jmp 0xbe8d
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 0x20(%rsp), %rdx
movl (%rdx), %ecx
addl %ecx, %eax
addl $0x7, %eax
movl %eax, (%rdx)
xorl %eax, %eax
testb %al, %al
jne 0xbd16
movl 0x10(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq