// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Dasher.cpp
// Function: Dasher::GoToPointWithCertainPosture(Agent&, AtomicAction&, Vector, double, double, bool, bool)
void Dasher::GoToPointWithCertainPosture(Agent &agent, AtomicAction &act,
                                         Vector target, double buffer,
                                         double power, const bool inverse,
                                         bool turn_first) {
  act.Clear();

  const Vector &my_pre_pos = agent.Self().GetPredictedPos(1);
  double dist = my_pre_pos.Dist(target);
  AngleDeg dirdiff =
      inverse
          ? GetNormalizeAngleDeg((my_pre_pos - target).Dir() -
                                 agent.GetSelf().GetBodyDir())
          : GetNormalizeAngleDeg((target - my_pre_pos).Dir() -
                                 agent.GetSelf().GetBodyDir()); //需要转身的角度

  double bufang;

  buffer = Max(0.05, buffer); // TODO: wait test

  if (buffer > FLOAT_EPS) {
    bufang = ASin(buffer / dist / 2) * 2;
    bufang = Max(10.0, bufang);
  } else {
    bufang = 0.0;
  }

  if (fabs(dirdiff) > bufang) {
    TurnDashPlaning(agent, act, target, buffer, power, inverse, turn_first);
  } else {
    power = inverse ? -fabs(power) : fabs(power);
    power = agent.GetSelf().CorrectDashPowerForStamina(power);
    if (fabs(power) > FLOAT_EPS) {
      act.mType = CT_Dash;
      act.mDashPower = AdjustPowerForDash(agent.Self(), target, buffer, power);
      act.mDashPower =
          agent.GetSelf().CorrectDashPowerForStamina(act.mDashPower);
      if (fabs(act.mDashPower) > FLOAT_EPS) {
        act.mSucceed = true;
      } else {
        act.mType = CT_None; // power为零时就不要执行了，没意义
        TurnDashPlaning(agent, act, target, buffer, power, inverse,
                        turn_first); //再次考虑转身，以免漏掉一线好的转身的机会
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %r14d
movl %ecx, %r12d
movaps %xmm3, -0x50(%rbp)
movsd %xmm2, -0x30(%rbp)
movsd %xmm1, -0x40(%rbp)
movsd %xmm0, -0x38(%rbp)
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r13
movb $0x0, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rdx)
movups %xmm0, 0x14(%rdx)
movups %xmm0, 0x20(%rdx)
movq %rsi, %rdi
callq 0x10d5e
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0xd4c0
movsd -0x40(%rbp), %xmm5
movsd -0x38(%rbp), %xmm2
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm0
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
movapd %xmm0, %xmm4
subsd %xmm5, %xmm4
testl %r12d, %r12d
movsd %xmm3, -0x70(%rbp)
movsd %xmm4, -0x68(%rbp)
je 0x1b13c
leaq -0x88(%rbp), %rdi
movsd %xmm3, (%rdi)
movsd %xmm4, 0x8(%rdi)
jmp 0x1b158
subsd %xmm1, %xmm2
movapd %xmm5, %xmm1
subsd %xmm0, %xmm1
leaq -0x88(%rbp), %rdi
movsd %xmm2, (%rdi)
movsd %xmm1, 0x8(%rdi)
callq 0xcd30
movsd %xmm0, -0x60(%rbp)
movq %r15, %rdi
callq 0xcd42
movsd -0x60(%rbp), %xmm0
subsd 0xb0(%rax), %xmm0
movabsq $-0x3f99800000000000, %rax # imm = 0xC066800000000000
leaq -0x78(%rbp), %rdi
movq %rax, (%rdi)
callq 0xd305
movapd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm2
maxsd 0x3d0fa(%rip), %xmm2    # 0x58298
xorpd %xmm0, %xmm0
ucomisd 0x3be96(%rip), %xmm2    # 0x57040
movsd %xmm2, -0x30(%rbp)
jbe 0x1b206
movapd %xmm1, -0x60(%rbp)
movsd -0x68(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x70(%rbp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
mulsd 0x3c668(%rip), %xmm1    # 0x57848
leaq -0x88(%rbp), %rdi
movsd %xmm1, (%rdi)
callq 0x1cba1
movapd -0x60(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
addsd %xmm0, %xmm0
maxsd 0x3c522(%rip), %xmm0    # 0x57728
andpd 0x3be02(%rip), %xmm1    # 0x57010
ucomisd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm1
movaps -0x50(%rbp), %xmm3
jbe 0x1b23d
movzbl %r12b, %ecx
movzbl %r14b, %r8d
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movsd -0x38(%rbp), %xmm0
callq 0x1b320
jmp 0x1b2e4
testb %r12b, %r12b
jne 0x1b24b
andps 0x3bdc7(%rip), %xmm3    # 0x57010
jmp 0x1b252
orps 0x3bdce(%rip), %xmm3    # 0x57020
movaps %xmm3, -0x50(%rbp)
movq %r15, %rdi
callq 0xcd42
movq %rax, %rdi
movapd -0x50(%rbp), %xmm0
callq 0x3a8ce
movapd %xmm0, -0x50(%rbp)
movapd 0x3bd98(%rip), %xmm1    # 0x57010
andpd %xmm0, %xmm1
ucomisd 0x3bdbc(%rip), %xmm1    # 0x57040
jbe 0x1b2e4
movl $0x2, 0x4(%rbx)
movq %r15, %rdi
callq 0x10d5e
movq %rax, %rsi
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movaps -0x50(%rbp), %xmm3
callq 0x1bb22
movsd %xmm0, 0x20(%rbx)
movq %r15, %rdi
callq 0xcd42
movsd 0x20(%rbx), %xmm0
movq %rax, %rdi
callq 0x3a8ce
movsd %xmm0, 0x20(%rbx)
andpd 0x3bd39(%rip), %xmm0    # 0x57010
ucomisd 0x3bd61(%rip), %xmm0    # 0x57040
jbe 0x1b2f3
movb $0x1, (%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, 0x4(%rbx)
movzbl %r12b, %ecx
movzbl %r14b, %r8d
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movaps -0x50(%rbp), %xmm3
jmp 0x1b233