// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
testq %rdx, %rdx
je 0x1c16a
movl %ecx, %r15d
movq %rdx, %rbx
movq %rsi, %r14
movsd %xmm3, -0x30(%rbp)
xorps 0x3afaf(%rip), %xmm2    # 0x57020
leaq -0x48(%rbp), %rsi
movlps %xmm2, (%rsi)
leaq -0x40(%rbp), %rdi
callq 0xd02c
movsd %xmm0, -0x28(%rbp)
cmpl $0x2, %r15d
pushq $0x1
popq %r12
cmovgel %r15d, %r12d
movq %r14, %rdi
callq 0xcd42
movq %rax, %rdi
callq 0xd344
movsd 0x3af9e(%rip), %xmm0    # 0x57048
subsd (%rax), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movq %r14, %rdi
callq 0xcd42
movq %rax, %rdi
callq 0xd344
movsd (%rax), %xmm0
cvtsi2sd %r12d, %xmm1
callq 0x98a0
movsd 0x3af6a(%rip), %xmm1    # 0x57048
subsd %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq %r14, %rdi
callq 0xcd42
movsd -0x28(%rbp), %xmm0
ucomisd 0x60(%rax), %xmm0
jbe 0x1c111
movq %r14, %rdi
callq 0xcd42
movsd 0x60(%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movq %r14, %rdi
callq 0xcd42
movq %rax, %rdi
callq 0xd2d2
movsd -0x30(%rbp), %xmm0
mulsd (%rax), %xmm0
movsd -0x28(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x28(%rbp)
callq 0x3db2c
movsd 0x33c0(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
movsd -0x28(%rbp), %xmm1
ucomisd -0x30(%rbp), %xmm1
jbe 0x1c16e
movsd 0x33c0(%rax), %xmm1
jmp 0x1c18b
xorl %eax, %eax
jmp 0x1c191
movsd 0x33c8(%rax), %xmm0
movb $0x1, %al
ucomisd %xmm1, %xmm0
jbe 0x1c18d
callq 0x3db2c
movsd 0x33c8(%rax), %xmm1
xorl %eax, %eax
movsd %xmm1, (%rbx)
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq