// File: 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
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x138(%rbp)
movq %rdi, -0x148(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movsd %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x140(%rbp)
movq -0x10(%rbp), %rsi
callq 0x50020
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x1, %ecx
callq 0x53d50
movq -0x138(%rbp), %rdi
movb (%rdi), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x55ac1
jmp 0x5602c
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
addq $0x2b4580, %rdi         # imm = 0x2B4580
addq $0x40, %rdi
addq $0x8, %rsi
callq 0x11360
movq -0x140(%rbp), %rdi
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x28(%rbp)
addq $0x2b4580, %rdi         # imm = 0x2B4580
addq $0x30, %rdi
leaq -0x30(%rbp), %rsi
callq 0x11360
movq -0x140(%rbp), %rsi
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
addq $0x2b4580, %rsi         # imm = 0x2B4580
addq $0x18, %rsi
leaq -0x50(%rbp), %rdi
callq 0x110a0
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x113d0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x13320
movq -0x140(%rbp), %rsi
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movq %rsi, %rdi
addq $0x2b45d8, %rdi         # imm = 0x2B45D8
addq $0x2b4580, %rsi         # imm = 0x2B4580
addq $0x18, %rsi
callq 0x110a0
movq -0x140(%rbp), %rax
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
addq $0x2b4580, %rax         # imm = 0x2B4580
addq $0x18, %rax
movq %rax, -0x158(%rbp)
callq 0x798a0
movq -0x140(%rbp), %rsi
movq %rax, %rdi
addq $0x2b4580, %rsi         # imm = 0x2B4580
callq 0x129d0
movq %rax, %rdi
callq 0x12fe0
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x13320
movsd %xmm0, -0x80(%rbp)
movsd %xmm1, -0x78(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x90(%rbp)
movsd %xmm1, -0x88(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x32ae0
callq 0x855e0
movq %rax, %rdi
callq 0x113d0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x113f0
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x32970
leaq -0x40(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x150(%rbp)
callq 0x798a0
movq -0x140(%rbp), %rsi
movq %rax, %rdi
addq $0x2b4580, %rsi         # imm = 0x2B4580
callq 0x129d0
movq %rax, %rdi
callq 0x1deb0
movsd -0x150(%rbp), %xmm0
movsd (%rax), %xmm1
movsd 0x6c254(%rip), %xmm2    # 0xc1ed8
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x55d01
leaq -0x40(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x160(%rbp)
callq 0x798a0
movq -0x140(%rbp), %rsi
movq %rax, %rdi
addq $0x2b4580, %rsi         # imm = 0x2B4580
callq 0x129d0
movq %rax, %rdi
callq 0x12ef0
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x12f10
movsd -0x168(%rbp), %xmm0
movsd -0x160(%rbp), %xmm1
addsd (%rax), %xmm0
movsd 0x6b9d9(%rip), %xmm2    # 0xc16d0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x55d10
movq -0x138(%rbp), %rax
movb $0x0, (%rax)
jmp 0x5602c
movq -0x140(%rbp), %rax
movl 0x2b4580(%rax), %eax
movl %eax, -0x174(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x104e0
movl -0x174(%rbp), %edi
callq 0x570a0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10520
movaps %xmm0, %xmm1
movsd -0x170(%rbp), %xmm0
movaps 0x6b2f6(%rip), %xmm2    # 0xc1060
pand %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x55d87
leaq -0x40(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x98(%rbp)
jmp 0x55de2
leaq -0x40(%rbp), %rdi
callq 0x10520
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x55dab
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x180(%rbp)
jmp 0x55dd2
movsd -0x98(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x180(%rbp)
movsd -0x180(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0xa8(%rbp)
movsd %xmm1, -0xa0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x38(%rbp)
movsd -0x98(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xc8(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0xc0(%rbp)
movsd %xmm1, -0xb8(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x28(%rbp)
movsd -0x98(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xe0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x11110
movq -0x140(%rbp), %rsi
movsd %xmm0, -0xd8(%rbp)
movsd %xmm1, -0xd0(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %rsi, %rdi
addq $0x2b4580, %rdi         # imm = 0x2B4580
addq $0x30, %rdi
addq $0x2b4580, %rsi         # imm = 0x2B4580
addq $0x40, %rsi
callq 0x11360
movq -0x138(%rbp), %rsi
movsd %xmm0, -0x110(%rbp)
movsd %xmm1, -0x108(%rbp)
addq $0x8, %rsi
leaq -0x110(%rbp), %rdi
callq 0x11360
movq -0x140(%rbp), %rsi
movsd %xmm0, -0x100(%rbp)
movsd %xmm1, -0xf8(%rbp)
addq $0x2b4580, %rsi         # imm = 0x2B4580
addq $0x18, %rsi
leaq -0x100(%rbp), %rdi
callq 0x110a0
movq -0x140(%rbp), %rdi
movsd %xmm0, -0xf0(%rbp)
movsd %xmm1, -0xe8(%rbp)
leaq -0xf0(%rbp), %rsi
callq 0x57110
movl %eax, -0x14(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x128(%rbp)
movsd %xmm1, -0x120(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x10520
movq -0x140(%rbp), %rax
movsd %xmm0, -0x118(%rbp)
movl 0x2b4580(%rax), %esi
leaq -0x40(%rbp), %rdi
callq 0x111b0
movsd %xmm0, -0x188(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x10f10
movsd -0x188(%rbp), %xmm0
movq -0x140(%rbp), %rdi
mulsd (%rax), %xmm0
movsd %xmm0, -0x130(%rbp)
leaq -0x30(%rbp), %rsi
leaq -0x118(%rbp), %rdx
leaq -0x130(%rbp), %rcx
callq 0x569c0
movsd %xmm0, -0x20(%rbp)
movq -0x148(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopl (%rax)