// File: /workspace/github_cpp_makefile_star2_O2/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
movl %edx, -0x30(%rbp)
movq %rdi, %rbx
movabsq $0x7fffffff00000000, %r12 # imm = 0x7FFFFFFF00000000
movq %rsi, -0x40(%rbp)
andq %rsi, %r12
movl 0x1c(%rdi), %eax
movl %eax, -0x2c(%rbp)
pushq $0x2
popq %r13
movq $0x0, -0x38(%rbp)
cmpl -0x30(%rbp), %r13d
jge 0x75af
movabsq $0x3fa999999999999a, %rax # imm = 0x3FA999999999999A
movq %rax, -0x60(%rbp)
movq $0x1, -0x58(%rbp)
andw $0x0, -0x50(%rbp)
cvtsi2sd %r13d, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x802c
testb %al, %al
je 0x75a6
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x8c28
cmpq 0x8(%rax), %r14
jae 0x7592
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8c44
movq %rax, %rdi
callq 0x8d1a
movl %eax, %ecx
subl -0x40(%rbp), %ecx
subq %r12, %rax
cvtsi2sd %ecx, %xmm0
mulsd %xmm0, %xmm0
shrq $0x1f, %rax
andl $-0x2, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
movsd -0x48(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7584
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8c44
movb $0x1, %cl
movq %rcx, -0x38(%rbp)
cmpl $0xa, 0x8(%rax)
jne 0x7584
movq %rbx, %rdi
callq 0x8c28
leaq -0x1(%r14), %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x5460
testq %rax, %rax
je 0x7587
movq (%rax), %rcx
movq %rax, %rdi
callq *0x8(%rcx)
jmp 0x7587
movq %r14, %r15
incq %r15
movq %r15, %r14
jmp 0x74ef
callq 0x38f2
movq 0x28(%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
jmp 0x74db
addl $0x2, %r13d
jmp 0x74ac
movq -0x38(%rbp), %r14
testb $0x1, %r14b
je 0x75e8
leaq 0x3b3e(%rip), %rsi      # 0xb0fe
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x3120
leaq -0x88(%rbp), %rdi
callq 0x39be
leaq -0x88(%rbp), %rdi
callq 0x3340
movl -0x2c(%rbp), %eax
movl %eax, 0x1c(%rbx)
andb $0x1, %r14b
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x3340
jmp 0x7628
movq %rax, %rdi
callq 0x3aae
jmp 0x7625
jmp 0x7625
jmp 0x7625
jmp 0x7625
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3450