// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x30, %rsp
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rax
movl (%rsi), %ecx
testl %ecx, %ecx
jle 0x4d84c
decl %ecx
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rax,%rcx), %r12
addq $0xa8, %r12
jmp 0x4d863
notl %ecx
movslq %ecx, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rax,%rcx), %r12
addq $0x10d0, %r12           # imm = 0x10D0
xorpd %xmm0, %xmm0
cmpl $0x16, 0x1c(%rax)
je 0x4da8c
cmpb $0x1, 0x112(%r12)
jne 0x4da8c
cmpl $0x0, 0xc8(%r12)
jg 0x4da8c
cmpl $0x0, 0x124(%r12)
jg 0x4da8c
movsd 0x38(%rax), %xmm0
movsd 0x40(%rax), %xmm1
subsd 0x8(%r12), %xmm0
subsd 0x10(%r12), %xmm1
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
callq 0x3db2c
xorpd %xmm0, %xmm0
movsd -0x28(%rbp), %xmm1
ucomisd 0x3450(%rax), %xmm1
ja 0x4da8c
movsd 0xb0(%r12), %xmm0
movsd 0xc0(%r12), %xmm1
ucomisd 0xd1e3(%rip), %xmm1     # 0x5aaf0
ja 0x4d9df
movsd 0x30(%r12), %xmm1
movsd 0x38(%r12), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
ucomisd 0xbb47(%rip), %xmm1     # 0x59480
jbe 0x4d947
addq $0x30, %r12
movq %r12, %rdi
jmp 0x4d9da
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
movl 0x14b90(%rcx), %eax
addl $0x9, %eax
pushq $0xa
popq %rsi
cltd
idivl %esi
movslq %edx, %rax
imulq $0x2128, %rax, %rax     # imm = 0x2128
addq %rcx, %rax
movl (%rbx), %ecx
testl %ecx, %ecx
jle 0x4d985
decl %ecx
imulq $0x178, %rcx, %rcx      # imm = 0x178
addq %rcx, %rax
addq $0xa8, %rax
jmp 0x4d99a
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, -0x38(%rbp)
movsd %xmm2, -0x30(%rbp)
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
ucomisd 0xdce4(%rip), %xmm1     # 0x5b6b8
jbe 0x4d9df
leaq -0x38(%rbp), %rdi
callq 0xcd30
xorpd 0x9639(%rip), %xmm0     # 0x57020
leaq -0x38(%rbp), %rsi
movlpd %xmm0, (%rsi)
leaq -0x48(%rbp), %r12
movq %r12, %rdi
callq 0xd02c
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
testb %r15b, %r15b
je 0x4da7d
callq 0x38d94
movsd 0x31a8(%rax), %xmm0
xorl %eax, %eax
ucomisd 0x97fc(%rip), %xmm0     # 0x57220
movl $0x0, %edi
jbe 0x4da7f
movq 0x8(%r14), %rdx
movq 0x20f8(%rdx), %rcx
movq 0x2100(%rdx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movl (%rbx), %esi
movl %eax, %eax
cmpq %rax, %rdx
seta %dil
jbe 0x4da7f
movq (%rcx,%rax,8), %r8
cmpb $0x1, 0x112(%r8)
jne 0x4da79
movl 0x11c(%r8), %r9d
imull %esi, %r9d
testl %r9d, %r9d
jg 0x4da79
cmpb $0x0, 0x128(%r8)
jne 0x4da7f
incl %eax
jmp 0x4da46
xorl %edi, %edi
movzbl %dil, %esi
leaq -0x48(%rbp), %rdi
callq 0x3aeb3
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop