// File: 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
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x158(%rbp)
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rdi
callq 0x40800
movq -0x158(%rbp), %rdi
movq %rdx, -0x28(%rbp)
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x18(%rbp)
movb -0x24(%rbp), %al
movb %al, -0x14(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x56cf0
testb $0x1, %al
jne 0x8b4e0
jmp 0x8b4e5
jmp 0x8ba5a
movq -0x10(%rbp), %rdi
callq 0x40800
movq %rax, %rcx
movq -0x160(%rbp), %rax
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movl -0x48(%rbp), %ecx
movl %ecx, -0x38(%rbp)
movb -0x44(%rbp), %cl
movb %cl, -0x34(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movl -0x38(%rbp), %ecx
movl %ecx, 0x8(%rax)
movb -0x34(%rbp), %cl
movb %cl, 0xc(%rax)
movq -0x10(%rbp), %rdi
callq 0x10550
movq %rax, %rdi
callq 0x10570
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10590
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x168(%rbp)
movq -0x60(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x80(%rbp)
movsd %xmm1, -0x78(%rbp)
movq -0x60(%rbp), %rdi
callq 0x11170
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x11a10
movq -0x160(%rbp), %rdi
movsd 0x36220(%rip), %xmm0    # 0xc1828
movsd %xmm0, 0x21e8(%rdi)
addq $0x2200, %rdi           # imm = 0x2200
callq 0x8c7a0
callq 0x855e0
movq %rax, %rdi
callq 0x8c7c0
movsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x8c7e0
movsd (%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0xc8(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x12e50
movaps 0x359ee(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
movsd 0x359d2(%rip), %xmm1    # 0xc1050
divsd %xmm1, %xmm0
movsd 0x38876(%rip), %xmm1    # 0xc3f00
mulsd %xmm1, %xmm0
movsd 0x3597a(%rip), %xmm1    # 0xc1010
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd 0x395e6(%rip), %xmm0    # 0xc4c90
movsd %xmm0, -0xd0(%rbp)
movsd 0x395de(%rip), %xmm0    # 0xc4c98
ucomisd -0xd0(%rbp), %xmm0
jb 0x8ba5a
movq -0x58(%rbp), %rdi
callq 0x10a80
movq (%rax), %rcx
movq %rcx, -0xe0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xd8(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x198(%rbp)
movsd -0xb0(%rbp), %xmm0
subsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x190(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x12e50
movsd -0x198(%rbp), %xmm1
movaps %xmm0, %xmm3
movsd -0x190(%rbp), %xmm0
movaps 0x3592c(%rip), %xmm2    # 0xc1060
pand %xmm2, %xmm3
movsd 0x35910(%rip), %xmm2    # 0xc1050
divsd %xmm2, %xmm3
movsd 0x358c4(%rip), %xmm2    # 0xc1010
subsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x188(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x8c800
movsd -0x188(%rbp), %xmm0
mulsd (%rax), %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd -0xc0(%rbp), %xmm0
mulsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x180(%rbp)
movq -0x60(%rbp), %rdi
callq 0x11170
movsd -0x180(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x112c0
movsd %xmm0, -0xf8(%rbp)
movsd %xmm1, -0xf0(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x32ae0
leaq -0xe0(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x118(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x23d60
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x12a60
movq %rax, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x3fcd0
movq -0x160(%rbp), %rdi
movsd %xmm0, -0x110(%rbp)
movsd %xmm1, -0x108(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rsi
callq 0x8c820
movl %eax, -0x11c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x10520
movq -0x160(%rbp), %rdi
movsd %xmm0, -0x128(%rbp)
leaq -0x128(%rbp), %rsi
callq 0x8c860
movq -0x160(%rbp), %rdi
movl %eax, -0x120(%rbp)
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
addq $0x10, %rdi
movslq -0x11c(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x130(%rbp), %rsi
callq 0x8c8b0
movsd -0x178(%rbp), %xmm0
movq -0x160(%rbp), %rdi
movsd %xmm0, (%rax)
addq $0xb58, %rdi            # imm = 0xB58
movslq -0x11c(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x8c8d0
movq -0x160(%rbp), %rdi
movq -0xe0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xd8(%rbp), %rcx
movq %rcx, 0x8(%rax)
addq $0x2200, %rdi           # imm = 0x2200
leaq -0x120(%rbp), %rsi
callq 0x8c8f0
movq -0x160(%rbp), %rdi
movq %rax, -0x170(%rbp)
movsd 0x356b5(%rip), %xmm0    # 0xc1010
addsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
leaq -0x150(%rbp), %rsi
callq 0x8c820
movl %eax, -0x144(%rbp)
leaq -0x11c(%rbp), %rdi
leaq -0x144(%rbp), %rsi
callq 0x8ca00
movq -0x170(%rbp), %rdi
movq %rax, -0x140(%rbp)
leaq -0x140(%rbp), %rsi
callq 0x8c9d0
leaq -0xe0(%rbp), %rdi
callq 0x104e0
movq -0x160(%rbp), %rax
ucomisd 0x21e8(%rax), %xmm0
jbe 0x8b9e2
leaq -0xe0(%rbp), %rdi
callq 0x104e0
movq -0x160(%rbp), %rax
movsd %xmm0, 0x21e8(%rax)
leaq -0xe0(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x1a0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x113d0
movsd -0x1a0(%rbp), %xmm1
mulsd (%rax), %xmm1
movsd 0x355f1(%rip), %xmm0    # 0xc1008
ucomisd %xmm1, %xmm0
jbe 0x8ba3b
movq -0x160(%rbp), %rax
movb $0x1, 0x21f0(%rax)
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, 0x21f8(%rax)
jmp 0x8ba3d
movsd 0x355cb(%rip), %xmm0    # 0xc1010
addsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
jmp 0x8b6b2
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw %cs:(%rax,%rax)