Пример #1
0
    /// <summary>
    /// Executes the exit transitions between a submachine and the supermachine
    /// </summary>
    /// <param name="stateFrom">The exit state of the transition</param>
    /// <param name="stateTo">The entry state of the transition</param>
    /// <param name="entrySubMachineState">The 'Entry_State' of the submachine</param>
    /// <param name="superMachine">The supermachine where the trasition is going to</param>
    /// <param name="subMachine">The subsmachine the transition is leaving</param>
    private void ExitTransition(State stateFrom, State stateTo, State entrySubMachineState, BehaviourEngine superMachine, BehaviourEngine subMachine)
    {
        if (stateFrom.BehaviourEngine == superMachine)  // Exits from the super-machine
        // Transitions from Submachine.CurrentState -> Submachine.EntryState
        {
            Transition returnTransition = new Transition("reset_submachine", subMachine.actualState, new PushPerception(subMachine), entrySubMachineState, subMachine);
            returnTransition.FireTransition();

            subMachine.Reset();
            subMachine.Active   = false;
            superMachine.Active = true;

            // Transitions from stateFrom -> stateTo
            Transition superTransition = new Transition("to_state", stateFrom, new PushPerception(superMachine), stateTo, superMachine);
            superTransition.FireTransition();
        }
        else   // Exits from the sub-machine
               // Transitions from stateFrom -> Submachine.EntryState
        {
            Transition returnTransition = new Transition("reset_submachine", stateFrom, new PushPerception(subMachine), entrySubMachineState, subMachine);
            returnTransition.FireTransition();

            subMachine.Reset();
            subMachine.Active   = false;
            superMachine.Active = true;

            // Transitions from Supermachine.CurrentState -> stateTo
            Transition superTransition = new Transition("to_state", superMachine.actualState, new PushPerception(superMachine), stateTo, superMachine);
            superTransition.FireTransition();
        }
    }
Пример #2
0
    /// <summary>
    /// Executes the exit transitions between a submachine and the supermachine which is a <see cref="BehaviourTreeEngine"/>
    /// </summary>
    /// <param name="stateFrom">The exit state of the transition</param>
    /// <param name="stateTo">The entry state of the transition</param>
    /// <param name="entrySubMachineState">The 'Entry_State' of the submachine</param>
    /// <param name="superMachine">The supermachine where the trasition is going to</param>
    /// <param name="subMachine">The subsmachine the transition is leaving</param>
    private void ExitTransition(State stateFrom, LeafNode stateTo, ReturnValues returnValue, State entrySubMachineState, BehaviourTreeEngine superMachine, BehaviourEngine subMachine)
    {
        if (stateFrom.BehaviourEngine == superMachine)  // Exits from the super-machine
        // Transitions from Submachine.CurrentState -> Submachine.EntryState
        {
            Transition returnTransition = new Transition("reset_submachine", subMachine.actualState, new PushPerception(subMachine), entrySubMachineState, subMachine);
            returnTransition.FireTransition();

            subMachine.Reset();
            subMachine.Active   = false;
            superMachine.Active = true;
            stateTo.ReturnValue = returnValue;

            // Transitions from stateFrom -> stateTo
            // Maybe I should change this too, as I changed the next one?
            // TODO review if this is working properly

            Transition superTransition = new Transition("to_state", stateFrom, new PushPerception(superMachine), stateTo.StateNode, superMachine);
            superTransition.FireTransition();
        }
        else   // Exits from the sub-machine
               // Transitions from stateFrom -> Submachine.EntryState
        {
            Transition returnTransition = new Transition("reset_submachine", stateFrom, new PushPerception(subMachine), entrySubMachineState, subMachine);
            returnTransition.FireTransition();

            subMachine.Reset();
            subMachine.Active   = false;
            superMachine.Active = true;
            stateTo.ReturnValue = returnValue;

            // Transitions from Supermachine.CurrentState -> stateTo

            /* ¿BUG?
             * stateTo SHOULD BE THE SAME AS SuperMachine.CurrentState  --> We are exiting from a machine
             * that returns Succeed or Failed to the SuperMachine LeafNode, if we enter again to that Node
             * we are again putting the ReturnType to "process", so we enter in an infinite loop
             */

            //Transition superTransition = new Transition("to_state", superMachine.actualState, new PushPerception(superMachine), stateTo.StateNode, superMachine);
            //superTransition.FireTransition();
        }
    }