// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %rdi, %rbx
movl 0x1c(%rdi), %eax
movl %eax, -0x2c(%rbp)
movl %edx, -0x30(%rbp)
cmpl $0x3, %edx
jl 0x7f21
movq %rsi, %r12
movabsq $0x7fffffff00000000, %rax # imm = 0x7FFFFFFF00000000
andq %rsi, %rax
movq %rax, -0x40(%rbp)
movl $0x2, %r15d
movq $0x0, -0x38(%rbp)
movabsq $0x3fa999999999999a, %rax # imm = 0x3FA999999999999A
movq %rax, -0x80(%rbp)
movq $0x1, -0x78(%rbp)
movw $0x0, -0x70(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x8af4
testb %al, %al
je 0x7ed0
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x98f4
cmpq 0x8(%rax), %r13
jae 0x7ebc
movq %rbx, %rdi
movq %r13, %rsi
callq 0x993a
movq %rax, %rdi
callq 0x9a52
movl %eax, %ecx
movq %r12, %r14
subl %r12d, %ecx
subq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm0, %xmm0
shrq $0x1f, %rax
andl $-0x2, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movsd -0x48(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7eab
movq %rbx, %rdi
movq %r13, %rsi
callq 0x993a
movb $0x1, %cl
movq %rcx, -0x38(%rbp)
cmpl $0xa, 0x8(%rax)
jne 0x7eab
movq %rbx, %rdi
callq 0x98f4
leaq -0x1(%r13), %r12
movq 0x8(%rax), %rcx
cmpq %r13, %rcx
jbe 0x7eae
movq (%rax), %rdx
movq (%rdx,%r13,8), %rdi
movq (%rax), %rdx
movq 0x8(%rdx,%r13,8), %rsi
movq %rsi, (%rdx,%r13,8)
leaq 0x1(%r13), %rdx
movq %rdx, %r13
cmpq %rdx, %rcx
jne 0x7e7f
decq %rcx
movq %rcx, 0x8(%rax)
testq %rdi, %rdi
je 0x7eae
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x7eae
movq %r13, %r12
incq %r12
movq %r12, %r13
movq %r14, %r12
jmp 0x7de8
callq 0x38c6
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
jmp 0x7dd1
addl $0x2, %r15d
cmpl -0x30(%rbp), %r15d
jl 0x7da8
testb $0x1, -0x38(%rbp)
je 0x7f21
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x423b(%rip), %rsi      # 0xc12e
leaq 0x423c(%rip), %rdx      # 0xc136
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x574e
movq %r14, %rdi
callq 0x399e
movq -0x68(%rbp), %rdi
movb $0x1, %r14b
cmpq %r15, %rdi
je 0x7f24
callq 0x3230
jmp 0x7f24
xorl %r14d, %r14d
movl -0x2c(%rbp), %eax
movl %eax, 0x1c(%rbx)
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x7f58
callq 0x3230
jmp 0x7f58
jmp 0x7f55
jmp 0x7f55
jmp 0x7f55
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3430