// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b84e
movq %rax, -0x30(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x220a4
movq %rax, %r15
movq %r13, -0x38(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x2b064
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 0x2b86c
movl 0x4(%rbx), %r13d
movsd 0x40(%rbx), %xmm0
callq 0x9850
cvttsd2si %xmm0, %r15d
movl %r15d, 0x68(%rbx)
cmpl $0x1, %r13d
je 0x2afac
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 0x2afac
movl %eax, 0x68(%rbx)
movl $0x1, 0x4(%rbx)
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rdi
movl %r14d, %esi
callq 0x220a4
movsd 0x8(%r15), %xmm0
movsd 0x10(%r15), %xmm1
subsd (%rax), %xmm0
subsd 0x8(%rax), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movq -0x40(%rbp), %rax
movsd (%rax), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
ja 0x2afff
movl 0x68(%rbx), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
cmpl $0x2, 0x4(%rbx)
jl 0x2b029
movl 0x6c(%rbx), %ecx
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl 0x70(%rbx), %edx
cmpl %ecx, %edx
cmovlel %ecx, %edx
addl %r14d, %eax
movl %eax, 0x68(%rbx)
addl %r14d, %ecx
movl %ecx, 0x6c(%rbx)
addq $0x70, %rbx
movl %edx, %eax
jmp 0x2b02d
addq $0x68, %rbx
addl %r14d, %eax
movl %eax, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop