// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x3060
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movq 0x8(%rbx), %rcx
movl %eax, (%rcx)
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movq 0x8(%rbx), %rcx
movl %eax, 0x4(%rcx)
callq 0x3060
movl 0x4(%rbx), %ecx
movq 0x8(%rbx), %rdx
subl (%rdx), %ecx
incl %ecx
cltd
idivl %ecx
movl %edx, %r14d
callq 0x3060
movl (%rbx), %esi
movq 0x8(%rbx), %rcx
subl 0x4(%rcx), %esi
incl %esi
cltd
idivl %esi
movl (%rcx), %esi
testl %esi, %esi
jle 0xf267
movslq %edx, %rax
movslq %r14d, %rdx
cmpl $0x0, 0x4(%rcx)
movq %rax, %rdi
jle 0xf258
movq 0x10(%rbx), %rcx
movq (%rcx,%rdx,8), %rcx
movb $0x4d, (%rcx,%rdi)
incq %rdi
movq 0x8(%rbx), %rcx
movslq 0x4(%rcx), %rsi
addq %rax, %rsi
cmpq %rsi, %rdi
jl 0xf237
movl (%rcx), %esi
incq %rdx
leal (%rsi,%r14), %edi
movslq %edi, %rdi
cmpq %rdi, %rdx
jl 0xf22e
callq 0x3060
cltd
idivl 0x4(%rbx)
movl %edx, %ebp
callq 0x3060
cltd
idivl (%rbx)
movq 0x10(%rbx), %rax
movslq %ebp, %rcx
movq (%rax,%rcx,8), %rax
movslq %edx, %rcx
cmpb $0x20, (%rax,%rcx)
jne 0xf267
movb $0x48, (%rax,%rcx)
movl %ebp, 0x18(%rbx)
movl %ecx, 0x1c(%rbx)
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
jle 0xf302
movl (%rbx), %eax
xorl %r14d, %r14d
testl %eax, %eax
jle 0xf2f7
xorl %r15d, %r15d
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
cmpb $0x20, (%rax,%r15)
jne 0xf2e9
callq 0x3060
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x14f92(%rip), %xmm0    # 0x24260
movsd 0x156aa(%rip), %xmm1    # 0x24980
ucomisd %xmm0, %xmm1
jbe 0xf2e9
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
movb $0x58, (%rax,%r15)
incq %r15
movslq (%rbx), %rax
cmpq %rax, %r15
jl 0xf2ab
movl 0x4(%rbx), %ecx
incq %r14
movslq %ecx, %rdx
cmpq %rdx, %r14
jl 0xf2a4
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop