// File: 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
subq $0xf0, %rsp
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movsd %xmm2, -0x30(%rbp)
movsd %xmm3, -0x38(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1d810
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11650
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11670
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a80
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11170
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1d6d0
movq -0x40(%rbp), %rax
movsd (%rax), %xmm1
addsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x30da8
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x30f67
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x11360
movsd %xmm0, -0x78(%rbp)
movsd %xmm1, -0x70(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1d6d0
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x30de7
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x30f67
movq -0x58(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11170
movq -0xf0(%rbp), %rsi
movq %rax, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x1fde0
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x32670
leaq -0x90(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x32800
movsd %xmm0, -0xb8(%rbp)
movsd %xmm1, -0xb0(%rbp)
movq -0x58(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x110a0
movsd %xmm0, -0xd8(%rbp)
movsd %xmm1, -0xd0(%rbp)
movq -0x60(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x110a0
movsd %xmm0, -0xc8(%rbp)
movsd %xmm1, -0xc0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x104e0
movq -0x48(%rbp), %rax
movsd (%rax), %xmm1
movq -0x50(%rbp), %rax
mulsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0xe8(%rbp)
movq -0x68(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x1d7c0
movsd 0x90168(%rip), %xmm1    # 0xc1040
ucomisd %xmm1, %xmm0
jbe 0x30f05
movsd -0xe0(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x30f3e
callq 0x855e0
movq %rax, %rdi
callq 0x12b40
movq %rax, %rdi
leaq -0xe0(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x12a20
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x30f67
callq 0x855e0
movq %rax, %rdi
callq 0x12b60
movq %rax, %rdx
leaq -0x38(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x12a20
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)