// File: 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
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x168(%rbp)
movq -0x18(%rbp), %rsi
callq 0x8b480
leaq -0x3c(%rbp), %rdi
callq 0x4ad30
movq -0x168(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x8c860
movl %eax, -0x170(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4aaa0
movl -0x170(%rbp), %ecx
movq -0x168(%rbp), %rdi
movl %ecx, (%rax)
movsd -0x20(%rbp), %xmm0
movsd 0x3534c(%rip), %xmm1    # 0xc1010
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x8c860
movl %eax, -0x16c(%rbp)
movq $0x1, -0x58(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x4aaa0
movl -0x16c(%rbp), %ecx
movq -0x168(%rbp), %rdi
movl %ecx, (%rax)
movsd 0x35308(%rip), %xmm0    # 0xc1010
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x8c860
movl %eax, -0x15c(%rbp)
movq $0x2, -0x68(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4aaa0
movl -0x15c(%rbp), %ecx
movl %ecx, (%rax)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x11a10
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd 0x35ab0(%rip), %xmm0    # 0xc1828
movsd %xmm0, -0x98(%rbp)
movb $0x0, -0x99(%rbp)
movl $0x0, -0xa0(%rbp)
cmpl $0x3, -0xa0(%rbp)
jge 0x8c1b6
movl $0x0, -0xa4(%rbp)
movq -0x168(%rbp), %rax
movl -0xa4(%rbp), %ecx
movq %rcx, -0x178(%rbp)
addq $0x2200, %rax           # imm = 0x2200
movq %rax, -0x180(%rbp)
movslq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4aaa0
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x8c8f0
movq %rax, %rdi
callq 0x8ca30
movq %rax, %rcx
movq -0x178(%rbp), %rax
cmpq %rcx, %rax
jae 0x8c1a0
movq -0x168(%rbp), %rax
addq $0x2200, %rax           # imm = 0x2200
movq %rax, -0x190(%rbp)
movslq -0xa0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x4aaa0
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x8c8f0
movq %rax, %rdi
movl -0xa4(%rbp), %eax
movl %eax, %esi
callq 0x8ca50
movq %rax, %rcx
movq -0x168(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0xb4(%rbp)
addq $0x2200, %rax           # imm = 0x2200
movq %rax, -0x188(%rbp)
movslq -0xa0(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x4aaa0
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x8c8f0
movq %rax, %rdi
movl -0xa4(%rbp), %eax
movl %eax, %esi
callq 0x8ca50
movq -0x168(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0xc4(%rbp)
addq $0xb58, %rdi            # imm = 0xB58
movslq -0xb4(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0x8c8d0
movq %rax, %rdi
callq 0x10520
movq -0x168(%rbp), %rdi
movsd %xmm0, -0xd8(%rbp)
addq $0xb58, %rdi            # imm = 0xB58
movslq -0xc4(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xf0(%rbp), %rsi
callq 0x8c8d0
movq %rax, %rdi
callq 0x10520
movsd %xmm0, -0xe8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x8ca70
testb $0x1, %al
jne 0x8bf57
jmp 0x8c18a
movb $0x1, -0x99(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x8bf70
cmpq $0x0, -0x30(%rbp)
je 0x8c184
movsd -0xe8(%rbp), %xmm0
leaq -0xd8(%rbp), %rdi
callq 0x116b0
movsd %xmm0, -0xe8(%rbp)
movsd -0x20(%rbp), %xmm0
leaq -0xd8(%rbp), %rdi
callq 0x116b0
movq -0x168(%rbp), %rdi
movsd %xmm0, -0x20(%rbp)
movsd -0xe8(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
subsd -0xd8(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
addq $0xb58, %rdi            # imm = 0xB58
movslq -0xb4(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x120(%rbp), %rsi
callq 0x8c8d0
movq %rax, %rdi
leaq -0xf8(%rbp), %rsi
callq 0x13320
movq -0x168(%rbp), %rdi
movsd %xmm0, -0x118(%rbp)
movsd %xmm1, -0x110(%rbp)
addq $0xb58, %rdi            # imm = 0xB58
movslq -0xc4(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x8c8d0
movq %rax, %rdi
movsd 0x34fcb(%rip), %xmm0    # 0xc1010
subsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x140(%rbp)
leaq -0x140(%rbp), %rsi
callq 0x13320
movsd %xmm0, -0x130(%rbp)
movsd %xmm1, -0x128(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x11360
movsd %xmm0, -0x108(%rbp)
movsd %xmm1, -0x100(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x148(%rbp)
movsd -0x148(%rbp), %xmm0
ucomisd -0x98(%rbp), %xmm0
jbe 0x8c182
movq -0x168(%rbp), %rdi
movq -0x108(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x70(%rbp)
movsd -0x148(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
addq $0x10, %rdi
movslq -0xb4(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x150(%rbp), %rsi
callq 0x8c8b0
movq -0x168(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1a0(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x198(%rbp)
addq $0x10, %rdi
movslq -0xc4(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x158(%rbp), %rsi
callq 0x8c8b0
movsd -0x1a0(%rbp), %xmm0
movsd -0x198(%rbp), %xmm2
movsd (%rax), %xmm1
movsd 0x34eaa(%rip), %xmm3    # 0xc1010
subsd -0xf8(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
jmp 0x8c18c
movb $0x1, -0x1(%rbp)
jmp 0x8c1fd
jmp 0x8c18c
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x8bda8
jmp 0x8c1a2
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x8bd91
testb $0x1, -0x99(%rbp)
je 0x8c1f2
cmpq $0x0, -0x30(%rbp)
je 0x8c1d9
movq -0x30(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x8c1f0
movsd -0x90(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x8c1f2
movb -0x99(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax,%rax)