Example #1
0
    /// <summary>
    /// adds a movment option to the state if nor already contained
    /// </summary>
    /// <param name="option">the option being added</param>
    public void AddMovementOption(EntityMovementOption option)
    {
        if (MovementOptions == null)
        {
            movementOptions = new List <EntityMovementOption>();
        }

        if (movementOptions.Contains(option))
        {
            return; //already contained don't double add
        }
        movementOptions.Add(option);

        //add it's requests to the mapping at the end
        var att = Attribute.GetCustomAttribute(option.GetType(), typeof(PossibleTransitionRequestTypesAttribute)) as PossibleTransitionRequestTypesAttribute;

        if (att != null)
        {
            for (int i = 0; i < att.Types.Length; i++)
            {
                var req = TransitionRequest.Factory.BuildRequest(att.Types[i]);

                AddPriorityRequest(req, minPriorityValue);
            }
        }
    }
    /// <summary>
    /// adds a general movementoption to machine, if not already existing
    /// </summary>
    /// <param name="option"></param>
    public void AddGeneralMovementOption(EntityMovementOption option)
    {
        if (generalMovementOptions == null)
        {
            generalMovementOptions = new List <EntityMovementOption>();
        }

        if (!generalMovementOptions.Contains(option))
        {
            generalMovementOptions.Add(option);
        }
    }
Example #3
0
    /// <summary>
    /// removes a movment option from the state, and all it's associated transitions that it might cause
    /// </summary>
    /// <param name="option">the option being removed</param>
    public void RemoveMovementOption(EntityMovementOption option)
    {
        if (movementOptions.Remove(option))
        {
            PossibleTransitionRequestTypesAttribute att = Attribute.GetCustomAttribute(option.GetType(), typeof(PossibleTransitionRequestTypesAttribute)) as PossibleTransitionRequestTypesAttribute;
            if (att != null)
            {
                for (int i = 0; i < att.Types.Length; i++)
                {
                    var type = TransitionRequest.Factory.BuildRequest(att.Types[i]);

                    RemoveTransition(type);
                    //remove from mapping (relinearize if last one removed)
                    RemovePriorityMapping(type, i == att.Types.Length - 1);
                }
            }
        }
    }
    /// <summary>
    /// removes general movement option, propagates change to all states of machine
    /// to keep everything consistent
    /// </summary>
    /// <param name="opt"></param>
    public void RemoveGeneralMovementOption(EntityMovementOption opt)
    {
        int idx = generalMovementOptions.IndexOf(opt);

        if (idx < 0)
        {
            return;
        }

        if (idx < StateCount - 1)
        {
            generalMovementOptions[idx] = generalMovementOptions[StateCount - 1];
            idx = StateCount - 1;
        }
        generalMovementOptions.RemoveAt(idx);


        for (int i = 0; i < StateCount; i++)
        {
            var st = movementStates[i];
            st.RemoveMovementOption(opt);
        }
    }
Example #5
0
 public void AddGeneralMovementOption(EntityMovementOption option)
 {
     generalOptionsData.Add(option.GetType().Name);
 }
Example #6
0
 /// <summary>
 /// chcks if state contains movement option
 /// </summary>
 /// <param name="option">the option we want to know if it contains</param>
 /// <returns>true if contained false otherwise</returns>
 public bool ContainsMovementOption(EntityMovementOption option)
 {
     return(movementOptions.Contains(option));
 }
 /// <summary>
 /// finds index of movement option in general option list
 /// </summary>
 /// <param name="option">option we want the index of</param>
 /// <returns>the index of option</returns>
 public int GetIndexForMovementOption(EntityMovementOption option)
 {
     return(generalMovementOptions.IndexOf(option));
 }