// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movslq 0x9c(%rsp), %rax
shlq $0x5, %rax
cmpl $0x0, 0x1c(%rdi,%rax)
je 0xad1d
pushq $-0x1
popq %r14
jmp 0xb09d
movq %r8, %r12
movq %rdi, %rbx
movq %rcx, 0x18(%rsp)
movq %r9, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x90(%rsp), %r15
pushq $0xd
popq %rdi
pushq $0x13
popq %rdx
pushq $0x4b
popq %rcx
movl %ecx, %esi
callq 0x1130
movq %rbx, %r13
movq %rax, %rbx
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1120
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
movq (%r15), %r8
movslq 0x8(%r15), %rax
movq 0x30(%rsp), %r15
leaq 0x45e2(%rip), %rcx      # 0xf380
movslq (%rcx,%rax,4), %r9
addq %rcx, %r9
leaq 0x3482(%rip), %rcx      # 0xe22e
pushq $0x2
popq %rbp
pushq $0x16
popq %rdx
movq %rbx, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x1060
leaq (%r15,%r13), %r14
movq 0x8(%r13,%r15), %r8
leaq 0x353c(%rip), %rcx      # 0xe319
pushq $0x4
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1080
movq %r13, 0x28(%rsp)
movslq 0x10(%r13,%r15), %rax
cmpq $0x3, %rax
movq %r14, 0x20(%rsp)
jg 0xae37
movl 0x14(%r14), %r8d
leaq 0x4579(%rip), %rcx      # 0xf390
movslq (%rcx,%rax,4), %r9
addq %rcx, %r9
leaq 0x3ce4(%rip), %rcx      # 0xeb09
pushq $0x7
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
jmp 0xae9f
cmpl $0x6, %eax
je 0xae88
cmpl $0x5, %eax
je 0xae5e
cmpl $0x4, %eax
jne 0xae9f
movq 0x20(%rsp), %rax
movslq 0x14(%rax), %rax
shlq $0x6, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax), %r8
jmp 0xae6f
movq 0x20(%rsp), %rax
movslq 0x14(%rax), %rax
imulq $0x30, %rax, %rax
movq (%r12,%rax), %r8
leaq 0x3cab(%rip), %rcx      # 0xeb21
pushq $0x7
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
jmp 0xae9f
leaq 0x3ca5(%rip), %rcx      # 0xeb34
pushq $0x7
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
movq 0x28(%rsp), %rax
addq %r15, %rax
addq $0x1c, %rax
movq %rax, 0x50(%rsp)
xorl %edx, %edx
movl %edx, %r13d
movq %rdx, 0x18(%rsp)
leal 0x9(%rdx), %r14d
leaq (,%r13,8), %r15
xorl %r12d, %r12d
pushq $0x9
popq %rbp
cmpq $0x10, %r12
je 0xaf34
cmpq %r12, %r15
jne 0xaf12
movq %rbx, %rdi
movl $0xfe00, %esi           # imm = 0xFE00
xorl %edx, %edx
callq 0x11c0
leaq 0x7ec3(%rip), %rax      # 0x12db0
movq (%rax,%r13,8), %rcx
movq %rbx, %rdi
movl %r14d, %esi
pushq $0x1b
popq %rdx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0xfe00, %esi           # imm = 0xFE00
xorl %edx, %edx
callq 0x1060
jmp 0xaf2c
leaq 0x7e97(%rip), %rax      # 0x12db0
movq (%r12,%rax), %rcx
movq %rbx, %rdi
movl %ebp, %esi
pushq $0x1b
popq %rdx
xorl %eax, %eax
callq 0x1070
incl %ebp
addq $0x8, %r12
jmp 0xaecc
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x11e0
cmpl $0xa, %eax
je 0xaf7d
cmpl $0x103, %eax            # imm = 0x103
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %rdx
je 0xaf6e
cmpl $0x102, %eax            # imm = 0x102
jne 0xaf77
xorl %eax, %eax
testl %edx, %edx
setle %al
addl %edx, %eax
movl %eax, %edx
jmp 0xaf77
xorl %eax, %eax
testl %edx, %edx
setg %al
subl %eax, %edx
pushq $-0x1
popq %r14
jmp 0xaf8a
movq 0x18(%rsp), %rdx
movl %edx, %r14d
movq 0x30(%rsp), %rcx
cmpl $-0x1, %r14d
je 0xaeb2
testl %r14d, %r14d
movq 0x20(%rsp), %r8
pushq $0x1
popq %r9
jne 0xb041
xorl %r14d, %r14d
movq 0x38(%rsp), %rax
cmpl $0x2, (%rax)
jg 0xb041
movq 0x28(%rsp), %rax
cmpl $0x2, 0x18(%rax,%rcx)
jne 0xafcc
movq 0x48(%rsp), %rax
andq $0x0, (%rax)
movq 0x28(%rsp), %rax
addq %rcx, %rax
addq $0x18, %rax
pushq $0x1c
popq %rcx
movq 0xb8(%rsp), %r10
movq 0xb0(%rsp), %r11
movq 0x40(%rsp), %rdi
cmpq $0x7c, %rcx
je 0xb03a
movq 0x40(%rsp), %rdx
cmpl $0x0, (%rdx,%rcx)
jne 0xb034
movups (%r8), %xmm0
movups %xmm0, -0x1c(%rdi,%rcx)
movl (%rax), %edx
movl %edx, -0x4(%rdi,%rcx)
movl %r9d, (%rdi,%rcx)
movq 0x50(%rsp), %rsi
movl %r9d, (%rsi)
movq -0x8(%rax), %rsi
movq %rsi, -0xc(%rdi,%rcx)
testl %edx, %edx
jne 0xb034
andl $0x0, (%r10)
movl $0x1, (%r11)
addq $0x20, %rcx
jmp 0xaff0
movq 0x38(%rsp), %rax
incl (%rax)
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x20
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x1120
movl %ebp, 0x10(%rsp)
movl %ebp, 0x8(%rsp)
movl %ebp, (%rsp)
movq %rbx, %rdi
movl %ebp, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl %ebp, %r8d
movl %ebp, %r9d
callq 0x1120
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x1110
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq