// File: /workspace/github_cpp_makefile_star2_O1/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 0x28109
movq %rdi, %rbx
movq 0x18(%rax), %r12
movq 0x20(%rax), %rdi
callq 0x2adf8
movq %rax, %rdi
callq 0x48582
movq %rax, %r14
movq 0x80(%rbx), %rdi
callq 0x1356e
cmpq $0xb, 0x10(%r14)
jb 0x28109
cmpl $0x1, 0x1c(%r12)
jne 0x28109
movl 0x14(%r12), %ecx
addl 0x10(%r12), %ecx
imull $0xcccccccd, %ecx, %ecx # imm = 0xCCCCCCCD
movl $0x19999998, %edx       # imm = 0x19999998
addl %edx, %ecx
rorl %ecx
cmpl %edx, %ecx
ja 0x28109
movq 0x10(%rax), %rax
movq %rax, -0x98(%rbp)
xorl %eax, %eax
movq 0x60(%rbx,%rax,8), %rcx
cmpq $0x0, 0xcd8(%rcx)
je 0x27d53
incq %rax
cmpq $0x4, %rax
jne 0x27d36
movl $0x4, %eax
cmpl $0x4, %eax
je 0x28109
movq -0x98(%rbp), %rax
movl 0x4c(%rax), %ecx
movl %ecx, -0x30(%rbp)
movl 0x44(%rax), %ecx
movl %ecx, -0x2c(%rbp)
movl 0x48(%rax), %eax
movl $0x0, -0xb0(%rbp)
xorl %r15d, %r15d
movq %r15, -0xa8(%rbp)
movq %r15, -0x80(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq %r15, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movq %r15, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movq (%r14), %r13
cmpq %r14, %r13
je 0x27e70
addq $0x10d0, %r12           # imm = 0x10D0
addl -0x30(%rbp), %eax
movl %eax, -0x9c(%rbp)
addl %eax, -0x2c(%rbp)
movslq 0x10(%r13), %rax
movl %eax, -0xb0(%rbp)
imulq $0x178, %rax, %rax      # imm = 0x178
movsd -0x168(%rax,%r12), %xmm0
xorps 0x4323b(%rip), %xmm0    # 0x6b020
movlps %xmm0, -0xa8(%rbp)
cmpl -0x30(%rbp), %r15d
jge 0x27e1d
movq -0x88(%rbp), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq -0x80(%rbp), %rsi
je 0x27e38
movups -0xb0(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, (%rax)
jmp 0x27e60
cmpl -0x9c(%rbp), %r15d
jge 0x27e46
movq -0x68(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rsi
jne 0x27e0d
leaq -0xb0(%rbp), %rdx
callq 0x29102
jmp 0x27e60
cmpl -0x2c(%rbp), %r15d
jge 0x27e60
movq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rsi
jne 0x27e0d
jmp 0x27e38
incl %r15d
movq (%r13), %r13
cmpq %r14, %r13
jne 0x27dc3
movq -0x90(%rbp), %r14
movq -0x88(%rbp), %r15
cmpq %r15, %r14
je 0x27eb0
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x29250
movq %r14, %rdi
movq %r15, %rsi
callq 0x2935a
movq -0x70(%rbp), %r14
movq -0x68(%rbp), %r15
cmpq %r15, %r14
je 0x27eea
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x29250
movq %r14, %rdi
movq %r15, %rsi
callq 0x2935a
movq -0x50(%rbp), %r14
movq -0x48(%rbp), %r15
cmpq %r15, %r14
je 0x27f24
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x29250
movq %r14, %rdi
movq %r15, %rsi
callq 0x2935a
movq -0x98(%rbp), %rax
leaq 0x60(%rax), %r15
movl $0x1, %r14d
leaq 0x4463c(%rip), %r13     # 0x6c578
movq -0x98(%rbp), %rax
movslq 0x350(%rax,%r14,4), %rax
shlq $0x4, %rax
movl -0x8(%rax,%r15), %ecx
cmpq $0x3, %rcx
ja 0x28026
addq %r15, %rax
addq $-0x10, %rax
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
xorl %ecx, %ecx
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x27f9d
movslq 0x4(%rax), %rsi
movq -0x50(%rbp), %rdi
shlq $0x4, %rsi
movslq -0x10(%rdi,%rsi), %rsi
shlq $0x4, %rsi
movups (%rax), %xmm0
movups %xmm0, 0x50(%rsi,%rdx)
incq %rcx
cmpq $0x4, %rcx
jne 0x27f71
jmp 0x280ba
xorl %ecx, %ecx
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x27fd9
movslq 0x4(%rax), %rsi
movq -0x70(%rbp), %rdi
shlq $0x4, %rsi
movslq -0x10(%rdi,%rsi), %rsi
shlq $0x4, %rsi
movups (%rax), %xmm0
movups %xmm0, 0x50(%rsi,%rdx)
incq %rcx
cmpq $0x4, %rcx
jne 0x27fad
jmp 0x280ba
xorl %ecx, %ecx
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x28018
movslq 0x4(%rax), %rsi
movq -0x90(%rbp), %rdi
shlq $0x4, %rsi
movslq -0x10(%rdi,%rsi), %rsi
shlq $0x4, %rsi
movups (%rax), %xmm0
movups %xmm0, 0x50(%rsi,%rdx)
incq %rcx
cmpq $0x4, %rcx
jne 0x27fe9
jmp 0x280ba
movl $0x14, %edx
movq 0x5efbe(%rip), %rdi     # 0x86ff0
leaq 0x4468c(%rip), %rsi     # 0x6c6c5
callq 0x9560
movl $0x1, %edx
movq 0x5efa6(%rip), %rdi     # 0x86ff0
leaq 0x47171(%rip), %rsi     # 0x6f1c2
callq 0x9560
movq 0x5ef93(%rip), %rdi     # 0x86ff0
movl $0x3d3, %esi            # imm = 0x3D3
callq 0x9880
movq %rax, %r12
movl $0x3, %edx
movq %rax, %rdi
leaq 0x45406(%rip), %rsi     # 0x6d47f
callq 0x9560
movl $0xf, %edx
movq %r12, %rdi
leaq 0x4464d(%rip), %rsi     # 0x6c6da
callq 0x9560
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r12, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
incq %r14
cmpq $0xc, %r14
jne 0x27f3c
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x280dc
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x280f1
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x28109
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2811f
jmp 0x2811f
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x28137
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x2814c
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x28164
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq %rbx, %rdi
callq 0x98b0