// File: /workspace/github_c_makefile_star2_O2/S01den[P]Lost_CavernRL/item.c
// Function: setObjects
void setObjects(Map map[LONGUEUR][LARGEUR], Weapons listWeapons[], Weapons weponsOnFloor[], int nbrMaxWeapons, int *nbrWeapons, Armor armorList[], Armor armorOnFloor[], int nbrMaxArmor, int *nbrArmors)
{
	srand(time(NULL));

	int i = 0;
	int indice = 0;

	*nbrWeapons = rand()%nbrMaxWeapons+1;
	*nbrArmors = rand()%nbrMaxArmor+1;

	for(i = 0; i < *nbrWeapons; i++)
	{
		int rarity = rand()%100+1;
		if(rarity < 70)
		{
			indice = rand()%7;
			if(indice == 3)
				indice = 11;
			if(indice == 4)
				indice = 12;
			if(indice == 6)
				indice = 13;
		}
		else if(rarity >= 70 && rarity < 95)
		{
			indice = rand()%4+4;
			if(indice == 5)
				indice = 8;
			if(indice == 7)
				indice = 9;
		}
		else
		{
			indice = rand()%3+7;
			if(indice == 8)
				indice = 10;
			if(indice == 9)
				indice = 14;
		}

		indice = rand()%NBR_WEAPONS;
		weponsOnFloor[i].indice = indice;
		weponsOnFloor[i].name = listWeapons[indice].name;
		weponsOnFloor[i].rarity = listWeapons[indice].rarity;
		weponsOnFloor[i].degat = listWeapons[indice].degat;
		weponsOnFloor[i].efficiency = listWeapons[indice].efficiency;
		weponsOnFloor[i].strengthRequired = listWeapons[indice].strengthRequired;
		weponsOnFloor[i].state = listWeapons[indice].state;
		weponsOnFloor[i].range = listWeapons[indice].range;
		weponsOnFloor[i].type = listWeapons[indice].type;
		weponsOnFloor[i].cost = listWeapons[indice].cost;

		int posX = rand()%LONGUEUR;
		int posY = rand()%LARGEUR;
		if(posX == 0)
			posX++;
		if(posX == LONGUEUR-1)
			posX--;
		if(posY == 0)
			posY++;
		if(posY == LARGEUR || posY == LARGEUR-1)
			posY-=2;
		weponsOnFloor[i].x = posX;
		weponsOnFloor[i].y = posY;

		if(listWeapons[indice].type == 0)
			map[posX][posY].content = CONTACT_WEAPON;
		else
			map[posX][posY].content = DIST_WEAPON;
	}

	for(i = 0; i < *nbrArmors; i++)
	{
		int rarity = rand()%100+1;
		if(rarity < 70)
		{
			indice = rand()%4;
			if(indice == 1)
				indice = 4;
		}
		else if(rarity >= 70 && rarity < 95)
		{
			indice = rand()%3+4;
			if(indice == 4)
				indice = 1;
		}
		else
		{
			indice = rand()%2+7;
		}

		armorOnFloor[i].indice = indice;
		armorOnFloor[i].name = armorList[indice].name;
		armorOnFloor[i].rarity = armorList[indice].rarity;
		armorOnFloor[i].resistance = armorList[indice].resistance;
		armorOnFloor[i].strengthRequired = armorList[indice].strengthRequired;
		armorOnFloor[i].state = armorList[indice].state;

		int posX = rand()%LONGUEUR;
		int posY = rand()%LARGEUR;
		if(posX == 0)
			posX++;
		if(posX == LONGUEUR)
			posX--;
		if(posY == 0)
			posY++;
		if(posY == LARGEUR)
			posY--;

		armorOnFloor[i].x = posX;
		armorOnFloor[i].y = posY;
		map[posX][posY].content = ARMOR;
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, (%rsp)
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movq 0x50(%rsp), %r15
xorl %edi, %edi
callq 0x1210
movl %eax, %edi
callq 0x1170
callq 0x11d0
cltd
idivl %ebp
incl %edx
movq %r14, 0x8(%rsp)
movl %edx, (%r14)
callq 0x11d0
xorl %ecx, %ecx
cltd
idivl 0x58(%rsp)
incl %edx
movq 0x60(%rsp), %rax
movl %edx, (%rax)
addq $0x38, %r12
movq 0x8(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rcx
jge 0x73a1
movq %rcx, 0x10(%rsp)
callq 0x11d0
callq 0x11d0
callq 0x11d0
cltd
pushq $0xf
popq %rcx
idivl %ecx
movl %edx, -0xc(%r12)
movq %rbx, %r14
movslq %edx, %rbx
shlq $0x6, %rbx
movq (%r13,%rbx), %rax
movq %rax, -0x38(%r12)
movl 0x30(%r13,%rbx), %eax
movl %eax, -0x8(%r12)
movups 0x10(%r13,%rbx), %xmm0
movups %xmm0, -0x28(%r12)
movq 0x20(%r13,%rbx), %rax
movq %rax, -0x18(%r12)
movl 0x28(%r13,%rbx), %eax
movl %eax, -0x10(%r12)
callq 0x11d0
cltd
pushq $0x27
popq %rcx
idivl %ecx
movl %edx, %ebp
callq 0x11d0
cltd
movl $0x82, %ecx
idivl %ecx
cmpl $0x1, %ebp
movl %ebp, %eax
adcl $0x0, %eax
cmpl $0x26, %ebp
pushq $0x25
popq %rcx
cmovel %ecx, %eax
cmpl $0x1, %edx
movl %edx, %ecx
adcl $0x0, %ecx
cmpl $0x81, %edx
pushq $0x7f
popq %rdx
cmovel %edx, %ecx
movl %eax, -0x4(%r12)
movl %ecx, (%r12)
cmpl $0x1, 0x24(%r13,%rbx)
movq %r14, %rbx
pushq $0x9
popq %rdx
sbbl $0x0, %edx
cltq
movslq %ecx, %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r14, %rax
imulq $0x1c, %rcx, %rcx
movl %edx, (%rcx,%rax)
movq 0x10(%rsp), %rcx
incq %rcx
addq $0x40, %r12
jmp 0x72b5
addq $0x2c, %r15
xorl %r14d, %r14d
pushq $0x4
popq %r13
movl $0x82, %r12d
movq 0x60(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r14
jge 0x748e
callq 0x11d0
cltd
pushq $0x64
popq %rcx
idivl %ecx
cmpl $0x44, %edx
jg 0x73e5
callq 0x11d0
cltd
idivl %r13d
cmpl $0x1, %edx
cmovel %r13d, %edx
jmp 0x740e
movl %edx, %ebp
callq 0x11d0
cltd
cmpl $0x5d, %ebp
ja 0x7406
pushq $0x3
popq %rcx
idivl %ecx
movl %edx, %eax
leal 0x4(%rax), %edx
testl %eax, %eax
pushq $0x1
popq %rax
cmovel %eax, %edx
jmp 0x740e
pushq $0x2
popq %rcx
idivl %ecx
addl $0x7, %edx
movl %edx, -0xc(%r15)
movslq %edx, %rax
imulq $0x30, %rax, %rax
movq (%rsp), %rdx
movq (%rdx,%rax), %rcx
movq %rcx, -0x2c(%r15)
movl 0x24(%rdx,%rax), %ecx
movl %ecx, -0x8(%r15)
movl 0x1c(%rdx,%rax), %ecx
movl %ecx, -0x10(%r15)
movq 0x14(%rdx,%rax), %rax
movq %rax, -0x18(%r15)
callq 0x11d0
cltd
pushq $0x27
popq %rcx
idivl %ecx
movl %edx, %ebp
callq 0x11d0
cltd
idivl %r12d
cmpl $0x1, %ebp
adcl $0x0, %ebp
cmpl $0x1, %edx
adcl $0x0, %edx
movl %ebp, -0x4(%r15)
movl %edx, (%r15)
movslq %ebp, %rax
movslq %edx, %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %rbx, %rax
imulq $0x1c, %rcx, %rcx
movl $0x7, (%rcx,%rax)
incq %r14
addq $0x30, %r15
jmp 0x73b2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq