// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movsd %xmm2, -0x40(%rbp)
movsd %xmm1, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
movq %rsi, %rbx
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
movsd %xmm3, -0x48(%rbp)
movsd %xmm3, -0x50(%rbp)
movq %rsi, %rdi
callq 0xd2d2
movsd -0x60(%rbp), %xmm6
movsd -0x58(%rbp), %xmm5
movsd -0x40(%rbp), %xmm4
movsd 0x8(%rbx), %xmm0
movsd 0x10(%rbx), %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(%rbx), %xmm3
addsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x1bbb6
movsd -0x48(%rbp), %xmm0
jmp 0x1bd35
addsd 0x30(%rbx), %xmm0
addsd 0x38(%rbx), %xmm1
subsd %xmm6, %xmm0
subsd %xmm5, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm4
ja 0x1bd35
movq %rax, %r14
leaq 0x8(%rbx), %rax
leaq 0xb0(%rbx), %r15
movups (%rax), %xmm0
leaq -0x90(%rbp), %r12
movaps %xmm0, (%r12)
movsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x10(%r12)
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1cc46
leaq -0x70(%rbp), %rsi
movq %r13, %rdi
callq 0x1ccb4
subsd 0x8(%rbx), %xmm0
subsd 0x10(%rbx), %xmm1
subsd 0x30(%rbx), %xmm0
subsd 0x38(%rbx), %xmm1
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm1
movsd 0x80(%rbx), %xmm0
mulsd (%r14), %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, -0x40(%rbp)
movsd %xmm1, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xcd30
leaq -0x78(%rbp), %rdi
movsd %xmm0, (%rdi)
movq %r15, %rsi
callq 0x124e1
ucomisd 0x3b3e8(%rip), %xmm0    # 0x57088
jbe 0x1bcb9
movapd -0x40(%rbp), %xmm0
xorpd 0x3b371(%rip), %xmm0    # 0x57020
movapd %xmm0, -0x40(%rbp)
movlpd %xmm0, -0x30(%rbp)
callq 0x3db2c
xorpd %xmm0, %xmm0
movsd -0x48(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1bd02
movq %rax, %rcx
addq $0x33c8, %rcx           # imm = 0x33C8
movsd 0x33c8(%rax), %xmm0
movapd -0x40(%rbp), %xmm2
ucomisd %xmm0, %xmm2
leaq -0x30(%rbp), %rax
cmovbeq %rcx, %rax
maxsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
leaq -0x50(%rbp), %rcx
cmovbeq %rax, %rcx
jmp 0x1bd31
movq %rax, %rdx
addq $0x33c0, %rdx           # imm = 0x33C0
movapd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
leaq -0x30(%rbp), %rsi
leaq -0x50(%rbp), %rcx
cmovaq %rsi, %rcx
maxsd %xmm1, %xmm0
ucomisd 0x33c0(%rax), %xmm0
cmovaq %rdx, %rcx
movsd (%rcx), %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop