// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rdi, %r14
testl %esi, %esi
je 0x2101f
cmpl $0x1, %esi
jne 0x210af
movq 0x8(%r14), %rdi
callq 0xdd50
movsd 0x375d3(%rip), %xmm0    # 0x585f0
jmp 0x21085
movq 0x8(%r14), %rdi
callq 0xdd50
cmpl $0x2, 0xa4(%rax)
movq 0x8(%r14), %rdi
leaq 0x5d0ae(%rip), %rax     # 0x7e0e8
leaq 0x5d08f(%rip), %rcx     # 0x7e0d0
cmoveq %rax, %rcx
leaq 0x5d07c(%rip), %rax     # 0x7e0c8
leaq 0x5d05d(%rip), %rdx     # 0x7e0b0
cmoveq %rax, %rdx
cmpb $0x0, 0xc(%rdi)
cmovneq %rcx, %rdx
movq (%rdx), %rax
movq %rax, 0x10(%r14)
callq 0xdd50
cmpl $0x2, 0xa4(%rax)
jne 0x210c7
movq 0x8(%r14), %rdi
callq 0xdd50
movsd 0x37573(%rip), %xmm0    # 0x585f8
ucomisd 0x90(%rax), %xmm0
movq 0x8(%r14), %rax
movb 0xc(%rax), %al
leaq 0x5cfd5(%rip), %rcx     # 0x7e070
jbe 0x210b8
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
movq 0x40(%rax,%rcx), %rax
jmp 0x21140
movq 0x18(%r14), %rax
jmp 0x21144
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
movq 0x48(%rax,%rcx), %rax
jmp 0x21140
callq 0x3db2c
leaq 0x3830(%rax), %r15
movq 0x8(%r14), %rdi
callq 0xdd50
leaq 0x90(%rax), %rsi
movabsq $0x3ed92a737110e454, %rax # imm = 0x3ED92A737110E454
leaq -0x38(%rbp), %rdx
movq %rax, (%rdx)
movq %r15, %rdi
callq 0x12516
testb %al, %al
je 0x21126
movq 0x8(%r14), %rdi
callq 0xdd50
cmpb $0x1, 0x41(%rax)
jne 0x21126
movq 0x8(%r14), %rax
movzbl 0xc(%rax), %eax
leaq 0x5cf52(%rip), %rcx     # 0x7e070
xorl $0x1, %eax
jmp 0x210a2
movq 0x8(%r14), %rax
movzbl 0xc(%rax), %eax
leaq 0x5cf3b(%rip), %rcx     # 0x7e070
xorl $0x1, %eax
shll $0x5, %eax
movq 0x58(%rax,%rcx), %rax
movq %rax, 0x18(%r14)
leaq 0x20(%r14), %r15
movq 0x10(%r14), %rcx
movl 0x8(%rcx), %ecx
movl 0x8(%rax), %eax
shlq $0x20, %rax
orq %rcx, %rax
leaq -0x38(%rbp), %r12
movq %rax, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2289c
callq 0x2ca2e
leaq 0x37498(%rip), %rsi     # 0x58610
movq %rax, %rdi
callq 0x2cc3e
movq 0x8(%r14), %rcx
movq 0x18(%rcx), %rsi
addq $0x10, %rsi
movq %rax, %rdi
callq 0x10e94
leaq 0x37489(%rip), %rsi     # 0x58624
movq %rax, %rdi
callq 0x21b92
movq %rax, %r13
movq 0x8(%r14), %rdi
callq 0x21bf6
movq %rax, (%r12)
movl %edx, 0x8(%r12)
shrq $0x20, %rdx
movb %dl, 0xc(%r12)
leaq -0x38(%rbp), %rsi
movq %r13, %rdi
callq 0x21bc4
leaq 0x3744d(%rip), %rsi     # 0x58621
movq %rax, %rdi
callq 0x21c1c
movq %rax, %r14
movq %r15, %rdi
callq 0x2296e
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq %r14, %rdi
callq 0x21c4e
leaq 0x38223(%rip), %rsi     # 0x59420
movq %rax, %rdi
callq 0x21b92
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21c80
movq 0x55d99(%rip), %rsi     # 0x76fb0
movq %rax, %rdi
callq 0x10f5c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq