// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/WorldState.cpp
// Function: WorldStateUpdater::ComputeTackleProb(int const&, bool)
double WorldStateUpdater::ComputeTackleProb(const Unum &unum, bool foul) {
  const PlayerState &player = mpWorldState->GetPlayer(unum);

  if (mpWorldState->GetPlayMode() == PM_Before_Kick_Off ||
      player.IsAlive() == false || player.IsIdling() == true) {
    return 0.0;
  }

  const Vector &ball_pos = mpWorldState->GetBall().GetPos();
  const Vector &player_pos = player.GetPos();
  Vector ball_2_player = ball_pos - player_pos;
  if (ball_2_player.Mod() > ServerParam::instance().maxTackleDist()) {
    return 0.0;
  }

  const Vector &v = player.GetVel();
  double body_dir = player.GetBodyDir();
  if (player.GetBodyDirConf() > 0.9) {
    body_dir = player.GetBodyDir();
  } else if (v.Mod() > 0.2) {
    body_dir = v.Dir();
  } else {
    Vector posdiff =
        player.GetPos() - mpWorldState->GetHistory(1)->GetPlayer(unum).GetPos();
    if (posdiff.Mod() > 0.12) {
      body_dir = posdiff.Dir();
    }
  }

  ball_2_player = ball_2_player.Rotate(-body_dir);

  if (foul) {
    foul = false;
    if (PlayerParam::instance().playerVersion() > 14.0) {
      for (unsigned i = 0; i < mpWorldState->GetPlayerList().size();
           ++i) { //如对手无人可踢，则退化为正常铲球
        const PlayerState &opp = *mpWorldState->GetPlayerList()[i];

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

        foul = true;
        break;
      }
    }
  }

  return GetTackleProb(ball_2_player, foul);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rax
movl (%rsi), %ecx
testl %ecx, %ecx
jle 0x5c1b4
decl %ecx
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rax,%rcx), %r12
addq $0xa8, %r12
jmp 0x5c1cb
notl %ecx
movslq %ecx, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rax,%rcx), %r12
addq $0x10d0, %r12           # imm = 0x10D0
xorpd %xmm2, %xmm2
cmpl $0x16, 0x1c(%rax)
je 0x5c470
cmpb $0x1, 0x112(%r12)
jne 0x5c470
cmpl $0x0, 0xc8(%r12)
jg 0x5c470
cmpl $0x0, 0x124(%r12)
jg 0x5c470
movsd 0x38(%rax), %xmm1
movsd 0x40(%rax), %xmm0
subsd 0x8(%r12), %xmm1
subsd 0x10(%r12), %xmm0
movapd %xmm0, -0x60(%rbp)
mulsd %xmm0, %xmm0
movsd %xmm1, -0x48(%rbp)
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x49360
movsd -0x40(%rbp), %xmm0
ucomisd 0x3450(%rax), %xmm0
ja 0x5c46c
movsd 0xb0(%r12), %xmm0
movsd 0xc0(%r12), %xmm1
ucomisd 0x1089c(%rip), %xmm1    # 0x6cb10
ja 0x5c35c
movsd 0x30(%r12), %xmm1
movsd 0x38(%r12), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
ucomisd 0xf218(%rip), %xmm1     # 0x6b4b8
jbe 0x5c2ae
addq $0x30, %r12
movq %r12, %rdi
jmp 0x5c357
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
movl 0x14b90(%rcx), %eax
addl $0x9, %eax
cltq
imulq $0x66666667, %rax, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %eax
cltq
imulq $0x2128, %rax, %rax     # imm = 0x2128
addq %rcx, %rax
movl (%rbx), %ecx
testl %ecx, %ecx
jle 0x5c302
decl %ecx
imulq $0x178, %rcx, %rcx      # imm = 0x178
addq %rcx, %rax
addq $0xa8, %rax
jmp 0x5c317
notl %ecx
movslq %ecx, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
addq %rcx, %rax
addq $0x10d0, %rax           # imm = 0x10D0
movsd 0x8(%r12), %xmm1
subsd 0x8(%rax), %xmm1
movsd 0x10(%r12), %xmm2
subsd 0x10(%rax), %xmm2
movsd %xmm1, -0x80(%rbp)
movsd %xmm2, -0x78(%rbp)
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
ucomisd 0x11387(%rip), %xmm1    # 0x6d6d8
jbe 0x5c35c
leaq -0x80(%rbp), %rdi
callq 0xe702
mulsd 0xcd3c(%rip), %xmm0     # 0x690a0
divsd 0xccdc(%rip), %xmm0     # 0x69048
leaq -0x80(%rbp), %r12
leaq -0x98(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x92d0
movsd (%r12), %xmm0
movsd (%r13), %xmm2
movsd %xmm0, -0x68(%rbp)
mulsd -0x60(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd %xmm2, -0x70(%rbp)
mulsd %xmm2, %xmm1
subsd %xmm0, %xmm1
movl $0x3318, %r12d          # imm = 0x3318
testb %r15b, %r15b
movapd %xmm1, -0x40(%rbp)
je 0x5c434
callq 0x43dce
movsd 0x31a8(%rax), %xmm0
ucomisd 0xce89(%rip), %xmm0     # 0x69258
jbe 0x5c42f
movq 0x8(%r14), %rcx
movq 0x20f8(%rcx), %rax
movq 0x2100(%rcx), %rcx
subq %rax, %rcx
movapd -0x40(%rbp), %xmm1
je 0x5c434
sarq $0x3, %rcx
movl (%rbx), %edx
movl $0x1, %esi
xorl %edi, %edi
movq (%rax,%rdi,8), %rdi
cmpb $0x1, 0x112(%rdi)
jne 0x5c424
movl 0x11c(%rdi), %r8d
imull %edx, %r8d
testl %r8d, %r8d
jg 0x5c424
cmpb $0x0, 0x128(%rdi)
jne 0x5c57d
movl %esi, %edi
incl %esi
cmpq %rdi, %rcx
ja 0x5c3fa
jmp 0x5c434
movapd -0x40(%rbp), %xmm1
xorl %ebx, %ebx
ucomisd 0xe39a(%rip), %xmm1     # 0x6a7d8
setbe %bl
callq 0x49360
shll $0x4, %ebx
movsd 0x32f8(%rbx,%rax), %xmm0
movapd 0xcbb6(%rip), %xmm1     # 0x69010
andpd %xmm0, %xmm1
movsd 0xcbda(%rip), %xmm2     # 0x69040
ucomisd %xmm1, %xmm2
jbe 0x5c483
xorpd %xmm2, %xmm2
movapd %xmm2, %xmm0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movapd -0x40(%rbp), %xmm1
andpd 0xcb80(%rip), %xmm1     # 0x69010
divsd %xmm0, %xmm1
movapd %xmm1, -0x90(%rbp)
callq 0x49360
movapd -0x90(%rbp), %xmm0
ucomisd 0xcba7(%rip), %xmm0     # 0x69058
ja 0x5c46c
movsd -0x48(%rbp), %xmm1
mulsd -0x68(%rbp), %xmm1
movapd -0x60(%rbp), %xmm0
mulsd -0x70(%rbp), %xmm0
addsd %xmm1, %xmm0
movapd 0xcb3d(%rip), %xmm1     # 0x69010
andpd %xmm0, %xmm1
divsd 0x3310(%rax), %xmm1
ucomisd 0xcb71(%rip), %xmm1     # 0x69058
ja 0x5c46c
movapd %xmm1, -0x60(%rbp)
mulsd %xmm0, %xmm0
movapd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x49360
movsd -0x40(%rbp), %xmm0
ucomisd 0x3300(%rax), %xmm0
xorpd %xmm2, %xmm2
ja 0x5c470
callq 0x49360
movsd (%rax,%r12), %xmm1
movsd %xmm1, -0x48(%rbp)
movaps -0x90(%rbp), %xmm0
callq 0x98a0
movsd %xmm0, -0x40(%rbp)
movapd -0x60(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
callq 0x98a0
addsd -0x40(%rbp), %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm1, %xmm0
movsd 0xcaec(%rip), %xmm2     # 0x69058
movapd %xmm2, %xmm1
minsd %xmm0, %xmm1
subsd %xmm1, %xmm2
jmp 0x5c470
movl $0x33e0, %r12d          # imm = 0x33E0
jmp 0x5c434