// File: /workspace/github_cpp_makefile_star2_O1/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 0x1c281(%rip), %xmm4    # 0x6b040
ucomisd 0x140(%rdi), %xmm4
jbe 0x4eddc
ucomisd 0x148(%r14), %xmm4
jbe 0x4eddc
xorl %r15d, %r15d
jmp 0x4f06e
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 0x1c204(%rip), %xmm3    # 0x6b010
movapd %xmm1, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm4
jbe 0x4ee28
andpd %xmm5, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm4
ja 0x4ee55
movapd %xmm5, %xmm0
movapd %xmm1, -0x50(%rbp)
movapd %xmm5, -0x40(%rbp)
callq 0x90d0
movapd -0x40(%rbp), %xmm5
movapd -0x50(%rbp), %xmm1
mulsd 0x1c1fb(%rip), %xmm0    # 0x6b048
divsd 0x1c1fb(%rip), %xmm0    # 0x6b050
movq 0x20f8(%rbx), %rax
cmpq %rax, 0x2100(%rbx)
setne %r15b
je 0x4f06e
mulsd %xmm5, %xmm5
mulsd %xmm1, %xmm1
addsd %xmm5, %xmm1
movsd 0x1c21f(%rip), %xmm2    # 0x6b0a0
movsd %xmm0, -0x58(%rbp)
mulsd %xmm0, %xmm2
divsd 0x1c1b6(%rip), %xmm2    # 0x6b048
movsd %xmm2, -0x60(%rbp)
xorl %r12d, %r12d
movq (%rax,%r12,8), %r13
cmpb $0x1, 0x112(%r13)
jne 0x4eebb
movl 0x11c(%r14), %eax
imull 0x11c(%r13), %eax
testl %eax, %eax
jle 0x4eee1
incl %r12d
movq 0x20f8(%rbx), %rax
movq 0x2100(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
seta %r15b
ja 0x4ee9a
jmp 0x4f06e
cmpl $0x0, 0xc8(%r13)
jg 0x4eebb
cmpl $0x0, 0x124(%r13)
jg 0x4eebb
cmpb $0x1, 0x128(%r13)
jne 0x4eebb
movsd 0x8(%r13), %xmm4
movsd 0x10(%r13), %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 0x4eebb
movsd -0x60(%rbp), %xmm0
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %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 0x4eebb
mulsd %xmm4, %xmm6
mulsd %xmm0, %xmm5
addsd %xmm6, %xmm5
andpd 0x1c071(%rip), %xmm5    # 0x6b010
movapd %xmm5, -0x40(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%r13), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3038(%rax,%rcx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x450ba
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 0x4eebb
movsd 0xb0(%r13), %xmm0
subsd -0x58(%rbp), %xmm0
movsd 0x1c042(%rip), %xmm2    # 0x6b060
ucomisd %xmm0, %xmm2
jbe 0x4f038
movsd 0x1c044(%rip), %xmm3    # 0x6b070
addsd %xmm3, %xmm0
ucomisd %xmm0, %xmm2
ja 0x4f02c
jmp 0x4f058
movsd 0x1c008(%rip), %xmm2    # 0x6b048
ucomisd %xmm2, %xmm0
jb 0x4f058
movsd 0x1c01a(%rip), %xmm3    # 0x6b068
addsd %xmm3, %xmm0
ucomisd %xmm2, %xmm0
jae 0x4f04e
andpd 0x1bfb0(%rip), %xmm0    # 0x6b010
ucomisd 0x1c048(%rip), %xmm0    # 0x6b0b0
ja 0x4eebb
andb $0x1, %r15b
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq