// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/Dasher.cpp
// Function: Dasher::AdjustPowerForDash(PlayerState const&, Vector, double, double)
double Dasher::AdjustPowerForDash(const PlayerState &player, Vector target,
                                  double buffer, double power) {
  const double &speedmax = player.GetEffectiveSpeedMax();
  const double &effort = player.GetEffort();
  const double &accrate = player.GetDashPowerRate();
  const Vector &pos = player.GetPos();
  const Vector &vel = player.GetVel();

  const double &facing = player.GetBodyDir();

  if (pos.Dist(target) > speedmax + buffer) { //怎么跑的都不会跑过
    return power;
  }

  if ((pos + vel).Dist(target) < buffer) { //不跑也能到到达，就不用跑了
    return 0.0;
  }

  Line dash_line(Ray(pos, player.GetBodyDir()));
  Vector projective_target = dash_line.GetProjectPoint(target);
  Vector acc = projective_target - pos - vel;
  double dash_power = acc.Mod() / (effort * accrate);
  if (GetAngleDegDiffer(acc.Dir(), facing) > 90.0) {
    dash_power = -dash_power;
  }

  if (power > 0) {
    return MinMax(ServerParam::instance().minDashPower(), dash_power, power);
  } else {
    return MinMax(power, dash_power, ServerParam::instance().maxDashPower());
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movsd %xmm2, -0x30(%rbp)
movsd %xmm1, -0x48(%rbp)
movsd %xmm0, -0x50(%rbp)
movq %rsi, %r14
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
movsd %xmm3, -0x38(%rbp)
movsd %xmm3, -0x40(%rbp)
callq 0x43dce
movsd -0x50(%rbp), %xmm6
movsd -0x48(%rbp), %xmm5
movsd -0x30(%rbp), %xmm4
movsd 0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movapd %xmm0, %xmm2
subsd %xmm6, %xmm2
movapd %xmm1, %xmm3
subsd %xmm5, %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
movsd 0x60(%r14), %xmm3
addsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x20d46
movsd -0x38(%rbp), %xmm0
jmp 0x20f57
addsd 0x30(%r14), %xmm0
addsd 0x38(%r14), %xmm1
subsd %xmm6, %xmm0
subsd %xmm5, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm4
ja 0x20f57
movq 0x5c38(%rax), %rax
movslq 0x114(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
leaq (%rax,%rcx), %r12
addq $0x3030, %r12           # imm = 0x3030
leaq 0x8(%r14), %rax
movups (%rax), %xmm0
leaq -0x80(%rbp), %rbx
movaps %xmm0, (%rbx)
movsd 0xb0(%r14), %xmm0
movsd %xmm0, 0x10(%rbx)
leaq -0x98(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x220f2
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x221b4
movapd %xmm0, %xmm2
subsd 0x8(%r14), %xmm2
subsd 0x10(%r14), %xmm1
subsd 0x30(%r14), %xmm2
subsd 0x38(%r14), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movapd %xmm2, %xmm3
mulsd %xmm2, %xmm3
addsd %xmm0, %xmm3
sqrtsd %xmm3, %xmm3
movsd 0x80(%r14), %xmm0
mulsd (%r12), %xmm0
divsd %xmm0, %xmm3
movapd %xmm3, -0x30(%rbp)
movsd %xmm3, (%rbx)
movapd 0x481e3(%rip), %xmm3    # 0x69010
movapd %xmm2, %xmm0
andpd %xmm3, %xmm0
movsd 0x48203(%rip), %xmm4    # 0x69040
ucomisd %xmm0, %xmm4
jbe 0x20e51
andpd %xmm1, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm4
ja 0x20e6e
movapd %xmm1, %xmm0
movapd %xmm2, %xmm1
callq 0x90d0
mulsd 0x481e2(%rip), %xmm0    # 0x69048
divsd 0x481e2(%rip), %xmm0    # 0x69050
subsd 0xb0(%r14), %xmm0
movsd 0x481e1(%rip), %xmm1    # 0x69060
ucomisd %xmm0, %xmm1
jbe 0x20e99
movsd 0x481e3(%rip), %xmm2    # 0x69070
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0x20e8d
jmp 0x20ebd
ucomisd 0x481a7(%rip), %xmm0    # 0x69048
jb 0x20ebd
movsd 0x481bd(%rip), %xmm1    # 0x69068
movsd 0x48195(%rip), %xmm2    # 0x69048
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jae 0x20eb3
andpd 0x4814b(%rip), %xmm0    # 0x69010
ucomisd 0x481e3(%rip), %xmm0    # 0x690b0
jbe 0x20ee6
movapd -0x30(%rbp), %xmm0
xorpd 0x48144(%rip), %xmm0    # 0x69020
movapd %xmm0, -0x30(%rbp)
movlpd %xmm0, -0x80(%rbp)
callq 0x49360
xorpd %xmm0, %xmm0
movsd -0x38(%rbp), %xmm1
movq %rax, %rdx
ucomisd %xmm0, %xmm1
jbe 0x20f2b
addq $0x33c8, %rdx           # imm = 0x33C8
movsd 0x33c8(%rax), %xmm0
movapd -0x30(%rbp), %xmm2
ucomisd %xmm0, %xmm2
cmovaq %rbx, %rdx
maxsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
leaq -0x40(%rbp), %rcx
cmovbeq %rdx, %rcx
jmp 0x20f53
addq $0x33c0, %rdx           # imm = 0x33C0
movapd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
leaq -0x40(%rbp), %rcx
cmovaq %rbx, %rcx
maxsd %xmm1, %xmm0
ucomisd 0x33c0(%rax), %xmm0
cmovaq %rdx, %rcx
movsd (%rcx), %xmm0
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop