// File: /workspace/github_cpp_makefile_star2_O1/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:
xorl %eax, %eax
cmpl $0x60, %esi
jg 0x10163
cmpl $0x52, %esi
jg 0x101ca
cmpl $0x41, %esi
je 0x1023c
cmpl $0x44, %esi
je 0x10176
retq
cmpl $0x72, %esi
jg 0x101da
cmpl $0x61, %esi
je 0x1023c
cmpl $0x64, %esi
jne 0x10162
movslq 0x1c(%rdi), %rax
movl (%rdi), %ecx
decl %ecx
cmpl %ecx, %eax
je 0x102cc
movq 0x10(%rdi), %rcx
movslq 0x18(%rdi), %rdx
movq (%rcx,%rdx,8), %rcx
movzbl 0x1(%rcx,%rax), %edx
cmpl $0x4d, %edx
je 0x102c8
cmpl $0x20, %edx
jne 0x102cc
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 0x102c5
cmpl $0x53, %esi
je 0x10282
cmpl $0x57, %esi
je 0x101ec
jmp 0x10162
cmpl $0x73, %esi
je 0x10282
cmpl $0x77, %esi
jne 0x10162
movslq 0x18(%rdi), %rax
testq %rax, %rax
je 0x102cc
movq 0x10(%rdi), %rcx
movq -0x8(%rcx,%rax,8), %rax
movslq 0x1c(%rdi), %rcx
movzbl (%rax,%rcx), %edx
cmpl $0x4d, %edx
je 0x102c8
cmpl $0x20, %edx
jne 0x102cc
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 0x102c5
movslq 0x1c(%rdi), %rax
testq %rax, %rax
je 0x102cc
movq 0x10(%rdi), %rcx
movslq 0x18(%rdi), %rdx
movq (%rcx,%rdx,8), %rcx
movzbl -0x1(%rcx,%rax), %edx
cmpl $0x4d, %edx
je 0x102c8
cmpl $0x20, %edx
jne 0x102cc
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 0x102c5
movslq 0x18(%rdi), %rax
movl 0x4(%rdi), %ecx
decl %ecx
cmpl %ecx, %eax
je 0x102cc
movq 0x10(%rdi), %rcx
movq 0x8(%rcx,%rax,8), %rax
movslq 0x1c(%rdi), %rcx
movzbl (%rax,%rcx), %edx
cmpl $0x4d, %edx
je 0x102c8
cmpl $0x20, %edx
jne 0x102cc
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