// File: 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
subq $0xb0, %rsp
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movsd %xmm2, -0x38(%rbp)
movsd %xmm3, -0x40(%rbp)
movl %ecx, -0x44(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x3147e
movb $0x0, -0x1(%rbp)
jmp 0x3166d
movsd -0x38(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x68(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x176f0
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
cmpl $0x0, -0x44(%rbp)
jg 0x314d5
movl $0x1, -0x44(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10590
movq %rax, %rdi
callq 0x11740
movsd -0x90(%rbp), %xmm0
movsd 0x8fb0d(%rip), %xmm1    # 0xc1010
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10590
movq %rax, %rdi
callq 0x11740
movsd (%rax), %xmm0
cvtsi2sdl -0x44(%rbp), %xmm1
callq 0xaa50
movaps %xmm0, %xmm2
movsd -0x88(%rbp), %xmm0
movsd 0x8facb(%rip), %xmm1    # 0xc1010
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10590
movq %rax, %rdi
callq 0x1d810
movsd -0x80(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x31592
movq -0x28(%rbp), %rdi
callq 0x10590
movq %rax, %rdi
callq 0x1d810
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10590
movq %rax, %rdi
callq 0x11670
movsd -0xa0(%rbp), %xmm0
movsd (%rax), %xmm1
mulsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x12b60
movsd -0x98(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x31611
callq 0x855e0
movq %rax, %rdi
callq 0x12b60
movsd (%rax), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0x3166d
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x12b40
movsd -0xa8(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3165c
callq 0x855e0
movq %rax, %rdi
callq 0x12b40
movsd (%rax), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0x3166d
movsd -0x78(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)