// 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); } }