// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
pushq $0x8
popq %rdi
pushq $0x1e
popq %rsi
pushq $0x18
popq %rdx
pushq $0x39
popq %rcx
callq 0x1130
movq %rax, %rbx
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
xorl %r15d, %r15d
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1120
movslq %ebp, %rax
cmpl $0x2, (%r14,%rax,8)
jne 0x9d69
movq %r14, 0x20(%rsp)
movq %rax, 0x40(%rsp)
movslq 0x4(%r14,%rax,8), %rax
imulq $0x1c, %rax, %rax
movslq (%r13,%rax), %r14
movl 0x4(%r13,%rax), %ecx
movl %ecx, 0x3c(%rsp)
movl 0x8(%r13,%rax), %ecx
movl 0x10(%r13,%rax), %r15d
shll $0x8, %ecx
movzwl %cx, %ebp
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x11c0
testl %r15d, %r15d
je 0x97db
leaq 0x5301(%rip), %rax      # 0xeabc
movslq (%rax,%r14,4), %r8
addq %rax, %r8
leaq 0x4b4c(%rip), %rcx      # 0xe315
pushq $0x1
popq %rsi
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
jmp 0x97f2
leaq 0x4b1e(%rip), %rcx      # 0xe300
pushq $0x1
popq %rsi
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
xorl %r15d, %r15d
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x1060
leaq 0x576e(%rip), %rcx      # 0xef76
pushq $0x3
popq %rsi
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
leaq 0x575f(%rip), %rcx      # 0xef80
pushq $0x4
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x11e0
cmpl $0x32, %eax
je 0x98ff
cmpl $0x31, %eax
movq 0x40(%rsp), %r10
jne 0x9d61
movq 0x88(%rsp), %rax
movq 0x20(%rsp), %rcx
movslq 0x4(%rcx,%r10,8), %rcx
imulq $0x1c, %rcx, %rcx
movl $0x1, 0x10(%r13,%rcx)
pushq $0x10
popq %rcx
cmpq $0xd4, %rcx
je 0x9890
cmpl %r14d, -0x10(%r13,%rcx)
jne 0x988a
movl $0x1, (%r13,%rcx)
addq $0x1c, %rcx
jmp 0x9871
cmpl $0x6, %r14d
ja 0x9c6f
movl %r14d, %ecx
leaq 0x51c8(%rip), %rdx      # 0xea6c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movsd (%rax), %xmm0
cmpl $0x1, 0x3c(%rsp)
movq 0x20(%rsp), %r9
jne 0x9cb6
addsd 0x5217(%rip), %xmm0     # 0xeae0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rax
movl $0xc5, (%rax)
movups 0x56c8(%rip), %xmm0     # 0xefa7
movq 0x30(%rsp), %rax
movups %xmm0, 0x1f(%rax)
movups 0x56a9(%rip), %xmm0     # 0xef98
movups %xmm0, 0x10(%rax)
movups 0x568e(%rip), %xmm0     # 0xef88
jmp 0x9d52
movq 0x80(%rsp), %rcx
movl 0x14(%rcx), %eax
movl 0x18(%rcx), %edi
movslq %eax, %rdx
leaq 0x1(%rdx), %r8
movslq %edi, %rcx
imulq $0xe38, %r8, %r9        # imm = 0xE38
addq %r12, %r9
imulq $0x1c, %rcx, %rsi
cmpl $0x1, (%rsi,%r9)
movq 0x40(%rsp), %r10
jne 0x9964
movq 0x20(%rsp), %r9
movslq 0x4(%r9,%r10,8), %rax
imulq $0x1c, %rax, %rax
movl %r8d, 0x14(%r13,%rax)
movl %edi, 0x18(%r13,%rax)
imulq $0xe38, %rdx, %rax      # imm = 0xE38
addq %rax, %r12
movl $0x5, 0xe38(%rsi,%r12)
jmp 0x9bd0
leaq -0x1(%rdx), %r8
imulq $0xe38, %r8, %r9        # imm = 0xE38
addq %r12, %r9
cmpl $0x1, (%rsi,%r9)
movq 0x20(%rsp), %r9
jne 0x99ac
movslq 0x4(%r9,%r10,8), %rax
imulq $0x1c, %rax, %rax
movl %r8d, 0x14(%r13,%rax)
movl %edi, 0x18(%r13,%rax)
imulq $0xe38, %rdx, %rax      # imm = 0xE38
addq %rax, %r12
movl $0x5, -0xe38(%rsi,%r12)
jmp 0x9bd0
leaq 0x1(%rcx), %rsi
imulq $0xe38, %rdx, %rdx      # imm = 0xE38
addq %rdx, %r12
imulq $0x1c, %rsi, %rdx
cmpl $0x1, (%rdx,%r12)
jne 0x9b9b
addq %rdx, %r12
movslq 0x4(%r9,%r10,8), %rcx
imulq $0x1c, %rcx, %rcx
movl %eax, 0x14(%r13,%rcx)
movl %esi, 0x18(%r13,%rcx)
jmp 0x9bc8
xorl %eax, %eax
movq 0x80(%rsp), %rcx
cmpl $0x0, 0x30(%rcx)
setne %al
movl $0x3, 0x30(%rcx,%rax,4)
addl $0x2, 0x2c(%rcx)
movq 0x28(%rsp), %rax
movl $0x2f, (%rax)
leaq 0x56c1(%rip), %rsi      # 0xf0d4
pushq $0x5b
popq %rdx
movq 0x30(%rsp), %rdi
callq 0x11f0
movq 0x40(%rsp), %r10
jmp 0x9c6f
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
leaq 0x4827(%rip), %rcx      # 0xe26f
pushq $0x1
popq %rbp
pushq $0x35
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 0x55be(%rip), %rcx      # 0xf02e
pushq $0x2
popq %rsi
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x1100
movq %rbx, %rdi
callq 0x11e0
leal -0x31(%rax), %ecx
cmpl $0x8, %ecx
movq 0x20(%rsp), %r9
ja 0x9ac5
movl %eax, %eax
cmpl $0x2, -0x188(%r9,%rax,8)
jne 0x9ac5
movslq -0x184(%r9,%rax,8), %rax
imulq $0x1c, %rax, %rax
movl $0x1, 0x10(%r13,%rax)
andl $0x0, 0x4(%r13,%rax)
movq 0x28(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5590(%rip), %xmm0     # 0xf067
movq 0x30(%rsp), %rcx
movups %xmm0, (%rcx)
movabsq $0x212045544f4449, %rax # imm = 0x212045544F4449
movq %rax, 0xf(%rcx)
movq 0x40(%rsp), %r10
jmp 0x9d55
movq 0x80(%rsp), %rcx
movl 0x24(%rcx), %eax
cmpl $0x1, 0x3c(%rsp)
movq 0x20(%rsp), %r9
jne 0x9c79
decl %eax
movl %eax, 0x24(%rcx)
movq 0x28(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5575(%rip), %xmm0     # 0xf09e
movq 0x30(%rsp), %rax
movups %xmm0, 0x20(%rax)
movups 0x5555(%rip), %xmm0     # 0xf08e
movups %xmm0, 0x10(%rax)
movups 0x553a(%rip), %xmm0     # 0xf07e
jmp 0x9d52
movq 0x80(%rsp), %rcx
movl 0x20(%rcx), %eax
cmpl $0x1, 0x3c(%rsp)
movq 0x20(%rsp), %r9
jne 0x9cf7
decl %eax
movl %eax, 0x20(%rcx)
movq 0x28(%rsp), %rax
movl $0xc5, (%rax)
movups 0x547f(%rip), %xmm0     # 0xeffa
movq 0x30(%rsp), %rax
movups %xmm0, 0x1e(%rax)
movups 0x5461(%rip), %xmm0     # 0xefec
movups %xmm0, 0x10(%rax)
movups 0x5446(%rip), %xmm0     # 0xefdc
jmp 0x9d52
decq %rcx
imulq $0x1c, %rcx, %rdx
cmpl $0x1, (%rdx,%r12)
jne 0x9d61
addq %rdx, %r12
movq 0x20(%rsp), %r9
movslq 0x4(%r9,%r10,8), %rdx
imulq $0x1c, %rdx, %rdx
movl %eax, 0x14(%r13,%rdx)
movl %ecx, 0x18(%r13,%rdx)
movl $0x5, (%r12)
xorl %ebp, %ebp
jmp 0x9d55
movq 0x80(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpl $0x1, 0x3c(%rsp)
movq 0x20(%rsp), %r9
jne 0x9d2a
addl $-0x14, %eax
movl %eax, 0x10(%rcx)
movq 0x28(%rsp), %rax
movl $0xc5, (%rax)
movups 0x553e(%rip), %xmm0     # 0xf148
movq 0x30(%rsp), %rax
movups %xmm0, 0x19(%rax)
movups 0x5525(%rip), %xmm0     # 0xf13f
movups %xmm0, 0x10(%rax)
movups 0x550a(%rip), %xmm0     # 0xf12f
jmp 0x9d52
xorl %eax, %eax
movq 0x80(%rsp), %rcx
cmpl $0x0, 0x30(%rcx)
setne %al
movl $0x2, 0x30(%rcx,%rax,4)
movq 0x28(%rsp), %rax
movl $0xc5, (%rax)
movups 0x5532(%rip), %xmm0     # 0xf187
movq 0x30(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x5512(%rip), %xmm0     # 0xf177
movups %xmm0, (%rax)
movl $0x21204e, 0x1f(%rax)   # imm = 0x21204E
movq 0x20(%rsp), %r9
jmp 0x9d55
incl %eax
movl %eax, 0x24(%rcx)
movq 0x28(%rsp), %rax
movl $0x2f, (%rax)
movups 0x542e(%rip), %xmm0     # 0xf0be
movq 0x30(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups 0x540e(%rip), %xmm0     # 0xf0ae
movups %xmm0, (%rcx)
movabsq $0x2120294c474120, %rax # imm = 0x2120294C474120
movq %rax, 0x1e(%rcx)
jmp 0x9d55
addsd 0x4e1a(%rip), %xmm0     # 0xead8
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rax
movl $0x2f, (%rax)
movups 0x52f3(%rip), %xmm0     # 0xefc7
movq 0x30(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups 0x52d3(%rip), %xmm0     # 0xefb7
movups %xmm0, (%rcx)
movabsq $0x2930312d204c45, %rax # imm = 0x2930312D204C45
movq %rax, 0x1d(%rcx)
jmp 0x9d55
incl %eax
movl %eax, 0x20(%rcx)
movq 0x28(%rsp), %rax
movl $0x2f, (%rax)
movups 0x530c(%rip), %xmm0     # 0xf01a
movq 0x30(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x52ec(%rip), %xmm0     # 0xf00a
movups %xmm0, (%rax)
movl $0x212029, 0x20(%rax)   # imm = 0x212029
jmp 0x9d55
addl $0x14, %eax
movl %eax, 0x10(%rcx)
movq 0x28(%rsp), %rax
movl $0x2f, (%rax)
movups 0x5425(%rip), %xmm0     # 0xf167
movq 0x30(%rsp), %rax
movups %xmm0, 0xf(%rax)
movups 0x5406(%rip), %xmm0     # 0xf158
movups %xmm0, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%r9,%r10,8)
movl %ebp, %r15d
movq %rbx, %rdi
callq 0x1100
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 %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq