// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, %r14
testl %esi, %esi
movq %rdx, -0x50(%rbp)
je 0x26cfe
cmpl $0x1, %esi
jne 0x26d9a
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf4b0
movsd 0x43924(%rip), %xmm0    # 0x6a620
jmp 0x26d70
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf4b0
cmpl $0x2, 0xa4(%rax)
movq 0x8(%r14), %rdi
leaq 0x643cb(%rip), %rax     # 0x8b0e8
leaq 0x643ac(%rip), %rcx     # 0x8b0d0
cmoveq %rax, %rcx
leaq 0x64399(%rip), %rax     # 0x8b0c8
leaq 0x6437a(%rip), %rdx     # 0x8b0b0
cmoveq %rax, %rdx
cmpb $0x0, 0xc(%rdi)
cmovneq %rcx, %rdx
movq (%rdx), %rax
movq %rax, 0x10(%r14)
leaq 0x38(%rdi), %rsi
callq 0xf4b0
cmpl $0x2, 0xa4(%rax)
jne 0x26db5
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf4b0
movsd 0x438b8(%rip), %xmm0    # 0x6a628
ucomisd 0x90(%rax), %xmm0
movq 0x8(%r14), %rax
movb 0xc(%rax), %al
leaq 0x642ea(%rip), %rcx     # 0x8b070
jbe 0x26da3
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
movq 0x40(%rax,%rcx), %rax
jmp 0x26e7a
movq 0x18(%r14), %rax
jmp 0x26e7e
xorb $0x1, %al
movzbl %al, %eax
shll $0x5, %eax
movq 0x48(%rax,%rcx), %rax
jmp 0x26e7a
callq 0x49360
movq %rax, %r15
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf4b0
movsd 0x90(%rax), %xmm0
movsd 0x3830(%r15), %xmm1
addsd 0x42295(%rip), %xmm1    # 0x69078
ucomisd %xmm1, %xmm0
jb 0x26e60
movsd 0x3838(%r15), %xmm1
addsd 0x42246(%rip), %xmm1    # 0x69040
ucomisd %xmm0, %xmm1
jb 0x26e60
movsd 0x98(%rax), %xmm0
movsd 0x3840(%r15), %xmm1
addsd 0x4225f(%rip), %xmm1    # 0x69078
ucomisd %xmm1, %xmm0
jb 0x26e60
movsd 0x3848(%r15), %xmm1
addsd 0x42210(%rip), %xmm1    # 0x69040
ucomisd %xmm0, %xmm1
jb 0x26e60
movq 0x8(%r14), %rdi
leaq 0x38(%rdi), %rsi
callq 0xf4b0
cmpb $0x1, 0x41(%rax)
jne 0x26e60
movq 0x8(%r14), %rax
movzbl 0xc(%rax), %eax
leaq 0x64218(%rip), %rcx     # 0x8b070
xorl $0x1, %eax
jmp 0x26d8d
movq 0x8(%r14), %rax
movzbl 0xc(%rax), %eax
leaq 0x64201(%rip), %rcx     # 0x8b070
xorl $0x1, %eax
shll $0x5, %eax
movq 0x58(%rax,%rcx), %rax
movq %rax, 0x18(%r14)
leaq 0x20(%r14), %rdi
movq 0x10(%r14), %rcx
movl 0x8(%rcx), %ecx
movl 0x8(%rax), %eax
shlq $0x20, %rax
orq %rcx, %rax
leaq -0x38(%rbp), %rsi
movq %rax, (%rsi)
callq 0x285b2
callq 0x34c60
leaq 0x43795(%rip), %rsi     # 0x6a640
movq %rax, %rdi
callq 0x34e74
movq %rax, %r15
movq 0x8(%r14), %rax
movq 0x18(%rax), %r12
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x26ee2
addq $0x10, %r12
movq %r15, %rdi
addq $0x210, %rdi            # imm = 0x210
movq %r12, %rsi
callq 0xe974
leaq 0x4376b(%rip), %rsi     # 0x6a654
movq %r15, %rdi
callq 0x27b08
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 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x26f47
movq %r15, %rdi
addq $0x210, %rdi            # imm = 0x210
leaq -0x38(%rbp), %rsi
callq 0x2881c
leaq 0x43703(%rip), %rsi     # 0x6a651
movq %r15, %rdi
callq 0x27b52
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 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x26fc5
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 0x4448c(%rip), %rsi     # 0x6b458
movq %r15, %rdi
callq 0x27b08
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x27b9c
movq %rax, %rbx
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x27026
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