// File: /workspace/github_c_makefile_star2_O3/S01den[P]Lost_CavernRL/menu.c
// Function: takeDrug
int takeDrug(Map map[LONGUEUR][LARGEUR], Inventory inventory[], Drug drugs[], int indice, char messagePrint[], int *colorPrint, Player *player, double *diseaseLevel)
{
	int ret = 0;
	int i = 0;
	char *typeOfDrugs[] = {"VACCIN","STEROID","ANTIDOTE","STIMULANT","HALLUCINOGEN","MEDIPAC","NEUROPARALYSANT"};

	WINDOW* win_menuInvent;
	win_menuInvent = newwin(8,30,(LONGUEUR-5)/2+7,(LARGEUR-15)/2);
	box(win_menuInvent, 0 , 0);
	
	if(inventory[indice].type == 2)
	{
		Drug drugUse = drugs[inventory[indice].object];
		if(drugUse.discovered == 0)
		{
			wattron(win_menuInvent,COLOR_PAIR(drugUse.color));
			mvwprintw(win_menuInvent,1,3,"! : UNKNOWN DRUG");
			wattroff(win_menuInvent,COLOR_PAIR(drugUse.color));
		}
		else
		{
			wattron(win_menuInvent,COLOR_PAIR(drugUse.color));
			mvwprintw(win_menuInvent,1,3,"! : %s",typeOfDrugs[drugUse.type]);
			wattroff(win_menuInvent,COLOR_PAIR(drugUse.color));
		}

			mvwprintw(win_menuInvent,3,1,"1) INJECT");
			mvwprintw(win_menuInvent,4,1,"2) DROP");

			int charMenu = wgetch(win_menuInvent);
			switch(charMenu)
			{
				case '1':
					drugs[inventory[indice].object].discovered = 1;
					for(i = 0; i < NBR_DRUGS; i++)
					{
						if(drugs[i].type == drugUse.type)
						{
							drugs[i].discovered = 1;

						}
					}
					switch(drugUse.type)
					{
						case 0: // vaccin
							if(drugUse.poisoned == 1)
							{
								*diseaseLevel+=10;
								*colorPrint = 197;
								snprintf(messagePrint,100,"YOU TOOK A POISONNED VAX ! (DISEASE LEVEL +10)");
							}
							else
							{
								*diseaseLevel-=10;
								*colorPrint = 47;
								snprintf(messagePrint,100,"YOU TOOK A VAX ! (DISEASE LEVEL -10)");
							}
							break;
						case 1: // steroid
							if(drugUse.poisoned == 1)
							{
								player->strength--;
								*colorPrint = 197;
								snprintf(messagePrint,100,"YOU TOOK A POISONNED STEROID DOSE, (-1 STR) !");
							}
							else
							{
								player->strength++;
								*colorPrint = 47;
								snprintf(messagePrint,100,"YOU TOOK A STEROID DOSE, (+1 STR) !");
							}
							break;
						case 2: // antidote
							wclear(win_menuInvent);
							wattron(win_menuInvent,A_UNDERLINE);
							mvwprintw(win_menuInvent,1,(LARGEUR-15)/4+25,"ANTIDOTE");
							wattroff(win_menuInvent,A_UNDERLINE);
							mvwprintw(win_menuInvent,2,3,"SELECT A DRUG IN YOUR INVENTORY TO DISCOVER AND CLEAN IT");
							wrefresh(win_menuInvent);

							int keyAntidote = wgetch(win_menuInvent);
							if(keyAntidote >= '1' && keyAntidote <= '9')
							{
								keyAntidote -= ('0'+1);
								if(inventory[keyAntidote].type == 2)
								{
									drugs[inventory[keyAntidote].object].discovered = 1;
									drugs[inventory[keyAntidote].object].poisoned = 0;
								}
							}
							
							*colorPrint = 47;
							snprintf(messagePrint,100,"YOU TOOK AN ANTIDOTE !");
							break;
						case 3: // stimulant
							if(drugUse.poisoned == 1)
							{
								player->agility--;
								*colorPrint = 197;
								snprintf(messagePrint,100,"YOU TOOK A POISONNED STIMULANT DOSE, (-1 AGL) !");
							}
							else
							{
								player->agility++;
								*colorPrint = 47;
								snprintf(messagePrint,100,"YOU TOOK A STIMULANT DOSE, (+1 AGL) !");
							}
							break;
						case 4: // hallucinogen
							if(player->state != 0)
								player->state2 = 3;
							else
								player->state = 3;
							player->view += 2;
							*colorPrint = 47;
							snprintf(messagePrint,120,"YOU TOOK AN HALLUCINOGEN DRUG ! YOUR VISION IS ALTERED BUT YOUR FIELD OF VIEW IS INCREASED");
							break;
						case 5: // medipac
							if(drugUse.poisoned == 1)
							{
								player->life -= 20;
								*colorPrint = 197; 
								snprintf(messagePrint,100,"YOU TOOK A POISONNED MEDIPAC, (-20 LP) !");
							}
							else
							{
								player->life += 20;
								*colorPrint = 47; 
								snprintf(messagePrint,100,"YOU TOOK A MEDIPAC, (+20 LP) !");
							}
							break;
						case 6: // neuroparalysant
								if(player->state != 0)
									player->state2 = 2;
								else
									player->state = 2;
								*colorPrint = 197; 
								snprintf(messagePrint,100,"YOU TOOK A NEUROPARALYSER POISON !");						
							break;
					}
					
					inventory[indice].type = -1;
					inventory[indice].object = 0;
					ret = 1;
					break;

				case '2':
					if(map[player->x+1][player->y].content == FLOOR)
					{
						drugs[inventory[indice].object].x = player->x+1;
						drugs[inventory[indice].object].y = player->y;
						map[player->x+1][player->y].content = DRUG;

						inventory[indice].type = -1;
						inventory[indice].object = 0;
					}
					else if(map[player->x-1][player->y].content == FLOOR)
					{
						drugs[inventory[indice].object].x = player->x-1;
						drugs[inventory[indice].object].y = player->y;
						map[player->x-1][player->y].content = DRUG;

						inventory[indice].type = -1;
						inventory[indice].object = 0;
					}
					else if(map[player->x][player->y+1].content == FLOOR)
					{
						drugs[inventory[indice].object].x = player->x;
						drugs[inventory[indice].object].y = player->y+1;
						map[player->x][player->y+1].content = DRUG;

						inventory[indice].type = -1;
						inventory[indice].object = 0;
					}
					else if(map[player->x][player->y-1].content == FLOOR)
					{
						drugs[inventory[indice].object].x = player->x;
						drugs[inventory[indice].object].y = player->y-1;
						map[player->x][player->y-1].content = DRUG;

						inventory[indice].type = -1;
						inventory[indice].object = 0;
					}	
						break;
			}

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

 return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl %ecx, %r15d
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbp
movl $0x8, %edi
movl $0x1e, %esi
movl $0x18, %edx
movl $0x39, %ecx
callq 0x1130
movq %rax, %rbx
subq $0x8, %rsp
xorl %r12d, %r12d
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r12
pushq %r12
pushq %r12
callq 0x1120
addq $0x20, %rsp
movslq %r15d, %rax
cmpl $0x2, (%r14,%rax,8)
movl $0x0, %r15d
jne 0xb338
movq %r14, (%rsp)
movq %rax, 0x20(%rsp)
movslq 0x4(%r14,%rax,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movslq (%r13,%rcx), %r14
movl 0x4(%r13,%rcx), %eax
movl %eax, 0x1c(%rsp)
movl 0x8(%r13,%rcx), %eax
movl 0x10(%r13,%rcx), %r15d
shll $0x8, %eax
movzwl %ax, %r12d
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x11c0
testl %r15d, %r15d
je 0xad56
leaq 0x5dca(%rip), %rax      # 0x10afc
movslq (%rax,%r14,4), %r8
addq %rax, %r8
leaq 0x5615(%rip), %rcx      # 0x10355
movq %rbx, %rdi
movl $0x1, %esi
movl $0x3, %edx
xorl %eax, %eax
callq 0x1070
jmp 0xad71
leaq 0x55e3(%rip), %rcx      # 0x10340
movq %rbx, %rdi
movl $0x1, %esi
movl $0x3, %edx
xorl %eax, %eax
callq 0x1070
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x1060
leaq 0x622e(%rip), %rcx      # 0x10fb6
movq %rbx, %rdi
movl $0x3, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
leaq 0x621d(%rip), %rcx      # 0x10fc0
movq %rbx, %rdi
movl $0x4, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x11e0
cmpl $0x32, %eax
je 0xae94
cmpl $0x31, %eax
movl $0x0, %r12d
movq 0x20(%rsp), %r10
jne 0xb330
movq 0x68(%rsp), %rax
movq (%rsp), %rcx
movslq 0x4(%rcx,%r10,8), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl $0x1, 0x10(%r13,%rdx)
movl $0x10, %ecx
cmpl %r14d, -0x10(%r13,%rcx)
jne 0xae13
movl $0x1, (%r13,%rcx)
addq $0x1c, %rcx
cmpq $0xd4, %rcx
jne 0xae03
movl $0x1, %r15d
cmpl $0x6, %r14d
ja 0xb242
movl %r14d, %ecx
leaq 0x5c72(%rip), %rdx      # 0x10aac
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movsd (%rax), %xmm0
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb288
addsd 0x5cc2(%rip), %xmm0     # 0x10b20
movsd %xmm0, (%rax)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x6173(%rip), %xmm0     # 0x10fe7
movq 0x10(%rsp), %rax
movups %xmm0, 0x1f(%rax)
movups 0x6154(%rip), %xmm0     # 0x10fd8
movups %xmm0, 0x10(%rax)
movups 0x6139(%rip), %xmm0     # 0x10fc8
jmp 0xb324
movq 0x60(%rsp), %rcx
movl 0x14(%rcx), %eax
movl 0x18(%rcx), %esi
movslq %eax, %rcx
leaq 0x1(%rcx), %r8
movslq %esi, %rdi
leaq (%rdi,%rdi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rdi, %rdx
imulq $0xe38, %r8, %r9        # imm = 0xE38
addq %rbp, %r9
cmpl $0x1, (%r9,%rdx)
movq 0x20(%rsp), %r10
jne 0xaeff
movq (%rsp), %r9
movslq 0x4(%r9,%r10,8), %rax
leaq (%rax,%rax,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rax, %rdi
movl %r8d, 0x14(%r13,%rdi)
movl %esi, 0x18(%r13,%rdi)
imulq $0xe38, %rcx, %rax      # imm = 0xE38
addq %rax, %rbp
movl $0x5, 0xe38(%rbp,%rdx)
jmp 0xaf47
leaq -0x1(%rcx), %r8
imulq $0xe38, %r8, %r9        # imm = 0xE38
addq %rbp, %r9
cmpl $0x1, (%r9,%rdx)
movq (%rsp), %r9
jne 0xaf52
movslq 0x4(%r9,%r10,8), %rax
leaq (%rax,%rax,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rax, %rdi
movl %r8d, 0x14(%r13,%rdi)
movl %esi, 0x18(%r13,%rdi)
imulq $0xe38, %rcx, %rax      # imm = 0xE38
addq %rax, %rbp
movl $0x5, -0xe38(%rbp,%rdx)
xorl %r15d, %r15d
xorl %r12d, %r12d
jmp 0xb327
leaq 0x1(%rdi), %rdx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rbp
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdi, %rcx
incq %rcx
cmpl $0x1, (%rbp,%rcx)
movl $0x0, %r12d
jne 0xb164
addq %rcx, %rbp
movslq 0x4(%r9,%r10,8), %rcx
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
movl %eax, 0x14(%r13,%rsi)
movl %edx, 0x18(%r13,%rsi)
jmp 0xb1a2
xorl %eax, %eax
movq 0x60(%rsp), %rcx
cmpl $0x0, 0x30(%rcx)
setne %al
movl $0x3, 0x30(%rcx,%rax,4)
addl $0x2, 0x2c(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
leaq 0x6147(%rip), %rsi      # 0x11114
movl $0x5b, %edx
movq 0x10(%rsp), %rdi
callq 0x11f0
movq 0x20(%rsp), %r10
jmp 0xb242
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
leaq 0x52ab(%rip), %rcx      # 0x102af
movl $0x1, %r15d
movq %rbx, %rdi
movl $0x1, %esi
movl $0x35, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x1060
leaq 0x603a(%rip), %rcx      # 0x1106e
movq %rbx, %rdi
movl $0x2, %esi
movl $0x3, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x11e0
leal -0x31(%rax), %ecx
cmpl $0x8, %ecx
movq (%rsp), %r9
ja 0xb096
movl %eax, %eax
cmpl $0x2, -0x188(%r9,%rax,8)
jne 0xb096
movslq -0x184(%r9,%rax,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl $0x1, 0x10(%r13,%rcx)
movl $0x0, 0x4(%r13,%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5fff(%rip), %xmm0     # 0x110a7
movq 0x10(%rsp), %rcx
movups %xmm0, (%rcx)
movabsq $0x212045544f4449, %rax # imm = 0x212045544F4449
movq %rax, 0xf(%rcx)
movq 0x20(%rsp), %r10
jmp 0xb327
movq 0x60(%rsp), %rcx
movl 0x24(%rcx), %eax
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb24b
decl %eax
movl %eax, 0x24(%rcx)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5fe8(%rip), %xmm0     # 0x110de
movq 0x10(%rsp), %rax
movups %xmm0, 0x20(%rax)
movups 0x5fc8(%rip), %xmm0     # 0x110ce
movups %xmm0, 0x10(%rax)
movups 0x5fad(%rip), %xmm0     # 0x110be
jmp 0xb324
movq 0x60(%rsp), %rcx
movl 0x20(%rcx), %eax
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb2c9
decl %eax
movl %eax, 0x20(%rcx)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5ef6(%rip), %xmm0     # 0x1103a
movq 0x10(%rsp), %rax
movups %xmm0, 0x1e(%rax)
movups 0x5ed8(%rip), %xmm0     # 0x1102c
movups %xmm0, 0x10(%rax)
movups 0x5ebd(%rip), %xmm0     # 0x1101c
jmp 0xb324
leaq -0x1(%rdi), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rdi, %rdx
decq %rdx
cmpl $0x1, (%rbp,%rdx)
jne 0xb330
addq %rdx, %rbp
movq (%rsp), %r9
movslq 0x4(%r9,%r10,8), %rdx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movl %eax, 0x14(%r13,%rsi)
movl %ecx, 0x18(%r13,%rsi)
movl $0x5, (%rbp)
xorl %r15d, %r15d
jmp 0xb327
movq 0x60(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb2fc
addl $-0x14, %eax
movl %eax, 0x10(%rcx)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5fa8(%rip), %xmm0     # 0x11188
movq 0x10(%rsp), %rax
movups %xmm0, 0x19(%rax)
movups 0x5f8f(%rip), %xmm0     # 0x1117f
movups %xmm0, 0x10(%rax)
movups 0x5f74(%rip), %xmm0     # 0x1116f
jmp 0xb324
xorl %eax, %eax
movq 0x60(%rsp), %rcx
cmpl $0x0, 0x30(%rcx)
setne %al
movl $0x2, 0x30(%rcx,%rax,4)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5f9f(%rip), %xmm0     # 0x111c7
movq 0x10(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x5f7f(%rip), %xmm0     # 0x111b7
movups %xmm0, (%rax)
movl $0x21204e, 0x1f(%rax)   # imm = 0x21204E
movq (%rsp), %r9
jmp 0xb327
incl %eax
movl %eax, 0x24(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5e9c(%rip), %xmm0     # 0x110fe
movq 0x10(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups 0x5e7c(%rip), %xmm0     # 0x110ee
movups %xmm0, (%rcx)
movabsq $0x2120294c474120, %rax # imm = 0x2120294C474120
movq %rax, 0x1e(%rcx)
jmp 0xb327
addsd 0x5888(%rip), %xmm0     # 0x10b18
movsd %xmm0, (%rax)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5d61(%rip), %xmm0     # 0x11007
movq 0x10(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups 0x5d41(%rip), %xmm0     # 0x10ff7
movups %xmm0, (%rcx)
movabsq $0x2930312d204c45, %rax # imm = 0x2930312D204C45
movq %rax, 0x1d(%rcx)
jmp 0xb327
incl %eax
movl %eax, 0x20(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5d7a(%rip), %xmm0     # 0x1105a
movq 0x10(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x5d5a(%rip), %xmm0     # 0x1104a
movups %xmm0, (%rax)
movl $0x212029, 0x20(%rax)   # imm = 0x212029
jmp 0xb327
addl $0x14, %eax
movl %eax, 0x10(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5e93(%rip), %xmm0     # 0x111a7
movq 0x10(%rsp), %rax
movups %xmm0, 0xf(%rax)
movups 0x5e74(%rip), %xmm0     # 0x11198
movups %xmm0, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%r9,%r10,8)
movq %rbx, %rdi
callq 0x1100
subq $0x8, %rsp
movl $0x20, %r14d
movq %rbx, %rdi
movl $0x20, %esi
movl $0x20, %edx
movl $0x20, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r12
pushq %r12
pushq %r12
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 %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq