// File: /workspace/github_c_makefile_star2_O2/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, %r13d
movq %rcx, 0x28(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, 0x30(%rsp)
callq 0x11d0
cltd
idivl %ebp
leal 0xf(%rdx), %eax
xorl %r12d, %r12d
subl %ebp, %eax
cmovlel %r12d, %eax
leal 0xf(%rax,%rdx), %eax
leal 0xf(%r13,%r13), %ecx
movl %ecx, 0x18(%rsp)
leal 0x1e(%r13,%r13), %ecx
movl %ecx, 0x14(%rsp)
leal 0x2(%r13), %ecx
movl %ecx, 0x10(%rsp)
leal 0x28(,%r13,2), %ecx
movl %ecx, 0x20(%rsp)
movl %r13d, %ecx
addl $0x3, %ecx
movl %ecx, 0x1c(%rsp)
leal 0x14(,%r13,2), %ecx
movl %ecx, 0x24(%rsp)
testl %eax, %eax
movl $0x0, %r13d
movl %eax, 0xc(%rsp)
cmovgl %eax, %r13d
leaq 0x30(%r14), %rbp
pushq $0x9
popq %rbx
cmpq %r12, %r13
je 0x6433
callq 0x11d0
cltd
pushq $0x27
popq %rcx
idivl %ecx
movl %edx, -0x30(%rbp)
callq 0x11d0
cltd
movl $0x82, %ecx
idivl %ecx
movl %edx, -0x2c(%rbp)
movl -0x30(%rbp), %eax
pushq $0x1
popq %rcx
testl %eax, %eax
je 0x61a0
cmpl $0x27, %eax
jne 0x61a3
pushq $0x26
popq %rcx
movl %ecx, -0x30(%rbp)
testl %edx, %edx
jne 0x61ae
movl $0x1, -0x2c(%rbp)
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movl %r12d, %edx
callq 0x4e20
callq 0x11d0
cltd
pushq $0x64
popq %rcx
idivl %ecx
andl $0x0, -0xc(%rbp)
cmpl $0x27, %edx
jg 0x6224
andl $0x0, -0x8(%rbp)
movabsq $0x10000005a, %rax      # imm = 0x10000005A
movq %rax, -0x14(%rbp)
movl 0x24(%rsp), %eax
movl %eax, -0x28(%rbp)
callq 0x11d0
cltd
pushq $0x5
popq %r15
idivl %r15d
addl $0x3, %edx
movl %edx, -0x20(%rbp)
andl $0x0, -0x24(%rbp)
callq 0x11d0
cltd
idivl %r15d
addl $0x3, %edx
movl %edx, -0x1c(%rbp)
callq 0x11d0
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %edx, -0x18(%rbp)
jmp 0x62db
cmpl $0x3b, %edx
ja 0x626b
andl $0x0, -0x8(%rbp)
movabsq $0x200000055, %rax      # imm = 0x200000055
movq %rax, -0x14(%rbp)
movl 0x20(%rsp), %eax
movl %eax, -0x28(%rbp)
movabsq $0x300000000, %rax      # imm = 0x300000000
movq %rax, -0x24(%rbp)
callq 0x11d0
cltd
pushq $0x7
popq %rcx
idivl %ecx
addl 0x1c(%rsp), %edx
movl %edx, -0x1c(%rbp)
movl $0x1, -0x18(%rbp)
jmp 0x62db
andl $0x0, -0x8(%rbp)
cmpl $0x59, %edx
ja 0x62b0
movabsq $0x300000050, %rax      # imm = 0x300000050
movq %rax, -0x14(%rbp)
movl 0x14(%rsp), %eax
movl %eax, -0x28(%rbp)
callq 0x11d0
cltd
pushq $0x6
popq %rcx
idivl %ecx
addl 0x10(%rsp), %edx
movl %edx, -0x20(%rbp)
andl $0x0, -0x24(%rbp)
movq $0x3, -0x1c(%rbp)
leaq 0x8a95(%rip), %rax      # 0xed43
jmp 0x62d7
movabsq $0x400000064, %rax      # imm = 0x400000064
movq %rax, -0x14(%rbp)
movl 0x18(%rsp), %eax
movl %eax, -0x28(%rbp)
movaps 0x7c44(%rip), %xmm0     # 0xdf10
movups %xmm0, -0x24(%rbp)
leaq 0x8a56(%rip), %rax      # 0xed2d
movq %rax, (%rbp)
movl -0x10(%rbp), %eax
cmpl $0x2, %eax
je 0x63cf
cmpl $0x1, %eax
jne 0x6427
pushq $0xb
popq %rdi
callq 0x10a0
movq %rax, (%rbp)
callq 0x11d0
cltd
pushq $0x19
popq %r15
idivl %r15d
addb $0x41, %dl
movb %dl, 0x3(%rsp)
callq 0x11d0
cltd
idivl %ebx
addb $0x30, %dl
movb %dl, 0x4(%rsp)
movb $0x2d, 0x5(%rsp)
callq 0x11d0
cltd
idivl %r15d
addb $0x41, %dl
movb %dl, 0x6(%rsp)
callq 0x11d0
cltd
idivl %ebx
addb $0x30, %dl
movb %dl, 0x7(%rsp)
callq 0x11d0
cltd
idivl %ebx
addb $0x30, %dl
movb %dl, 0x8(%rsp)
movb $0x40, 0x9(%rsp)
movq (%rbp), %rdi
leaq 0x3(%rsp), %rsi
callq 0x1160
movabsq $0x403632442d3252, %rax # imm = 0x403632442D3252
cmpq %rax, 0x3(%rsp)
jne 0x6427
movq (%rbp), %rax
movabsq $0x3333422d44333444, %rcx # imm = 0x3333422D44333444
movq %rcx, (%rax)
movl $0x214633, 0x7(%rax)    # imm = 0x214633
movl $0x12c, -0x28(%rbp)     # imm = 0x12C
callq 0x11d0
cltd
pushq $0x32
popq %r15
idivl %r15d
addl $0x4, %edx
movl %edx, -0x20(%rbp)
andl $0x0, -0x24(%rbp)
callq 0x11d0
cltd
idivl %r15d
addl $0x4, %edx
movl %edx, -0x1c(%rbp)
callq 0x11d0
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %edx, -0x18(%rbp)
jmp 0x6427
pushq $0xb
popq %rdi
callq 0x10a0
movq %rax, (%rbp)
movw $0x5454, 0x3(%rsp)      # imm = 0x5454
movb $0x5f, 0x5(%rsp)
callq 0x11d0
cltd
idivl %ebx
addb $0x30, %dl
movb %dl, 0x6(%rsp)
callq 0x11d0
cltd
idivl %ebx
addb $0x30, %dl
movb %dl, 0x7(%rsp)
callq 0x11d0
cltd
idivl %ebx
addb $0x30, %dl
movb %dl, 0x8(%rsp)
movb $0x26, 0x9(%rsp)
movq (%rbp), %rdi
leaq 0x3(%rsp), %rsi
callq 0x1160
incq %r12
addq $0x38, %rbp
jmp 0x6167
movq 0x28(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)