// File: /workspace/github_cpp_makefile_star2_O1/wrighteagle2d[P]wrighteaglebase/Debug/../src/InterceptInfo.cpp
// Function: InterceptInfo::CalcIdealInterception(BallState const&, PlayerInterceptInfo*, double const&)
void InterceptInfo::CalcIdealInterception(const BallState &ball,
                                          PlayerInterceptInfo *pInfo,
                                          const double &buffer) {
  const int idle_cycle = pInfo->mpPlayer->GetIdleCycle();

  // step 1. 求解简化截球模型
  InterceptModel::instance().CalcInterception(
      ball.GetPredictedPos(idle_cycle), ball.GetPredictedVel(idle_cycle),
      buffer, pInfo->mpPlayer, &(pInfo->solution));

  // step 2. 修正截球区间
  //	取整
  if (pInfo->solution.interc == 1) {
    pInfo->mInterCycle[0] = (int)floor(pInfo->solution.intert[0]);
  } else { // 3
    pInfo->mInterCycle[0] = (int)floor(pInfo->solution.intert[0]);
    pInfo->mInterCycle[1] = (int)ceil(pInfo->solution.intert[1]);
    pInfo->mInterCycle[2] = (int)floor(pInfo->solution.intert[2]);

    if (pInfo->mInterCycle[0] > pInfo->mInterCycle[1]) {
      pInfo->mInterCycle[0] = pInfo->mInterCycle[2];
      pInfo->solution.interc = 1;
    }
  }

  bool kickable =
      pInfo->mpPlayer->GetPos().Dist(ball.GetPredictedPos(idle_cycle)) <
      buffer; //判断开始截球的第一个周期，是否可踢
  if (!kickable) {
    pInfo->mInterCycle[0] = Max(pInfo->mInterCycle[0], 1);
  } else {
    pInfo->mInterCycle[0] = 0;
  }

  if (pInfo->solution.interc > 1) {
    pInfo->mInterCycle[1] = Max(pInfo->mInterCycle[1], pInfo->mInterCycle[0]);
    pInfo->mInterCycle[2] = Max(pInfo->mInterCycle[2], pInfo->mInterCycle[1]);
  }

  if (pInfo->solution.interc <= 1) {
    pInfo->mInterCycle[0] += idle_cycle;
  } else {
    pInfo->mInterCycle[0] += idle_cycle;
    pInfo->mInterCycle[1] += idle_cycle;
    pInfo->mInterCycle[2] += idle_cycle;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
movq 0x60(%rsi), %rax
movl 0x124(%rax), %r14d
addl 0xc8(%rax), %r14d
callq 0x2c15e
movq %rax, -0x30(%rbp)
movq 0x68(%r13), %rdi
movl %r14d, %esi
callq 0x22890
movq %rax, %r15
movq %r13, -0x38(%rbp)
movq 0x68(%r13), %rdi
movl %r14d, %esi
callq 0x2b9d0
movq %r12, -0x40(%rbp)
movsd (%r12), %xmm0
movq 0x60(%rbx), %rcx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %rbx, %r8
callq 0x2c17c
movl 0x4(%rbx), %r13d
movsd 0x40(%rbx), %xmm0
callq 0x9850
cvttsd2si %xmm0, %r15d
movl %r15d, 0x68(%rbx)
cmpl $0x1, %r13d
je 0x2b890
movsd 0x48(%rbx), %xmm0
movsd 0x50(%rbx), %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x9100
cvttsd2si %xmm0, %r13d
movl %r13d, 0x6c(%rbx)
movsd -0x30(%rbp), %xmm0
callq 0x9850
cvttsd2si %xmm0, %eax
movl %eax, 0x70(%rbx)
cmpl %r13d, %r15d
jle 0x2b890
movl %eax, 0x68(%rbx)
movl $0x1, 0x4(%rbx)
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
movl %r14d, %esi
callq 0x22890
movsd 0x8(%r15), %xmm0
movsd 0x10(%r15), %xmm1
subsd (%rax), %xmm0
subsd 0x8(%rax), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2b8d5
sqrtsd %xmm0, %xmm0
jmp 0x2b8da
callq 0x93c0
movq -0x40(%rbp), %rax
movsd (%rax), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
ja 0x2b8f8
movl 0x68(%rbx), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
movl %eax, 0x68(%rbx)
movl 0x4(%rbx), %eax
cmpl $0x2, %eax
jl 0x2b91c
movl 0x68(%rbx), %ecx
movl 0x6c(%rbx), %edx
cmpl %ecx, %edx
cmovgl %edx, %ecx
movl %ecx, 0x6c(%rbx)
movl 0x70(%rbx), %edx
cmpl %ecx, %edx
cmovgl %edx, %ecx
movl %ecx, 0x70(%rbx)
addl %r14d, 0x68(%rbx)
cmpl $0x2, %eax
jl 0x2b92d
addl %r14d, 0x6c(%rbx)
addl %r14d, 0x70(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq