// File: /workspace/github_c_makefile_star2_O1/S01den[P]Lost_CavernRL/pnj.c
// Function: setPnj
void setPnj(Map map[LONGUEUR][LARGEUR], Pnj pnj[], int *nbrPnjOnFloor)
{
	*nbrPnjOnFloor = rand()%NBR_PNJ_MAX+1;
	char *nameClerc[] = {"Sister Maria", "Brother Mikael","Mother Cynthia", "Father Lyris"};
	char *nameWorker[] = {"Swann","Nicolas","Thomas","Erica"};
	char *nameErmit[] = {"Michel","Wallace","Francis","Jannice"};
	char *nameScientific[] = {"Dr Jane","Dr Cooper","Dr Jones","Dr Marlene"}; 
	
	int i = 0;

	for(i = 0; i < *nbrPnjOnFloor; i++) // let's spawn the NPC
	{
		pnj[i].x = rand()%LONGUEUR;
		pnj[i].y = rand()%LARGEUR;
		pnj[i].questDone = 0;

		if(pnj[i].x == 0)
			pnj[i].x++;
		if(pnj[i].x == LONGUEUR)
			pnj[i].x--;
		if(pnj[i].y == 0)
			pnj[i].y++;
		if(pnj[i].y == LARGEUR)
			pnj[i].y--;

		if(map[pnj[i].x][pnj[i].y].content != FLOOR)
		{
			if(LARGEUR-pnj[i].y > pnj[i].y)
			{
				while(map[pnj[i].x][pnj[i].y].content != FLOOR && pnj[i].y < LARGEUR)
				{
					pnj[i].y++;
				}
			}
			else
			{
				while(map[pnj[i].x][pnj[i].y].content != FLOOR && pnj[i].y > 0)
				{
					pnj[i].y--;
				}
			}
		}

		int rollType = rand()%4;
		pnj[i].type = rollType;

		switch(pnj[i].type)
		{
			case 0: // cleric
				pnj[i].name = nameClerc[rand()%4];
				pnj[i].quest = rand()%3;
				break;
			case 1: // worker
				pnj[i].name = nameWorker[rand()%4];
				pnj[i].quest = rand()%3+3;
				break;
			case 2: // ermit
				pnj[i].name = nameErmit[rand()%4];
				pnj[i].quest = rand()%3+6;
				break;
			case 3: // scientific
				pnj[i].name = nameScientific[rand()%4];
				pnj[i].quest = rand()%2+9;
				break;
		}
			map[pnj[i].x][pnj[i].y].content = PNJ;
			map[pnj[i].x][pnj[i].y].typePnj = pnj[i].type;

	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
movl %eax, %edx
subl %ecx, %edx
negl %ecx
addl %ecx, %eax
incl %eax
movl %eax, (%rbx)
testl %edx, %edx
js 0xca29
leaq -0x1c(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x1c(%r15), %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
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
movq %r12, %rbp
shlq $0x5, %rbp
leaq (%r14,%rbp), %r13
movl %eax, 0x14(%r14,%rbp)
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, 0x18(%r14,%rbp)
movl $0x0, 0x10(%r14,%rbp)
cmpl $0x0, 0x14(%r14,%rbp)
jne 0xc7b7
movl $0x1, 0x14(%r13)
cmpl $0x27, 0x14(%r13)
jne 0xc7c6
movl $0x26, 0x14(%r13)
testl %eax, %eax
jne 0xc7d2
movl $0x1, 0x18(%r13)
cmpl $0x82, 0x18(%r13)
jne 0xc7e4
movl $0x81, 0x18(%r13)
movslq 0x14(%r13), %rax
movslq 0x18(%r13), %rsi
imulq $0xe38, %rax, %rax      # imm = 0xE38
leaq (%r15,%rax), %rdi
leaq (%rsi,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rsi, %rcx
cmpl $0x1, (%rdi,%rcx)
je 0xc897
movl $0x82, %r9d
subl %esi, %r9d
movl 0x18(%r13), %ecx
movslq %ecx, %rdx
leaq (%rdx,%rdx,8), %r8
leaq (%r8,%r8,2), %r8
addq %rdx, %r8
movl (%rdi,%r8), %edi
cmpl %esi, %r9d
jle 0xc862
cmpl $0x81, %ecx
jg 0xc897
cmpl $0x1, %edi
je 0xc897
addq 0x8(%rsp), %rax
addq %r8, %rax
movq %rdx, %rcx
movq %rcx, %rdx
incq %rcx
cmpq $0x80, %rdx
jg 0xc893
cmpl $0x1, (%rax)
leaq 0x1c(%rax), %rax
jne 0xc848
jmp 0xc893
testl %ecx, %ecx
jle 0xc897
cmpl $0x1, %edi
je 0xc897
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
addq %rdx, %rax
addq 0x10(%rsp), %rax
movq %rcx, %rdx
decq %rcx
cmpq $0x2, %rdx
jl 0xc893
cmpl $0x1, (%rax)
leaq -0x1c(%rax), %rax
jne 0xc87e
movl %ecx, 0x18(%r13)
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
movl %eax, 0x8(%r13)
cmpl $0x3, %eax
ja 0xc9ee
leaq 0x49f3(%rip), %rcx      # 0x112b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x49ff(%rip), %rcx      # 0x112e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rax, (%r13)
callq 0x11d0
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
jmp 0xc9ea
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x49d4(%rip), %rcx      # 0x11300
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rax, (%r13)
callq 0x11d0
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
negl %ecx
addl %ecx, %eax
addl $0x6, %eax
jmp 0xc9ea
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x4994(%rip), %rcx      # 0x11310
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rax, (%r13)
callq 0x11d0
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
andl $-0x2, %ecx
negl %ecx
addl %ecx, %eax
addl $0x9, %eax
jmp 0xc9ea
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x4936(%rip), %rcx      # 0x112f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rax, (%r13)
callq 0x11d0
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
negl %ecx
addl %ecx, %eax
addl $0x3, %eax
movl %eax, 0xc(%r13)
movslq 0x14(%r13), %rax
movslq 0x18(%r13), %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r15, %rax
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl $0xb, (%rax,%rdx)
movl 0x8(%r13), %ecx
movl %ecx, 0x10(%rax,%rdx)
incq %r12
movslq (%rbx), %rax
cmpq %rax, %r12
jl 0xc741
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq