// File: /workspace/github_c_makefile_star2_O3/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
movl %r8d, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
leaq 0x70(%rsp), %rax
movl 0x14(%rax), %r13d
movl 0x18(%rax), %r12d
movl $0x0, 0x1c(%rsp)
decl 0x1c(%rsi)
movq %rdi, 0x30(%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0xc(%rsp)
cmpl $0x70, %ecx
jle 0xbdca
addl $-0x71, %ecx
cmpl $0x7, %ecx
ja 0xbe21
leaq 0x554d(%rip), %rdx      # 0x11304
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x0, 0x10(%rsp)
jmp 0xbde3
cmpl $0x61, %ecx
je 0xbdff
cmpl $0x64, %ecx
je 0xbe11
cmpl $0x65, %ecx
je 0xbe19
jmp 0xbe21
movl $0x1, 0x10(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
jmp 0xbe21
movl $0x1, 0xc(%rsp)
movl $0x1, 0x10(%rsp)
jmp 0xbe21
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
jmp 0xbe21
movl $0x0, 0x10(%rsp)
movl $0x1, 0xc(%rsp)
movl 0x24(%rax), %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
cmpl $0x0, 0x20(%r14)
jle 0xbf35
movq %r9, 0x20(%rsp)
sarl $0x2, %ecx
movl %ecx, 0x14(%rsp)
xorl %ebp, %ebp
movslq %r13d, %rax
movslq %r12d, %rcx
imulq $0xe38, %rax, %r15      # imm = 0xE38
addq 0x30(%rsp), %r15
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rbx
addq %rcx, %rbx
cmpl $0x0, 0xc(%r15,%rbx)
jle 0xbe90
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(%r14), %eax
jle 0xbea7
addq %rbx, %r15
cmpl $0x2, (%r15)
je 0xbec7
incl %ebp
addl 0x10(%rsp), %r13d
addl 0xc(%rsp), %r12d
jmp 0xbebf
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %r12d, %edx
movl 0x18(%rsp), %ecx
callq 0x5820
testl %eax, %eax
jns 0xbee1
cmpl 0x20(%r14), %ebp
jl 0xbe45
jmp 0xbf35
leaq 0x1c(%rsp), %r8
movq 0x30(%rsp), %rdi
movl %r13d, %esi
movl %r12d, %edx
movq %r14, %rcx
callq 0x929c
jmp 0xbf35
movl 0x14(%rsp), %edx
addl 0x10(%r14), %edx
movl %eax, %eax
imulq $0x38, %rax, %rcx
movl %edx, %eax
negl %eax
cmovnsl %edx, %eax
movq 0x28(%rsp), %rdx
addl 0x8(%rdx,%rcx), %eax
leaq (%rdx,%rcx), %rbx
movl %eax, 0x8(%rdx,%rcx)
cmpl $0x1, 0x2c(%r14)
jne 0xbf31
callq 0x11d0
testb $0x3, %al
jne 0xbf2e
callq 0x11d0
andl $0x80000001, %eax       # imm = 0x80000001
xorl %ecx, %ecx
cmpl $0x1, %eax
setne %cl
incl %ecx
movl %ecx, 0x24(%rbx)
movl 0x8(%rbx), %eax
testl %eax, %eax
jle 0xbf48
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%rbx), %eax
movl $0x1, %ebx
cmpl $0x2, %eax
je 0xbf8a
cmpl $0x1, %eax
jne 0xbf37
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 0xbfbc
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)
jmp 0xbf37