// File: 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
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x170(%rbp)
cmpq $0x0, 0x80(%rax)
jne 0x3f079
jmp 0x3f907
movq -0x170(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x10550
movq %rax, %rcx
movq -0x170(%rbp), %rax
movq %rcx, -0x10(%rbp)
movq 0x80(%rax), %rdi
callq 0x2e810
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x49590
movq %rax, %rdi
callq 0x7f130
movq %rax, %rcx
movq -0x170(%rbp), %rax
movq %rcx, -0x20(%rbp)
movq 0x80(%rax), %rdi
callq 0x1a4c0
movq %rax, %rdi
callq 0x27400
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x40a70
cmpq $0xb, %rax
jb 0x3f119
movq -0x10(%rbp), %rdi
callq 0x10ed0
cmpl $0x1, %eax
jne 0x3f119
movq -0x10(%rbp), %rdi
callq 0x12100
movq %rax, %rdi
movl $0xa, %esi
callq 0x40aa0
cmpl $0x0, %eax
je 0x3f11e
jmp 0x3f907
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jge 0x3f163
movq -0x170(%rbp), %rdi
addq $0x60, %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x40a10
movq (%rax), %rax
cmpq $0x0, 0xcd8(%rax)
jne 0x3f156
jmp 0x3f163
jmp 0x3f158
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3f125
cmpl $0x4, -0x2c(%rbp)
jne 0x3f16e
jmp 0x3f907
movq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x40620
movl %eax, -0x44(%rbp)
leaq -0x44(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x40620
movl %eax, -0x54(%rbp)
leaq -0x54(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x40620
movl %eax, -0x64(%rbp)
leaq -0x64(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x68(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x1b700
leaq -0x90(%rbp), %rdi
callq 0x40ac0
leaq -0xa8(%rbp), %rdi
callq 0x40ac0
leaq -0xc0(%rbp), %rdi
callq 0x40ac0
movq -0x20(%rbp), %rdi
callq 0x27320
movq %rax, -0xc8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x27380
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x27350
testb $0x1, %al
jne 0x3f229
jmp 0x3f374
leaq -0xc8(%rbp), %rdi
callq 0x40ae0
movl (%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x1d480
movq %rax, -0x178(%rbp)
jmp 0x3f250
movq -0x178(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x180(%rbp)
jmp 0x3f269
movq -0x180(%rbp), %rdi
callq 0x17700
movq %rax, -0x188(%rbp)
jmp 0x3f27e
movq -0x188(%rbp), %rax
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x68(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x3f302
leaq -0x90(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x40b10
jmp 0x3f2c2
jmp 0x3f35a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x40c40
leaq -0xa8(%rbp), %rdi
callq 0x40c40
leaq -0x90(%rbp), %rdi
callq 0x40c40
jmp 0x3f910
movl -0x68(%rbp), %eax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
movq -0x50(%rbp), %rdx
addl (%rdx), %ecx
cmpl %ecx, %eax
jge 0x3f329
leaq -0xa8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x40b10
jmp 0x3f327
jmp 0x3f358
movl -0x68(%rbp), %eax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
movq -0x50(%rbp), %rdx
addl (%rdx), %ecx
movq -0x60(%rbp), %rdx
addl (%rdx), %ecx
cmpl %ecx, %eax
jge 0x3f356
leaq -0xc0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x40b10
jmp 0x3f354
jmp 0x3f356
jmp 0x3f358
jmp 0x3f35a
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x273e0
jmp 0x3f1fd
leaq -0x90(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x40bc0
movq -0x190(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x40bf0
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x40b80
jmp 0x3f3b6
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x40bc0
movq -0x198(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x40bf0
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x40b80
jmp 0x3f3f8
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x40bc0
movq -0x1a0(%rbp), %rdi
movq %rax, -0x108(%rbp)
callq 0x40bf0
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x40b80
jmp 0x3f43a
movl $0x1, -0x114(%rbp)
cmpl $0xb, -0x114(%rbp)
jg 0x3f8e3
movq -0x28(%rbp), %rdi
movl -0x114(%rbp), %esi
callq 0x299d0
movq %rax, -0x1a8(%rbp)
jmp 0x3f469
movq -0x1a8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x3f47b
jmp 0x3f8cf
movq -0x28(%rbp), %rdi
movl -0x114(%rbp), %esi
callq 0x299d0
movq %rax, -0x1b0(%rbp)
jmp 0x3f493
movq -0x1b0(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1b4(%rbp)
subl $0x1, %eax
je 0x3f70e
jmp 0x3f4bc
movl -0x1b4(%rbp), %eax
subl $0x2, %eax
je 0x3f5f6
jmp 0x3f4cd
movl -0x1b4(%rbp), %eax
subl $0x3, %eax
jne 0x3f826
jmp 0x3f4de
movl $0x0, -0x124(%rbp)
cmpl $0x4, -0x124(%rbp)
jge 0x3f5f1
movq -0x170(%rbp), %rdi
addq $0x60, %rdi
movslq -0x124(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x130(%rbp), %rsi
callq 0x40a10
movq %rax, -0x1c0(%rbp)
jmp 0x3f523
movq -0x1c0(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0xcd8(%rax)
jne 0x3f5db
movq -0x170(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0x1d0(%rbp)
addq $0x60, %rdi
movslq -0x124(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x40a10
movq %rax, -0x1c8(%rbp)
jmp 0x3f577
movq -0x1c8(%rbp), %rax
movq (%rax), %rax
addq $0x60, %rax
movq %rax, -0x1e0(%rbp)
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
decl %eax
movslq %eax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x40c20
movq -0x1e0(%rbp), %rdi
movq %rax, %rsi
callq 0x40240
movq %rax, -0x1d8(%rbp)
jmp 0x3f5bf
movq -0x1d8(%rbp), %rax
movq -0x1d0(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x3f5dd
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x3f4e8
jmp 0x3f8cd
movl $0x0, -0x13c(%rbp)
cmpl $0x4, -0x13c(%rbp)
jge 0x3f709
movq -0x170(%rbp), %rdi
addq $0x60, %rdi
movslq -0x13c(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x148(%rbp), %rsi
callq 0x40a10
movq %rax, -0x1e8(%rbp)
jmp 0x3f63b
movq -0x1e8(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0xcd8(%rax)
jne 0x3f6f3
movq -0x170(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0x1f8(%rbp)
addq $0x60, %rdi
movslq -0x13c(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x150(%rbp), %rsi
callq 0x40a10
movq %rax, -0x1f0(%rbp)
jmp 0x3f68f
movq -0x1f0(%rbp), %rax
movq (%rax), %rax
addq $0x60, %rax
movq %rax, -0x208(%rbp)
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
decl %eax
movslq %eax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x40c20
movq -0x208(%rbp), %rdi
movq %rax, %rsi
callq 0x40240
movq %rax, -0x200(%rbp)
jmp 0x3f6d7
movq -0x200(%rbp), %rax
movq -0x1f8(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x3f6f5
movl -0x13c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x3f600
jmp 0x3f8cd
movl $0x0, -0x154(%rbp)
cmpl $0x4, -0x154(%rbp)
jge 0x3f821
movq -0x170(%rbp), %rdi
addq $0x60, %rdi
movslq -0x154(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0x160(%rbp), %rsi
callq 0x40a10
movq %rax, -0x210(%rbp)
jmp 0x3f753
movq -0x210(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0xcd8(%rax)
jne 0x3f80b
movq -0x170(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0x220(%rbp)
addq $0x60, %rdi
movslq -0x154(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x168(%rbp), %rsi
callq 0x40a10
movq %rax, -0x218(%rbp)
jmp 0x3f7a7
movq -0x218(%rbp), %rax
movq (%rax), %rax
addq $0x60, %rax
movq %rax, -0x230(%rbp)
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
decl %eax
movslq %eax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x40c20
movq -0x230(%rbp), %rdi
movq %rax, %rsi
callq 0x40240
movq %rax, -0x228(%rbp)
jmp 0x3f7ef
movq -0x228(%rbp), %rax
movq -0x220(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x3f80d
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x3f718
jmp 0x3f8cd
jmp 0x3f828
movq 0xbe7c1(%rip), %rdi     # 0xfdff0
leaq 0x82db7(%rip), %rsi     # 0xc25ed
callq 0xa5a0
movq %rax, -0x238(%rbp)
jmp 0x3f844
movq -0x238(%rbp), %rdi
leaq 0x859ff(%rip), %rsi     # 0xc5251
callq 0xa5a0
movq %rax, -0x240(%rbp)
jmp 0x3f860
movq -0x240(%rbp), %rdi
movl $0x3d3, %esi            # imm = 0x3D3
callq 0xaa40
movq %rax, -0x248(%rbp)
jmp 0x3f87a
movq -0x248(%rbp), %rdi
leaq 0x83cd7(%rip), %rsi     # 0xc355f
callq 0xa5a0
movq %rax, -0x250(%rbp)
jmp 0x3f896
movq -0x250(%rbp), %rdi
leaq 0x82d5e(%rip), %rsi     # 0xc2602
callq 0xa5a0
movq %rax, -0x258(%rbp)
jmp 0x3f8b2
movq -0x258(%rbp), %rdi
movq 0xbe6f0(%rip), %rsi     # 0xfdfb0
callq 0xa630
jmp 0x3f8c7
jmp 0x3f8c9
jmp 0x3f8cb
jmp 0x3f8cd
jmp 0x3f8cf
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x3f444
leaq -0xc0(%rbp), %rdi
callq 0x40c40
leaq -0xa8(%rbp), %rdi
callq 0x40c40
leaq -0x90(%rbp), %rdi
callq 0x40c40
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
movq -0xd8(%rbp), %rdi
callq 0xaa60
nopl (%rax)