// File: /workspace/github_c_makefile_star2_O3/S01den[P]Lost_CavernRL/ennemy.c
// Function: setEnnemies
void setEnnemies(Map map[LONGUEUR][LARGEUR], Ennemy ennemies[], int nbrEnnemies, int *nbrEnnemyInFloor, int floor)
{
	int nbrEnnemiesRand = rand()%nbrEnnemies+15;
	if(nbrEnnemiesRand > nbrEnnemies)
		nbrEnnemiesRand -= (nbrEnnemies-nbrEnnemiesRand);
	
	int i = 0;
	char name[9];


	for(i = 0; i < nbrEnnemiesRand; i++) // let's spawn the monsters
	{
		ennemies[i].x = rand()%LONGUEUR;
		ennemies[i].y = rand()%LARGEUR;

		if(ennemies[i].x == 0)
			ennemies[i].x++;
		if(ennemies[i].x == LONGUEUR)
			ennemies[i].x--;
		if(ennemies[i].y == 0)
			ennemies[i].y++;
		if(ennemies[i].y == LARGEUR)
			ennemies[i].y--;
		
		moveRand(ennemies,map,i);

		int rollType = rand()%100;

		ennemies[i].effect = 0;

		if(rollType < 40) // droid
		{
			ennemies[i].boss = 0;
			ennemies[i].type = 1;
			ennemies[i].efficiency = 90;
			ennemies[i].life = 20+2*floor;
			ennemies[i].strength = rand()%5+3;
			ennemies[i].seen = 0;
			ennemies[i].agility = rand()%5+3;
			ennemies[i].haveBlaster = rand()%2;
		}
		else if(rollType >= 40 && rollType < 60)
		{
			ennemies[i].boss = 0;
			ennemies[i].type = 2;
			ennemies[i].efficiency = 85;
			ennemies[i].life = 40+2*floor;
			ennemies[i].strength = 3;
			ennemies[i].seen = 0;
			ennemies[i].agility = rand()%7+(3+floor);
			ennemies[i].haveBlaster = 1;			
		}
		else if(rollType >= 60 && rollType < 90)
		{
			ennemies[i].boss = 0;
			ennemies[i].type = 3; 
			ennemies[i].efficiency = 80;
			ennemies[i].life = 30+2*floor;
			ennemies[i].strength = rand()%6+(2+floor);
			ennemies[i].seen = 0;
			ennemies[i].agility = 3;
			ennemies[i].haveBlaster = 0;
			ennemies[i].name = "GUARDIAN";	
		}
		else if(rollType >= 90 && rollType < 100)
		{
			ennemies[i].boss = 0;
			ennemies[i].type = 4;
			ennemies[i].efficiency = 100;
			ennemies[i].life = 15+2*floor;
			ennemies[i].strength = 3;
			ennemies[i].seen = 0;
			ennemies[i].agility = 3;
			ennemies[i].haveBlaster = 0;
			ennemies[i].name = "INFECTED GUARDIAN";	
		}

		if(ennemies[i].type == 1)
		{
			ennemies[i].name = (char*)malloc(11*sizeof(char));
			name[0] = rand()%25+65;
			name[1] = rand()%9+48;
			name[2] = '-';
			name[3] = rand()%25+65;
			name[4] = rand()%9+48;
			name[5] = rand()%9+48;
			name[6] = '@';
			strcpy(ennemies[i].name,name);

			if(strcmp(name,"R2-D26@") == 0)
			{
				strcpy(ennemies[i].name,"D43D-B33F!");
				ennemies[i].life = 300;
				ennemies[i].strength = rand()%50+4;
				ennemies[i].seen = 0;
				ennemies[i].agility = rand()%50+4;
				ennemies[i].haveBlaster = rand()%2;				
			}
		}
		else if(ennemies[i].type == 2)
		{
			ennemies[i].name = (char*)malloc(11*sizeof(char));
			name[0] = 'T';
			name[1] = 'T';
			name[2] = '_';
			name[3] = rand()%9+48;
			name[4] = rand()%9+48;
			name[5] = rand()%9+48;
			name[6] = '&';
			strcpy(ennemies[i].name,name);
		}
	}

	*nbrEnnemyInFloor = nbrEnnemiesRand;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %r14d
movq %rcx, 0x28(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
callq 0x11d0
cltd
idivl %ebp
leal 0xf(%rdx), %eax
xorl %ebx, %ebx
subl %ebp, %eax
cmovlel %ebx, %eax
addl %edx, %eax
addl $0xf, %eax
movl %eax, 0x10(%rsp)
testl %eax, %eax
jle 0x7330
movl %r14d, %eax
leal 0xf(,%rax,2), %ecx
movl %ecx, 0x1c(%rsp)
leal 0x1e(,%rax,2), %ecx
movl %ecx, 0x18(%rsp)
leal 0x2(%r14), %ecx
movl %ecx, 0x14(%rsp)
leal 0x28(,%rax,2), %ecx
movl %ecx, 0x20(%rsp)
addl $0x3, %r14d
movq %r14, 0x30(%rsp)
leal 0x14(,%rax,2), %eax
movl %eax, 0x24(%rsp)
movl 0x10(%rsp), %r14d
leaq 0x30(%r15), %r13
xorl %ebp, %ebp
callq 0x11d0
cltq
imulq $-0x2df2df2d, %rax, %rcx # imm = 0xD20D20D3
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x5, %ecx
addl %edx, %ecx
imull $0x27, %ecx, %ecx
subl %ecx, %eax
movl %eax, -0x30(%r13)
callq 0x11d0
cltq
imulq $0x7e07e07f, %rax, %rcx # imm = 0x7E07E07F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
movl %ecx, %edx
shll $0x7, %edx
leal (%rdx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, -0x2c(%r13)
movl -0x30(%r13), %ecx
testl %ecx, %ecx
je 0x6ef9
cmpl $0x27, %ecx
jne 0x6f02
movl $0x26, %ecx
jmp 0x6efe
movl $0x1, %ecx
movl %ecx, -0x30(%r13)
testl %eax, %eax
jne 0x6f0e
movl $0x1, -0x2c(%r13)
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x5634
callq 0x11d0
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
movl $0x0, -0xc(%r13)
cmpl $0x27, %eax
jg 0x6fd6
movl %ebx, -0x8(%r13)
movabsq $0x10000005a, %rax      # imm = 0x10000005A
movq %rax, -0x14(%r13)
movl 0x24(%rsp), %eax
movl %eax, -0x28(%r13)
callq 0x11d0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
addl %ecx, %eax
addl $0x3, %eax
movl %eax, -0x20(%r13)
movl %ebx, -0x24(%r13)
callq 0x11d0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
addl %ecx, %eax
addl $0x3, %eax
movl %eax, -0x1c(%r13)
callq 0x11d0
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
andl $-0x2, %ecx
subl %ecx, %eax
movl %eax, -0x18(%r13)
jmp 0x70d8
cmpl $0x3b, %eax
ja 0x7045
movl $0x0, -0x8(%r13)
movabsq $0x200000055, %rax      # imm = 0x200000055
movq %rax, -0x14(%r13)
movl 0x20(%rsp), %eax
movl %eax, -0x28(%r13)
movabsq $0x300000000, %rax      # imm = 0x300000000
movq %rax, -0x24(%r13)
callq 0x11d0
cltq
imulq $-0x6db6db6d, %rax, %rcx # imm = 0x92492493
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x2, %ecx
addl %edx, %ecx
leal (,%rcx,8), %edx
subl %edx, %ecx
addl 0x30(%rsp), %eax
addl %ecx, %eax
movl %eax, -0x1c(%r13)
movl $0x1, -0x18(%r13)
jmp 0x70d8
movl $0x0, -0x8(%r13)
cmpl $0x59, %eax
ja 0x70ab
movabsq $0x300000050, %rax      # imm = 0x300000050
movq %rax, -0x14(%r13)
movl 0x18(%rsp), %eax
movl %eax, -0x28(%r13)
callq 0x11d0
cltq
imulq $0x2aaaaaab, %rax, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
addl 0x14(%rsp), %eax
movl %eax, -0x20(%r13)
movl $0x0, -0x24(%r13)
movq $0x3, -0x1c(%r13)
leaq 0x9cda(%rip), %rax      # 0x10d83
jmp 0x70d4
movabsq $0x400000064, %rax      # imm = 0x400000064
movq %rax, -0x14(%r13)
movl 0x1c(%rsp), %eax
movl %eax, -0x28(%r13)
movaps 0x8e88(%rip), %xmm0     # 0xff50
movups %xmm0, -0x24(%r13)
leaq 0x9c99(%rip), %rax      # 0x10d6d
movq %rax, (%r13)
movl -0x10(%r13), %eax
cmpl $0x2, %eax
je 0x7281
cmpl $0x1, %eax
jne 0x7320
movl $0xb, %edi
callq 0x10a0
movq %rax, (%r13)
callq 0x11d0
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x23, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
addb $0x41, %al
movb %al, 0x7(%rsp)
callq 0x11d0
cltq
imulq $0x38e38e39, %rax, %rcx # imm = 0x38E38E39
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
subl %ecx, %eax
addb $0x30, %al
movb %al, 0x8(%rsp)
movb $0x2d, 0x9(%rsp)
callq 0x11d0
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x23, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
addb $0x41, %al
movb %al, 0xa(%rsp)
callq 0x11d0
cltq
imulq $0x38e38e39, %rax, %rcx # imm = 0x38E38E39
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
subl %ecx, %eax
addb $0x30, %al
movb %al, 0xb(%rsp)
callq 0x11d0
cltq
imulq $0x38e38e39, %rax, %rcx # imm = 0x38E38E39
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
subl %ecx, %eax
addb $0x30, %al
movb %al, 0xc(%rsp)
movb $0x40, 0xd(%rsp)
movq (%r13), %rdi
leaq 0x7(%rsp), %rsi
callq 0x1160
movabsq $0x403632442d3252, %rax # imm = 0x403632442D3252
cmpq %rax, 0x7(%rsp)
jne 0x7320
movq (%r13), %rax
movabsq $0x3333422d44333444, %rcx # imm = 0x3333422D44333444
movq %rcx, (%rax)
movl $0x214633, 0x7(%rax)    # imm = 0x214633
movl $0x12c, -0x28(%r13)     # imm = 0x12C
callq 0x11d0
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x24, %rcx
addl %edx, %ecx
imull $0x32, %ecx, %ecx
negl %ecx
addl %ecx, %eax
addl $0x4, %eax
movl %eax, -0x20(%r13)
movl $0x0, -0x24(%r13)
callq 0x11d0
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x24, %rcx
addl %edx, %ecx
imull $0x32, %ecx, %ecx
negl %ecx
addl %ecx, %eax
addl $0x4, %eax
movl %eax, -0x1c(%r13)
callq 0x11d0
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
andl $-0x2, %ecx
subl %ecx, %eax
movl %eax, -0x18(%r13)
jmp 0x7320
movl $0xb, %edi
callq 0x10a0
movq %rax, (%r13)
movw $0x5454, 0x7(%rsp)      # imm = 0x5454
movb $0x5f, 0x9(%rsp)
callq 0x11d0
cltq
imulq $0x38e38e39, %rax, %rcx # imm = 0x38E38E39
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
subl %ecx, %eax
addb $0x30, %al
movb %al, 0xa(%rsp)
callq 0x11d0
cltq
imulq $0x38e38e39, %rax, %rcx # imm = 0x38E38E39
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
subl %ecx, %eax
addb $0x30, %al
movb %al, 0xb(%rsp)
callq 0x11d0
cltq
imulq $0x38e38e39, %rax, %rcx # imm = 0x38E38E39
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
subl %ecx, %eax
addb $0x30, %al
movb %al, 0xc(%rsp)
movb $0x26, 0xd(%rsp)
movq (%r13), %rdi
leaq 0x7(%rsp), %rsi
callq 0x1160
incq %rbp
addq $0x38, %r13
cmpq %r14, %rbp
jb 0x6e95
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
movl %ecx, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop