// File: /workspace/github_c_makefile_star2_O1/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 0xb243
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 0xac61
leaq 0x5ddb(%rip), %rax      # 0x10a18
movslq (%rax,%r14,4), %r8
addq %rax, %r8
leaq 0x56ae(%rip), %rcx      # 0x102f9
movq %rbx, %rdi
movl $0x1, %esi
movl $0x3, %edx
xorl %eax, %eax
callq 0x1070
jmp 0xac7c
leaq 0x567c(%rip), %rcx      # 0x102e4
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 0x6243(%rip), %rcx      # 0x10ed6
movq %rbx, %rdi
movl $0x3, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
leaq 0x6232(%rip), %rcx      # 0x10ee0
movq %rbx, %rdi
movl $0x4, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x11e0
cmpl $0x32, %eax
je 0xad9f
cmpl $0x31, %eax
movl $0x0, %r12d
movq 0x20(%rsp), %r10
jne 0xb23b
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 0xad1e
movl $0x1, (%r13,%rcx)
addq $0x1c, %rcx
cmpq $0xd4, %rcx
jne 0xad0e
movl $0x1, %r15d
cmpl $0x6, %r14d
ja 0xb14d
movl %r14d, %ecx
leaq 0x5c83(%rip), %rdx      # 0x109c8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movsd (%rax), %xmm0
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb193
addsd 0x5cd7(%rip), %xmm0     # 0x10a40
movsd %xmm0, (%rax)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x6188(%rip), %xmm0     # 0x10f07
movq 0x10(%rsp), %rax
movups %xmm0, 0x1f(%rax)
movups 0x6169(%rip), %xmm0     # 0x10ef8
movups %xmm0, 0x10(%rax)
movups 0x614e(%rip), %xmm0     # 0x10ee8
jmp 0xb22f
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 0xae0a
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 0xae52
leaq -0x1(%rcx), %r8
imulq $0xe38, %r8, %r9        # imm = 0xE38
addq %rbp, %r9
cmpl $0x1, (%r9,%rdx)
movq (%rsp), %r9
jne 0xae5d
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 0xb232
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 0xb06f
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 0xb0ad
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 0x615c(%rip), %rsi      # 0x11034
movl $0x5b, %edx
movq 0x10(%rsp), %rdi
callq 0x11f0
movq 0x20(%rsp), %r10
jmp 0xb14d
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
leaq 0x5344(%rip), %rcx      # 0x10253
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 0x604f(%rip), %rcx      # 0x10f8e
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 0xafa1
movl %eax, %eax
cmpl $0x2, -0x188(%r9,%rax,8)
jne 0xafa1
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 0x6014(%rip), %xmm0     # 0x10fc7
movq 0x10(%rsp), %rcx
movups %xmm0, (%rcx)
movabsq $0x212045544f4449, %rax # imm = 0x212045544F4449
movq %rax, 0xf(%rcx)
movq 0x20(%rsp), %r10
jmp 0xb232
movq 0x60(%rsp), %rcx
movl 0x24(%rcx), %eax
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb156
decl %eax
movl %eax, 0x24(%rcx)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5ffd(%rip), %xmm0     # 0x10ffe
movq 0x10(%rsp), %rax
movups %xmm0, 0x20(%rax)
movups 0x5fdd(%rip), %xmm0     # 0x10fee
movups %xmm0, 0x10(%rax)
movups 0x5fc2(%rip), %xmm0     # 0x10fde
jmp 0xb22f
movq 0x60(%rsp), %rcx
movl 0x20(%rcx), %eax
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb1d4
decl %eax
movl %eax, 0x20(%rcx)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5f0b(%rip), %xmm0     # 0x10f5a
movq 0x10(%rsp), %rax
movups %xmm0, 0x1e(%rax)
movups 0x5eed(%rip), %xmm0     # 0x10f4c
movups %xmm0, 0x10(%rax)
movups 0x5ed2(%rip), %xmm0     # 0x10f3c
jmp 0xb22f
leaq -0x1(%rdi), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rdi, %rdx
decq %rdx
cmpl $0x1, (%rbp,%rdx)
jne 0xb23b
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 0xb232
movq 0x60(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpl $0x1, 0x1c(%rsp)
movq (%rsp), %r9
jne 0xb207
addl $-0x14, %eax
movl %eax, 0x10(%rcx)
movq 0x8(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5fbd(%rip), %xmm0     # 0x110a8
movq 0x10(%rsp), %rax
movups %xmm0, 0x19(%rax)
movups 0x5fa4(%rip), %xmm0     # 0x1109f
movups %xmm0, 0x10(%rax)
movups 0x5f89(%rip), %xmm0     # 0x1108f
jmp 0xb22f
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 0x5fb4(%rip), %xmm0     # 0x110e7
movq 0x10(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x5f94(%rip), %xmm0     # 0x110d7
movups %xmm0, (%rax)
movl $0x21204e, 0x1f(%rax)   # imm = 0x21204E
movq (%rsp), %r9
jmp 0xb232
incl %eax
movl %eax, 0x24(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5eb1(%rip), %xmm0     # 0x1101e
movq 0x10(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups 0x5e91(%rip), %xmm0     # 0x1100e
movups %xmm0, (%rcx)
movabsq $0x2120294c474120, %rax # imm = 0x2120294C474120
movq %rax, 0x1e(%rcx)
jmp 0xb232
addsd 0x589d(%rip), %xmm0     # 0x10a38
movsd %xmm0, (%rax)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5d76(%rip), %xmm0     # 0x10f27
movq 0x10(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups 0x5d56(%rip), %xmm0     # 0x10f17
movups %xmm0, (%rcx)
movabsq $0x2930312d204c45, %rax # imm = 0x2930312D204C45
movq %rax, 0x1d(%rcx)
jmp 0xb232
incl %eax
movl %eax, 0x20(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5d8f(%rip), %xmm0     # 0x10f7a
movq 0x10(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x5d6f(%rip), %xmm0     # 0x10f6a
movups %xmm0, (%rax)
movl $0x212029, 0x20(%rax)   # imm = 0x212029
jmp 0xb232
addl $0x14, %eax
movl %eax, 0x10(%rcx)
movq 0x8(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5ea8(%rip), %xmm0     # 0x110c7
movq 0x10(%rsp), %rax
movups %xmm0, 0xf(%rax)
movups 0x5e89(%rip), %xmm0     # 0x110b8
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