// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/Dasher.cpp
// Function: Dasher::CyclePredictedToPoint(PlayerState const&, Vector, double)
int Dasher::CyclePredictedToPoint(const PlayerState &player, Vector target,
                                  double dash_power) {
  double corrected_dash_power = dash_power;
  double effective_power;
  double predicted_stamina = player.GetStamina();
  double predicted_effort = player.GetEffort();
  double predicted_recovery = player.GetRecovery();
  double predicted_capacity = player.GetCapacity();
  double myang = player.GetBodyDir();
  Vector position = player.GetPos();
  Vector velocity;

  if (player.GetVelConf() < FLOAT_EPS) {
    velocity = Vector(0, 0);
  } else {
    velocity = player.GetVel();
  }

  Vector last_position = position;
  int max_cyc =
      (int)(position.Dist(target) / player.GetEffectiveSpeedMax() + 100);
  int last_action = 0; /* 0 -- turn , 1 -- dash*/

  for (int i = 0; i < max_cyc; i++) {
    if (position.Dist(target) < PlayerParam::instance().AtPointBuffer()) {
      return i;
    }

    if (position.Dist(target) > last_position.Dist(target) + FLOAT_EPS &&
        last_action == 1) {
      return i;
    }

    last_position = position;

    /*decide if we should turn*/
    double targ_ang;
    if (dash_power > 0) {
      targ_ang = (target - position).Dir() - myang;
    } else {
      targ_ang = (target - position).Dir() - GetNormalizeAngleDeg(myang + 180);
    }

    double max_go_to_point_angle_err = 4; //见08CP_max_go_to_point_angle_err
    if (fabs(GetNormalizeAngleDeg(targ_ang)) > max_go_to_point_angle_err) {
      /*turnint*/
      double this_turn =
          MinMax(-player.GetMaxTurnAngle(), GetNormalizeAngleDeg(targ_ang),
                 player.GetMaxTurnAngle());

      myang += this_turn;
      corrected_dash_power = 0;
      last_action = 0;
    } else {
      corrected_dash_power = player.CorrectDashPowerForStamina(dash_power);
      if (fabs(corrected_dash_power) > predicted_stamina) {
        effective_power = Sign(corrected_dash_power) * predicted_stamina;
      } else {
        effective_power = corrected_dash_power;
      }

      effective_power *= predicted_effort;
      effective_power *= player.GetDashPowerRate();
      velocity += Polar2Vector(effective_power, myang);
      last_action = 1;
    }

    if (velocity.Mod() > player.GetEffectiveSpeedMax()) {
      velocity *= (player.GetEffectiveSpeedMax() / velocity.Mod());
    }

    position += velocity;
    velocity *= player.GetPlayerDecay();

    // 08 内UpdatePredictStaminaWithDash函数 直接写入此函数
    if (dash_power > 0) {
      predicted_stamina -= dash_power;
    } else {
      predicted_stamina -= 2 * dash_power;
    }

    if (predicted_stamina < 0) {
      predicted_stamina = 0;
    }

    if (predicted_stamina < ServerParam::instance().recoverDecStamina() &&
        predicted_recovery > ServerParam::instance().recoverMin()) {
      predicted_recovery -= ServerParam::instance().recoverDec();
    }

    if (predicted_stamina < ServerParam::instance().effortDecStamina() &&
        predicted_effort > player.GetEffortMin()) {
      predicted_effort -= ServerParam::instance().effortDec();
    }

    if (predicted_stamina > ServerParam::instance().effortIncStamina() &&
        predicted_effort < player.GetEffortMax()) {
      predicted_effort += ServerParam::instance().effortDec();
    }

    //增加capacity改进
    double stamina_inc =
        Min(predicted_recovery * player.GetStaminaIncMax(), predicted_capacity);
    predicted_stamina += stamina_inc;
    if (predicted_stamina > ServerParam::instance().staminaMax()) {
      predicted_stamina = ServerParam::instance().staminaMax();
    }

    predicted_capacity -= stamina_inc;
    if (predicted_capacity < 0) {
      predicted_capacity = 0;
    }
  }

  return max_cyc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movsd %xmm2, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10cd0
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11650
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32a80
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x28(%rbp), %rdi
callq 0x12be0
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11170
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq (%rax), %rcx
movq %rcx, -0x78(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x11a10
movq -0x28(%rbp), %rdi
callq 0x32aa0
movsd 0x8f395(%rip), %xmm0    # 0xc1008
ucomisd (%rax), %xmm0
jbe 0x31cc4
xorps %xmm0, %xmm0
movsd %xmm0, -0xb0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x11a10
movq -0xa8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x31cdf
movq -0x28(%rbp), %rdi
callq 0x10a80
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1d6d0
movsd %xmm0, -0x170(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1d810
movsd -0x170(%rbp), %xmm0
divsd (%rax), %xmm0
movsd 0x8f9b1(%rip), %xmm1    # 0xc16d8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0xcc(%rbp)
movl $0x0, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jge 0x3237c
leaq -0x78(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1d6d0
movsd %xmm0, -0x178(%rbp)
callq 0x798a0
movq %rax, %rdi
callq 0x32ac0
movsd -0x178(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x31d9d
movl -0xd4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x32385
leaq -0x78(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1d6d0
movsd %xmm0, -0x180(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1d6d0
movaps %xmm0, %xmm1
movsd -0x180(%rbp), %xmm0
movsd 0x8f233(%rip), %xmm2    # 0xc1008
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x31df6
cmpl $0x1, -0xd0(%rbp)
jne 0x31df6
movl -0xd4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x32385
movq -0x78(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xc0(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x31e52
leaq -0x18(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0xf0(%rbp)
movsd %xmm1, -0xe8(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x10520
subsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
jmp 0x31ec3
leaq -0x18(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x100(%rbp)
movsd %xmm1, -0xf8(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x188(%rbp)
movsd 0x8f19d(%rip), %xmm0    # 0xc1028
addsd -0x68(%rbp), %xmm0
movsd 0x8f198(%rip), %xmm1    # 0xc1030
movsd %xmm1, -0x108(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x116b0
movaps %xmm0, %xmm1
movsd -0x188(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd 0x903cd(%rip), %xmm0    # 0xc2298
movsd %xmm0, -0x110(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd 0x8f14d(%rip), %xmm1    # 0xc1030
movsd %xmm1, -0x118(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x116b0
movaps 0x8f162(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
ucomisd -0x110(%rbp), %xmm0
jbe 0x31fc4
movq -0x28(%rbp), %rdi
callq 0x325d0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd 0x8f0e8(%rip), %xmm1    # 0xc1030
movsd %xmm1, -0x138(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x116b0
movsd %xmm0, -0x130(%rbp)
movq -0x28(%rbp), %rdi
callq 0x325d0
movsd %xmm0, -0x140(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x12a20
movsd (%rax), %xmm0
movsd %xmm0, -0x120(%rbp)
movsd -0x120(%rbp), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0xd0(%rbp)
jmp 0x32071
movq -0x28(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
callq 0x7c940
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movaps 0x8f07d(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x32007
leaq -0x38(%rbp), %rdi
callq 0x1f2e0
cvtsi2sd %eax, %xmm0
mulsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x32011
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x50(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11670
movsd (%rax), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x112c0
movsd %xmm0, -0x150(%rbp)
movsd %xmm1, -0x148(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x32ae0
movl $0x1, -0xd0(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x190(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1d810
movsd -0x190(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x320e7
movq -0x28(%rbp), %rdi
callq 0x1d810
movsd (%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x104e0
movaps %xmm0, %xmm1
movsd -0x198(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x158(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x113f0
leaq -0x78(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x32ae0
movq -0x28(%rbp), %rdi
callq 0x11740
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x113f0
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x32132
movsd -0x30(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x32149
movsd -0x30(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x3215b
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x1a0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b30
movsd -0x1a0(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x321ce
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b50
movsd -0x1a8(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x321ce
callq 0x855e0
movq %rax, %rdi
callq 0x32b70
movsd (%rax), %xmm1
movsd -0x58(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x1b0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b90
movsd -0x1b0(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3223d
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x1b8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32bb0
movsd -0x1b8(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x3223d
callq 0x855e0
movq %rax, %rdi
callq 0x32bf0
movsd (%rax), %xmm1
movsd -0x50(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x1c0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32c10
movsd -0x1c0(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x322a8
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x1c8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32c30
movsd -0x1c8(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x322a8
callq 0x855e0
movq %rax, %rdi
callq 0x32bf0
movsd (%rax), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x1d8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x328b0
movsd -0x1d8(%rbp), %xmm0
mulsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x12a60
movsd (%rax), %xmm0
movsd %xmm0, -0x160(%rbp)
movsd -0x160(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x1d0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32930
movsd -0x1d0(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x3233e
callq 0x855e0
movq %rax, %rdi
callq 0x32930
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x160(%rbp), %xmm1
movsd -0x60(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x32366
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x32368
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x31d49
movl -0xcc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)