예제 #1
0
    /// <summary>
    /// Advance _chance amount of alive cells to _nextsState
    /// </summary>
    /// <returns><c>true</c> There was transition happening <c>false</c> There wasn't any transition happening </returns>
    /// <param name="_nextState"> The state in which the squad child advances to </param>
    /// <param name="_chance"> The chance in which the squad child cell will advance </param>
    public static bool AdvanceSquadPercentage(SCState _nextState, float _chance)
    {
        // if: All the alive child is the _nextstate state
        if (SquadChildFSM.AliveCount() == SquadChildFSM.StateCount(_nextState))
        {
            return(false);
        }

        // for: Checksthrough all the child in the array
        for (int i = 0; i < s_array_SquadChildFSM.Length; i++)
        {
            if (s_array_SquadChildFSM[i].EnumState != SCState.Dead)
            {
                // if: the current cell type is NOT the targeted cell type, as transition would be useless
                if (s_array_SquadChildFSM[i].EnumState != _nextState)
                {
                    // if: The it is within the chance range
                    if (UnityEngine.Random.value <= _chance)
                    {
                        s_array_SquadChildFSM[i].Advance(_nextState);
                    }
                }
            }
        }
        return(true);
    }
예제 #2
0
    // Public Functions
    // Think(): The think process of the Squad Captain. Call this method to return the desire state that the SquadCaptain should be in
    public void Think()
    {
        // if: Restricts the brain from think too much
        if (fCurrentThinkCooldown >= fThinkCooldown)
        {
            fCurrentThinkCooldown = 0f;
        }
        else
        {
            fCurrentThinkCooldown += Time.deltaTime;
            return;
        }

        // Squad Child Cells Count Check
        // if: The number of alive squad child is less than fMininumChildCount <--------------------------------------------- DEPERATE TIMES
        if (PlayerSquadFSM.Instance.AliveChildCount() < nMinimumChildProducing)
        {
            SquadChildFSM.AdvanceSquadPercentage(SCState.Produce, 1f);
            m_PlayerSquadFSM.Advance(PSState.Produce);
        }
        // else if: There is more than enough child cells producing, moves to idle <----------------------------------------- RECOVERY
        else if (SquadChildFSM.StateCount(SCState.Produce) > nMaximumChildProducing)
        {
            SquadChildFSM.AdvanceSquadPercentage(SCState.Produce, SCState.Idle, 0.75f);
        }

        // if: There is child idling, assign them to defence <-------------------------------------------------------------- ASSIGN JOB
        if (SquadChildFSM.StateCount(SCState.Idle) > 0)
        {
            // if: Aggressive is triggered
            if (UnityEngine.Random.value > fAggressiveToDefensive)
            {
                SquadChildFSM.AdvanceSquadPercentage(SCState.Idle, SCState.Attack, 1f);
            }
            else if (SquadChildFSM.StateCount(SCState.Defend) < nMaximumChildDefence)
            {
                // nPredictedCount: The predicted number of defence cells it would have
                int nPredictedCount = (int)((float)SquadChildFSM.StateCount(SCState.Idle) * (1f - fAggressiveToDefensive)) + SquadChildFSM.StateCount(SCState.Defend);

                // if: The current predicted count is more that its requirement AND there is room to spawn more defence
                if (nPredictedCount > nMinimumIdleToDefence && SquadChildFSM.StateCount(SCState.Defend) < nMaximumChildDefence)
                {
                    SquadChildFSM.AdvanceSquadPercentage(SCState.Idle, SCState.Defend, 1f - fAggressiveToDefensive);
                }
            }
        }

        // if: There is no child cells producing but it is still important to do it <-------------------------------------- ASSIGN JOB
        if (SquadChildFSM.StateCount(SCState.Produce) == 0 && SquadChildFSM.AliveCount() < nOptionalToProduceAt)
        {
            SquadChildFSM.AdvanceSquadPercentage(SCState.Produce, 0.2f);
        }

        // if: There is extra child in Idle and the player have relatively low amount of resource
        if (SquadChildFSM.StateCount(SCState.Idle) >= nAmountIdleBeforeConsider && player_control.Instance.s_nResources <= nNeedNutrients)
        {
            SquadChildFSM.AdvanceSquadPercentage(SCState.Idle, SCState.FindResource, 0.75f);
        }
    }
예제 #3
0
 // CheckDieable(): Since the health of the squad captain is determine by the number of squad child, it checks if the health reaches 0
 public bool CheckDieable()
 {
     if (SquadChildFSM.AliveCount() == 0)
     {
         Advance(PSState.Dead);
         MainCamera.CameraShake(5, 0.7f);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #4
0
 /// <summary>
 /// Returns the number of squad child cells that is alive
 /// </summary>
 /// <returns></returns>
 public int AliveChildCount()
 {
     return(SquadChildFSM.AliveCount());
 }