// File: /workspace/github_cpp_makefile_star2_O1/wrighteagle2d[P]wrighteaglebase/Debug/../src/Trainer.cpp
// Function: Trainer::Condition::CheckState(WorldState const&)
bool Trainer::Condition::CheckState(const WorldState &state) {
  //检测当前状态的条件
  bool result = false;
  switch (mType) {
  case ET_ANDComplex:
    if (!mSubCondition.empty()) {
      for (std::vector<Trainer::Condition>::iterator it = mSubCondition.begin();
           it != mSubCondition.end(); it++) {
        if (!it->CheckState(state)) {
          return false; //有一个不满足就不满足
        }
      }
    }
    break;
  case ET_ORComplex:
    if (!mSubCondition.empty()) {
      for (std::vector<Trainer::Condition>::iterator it = mSubCondition.begin();
           it != mSubCondition.end(); it++) {
        if (it->CheckState(state)) {
          return true; //有一个满足就满足
        }
      }
    }
    break;
  case ET_Time: //过x个周期自然终止
    if (state.CurrentTime().T() - mpTrainer->GetLastStopTime() >= mArg1) {
      std::cout << "Trigger time longer than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_BallXbt: //球的x坐标大于某值停止
    if ((state.GetBall().GetPos().X() > mArg1 && !mConverse) ||
        (!state.GetBall().GetPos().X() > mArg1 && mConverse)) {
      std::cout << "Trigger Ball's X larger than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_BallXlt: //球的x坐标小于某值停止
    if ((state.GetBall().GetPos().X() < mArg1 && !mConverse) ||
        (!state.GetBall().GetPos().X() < mArg1 && mConverse)) {
      std::cout << "Trigger Ball's X less than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_BallYbt: //球的y坐标。。
    if ((state.GetBall().GetPos().Y() > mArg1 && !mConverse) ||
        (!state.GetBall().GetPos().Y() > mArg1 && mConverse)) {
      std::cout << "Trigger Ball's Y larger than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_BallYlt: //。。
    if ((state.GetBall().GetPos().Y() < mArg1 && !mConverse) ||
        (!state.GetBall().GetPos().Y() < mArg1 && mConverse)) {
      std::cout << "Trigger Ball's Y less than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_Ball2Playerbt: //球到某人的距离大于某值
    if (!mArg2) {
      for (int i = 1; i <= TEAMSIZE; i++) {
        if (state.GetOpponent(i).IsAlive())
          if (state.GetOpponent(i).GetPos().Dist(state.GetBall().GetPos()) >
              mArg1) {
            std::cout << "Trigger Ball to #" << i
                      << "Player's distance longer than " << mArg1 << std::endl;
            result = true;
            break;
          }
      }
      break;
    }
    if (state.GetBall().GetPos().Dist(state.GetPlayer(mArg2).GetPos()) >
        mArg1) {
      std::cout << "Trigger Ball to #" << mArg2
                << "Player's distance longer than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_Ball2Playerlt: //球到某人的距离小于某值
    if (!mArg2) {
      for (int i = 1; i <= TEAMSIZE; i++) {
        if (state.GetOpponent(i).IsAlive())
          if (state.GetOpponent(i).GetPos().Dist(state.GetBall().GetPos()) <
              mArg1) {
            std::cout << "Trigger Ball to #" << i
                      << "Player's distance less than " << mArg1 << std::endl;
            result = true;
            break;
          }
      }
      break;
    }
    if (state.GetBall().GetPos().Dist(state.GetPlayer(mArg2).GetPos()) <
        mArg1) {
      std::cout << "Trigger Ball to #" << mArg2
                << "Player's distance less than " << mArg1 << std::endl;
      result = true;
    }
    break;
  case ET_NonPlayOn:
    if (state.GetPlayMode() != PM_Play_On) {
      result = true;
      std::cout << "Trigger NonPlayOn" << std::endl;
    }
    break;
  case ET_Null:
    break;
  }

  if (result) //满足终止条件了
  {
    int intervalCycle = state.CurrentTime().T() - mpTrainer->GetLastStopTime();
    if (intervalCycle > mMaxInterval) {
      mMaxInterval = intervalCycle;
      mMaxTime = state.CurrentTime().T();
    }
    if (intervalCycle < mMinInterval) {
      mMinInterval = intervalCycle;
      mMinTime = state.CurrentTime().T();
    }
    mCount++;
  }

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl (%rdi), %eax
decl %eax
cmpl $0x9, %eax
ja 0x51ab8
leaq 0x1d6f2(%rip), %rcx     # 0x6ecb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x10(%r14), %eax
movq 0x38(%rbx), %rcx
subl 0x194(%rcx), %eax
cvtsi2sd %eax, %xmm0
ucomisd 0x8(%rbx), %xmm0
jb 0x51ab8
movq 0x359d5(%rip), %r15     # 0x86fc0
leaq 0x1d84b(%rip), %rsi     # 0x6ee3d
movl $0x19, %edx
jmp 0x517ab
movsd 0x40(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x51613
cmpb $0x1, 0x54(%rbx)
jne 0x5163c
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x19a34(%rip), %xmm2    # 0x6b058
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x51ab8
cmpb $0x1, 0x54(%rbx)
jne 0x51ab8
movq 0x3597d(%rip), %r15     # 0x86fc0
leaq 0x1d865(%rip), %rsi     # 0x6eeaf
jmp 0x516d0
movq 0x18(%rbx), %r12
cmpq 0x20(%rbx), %r12
je 0x51ab8
xorl %r15d, %r15d
movq %r12, %rdi
movq %r14, %rsi
callq 0x51596
testb %al, %al
jne 0x519d4
addq $0x58, %r12
cmpq 0x20(%rbx), %r12
jne 0x51660
jmp 0x51abb
movsd 0x38(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x51699
cmpb $0x1, 0x54(%rbx)
jne 0x516c2
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x199ae(%rip), %xmm2    # 0x6b058
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x51ab8
cmpb $0x1, 0x54(%rbx)
jne 0x51ab8
movq 0x358f7(%rip), %r15     # 0x86fc0
leaq 0x1d7a5(%rip), %rsi     # 0x6ee75
movl $0x1b, %edx
jmp 0x517ab
movsd 0x40(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x516f1
cmpb $0x1, 0x54(%rbx)
jne 0x5171a
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x19956(%rip), %xmm2    # 0x6b058
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x51ab8
cmpb $0x1, 0x54(%rbx)
jne 0x51ab8
movq 0x3589f(%rip), %r15     # 0x86fc0
leaq 0x1d769(%rip), %rsi     # 0x6ee91
jmp 0x517a6
cmpl $0x1, 0x1c(%r14)
je 0x51ab8
movq 0x35884(%rip), %r15     # 0x86fc0
leaq 0x1d7d6(%rip), %rsi     # 0x6ef19
movl $0x11, %edx
movq %r15, %rdi
callq 0x9560
movq (%r15), %rax
jmp 0x51a8f
movsd 0x38(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x5176f
cmpb $0x1, 0x54(%rbx)
jne 0x51798
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x198d8(%rip), %xmm2    # 0x6b058
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x51ab8
cmpb $0x1, 0x54(%rbx)
jne 0x51ab8
movq 0x35821(%rip), %r15     # 0x86fc0
leaq 0x1d6b1(%rip), %rsi     # 0x6ee57
movl $0x1d, %edx
movq %r15, %rdi
jmp 0x51a77
movsd 0x10(%rbx), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x517c8
jnp 0x518d0
cvttsd2si %xmm0, %eax
leal -0x1(%rax), %ecx
leaq 0x10d0(%r14), %rdx
testl %eax, %eax
notl %eax
cmovgl %ecx, %eax
leaq 0xa8(%r14), %rcx
cmovleq %rdx, %rcx
cltq
imulq $0x178, %rax, %rax      # imm = 0x178
movsd 0x38(%r14), %xmm0
subsd 0x8(%rcx,%rax), %xmm0
movsd 0x40(%r14), %xmm1
subsd 0x10(%rcx,%rax), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x519e4
sqrtsd %xmm0, %xmm0
jmp 0x519e9
movsd 0x10(%rbx), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x5183d
jnp 0x51950
cvttsd2si %xmm0, %eax
leal -0x1(%rax), %ecx
leaq 0x10d0(%r14), %rdx
testl %eax, %eax
notl %eax
cmovgl %ecx, %eax
leaq 0xa8(%r14), %rcx
cmovleq %rdx, %rcx
cltq
imulq $0x178, %rax, %rax      # imm = 0x178
movsd 0x38(%r14), %xmm0
subsd 0x8(%rcx,%rax), %xmm0
movsd 0x40(%r14), %xmm1
subsd 0x10(%rcx,%rax), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x51a2d
sqrtsd %xmm0, %xmm0
jmp 0x51a32
movq 0x18(%rbx), %r12
cmpq 0x20(%rbx), %r12
je 0x51ab8
xorl %r15d, %r15d
movq %r12, %rdi
movq %r14, %rsi
callq 0x51596
testb %al, %al
je 0x519dc
addq $0x58, %r12
cmpq 0x20(%rbx), %r12
jne 0x518ae
jmp 0x51abb
leaq 0x10d8(%r14), %r13
movb $0x1, %r15b
movl $0x1, %r12d
cmpb $0x1, 0x10a(%r13)
jne 0x5192e
movsd (%r13), %xmm0
subsd 0x38(%r14), %xmm0
movsd 0x8(%r13), %xmm1
subsd 0x40(%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x5191a
sqrtsd %xmm0, %xmm0
jmp 0x51923
callq 0x93c0
xorpd %xmm2, %xmm2
ucomisd 0x8(%rbx), %xmm0
ja 0x51b00
cmpq $0xb, %r12
leaq 0x1(%r12), %rax
setb %r15b
addq $0x178, %r13            # imm = 0x178
movq %rax, %r12
cmpq $0xc, %rax
jne 0x518e0
jmp 0x51abb
leaq 0x10d8(%r14), %r13
movb $0x1, %r15b
movl $0x1, %r12d
cmpb $0x1, 0x10a(%r13)
jne 0x519b2
movsd (%r13), %xmm0
subsd 0x38(%r14), %xmm0
movsd 0x8(%r13), %xmm1
subsd 0x40(%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x5199a
sqrtsd %xmm0, %xmm0
jmp 0x519a3
callq 0x93c0
xorpd %xmm2, %xmm2
movsd 0x8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
ja 0x51b37
cmpq $0xb, %r12
leaq 0x1(%r12), %rax
setb %r15b
addq $0x178, %r13            # imm = 0x178
movq %rax, %r12
cmpq $0xc, %rax
jne 0x51960
jmp 0x51abb
movb $0x1, %r15b
jmp 0x51aea
xorl %r15d, %r15d
jmp 0x51aea
callq 0x93c0
ucomisd 0x8(%rbx), %xmm0
jbe 0x51ab8
movq 0x355c5(%rip), %r15     # 0x86fc0
leaq 0x1d4c9(%rip), %rsi     # 0x6eecb
movl $0x11, %edx
movq %r15, %rdi
callq 0x9560
movsd 0x10(%rbx), %xmm0
movq %r15, %rdi
callq 0x97d0
movq %rax, %r15
leaq 0x1d4b7(%rip), %rsi     # 0x6eedd
movl $0x1e, %edx
jmp 0x51a74
callq 0x93c0
movsd 0x8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x51ab8
movq 0x3557c(%rip), %r15     # 0x86fc0
leaq 0x1d480(%rip), %rsi     # 0x6eecb
movl $0x11, %edx
movq %r15, %rdi
callq 0x9560
movsd 0x10(%rbx), %xmm0
movq %r15, %rdi
callq 0x97d0
movq %rax, %r15
leaq 0x1d48d(%rip), %rsi     # 0x6eefc
movl $0x1c, %edx
movq %rax, %rdi
callq 0x9560
movsd 0x8(%rbx), %xmm0
movq %r15, %rdi
callq 0x97d0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r15, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
movb $0x1, %r15b
jmp 0x51abb
xorl %r15d, %r15d
testb $0x1, %r15b
je 0x51aea
movl 0x10(%r14), %eax
movq 0x38(%rbx), %rdx
movl %eax, %ecx
subl 0x194(%rdx), %ecx
cmpl 0x40(%rbx), %ecx
jle 0x51adc
movl %ecx, 0x40(%rbx)
movl %eax, 0x4c(%rbx)
cmpl 0x44(%rbx), %ecx
jge 0x51ae7
movl %ecx, 0x44(%rbx)
movl %eax, 0x48(%rbx)
incl 0x50(%rbx)
andb $0x1, %r15b
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x354b9(%rip), %r13     # 0x86fc0
leaq 0x1d3bd(%rip), %rsi     # 0x6eecb
movl $0x11, %edx
movq %r13, %rdi
callq 0x9560
movq %r13, %rdi
movl %r12d, %esi
callq 0x9880
movq %rax, %r12
leaq 0x1d3ad(%rip), %rsi     # 0x6eedd
movl $0x1e, %edx
jmp 0x51b6c
movq 0x35482(%rip), %r13     # 0x86fc0
leaq 0x1d386(%rip), %rsi     # 0x6eecb
movl $0x11, %edx
movq %r13, %rdi
callq 0x9560
movq %r13, %rdi
movl %r12d, %esi
callq 0x9880
movq %rax, %r12
leaq 0x1d395(%rip), %rsi     # 0x6eefc
movl $0x1c, %edx
movq %rax, %rdi
callq 0x9560
movsd 0x8(%rbx), %xmm0
movq %r12, %rdi
callq 0x97d0
movq %rax, %rdi
callq 0x9240
jmp 0x51abb