// File: /workspace/github_c_makefile_star2_O3/S01den[P]Lost_CavernRL/pnj.c
// Function: sayQuest
int sayQuest(Pnj pnj, Quest listQuests[], Quest actQuests[], int *nbrQuestAct, Weapons listWeapons[], Armor listArmor[], double *disease, int *questDrug, int *drugUsed)
{
	char *classNames[] = {"CLERIC","WORKER","ERMIT","SCIENTIST"};
	char *typeRewards[] = {"VAX","LIFE POINTS","COMPONENTS","EXOTIC BLOOD"};
	int key = 0;
	int i = 0;
	int select = 0;
	int choice = -1;

	if(listQuests[pnj.quest].isSet == 0)
	{
		WINDOW *win;
		win = newwin(13,75,LONGUEUR/2,LARGEUR/2+10);
		box(win,0,0);
		wattron(win, A_UNDERLINE);
		mvwprintw(win,2,22,"%s (%s)",pnj.name, classNames[pnj.type]);
		wattroff(win, A_UNDERLINE);
		mvwprintw(win,4,2,"%s",listQuests[pnj.quest].description);
		keypad(win, TRUE);
		if(listQuests[pnj.quest].typeReward <= 3)
		{
			mvwprintw(win,7,2,"Reward: %d (%s)", listQuests[pnj.quest].reward, typeRewards[listQuests[pnj.quest].typeReward]);
		}
		else if(listQuests[pnj.quest].typeReward == 4)
		{
			mvwprintw(win,7,2,"Reward: %s", listWeapons[listQuests[pnj.quest].reward].name);
		}
		else if(listQuests[pnj.quest].typeReward == 5)
		{
			mvwprintw(win,7,2,"Reward: %s", listArmor[listQuests[pnj.quest].reward].name);
		}
		else if(listQuests[pnj.quest].typeReward == 6)
		{
			mvwprintw(win,7,2,"Reward: a drug");
		}

		char *menus[] = {"ACCEPT","REJECT"};

		while(1)
		{
			for(i = 0; i < 2; i++)
			{
				if(i == select)
				{
					wattron(win, COLOR_PAIR(STAIRS_COLOR));
					mvwprintw(win, i+9, 75/2-10, menus[i]);
					wattroff(win,COLOR_PAIR(STAIRS_COLOR));
				}
				else
				{
					mvwprintw(win, i+9, 75/2-10, menus[i]);
				}
			}

			wrefresh(win);

			key = wgetch(win);
			switch(key)
			{	
				case KEY_DOWN:
					if(select+1<=1)
						select++;
					break;

				case KEY_UP:
					if(select-1 >= 0)
						select--;
					break;

				case '\n':
					choice = select;
					break;
			}
			if(choice != -1)
				break;
		}

		if(choice == 0 && *nbrQuestAct+1 <= NBR_QUESTS_MAX)
		{
			if(listQuests[pnj.quest].indice == 2)
			{
				*disease = 0;
			}
			int indiceQuest = 0;
			for(indiceQuest = 0; indiceQuest < NBR_QUESTS_MAX; indiceQuest++)
			{
				if(actQuests[indiceQuest].isSet == 0)
				{
					actQuests[indiceQuest].name = listQuests[pnj.quest].name;
					actQuests[indiceQuest].description = listQuests[pnj.quest].description;
					actQuests[indiceQuest].indice = listQuests[pnj.quest].indice;
					actQuests[indiceQuest].isSet = 1;
					listQuests[pnj.quest].isSet = 1;
					actQuests[indiceQuest].typeReward = listQuests[pnj.quest].typeReward;
					actQuests[indiceQuest].reward = listQuests[pnj.quest].reward;
					if(actQuests[indiceQuest].indice == 0)
					{
						*drugUsed = 0;
						*questDrug = 1;
					}
				}
			}
			(*nbrQuestAct)++;
		}

		box(win, ' ', ' ');
		wborder(win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
		wclear(win);
		wrefresh(win);
		delwin(win);
	}

	return choice;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movslq 0x7c(%rsp), %r15
shlq $0x5, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x0, 0x1c(%rdi,%r15)
jne 0xc7d1
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r14
movq %r8, (%rsp)
movq %rcx, 0x8(%rsp)
movq %r9, 0x18(%rsp)
leaq 0x70(%rsp), %rbp
movl $0xd, %edi
movl $0x4b, %esi
movl $0x13, %edx
movl $0x4b, %ecx
callq 0x1130
movq %rax, %rbx
subq $0x8, %rsp
xorl %eax, %eax
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq %rax
callq 0x1120
addq $0x20, %rsp
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
movq (%rbp), %r8
movslq 0x8(%rbp), %rax
leaq 0x4f29(%rip), %rcx      # 0x113d0
movslq (%rcx,%rax,4), %r9
addq %rcx, %r9
leaq 0x3db9(%rip), %rcx      # 0x1026e
movq %rbx, %rdi
movl $0x2, %esi
movl $0x16, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x1060
leaq (%r14,%r15), %rbp
movq 0x8(%r14,%r15), %r8
leaq 0x3e71(%rip), %rcx      # 0x10359
movq %rbx, %rdi
movl $0x4, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1080
movslq 0x10(%r14,%r15), %rax
cmpq $0x3, %rax
movq %r12, 0x30(%rsp)
movq %r13, 0x28(%rsp)
movq %rbp, 0x10(%rsp)
jg 0xc552
movl 0x14(%rbp), %r8d
leaq 0x4eb2(%rip), %rcx      # 0x113e0
movslq (%rcx,%rax,4), %r9
addq %rcx, %r9
leaq 0x460d(%rip), %rcx      # 0x10b49
movq %rbx, %rdi
movl $0x7, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1070
jmp 0xc5c6
cmpl $0x6, %eax
je 0xc5ab
cmpl $0x5, %eax
je 0xc575
cmpl $0x4, %eax
jne 0xc5c6
movq 0x10(%rsp), %rax
movslq 0x14(%rax), %rax
shlq $0x6, %rax
movq 0x8(%rsp), %rcx
jmp 0xc58a
movq 0x10(%rsp), %rax
movslq 0x14(%rax), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq (%rsp), %rcx
movq (%rcx,%rax), %r8
leaq 0x45cc(%rip), %rcx      # 0x10b61
movq %rbx, %rdi
movl $0x7, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1070
jmp 0xc5c6
leaq 0x45c2(%rip), %rcx      # 0x10b74
movq %rbx, %rdi
movl $0x7, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1070
movq %r14, 0x8(%rsp)
movq %r15, (%rsp)
leaq (%r14,%r15), %rax
addq $0x1c, %rax
movq %rax, 0x20(%rsp)
leaq 0x77cd(%rip), %r14      # 0x13db0
xorl %r13d, %r13d
movl %r13d, %r12d
leal 0x9(%r13), %ebp
movb $0x1, %r15b
xorl %esi, %esi
cmpq %r12, %rsi
jne 0xc62c
movq %rbx, %rdi
movl $0xfe00, %esi           # imm = 0xFE00
xorl %edx, %edx
callq 0x11c0
movq (%r14,%r12,8), %rcx
movq %rbx, %rdi
movl %ebp, %esi
movl $0x1b, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0xfe00, %esi           # imm = 0xFE00
xorl %edx, %edx
callq 0x1060
jmp 0xc642
movq (%r14,%rsi,8), %rcx
addl $0x9, %esi
movq %rbx, %rdi
movl $0x1b, %edx
xorl %eax, %eax
callq 0x1070
movl $0x1, %esi
testb $0x1, %r15b
movl $0x0, %r15d
jne 0xc5f2
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x11e0
cmpl $0xa, %eax
je 0xc698
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x103, %eax            # imm = 0x103
je 0xc68b
cmpl $0x102, %eax            # imm = 0x102
jne 0xc69b
xorl %eax, %eax
testl %r13d, %r13d
setle %al
addl %r13d, %eax
movl %eax, %r13d
jmp 0xc69b
xorl %eax, %eax
testl %r13d, %r13d
setg %al
subl %eax, %r13d
jmp 0xc69b
movl %r13d, %ebp
cmpl $-0x1, %ebp
je 0xc5e6
testl %ebp, %ebp
jne 0xc759
xorl %ebp, %ebp
movq 0x30(%rsp), %r8
cmpl $0x2, (%r8)
jg 0xc759
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
cmpl $0x2, 0x18(%rax,%rcx)
jne 0xc6d9
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
addq %rcx, %rax
addq $0x18, %rax
movl $0x1c, %ecx
movl $0x1, %edx
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x98(%rsp), %r11
movq 0x90(%rsp), %r14
movq 0x20(%rsp), %r15
cmpl $0x0, (%r9,%rcx)
jne 0xc74c
movups (%r10), %xmm0
movups %xmm0, -0x1c(%r9,%rcx)
movl (%rax), %esi
movl %esi, -0x4(%r9,%rcx)
movl %edx, (%r9,%rcx)
movl %edx, (%r15)
movq -0x8(%rax), %rdi
movq %rdi, -0xc(%r9,%rcx)
testl %esi, %esi
jne 0xc74c
movl $0x0, (%r11)
movl $0x1, (%r14)
addq $0x20, %rcx
cmpq $0x7c, %rcx
jne 0xc712
incl (%r8)
subq $0x8, %rsp
xorl %eax, %eax
movl $0x20, %r14d
movq %rbx, %rdi
movl $0x20, %esi
movl $0x20, %edx
movl $0x20, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq %rax
callq 0x1120
addq $0x18, %rsp
movq %rbx, %rdi
movl $0x20, %esi
movl $0x20, %edx
movl $0x20, %ecx
movl $0x20, %r8d
movl $0x20, %r9d
pushq %r14
pushq %r14
pushq %r14
callq 0x1120
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x1110
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq