// File: Jacobious52[P]Tanks/Terrain.cpp
// Function: Terrain::_init()
void Terrain::_init()
{
    _size = ConsoleTools::get_terminal_size();
    _position = Point<int>::zero();

    shuffle_wind_speed();

    // create a array of terrain heights at every x pos
    int *height_map = new int[get_size().x];
    _gen_terrain(0, get_size().x, height_map);

    // fill in the map with sprites for every x pos
    for (int i = 0; i < get_size().x; ++i)
    {
        for (int h = get_size().y - height_map[i]; h < get_size().y; ++h)
        {
            Sprite *tile = new Sprite(" ");
            tile->set_position(Point<int>(i, h));
            if (h == get_size().y - 1)
            {
                tile->set_bcolor(ConsoleTools::white);
                tile->tag = TERRAIN_ROCK;
                tile->set_texture(" ");
            }
            else
            {
                tile->set_bcolor(ConsoleTools::green);
                tile->tag = TERRAIN_DIRT;
            }
            add_child(tile);
        }
    }

    delete[] height_map;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0x4cb0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x10(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, 0x20(%rax)
callq 0x7110
movq -0xd0(%rbp), %rdi
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, 0x18(%rdi)
callq 0xc600
movq -0xd0(%rbp), %rdi
callq 0x106a0
movq %rax, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq -0xd0(%rbp), %rdi
movq %rax, -0x20(%rbp)
callq 0x106a0
movq -0xd0(%rbp), %rdi
movq %rax, -0x30(%rbp)
movl -0x30(%rbp), %edx
movq -0x20(%rbp), %rcx
xorl %esi, %esi
callq 0xc680
movl $0x0, -0x34(%rbp)
movq -0xd0(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, -0xd4(%rbp)
callq 0x106a0
movq %rax, %rcx
movl -0xd4(%rbp), %eax
movq %rcx, -0x3c(%rbp)
cmpl -0x3c(%rbp), %eax
jge 0xc5b7
movq -0xd0(%rbp), %rdi
callq 0x106a0
movq %rax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, -0x40(%rbp)
movq -0xd0(%rbp), %rdi
movl -0x40(%rbp), %eax
movl %eax, -0xd8(%rbp)
callq 0x106a0
movq %rax, %rcx
movl -0xd8(%rbp), %eax
movq %rcx, -0x50(%rbp)
cmpl -0x4c(%rbp), %eax
jge 0xc5a7
movl $0x60, %edi
callq 0x43a0
movq %rax, -0xe8(%rbp)
movb $0x1, -0x8d(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x45f0
movq -0xe0(%rbp), %rdx
leaq 0x7d09(%rip), %rsi      # 0x140ad
leaq -0x78(%rbp), %rdi
callq 0x4490
jmp 0xc3af
movq -0xe8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x72a0
jmp 0xc3c1
movb $0x0, -0x8d(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x4200
jmp 0xc3d3
leaq -0x79(%rbp), %rdi
callq 0x4400
movq -0xe8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl -0x34(%rbp), %esi
movl -0x40(%rbp), %edx
leaq -0x98(%rbp), %rdi
callq 0x4ed0
movq -0xf8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x10680
movq -0xd0(%rbp), %rdi
movl -0x40(%rbp), %eax
movl %eax, -0xec(%rbp)
callq 0x106a0
movq %rax, %rcx
movl -0xec(%rbp), %eax
movq %rcx, -0xa0(%rbp)
movl -0x9c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xc570
movq -0x58(%rbp), %rdi
movl $0x25, %esi
callq 0xa6b0
movq -0x58(%rbp), %rax
movl $0xb, 0x8(%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x45f0
movq -0x100(%rbp), %rdx
leaq 0x7c1b(%rip), %rsi      # 0x140ad
leaq -0xc0(%rbp), %rdi
callq 0x4490
jmp 0xc4a0
movq -0x108(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa700
jmp 0xc4b5
leaq -0xc0(%rbp), %rdi
callq 0x4200
jmp 0xc4c3
leaq -0xc1(%rbp), %rdi
callq 0x4400
jmp 0xc589
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xc507
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x4200
jmp 0xc505
jmp 0xc507
leaq -0x79(%rbp), %rdi
callq 0x4400
testb $0x1, -0x8d(%rbp)
jne 0xc51b
jmp 0xc527
movq -0xe8(%rbp), %rdi
callq 0x4360
jmp 0xc5dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xc562
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x4200
jmp 0xc560
jmp 0xc562
leaq -0xc1(%rbp), %rdi
callq 0x4400
jmp 0xc5dd
movq -0x58(%rbp), %rdi
movl $0x20, %esi
callq 0xa6b0
movq -0x58(%rbp), %rax
movl $0xa, 0x8(%rax)
movq -0xd0(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x10420
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xc343
jmp 0xc5a9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xc2f7
movq -0x20(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, %rax
je 0xc5d4
movq -0x110(%rbp), %rdi
callq 0x4470
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x45e0
movq %rax, %rdi
callq 0x4ec0
nopw %cs:(%rax,%rax)