示例#1
0
        public BTGuard(Guard ownerBrain) : base(ownerBrain)
        {
            // Actions
            chaseAction                 = new Chase(NodeOwner);
            investigateAction           = new Investigate(NodeOwner);
            lookAroundAction            = new LookAround(NodeOwner);
            moveToNextPatrolPointAction = new MoveToPatrolPoint(NodeOwner);
            chooseNextPatrolPointAction = new ChooseNextPatrolPoint(NodeOwner);
            catchSpyAction              = new CatchSpy(NodeOwner);

            // Conditions
            canIHearSpyCondition = new CanIHearSpy(NodeOwner);
            canISeeSpyCondition  = new CanISeeSpy(NodeOwner);
            haveIArrivedToThePatrolPointCondition = new HaveIArrivedToThePatrolPoint(NodeOwner);
            haveIFinishedLookingAroundCondition   = new HaveIFinishedLookingAround(NodeOwner);
            amIChasingCondition = new AmIChasing(NodeOwner);
            haveIFinishedInvestigatingCondition = new HaveIFinishedInvestigating(NodeOwner);
            canICatchSpyCondition = new CanICatchSpy(NodeOwner);

            // Composites
            rootSequence          = new Sequence();
            patrolSequence        = new Sequence();
            patrolParallel        = new Parallel(3, 1);
            chaseParallel         = new Parallel(3, 1);
            chaseSequence         = new PrioritisedSequence();
            engageSelector        = new Selector();
            patrolSelector        = new Selector();
            investigationParallel = new Parallel(3, 1);
            investigationSequence = new Sequence();
            hearChaseSequence     = new Sequence();
            seeChaseSequence      = new Sequence();

            // Decorators
            repeatUntilFailDecoratorForPatrolSequence = new RepeatUntilFail(patrolSequence);


            // Tree Structure

            // Tree level 0
            rootSequence.AddChildNode(patrolSelector);
            rootSequence.AddChildNode(engageSelector);

            // Tree level 1
            patrolSelector.AddChildNode(amIChasingCondition);
            patrolSelector.AddChildNode(patrolParallel);

            engageSelector.AddChildNode(chaseParallel);
            engageSelector.AddChildNode(investigationParallel);

            // Tree level 2
            patrolParallel.AddChildNode(repeatUntilFailDecoratorForPatrolSequence);
            patrolParallel.AddChildNode(canIHearSpyCondition);
            patrolParallel.AddChildNode(canISeeSpyCondition);

            chaseParallel.AddChildNode(chaseSequence);
            chaseParallel.AddChildNode(hearChaseSequence);
            chaseParallel.AddChildNode(seeChaseSequence);

            investigationParallel.AddChildNode(investigationSequence);
            investigationParallel.AddChildNode(canIHearSpyCondition);
            investigationParallel.AddChildNode(canISeeSpyCondition);

            // Tree level 3
            patrolSequence.AddChildNode(moveToNextPatrolPointAction);
            patrolSequence.AddChildNode(haveIArrivedToThePatrolPointCondition);
            patrolSequence.AddChildNode(lookAroundAction);
            patrolSequence.AddChildNode(haveIFinishedLookingAroundCondition);
            patrolSequence.AddChildNode(chooseNextPatrolPointAction);

            chaseSequence.AddChildNode(chaseAction);
            chaseSequence.AddChildNode(canICatchSpyCondition);
            chaseSequence.AddChildNode(catchSpyAction);

            hearChaseSequence.AddChildNode(canIHearSpyCondition);
            hearChaseSequence.AddChildNode(chaseAction);

            seeChaseSequence.AddChildNode(canISeeSpyCondition);
            seeChaseSequence.AddChildNode(chaseAction);

            investigationSequence.AddChildNode(investigateAction);
            investigationSequence.AddChildNode(haveIFinishedInvestigatingCondition);
        }