// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Kicker.cpp
// Function: Kicker::TurnPlan(Agent const&, int, double)
AtomicAction Kicker::TurnPlan(const Agent &agent, int index,
                              double turn_max_speed) {
  UpdateKickData(agent);

  AtomicAction a = GetStopBallAction(agent, true);
  if (a.mSucceed == false) {
    return a;
  }

  // kick之后的各个量
  Vector ball_vel = mInput.mBallVel + a.mKickVel;
  Vector ball_pos = mInput.mBallPos + ball_vel - mInput.mPlayerVel;
  ball_vel = ball_vel * ServerParam::instance().ballDecay();
  Vector target = mKickTarget - mInput.mPlayerVel;
  Vector player_vel =
      mInput.mPlayerVel *
      PlayerParam::instance().HeteroPlayer(mInput.mPlayerType).playerDecay();

  // turn-转坐标轴之前的状态
  ball_pos += ball_vel - player_vel;
  ball_vel *= ServerParam::instance().ballDecay();
  target -= player_vel;
  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) //保证不碰撞
  {
    a.mSucceed = false;
    return a;
  }

  double max_turn_angle = GetMaxTurnAngle(mInput.mPlayerType, player_vel.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);

  Vector kicked_ball_pos =
      mInput.mBallPos + mInput.mBallVel + a.mKickVel - mInput.mPlayerVel;
  index = NearestPoint(kicked_ball_pos); // 这里要用kick后的点算
  turn_max_speed =
      GetOneKickMaxSpeed(ball_vel, (target - ball_pos).Dir(),
                         GetKickRate(ball_pos, mInput.mPlayerType) *
                             ServerParam::instance().maxPower());
  return a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x2703e
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x29008
cmpb $0x0, (%rbx)
je 0x2a4a4
movsd 0x8(%rbx), %xmm0
movsd 0x10(%rbx), %xmm1
movsd 0x2b45c0(%r14), %xmm2
movsd %xmm0, -0x80(%rbp)
addsd %xmm0, %xmm2
movsd %xmm2, -0x40(%rbp)
movsd 0x2b45c8(%r14), %xmm0
movsd %xmm1, -0x78(%rbp)
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x2b45b0(%r14), %xmm3
addsd %xmm2, %xmm3
movsd 0x2b45b8(%r14), %xmm1
addsd %xmm0, %xmm1
subsd 0x2b4598(%r14), %xmm3
movsd %xmm3, -0x58(%rbp)
subsd 0x2b45a0(%r14), %xmm1
movsd %xmm1, -0x60(%rbp)
callq 0x3db2c
movsd 0x30e0(%rax), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd -0x50(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movsd 0x2b45d8(%r14), %xmm1
movsd 0x2b45e0(%r14), %xmm0
subsd 0x2b4598(%r14), %xmm1
movsd %xmm1, -0x88(%rbp)
subsd 0x2b45a0(%r14), %xmm0
movsd %xmm0, -0x90(%rbp)
callq 0x38d94
movq 0x5c38(%rax), %rax
movslq 0x2b4580(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3020(%rax,%rcx), %xmm1
movsd 0x2b4598(%r14), %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, -0x70(%rbp)
mulsd 0x2b45a0(%r14), %xmm1
movsd %xmm1, -0x68(%rbp)
movsd -0x40(%rbp), %xmm0
subsd %xmm2, %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm2
subsd %xmm1, %xmm2
addsd -0x60(%rbp), %xmm2
movsd %xmm2, -0x60(%rbp)
movsd %xmm0, -0xb0(%rbp)
movsd %xmm2, -0xa8(%rbp)
callq 0x3db2c
movsd 0x30e0(%rax), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0xc0(%rbp)
movsd -0x50(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0xb8(%rbp)
movsd -0x88(%rbp), %xmm0
subsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x90(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x60(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x58(%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 0x2dcb9(%rip), %xmm0    # 0x57f10
movsd -0x40(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x2a2ab
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), %xmm0
addsd 0x30d8(%rax), %xmm0
addsd 0x2d474(%rip), %xmm0    # 0x57718
ucomisd -0x40(%rbp), %xmm0
jbe 0x2a2b3
movb $0x0, (%rbx)
jmp 0x2a4a4
movl 0x2b4580(%r14), %edi
movsd -0x68(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x70(%rbp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
callq 0x2ac27
movapd %xmm0, -0x40(%rbp)
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
callq 0xcd30
andpd 0x2cd1b(%rip), %xmm0    # 0x57010
movapd %xmm0, -0x50(%rbp)
movq %r15, %rdi
callq 0xcd30
movapd -0x40(%rbp), %xmm3
ucomisd -0x50(%rbp), %xmm3
ja 0x2a333
movapd 0x2cd0a(%rip), %xmm2    # 0x57020
xorpd %xmm3, %xmm2
xorpd %xmm1, %xmm1
cmpltsd %xmm0, %xmm1
andpd %xmm1, %xmm3
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movapd %xmm1, %xmm0
xorpd 0x2cce5(%rip), %xmm0    # 0x57020
movapd %xmm0, -0x40(%rbp)
leaq -0xa0(%rbp), %r15
movlpd %xmm0, (%r15)
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xd02c
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
movaps -0x40(%rbp), %xmm0
movlps %xmm0, (%r15)
leaq -0xc0(%rbp), %r15
leaq -0xa0(%rbp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0xd02c
movsd %xmm0, (%r15)
movsd %xmm1, 0x8(%r15)
movaps -0x40(%rbp), %xmm0
movlps %xmm0, (%r13)
leaq -0xd0(%rbp), %r13
leaq -0xa0(%rbp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0xd02c
movsd %xmm0, (%r13)
movsd %xmm1, 0x8(%r13)
movsd 0x2b45b0(%r14), %xmm0
movsd 0x2b45b8(%r14), %xmm1
addsd 0x2b45c0(%r14), %xmm0
addsd 0x2b45c8(%r14), %xmm1
movsd -0x80(%rbp), %xmm2
addsd %xmm0, %xmm2
movsd -0x78(%rbp), %xmm0
addsd %xmm1, %xmm0
subsd 0x2b4598(%r14), %xmm2
subsd 0x2b45a0(%r14), %xmm0
movsd %xmm2, (%r15)
movsd %xmm0, 0x8(%r15)
leaq -0xa0(%rbp), %rsi
movq %r14, %rdi
callq 0x2ac8a
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
subsd (%r12), %xmm0
subsd 0x8(%r12), %xmm1
leaq -0xf0(%rbp), %rdi
movsd %xmm0, (%rdi)
movsd %xmm1, 0x8(%rdi)
callq 0xcd30
leaq -0xe0(%rbp), %r15
movsd %xmm0, (%r15)
movl 0x2b4580(%r14), %esi
movq %r12, %rdi
callq 0xd05c
movsd %xmm0, -0x40(%rbp)
callq 0x3db2c
movsd -0x40(%rbp), %xmm0
mulsd 0x3130(%rax), %xmm0
leaq -0xd8(%rbp), %rcx
movsd %xmm0, (%rcx)
movq %r14, %rdi
leaq -0xc0(%rbp), %rsi
movq %r15, %rdx
callq 0x2a844
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop