// File: /workspace/github_c_makefile_star2_O2/S01den[P]Lost_CavernRL/screen.c
// Function: recalcScreen
void recalcScreen(WINDOW *win_map, Map map[LONGUEUR][LARGEUR], int nbrEnnemies, Ennemy ennemies[])
{
	const char tileset_ennemies[] = "dtgn";
	const char tileset[] = " .#>=!+]/;* ?";
	const char tileset_pnj[] = "cwes";
	
	int j = 0;
	int i = 0;

	for(i = 0; i < LARGEUR; i++)
	{
		for(j = 0; j < LONGUEUR; j++)
		{
			if(map[j][i].seen == 1)
			{
				if(map[j][i].typeEnnemy == 0)
				{
					if(map[j][i].content == STAIRS)
					{
						wattron(win_map,A_BOLD);
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,A_BOLD);
					}
					else if(map[j][i].content == HOLE)
					{
						wattron(win_map,COLOR_PAIR(COLOR_HOLE));
						mvwprintw(win_map,j+1,i+1," ");
						wattroff(win_map,COLOR_PAIR(COLOR_HOLE));	
					}
					else if(map[j][i].content == MINES || map[j][i].content == DIST_WEAPON || map[j][i].content == CONTACT_WEAPON || map[j][i].content == DRUG || map[j][i].content == COMPUTER)
					{
						wattron(win_map,A_BOLD);
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,A_BOLD);		
					}
					else if(map[j][i].content == DOOR)
					{
						wattron(win_map,COLOR_PAIR(15));
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,COLOR_PAIR(15));			
					}
					else if(map[j][i].content == PNJ)
					{
						wattron(win_map,A_BOLD);
						mvwprintw(win_map,j+1,i+1,"%c",tileset_pnj[map[j][i].typePnj]);
						wattroff(win_map,A_BOLD);
					}				
					else if(map[j][i].content == BOMB)
					{
						wattron(win_map,A_BOLD);
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,A_BOLD);
						if(map[j][i].resistance-1 > 0)
						{
							map[j][i].resistance--;
						}
						else // EXPLOSION !!!
						{
							map[j][i].resistance = 0;
							map[j][i].content = FLOOR;
							map[j][i].effect = 2;
							if(i > 0)
								map[j][i-1].effect = 2;
							if(i < LARGEUR-1)
								map[j][i+1].effect = 2;
							if(j > 0)
								map[j-1][i].effect = 2;		
							if(j < LONGUEUR-1)
								map[j+1][i].effect = 2;

							int k = 0;
							int l = 0;

							int minJ = j-5;
							if(minJ < 0)
								minJ = 0;
							int maxJ = j+5;
							if(maxJ >= LONGUEUR)
								minJ = LONGUEUR-1;
							int minI = i-5;
							if(minI < 0)
								minI = 0;
							int maxI = i+5;
							if(maxI >= LARGEUR)
								maxI = LARGEUR-1;

							for(k = minJ; k <= maxJ; k++)
							{
								for(l = minI; l <= maxI; l++)
								{
									if(testEnnemyOnPos(ennemies,k,l,nbrEnnemies) >= 0)
									{
										ennemies[testEnnemyOnPos(ennemies,k,l,nbrEnnemies)].life -= 21+rand()%10;
									}
									if(rand()%4 <= 2)
									{
										map[k][l].resistance = 0;
										map[k][l].content = FLOOR;
									}
									if(rand()%5 == 0) //set fire
										map[k][l].effect = 1;	
								}
							}	

							flashBomb(win_map);
						}
					}
					else if(map[j][i].effect == 0)
					{
						wattron(win_map,A_DIM);
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,A_DIM);
					}
					else if(map[j][i].effect == 1) // fire
					{
						if(rand()%300 <= 298)
						{
							if(rand()%4 == 3)
							{
								wattron(win_map,COLOR_PAIR(10));
								mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
								wattroff(win_map,COLOR_PAIR(10));		
							}
							else
							{
								wattron(win_map,COLOR_PAIR(203));
								mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
								wattroff(win_map,COLOR_PAIR(203));
							}					
						}
						else
						{
							map[j][i].effect = 0;
							wattron(win_map,A_BOLD);
							mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
							wattroff(win_map,A_BOLD);						
						}

						if(map[j][i].content == WALL && rand()%10 == 2)
						{
							if(map[j][i].resistance-1 > 0)
							{
								map[j][i].resistance--;
							}
							else
							{
								map[j][i].resistance = 0;
								if(rand()%100 <= 90)
									map[j][i].content = FLOOR;
								else
								{
									map[j][i].content = MINES;
									map[j][i].trap = 1;
								}
							}
						}						
					}
					else if(map[j][i].effect == 2) // radioactive
					{
						wattron(win_map,COLOR_PAIR(41));
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,COLOR_PAIR(41));				
					}
					else if(map[j][i].effect == 4) // gem
					{
						wattron(win_map,COLOR_PAIR(124));
						mvwprintw(win_map,j+1,i+1,"%c",tileset[map[j][i].content]);
						wattroff(win_map,COLOR_PAIR(124));				
					}
					else if(map[j][i].effect == 3) // lava
					{
						if(rand()%4 == 0)
						{
							wattron(win_map,COLOR_PAIR(203));
							mvwprintw(win_map,j+1,i+1,"*");
							wattroff(win_map,COLOR_PAIR(203));
						}
						else
						{
							wattron(win_map,COLOR_PAIR(COLOR_LAVA));
							mvwprintw(win_map,j+1,i+1,"*");
							wattroff(win_map,COLOR_PAIR(COLOR_LAVA));
						}

						int counterX = 0;
						int counterY = 0;

						for(counterX = -1; counterX <= 1; counterX++) // the lava flow
						{
							for(counterY = -1; counterY <= 1; counterY++)
							{
								if(rand()%10 == 0)
								{
									if(map[j+counterX][i+counterY].content == FLOOR || map[j+counterX][i+counterY].content == CONTACT_WEAPON || map[j+counterX][i+counterY].content == DIST_WEAPON)
									{
										map[j+counterX][i+counterY].effect = 3;
									}
								}
							}
						}		
					}				
				}
				else
				{
					int ennemy = testEnnemyOnPos(ennemies,j,i,nbrEnnemies);
					if(ennemy >= 0)
					{
						ennemies[ennemy].seen = 0;
						wattron(win_map,A_BOLD);
						mvwprintw(win_map,j+1,i+1,"%c",tileset_ennemies[map[j][i].typeEnnemy-1]);
						wattroff(win_map,A_BOLD);
					}
				}
			}				
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movl %edx, %ebp
leaq -0xe38(%rsi), %rax
movq %rax, 0x50(%rsp)
leaq -0x8c(%rsi), %rax
movq %rax, 0x48(%rsp)
movq %rsi, 0x38(%rsp)
leaq -0xe50(%rsi), %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %rdi, 0x10(%rsp)
movq %rax, 0x20(%rsp)
cmpl $0x6, %eax
pushq $0x5
popq %rax
movl %eax, %esi
movq 0x20(%rsp), %rax
cmovgel %eax, %esi
cmpq $0x82, %rax
je 0xc82b
imulq $0x1c, %rsi, %rdi
addq $-0x5, %rsi
imulq $0x1c, %rax, %rcx
movq %rax, %rdx
movq 0x50(%rsp), %rax
movq %rcx, 0x28(%rsp)
addq %rcx, %rax
addq $0x4, %rax
movq %rax, 0x60(%rsp)
leaq 0x1(%rdx), %rax
movq %rax, 0x8(%rsp)
leaq -0x1(%rdx), %rax
cmpl $0x7c, %edx
pushq $0x7c
popq %rcx
cmovbl %edx, %ecx
addl $0x5, %ecx
movq %rcx, 0x80(%rsp)
addq 0x48(%rsp), %rdi
movq %rdi, 0x68(%rsp)
imulq $0x1c, %rax, %rax
movq %rax, 0x58(%rsp)
movq 0x30(%rsp), %rax
xorl %r15d, %r15d
movq %rsi, 0x78(%rsp)
cmpq $0x27, %r15
je 0xc81b
movq %rax, 0x40(%rsp)
imulq $0xe38, %r15, %r12      # imm = 0xE38
movq 0x38(%rsp), %rax
leaq (%rax,%r12), %r13
movq 0x28(%rsp), %rax
cmpl $0x1, 0x8(%rax,%r13)
jne 0xc27c
movq %r15, (%rsp)
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %r15
cmpl $0x0, 0xc(%r15)
je 0xc20f
movq %r15, %r12
movq %rbx, %rdi
movq (%rsp), %r15
movl %r15d, %esi
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
callq 0x4f9a
testl %eax, %eax
js 0xc27c
movl %eax, %eax
imulq $0x38, %rax, %rax
andl $0x0, 0xc(%rbx,%rax)
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x11c0
movslq 0xc(%r12), %rax
leaq 0x3802(%rip), %rcx      # 0xfa09
movsbl -0x1(%rax,%rcx), %r8d
jmp 0xc253
movl (%r15), %eax
cmpq $0xc, %rax
ja 0xc2da
leaq 0x3795(%rip), %rcx      # 0xf9b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x11c0
movslq (%r15), %rax
leaq 0x37c4(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq (%rsp), %r15
leal 0x1(%r15), %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
leaq 0x379a(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x1060
incq %r15
movq 0x40(%rsp), %rax
addq $0xe38, %rax            # imm = 0xE38
jmp 0xc177
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0xf00, %esi            # imm = 0xF00
xorl %edx, %edx
callq 0x11c0
movslq (%r15), %rax
leaq 0x3761(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq (%rsp), %r15
leal 0x1(%r15), %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
leaq 0x3737(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0xf00, %esi            # imm = 0xF00
jmp 0xc275
movq %r15, %r13
movl 0x4(%r15), %eax
cmpq $0x4, %rax
movq (%rsp), %r15
ja 0xc27c
leaq 0x36fa(%rip), %rcx      # 0xf9ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x100000, %esi         # imm = 0x100000
xorl %edx, %edx
callq 0x11c0
movslq (%r13), %rax
leaq 0x36f4(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq (%rsp), %r15
leal 0x1(%r15), %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
leaq 0x36ca(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0x100000, %esi         # imm = 0x100000
jmp 0xc275
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x11c0
movslq 0x10(%r15), %rax
leaq 0x36b3(%rip), %rcx      # 0xfa1c
jmp 0xc24a
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x11c0
movq (%rsp), %rax
leaq 0x1(%rax), %rsi
movslq (%r15), %rax
leaq 0x367a(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq %r14, %rdi
movq %rsi, 0x18(%rsp)
movq 0x8(%rsp), %rdx
leaq 0x3653(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x1060
movl 0x14(%r15), %eax
cmpl $0x2, %eax
jl 0xc416
decl %eax
movl %eax, 0x14(%r15)
jmp 0xc58a
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0xea00, %esi           # imm = 0xEA00
xorl %edx, %edx
callq 0x11c0
movq (%rsp), %r15
leal 0x1(%r15), %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
leaq 0xdfc(%rip), %rcx       # 0xd1fe
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0xea00, %esi           # imm = 0xEA00
jmp 0xc275
andl $0x0, 0x14(%r15)
movabsq $0x200000001, %rax      # imm = 0x200000001
movq %rax, (%r15)
cmpq $0x0, 0x20(%rsp)
je 0xc449
movq 0x58(%rsp), %rax
movl $0x2, 0x4(%rax,%r13)
cmpq $0x81, 0x20(%rsp)
je 0xc458
imulq $0x1c, 0x8(%rsp), %rax
movl $0x2, 0x4(%rax,%r13)
movq (%rsp), %rdx
testq %rdx, %rdx
je 0xc474
movq 0x60(%rsp), %rax
movl $0x2, (%rax,%r12)
cmpq $0x26, %rdx
je 0xc48f
imulq $0xe38, 0x18(%rsp), %rax # imm = 0xE38
addq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
movl $0x2, 0x4(%rcx,%rax)
cmpl $0x6, %edx
pushq $0x5
popq %rax
cmovael %edx, %eax
addl $-0x5, %eax
leaq 0x5(%rdx), %rcx
movq %rcx, 0x70(%rsp)
cmpq $0x22, %rdx
movslq %eax, %r13
pushq $0x26
popq %rax
cmovaeq %rax, %r13
imulq $0xe38, %r13, %r12      # imm = 0xE38
addq 0x68(%rsp), %r12
cmpq 0x70(%rsp), %r13
jg 0xc580
movq %r12, 0x18(%rsp)
movq 0x78(%rsp), %r14
cmpq 0x80(%rsp), %r14
ja 0xc56c
movq %rbx, %rdi
movl %r13d, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x4f9a
testl %eax, %eax
js 0xc52a
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
movl %edx, %r15d
movq %rbx, %rdi
movl %r13d, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x4f9a
cltq
imulq $0x38, %rax, %rax
movl 0x8(%rbx,%rax), %ecx
negl %r15d
addl %r15d, %ecx
addl $-0x15, %ecx
movl %ecx, 0x8(%rbx,%rax)
callq 0x11d0
cltd
pushq $0x4
popq %rcx
idivl %ecx
cmpl $0x2, %edx
jg 0xc548
andl $0x0, 0x14(%r12)
movl $0x1, (%r12)
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
testl %edx, %edx
jne 0xc560
movl $0x1, 0x4(%r12)
incq %r14
addq $0x1c, %r12
jmp 0xc4d3
incq %r13
movq 0x18(%rsp), %r12
addq $0xe38, %r12            # imm = 0xE38
jmp 0xc4be
movq 0x10(%rsp), %rdi
callq 0xbfdd
movq (%rsp), %r15
jmp 0xc27c
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x7c00, %esi           # imm = 0x7C00
xorl %edx, %edx
callq 0x11c0
movslq (%r13), %rax
leaq 0x345c(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq (%rsp), %r15
leal 0x1(%r15), %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
leaq 0x3432(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0x7c00, %esi           # imm = 0x7C00
jmp 0xc275
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x2900, %esi           # imm = 0x2900
xorl %edx, %edx
callq 0x11c0
movslq (%r13), %rax
leaq 0x340d(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq (%rsp), %r15
leal 0x1(%r15), %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
leaq 0x33e3(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
movl $0x2900, %esi           # imm = 0x2900
jmp 0xc275
callq 0x11d0
movq (%rsp), %rcx
leal 0x1(%rcx), %r14d
testb $0x3, %al
movl $0xf500, %r15d          # imm = 0xF500
movl $0xcb00, %eax           # imm = 0xCB00
cmovel %eax, %r15d
movq 0x10(%rsp), %r12
movq %r12, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x11c0
movq %r12, %rdi
movl %r14d, %esi
movq 0x8(%rsp), %rdx
leaq 0x2b36(%rip), %rcx      # 0xf1a9
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x1060
movq 0x40(%rsp), %r14
pushq $-0x1
popq %r13
cmpq $0x2, %r13
movq (%rsp), %r15
je 0xc27c
xorl %r12d, %r12d
cmpq $0x54, %r12
je 0xc6d8
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
testl %edx, %edx
jne 0xc6d2
movl -0x4(%r14,%r12), %eax
cmpl $0x9, %eax
ja 0xc6d2
movl $0x302, %ecx            # imm = 0x302
btl %eax, %ecx
jae 0xc6d2
movl $0x3, (%r14,%r12)
addq $0x1c, %r12
jmp 0xc6a1
incq %r13
addq $0xe38, %r14            # imm = 0xE38
jmp 0xc690
callq 0x11d0
cltd
movl $0x12c, %ecx            # imm = 0x12C
idivl %ecx
cmpl $0x12a, %edx            # imm = 0x12A
movq 0x10(%rsp), %r12
jg 0xc72a
callq 0x11d0
andl $0x80000003, %eax       # imm = 0x80000003
movq (%rsp), %rcx
incl %ecx
movl %ecx, 0x18(%rsp)
cmpl $0x3, %eax
movq %r13, %r15
jne 0xc763
movl $0xa00, %r14d           # imm = 0xA00
movq %r12, %rdi
movl $0xa00, %esi            # imm = 0xA00
jmp 0xc771
movq %r13, %r15
andl $0x0, 0x4(%r13)
movl $0x200000, %r14d        # imm = 0x200000
movq %r12, %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %edx, %edx
callq 0x11c0
movslq (%r13), %rax
leaq 0x32bc(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq (%rsp), %rax
leal 0x1(%rax), %esi
movq %r12, %rdi
jmp 0xc78e
movl $0xcb00, %r14d          # imm = 0xCB00
movq %r12, %rdi
movl $0xcb00, %esi           # imm = 0xCB00
xorl %edx, %edx
callq 0x11c0
movslq (%r15), %rax
leaq 0x328c(%rip), %rcx      # 0xfa0e
movsbl (%rax,%rcx), %r8d
movq %r12, %rdi
movl 0x18(%rsp), %esi
movq 0x8(%rsp), %rdx
leaq 0x3266(%rip), %rcx      # 0xfa00
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x1060
cmpl $0x2, (%r15)
movq (%rsp), %r15
jne 0xc27c
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
cmpl $0x2, %edx
jne 0xc27c
movl 0x14(%r13), %eax
cmpl $0x2, %eax
jl 0xc7e4
decl %eax
movl %eax, 0x14(%r13)
jmp 0xc58a
andl $0x0, 0x14(%r13)
callq 0x11d0
cltd
pushq $0x64
popq %rcx
idivl %ecx
cmpl $0x5a, %edx
jg 0xc806
movl $0x1, (%r13)
jmp 0xc58a
movl $0x4, (%r13)
movl $0x1, 0x18(%r13)
jmp 0xc58a
addq $0x1c, 0x30(%rsp)
movq 0x8(%rsp), %rax
jmp 0xc0f0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq