// File: /workspace/github_cpp_makefile_star2_O1/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)
movq %rsi, %rbx
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movsd %xmm3, -0x48(%rbp)
movsd %xmm3, -0x50(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %r14
movslq 0x114(%rbx), %r15
movsd 0x8(%rbx), %xmm0
movsd 0x10(%rbx), %xmm1
subsd -0x40(%rbp), %xmm0
subsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2130b
sqrtsd %xmm0, %xmm0
jmp 0x21310
callq 0x93c0
movsd 0x60(%rbx), %xmm1
addsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2132a
movsd -0x48(%rbp), %xmm2
jmp 0x2156a
movsd 0x8(%rbx), %xmm0
movsd 0x10(%rbx), %xmm1
addsd 0x30(%rbx), %xmm0
addsd 0x38(%rbx), %xmm1
subsd -0x40(%rbp), %xmm0
subsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jb 0x21364
sqrtsd %xmm0, %xmm0
jmp 0x2136d
callq 0x93c0
xorpd %xmm2, %xmm2
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x2156a
imulq $0x3700, %r15, %rax     # imm = 0x3700
leaq (%r14,%rax), %r12
addq $0x3030, %r12           # imm = 0x3030
leaq 0x8(%rbx), %rax
movups (%rax), %xmm0
leaq -0x70(%rbp), %r14
movaps %xmm0, (%r14)
movsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x10(%r14)
leaq -0x98(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2276a
leaq -0x40(%rbp), %rsi
movq %r15, %rdi
callq 0x2282c
movapd %xmm0, %xmm5
subsd 0x8(%rbx), %xmm5
subsd 0x10(%rbx), %xmm1
subsd 0x30(%rbx), %xmm5
subsd 0x38(%rbx), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm2, %xmm0
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm0
jb 0x21405
sqrtsd %xmm0, %xmm3
jmp 0x21426
movapd %xmm5, -0x30(%rbp)
movapd %xmm1, -0x80(%rbp)
callq 0x93c0
movapd -0x80(%rbp), %xmm1
movapd -0x30(%rbp), %xmm5
xorpd %xmm4, %xmm4
movapd %xmm0, %xmm3
movsd 0x80(%rbx), %xmm0
mulsd (%r12), %xmm0
divsd %xmm0, %xmm3
movsd %xmm3, -0x70(%rbp)
movapd 0x49bcb(%rip), %xmm0    # 0x6b010
movapd %xmm5, %xmm2
andpd %xmm0, %xmm2
movsd 0x49beb(%rip), %xmm6    # 0x6b040
ucomisd %xmm2, %xmm6
jbe 0x21465
andpd %xmm1, %xmm0
ucomisd %xmm0, %xmm6
ja 0x21490
movapd %xmm1, %xmm0
movapd %xmm5, %xmm1
movapd %xmm3, -0x30(%rbp)
callq 0x90d0
movapd -0x30(%rbp), %xmm3
movapd %xmm0, %xmm4
mulsd 0x49bc0(%rip), %xmm4    # 0x6b048
divsd 0x49bc0(%rip), %xmm4    # 0x6b050
subsd 0xb0(%rbx), %xmm4
movsd 0x49bc0(%rip), %xmm0    # 0x6b060
ucomisd %xmm4, %xmm0
jbe 0x214ba
movsd 0x49bc2(%rip), %xmm1    # 0x6b070
addsd %xmm1, %xmm4
ucomisd %xmm4, %xmm0
ja 0x214ae
jmp 0x214de
ucomisd 0x49b86(%rip), %xmm4    # 0x6b048
jb 0x214de
movsd 0x49b9c(%rip), %xmm0    # 0x6b068
movsd 0x49b74(%rip), %xmm1    # 0x6b048
addsd %xmm0, %xmm4
ucomisd %xmm1, %xmm4
jae 0x214d4
andpd 0x49b2a(%rip), %xmm4    # 0x6b010
ucomisd 0x49bc2(%rip), %xmm4    # 0x6b0b0
jbe 0x214fd
xorpd 0x49b28(%rip), %xmm3    # 0x6b020
movlpd %xmm3, -0x70(%rbp)
callq 0x4a75c
xorpd %xmm0, %xmm0
movsd -0x48(%rbp), %xmm1
movq %rax, %rdx
ucomisd %xmm0, %xmm1
jbe 0x2153e
addq $0x33c8, %rdx           # imm = 0x33C8
movsd -0x70(%rbp), %xmm0
ucomisd 0x33c8(%rax), %xmm0
cmovaq %r14, %rdx
movsd (%rdx), %xmm0
ucomisd %xmm1, %xmm0
leaq -0x50(%rbp), %rcx
cmovbeq %rdx, %rcx
jmp 0x21566
addq $0x33c0, %rdx           # imm = 0x33C0
movsd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
leaq -0x50(%rbp), %rcx
cmovaq %r14, %rcx
movsd (%rcx), %xmm0
ucomisd 0x33c0(%rax), %xmm0
cmovaq %rdx, %rcx
movsd (%rcx), %xmm2
movapd %xmm2, %xmm0
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq