// File: /workspace/github_cpp_makefile_star2_O2/MichaelXanth[P]RPG_Game/Grid/Grid.cpp
// Function: Grid::MoveHeroes(char)
bool Grid::MoveHeroes(char movement)
{
    // It exists so that we can define if a battle is going to happen or not
    bool heroMoved = false; 

    switch(movement)
    {
        // Going left
        case 'a':
        case 'A':
            if (heroLoc[1] != 0) {
                if (grid[heroLoc[0]][heroLoc[1] - 1] == ' ') {
                    grid[heroLoc[0]][heroLoc[1] - 1] = 'H';
                    grid[heroLoc[0]][heroLoc[1]] = ' ';
                    heroLoc[1] = heroLoc[1] - 1;
                    heroMoved = true;
                    break;
                
                } else if (grid[heroLoc[0]][heroLoc[1] - 1] == 'M') {
                    heroInStore = true;
                    break;
                }
            }
        break;

        // Going right
        case 'd':
        case 'D':
            if (heroLoc[1] != horizontalSize - 1) {
                if (grid[heroLoc[0]][heroLoc[1] + 1] == ' ') {
                    grid[heroLoc[0]][heroLoc[1] + 1] = 'H';
                    grid[heroLoc[0]][heroLoc[1]] = ' ';
                    heroLoc[1] = heroLoc[1] + 1;
                    heroMoved = true;
                    break;
                
                } else if (grid[heroLoc[0]][heroLoc[1] + 1] == 'M') {
                    heroInStore = true;
                    break;
                }
            }
            break;
        
        // Going Up
        case 'w':
        case 'W':
            if (heroLoc[0] != 0){
                if (grid[heroLoc[0] - 1][heroLoc[1]] == ' ')
                {
                    grid[heroLoc[0] - 1][heroLoc[1]] = 'H';
                    grid[heroLoc[0]][heroLoc[1]] = ' ';
                    heroLoc[0] = heroLoc[0] - 1;
                    heroMoved = true;
                    break;
                
                } else if (grid[heroLoc[0] - 1][heroLoc[1]] == 'M') {
                    heroInStore = true;
                    break;
                }
            }
            break;
        
        // Going Down
        case 's':
        case 'S':
            if(heroLoc[0] != verticalSize - 1) {
                if(grid[heroLoc[0] + 1][heroLoc[1]] == ' ') {
                    grid[heroLoc[0] + 1][heroLoc[1]] = 'H';
                    grid[heroLoc[0]][heroLoc[1]] = ' ';
                    heroLoc[0] = heroLoc[0] + 1;
                    heroMoved = true;
                    break;
                
                } else if(grid[heroLoc[0] + 1][heroLoc[1]] == 'M') {
                    heroInStore = true;
                    break;
                }
            }
            break;
    }

    return heroMoved;
}

// Assembly:
cmpl $0x41, %esi
je 0xc97e
cmpl $0x44, %esi
je 0xca1f
cmpl $0x53, %esi
je 0xca68
cmpl $0x57, %esi
je 0xc9cf
cmpl $0x77, %esi
je 0xc9cf
cmpl $0x64, %esi
je 0xca1f
cmpl $0x73, %esi
je 0xca68
cmpl $0x61, %esi
jne 0xcab2
movslq 0x1c(%rdi), %rax
testq %rax, %rax
je 0xcab2
movq 0x10(%rdi), %rcx
movslq 0x18(%rdi), %rdx
movq (%rcx,%rdx,8), %rcx
movzbl -0x1(%rcx,%rax), %edx
cmpl $0x4d, %edx
je 0xcaae
cmpl $0x20, %edx
jne 0xcab2
movb $0x48, -0x1(%rcx,%rax)
movq 0x10(%rdi), %rax
movslq 0x18(%rdi), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x1c(%rdi), %rcx
movb $0x20, (%rax,%rcx)
decl 0x1c(%rdi)
jmp 0xcaab
movslq 0x18(%rdi), %rax
testq %rax, %rax
je 0xcab2
movq 0x10(%rdi), %rcx
movq -0x8(%rcx,%rax,8), %rax
movslq 0x1c(%rdi), %rcx
movzbl (%rax,%rcx), %edx
cmpl $0x4d, %edx
je 0xcaae
cmpl $0x20, %edx
jne 0xcab2
movb $0x48, (%rax,%rcx)
movq 0x10(%rdi), %rax
movslq 0x18(%rdi), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x1c(%rdi), %rcx
movb $0x20, (%rax,%rcx)
decl 0x18(%rdi)
jmp 0xcaab
movslq 0x1c(%rdi), %rax
movl (%rdi), %ecx
decl %ecx
cmpl %ecx, %eax
je 0xcab2
movq 0x10(%rdi), %rcx
movslq 0x18(%rdi), %rdx
movq (%rcx,%rdx,8), %rcx
movzbl 0x1(%rcx,%rax), %edx
cmpl $0x4d, %edx
je 0xcaae
cmpl $0x20, %edx
jne 0xcab2
movb $0x48, 0x1(%rcx,%rax)
movq 0x10(%rdi), %rax
movslq 0x18(%rdi), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x1c(%rdi), %rcx
movb $0x20, (%rax,%rcx)
incl 0x1c(%rdi)
jmp 0xcaab
movslq 0x18(%rdi), %rax
movl 0x4(%rdi), %ecx
decl %ecx
cmpl %ecx, %eax
je 0xcab2
movq 0x10(%rdi), %rcx
movq 0x8(%rcx,%rax,8), %rax
movslq 0x1c(%rdi), %rcx
movzbl (%rax,%rcx), %edx
cmpl $0x4d, %edx
je 0xcaae
cmpl $0x20, %edx
jne 0xcab2
movb $0x48, (%rax,%rcx)
movq 0x10(%rdi), %rax
movslq 0x18(%rdi), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x1c(%rdi), %rcx
movb $0x20, (%rax,%rcx)
incl 0x18(%rdi)
movb $0x1, %al
retq
movb $0x1, 0x20(%rdi)
xorl %eax, %eax
retq
nop