// File: /workspace/github_cpp_makefile_star2_O2/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
movl (%rdi), %eax
decl %eax
cmpl $0x9, %eax
ja 0x43de5
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x17226(%rip), %rcx     # 0x5ac60
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 0x43de5
movq 0x33559(%rip), %rdi     # 0x76fc0
leaq 0x1737f(%rip), %rsi     # 0x5aded
jmp 0x43e44
movsd 0x40(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x43a8a
cmpb $0x1, 0x54(%rbx)
jne 0x43ab3
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x135ad(%rip), %xmm2    # 0x57048
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x43de5
cmpb $0x1, 0x54(%rbx)
jne 0x43de5
movq 0x33506(%rip), %rdi     # 0x76fc0
leaq 0x1739e(%rip), %rsi     # 0x5ae5f
jmp 0x43e44
movq 0x18(%rbx), %r12
cmpq 0x20(%rbx), %r12
je 0x43de5
cmpq 0x20(%rbx), %r12
setne %r15b
je 0x43e8a
movq %r12, %rdi
movq %r14, %rsi
callq 0x43a12
addq $0x58, %r12
testb %al, %al
je 0x43ad4
jmp 0x43e8a
movsd 0x38(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x43b11
cmpb $0x1, 0x54(%rbx)
jne 0x43b3a
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x13526(%rip), %xmm2    # 0x57048
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x43de5
cmpb $0x1, 0x54(%rbx)
jne 0x43de5
movq 0x3347f(%rip), %rdi     # 0x76fc0
leaq 0x172dd(%rip), %rsi     # 0x5ae25
jmp 0x43e44
movsd 0x40(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x43b64
cmpb $0x1, 0x54(%rbx)
jne 0x43b8d
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x134d3(%rip), %xmm2    # 0x57048
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x43de5
cmpb $0x1, 0x54(%rbx)
jne 0x43de5
movq 0x3342c(%rip), %rdi     # 0x76fc0
leaq 0x172a6(%rip), %rsi     # 0x5ae41
jmp 0x43e44
cmpl $0x1, 0x1c(%r14)
je 0x43de5
movq 0x3340e(%rip), %rdi     # 0x76fc0
leaq 0x17310(%rip), %rsi     # 0x5aec9
callq 0x94b0
jmp 0x43e56
movsd 0x38(%r14), %xmm1
movsd 0x8(%rbx), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x43bda
cmpb $0x1, 0x54(%rbx)
jne 0x43c03
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movsd 0x1345d(%rip), %xmm2    # 0x57048
andpd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x43de5
cmpb $0x1, 0x54(%rbx)
jne 0x43de5
movq 0x333b6(%rip), %rdi     # 0x76fc0
leaq 0x171f6(%rip), %rsi     # 0x5ae07
jmp 0x43e44
movsd 0x10(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x43c2b
jnp 0x43cc5
leaq 0x38(%r14), %rdi
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x43d51
decl %eax
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%r14,%rax), %rsi
addq $0xa8, %rsi
jmp 0x43d67
movsd 0x10(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x43c69
jnp 0x43d09
leaq 0x38(%r14), %rdi
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x43d99
decl %eax
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%r14,%rax), %rsi
addq $0xa8, %rsi
jmp 0x43daf
movq 0x18(%rbx), %r12
cmpq 0x20(%rbx), %r12
je 0x43de5
xorl %r15d, %r15d
cmpq 0x20(%rbx), %r12
je 0x43de5
movq %r12, %rdi
movq %r14, %rsi
callq 0x43a12
addq $0x58, %r12
testb %al, %al
jne 0x43ca3
jmp 0x43e8a
leaq 0x38(%r14), %r12
leaq 0x10d8(%r14), %r13
pushq $-0xb
popq %r15
testq %r15, %r15
je 0x43de5
cmpb $0x1, 0x10a(%r13)
jne 0x43cfd
movq %r13, %rdi
movq %r12, %rsi
callq 0x2198a
ucomisd 0x8(%rbx), %xmm0
ja 0x43ded
incq %r15
addq $0x178, %r13            # imm = 0x178
jmp 0x43cd4
leaq 0x38(%r14), %r12
leaq 0x10d8(%r14), %r13
pushq $-0xb
popq %r15
testq %r15, %r15
je 0x43de5
cmpb $0x1, 0x10a(%r13)
jne 0x43d45
movq %r13, %rdi
movq %r12, %rsi
callq 0x2198a
movsd 0x8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
ja 0x43e18
incq %r15
addq $0x178, %r13            # imm = 0x178
jmp 0x43d18
notl %eax
cltq
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%r14,%rax), %rsi
addq $0x10d0, %rsi           # imm = 0x10D0
addq $0x8, %rsi
callq 0x2198a
ucomisd 0x8(%rbx), %xmm0
jbe 0x43de5
movq 0x33242(%rip), %rdi     # 0x76fc0
leaq 0x170f6(%rip), %rsi     # 0x5ae7b
callq 0x94b0
movsd 0x10(%rbx), %xmm0
movq %rax, %rdi
callq 0x97e0
jmp 0x43e0f
notl %eax
cltq
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%r14,%rax), %rsi
addq $0x10d0, %rsi           # imm = 0x10D0
addq $0x8, %rsi
callq 0x2198a
movsd 0x8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x43de5
movq 0x331f6(%rip), %rdi     # 0x76fc0
leaq 0x170aa(%rip), %rsi     # 0x5ae7b
callq 0x94b0
movsd 0x10(%rbx), %xmm0
movq %rax, %rdi
callq 0x97e0
jmp 0x43e3a
xorl %r15d, %r15d
jmp 0x43e8a
addl $0xc, %r15d
movq 0x331c8(%rip), %rdi     # 0x76fc0
leaq 0x1707c(%rip), %rsi     # 0x5ae7b
callq 0x94b0
movq %rax, %rdi
movl %r15d, %esi
callq 0x9890
leaq 0x17077(%rip), %rsi     # 0x5ae8d
jmp 0x43e41
addl $0xc, %r15d
movq 0x3319d(%rip), %rdi     # 0x76fc0
leaq 0x17051(%rip), %rsi     # 0x5ae7b
callq 0x94b0
movq %rax, %rdi
movl %r15d, %esi
callq 0x9890
leaq 0x1706b(%rip), %rsi     # 0x5aeac
movq %rax, %rdi
callq 0x94b0
movsd 0x8(%rbx), %xmm0
movq %rax, %rdi
callq 0x97e0
movq %rax, %rdi
callq 0x99e8
movl 0x10(%r14), %eax
movq 0x38(%rbx), %rdx
movl %eax, %ecx
subl 0x194(%rdx), %ecx
cmpl 0x40(%rbx), %ecx
jle 0x43e79
movl %ecx, 0x40(%rbx)
movl %eax, 0x4c(%rbx)
cmpl 0x44(%rbx), %ecx
jge 0x43e84
movl %ecx, 0x44(%rbx)
movl %eax, 0x48(%rbx)
incl 0x50(%rbx)
movb $0x1, %r15b
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq