Example #1
0
    /// <summary>
    /// If someone depends on a char and that char is removed, remove that someone.
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="CurrentState"></param>
    /// <param name="NextState"></param>
    /// <returns></returns>
    public void removeDependencies(int ID, CharController.State CurrentState, CharController.State NextState)
    {
        //If we're alreasdy "WaitingOut"side of Selection, or needed by no one, nothing to do here.
        if (NeededBy[ID].Length == 0 || NextState == CharController.State.WaitingOut)
        {
            return;
        }

        //Tell friends we're leaving.
        CBUG.Log(ID_to_Name[ID] + " has " + NeededBy[ID].Length + " references on to remove");
        for (int i = 0; i < NeededBy[ID].Length; i++)
        {
            //To prevent multiple calls to a Character within a single frame, we check action buffer.
            if (!ActionBufferRemove.ContainsKey(NeededBy[ID][i]))
            {
                //Fixing circular dependency with this:
                //Don't call the one who called me.
                //if Caller of Past == Character I want to Call, don't call
                if ((!ActionBufferRemove.ContainsKey(ID)) || ActionBufferRemove[ID] != NeededBy[ID][i])
                {
                    if (Characters[NeededBy[ID][i]].GetComponent <CharController>().NextState != CharController.State.WaitingOut)
                    {
                        ActionBufferRemove.Add(NeededBy[ID][i], ID);
                        Characters[NeededBy[ID][i]].GetComponent <CharController>().OnPointerClick(null);
                    }
                }
            }
        }
    }
Example #2
0
    /// <summary>
    /// Makes sure there is space available for Char N Friends.
    /// If so, also tell friend to go as well.
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="CurrentState"></param>
    /// <param name="NextState"></param>
    /// <returns></returns>
    public bool includeDependencies(int ID, CharController.State CurrentState, CharController.State NextState)
    {
        //If we're already "WaitingIn" Selection, or have no friends, nothing to do here.
        if (DependenciesOf[ID].Length == 0 || NextState == CharController.State.WaitingIn)
        {
            return(true);
        }

        //Is there space for us and our friends? If not, don't act!
        int totalDependenciesNotSelected = 0;

        for (int x = 0; x < DependenciesOf[ID].Length; x++)
        {
            if (Characters[DependenciesOf[ID][x]].GetComponent <CharController>().NextState == CharController.State.WaitingOut)
            {
                totalDependenciesNotSelected++;
            }
        }
        if (!IsPositionAvailable(totalDependenciesNotSelected + 1))
        {
            return(false);
        }

        //Tell friends they got "clicked".
        CBUG.Log(ID_to_Name[ID] + " has " + DependenciesOf[ID].Length + " friends to add");
        for (int i = 0; i < DependenciesOf[ID].Length; i++)
        {
            //To prevent multiple calls to a Character within a single frame, we check action buffer.
            if (!ActionBufferAdd.ContainsKey(DependenciesOf[ID][i]))
            {
                //Fixing circular dependency with this:
                //Don't call the one who called me.
                //if Caller of Past == Character I want to Call, don't call
                if ((!ActionBufferAdd.ContainsKey(ID)) || ActionBufferAdd[ID] != DependenciesOf[ID][i])
                {
                    //Don't call anyone already settled in.
                    if (Characters[DependenciesOf[ID][i]].GetComponent <CharController>().NextState != CharController.State.WaitingIn)
                    {
                        ActionBufferAdd.Add(DependenciesOf[ID][i], ID);
                        Characters[DependenciesOf[ID][i]].GetComponent <CharController>().OnPointerClick(null);
                    }
                }
            }
        }
        return(true);
    }