// File: 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
subq $0xb0, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x23eb0
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rdi
callq 0x10ed0
cmpl $0x16, %eax
je 0xad534
movq -0x28(%rbp), %rdi
callq 0x23f20
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xad534
movq -0x28(%rbp), %rdi
callq 0x332f0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xad541
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xad816
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x10570
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0xa0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0xbe600
movsd -0xa0(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xad5c2
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xad816
movq -0x28(%rbp), %rdi
callq 0x10a80
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11170
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32a60
movsd 0x15276(%rip), %xmm1    # 0xc2868
ucomisd %xmm1, %xmm0
jbe 0xad60f
movq -0x28(%rbp), %rdi
callq 0x11170
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0xad6bf
movq -0x50(%rbp), %rdi
callq 0x104e0
movsd 0x152d0(%rip), %xmm1    # 0xc28f0
ucomisd %xmm1, %xmm0
jbe 0xad639
movq -0x50(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x58(%rbp)
jmp 0xad6bd
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, -0xa8(%rbp)
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0xab550
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x23eb0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x68(%rbp)
movsd %xmm1, -0x60(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x104e0
movsd 0x180b9(%rip), %xmm1    # 0xc5760
ucomisd %xmm1, %xmm0
jbe 0xad6bb
leaq -0x68(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x58(%rbp)
jmp 0xad6bd
jmp 0xad6bf
movsd -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x80(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0x78(%rbp)
movsd %xmm1, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x40(%rbp)
testb $0x1, -0x19(%rbp)
je 0xad800
movb $0x0, -0x19(%rbp)
callq 0x798a0
movq %rax, %rdi
callq 0x176d0
movsd (%rax), %xmm0
movsd 0x13ab2(%rip), %xmm1    # 0xc11e0
ucomisd %xmm1, %xmm0
jbe 0xad7fe
movl $0x0, -0x84(%rbp)
movq -0x98(%rbp), %rax
movl -0x84(%rbp), %ecx
movq %rcx, -0xb0(%rbp)
movq 0x8(%rax), %rdi
callq 0x81040
movq %rax, %rdi
callq 0x81170
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0xad7fc
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x81040
movq %rax, %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x81190
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x23f20
testb $0x1, %al
jne 0xad7b6
jmp 0xad7e8
movq -0x90(%rbp), %rdi
callq 0x1b470
movq -0x18(%rbp), %rcx
imull (%rcx), %eax
cmpl $0x0, %eax
jle 0xad7d0
jmp 0xad7e8
movq -0x90(%rbp), %rdi
callq 0x10ef0
testb $0x1, %al
jne 0xad7e2
jmp 0xad7e8
movb $0x1, -0x19(%rbp)
jmp 0xad7fc
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xad742
jmp 0xad7fe
jmp 0xad800
movb -0x19(%rbp), %al
leaq -0x48(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x7d7c0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)