// File: /workspace/github_cpp_makefile_star2_O1/Jacobious52[P]Tanks/Terrain.cpp
// Function: Terrain::impact(Point<int>, int)
bool Terrain::impact(Point<int> pos, int radius)
{
    int old_pos = _position.y;
    bool hit = false;

    // increment radius destruction in steps for animation
    for (int r = 2; r < radius; r+=2)
    {
        // pause for 0.05 seconds
        Timer timer(0.05, 1);
        while (timer.tick())
        {
            LOOPV(i, this)
            {
                // get the distance and add horrizontal stretch to look nicer
                Point<int> tile_pos = get_child(i)->get_position();
                Point<int> dist = tile_pos - pos;
                if (sqrt(pow(dist.x, 2) + pow(dist.y*2, 2)) < r)
                {
                    if (get_child(i)->tag == TERRAIN_DIRT)
                    {
                        delete get_children()->remove(i--);
                    }
                    hit = true;
                }
            }

            // for screen update for destruction animation
            ConsoleTools::clear_screen();
            _parent->draw();
        }
    }

    if (hit == true)
    {
        ConsoleTools::play_music("boom.wav");
    }

    _position.y = old_pos;

    return hit;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movl 0x1c(%rdi), %r13d
movl %edx, -0x30(%rbp)
cmpl $0x3, %edx
jl 0x7ece
movq %rsi, %r12
movl %r13d, -0x2c(%rbp)
movabsq $0x7fffffff00000000, %r13 # imm = 0x7FFFFFFF00000000
andq %rsi, %r13
movl $0x2, %eax
xorl %r14d, %r14d
movabsq $0x3fa999999999999a, %rcx # imm = 0x3FA999999999999A
movq %rcx, -0x78(%rbp)
movq $0x1, -0x70(%rbp)
movw $0x0, -0x68(%rbp)
movl %eax, -0x34(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x8ae8
testb %al, %al
je 0x7eb9
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x98e8
cmpq 0x8(%rax), %r15
jae 0x7ea5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x992e
movq %rax, %rdi
callq 0x9a42
movl %eax, %ecx
subl %r12d, %ecx
subq %r13, %rax
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm1, %xmm1
shrq $0x1f, %rax
andl $-0x2, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x4403(%rip), %xmm0     # 0xc228
jb 0x7e2d
sqrtsd %xmm0, %xmm0
jmp 0x7e32
callq 0x31e0
movsd -0x40(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7e9d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x992e
movb $0x1, %r14b
cmpl $0xa, 0x8(%rax)
jne 0x7e9d
movq %rbx, %rdi
callq 0x98e8
movq 0x8(%rax), %rcx
cmpq %r15, %rcx
jbe 0x7e8d
movq (%rax), %rdx
movq (%rdx,%r15,8), %rdi
movq %r15, %rdx
movq (%rax), %rsi
movq 0x8(%rsi,%rdx,8), %r8
movq %r8, (%rsi,%rdx,8)
leaq 0x1(%rdx), %rsi
movq %rsi, %rdx
cmpq %rsi, %rcx
jne 0x7e6c
decq %rcx
movq %rcx, 0x8(%rax)
jmp 0x7e8f
xorl %edi, %edi
decq %r15
testq %rdi, %rdi
je 0x7e9d
movq (%rdi), %rax
callq *0x8(%rax)
incq %r15
jmp 0x7dcf
callq 0x38d6
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
jmp 0x7dbb
movl -0x34(%rbp), %eax
addl $0x2, %eax
cmpl -0x30(%rbp), %eax
jl 0x7d90
movl -0x2c(%rbp), %r13d
jmp 0x7ed1
xorl %r14d, %r14d
testb $0x1, %r14b
je 0x7f10
leaq -0x50(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x4247(%rip), %rsi      # 0xc12e
leaq 0x4248(%rip), %rdx      # 0xc136
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0x5744
movq %r15, %rdi
callq 0x39ae
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x7f10
callq 0x3240
movl %r13d, 0x1c(%rbx)
andb $0x1, %r14b
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x7f46
callq 0x3240
jmp 0x7f46
jmp 0x7f43
jmp 0x7f43
jmp 0x7f43
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3440