// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Formation.cpp
// Function: Formation::Instance::UpdateOpponentRole()
void Formation::Instance::UpdateOpponentRole() {
  if (!mpAgent) {
    Assert(0);
    return;
  }

  const WorldState &world_state = mpAgent->GetWorldState();
  const InfoState &info_state = mpAgent->GetInfoState();
  const std::list<KeyPlayerInfo> &opp_list =
      info_state.GetPositionInfo().GetXSortOpponent();
  const FormationBase &teammate_formation =
      mpAgent->GetFormation().GetTeammateFormation();
  if (opp_list.size() < TEAMSIZE || world_state.GetPlayMode() != PM_Play_On ||
      world_state.CurrentTime() % 10 != 0) {
    return; // 按照WE2008，不满足这些条件就返回
  }

  int i;
  for (i = 0; i < FT_Max; ++i) {
    if (mpOpponentFormations[i]->mUsedTimes == 0) {
      break;
    }
  }
  if (i == FT_Max) {
    return; // 如果所有阵型信息均被教练的消息设置过，则不再考虑
  }

  const int &forward_num = teammate_formation.GetLineArrange(3);
  const int &midfielder_num = teammate_formation.GetLineArrange(2);
  const int &defender_num = teammate_formation.GetLineArrange(1);

  int count = 0;
  KeyPlayerInfo kp;
  std::vector<KeyPlayerInfo> forward, midfielder, defender; // 守门员不考虑
  for (std::list<KeyPlayerInfo>::const_iterator it = opp_list.begin();
       it != opp_list.end(); ++it) {
    kp.mUnum = it->mUnum;
    kp.mValue = -world_state.GetOpponent(kp.mUnum).GetPos().Y();
    if (count < forward_num) {
      forward.push_back(kp);
    } else if (count < forward_num + midfielder_num) {
      midfielder.push_back(kp);
    } else if (count < forward_num + midfielder_num + defender_num) {
      defender.push_back(kp);
    }
    ++count;
  }
  std::sort(forward.begin(), forward.end());
  std::sort(midfielder.begin(), midfielder.end());
  std::sort(defender.begin(), defender.end());

  for (Unum i = 1; i <= TEAMSIZE; ++i) {
    if (teammate_formation.GetPlayerRoleType(i).mLineType == LT_Goalie) {
      continue;
    }

    const RoleType &role = teammate_formation.GetPlayerRoleType(i);
    switch (role.mLineType) {
    case LT_Forward:
      Assert(role.mIndexY - 1 >= 0 && role.mIndexY - 1 < (int)forward.size());
      for (int j = 0; j < FT_Max; ++j) {
        if (mpOpponentFormations[j]->mUsedTimes == 0) {
          mpOpponentFormations[j]
              ->mPlayerRole[forward[role.mIndexY - 1].mUnum] = role;
        }
      }
      break;
    case LT_Midfielder:
      Assert(role.mIndexY - 1 >= 0 &&
             role.mIndexY - 1 < (int)midfielder.size());
      for (int j = 0; j < FT_Max; ++j) {
        if (mpOpponentFormations[j]->mUsedTimes == 0) {
          mpOpponentFormations[j]
              ->mPlayerRole[midfielder[role.mIndexY - 1].mUnum] = role;
        }
      }
      break;
    case LT_Defender:
      Assert(role.mIndexY - 1 >= 0 && role.mIndexY - 1 < (int)defender.size());
      for (int j = 0; j < FT_Max; ++j) {
        if (mpOpponentFormations[j]->mUsedTimes == 0) {
          mpOpponentFormations[j]
              ->mPlayerRole[defender[role.mIndexY - 1].mUnum] = role;
        }
      }
      break;
    default:
      PRINT_ERROR("line type error");
      break;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq 0x80(%rdi), %rax
testq %rax, %rax
je 0x21891
movq %rdi, %rbx
movq 0x18(%rax), %r13
movq 0x20(%rax), %rdi
callq 0x244e8
movq %rax, %rdi
callq 0x3bb80
movq %rax, %r12
movq 0x80(%rbx), %rdi
callq 0x10dfe
cmpq $0xb, 0x10(%r12)
jb 0x21891
cmpl $0x1, 0x1c(%r13)
jne 0x21891
movq %rax, %rcx
movl 0x14(%r13), %eax
addl 0x10(%r13), %eax
pushq $0xa
popq %rsi
cltd
idivl %esi
testl %edx, %edx
jne 0x21891
movq 0x10(%rcx), %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
cmpq $0x4, %rax
je 0x21891
movq 0x60(%rbx,%rax,8), %rcx
incq %rax
cmpq $0x0, 0xcd8(%rcx)
jne 0x21607
movq -0x40(%rbp), %rax
movl 0x4c(%rax), %ecx
movl 0x48(%rax), %edx
movl %ecx, -0x34(%rbp)
addl %ecx, %edx
movl 0x44(%rax), %eax
leaq -0xb0(%rbp), %rcx
andl $0x0, (%rcx)
movl %edx, -0x30(%rbp)
addl %edx, %eax
movl %eax, -0x2c(%rbp)
andq $0x0, 0x8(%rcx)
leaq -0xa0(%rbp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq -0x80(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x60(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
addq $0x10d0, %r13           # imm = 0x10D0
xorl %r15d, %r15d
movq %r12, %r14
movq (%r14), %r14
cmpq %r12, %r14
je 0x216e6
movslq 0x10(%r14), %rax
movl %eax, -0xb0(%rbp)
imulq $0x178, %rax, %rax      # imm = 0x178
movsd -0x168(%rax,%r13), %xmm0
xorps 0x35973(%rip), %xmm0    # 0x57020
movlps %xmm0, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
cmpl -0x34(%rbp), %r15d
jl 0x216d5
leaq -0x80(%rbp), %rdi
cmpl -0x30(%rbp), %r15d
jl 0x216d5
leaq -0x60(%rbp), %rdi
cmpl -0x2c(%rbp), %r15d
jge 0x216e1
leaq -0xb0(%rbp), %rsi
callq 0x21cb2
incl %r15d
jmp 0x21683
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x22d46
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x22d46
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x22d46
movq -0x40(%rbp), %r12
leaq 0x60(%r12), %r15
pushq $0x1
popq %r13
leaq 0x36e09(%rip), %r14     # 0x58530
cmpq $0xc, %r13
je 0x21873
movslq 0x350(%r12,%r13,4), %rax
shlq $0x4, %rax
movl -0x8(%rax,%r15), %ecx
cmpq $0x3, %rcx
ja 0x21816
addq %r15, %rax
addq $-0x10, %rax
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x2186b
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x21794
movslq 0x4(%rax), %rsi
movq -0x60(%rbp), %rdi
shlq $0x4, %rsi
movslq -0x10(%rdi,%rsi), %rsi
shlq $0x4, %rsi
movups (%rax), %xmm0
movups %xmm0, 0x50(%rsi,%rdx)
incq %rcx
jmp 0x2175e
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x2186b
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x217d1
movslq 0x4(%rax), %rsi
movq -0x80(%rbp), %rdi
shlq $0x4, %rsi
movslq -0x10(%rdi,%rsi), %rsi
shlq $0x4, %rsi
movups (%rax), %xmm0
movups %xmm0, 0x50(%rsi,%rdx)
incq %rcx
jmp 0x2179b
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x2186b
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x21811
movslq 0x4(%rax), %rsi
movq -0xa0(%rbp), %rdi
shlq $0x4, %rsi
movslq -0x10(%rdi,%rsi), %rsi
shlq $0x4, %rsi
movups (%rax), %xmm0
movups %xmm0, 0x50(%rsi,%rdx)
incq %rcx
jmp 0x217d8
movq 0x557d3(%rip), %rdi     # 0x76ff0
leaq 0x36e61(%rip), %rsi     # 0x58685
callq 0x94b0
movq %rax, %rdi
leaq 0x3993f(%rip), %rsi     # 0x5b172
callq 0x94b0
movq %rax, %rdi
movl $0x3d3, %esi            # imm = 0x3D3
callq 0x9890
movq %rax, %rdi
leaq 0x37bd0(%rip), %rsi     # 0x5941f
callq 0x94b0
movq %rax, %rdi
leaq 0x36e3c(%rip), %rsi     # 0x5869a
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
incq %r13
jmp 0x21727
leaq -0x60(%rbp), %rdi
callq 0x22bb2
leaq -0x80(%rbp), %rdi
callq 0x22bb2
leaq -0xa0(%rbp), %rdi
callq 0x22bb2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x218a7
jmp 0x218a7
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x22bb2
leaq -0x80(%rbp), %rdi
callq 0x22bb2
leaq -0xa0(%rbp), %rdi
callq 0x22bb2
movq %rbx, %rdi
callq 0x98b0