// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Tackler.cpp
// Function: Tackler::GetTackleInfoToDir(Agent const&, double, double*, Vector*)
bool Tackler::GetTackleInfoToDir(const Agent &agent, AngleDeg dir,
                                 AngleDeg *p_tackle_angle, Vector *p_ball_vel) {
  UpdateTackleData(agent);

  Array<int, 3> dir_idx;

  dir_idx[0] = dir2idx(dir);       //当前区间
  dir_idx[1] = dir2idx(dir - 1.0); //左边相邻区间
  dir_idx[2] = dir2idx(dir + 1.0); //右边相邻区间

  Vector optimal_ball_vel;
  AngleDeg best_tackle_angle = 0.0;
  double max_ball_speed = -1.0;
  bool ret = false;

  for (int j = 0; j < 3; ++j) {
    for (uint i = 0; i < mDirMap[dir_idx[j]].size(); ++i) {
      const int angle_idx1 = mDirMap[dir_idx[j]][i].first;
      const int angle_idx2 = mDirMap[dir_idx[j]][i].second;

      AngleDeg dir1 = mBallVelAfterTackle[angle_idx1].Dir();
      AngleDeg dir2 = mBallVelAfterTackle[angle_idx2].Dir();

      if (IsAngleDegInBetween(dir1, dir, dir2)) {
        ret = true;

        if (p_tackle_angle ||
            p_ball_vel) { //这里要找出使出球速度最大的tackle_angle
          dir2 = GetNormalizeAngleDeg(dir2, dir1);
          dir = GetNormalizeAngleDeg(dir, dir1);

          double rate = (dir2 - dir) / (dir2 - dir1);
          Vector ball_vel = mBallVelAfterTackle[angle_idx1] * rate +
                            mBallVelAfterTackle[angle_idx2] * (1.0 - rate);
          double ball_speed = ball_vel.Mod();

          if (ball_speed > max_ball_speed) {
            optimal_ball_vel = ball_vel;
            max_ball_speed = ball_speed;
            best_tackle_angle = mTackleAngle[angle_idx1] * rate +
                                mTackleAngle[angle_idx2] * (1.0 - rate);
          }

          continue;
        }

        return true;
      }
    }
  }

  if (ret) {
    if (p_ball_vel) {
      *p_ball_vel = optimal_ball_vel;
    }

    if (p_tackle_angle) {
      *p_tackle_angle = best_tackle_angle;
    }
  }

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rdi, %r15
leaq -0x70(%rbp), %r12
movsd %xmm0, (%r12)
callq 0x40e8c
movq %r15, %rdi
movq %r12, %rsi
callq 0x41926
movl %eax, -0x8c(%rbp)
movsd 0x15d33(%rip), %xmm1    # 0x57070
movsd (%r12), %xmm0
movsd %xmm1, -0x68(%rbp)
addsd %xmm1, %xmm0
leaq -0x38(%rbp), %r13
movsd %xmm0, (%r13)
movq %r15, %rdi
movq %r13, %rsi
callq 0x41926
movl %eax, -0x88(%rbp)
movsd (%r12), %xmm0
addsd 0x15cd3(%rip), %xmm0    # 0x57048
movsd %xmm0, (%r13)
leaq -0x38(%rbp), %rsi
movq %r15, %rdi
callq 0x41926
movl %eax, -0x84(%rbp)
leaq 0x2200(%r15), %rax
movq %rax, -0x58(%rbp)
movq %r15, -0xb0(%rbp)
leaq 0xb58(%r15), %rax
movq %rax, -0xb8(%rbp)
movq %rbx, %rax
movq %r14, -0x98(%rbp)
orq %r14, %rax
setne -0x29(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorl %eax, %eax
movsd %xmm0, -0x40(%rbp)
movq $0x0, -0x80(%rbp)
movsd %xmm0, -0x78(%rbp)
movq %rbx, -0xa0(%rbp)
movq -0xb8(%rbp), %r12
cmpq $0x3, %rax
je 0x415e5
movq %rax, -0xa8(%rbp)
leaq -0x8c(,%rax,4), %r14
addq %rbp, %r14
xorl %r13d, %r13d
movq -0x58(%rbp), %rbx
movq %r14, -0x60(%rbp)
movl %r13d, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4194e
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
jbe 0x415bb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4194e
movq (%rax), %rax
movslq (%rax,%r13,8), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4194e
movq (%rax), %rax
movslq 0x4(%rax,%r13,8), %r14
movq %r15, -0xc8(%rbp)
shlq $0x4, %r15
addq %r12, %r15
movq %r15, %rdi
callq 0xcd30
movsd %xmm0, -0x38(%rbp)
movq %r14, -0xc0(%rbp)
shlq $0x4, %r14
addq %r12, %r14
movq %r14, %rdi
callq 0xcd30
movsd %xmm0, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x4199f
testb %al, %al
je 0x4157d
cmpb $0x0, -0x29(%rbp)
je 0x415d1
movsd -0x50(%rbp), %xmm0
leaq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0xd305
movsd %xmm0, -0x50(%rbp)
movsd -0x70(%rbp), %xmm0
movq %rbx, %rdi
callq 0xd305
movsd %xmm0, -0x70(%rbp)
movsd -0x50(%rbp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
subsd -0x38(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd (%r15), %xmm1
mulsd %xmm2, %xmm1
movsd 0x8(%r15), %xmm3
mulsd %xmm2, %xmm3
movsd 0x15b3f(%rip), %xmm4    # 0x57048
subsd %xmm2, %xmm4
movsd (%r14), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
movsd 0x8(%r14), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm3, %xmm1
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
movapd %xmm0, %xmm5
mulsd %xmm0, %xmm5
addsd %xmm3, %xmm5
sqrtsd %xmm5, %xmm3
movb $0x1, %al
movq %rax, -0x80(%rbp)
movsd -0x68(%rbp), %xmm5
ucomisd %xmm5, %xmm3
jbe 0x4158e
movq -0xb0(%rbp), %rax
movq -0xc0(%rbp), %rcx
mulsd 0x10(%rax,%rcx,8), %xmm4
movq -0xc8(%rbp), %rcx
mulsd 0x10(%rax,%rcx,8), %xmm2
addsd %xmm4, %xmm2
movsd %xmm2, -0x78(%rbp)
jmp 0x4159c
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x68(%rbp), %xmm3
jmp 0x415a0
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movapd %xmm5, %xmm3
movq -0x58(%rbp), %rbx
movq -0x60(%rbp), %r14
incl %r13d
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
movsd %xmm3, -0x68(%rbp)
jmp 0x41410
movq -0xa8(%rbp), %rax
incq %rax
movq -0xa0(%rbp), %rbx
jmp 0x413e9
movb $0x1, %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, -0x80(%rbp)
movq -0x98(%rbp), %rax
je 0x4161c
testq %rax, %rax
je 0x4160a
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movb $0x1, %al
testq %rbx, %rbx
je 0x415d3
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x415d3
xorl %eax, %eax
jmp 0x415d3