// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %r12d, %r12d
movsd 0x15922(%rip), %xmm0    # 0x57040
ucomisd 0x140(%rdi), %xmm0
jbe 0x4174b
ucomisd 0x148(%r14), %xmm0
movl $0x0, %r13d
jbe 0x4174b
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
movsd 0x38(%rbx), %xmm3
movsd 0x40(%rbx), %xmm0
movsd %xmm1, -0x60(%rbp)
subsd %xmm1, %xmm3
movsd %xmm2, -0x58(%rbp)
subsd %xmm2, %xmm0
leaq -0xa0(%rbp), %rdi
movsd %xmm3, (%rdi)
movsd %xmm0, 0x8(%rdi)
mulsd %xmm0, %xmm0
mulsd %xmm3, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x50(%rbp)
callq 0xcd30
movapd 0x1587f(%rip), %xmm1    # 0x57020
movapd %xmm0, -0x80(%rbp)
xorpd %xmm0, %xmm1
movapd %xmm1, -0x90(%rbp)
movl %r12d, %r12d
movq 0x20f8(%rbx), %rax
movq 0x2100(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
seta %r13b
jbe 0x41739
movq (%rax,%r12,8), %r15
cmpb $0x1, 0x112(%r15)
jne 0x417f8
movl 0x11c(%r14), %eax
imull 0x11c(%r15), %eax
testl %eax, %eax
jle 0x417fd
incl %r12d
jmp 0x417b2
cmpl $0x0, 0xc8(%r15)
jg 0x417f8
cmpl $0x0, 0x124(%r15)
jg 0x417f8
cmpb $0x1, 0x128(%r15)
jne 0x417f8
movsd 0x8(%r15), %xmm0
movsd 0x10(%r15), %xmm1
subsd -0x60(%rbp), %xmm0
subsd -0x58(%rbp), %xmm1
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd -0x50(%rbp), %xmm0
ja 0x417f8
movapd -0x90(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xd02c
movapd %xmm1, %xmm2
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x417f8
andpd 0x15784(%rip), %xmm2    # 0x57010
movapd %xmm2, -0x70(%rbp)
movq %r15, %rdi
callq 0x2abf4
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq %r14, %rdi
callq 0x2abf4
movsd -0x48(%rbp), %xmm1
addsd (%rax), %xmm1
movapd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x417f8
movsd 0xb0(%r15), %xmm0
subsd -0x80(%rbp), %xmm0
movabsq $-0x3f99800000000000, %rax # imm = 0xC066800000000000
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xd305
andpd 0x15721(%rip), %xmm0    # 0x57010
ucomisd 0x15791(%rip), %xmm0    # 0x57088
ja 0x417f8
jmp 0x41739