// File: /workspace/github_c_makefile_star2_O1/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 0xc6b3
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 0x4f3d(%rip), %rcx      # 0x112c0
movslq (%rcx,%rax,4), %r9
addq %rcx, %r9
leaq 0x3e81(%rip), %rcx      # 0x10212
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 0x3f39(%rip), %rcx      # 0x102fd
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 0xc42e
movl 0x14(%rbp), %r8d
leaq 0x4ec6(%rip), %rcx      # 0x112d0
movslq (%rcx,%rax,4), %r9
addq %rcx, %r9
leaq 0x4651(%rip), %rcx      # 0x10a69
movq %rbx, %rdi
movl $0x7, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1070
jmp 0xc4a2
cmpl $0x6, %eax
je 0xc487
cmpl $0x5, %eax
je 0xc451
cmpl $0x4, %eax
jne 0xc4a2
movq 0x10(%rsp), %rax
movslq 0x14(%rax), %rax
shlq $0x6, %rax
movq 0x8(%rsp), %rcx
jmp 0xc466
movq 0x10(%rsp), %rax
movslq 0x14(%rax), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq (%rsp), %rcx
movq (%rcx,%rax), %r8
leaq 0x4610(%rip), %rcx      # 0x10a81
movq %rbx, %rdi
movl $0x7, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1070
jmp 0xc4a2
leaq 0x4606(%rip), %rcx      # 0x10a94
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 0x78f1(%rip), %r13      # 0x13db0
xorl %r14d, %r14d
movl %r14d, %r12d
shlq $0x3, %r12
movl $0x9, %ebp
xorl %r15d, %r15d
cmpq %r15, %r12
jne 0xc50b
movq %rbx, %rdi
movl $0xfe00, %esi           # imm = 0xFE00
xorl %edx, %edx
callq 0x11c0
movq (%r15,%r13), %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 0xc520
movq (%r15,%r13), %rcx
movq %rbx, %rdi
movl %ebp, %esi
movl $0x1b, %edx
xorl %eax, %eax
callq 0x1070
incl %ebp
addq $0x8, %r15
cmpq $0x8, %r15
je 0xc4d1
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x11e0
cmpl $0xa, %eax
je 0xc56e
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x103, %eax            # imm = 0x103
je 0xc561
cmpl $0x102, %eax            # imm = 0x102
jne 0xc571
xorl %eax, %eax
testl %r14d, %r14d
setle %al
addl %eax, %r14d
jmp 0xc571
xorl %eax, %eax
testl %r14d, %r14d
setg %al
subl %eax, %r14d
jmp 0xc571
movl %r14d, %ebp
cmpl $-0x1, %ebp
je 0xc4c2
testl %ebp, %ebp
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
jne 0xc63b
cmpl $0x2, (%r8)
jg 0xc63b
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
cmpl $0x2, 0x18(%rax,%rcx)
jne 0xc5b2
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 0x10(%rsp), %r10
movq 0x98(%rsp), %r11
movq 0x90(%rsp), %r14
movq 0x20(%rsp), %r15
cmpl $0x0, (%r9,%rcx)
jne 0xc62e
movq (%r10), %rsi
movq %rsi, -0x1c(%r9,%rcx)
movq -0x14(%r15), %rsi
movq %rsi, -0x14(%r9,%rcx)
movl (%rax), %esi
movl %esi, -0x4(%r9,%rcx)
movl %edx, (%r9,%rcx)
movl %edx, (%r15)
movl -0x8(%rax), %edi
movl %edi, -0xc(%r9,%rcx)
movl -0x4(%rax), %edi
movl %edi, -0x8(%r9,%rcx)
testl %esi, %esi
jne 0xc62e
movl $0x0, (%r11)
movl $0x1, (%r14)
addq $0x20, %rcx
cmpq $0x7c, %rcx
jne 0xc5e6
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