// File: 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
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x10fb0
movaps %xmm0, %xmm1
movsd 0x34bff(%rip), %xmm0    # 0xc1008
ucomisd %xmm1, %xmm0
jbe 0x8c437
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x10fb0
movaps %xmm0, %xmm1
movsd 0x34be0(%rip), %xmm0    # 0xc1008
ucomisd %xmm1, %xmm0
jbe 0x8c437
movb $0x0, -0x1(%rbp)
jmp 0x8c6ca
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10570
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2e700
movsd %xmm0, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x81040
movq %rax, %rdi
callq 0x81170
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8c6c6
movq -0x18(%rbp), %rdi
callq 0x81040
movq %rax, %rdi
movl -0x5c(%rbp), %eax
movl %eax, %esi
callq 0x81190
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x23f20
testb $0x1, %al
jne 0x8c50e
jmp 0x8c6b8
movq -0x68(%rbp), %rdi
callq 0x1b470
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1b470
movl %eax, %ecx
movl -0xac(%rbp), %eax
imull %ecx, %eax
cmpl $0x0, %eax
jle 0x8c53b
jmp 0x8c6b8
movq -0x68(%rbp), %rdi
callq 0x332f0
testb $0x1, %al
jne 0x8c54a
jmp 0x8c54f
jmp 0x8c6b8
movq -0x68(%rbp), %rdi
callq 0x10ef0
testb $0x1, %al
jne 0x8c561
jmp 0x8c6b8
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
leaq -0x28(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x78(%rbp)
movsd %xmm1, -0x70(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2e700
ucomisd -0x50(%rbp), %xmm0
jbe 0x8c599
jmp 0x8c6b8
movsd -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x90(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0x88(%rbp)
movsd %xmm1, -0x80(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x176f0
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
ja 0x8c657
leaq -0x78(%rbp), %rdi
callq 0x17700
movsd (%rax), %xmm0
movaps 0x34a4d(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x68(%rbp), %rdi
callq 0x57020
movsd (%rax), %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x57020
movsd -0xc0(%rbp), %xmm1
movsd -0xb8(%rbp), %xmm0
addsd (%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x8c659
jmp 0x8c6b8
movq -0x68(%rbp), %rdi
callq 0x11170
movsd (%rax), %xmm0
subsd -0x58(%rbp), %xmm0
movsd 0x349bd(%rip), %xmm1    # 0xc1030
movsd %xmm1, -0xa0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x116b0
movaps 0x349d2(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd 0x34996(%rip), %xmm1    # 0xc1040
ucomisd %xmm1, %xmm0
jbe 0x8c6b2
jmp 0x8c6b8
movb $0x1, -0x1(%rbp)
jmp 0x8c6ca
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x8c4b1
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)