// File: MichaelXanth[P]RPG_Game/Grid/Grid.cpp
// Function: Grid::BuildGrid()
void Grid::BuildGrid(void)
{
    int marketP[2];
    // Detemines how many lines and rows the market will have
    marketBlocks[0] = (rand() % 4) + 1;
    marketBlocks[1] = (rand() % 5) + 1;
    marketP[0]      =  rand() % (verticalSize   - marketBlocks[0] + 1);
    marketP[1]      =  rand() % (horizontalSize - marketBlocks[1] + 1);

    // Marks the spaces the market fills with 'M'
    for (int i = marketP[0]; i < marketBlocks[0] + marketP[0]; i++)
        for (int j = marketP[1]; j < marketBlocks[1] + marketP[1]; j++)
            grid[i][j] = 'M';

    int  heroP[2];
    bool heroPlaced = false;

    // Detemines the hero location
    while(heroPlaced != true) {
        heroP[0] = rand() % verticalSize;
        heroP[1] = rand() % horizontalSize;

        if (grid[heroP[0]][heroP[1]] == ' ') {
            grid[heroP[0]][heroP[1]] = 'H';
            heroLoc[0] = heroP[0];
            heroLoc[1] = heroP[1];
            heroPlaced = true;
        }
    }

    // Determines where non-accessible blocks are placed
    for(int i = 0; i < verticalSize; i++) {
        float chance = 0.1;

        for(int j = 0; j < horizontalSize; j++)
            if (grid[i][j] == ' ' && (double)rand() / RAND_MAX < chance)
                grid[i][j] = 'X';
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
callq 0x40a0
movl $0x4, %ecx
cltd
idivl %ecx
movq -0x38(%rbp), %rax
addl $0x1, %edx
movq 0x8(%rax), %rax
movl %edx, (%rax)
callq 0x40a0
movl $0x5, %ecx
cltd
idivl %ecx
movq -0x38(%rbp), %rax
addl $0x1, %edx
movq 0x8(%rax), %rax
movl %edx, 0x4(%rax)
callq 0x40a0
movq -0x38(%rbp), %rdx
movl 0x4(%rdx), %ecx
movq 0x8(%rdx), %rdx
subl (%rdx), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
movl %edx, -0x10(%rbp)
callq 0x40a0
movq -0x38(%rbp), %rdx
movl (%rdx), %ecx
movq 0x8(%rdx), %rdx
subl 0x4(%rdx), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
movl %edx, -0xc(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x38(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x8(%rcx), %rcx
movl (%rcx), %ecx
addl -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1d074
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x38(%rbp), %rcx
movl -0x18(%rbp), %eax
movq 0x8(%rcx), %rcx
movl 0x4(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1d067
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movb $0x4d, (%rax,%rcx)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1d02f
jmp 0x1d069
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d015
movb $0x0, -0x21(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x1d0eb
callq 0x40a0
movq -0x38(%rbp), %rcx
cltd
idivl 0x4(%rcx)
movl %edx, -0x20(%rbp)
callq 0x40a0
movq -0x38(%rbp), %rcx
cltd
idivl (%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x1c(%rbp)
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x1d0e9
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x1c(%rbp), %rdx
movb $0x48, (%rcx,%rdx)
movl -0x20(%rbp), %ecx
movl %ecx, 0x18(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x1c(%rax)
movb $0x1, -0x21(%rbp)
jmp 0x1d078
movl $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x1d197
movss 0x20872(%rip), %xmm0    # 0x3d97c
movss %xmm0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl (%rcx), %eax
jge 0x1d187
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x1d17a
callq 0x40a0
cvtsi2sd %eax, %xmm1
movsd 0x20111(%rip), %xmm0    # 0x3d260
divsd %xmm0, %xmm1
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1d17a
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movb $0x58, (%rax,%rcx)
jmp 0x1d17c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1d116
jmp 0x1d189
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1d0f2
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)