// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/Tackler.cpp
// Function: Tackler::MayDangerousIfTackle(PlayerState const&, WorldState const&)
bool Tackler::MayDangerousIfTackle(const PlayerState &tackler,
                                   const WorldState &world_state) {
  if (tackler.GetTackleProb(false) < FLOAT_EPS &&
      tackler.GetTackleProb(true) < FLOAT_EPS) { //不可铲
    return false;
  }

  const Vector tackler_pos = tackler.GetPos();
  const Vector ball_pos = world_state.GetBall().GetPos();
  const Vector ball_2_tackler = ball_pos - tackler_pos;
  const double ball_dist2 = ball_2_tackler.Mod2();
  const AngleDeg ball_dir = ball_2_tackler.Dir();

  for (unsigned i = 0; i < world_state.GetPlayerList().size(); ++i) {
    const PlayerState &opp = *world_state.GetPlayerList()[i];

    if (!opp.IsAlive())
      continue; // dead
    if (opp.GetUnum() * tackler.GetUnum() > 0)
      continue; // not opp
    if (opp.IsIdling())
      continue; // idling
    if (!opp.IsKickable())
      continue; // not kickable

    // cond. 1. opp no dashing -- 无从知晓，这里认为对手一定会dash
    // cond. 2. ball near -- 球离自己更近，不构成危险情况
    Vector opp_2_tackler = opp.GetPos() - tackler_pos;
    if (opp_2_tackler.Mod2() > ball_dist2)
      continue;
    // cond. 3. behind or big y_diff --
    // 对手在自己与球连线方向上在自己身后或错开位置太大，不构成危险情况
    opp_2_tackler = opp_2_tackler.Rotate(-ball_dir);
    if (opp_2_tackler.X() < 0.0 ||
        std::fabs(opp_2_tackler.Y()) >
            opp.GetPlayerSize() + tackler.GetPlayerSize())
      continue;
    // cond. 4. over body_diff --
    // 对手身体角度跟自己与球连线方向的夹角大于90度，不构成危险情况
    AngleDeg body_diff =
        std::fabs(GetNormalizeAngleDeg(opp.GetBodyDir() - ball_dir));
    if (body_diff > 90.0)
      continue;

    return true;
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x1b8ed(%rip), %xmm4    # 0x69040
ucomisd 0x140(%rdi), %xmm4
jbe 0x4d77d
ucomisd 0x148(%r14), %xmm4
jbe 0x4d77d
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x8(%r14), %xmm3
movsd 0x10(%r14), %xmm2
movsd 0x38(%rbx), %xmm1
movsd 0x40(%rbx), %xmm5
movsd %xmm3, -0x70(%rbp)
subsd %xmm3, %xmm1
movsd %xmm2, -0x68(%rbp)
subsd %xmm2, %xmm5
movapd 0x1b863(%rip), %xmm3    # 0x69010
movapd %xmm1, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm4
jbe 0x4d7c9
andpd %xmm5, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm4
ja 0x4d7f6
movapd %xmm5, %xmm0
movapd %xmm1, -0x50(%rbp)
movapd %xmm5, -0x40(%rbp)
callq 0x90d0
movapd -0x40(%rbp), %xmm5
movapd -0x50(%rbp), %xmm1
mulsd 0x1b85a(%rip), %xmm0    # 0x69048
divsd 0x1b85a(%rip), %xmm0    # 0x69050
movq 0x20f8(%rbx), %rax
xorl %r15d, %r15d
cmpq %rax, 0x2100(%rbx)
je 0x4d76b
mulsd %xmm5, %xmm5
mulsd %xmm1, %xmm1
addsd %xmm5, %xmm1
movsd 0x1b87f(%rip), %xmm2    # 0x690a0
movsd %xmm0, -0x58(%rbp)
mulsd %xmm0, %xmm2
divsd 0x1b816(%rip), %xmm2    # 0x69048
movsd %xmm2, -0x60(%rbp)
leaq -0x78(%rbp), %r13
movq (%rax,%r15,8), %r12
cmpb $0x1, 0x112(%r12)
jne 0x4d85e
movl 0x11c(%r14), %eax
imull 0x11c(%r12), %eax
testl %eax, %eax
jle 0x4d880
incl %r15d
movq 0x20f8(%rbx), %rax
movq 0x2100(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x4d83b
jmp 0x4d768
cmpl $0x0, 0xc8(%r12)
jg 0x4d85e
cmpl $0x0, 0x124(%r12)
jg 0x4d85e
cmpb $0x1, 0x128(%r12)
jne 0x4d85e
movsd 0x8(%r12), %xmm4
movsd 0x10(%r12), %xmm3
subsd -0x70(%rbp), %xmm4
subsd -0x68(%rbp), %xmm3
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
movapd %xmm4, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x4d85e
movsd -0x60(%rbp), %xmm0
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
movapd %xmm1, -0x50(%rbp)
movapd %xmm3, -0x40(%rbp)
movsd %xmm4, -0x30(%rbp)
callq 0x92d0
movsd -0x30(%rbp), %xmm6
movapd -0x40(%rbp), %xmm5
movsd -0x80(%rbp), %xmm4
movsd -0x78(%rbp), %xmm0
movapd %xmm4, %xmm2
mulsd %xmm5, %xmm2
movapd %xmm6, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm1
movapd -0x50(%rbp), %xmm1
ja 0x4d85e
mulsd %xmm4, %xmm6
mulsd %xmm0, %xmm5
addsd %xmm6, %xmm5
andpd 0x1b6ce(%rip), %xmm5    # 0x69010
movapd %xmm5, -0x40(%rbp)
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r12), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3038(%rax,%rcx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x43dce
movapd -0x50(%rbp), %xmm1
movq 0x5c38(%rax), %rax
movslq 0x114(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x30(%rbp), %xmm2
addsd 0x3038(%rax,%rcx), %xmm2
movapd -0x40(%rbp), %xmm0
ucomisd %xmm2, %xmm0
ja 0x4d85e
movsd 0xb0(%r12), %xmm0
subsd -0x58(%rbp), %xmm0
movsd 0x1b69d(%rip), %xmm2    # 0x69060
ucomisd %xmm0, %xmm2
jbe 0x4d9dd
movsd 0x1b69f(%rip), %xmm3    # 0x69070
addsd %xmm3, %xmm0
ucomisd %xmm0, %xmm2
ja 0x4d9d1
jmp 0x4d9fd
movsd 0x1b663(%rip), %xmm2    # 0x69048
ucomisd %xmm2, %xmm0
movsd 0x1b677(%rip), %xmm3    # 0x69068
jb 0x4d9fd
addsd %xmm3, %xmm0
ucomisd %xmm2, %xmm0
jae 0x4d9f3
andpd 0x1b60b(%rip), %xmm0    # 0x69010
ucomisd 0x1b6a3(%rip), %xmm0    # 0x690b0
ja 0x4d85e
movb $0x1, %r15b
jmp 0x4d76b
nop