// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movsd 0x8(%rsi), %xmm6
movsd 0x10(%rsi), %xmm5
movapd %xmm6, %xmm3
movsd %xmm0, -0x80(%rbp)
subsd %xmm0, %xmm3
movapd %xmm5, %xmm4
movsd %xmm1, -0x88(%rbp)
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
divsd 0x60(%rsi), %xmm3
addsd 0x47e3c(%rip), %xmm3    # 0x69730
movapd %xmm2, -0xd0(%rbp)
cvttsd2si %xmm3, %r14d
testl %r14d, %r14d
jle 0x21ffe
movq %rsi, %rbx
movsd 0x48(%rsi), %xmm3
movsd 0x47726(%rip), %xmm0    # 0x69040
ucomisd %xmm3, %xmm0
cmpltsd %xmm0, %xmm3
movsd 0x38(%rsi), %xmm2
andnpd %xmm2, %xmm3
xorpd %xmm0, %xmm0
ja 0x21937
movsd 0x30(%rbx), %xmm0
movsd 0xb0(%rbx), %xmm1
movsd %xmm1, -0x48(%rbp)
movsd 0x88(%rbx), %xmm1
movsd %xmm1, -0x90(%rbp)
movsd 0x90(%rbx), %xmm1
movsd %xmm1, -0x40(%rbp)
movsd 0x80(%rbx), %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0x78(%rbx), %xmm1
movaps %xmm1, -0x60(%rbp)
xorl %r13d, %r13d
leaq -0xe8(%rbp), %r12
xorl %r15d, %r15d
movapd %xmm5, %xmm7
movapd %xmm6, %xmm4
movsd -0x88(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
movsd %xmm4, -0x78(%rbp)
movsd %xmm7, -0xc0(%rbp)
movapd %xmm3, -0xa0(%rbp)
movsd %xmm0, -0x38(%rbp)
movapd %xmm6, %xmm0
movsd %xmm6, -0xb0(%rbp)
subsd %xmm1, %xmm0
movsd %xmm5, -0xa8(%rbp)
movapd %xmm5, %xmm1
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
callq 0x43dce
movsd -0x70(%rbp), %xmm4
movsd 0x5c68(%rax), %xmm0
ucomisd %xmm4, %xmm0
ja 0x22006
movsd -0x78(%rbp), %xmm1
movsd -0x80(%rbp), %xmm3
subsd %xmm3, %xmm1
movsd -0xc0(%rbp), %xmm0
movsd -0x88(%rbp), %xmm2
subsd %xmm2, %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
addsd 0x475ff(%rip), %xmm0    # 0x69040
ucomisd %xmm0, %xmm4
seta %al
cmpl $0x1, %r15d
sete %cl
testb %cl, %al
jne 0x22006
movapd %xmm3, %xmm1
movapd -0xd0(%rbp), %xmm0
ucomisd 0x47625(%rip), %xmm0    # 0x69090
subsd -0xb0(%rbp), %xmm1
subsd -0xa8(%rbp), %xmm2
movapd %xmm1, %xmm0
movapd 0x47589(%rip), %xmm4    # 0x69010
andpd %xmm4, %xmm0
movapd %xmm2, %xmm3
andpd %xmm4, %xmm3
movsd 0x475a5(%rip), %xmm4    # 0x69040
cmpltpd %xmm4, %xmm0
cmpltpd %xmm4, %xmm3
andpd %xmm0, %xmm3
movd %xmm3, %eax
xorpd %xmm0, %xmm0
jbe 0x21b06
testb $0x1, %al
movsd 0x4758b(%rip), %xmm4    # 0x69048
jne 0x21adc
movapd %xmm2, %xmm0
callq 0x90d0
movsd 0x47578(%rip), %xmm4    # 0x69048
mulsd %xmm4, %xmm0
divsd 0x47574(%rip), %xmm0    # 0x69050
subsd -0x48(%rbp), %xmm0
movsd 0x47577(%rip), %xmm5    # 0x69060
movsd 0x4757f(%rip), %xmm6    # 0x69070
movapd 0x47517(%rip), %xmm2    # 0x69010
movsd 0x47567(%rip), %xmm7    # 0x69068
jmp 0x21b86
testb $0x1, %al
movsd 0x47538(%rip), %xmm4    # 0x69048
jne 0x21b2f
movapd %xmm2, %xmm0
callq 0x90d0
movsd 0x47525(%rip), %xmm4    # 0x69048
mulsd %xmm4, %xmm0
divsd 0x47521(%rip), %xmm0    # 0x69050
movsd -0x48(%rbp), %xmm1
addsd %xmm4, %xmm1
movsd 0x47520(%rip), %xmm5    # 0x69060
ucomisd %xmm1, %xmm5
movsd 0x47524(%rip), %xmm6    # 0x69070
movsd 0x47514(%rip), %xmm7    # 0x69068
jbe 0x21b6a
movapd 0x474b2(%rip), %xmm2    # 0x69010
addsd %xmm6, %xmm1
ucomisd %xmm1, %xmm5
ja 0x21b5e
jmp 0x21b82
ucomisd %xmm4, %xmm1
movapd 0x4749a(%rip), %xmm2    # 0x69010
jb 0x21b82
addsd %xmm7, %xmm1
ucomisd %xmm4, %xmm1
jae 0x21b78
subsd %xmm1, %xmm0
ucomisd %xmm0, %xmm5
jbe 0x21b9c
movapd %xmm0, %xmm1
addsd %xmm6, %xmm1
ucomisd %xmm1, %xmm5
ja 0x21b90
jmp 0x21bdf
ucomisd %xmm4, %xmm0
jae 0x21bd1
movapd %xmm0, %xmm1
andpd %xmm2, %xmm1
ucomisd 0x48766(%rip), %xmm1    # 0x6a318
jbe 0x21c40
movsd 0x158(%rbx), %xmm1
movapd %xmm1, %xmm2
xorpd 0x47454(%rip), %xmm2    # 0x69020
jmp 0x21fe9
movapd %xmm0, %xmm1
addsd %xmm7, %xmm1
ucomisd %xmm4, %xmm1
jae 0x21bd5
andpd %xmm2, %xmm1
ucomisd 0x4872d(%rip), %xmm1    # 0x6a318
jbe 0x21c40
ucomisd %xmm0, %xmm5
movsd 0x158(%rbx), %xmm1
movapd %xmm1, %xmm2
xorpd 0x4741b(%rip), %xmm2    # 0x69020
jbe 0x21fe9
movsd -0x38(%rbp), %xmm3
addsd %xmm6, %xmm0
ucomisd %xmm0, %xmm5
ja 0x21c10
movapd -0xa0(%rbp), %xmm4
maxsd %xmm2, %xmm0
minsd %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
xorl %r15d, %r15d
jmp 0x21d2a
movq %rbx, %rdi
movapd -0xd0(%rbp), %xmm0
callq 0x45d84
movapd %xmm0, %xmm1
andpd 0x473b4(%rip), %xmm1    # 0x69010
movapd -0x60(%rbp), %xmm5
movapd %xmm5, %xmm2
xorpd 0x473b3(%rip), %xmm2    # 0x69020
xorpd %xmm3, %xmm3
cmplesd %xmm0, %xmm3
movapd %xmm3, %xmm4
andpd %xmm5, %xmm4
andnpd %xmm2, %xmm3
orpd %xmm4, %xmm3
cmpltsd %xmm1, %xmm5
movapd %xmm5, %xmm1
andnpd %xmm0, %xmm1
andpd %xmm3, %xmm5
orpd %xmm1, %xmm5
mulsd -0x30(%rbp), %xmm5
movapd %xmm5, -0x70(%rbp)
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movapd -0x70(%rbp), %xmm0
mulsd 0x3030(%rax,%rcx), %xmm0
movapd %xmm0, -0x70(%rbp)
movsd -0x48(%rbp), %xmm0
mulsd 0x47371(%rip), %xmm0    # 0x69050
divsd 0x47361(%rip), %xmm0    # 0x69048
leaq -0xf0(%rbp), %rdi
movq %r12, %rsi
callq 0x92d0
movsd -0xe8(%rbp), %xmm0
movapd -0x70(%rbp), %xmm1
mulsd %xmm1, %xmm0
mulsd -0xf0(%rbp), %xmm1
movsd -0x38(%rbp), %xmm3
addsd %xmm0, %xmm3
movapd -0xa0(%rbp), %xmm4
addsd %xmm1, %xmm4
movl $0x1, %r15d
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm1
movsd 0x60(%rbx), %xmm0
ucomisd %xmm0, %xmm1
movapd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x78(%rbp)
divsd %xmm1, %xmm0
movapd %xmm4, -0xa0(%rbp)
movapd %xmm0, -0xc0(%rbp)
jbe 0x21d6f
mulsd %xmm0, %xmm3
movsd %xmm3, -0x38(%rbp)
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3020(%rax,%rcx), %xmm0
movsd %xmm0, -0xe0(%rbp)
movapd -0xd0(%rbp), %xmm3
movapd %xmm3, %xmm0
addsd %xmm3, %xmm0
xorpd %xmm1, %xmm1
cmpltsd %xmm3, %xmm1
movapd %xmm1, %xmm2
andpd %xmm3, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movapd -0x60(%rbp), %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, -0x60(%rbp)
callq 0x49360
movsd 0x3438(%rax), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x21e22
callq 0x49360
movsd -0x40(%rbp), %xmm0
ucomisd 0x3068(%rax), %xmm0
jbe 0x21e22
movsd %xmm0, -0x40(%rbp)
callq 0x49360
movsd -0x40(%rbp), %xmm0
subsd 0x3070(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x49360
movsd 0x3430(%rax), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x21e7c
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x30(%rbp), %xmm0
ucomisd 0x3060(%rax,%rcx), %xmm0
jbe 0x21e7c
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movsd -0x30(%rbp), %xmm0
subsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movsd -0x60(%rbp), %xmm0
ucomisd 0x3440(%rax), %xmm0
jbe 0x21eda
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3058(%rax,%rcx), %xmm0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x21eda
movsd %xmm1, -0x30(%rbp)
callq 0x49360
movsd -0x30(%rbp), %xmm0
addsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3018(%rax,%rcx), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
minsd %xmm0, %xmm1
movsd %xmm1, -0xd8(%rbp)
movsd -0x60(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
callq 0x49360
movsd -0x60(%rbp), %xmm8
ucomisd 0x3048(%rax), %xmm8
jbe 0x21f48
callq 0x49360
movsd 0x3048(%rax), %xmm8
movapd -0xa0(%rbp), %xmm0
movapd -0xc0(%rbp), %xmm1
mulsd %xmm0, %xmm1
movapd -0x70(%rbp), %xmm3
cmpltsd -0x78(%rbp), %xmm3
andpd %xmm3, %xmm1
andnpd %xmm0, %xmm3
orpd %xmm1, %xmm3
movsd -0xb0(%rbp), %xmm4
movapd %xmm4, %xmm6
movsd -0x38(%rbp), %xmm0
addsd %xmm0, %xmm6
movsd -0xa8(%rbp), %xmm7
movapd %xmm7, %xmm5
addsd %xmm3, %xmm5
movsd -0xe0(%rbp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm3
movsd -0x90(%rbp), %xmm1
subsd -0xd8(%rbp), %xmm1
xorpd %xmm2, %xmm2
maxsd %xmm1, %xmm2
incl %r13d
movapd %xmm8, -0x60(%rbp)
movsd %xmm2, -0x90(%rbp)
cmpl %r14d, %r13d
movsd -0x88(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
jne 0x21999
jmp 0x22003
movsd -0x38(%rbp), %xmm3
ucomisd %xmm4, %xmm0
jb 0x21c1a
addsd %xmm7, %xmm0
jmp 0x21fee
xorl %r13d, %r13d
jmp 0x22006
movl %r14d, %r13d
cmpl %r14d, %r13d
cmovll %r13d, %r14d
movl %r14d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq