// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
callq 0x3060
movl (%rbx), %ecx
movq 0x8(%rbx), %rsi
subl 0x4(%rsi), %ecx
incl %ecx
cltd
idivl %ecx
cmpl $0x0, (%rsi)
jle 0xf2fb
movslq %edx, %rax
movslq %ebp, %rcx
movq %rcx, %rdx
movq 0x8(%rbx), %rsi
cmpl $0x0, 0x4(%rsi)
movq %rax, %rsi
jle 0xf2e9
movq 0x10(%rbx), %rdi
movq (%rdi,%rdx,8), %rdi
movb $0x4d, (%rdi,%rsi)
incq %rsi
movq 0x8(%rbx), %rdi
movslq 0x4(%rdi), %rdi
addq %rax, %rdi
cmpq %rdi, %rsi
jl 0xf2ca
incq %rdx
movq 0x8(%rbx), %rsi
movslq (%rsi), %rsi
addq %rcx, %rsi
cmpq %rsi, %rdx
jl 0xf2bd
xorl %r14d, %r14d
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 0xf332
movb $0x48, (%rax,%rcx)
movl %ebp, 0x18(%rbx)
movl %ecx, 0x1c(%rbx)
movb $0x1, %r14b
testb $0x1, %r14b
je 0xf2fe
cmpl $0x0, 0x4(%rbx)
jle 0xf39e
xorl %r14d, %r14d
cmpl $0x0, (%rbx)
jle 0xf392
xorl %r15d, %r15d
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
cmpb $0x20, (%rax,%r15)
jne 0xf387
callq 0x3060
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x14ef4(%rip), %xmm0    # 0x24260
movsd 0x1560c(%rip), %xmm1    # 0x24980
ucomisd %xmm0, %xmm1
jbe 0xf387
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
movb $0x58, (%rax,%r15)
incq %r15
movslq (%rbx), %rax
cmpq %rax, %r15
jl 0xf349
incq %r14
movslq 0x4(%rbx), %rax
cmpq %rax, %r14
jl 0xf341
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop