// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Kicker.cpp
// Function: Kicker::UpdateKickData(Agent const&)
void Kicker::UpdateKickData(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();

  /** absolute values */
  mInput.mBallPos = ball_state.GetPos();
  mInput.mBallVel = ball_state.GetVel();
  mInput.mPlayerPos = player_state.GetPos();
  mInput.mPlayerVel = player_state.GetVel();
  mInput.mPlayerBodyDir = player_state.GetBodyDir();

  /** relative values */
  mInput.mBallPos =
      (mInput.mBallPos - mInput.mPlayerPos).Rotate(-mInput.mPlayerBodyDir);
  mInput.mBallVel = mInput.mBallVel.Rotate(-mInput.mPlayerBodyDir);
  mInput.mPlayerVel = mInput.mPlayerVel.Rotate(-mInput.mPlayerBodyDir);

  /** player type is changed */
  if (mInput.mPlayerType != player_state.GetPlayerType()) {
    mInput.mPlayerType = player_state.GetPlayerType();

    for (int k = 0; k < POINTS_NUM; ++k) {
      mKickRate[k] = GetKickRate(mPoint[k], mInput.mPlayerType);
      mMaxAccel[k] = ServerParam::instance().maxPower() *
                     mKickRate[k]; //计算出对应该点最大的eff_power
    }

    for (int i = 0; i < POINTS_NUM; ++i) //考虑kick_rand
    {
      AngleDeg angle_diff = mPoint[i].Dir();
      angle_diff = GetNormalizeAngleDeg(angle_diff);
      double dir_diff = Deg2Rad(fabs(angle_diff));
      double dist_2_ball = mPoint[i].Mod() -
                           PlayerParam::instance()
                               .HeteroPlayer(mInput.mPlayerType)
                               .playerSize() -
                           ServerParam::instance().ballSize();
      double kick_pos_rand =
          dir_diff / M_PI + dist_2_ball / PlayerParam::instance()
                                              .HeteroPlayer(mInput.mPlayerType)
                                              .kickableMargin();
      mRandEva[i] = mRandCurve.GetOutput(kick_pos_rand);
    }
  }

  /** initial */
  for (int i = 0; i < POINTS_NUM; i++) {
    mPointEva[i] = mRandEva[i];
  }

  /** 排除掉一定不能踢的点 */
  Vector ball_next_pos = mInput.mBallPos + mInput.mBallVel - mInput.mPlayerVel;
  double eff_power =
      ServerParam::instance().maxPower() *
      agent.GetSelf().GetKickRate(); //球在当前位置下的实际可以踢到的最大加速度
  double outside_buf = 0.3;
  Vector temp_pos = Vector(0.0, 0.0);

  double x_max = ServerParam::instance().PITCH_LENGTH * 0.5 -
                 mInput.mPlayerPos.X() - outside_buf;
  double x_min = -ServerParam::instance().PITCH_LENGTH * 0.5 -
                 mInput.mPlayerPos.X() + outside_buf;
  double y_max = ServerParam::instance().PITCH_WIDTH * 0.5 -
                 mInput.mPlayerPos.Y() - outside_buf;
  double y_min = -ServerParam::instance().PITCH_WIDTH * 0.5 -
                 mInput.mPlayerPos.Y() + outside_buf;

  for (int i = 0; i < POINTS_NUM; i++) {
    temp_pos =
        (mInput.mPlayerVel + mPoint[i])
            .Rotate(mInput.mPlayerBodyDir); /** 把x正方向变为和球场一样 */
    if (ball_next_pos.Dist(mPoint[i]) > eff_power /** 踢不到该点 */
        || temp_pos.X() > x_max || temp_pos.X() < x_min ||
        temp_pos.Y() > y_max || temp_pos.Y() < y_min) /** 会出界 */
    {
      mPointEva[i] = 0.0;
      continue;
    }
  }

  /** 考虑近身对手，不用InfoState的东西，接口更简单 */
  int min_unum = 0;
  double min_dist = 100.0;
  for (int i = 1; i <= TEAMSIZE; ++i) {
    double opp_kick_area;
    if (i == agent.GetWorldState().GetOpponentGoalieUnum()) {
      opp_kick_area = ServerParam::instance().maxCatchableArea();
    } else {
      opp_kick_area = agent.GetWorldState().GetOpponent(i).GetKickableArea();
    }
    double dist = agent.GetWorldState().GetOpponent(i).GetPos().Dist(
                      ball_state.GetPos()) -
                  opp_kick_area;

    if (dist < min_dist) {
      min_dist = dist;
      min_unum = i;
    }
  }

  if (min_unum != 0) {
    double opp_kick_area = 0.0;
    Vector opp_next_pos = agent.GetWorldState().GetOpponent(min_unum).GetPos();
    opp_next_pos = (opp_next_pos - (mInput.mPlayerPos + mInput.mPlayerVel))
                       .Rotate(-mInput.mPlayerBodyDir);
    if (min_unum == agent.GetWorldState().GetOpponentGoalieUnum()) {
      opp_kick_area = ServerParam::instance().maxCatchableArea();
    } else {
      opp_kick_area =
          agent.GetWorldState().GetOpponent(min_unum).GetKickableArea();
    }

    if (opp_next_pos.Mod() < opp_kick_area + 2.0) {
      double dist = 0.0;
      for (int i = 0; i < POINTS_NUM; i++) {
        dist = opp_next_pos.Dist(mPoint[i]) - opp_kick_area;
        mPointEva[i] *= mOppCurve.GetOutput(dist);
      }
    }
  }

  /** max kick rand factor */
  mMaxRandFactor = GetMaxKickRand(mInput.mBallPos, ball_state.GetVel(),
                                  player_state.GetPlayerType(),
                                  ServerParam::instance().maxPower());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x21bf6
leaq -0x50(%rbp), %rsi
movq %rax, (%rsi)
movl %edx, 0x8(%rsi)
shrq $0x20, %rdx
movb %dl, 0xc(%rsi)
movq %rbx, %rdi
callq 0x2a9d6
testb %al, %al
jne 0x277d3
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, -0x58(%rbp)
movq %r14, %rdi
callq 0xcd42
movq %rax, %r12
movups 0x38(%r15), %xmm0
movups %xmm0, 0x2b45b0(%rbx)
leaq 0x2b45c0(%rbx), %r14
movq %r15, -0x60(%rbp)
movups 0x60(%r15), %xmm0
movups %xmm0, 0x2b45c0(%rbx)
movups 0x8(%rax), %xmm0
movups %xmm0, 0x2b4588(%rbx)
movups 0x30(%rax), %xmm0
movups %xmm0, 0x2b4598(%rbx)
movsd 0xb0(%rax), %xmm0
movsd %xmm0, 0x2b45a8(%rbx)
movsd 0x2b45b0(%rbx), %xmm1
movsd 0x2b45b8(%rbx), %xmm2
subsd 0x2b4588(%rbx), %xmm1
subsd 0x2b4590(%rbx), %xmm2
leaq 0x2b4598(%rbx), %r15
leaq -0x50(%rbp), %r13
movsd %xmm1, (%r13)
movsd %xmm2, 0x8(%r13)
xorps 0x2fef0(%rip), %xmm0    # 0x57020
leaq -0xa0(%rbp), %rsi
movlps %xmm0, (%rsi)
movq %r13, %rdi
callq 0xd02c
movsd %xmm0, 0x2b45b0(%rbx)
movsd %xmm1, 0x2b45b8(%rbx)
movsd 0x2b45a8(%rbx), %xmm0
xorps 0x2febf(%rip), %xmm0    # 0x57020
movlps %xmm0, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xd02c
movsd %xmm0, 0x2b45c0(%rbx)
movsd %xmm1, 0x2b45c8(%rbx)
movsd 0x2b45a8(%rbx), %xmm0
xorpd 0x2fe8f(%rip), %xmm0    # 0x57020
movlpd %xmm0, (%r13)
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0xd02c
movsd %xmm0, 0x2b4598(%rbx)
movsd %xmm1, 0x2b45a0(%rbx)
movq %r12, -0x80(%rbp)
movl 0x114(%r12), %eax
cmpl %eax, 0x2b4580(%rbx)
jne 0x27563
movq -0x60(%rbp), %rax
leaq 0x38(%rax), %rcx
movq %rcx, -0x98(%rbp)
leaq 0x2b45b0(%rbx), %rcx
movq %rcx, -0x78(%rbp)
addq $0x60, %rax
movq %rax, -0x60(%rbp)
leaq 0x2b45a8(%rbx), %r15
movq $-0x288, %rax           # imm = 0xFD78
movq -0x58(%rbp), %r13
testq %rax, %rax
je 0x2721c
movsd 0x2b4d80(%rbx,%rax), %xmm0
movsd %xmm0, 0x2b5008(%rbx,%rax)
addq $0x8, %rax
jmp 0x271ff
movsd 0x2b45b0(%rbx), %xmm0
movsd 0x2b45b8(%rbx), %xmm1
addsd 0x2b45c0(%rbx), %xmm0
addsd 0x2b45c8(%rbx), %xmm1
subsd 0x2b4598(%rbx), %xmm0
movsd %xmm0, -0x90(%rbp)
subsd 0x2b45a0(%rbx), %xmm1
movsd %xmm1, -0x88(%rbp)
callq 0x3db2c
movsd 0x3130(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r13, %rdi
callq 0xcd42
movsd -0x30(%rbp), %xmm0
mulsd 0x130(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
leaq 0x32c34(%rip), %rax     # 0x59ec8
movsd (%rax), %xmm0
movapd %xmm0, -0x40(%rbp)
mulsd 0x305a3(%rip), %xmm0    # 0x57848
subsd 0x2b4588(%rbx), %xmm0
addsd 0x3160b(%rip), %xmm0    # 0x588c0
movapd %xmm0, -0xc0(%rbp)
callq 0x3db2c
movapd 0x2fd56(%rip), %xmm0    # 0x57020
movapd -0x40(%rbp), %xmm1
xorpd %xmm0, %xmm1
mulsd 0x3056d(%rip), %xmm1    # 0x57848
subsd 0x2b4588(%rbx), %xmm1
addsd 0x306b5(%rip), %xmm1    # 0x579a0
movapd %xmm1, -0x40(%rbp)
callq 0x3db2c
leaq 0x32bd4(%rip), %rax     # 0x59ed0
movsd (%rax), %xmm0
movapd %xmm0, -0x70(%rbp)
mulsd 0x3053b(%rip), %xmm0    # 0x57848
subsd 0x2b4590(%rbx), %xmm0
addsd 0x315a3(%rip), %xmm0    # 0x588c0
movapd %xmm0, -0xb0(%rbp)
callq 0x3db2c
movapd -0x70(%rbp), %xmm0
xorpd 0x2fce9(%rip), %xmm0    # 0x57020
mulsd 0x30509(%rip), %xmm0    # 0x57848
subsd 0x2b4590(%rbx), %xmm0
addsd 0x30651(%rip), %xmm0    # 0x579a0
movapd %xmm0, -0x70(%rbp)
xorl %r12d, %r12d
leaq -0x50(%rbp), %r14
cmpq $0x288, %r12            # imm = 0x288
je 0x2740c
movsd 0x2b4598(%rbx), %xmm0
movsd 0x2b45a0(%rbx), %xmm1
addsd 0x48(%rbx,%r12,2), %xmm0
addsd 0x50(%rbx,%r12,2), %xmm1
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xd02c
movsd -0x90(%rbp), %xmm2
subsd 0x48(%rbx,%r12,2), %xmm2
movsd -0x88(%rbp), %xmm3
subsd 0x50(%rbx,%r12,2), %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
ucomisd -0x30(%rbp), %xmm2
ja 0x273fa
ucomisd -0xc0(%rbp), %xmm0
ja 0x273fa
movapd -0x40(%rbp), %xmm2
ucomisd %xmm0, %xmm2
ja 0x273fa
ucomisd -0xb0(%rbp), %xmm1
ja 0x273fa
movapd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x27403
andq $0x0, 0x2b4d80(%rbx,%r12)
addq $0x8, %r12
jmp 0x2735b
movsd 0x302f4(%rip), %xmm0    # 0x57708
xorl %r14d, %r14d
pushq $0x1
popq %r15
movl $0x10d0, %r12d          # imm = 0x10D0
cmpq $0xc, %r15
je 0x274b6
movsd %xmm0, -0x30(%rbp)
movq 0x18(%r13), %rdi
movl 0x2114(%rdi), %eax
cmpq %rax, %r15
jne 0x27450
callq 0x3db2c
addq $0x3458, %rax           # imm = 0x3458
leaq -0x1(%r15), %r13
jmp 0x2745e
leaq -0x1(%r15), %r13
movq (%rdi,%r12), %rax
addq %r12, %rdi
callq *0x10(%rax)
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x58(%rbp), %rdx
movq 0x18(%rdx), %rax
imulq $0x178, %r13, %rcx      # imm = 0x178
movq %rdx, %r13
leaq (%rax,%rcx), %rdi
addq $0x10d8, %rdi           # imm = 0x10D8
movq -0x98(%rbp), %rsi
callq 0x2198a
subsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
cmoval %r15d, %r14d
minsd %xmm1, %xmm0
incq %r15
movl $0x178, %eax            # imm = 0x178
addq %rax, %r12
jmp 0x27421
testl %r14d, %r14d
je 0x277a3
movq 0x18(%r13), %rax
leal -0x1(%r14), %ecx
movslq %ecx, %rcx
imulq $0x178, %rcx, %r15      # imm = 0x178
movsd 0x10d8(%rax,%r15), %xmm0
movsd 0x10e0(%rax,%r15), %xmm1
movsd 0x2b4588(%rbx), %xmm2
movsd 0x2b4590(%rbx), %xmm3
addsd 0x2b4598(%rbx), %xmm2
subsd %xmm2, %xmm0
addsd 0x2b45a0(%rbx), %xmm3
subsd %xmm3, %xmm1
leaq -0x50(%rbp), %rdi
movsd %xmm0, (%rdi)
movsd %xmm1, 0x8(%rdi)
movsd 0x2b45a8(%rbx), %xmm0
xorps 0x2faf7(%rip), %xmm0    # 0x57020
leaq -0xa0(%rbp), %rsi
movlps %xmm0, (%rsi)
callq 0xd02c
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x40(%rbp)
movq 0x18(%r13), %rax
cmpl 0x2114(%rax), %r14d
jne 0x276e8
callq 0x3db2c
addq $0x3458, %rax           # imm = 0x3458
jmp 0x276f9
movl %eax, 0x2b4580(%rbx)
leaq 0x48(%rbx), %r15
movq $-0x288, %r12           # imm = 0xFD78
movq %r15, %r14
testq %r12, %r12
je 0x275bf
movl 0x2b4580(%rbx), %esi
movq %r14, %rdi
callq 0xd05c
movsd %xmm0, 0x2b4870(%rbx,%r12)
callq 0x3db2c
movsd 0x3130(%rax), %xmm0
mulsd 0x2b4870(%rbx,%r12), %xmm0
movsd %xmm0, 0x2b4af8(%rbx,%r12)
addq $0x8, %r12
addq $0x10, %r14
jmp 0x27577
leaq 0x2b4530(%rbx), %r13
movl $0x5695f, %r12d         # imm = 0x5695F
leaq -0x50(%rbp), %r14
cmpq $0x569b0, %r12          # imm = 0x569B0
je 0x271cb
movq %r15, %rdi
callq 0xcd30
movabsq $-0x3f99800000000000, %rax # imm = 0xC066800000000000
movq %rax, -0x50(%rbp)
movq %r14, %rdi
callq 0xd305
movapd %xmm0, %xmm1
andpd 0x2fa09(%rip), %xmm1    # 0x57010
movsd 0x2fa99(%rip), %xmm0    # 0x570a8
mulsd %xmm0, %xmm1
divsd 0x2fa4d(%rip), %xmm1    # 0x57068
movapd %xmm1, -0x40(%rbp)
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x38d94
movq 0x5c38(%rax), %rax
movslq 0x2b4580(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x30(%rbp), %xmm0
subsd 0x3038(%rax,%rcx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
movsd -0x30(%rbp), %xmm0
subsd 0x30d8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movapd -0x40(%rbp), %xmm0
divsd 0x2fa17(%rip), %xmm0    # 0x570a8
movapd %xmm0, -0x40(%rbp)
callq 0x38d94
movq 0x5c38(%rax), %rax
movslq 0x2b4580(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x30(%rbp), %xmm0
divsd 0x3040(%rax,%rcx), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movq %r13, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x2aa02
movsd %xmm0, (%rbx,%r12,8)
incq %r12
addq $0x10, %r15
jmp 0x275d0
leaq (%rax,%r15), %rdi
addq $0x10d0, %rdi           # imm = 0x10D0
movq (%rdi), %rax
callq *0x10(%rax)
movsd (%rax), %xmm2
movsd -0x40(%rbp), %xmm0
mulsd %xmm0, %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
movsd 0x30039(%rip), %xmm1    # 0x57758
movsd %xmm2, -0x58(%rbp)
addsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x277a3
leaq 0x2b4508(%rbx), %r14
xorl %r13d, %r13d
leaq -0x50(%rbp), %r15
pushq $0x1
popq %r12
cmpq $0x288, %r13            # imm = 0x288
je 0x277a3
movsd -0x30(%rbp), %xmm0
subsd 0x48(%rbx,%r13,2), %xmm0
movsd -0x40(%rbp), %xmm1
subsd 0x50(%rbx,%r13,2), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
subsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x2aa02
mulsd 0x2b4d80(%rbx,%r13), %xmm0
movsd %xmm0, 0x2b4d80(%rbx,%r13)
addq $0x8, %r13
jmp 0x27740
movq -0x80(%rbp), %rax
movl 0x114(%rax), %r14d
callq 0x3db2c
movsd 0x3130(%rax), %xmm0
movq -0x78(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl %r14d, %edx
callq 0x2aa46
movsd %xmm0, 0x2b5008(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop