// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/Dasher.cpp
// Function: Dasher::GetPowerForForwardDash(Agent const&, double*, Vector, double, double, int)
bool Dasher::GetPowerForForwardDash(const Agent &agent, double *dash_power,
                                    Vector posRelTo, double angBody,
                                    double dEffort, int iCycles) {
  // the distance desired is the x-direction to the relative position we
  // we want to move to. If point lies far away, we dash maximal. Furthermore
  // we subtract the x contribution of the velocity because it is not necessary
  // to dash maximal.
  if (!dash_power) {
    return false;
  }
  double dDist = posRelTo.Rotate(-angBody).X(); // get distance in direction

  if (iCycles <= 0)
    iCycles = 1;
  double dAcc = dDist * (1 - agent.GetSelf().GetPlayerDecay()) /
                (1 - pow(agent.GetSelf().GetPlayerDecay(),
                         iCycles)); // get the first Geom
  // get speed to travel now
  if (dAcc > agent.GetSelf().GetEffectiveSpeedMax()) // if too far away
  {
    dAcc = agent.GetSelf().GetEffectiveSpeedMax(); // set maximum speed
  }
  // dAcc -= vel.rotate(-angBody).x;             // subtract current velocity

  // acceleration = dash_power * dash_power_rate * effort ->
  // dash_power = acceleration / (dash_power_rate * effort )
  double dDashPower = dAcc / (agent.GetSelf().GetDashPowerRate() * dEffort);
  if (dDashPower > ServerParam::instance().maxDashPower()) {
    *dash_power = ServerParam::instance().maxDashPower();
    return false;
  } else if (dDashPower < ServerParam::instance().minDashPower()) {
    *dash_power = ServerParam::instance().minDashPower();
    return false;
  } else {
    *dash_power = dDashPower;
    return true;
  }
}

// Assembly:
testq %rdx, %rdx
je 0x214b7
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r15d
movq %rdx, %rbx
movq %rsi, %r14
movsd %xmm3, -0x38(%rbp)
mulsd 0x47d68(%rip), %xmm2    # 0x690a0
divsd 0x47d08(%rip), %xmm2    # 0x69048
leaq -0x50(%rbp), %r12
leaq -0x48(%rbp), %r13
movsd %xmm0, -0x30(%rbp)
movapd %xmm2, %xmm0
movq %r12, %rdi
movq %r13, %rsi
movsd %xmm1, -0x40(%rbp)
callq 0x92d0
movsd -0x40(%rbp), %xmm1
mulsd (%r12), %xmm1
movsd -0x30(%rbp), %xmm0
mulsd (%r13), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
cmpl $0x2, %r15d
movl $0x1, %r12d
cmovgel %r15d, %r12d
movq %r14, %rdi
callq 0xe75a
movq %rax, %r15
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r15), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x47c9d(%rip), %xmm0    # 0x69058
subsd 0x3020(%rax,%rcx), %xmm0
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r14, %rdi
callq 0xe75a
movq %rax, %r15
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r15), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3020(%rax,%rcx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
callq 0x98a0
movsd 0x47c47(%rip), %xmm1    # 0x69058
subsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r14, %rdi
callq 0xe75a
movsd -0x30(%rbp), %xmm0
ucomisd 0x60(%rax), %xmm0
jbe 0x21444
movq %r14, %rdi
callq 0xe75a
movsd 0x60(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r14, %rdi
callq 0xe75a
movq %rax, %r14
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x38(%rbp), %xmm0
mulsd 0x3030(%rax,%rcx), %xmm0
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x49360
movsd 0x33c0(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x49360
movsd -0x30(%rbp), %xmm1
ucomisd -0x38(%rbp), %xmm1
jbe 0x214ba
movsd 0x33c0(%rax), %xmm1
jmp 0x214d7
xorl %eax, %eax
retq
movsd 0x33c8(%rax), %xmm0
movb $0x1, %al
ucomisd %xmm1, %xmm0
jbe 0x214d9
callq 0x49360
movsd 0x33c8(%rax), %xmm1
xorl %eax, %eax
movsd %xmm1, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq