// File: 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
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x10f70
movl %eax, -0x1c(%rbp)
callq 0x4cc20
movq %rax, -0x108(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x11fc0
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x11ff0
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq %rax, %rdx
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x10(%rbp), %r8
callq 0x4ccb0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x4a3f8
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movq $0x0, -0x28(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x4aae0
movsd (%rax), %xmm0
callq 0xaa00
cvttsd2si %xmm0, %eax
movl %eax, -0x10c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0x4aaa0
movl -0x10c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x4a575
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movq $0x0, -0x38(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x4aae0
movsd (%rax), %xmm0
callq 0xaa00
cvttsd2si %xmm0, %eax
movl %eax, -0x11c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0x40(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x4aaa0
movl -0x11c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movq $0x1, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x4aae0
movsd (%rax), %xmm0
callq 0xa110
cvttsd2si %xmm0, %eax
movl %eax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x1, -0x50(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x4aaa0
movl -0x118(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movq $0x2, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x4aae0
movsd (%rax), %xmm0
callq 0xaa00
cvttsd2si %xmm0, %eax
movl %eax, -0x114(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x2, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x4aaa0
movl -0x114(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0x68(%rbp)
leaq -0x68(%rbp), %rsi
callq 0x4aaa0
movl (%rax), %eax
movl %eax, -0x110(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x1, -0x70(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x4aaa0
movq %rax, %rcx
movl -0x110(%rbp), %eax
cmpl (%rcx), %eax
jle 0x4a573
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x2, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x4aaa0
movl (%rax), %eax
movl %eax, -0x120(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0x80(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x4aaa0
movl -0x120(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0x4a575
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x128(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x11fc0
movq -0x128(%rbp), %rdi
movq %rax, %rsi
callq 0x1d6d0
movaps %xmm0, %xmm1
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movb %al, -0x81(%rbp)
testb $0x1, -0x81(%rbp)
jne 0x4a634
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0x90(%rbp)
leaq -0x90(%rbp), %rsi
callq 0x4aaa0
movq %rax, %rdi
movl $0x1, -0x94(%rbp)
leaq -0x94(%rbp), %rsi
callq 0x329c0
movl (%rax), %eax
movl %eax, -0x12c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0xa0(%rbp)
leaq -0xa0(%rbp), %rsi
callq 0x4aaa0
movl -0x12c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x4a659
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0xa8(%rbp)
leaq -0xa8(%rbp), %rsi
callq 0x4aaa0
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jle 0x4a76d
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x1, -0xb0(%rbp)
leaq -0xb0(%rbp), %rsi
callq 0x4aaa0
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0xb8(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x4aaa0
movq -0x148(%rbp), %rdi
movq %rax, %rsi
callq 0x329c0
movl (%rax), %eax
movl %eax, -0x13c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x1, -0xc0(%rbp)
leaq -0xc0(%rbp), %rsi
callq 0x4aaa0
movl -0x13c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x2, -0xc8(%rbp)
leaq -0xc8(%rbp), %rsi
callq 0x4aaa0
movq %rax, -0x138(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x1, -0xd0(%rbp)
leaq -0xd0(%rbp), %rsi
callq 0x4aaa0
movq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x329c0
movl (%rax), %eax
movl %eax, -0x130(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x2, -0xd8(%rbp)
leaq -0xd8(%rbp), %rsi
callq 0x4aaa0
movl -0x130(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jg 0x4a7ae
movl -0x1c(%rbp), %eax
movl %eax, -0x14c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0xe0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0x4aaa0
movl -0x14c(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x4a844
movl -0x1c(%rbp), %eax
movl %eax, -0x158(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x0, -0xe8(%rbp)
leaq -0xe8(%rbp), %rsi
callq 0x4aaa0
movl -0x158(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x154(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x1, -0xf0(%rbp)
leaq -0xf0(%rbp), %rsi
callq 0x4aaa0
movl -0x154(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x150(%rbp)
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
movq $0x2, -0xf8(%rbp)
leaq -0xf8(%rbp), %rsi
callq 0x4aaa0
movl -0x150(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)