// File: /workspace/github_c_makefile_star2_O3/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 0xcafb
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
movslq %eax, %rcx
imulq $0x7e07e07f, %rcx, %rax # imm = 0x7E07E07F
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rax
addl %edx, %eax
movl %eax, %edx
shll $0x7, %edx
leal (%rdx,%rax,2), %eax
subl %eax, %ecx
movl %ecx, 0x18(%r14,%rbp)
movl $0x0, 0x10(%r14,%rbp)
movl 0x14(%r14,%rbp), %eax
testl %eax, %eax
je 0xc8da
cmpl $0x27, %eax
jne 0xc8e3
movl $0x26, %eax
jmp 0xc8df
movl $0x1, %eax
movl %eax, 0x14(%r13)
testl %ecx, %ecx
jne 0xc8f4
movl $0x1, 0x18(%r13)
movl $0x1, %ecx
movslq %eax, %rdx
movslq %ecx, %rax
imulq $0xe38, %rdx, %rdx      # imm = 0xE38
leaq (%r15,%rdx), %rdi
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rsi,%rax), %r8
cmpl $0x1, (%rdi,%r8)
je 0xc969
movl $0x82, %edi
subl %ecx, %edi
addq %rax, %rdx
cmpl %ecx, %edi
jle 0xc948
addq 0x8(%rsp), %rdx
addq %rsi, %rdx
movq %rax, %rcx
incq %rax
cmpq $0x80, %rcx
jg 0xc965
cmpl $0x1, (%rdx)
leaq 0x1c(%rdx), %rdx
jne 0xc92e
jmp 0xc965
addq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rax, %rcx
decq %rax
cmpq $0x2, %rcx
jl 0xc965
cmpl $0x1, (%rdx)
leaq -0x1c(%rdx), %rdx
jne 0xc950
movl %eax, 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 0xcac0
leaq 0x4a31(%rip), %rcx      # 0x113c0
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 0x4a3d(%rip), %rcx      # 0x113f0
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 0xcabc
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x4a12(%rip), %rcx      # 0x11410
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 0xcabc
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x49d2(%rip), %rcx      # 0x11420
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 0xcabc
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cltq
leaq 0x4974(%rip), %rcx      # 0x11400
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 0xc85e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq