// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
callq 0x394e
movq %rax, 0x20(%rbx)
movq $0x0, 0x18(%rbx)
callq 0x30d0
cvtsi2ss %eax, %xmm0
mulss 0x48fe(%rip), %xmm0     # 0xc1f8
movaps %xmm0, -0x40(%rbp)
callq 0x30d0
testb $0x1, %al
je 0x790d
movaps -0x40(%rbp), %xmm0
jmp 0x7918
movaps -0x40(%rbp), %xmm0
xorps 0x48e8(%rip), %xmm0     # 0xc200
movss %xmm0, 0x34(%rbx)
movq %rbx, %rdi
callq 0x9a66
shlq $0x20, %rax
movq %rax, %rcx
sarq $0x1e, %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x3030
movq %rax, %r14
movq %rbx, %rdi
callq 0x9a66
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movq %r14, -0x40(%rbp)
movq %r14, %rcx
callq 0x7b5a
movq %rbx, %rdi
callq 0x9a66
testl %eax, %eax
jle 0x7abf
xorl %r12d, %r12d
leaq -0x68(%rbp), %r13
movq %rbx, -0x48(%rbp)
movq %rbx, %rdi
callq 0x9a66
movq %rax, %r14
shrq $0x20, %r14
movq -0x40(%rbp), %rax
subl (%rax,%r12,4), %r14d
movq %rbx, %rdi
callq 0x9a66
shrq $0x20, %rax
cmpl %eax, %r14d
jge 0x7aa9
movl $0x60, %edi
callq 0x3260
movq %rax, %r15
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %r13, %rdi
leaq 0x4706(%rip), %rsi      # 0xc0cd
leaq 0x4700(%rip), %rdx      # 0xc0ce
callq 0x574e
movq %r15, %rdi
movq %r13, %rsi
callq 0x4ef4
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x79f0
callq 0x3230
movq %r14, %rsi
shlq $0x20, %rsi
orq %r12, %rsi
movq %r15, %rdi
callq 0x9a5c
movq %rbx, %rdi
callq 0x9a66
shrq $0x20, %rax
decl %eax
cmpl %eax, %r14d
jne 0x7a81
movq %r12, %rbx
movq %r13, %r12
movq %r15, %rdi
movl $0x25, %esi
callq 0x68fa
movl $0xb, 0x8(%r15)
leaq -0x78(%rbp), %r13
movq %r13, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
leaq 0x4684(%rip), %rsi      # 0xc0cd
leaq 0x467e(%rip), %rdx      # 0xc0ce
callq 0x574e
movq %r15, %rdi
leaq -0x88(%rbp), %rsi
callq 0x6932
movq -0x88(%rbp), %rdi
cmpq %r13, %rdi
movq %r12, %r13
movq %rbx, %r12
movq -0x48(%rbp), %rbx
je 0x7a96
callq 0x3230
jmp 0x7a96
movq %r15, %rdi
movl $0x20, %esi
callq 0x68fa
movl $0xa, 0x8(%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x98fe
incl %r14d
jmp 0x7993
incq %r12
movq %rbx, %rdi
callq 0x9a66
cltq
cmpq %rax, %r12
jl 0x797c
movq -0x40(%rbp), %rdi
callq 0x32f0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r13, %rdi
jne 0x7b05
jmp 0x7b0a
movq %rax, %rbx
jmp 0x7b02
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x7b02
callq 0x3230
movq %r15, %rdi
callq 0x3230
movq %rbx, %rdi
callq 0x3430