// File: /workspace/github_cpp_makefile_star2_O3/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 0x278d2
movq %rdi, %rbx
movq 0x18(%rax), %r12
movq 0x20(%rax), %rdi
callq 0x2a4b4
movq %rax, %rdi
callq 0x4717e
movq %rax, %r14
movq 0x80(%rbx), %rdi
callq 0x13432
cmpq $0xb, 0x10(%r14)
jb 0x278d2
cmpl $0x1, 0x1c(%r12)
jne 0x278d2
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 0x278d2
movq 0x10(%rax), %rax
movq %rax, -0x88(%rbp)
xorl %eax, %eax
movq 0x60(%rbx,%rax,8), %rcx
cmpq $0x0, 0xcd8(%rcx)
je 0x27533
incq %rax
cmpq $0x4, %rax
jne 0x27516
jmp 0x278d2
movq -0x88(%rbp), %rax
movl 0x4c(%rax), %ecx
movl 0x44(%rax), %edx
movl 0x48(%rax), %eax
movl $0x0, -0xa8(%rbp)
xorl %r15d, %r15d
movq %r15, -0xa0(%rbp)
movq %r15, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq %r15, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movq %r15, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movq (%r14), %r13
cmpq %r14, %r13
je 0x2767f
addq $0x10d0, %r12           # imm = 0x10D0
movl %ecx, -0x94(%rbp)
addl %ecx, %eax
movl %eax, -0x90(%rbp)
addl %eax, %edx
movl %edx, -0x8c(%rbp)
movslq 0x10(%r13), %rax
movl %eax, -0xa8(%rbp)
imulq $0x178, %rax, %rax      # imm = 0x178
movsd -0x168(%rax,%r12), %xmm0
xorps 0x41a63(%rip), %xmm0    # 0x69020
movlps %xmm0, -0xa0(%rbp)
cmpl -0x94(%rbp), %r15d
jge 0x275ef
movq -0x78(%rbp), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq -0x70(%rbp), %rsi
je 0x2760a
movups -0xa8(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, (%rax)
jmp 0x27635
cmpl -0x90(%rbp), %r15d
jge 0x27618
movq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rsi
jne 0x275df
leaq -0xa8(%rbp), %rdx
callq 0x288ac
jmp 0x27635
cmpl -0x8c(%rbp), %r15d
jge 0x27635
movq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rsi
jne 0x275df
jmp 0x2760a
incl %r15d
movq (%r13), %r13
cmpq %r14, %r13
jne 0x2759b
movq -0x80(%rbp), %r14
movq -0x78(%rbp), %r15
cmpq %r15, %r14
je 0x2767f
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 0x289fa
movq %r14, %rdi
movq %r15, %rsi
callq 0x28b04
movq -0x60(%rbp), %r14
movq -0x58(%rbp), %r15
cmpq %r15, %r14
je 0x276b9
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 0x289fa
movq %r14, %rdi
movq %r15, %rsi
callq 0x28b04
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x276f3
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 0x289fa
movq %r14, %rdi
movq %r15, %rsi
callq 0x28b04
movq -0x88(%rbp), %rax
leaq 0x60(%rax), %r15
movl $0x1, %r14d
leaq 0x42e5d(%rip), %r13     # 0x6a568
movq -0x88(%rbp), %rax
movslq 0x350(%rax,%r14,4), %rax
shlq $0x4, %rax
movl -0x8(%rax,%r15), %ecx
cmpq $0x3, %rcx
ja 0x277f2
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 0x2776c
movslq 0x4(%rax), %rsi
movq -0x40(%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 0x27740
jmp 0x27886
xorl %ecx, %ecx
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x277a8
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
cmpq $0x4, %rcx
jne 0x2777c
jmp 0x27886
xorl %ecx, %ecx
movq 0x60(%rbx,%rcx,8), %rdx
cmpq $0x0, 0xcd8(%rdx)
jne 0x277e4
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
cmpq $0x4, %rcx
jne 0x277b8
jmp 0x27886
movl $0x14, %edx
movq 0x5c7f2(%rip), %rdi     # 0x83ff0
leaq 0x42eb0(%rip), %rsi     # 0x6a6b5
callq 0x9560
movl $0x1, %edx
movq 0x5c7da(%rip), %rdi     # 0x83ff0
leaq 0x45975(%rip), %rsi     # 0x6d192
callq 0x9560
movq 0x5c7c7(%rip), %rdi     # 0x83ff0
movl $0x3d3, %esi            # imm = 0x3D3
callq 0x9880
movq %rax, %r12
movl $0x3, %edx
movq %rax, %rdi
leaq 0x43c12(%rip), %rsi     # 0x6b457
callq 0x9560
movl $0xf, %edx
movq %r12, %rdi
leaq 0x42e71(%rip), %rsi     # 0x6a6ca
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 0x2770b
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x278a8
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x278bd
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x278d2
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x278e8
jmp 0x278e8
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x27900
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x27915
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x2792a
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
movq %rbx, %rdi
callq 0x98b0