// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Kicker.cpp
// Function: Kicker::GetTurnAction(Agent const&)
AtomicAction Kicker::GetTurnAction(const Agent &agent) {
  UpdateKickData(agent);

  AtomicAction a;
  a.mSucceed = false;

  Vector ball_pos = mInput.mBallPos + mInput.mBallVel - mInput.mPlayerVel;
  Vector ball_vel = mInput.mBallVel * ServerParam::instance().ballDecay();
  Vector target = mKickTarget - mInput.mPlayerVel;
  if (ball_pos.Mod() < PlayerParam::instance()
                               .HeteroPlayer(mInput.mPlayerType)
                               .kickableArea() -
                           0.05 &&
      ball_pos.Mod() > PlayerParam::instance()
                               .HeteroPlayer(mInput.mPlayerType)
                               .playerSize() +
                           ServerParam::instance().ballSize() + 0.01) {
    double max_turn_angle =
        GetMaxTurnAngle(mInput.mPlayerType, mInput.mPlayerVel.Mod());
    if (max_turn_angle > fabs(ball_pos.Dir())) {
      max_turn_angle = ball_pos.Dir();
    } else {
      max_turn_angle = (ball_pos.Dir() > 0) ? max_turn_angle : -max_turn_angle;
    }

    /** turn之后的状态 */
    ball_pos = ball_pos.Rotate(-max_turn_angle);
    ball_vel = ball_vel.Rotate(-max_turn_angle);
    target = target.Rotate(-max_turn_angle);

    double kick_angle = (target - ball_pos).Dir();
    if (fabs(kick_angle) < 90.0) // 尽量转身以后要面对要踢的方向
    {
      double max_speed =
          GetOneKickMaxSpeed(ball_vel, kick_angle,
                             GetKickRate(ball_pos, mInput.mPlayerType) *
                                 ServerParam::instance().maxPower());
      if (max_speed >
          mKickSpeed +
              0.16) /** 这里要苛刻一点，否则可能由于误差导致转身过后达不到所需速度 */
      {
        a.mType = CT_Turn;
        a.mSucceed = true;
        a.mTurnAngle = max_turn_angle;
      }
    }
  }
  return a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x2703e
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x14(%rbx)
movups %xmm0, 0x4(%rbx)
movb $0x0, (%rbx)
movsd 0x2b45b0(%r14), %xmm1
movsd 0x2b45b8(%r14), %xmm0
addsd 0x2b45c0(%r14), %xmm1
addsd 0x2b45c8(%r14), %xmm0
subsd 0x2b4598(%r14), %xmm1
movsd %xmm1, -0x40(%rbp)
subsd 0x2b45a0(%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x70(%rbp)
movsd %xmm0, -0x68(%rbp)
callq 0x3db2c
movsd 0x30e0(%rax), %xmm0
movsd 0x2b45c0(%r14), %xmm1
mulsd %xmm0, %xmm1
mulsd 0x2b45c8(%r14), %xmm0
movsd %xmm1, -0x80(%rbp)
movsd %xmm0, -0x78(%rbp)
movsd 0x2b45d8(%r14), %xmm0
movsd 0x2b45e0(%r14), %xmm1
subsd 0x2b4598(%r14), %xmm0
subsd 0x2b45a0(%r14), %xmm1
movsd %xmm0, -0x90(%rbp)
movsd %xmm1, -0x88(%rbp)
movsd -0x50(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x40(%rbp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x38d94
movq 0x5c38(%rax), %rax
movslq 0x2b4580(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3080(%rax,%rcx), %xmm0
addsd 0x2e109(%rip), %xmm0    # 0x57f10
ucomisd -0x40(%rbp), %xmm0
jbe 0x2a01c
callq 0x38d94
movq 0x5c38(%rax), %rax
movslq 0x2b4580(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3038(%rax,%rcx), %xmm0
movsd %xmm0, -0x50(%rbp)
callq 0x3db2c
movsd -0x50(%rbp), %xmm1
addsd 0x30d8(%rax), %xmm1
addsd 0x2d8c4(%rip), %xmm1    # 0x57718
movsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2a01c
movl 0x2b4580(%r14), %edi
movsd 0x2b4598(%r14), %xmm0
movsd 0x2b45a0(%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
callq 0x2ac27
movapd %xmm0, -0x40(%rbp)
leaq -0x70(%rbp), %r15
movq %r15, %rdi
callq 0xcd30
andpd 0x2d166(%rip), %xmm0    # 0x57010
movapd %xmm0, -0x50(%rbp)
movq %r15, %rdi
callq 0xcd30
movapd -0x40(%rbp), %xmm3
ucomisd -0x50(%rbp), %xmm3
ja 0x29ee8
movapd 0x2d155(%rip), %xmm2    # 0x57020
xorpd %xmm3, %xmm2
xorpd %xmm1, %xmm1
cmpltsd %xmm0, %xmm1
andpd %xmm1, %xmm3
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movapd %xmm1, %xmm0
movapd 0x2d130(%rip), %xmm1    # 0x57020
movapd %xmm0, -0x50(%rbp)
xorpd %xmm0, %xmm1
movapd %xmm1, -0x40(%rbp)
leaq -0x60(%rbp), %r12
movlpd %xmm1, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0xd02c
movsd %xmm0, (%r15)
movsd %xmm1, 0x8(%r15)
movaps -0x40(%rbp), %xmm0
movlps %xmm0, (%r12)
leaq -0x80(%rbp), %r12
leaq -0x60(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xd02c
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
movapd -0x40(%rbp), %xmm0
movlpd %xmm0, (%r13)
leaq -0x90(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0xd02c
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
subsd (%r15), %xmm0
subsd 0x8(%r15), %xmm1
movsd %xmm0, (%r13)
movsd %xmm1, 0x8(%r13)
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0xcd30
movsd %xmm0, (%r15)
andpd 0x2d06f(%rip), %xmm0    # 0x57010
movsd 0x2d0df(%rip), %xmm1    # 0x57088
ucomisd %xmm0, %xmm1
jbe 0x2a01c
movl 0x2b4580(%r14), %esi
leaq -0x70(%rbp), %rdi
callq 0xd05c
movsd %xmm0, -0x40(%rbp)
callq 0x3db2c
movsd -0x40(%rbp), %xmm0
mulsd 0x3130(%rax), %xmm0
leaq -0x98(%rbp), %rcx
movsd %xmm0, (%rcx)
leaq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %r14, %rdi
callq 0x2a844
movsd 0x2b45d0(%r14), %xmm1
addsd 0x2e8ce(%rip), %xmm1    # 0x588d0
ucomisd %xmm1, %xmm0
jbe 0x2a01c
movl $0x1, 0x4(%rbx)
movb $0x1, (%rbx)
movapd -0x50(%rbp), %xmm0
movsd %xmm0, 0x18(%rbx)
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq