// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, %r14
movq %rdi, %r15
movq 0x8(%rdi), %rax
movl (%rsi), %ecx
leal -0x1(%rcx), %esi
leaq 0x10d0(%rax), %rdi
leaq 0xa8(%rax), %r12
testl %ecx, %ecx
notl %ecx
cmovgl %esi, %ecx
cmovleq %rdi, %r12
xorpd %xmm2, %xmm2
cmpl $0x16, 0x1c(%rax)
je 0x5de11
movslq %ecx, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
addq %rcx, %r12
cmpb $0x1, 0x112(%r12)
jne 0x5de11
cmpl $0x0, 0xc8(%r12)
jg 0x5de11
cmpl $0x0, 0x124(%r12)
jg 0x5de11
movl %edx, %ebx
movsd 0x38(%rax), %xmm0
movsd 0x40(%rax), %xmm1
subsd 0x8(%r12), %xmm0
subsd 0x10(%r12), %xmm1
movapd %xmm1, -0x60(%rbp)
mulsd %xmm1, %xmm1
movsd %xmm0, -0x48(%rbp)
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5db7b
sqrtsd %xmm0, %xmm0
jmp 0x5db80
callq 0x93c0
movsd %xmm0, -0x40(%rbp)
callq 0x4a75c
movsd -0x40(%rbp), %xmm0
ucomisd 0x3450(%rax), %xmm0
ja 0x5de0d
movsd 0xb0(%r12), %xmm1
movsd 0xc0(%r12), %xmm0
ucomisd 0x10f87(%rip), %xmm0    # 0x6eb40
ja 0x5dcd5
movsd %xmm1, -0x40(%rbp)
movsd 0x30(%r12), %xmm0
movsd 0x38(%r12), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5dbee
sqrtsd %xmm0, %xmm0
jmp 0x5dbf3
callq 0x93c0
ucomisd 0xf8e5(%rip), %xmm0     # 0x6d4e0
jbe 0x5dc09
addq $0x30, %r12
movq %r12, %rdi
jmp 0x5dccc
movq 0x8(%r15), %rax
movq 0x8(%rax), %rax
movl 0x14b90(%rax), %ecx
movl %ecx, %edx
addl $0x9, %edx
movslq %edx, %rdx
imulq $0x66666667, %rdx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
negl %edx
addl %edx, %ecx
addl $0x9, %ecx
movslq %ecx, %rcx
imulq $0x2128, %rcx, %rcx     # imm = 0x2128
movl (%r14), %edx
leal -0x1(%rdx), %esi
testl %edx, %edx
notl %edx
cmovgl %esi, %edx
leaq 0xa8(%rax,%rcx), %rsi
leaq 0x10d0(%rax,%rcx), %rax
cmovgq %rsi, %rax
movslq %edx, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
movsd 0x8(%r12), %xmm0
movsd 0x10(%r12), %xmm1
subsd 0x8(%rax,%rcx), %xmm0
subsd 0x10(%rax,%rcx), %xmm1
movsd %xmm0, -0x80(%rbp)
movsd %xmm1, -0x78(%rbp)
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5dcb4
sqrtsd %xmm0, %xmm0
jmp 0x5dcb9
callq 0x93c0
movsd -0x40(%rbp), %xmm1
ucomisd 0x11a52(%rip), %xmm0    # 0x6f718
jbe 0x5dcd5
leaq -0x80(%rbp), %rdi
callq 0xe804
movapd %xmm0, %xmm1
mulsd 0xd3c3(%rip), %xmm1     # 0x6b0a0
divsd 0xd363(%rip), %xmm1     # 0x6b048
leaq -0x80(%rbp), %r12
leaq -0x98(%rbp), %r13
movapd %xmm1, %xmm0
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
testb %bl, %bl
movapd %xmm1, -0x40(%rbp)
je 0x5ddd1
callq 0x450ba
movsd 0x31a8(%rax), %xmm0
ucomisd 0xd50f(%rip), %xmm0     # 0x6b258
jbe 0x5ddc6
movq 0x8(%r15), %rcx
movq 0x20f8(%rcx), %rax
movq 0x2100(%rcx), %rcx
subq %rax, %rcx
movapd -0x40(%rbp), %xmm1
je 0x5ddcf
sarq $0x3, %rcx
movl (%r14), %edx
movl $0x1, %esi
xorl %r8d, %r8d
movl $0x1, %edi
xorl %ebx, %ebx
movq (%rax,%r8,8), %r9
movb $0x1, %r8b
cmpb $0x1, 0x112(%r9)
jne 0x5ddb5
movl 0x11c(%r9), %r10d
imull %edx, %r10d
testl %r10d, %r10d
jg 0x5ddb5
movb 0x128(%r9), %r9b
movl %r9d, %r8d
xorb $0x1, %r8b
movzbl %bl, %ebx
testb %r9b, %r9b
cmovnel %esi, %ebx
testb %r8b, %r8b
je 0x5ddd1
movl %edi, %r8d
incl %edi
cmpq %r8, %rcx
ja 0x5dd7d
jmp 0x5ddd1
xorl %ebx, %ebx
movapd -0x40(%rbp), %xmm1
jmp 0x5ddd1
xorl %ebx, %ebx
xorl %r14d, %r14d
ucomisd 0xea0c(%rip), %xmm1     # 0x6c7e8
setbe %r14b
callq 0x4a75c
shll $0x4, %r14d
movsd 0x32f8(%r14,%rax), %xmm0
movapd 0xd215(%rip), %xmm1     # 0x6b010
andpd %xmm0, %xmm1
movsd 0xd239(%rip), %xmm2     # 0x6b040
ucomisd %xmm1, %xmm2
jbe 0x5de24
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 0xd1df(%rip), %xmm1     # 0x6b010
divsd %xmm0, %xmm1
movapd %xmm1, -0x90(%rbp)
callq 0x4a75c
movapd -0x90(%rbp), %xmm0
ucomisd 0xd206(%rip), %xmm0     # 0x6b058
ja 0x5de0d
movsd -0x48(%rbp), %xmm1
mulsd -0x68(%rbp), %xmm1
movapd -0x60(%rbp), %xmm3
mulsd -0x70(%rbp), %xmm3
addsd %xmm1, %xmm3
movapd 0xd19c(%rip), %xmm0     # 0x6b010
andpd %xmm3, %xmm0
divsd 0x3310(%rax), %xmm0
movapd %xmm0, -0x60(%rbp)
ucomisd 0xd1cb(%rip), %xmm0     # 0x6b058
xorpd %xmm2, %xmm2
ja 0x5de11
mulsd %xmm3, %xmm3
movapd -0x40(%rbp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm3, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5deb8
sqrtsd %xmm0, %xmm0
jmp 0x5debd
callq 0x93c0
movsd %xmm0, -0x40(%rbp)
callq 0x4a75c
movsd -0x40(%rbp), %xmm0
ucomisd 0x3300(%rax), %xmm0
xorpd %xmm2, %xmm2
ja 0x5de11
callq 0x4a75c
leaq 0x3318(%rax), %rcx
addq $0x33e0, %rax           # imm = 0x33E0
testb $0x1, %bl
cmoveq %rcx, %rax
movsd (%rax), %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 0xd123(%rip), %xmm2     # 0x6b058
movapd %xmm2, %xmm1
minsd %xmm0, %xmm1
subsd %xmm1, %xmm2
jmp 0x5de11