// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rdx, -0x50(%rbp)
movq %rdi, %r14
cmpl $0x1, %esi
je 0x27588
testl %esi, %esi
jne 0x276ba
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf5c4
movq 0x8(%r14), %rdi
movzbl 0xc(%rdi), %ecx
shll $0x5, %ecx
cmpl $0x2, 0xa4(%rax)
movl $0x58, %eax
movl $0x40, %edx
cmoveq %rax, %rdx
orq %rcx, %rdx
leaq 0x66b44(%rip), %r12     # 0x8e070
movq (%r12,%rdx), %rax
movq %rax, 0x10(%r14)
leaq 0x38(%rdi), %rsi
callq 0xf5c4
cmpl $0x2, 0xa4(%rax)
jne 0x275cd
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf5c4
movsd 0x450d9(%rip), %xmm0    # 0x6c638
ucomisd 0x90(%rax), %xmm0
movq 0x8(%r14), %rax
movb 0xc(%rax), %al
jbe 0x276a4
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
addq %r12, %rax
addq $0x40, %rax
jmp 0x276b3
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf5c4
movsd 0x45093(%rip), %xmm0    # 0x6c630
ucomisd 0x90(%rax), %xmm0
movq 0x8(%r14), %rax
movb 0xc(%rax), %al
jbe 0x27675
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
leaq 0x66aaf(%rip), %rcx     # 0x8e070
addq %rcx, %rax
addq $0x40, %rax
jmp 0x276b3
callq 0x4a75c
movq %rax, %r15
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf5c4
movsd 0x90(%rax), %xmm0
movsd 0x3830(%r15), %xmm1
addsd 0x43a7d(%rip), %xmm1    # 0x6b078
ucomisd %xmm1, %xmm0
jb 0x2768d
movsd 0x3838(%r15), %xmm1
addsd 0x43a2a(%rip), %xmm1    # 0x6b040
ucomisd %xmm0, %xmm1
jb 0x2768d
movsd 0x98(%rax), %xmm0
movsd 0x3840(%r15), %xmm1
addsd 0x43a43(%rip), %xmm1    # 0x6b078
ucomisd %xmm1, %xmm0
jb 0x2768d
movsd 0x3848(%r15), %xmm1
addsd 0x439f4(%rip), %xmm1    # 0x6b040
ucomisd %xmm0, %xmm1
jb 0x2768d
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf5c4
cmpb $0x1, 0x41(%rax)
jne 0x2768d
movq 0x8(%r14), %rax
movzbl 0xc(%rax), %eax
xorl $0x1, %eax
jmp 0x27579
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
leaq 0x669ec(%rip), %rcx     # 0x8e070
addq %rcx, %rax
addq $0x48, %rax
jmp 0x276b3
movq 0x8(%r14), %rax
movzbl 0xc(%rax), %eax
xorl $0x1, %eax
shll $0x5, %eax
addq %r12, %rax
addq $0x58, %rax
jmp 0x276b3
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
addq %r12, %rax
addq $0x48, %rax
movq (%rax), %rax
movq %rax, 0x18(%r14)
leaq 0x20(%r14), %rdi
movq 0x10(%r14), %rax
movq 0x18(%r14), %rcx
movl 0x8(%rax), %eax
movl 0x8(%rcx), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
leaq -0x38(%rbp), %rsi
movq %rcx, (%rsi)
callq 0x28e0e
callq 0x35b4a
leaq 0x44f65(%rip), %rsi     # 0x6c650
movq %rax, %rdi
callq 0x35d5e
movq %rax, %r15
movq 0x8(%r14), %rax
movq 0x18(%rax), %r12
callq 0x450ba
cmpb $0x1, 0x5c45(%rax)
jne 0x27722
addq $0x10, %r12
movq %r15, %rdi
addq $0x210, %rdi            # imm = 0x210
movq %r12, %rsi
callq 0xea74
leaq 0x44f3b(%rip), %rsi     # 0x6c664
movq %r15, %rdi
callq 0x2833e
movq %rax, %r15
movq 0x8(%r14), %rax
movl 0x8(%rax), %ecx
movq 0x18(%rax), %rdx
movq 0x10(%rdx), %rdx
movb 0xc(%rax), %al
movl %ecx, -0x38(%rbp)
movq %rdx, -0x34(%rbp)
movb %al, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rax, -0x38(%rbp)
movl %ecx, -0x30(%rbp)
shrq $0x20, %rcx
movb %cl, -0x2c(%rbp)
callq 0x450ba
cmpb $0x1, 0x5c45(%rax)
jne 0x27787
movq %r15, %rdi
addq $0x210, %rdi            # imm = 0x210
leaq -0x38(%rbp), %rsi
callq 0x29072
leaq 0x44ed3(%rip), %rsi     # 0x6c661
movq %r15, %rdi
callq 0x28388
movq %rax, %r15
movq 0x68(%r14), %r13
movq 0x48(%r14), %rbx
movq 0x50(%r14), %r12
movq 0x58(%r14), %rax
movq %rax, -0x40(%rbp)
movq 0x30(%r14), %rax
movq %rax, -0x48(%rbp)
movq 0x40(%r14), %r14
callq 0x450ba
cmpb $0x1, 0x5c45(%rax)
jne 0x27805
movq %r13, %rax
subq %rbx, %rax
shrq $0x3, %rax
cmpq $0x1, %r13
adcq $-0x1, %rax
shlq $0x6, %rax
subq -0x40(%rbp), %r12
sarq $0x3, %r12
subq -0x48(%rbp), %r14
sarq $0x3, %r14
addq %r12, %r14
addq %rax, %r14
movq %r15, %rdi
addq $0x210, %rdi            # imm = 0x210
movq %r14, %rsi
callq 0x9320
leaq 0x45c74(%rip), %rsi     # 0x6d480
movq %r15, %rdi
callq 0x2833e
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x283d2
movq %rax, %rbx
callq 0x450ba
cmpb $0x1, 0x5c45(%rax)
jne 0x27866
movq %rbx, %r14
addq $0x210, %r14            # imm = 0x210
movq 0x210(%rbx), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r14, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop