// File: /workspace/github_cpp_makefile_star2_O1/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
movaps %xmm2, -0xd0(%rbp)
movapd %xmm0, %xmm2
movq %rsi, %rbx
movsd 0x78(%rsi), %xmm0
movaps %xmm0, -0x70(%rbp)
movsd 0x80(%rsi), %xmm3
movsd 0x90(%rsi), %xmm4
movsd 0x88(%rsi), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd 0xb0(%rsi), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x8(%rsi), %xmm7
movsd 0x10(%rsi), %xmm8
movsd 0x48(%rsi), %xmm5
movsd 0x30(%rsi), %xmm6
movsd 0x38(%rsi), %xmm9
movapd %xmm7, %xmm0
movsd %xmm2, -0xa8(%rbp)
subsd %xmm2, %xmm0
movapd %xmm8, %xmm2
movsd %xmm1, -0xb0(%rbp)
subsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm3, -0x30(%rbp)
movsd %xmm4, -0x58(%rbp)
jb 0x21fa4
sqrtsd %xmm0, %xmm0
jmp 0x21feb
movapd %xmm5, -0x80(%rbp)
movsd %xmm7, -0x38(%rbp)
movsd %xmm8, -0x90(%rbp)
movsd %xmm6, -0x88(%rbp)
movapd %xmm9, -0x50(%rbp)
callq 0x93c0
movapd -0x50(%rbp), %xmm9
movsd -0x88(%rbp), %xmm6
movsd -0x90(%rbp), %xmm8
movsd -0x38(%rbp), %xmm7
movapd -0x80(%rbp), %xmm5
divsd 0x60(%rbx), %xmm0
addsd 0x49738(%rip), %xmm0    # 0x6b730
cvttsd2si %xmm0, %r14d
testl %r14d, %r14d
jle 0x226c8
movsd 0x49032(%rip), %xmm0    # 0x6b040
ucomisd %xmm5, %xmm0
cmpltsd %xmm0, %xmm5
andnpd %xmm9, %xmm5
xorpd %xmm2, %xmm2
ja 0x22026
movapd %xmm6, %xmm2
xorl %r13d, %r13d
leaq -0xe0(%rbp), %r12
xorl %r15d, %r15d
movapd %xmm8, %xmm4
movapd %xmm7, %xmm3
movsd %xmm4, -0x98(%rbp)
movsd %xmm3, -0xb8(%rbp)
movapd %xmm7, %xmm0
movapd %xmm8, %xmm1
movsd %xmm7, -0x90(%rbp)
subsd -0xa8(%rbp), %xmm0
movsd %xmm8, -0x88(%rbp)
subsd -0xb0(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x49006(%rip), %xmm0    # 0x6b090
movapd %xmm5, -0x80(%rbp)
movsd %xmm2, -0x38(%rbp)
movsd %xmm0, -0xd8(%rbp)
jb 0x220a4
sqrtsd %xmm0, %xmm0
jmp 0x220a9
callq 0x93c0
movsd %xmm0, -0x50(%rbp)
callq 0x450ba
movsd 0x5c68(%rax), %xmm0
ucomisd -0x50(%rbp), %xmm0
ja 0x226cb
movsd -0xd8(%rbp), %xmm0
ucomisd 0x48fba(%rip), %xmm0    # 0x6b090
jb 0x220e1
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x220ea
callq 0x93c0
movapd %xmm0, %xmm2
movsd -0xb8(%rbp), %xmm0
subsd -0xa8(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
subsd -0xb0(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x48f72(%rip), %xmm0    # 0x6b090
jb 0x22126
sqrtsd %xmm0, %xmm0
jmp 0x22135
movsd %xmm2, -0x50(%rbp)
callq 0x93c0
movsd -0x50(%rbp), %xmm2
movsd 0x48f23(%rip), %xmm5    # 0x6b060
movsd 0x48f23(%rip), %xmm6    # 0x6b068
addsd 0x48ef3(%rip), %xmm0    # 0x6b040
cmpl $0x1, %r15d
jne 0x2215d
ucomisd %xmm0, %xmm2
ja 0x226cb
movapd -0xd0(%rbp), %xmm0
ucomisd 0x48f23(%rip), %xmm0    # 0x6b090
movsd -0xa8(%rbp), %xmm1
subsd -0x90(%rbp), %xmm1
movsd -0xb0(%rbp), %xmm2
subsd -0x88(%rbp), %xmm2
movapd %xmm1, %xmm0
movapd 0x48e77(%rip), %xmm4    # 0x6b010
andpd %xmm4, %xmm0
movapd %xmm2, %xmm3
andpd %xmm4, %xmm3
movsd 0x48e93(%rip), %xmm4    # 0x6b040
cmpltpd %xmm4, %xmm0
cmpltpd %xmm4, %xmm3
andpd %xmm0, %xmm3
movd %xmm3, %eax
xorpd %xmm0, %xmm0
jbe 0x22209
testb $0x1, %al
jne 0x221f2
movapd %xmm2, %xmm0
callq 0x90d0
movsd 0x48e8e(%rip), %xmm6    # 0x6b068
movsd 0x48e7e(%rip), %xmm5    # 0x6b060
mulsd 0x48e5e(%rip), %xmm0    # 0x6b048
divsd 0x48e5e(%rip), %xmm0    # 0x6b050
subsd -0x60(%rbp), %xmm0
movsd 0x48e49(%rip), %xmm2    # 0x6b048
movsd 0x48e69(%rip), %xmm4    # 0x6b070
jmp 0x22263
testb $0x1, %al
jne 0x22236
movapd %xmm2, %xmm0
callq 0x90d0
movsd 0x48e4a(%rip), %xmm6    # 0x6b068
movsd 0x48e3a(%rip), %xmm5    # 0x6b060
mulsd 0x48e1a(%rip), %xmm0    # 0x6b048
divsd 0x48e1a(%rip), %xmm0    # 0x6b050
movsd -0x60(%rbp), %xmm1
movsd 0x48e05(%rip), %xmm2    # 0x6b048
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm5
movsd 0x48e1d(%rip), %xmm4    # 0x6b070
jbe 0x22279
addsd %xmm4, %xmm1
ucomisd %xmm1, %xmm5
ja 0x22255
subsd %xmm1, %xmm0
ucomisd %xmm0, %xmm5
jbe 0x22285
movapd %xmm0, %xmm1
addsd %xmm4, %xmm1
ucomisd %xmm1, %xmm5
ja 0x2226d
jmp 0x2229d
ucomisd %xmm2, %xmm1
jb 0x2225f
addsd %xmm6, %xmm1
jmp 0x22279
ucomisd %xmm2, %xmm0
movapd %xmm0, %xmm1
jb 0x2229d
movapd %xmm0, %xmm1
addsd %xmm6, %xmm1
ucomisd %xmm2, %xmm1
jae 0x22293
movapd 0x48d6b(%rip), %xmm3    # 0x6b010
andpd %xmm3, %xmm1
ucomisd 0x4a077(%rip), %xmm1    # 0x6c328
jbe 0x2230b
ucomisd %xmm0, %xmm5
movapd -0x80(%rbp), %xmm3
jbe 0x222ff
addsd %xmm4, %xmm0
ucomisd %xmm0, %xmm5
ja 0x222be
movsd 0x158(%rbx), %xmm1
movapd %xmm1, %xmm2
xorpd 0x48d44(%rip), %xmm2    # 0x6b020
maxsd %xmm2, %xmm0
minsd %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
xorl %r15d, %r15d
movsd -0x38(%rbp), %xmm1
jmp 0x223f6
ucomisd %xmm2, %xmm0
jb 0x222c8
addsd %xmm6, %xmm0
jmp 0x222ff
movq %rbx, %rdi
movapd -0xd0(%rbp), %xmm0
callq 0x470e2
movapd %xmm0, %xmm1
andpd 0x48ce9(%rip), %xmm1    # 0x6b010
movapd -0x70(%rbp), %xmm5
movapd %xmm5, %xmm2
xorpd 0x48ce8(%rip), %xmm2    # 0x6b020
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, -0x50(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movapd -0x50(%rbp), %xmm0
mulsd 0x3030(%rax,%rcx), %xmm0
movapd %xmm0, -0x50(%rbp)
movsd -0x60(%rbp), %xmm0
mulsd 0x48ca6(%rip), %xmm0    # 0x6b050
divsd 0x48c96(%rip), %xmm0    # 0x6b048
leaq -0xe8(%rbp), %rdi
movq %r12, %rsi
callq 0x92d0
movsd -0xe0(%rbp), %xmm0
movapd -0x50(%rbp), %xmm1
mulsd %xmm1, %xmm0
mulsd -0xe8(%rbp), %xmm1
movapd %xmm1, %xmm2
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
movapd -0x80(%rbp), %xmm3
addsd %xmm2, %xmm3
movl $0x1, %r15d
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
ucomisd 0x48c7e(%rip), %xmm2    # 0x6b090
movapd %xmm3, -0x80(%rbp)
movsd %xmm1, -0x38(%rbp)
jb 0x22427
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
jmp 0x2243a
movapd %xmm2, %xmm0
movsd %xmm2, -0x50(%rbp)
callq 0x93c0
movsd -0x50(%rbp), %xmm2
movsd 0x60(%rbx), %xmm3
ucomisd %xmm3, %xmm0
jbe 0x2248b
ucomisd 0x48c43(%rip), %xmm2    # 0x6b090
jb 0x22458
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
jmp 0x2246b
movapd %xmm2, %xmm0
movsd %xmm3, -0x50(%rbp)
callq 0x93c0
movsd -0x50(%rbp), %xmm3
movapd -0x80(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm3
mulsd %xmm3, %xmm2
movsd %xmm2, -0x38(%rbp)
mulsd %xmm3, %xmm1
movapd %xmm1, -0x80(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3020(%rax,%rcx), %xmm0
movsd %xmm0, -0x50(%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 -0x70(%rbp), %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, -0x70(%rbp)
callq 0x4a75c
movsd 0x3438(%rax), %xmm0
ucomisd -0x70(%rbp), %xmm0
jbe 0x22536
callq 0x4a75c
movsd -0x58(%rbp), %xmm0
ucomisd 0x3068(%rax), %xmm0
jbe 0x22536
movsd %xmm0, -0x58(%rbp)
callq 0x4a75c
movsd -0x58(%rbp), %xmm0
subsd 0x3070(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
callq 0x4a75c
movsd 0x3430(%rax), %xmm0
ucomisd -0x70(%rbp), %xmm0
jbe 0x22590
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x30(%rbp), %xmm0
ucomisd 0x3060(%rax,%rcx), %xmm0
jbe 0x22590
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
movsd -0x30(%rbp), %xmm0
subsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
movsd -0x70(%rbp), %xmm0
ucomisd 0x3440(%rax), %xmm0
jbe 0x225ee
callq 0x450ba
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 0x225ee
movsd %xmm1, -0x30(%rbp)
callq 0x4a75c
movsd -0x30(%rbp), %xmm0
addsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%rbx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3018(%rax,%rcx), %xmm0
mulsd -0x58(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
minsd %xmm0, %xmm1
movsd %xmm1, -0x98(%rbp)
movsd -0x70(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
callq 0x4a75c
movsd -0x70(%rbp), %xmm6
ucomisd 0x3048(%rax), %xmm6
jbe 0x22659
callq 0x4a75c
movsd 0x3048(%rax), %xmm6
movsd -0x90(%rbp), %xmm3
movapd %xmm3, %xmm7
movsd -0x38(%rbp), %xmm2
addsd %xmm2, %xmm7
movsd -0x88(%rbp), %xmm4
movapd %xmm4, %xmm8
movapd -0x80(%rbp), %xmm5
addsd %xmm5, %xmm8
movsd -0x50(%rbp), %xmm0
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm5
movsd -0xa0(%rbp), %xmm1
subsd -0x98(%rbp), %xmm1
xorpd %xmm0, %xmm0
maxsd %xmm1, %xmm0
incl %r13d
movapd %xmm6, -0x70(%rbp)
movsd %xmm0, -0xa0(%rbp)
cmpl %r14d, %r13d
jne 0x2203c
movl %r14d, %r13d
jmp 0x226cb
xorl %r13d, %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
nop