// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/Formation.cpp
// Function: FormationBase::GetExpectedGoaliePos(Vector const&, double, Vector const&, int)
Vector FormationBase::GetExpectedGoaliePos(const Vector &ball_pos, double run,
                                           const Vector &goalie_pos,
                                           int cycle_delay) {
  Vector p[2];
  p[0] = Vector(ServerParam::instance().PITCH_LENGTH / 2.0,
                -ServerParam::instance().goalWidth() / 2.0 + 0.1); // top
  p[1] = Vector(ServerParam::instance().PITCH_LENGTH / 2.0,
                ServerParam::instance().goalWidth() / 2.0 - 0.1); // down

  double tmp, distg;
  distg = ball_pos.Dist(goalie_pos);
  AngleDeg mid;
  mid = GetNormalizeAngleDeg(
      ((p[1] - ball_pos).Dir() + (p[0] - ball_pos).Dir()) / 2); //取角平分线
  tmp = ball_pos.Dist(Vector(ServerParam::instance().PITCH_LENGTH / 2.0, 0.0)) -
        2.0;
  Vector tgPos, jgPos;
  tgPos = ball_pos +
          Polar2Vector(distg, mid); // 估计守门员可能的位置,守门员向角平分线运动
  if (tgPos.Dist(ball_pos) > tmp) {
    tgPos = ball_pos + (tgPos - ball_pos).SetLength(tmp); // 调整到球场内
  }
  if (goalie_pos.Dist(tgPos) < run + cycle_delay * 0.8) {
    jgPos = tgPos; // 守门员向tgpos尽可能运动
  } else {
    jgPos = goalie_pos +
            Polar2Vector(run + cycle_delay * 0.8, (tgPos - goalie_pos).Dir());
  }
  return jgPos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movl %ecx, -0x34(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, -0x1e0(%rbp)
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x68(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x11a10
movq -0x1e8(%rbp), %rax
movq -0x1e0(%rbp), %rcx
addq $0x10, %rax
cmpq %rcx, %rax
movq %rax, -0x1d8(%rbp)
jne 0x38dd8
callq 0x855e0
leaq 0x8b20b(%rip), %rax     # 0xc4038
movsd (%rax), %xmm0
movsd 0x88677(%rip), %xmm1    # 0xc14b0
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x3fcb0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x8863b(%rip), %xmm1    # 0xc14b0
divsd %xmm1, %xmm0
movsd 0x8968f(%rip), %xmm1    # 0xc2510
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x11a10
movq -0x80(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x855e0
leaq 0x8b178(%rip), %rax     # 0xc4038
movsd (%rax), %xmm0
movsd 0x885e4(%rip), %xmm1    # 0xc14b0
divsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x3fcb0
movsd (%rax), %xmm0
movsd 0x885bf(%rip), %xmm1    # 0xc14b0
divsd %xmm1, %xmm0
movsd 0x89613(%rip), %xmm1    # 0xc2510
subsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x11a10
movq -0xa0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1d6d0
movsd %xmm0, -0xc0(%rbp)
leaq -0x60(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0xd8(%rbp)
movsd %xmm1, -0xd0(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x200(%rbp)
leaq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0xe8(%rbp)
movsd %xmm1, -0xe0(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x10520
movaps %xmm0, %xmm1
movsd -0x200(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0x884ed(%rip), %xmm1    # 0xc14b0
divsd %xmm1, %xmm0
movsd 0x88061(%rip), %xmm1    # 0xc1030
movsd %xmm1, -0xf0(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x116b0
movsd %xmm0, -0xc8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x1f8(%rbp)
callq 0x855e0
leaq 0x8b036(%rip), %rax     # 0xc4038
movsd (%rax), %xmm0
movsd 0x884a2(%rip), %xmm1    # 0xc14b0
divsd %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x110(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x11a10
movq -0x1f8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1d6d0
movsd 0x88456(%rip), %xmm1    # 0xc14b0
subsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x128(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x130(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x128(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x11a10
xorps %xmm0, %xmm0
movsd %xmm0, -0x138(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x140(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x11a10
movq -0x20(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x112c0
movq -0x1f0(%rbp), %rdi
movsd %xmm0, -0x160(%rbp)
movsd %xmm1, -0x158(%rbp)
leaq -0x160(%rbp), %rsi
callq 0x11360
movsd %xmm0, -0x150(%rbp)
movsd %xmm1, -0x148(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x1d6d0
ucomisd -0xb8(%rbp), %xmm0
jbe 0x391db
movq -0x20(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x110a0
movsd %xmm0, -0x190(%rbp)
movsd %xmm1, -0x188(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3fcd0
movq -0x208(%rbp), %rdi
movsd %xmm0, -0x180(%rbp)
movsd %xmm1, -0x178(%rbp)
leaq -0x180(%rbp), %rsi
callq 0x11360
movsd %xmm0, -0x170(%rbp)
movsd %xmm1, -0x168(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x1d6d0
movaps %xmm0, %xmm1
movsd -0x28(%rbp), %xmm2
cvtsi2sdl -0x34(%rbp), %xmm0
movsd 0x89318(%rip), %xmm3    # 0xc2518
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x39229
movq -0x120(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x392e6
movq -0x30(%rbp), %rax
movq %rax, -0x210(%rbp)
movsd -0x28(%rbp), %xmm1
cvtsi2sdl -0x34(%rbp), %xmm0
movsd 0x892d2(%rip), %xmm2    # 0xc2518
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1b8(%rbp)
movq -0x30(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x110a0
movsd %xmm0, -0x1d0(%rbp)
movsd %xmm1, -0x1c8(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x1c0(%rbp)
leaq -0x1b8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x112c0
movq -0x210(%rbp), %rdi
movsd %xmm0, -0x1b0(%rbp)
movsd %xmm1, -0x1a8(%rbp)
leaq -0x1b0(%rbp), %rsi
callq 0x11360
movsd %xmm0, -0x1a0(%rbp)
movsd %xmm1, -0x198(%rbp)
movq -0x1a0(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x8(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopl (%rax)