// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Tackler.cpp
// Function: Tackler::UpdateTackleData(Agent const&)
void Tackler::UpdateTackleData(const Agent &agent) {
  if (mAgentID == agent.GetAgentID()) {
    return; /** no need to update */
  }

  mAgentID = agent.GetAgentID();

  const BallState &ball_state = agent.GetWorldState().GetBall();
  const PlayerState &player_state = agent.GetSelf();
  Vector ball_2_player = (ball_state.GetPos() - player_state.GetPos())
                             .Rotate(-player_state.GetBodyDir());

  Vector ball_vel;
  mMaxTackleSpeed = -1.0;
  mDirMap.clear();

  const double max_tackle_power = ServerParam::instance().maxTacklePower();
  const double min_back_tackle_power =
      ServerParam::instance().maxBackTacklePower();

  double factor = 1.0 - 0.5 * (fabs(Deg2Rad(ball_2_player.Dir())) / M_PI);

  for (AngleDeg tackle_angle = -180.0 + FLOAT_EPS;
       tackle_angle <= 180.0 + FLOAT_EPS; tackle_angle += 1.0) {
    Vector ball_vel(ball_state.GetVel());
    double eff_power =
        (min_back_tackle_power + ((max_tackle_power - min_back_tackle_power) *
                                  (1.0 - fabs(Deg2Rad(tackle_angle)) / M_PI))) *
        ServerParam::instance().tacklePowerRate();
    eff_power *= factor;
    ball_vel +=
        Polar2Vector(eff_power, tackle_angle + player_state.GetBodyDir());
    ball_vel = ball_vel.SetLength(
        Min(ball_vel.Mod(), ServerParam::instance().ballSpeedMax()));

    int angle_idx = ang2idx(tackle_angle);
    int dir_idx = dir2idx(ball_vel.Dir());

    mTackleAngle[angle_idx] = tackle_angle;
    mBallVelAfterTackle[angle_idx] = ball_vel;
    mDirMap[dir_idx].push_back(
        std::make_pair(angle_idx, ang2idx(tackle_angle + 1.0)));

    if (ball_vel.Mod() > mMaxTackleSpeed) {
      mMaxTackleSpeed = ball_vel.Mod();
    }

    if (ball_vel.Mod() * ServerParam::instance().ballDecay() < FLOAT_EPS) {
      mCanTackleStopBall = true;
      mTackleStopBallAngle = tackle_angle;
    }
  }
  //
  //
  //    for (AngleDeg tackle_angle = -180.0 + 0.3; tackle_angle <= 180.0 +
  //    FLOAT_EPS; tackle_angle += 1.0) { 	Vector ball_vel =
  //    GetBallVelAfterTackle(agent, tackle_angle); 	AngleDeg tackle_angle2 =
  //    0.0; 	GetTackleAngleToDir(agent, ball_vel.Dir(), & tackle_angle2);
  //
  //    	std::cout << tackle_angle << " " << tackle_angle2 << std::endl;
  //    }
  //
  //    exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x21bf6
leaq -0xb0(%rbp), %rsi
movq %rax, (%rsi)
movl %edx, 0x8(%rsi)
shrq $0x20, %rdx
movb %dl, 0xc(%rsi)
movq %rbx, %rdi
callq 0x2a9d6
testb %al, %al
je 0x40ee0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x21bf6
movq %rax, (%rbx)
movl %edx, 0x8(%rbx)
shrq $0x20, %rdx
movb %dl, 0xc(%rbx)
movq 0x18(%r14), %r15
movq %r14, %rdi
callq 0xcd42
movsd 0x38(%r15), %xmm0
movsd 0x40(%r15), %xmm1
subsd 0x8(%rax), %xmm0
subsd 0x10(%rax), %xmm1
leaq -0x40(%rbp), %rdi
movsd %xmm0, (%rdi)
movsd %xmm1, 0x8(%rdi)
movq %rax, -0x78(%rbp)
movsd 0xb0(%rax), %xmm0
xorps 0x160e9(%rip), %xmm0    # 0x57020
leaq -0x30(%rbp), %rsi
movlps %xmm0, (%rsi)
callq 0xd02c
leaq -0xb0(%rbp), %r12
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x21e8(%rbx)
leaq 0x2200(%rbx), %rdi
movq %rdi, -0x70(%rbp)
callq 0x41abe
callq 0x3db2c
movsd 0x3360(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
callq 0x3db2c
movsd 0x3368(%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq %r12, %rdi
callq 0xcd30
movsd 0x160fc(%rip), %xmm1    # 0x570a8
mulsd %xmm1, %xmm0
divsd 0x160b0(%rip), %xmm0    # 0x57068
andpd 0x16050(%rip), %xmm0    # 0x57010
divsd %xmm1, %xmm0
mulsd 0x16094(%rip), %xmm0    # 0x57060
addsd 0x16074(%rip), %xmm0    # 0x57048
movapd %xmm0, -0xa0(%rbp)
addq $0x60, %r15
movq %r15, -0x80(%rbp)
movsd -0x50(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0xb58(%rbx), %r14
movsd 0x19b56(%rip), %xmm0    # 0x5ab58
leaq -0x48(%rbp), %r12
movsd %xmm0, -0x30(%rbp)
movsd 0x19b4d(%rip), %xmm1    # 0x5ab60
ucomisd %xmm0, %xmm1
jb 0x40ece
movq -0x80(%rbp), %rax
movups (%rax), %xmm1
movaps %xmm1, -0x40(%rbp)
movsd 0x16078(%rip), %xmm1    # 0x570a8
mulsd %xmm1, %xmm0
divsd 0x1602c(%rip), %xmm0    # 0x57068
andpd 0x15fcc(%rip), %xmm0    # 0x57010
divsd %xmm1, %xmm0
movsd 0x15ff8(%rip), %xmm1    # 0x57048
subsd %xmm0, %xmm1
mulsd -0x50(%rbp), %xmm1
addsd -0x68(%rbp), %xmm1
movsd %xmm1, -0x58(%rbp)
callq 0x3db2c
movsd -0x58(%rbp), %xmm0
mulsd 0x3328(%rax), %xmm0
mulsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x78(%rbp), %rax
addsd 0xb0(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
callq 0xd15b
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
addsd -0x38(%rbp), %xmm1
movsd %xmm1, -0x38(%rbp)
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x3db2c
movsd -0x48(%rbp), %xmm0
ucomisd 0x30f8(%rax), %xmm0
leaq 0x30f8(%rax), %rsi
cmovbeq %r12, %rsi
leaq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x219b2
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
callq 0x41902
movl %eax, %r15d
movq %r13, %rdi
callq 0xcd30
movsd %xmm0, -0x48(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41926
movl %eax, -0x5c(%rbp)
movsd -0x30(%rbp), %xmm0
movslq %r15d, %r13
movsd %xmm0, 0x10(%rbx,%r13,8)
movq %r13, %rax
shlq $0x4, %rax
movaps -0x40(%rbp), %xmm0
movups %xmm0, (%r14,%rax)
movq -0x70(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x4194e
movq %rax, %r15
movsd -0x30(%rbp), %xmm0
addsd 0x15edc(%rip), %xmm0    # 0x57048
movsd %xmm0, -0x88(%rbp)
movq %rbx, %rdi
leaq -0x88(%rbp), %rsi
callq 0x41902
shlq $0x20, %rax
movl %r13d, %ecx
orq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x41d9e
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
ucomisd 0x21e8(%rbx), %xmm0
jbe 0x411c8
movsd %xmm0, 0x21e8(%rbx)
movsd %xmm0, -0x58(%rbp)
callq 0x3db2c
movsd -0x58(%rbp), %xmm1
mulsd 0x30e0(%rax), %xmm1
movsd 0x15e59(%rip), %xmm0    # 0x57040
ucomisd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm0
jbe 0x41201
movb $0x1, 0x21f0(%rbx)
movsd %xmm0, 0x21f8(%rbx)
addsd 0x15e3f(%rip), %xmm0    # 0x57048
jmp 0x41006