Example #1
0
    /// <summary>
    /// Add New State into the list
    /// </summary>
    public void AddFSMState(FlockFSMStateT1 fsmState)
    {
        // Check for Null reference before deleting
        if (fsmState == null)
        {
            Debug.LogError("FSMT1 ERROR: Null reference is not allowed");
        }

        // First State inserted is also the Initial state
        //   the state the machine is in when the simulation begins
        if (fsmStates.Count == 0)
        {
            fsmStates.Add(fsmState);
            currentState   = fsmState;
            currentStateID = fsmState.ID;
            return;
        }

        // Add the state to the List if it´s not inside it
        foreach (FlockFSMStateT1 state in fsmStates)
        {
            if (state.ID == fsmState.ID)
            {
                Debug.LogError("FSMT1 ERROR: Trying to add a state that was already inside the list");
                return;
            }
        }

        //If no state in the current then add the state to the list
        fsmStates.Add(fsmState);
    }
Example #2
0
    /// <summary>
    /// This method tries to change the state the FSMT1 is in based on
    /// the current state and the transition passed. If current state
    ///  doesn´t have a target state for the transition passed,
    /// an ERROR message is printed.
    /// </summary>
    public void PerformTransition(FlockTransitionT1 transT1)
    {
        // Check for NullTransition before changing the current state
        if (transT1 == FlockTransitionT1.None)
        {
            Debug.LogError("FSMT1 ERROR: Null transition is not allowed");
            return;
        }

        // Check if the currentState has the transition passed as argument
        FlockFSMStateT1ID id = currentState.GetOutputState(transT1);

        if (id == FlockFSMStateT1ID.None)
        {
            Debug.LogError("FSMT1 ERROR: Current State does not have a target state for this transition");
            return;
        }

        // Update the currentStateID and currentState
        currentStateID = id;
        foreach (FlockFSMStateT1 state in fsmStates)
        {
            if (state.ID == currentStateID)
            {
                currentState = state;
                break;
            }
        }
    }
Example #3
0
    public void AddTransition(FlockTransitionT1 transition, FlockFSMStateT1ID id)
    {
        // Check if anyone of the args is invallid
        if (transition == FlockTransitionT1.None || id == FlockFSMStateT1ID.None)
        {
            Debug.LogWarning("FSMStateT1 : Null transition not allowed");
            return;
        }

        //Since this is a Deterministc FSMT1,
        //Check if the current transition was already inside the map
        if (map.ContainsKey(transition))
        {
            Debug.LogWarning("FSMStateT1 ERROR: transition is already inside the map");
            return;
        }

        map.Add(transition, id);
        Debug.Log("Added : " + transition + " with ID : " + id);
    }
Example #4
0
    /// <summary>
    /// This method delete a state from the FSMT1 List if it exists,
    ///   or prints an ERROR message if the state was not on the List.
    /// </summary>
    public void DeleteState(FlockFSMStateT1ID fsmState)
    {
        // Check for NullState before deleting
        if (fsmState == FlockFSMStateT1ID.None)
        {
            Debug.LogError("FSMT1 ERROR: bull id is not allowed");
            return;
        }

        // Search the List and delete the state if it´s inside it
        foreach (FlockFSMStateT1 state in fsmStates)
        {
            if (state.ID == fsmState)
            {
                fsmStates.Remove(state);
                return;
            }
        }
        Debug.LogError("FSMT1 ERROR: The state passed was not on the list. Impossible to delete it");
    }