// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/Formation.cpp
// Function: Formation::Update(Formation::UpdatePolicy, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Formation::Update(UpdatePolicy policy, std::string update_name) {
  switch (policy) {
  case Offensive:
    if (mAgent.GetStrategy().GetSituation() != ST_Defense) {
      SetTeammateFormationType(FT_Attack_Forward);
    } else {
      SetTeammateFormationType(FT_Defend_Back);
    }

    // TODO: 对手的阵型分析，这里WE2008用的比较混乱，可能会有bug
    if (mAgent.GetStrategy().GetSituation() != ST_Defense) {
      if (ServerParam::instance().ourPenaltyArea().IsWithin(
              mAgent.GetStrategy().GetBallInterPos()) &&
          mAgent.GetStrategy().IsBallFree()) {
        SetOpponentFormationType(FT_Attack_Forward); // 认为对手还处于进攻状态
      } else {
        SetOpponentFormationType(FT_Defend_Back);
      }
    } else {
      if (mAgent.GetStrategy().GetBallInterPos().X() < -26.0) {
        SetOpponentFormationType(FT_Attack_Forward);
      } else {
        SetOpponentFormationType(FT_Attack_Midfield);
      }
    }
    break;

  case Defensive:
    if (mAgent.GetStrategy().GetBallInterPos().X() < -30.0) {
      SetOpponentFormationType(FT_Attack_Forward);
    } else {
      SetOpponentFormationType(FT_Attack_Midfield);
    }
    break;
  }

  mFormationTypeStack.push(make_pair(mpTeammateFormation->GetFormationType(),
                                     mpOpponentFormation->GetFormationType()));

  Logger::instance().GetTextLogger("formation_update")
      << mAgent.GetWorldState().CurrentTime() << ", " << mAgent.GetAgentID()
      << ", +, " << mFormationTypeStack.size() << ": " << update_name << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdx, -0x70(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x5c(%rbp)
testl %eax, %eax
je 0x3e5ef
jmp 0x3e5de
movl -0x5c(%rbp), %eax
subl $0x1, %eax
je 0x3e71e
jmp 0x3e766
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x14050
movq %rax, %rdi
callq 0x406a0
cmpl $0x2, (%rax)
je 0x3e616
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x3e4d0
jmp 0x3e624
movq -0x68(%rbp), %rdi
movl $0x3, %esi
callq 0x3e4d0
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x14050
movq %rax, %rdi
callq 0x406a0
cmpl $0x2, (%rax)
je 0x3e6d4
callq 0x855e0
movq %rax, %rdi
callq 0x1fe50
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x80(%rbp)
movq 0x8(%rax), %rdi
callq 0x14050
movq %rax, %rdi
callq 0x14080
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movsd 0x8298e(%rip), %xmm0    # 0xc1008
movsd %xmm0, -0x20(%rbp)
leaq -0x20(%rbp), %rdx
callq 0x1d850
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x71(%rbp)
jne 0x3e696
jmp 0x3e6ae
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x14050
movq %rax, %rdi
callq 0x406c0
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x3e6b7
jmp 0x3e6c4
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x3e540
jmp 0x3e6d2
movq -0x68(%rbp), %rdi
movl $0x3, %esi
callq 0x3e540
jmp 0x3e71c
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x14050
movq %rax, %rdi
callq 0x14080
movq %rax, %rdi
callq 0x176f0
movsd 0x8365f(%rip), %xmm0    # 0xc1d58
ucomisd (%rax), %xmm0
jbe 0x3e70c
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x3e540
jmp 0x3e71a
movq -0x68(%rbp), %rdi
movl $0x1, %esi
callq 0x3e540
jmp 0x3e71c
jmp 0x3e766
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x14050
movq %rax, %rdi
callq 0x14080
movq %rax, %rdi
callq 0x176f0
movsd 0x83e1d(%rip), %xmm0    # 0xc2560
ucomisd (%rax), %xmm0
jbe 0x3e756
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x3e540
jmp 0x3e764
movq -0x68(%rbp), %rdi
movl $0x1, %esi
callq 0x3e540
jmp 0x3e766
movq -0x68(%rbp), %rax
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, -0xa0(%rbp)
movq 0x10(%rax), %rdi
callq 0x40740
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, -0x2c(%rbp)
movq 0x18(%rax), %rdi
callq 0x40740
movl %eax, -0x30(%rbp)
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40710
movq -0xa0(%rbp), %rdi
movq %rax, -0x28(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x406e0
callq 0x5add0
movq %rax, %rdi
leaq 0x83db2(%rip), %rsi     # 0xc2578
callq 0x5b110
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x98(%rbp)
movq 0x8(%rax), %rdi
callq 0x10550
movq %rax, %rdi
callq 0x12100
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x1a640
movq %rax, %rdi
leaq 0x83d89(%rip), %rsi     # 0xc258c
callq 0x40760
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x90(%rbp)
movq 0x8(%rax), %rdi
callq 0x40800
movq -0x90(%rbp), %rdi
movq %rdx, -0x48(%rbp)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x38(%rbp)
movb -0x44(%rbp), %al
movb %al, -0x34(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x407b0
movq %rax, %rdi
leaq 0x83d34(%rip), %rsi     # 0xc2589
callq 0x40860
movq -0x68(%rbp), %rdi
movq %rax, -0x88(%rbp)
addq $0x20, %rdi
callq 0x40900
movq -0x88(%rbp), %rdi
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x408b0
movq %rax, %rdi
leaq 0x84cd4(%rip), %rsi     # 0xc3560
callq 0x40760
movq -0x70(%rbp), %rsi
movq %rax, %rdi
callq 0x40920
movq %rax, %rdi
movq 0xbf709(%rip), %rsi     # 0xfdfb0
callq 0x1a7c0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)