// File: 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:
pushq %rbp
movq %rsp, %rbp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movb $0x0, -0xa(%rbp)
movsbl -0x9(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0x18(%rbp)
subl $0x36, %eax
ja 0x1e1f4
movq -0x18(%rbp), %rax
leaq 0x1fa45(%rip), %rcx     # 0x3d980
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x1dfea
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movslq 0x18(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movl 0x1c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x1dfb7
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x1c(%rax), %edx
subl $0x1, %edx
movslq %edx, %rdx
movb $0x48, (%rcx,%rdx)
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x1c(%rax), %rdx
movb $0x20, (%rcx,%rdx)
movl 0x1c(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movb $0x1, -0xa(%rbp)
jmp 0x1e1f4
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movslq 0x18(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movl 0x1c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x4d, %eax
jne 0x1dfe6
movq -0x20(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0x1e1f4
jmp 0x1dfe8
jmp 0x1dfea
jmp 0x1e1f4
movq -0x20(%rbp), %rcx
movl 0x1c(%rcx), %eax
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e09b
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movslq 0x18(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movl 0x1c(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x1e068
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x1c(%rax), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb $0x48, (%rcx,%rdx)
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x1c(%rax), %rdx
movb $0x20, (%rcx,%rdx)
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movb $0x1, -0xa(%rbp)
jmp 0x1e1f4
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movslq 0x18(%rcx), %rdx
movq (%rax,%rdx,8), %rax
movl 0x1c(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x4d, %eax
jne 0x1e097
movq -0x20(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0x1e1f4
jmp 0x1e099
jmp 0x1e09b
jmp 0x1e1f4
movq -0x20(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1e146
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movl 0x18(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x1c(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x1e113
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movl 0x18(%rax), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x1c(%rax), %rdx
movb $0x48, (%rcx,%rdx)
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x1c(%rax), %rdx
movb $0x20, (%rcx,%rdx)
movl 0x18(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x18(%rax)
movb $0x1, -0xa(%rbp)
jmp 0x1e1f4
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movl 0x18(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x1c(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x4d, %eax
jne 0x1e142
movq -0x20(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0x1e1f4
jmp 0x1e144
jmp 0x1e146
jmp 0x1e1f4
movq -0x20(%rbp), %rcx
movl 0x18(%rcx), %eax
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e1f2
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movl 0x18(%rcx), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x1c(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x1e1c2
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movl 0x18(%rax), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x1c(%rax), %rdx
movb $0x48, (%rcx,%rdx)
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x1c(%rax), %rdx
movb $0x20, (%rcx,%rdx)
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movb $0x1, -0xa(%rbp)
jmp 0x1e1f4
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rax
movl 0x18(%rcx), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq 0x1c(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x4d, %eax
jne 0x1e1ee
movq -0x20(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0x1e1f4
jmp 0x1e1f0
jmp 0x1e1f2
jmp 0x1e1f4
movb -0xa(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopl (%rax,%rax)