예제 #1
0
    private void PathFound(bool success, PathData pathData)
    {
        AIMoveAction moveAction = null;

        if (success)
        {
            moveAction = new AIMoveAction(pathData.waypoints, 1f);
        }

        _childFSM.SetState(moveAction);
    }
예제 #2
0
    ///<summary>
    /// Starts off the AI; lets it make a decision on how to act
    ///</summary>
    public void RunAI()
    {
#if UNITY_EDITOR
        if (DebugSettings.debugAIManager)
        {
            Debug.Log("_____.....--~~~^^^^^^^^~~~--....._____");
            Debug.Log("Starting AI for unit " + unitManager.currentTurnUnit + ".");
        }
#endif

        ScanForUnits();                 // Splitting into functions means some actions have to be done twice.
        ScanForActions();               // But it does increase readability, instead of one absurdly large function (especially as features get added).

        AIAction [] actionList = actionsToConsider.OrderByDescending(Action => Action.score).ToArray <AIAction> ();

#if UNITY_EDITOR
        if (DebugSettings.debugAIManager)
        {
            Debug.Log("-**- AI " + unitManager.currentTurnUnit.name + " going. \n Has " + actionList.Length + " possible actions. -**-");
            int debugitterator = 0;
            foreach (AIAction action in actionList)
            {
                if (action is AIAttackAction)
                {
                    Debug.Log("Action " + debugitterator + ": Attacking " + action.targetUnit.unit + ", for " + action.score + " score.");
                }
                if (action is AIAbilityAction)
                {
                    Debug.Log("Action " + debugitterator + ": casting " + "[ability name]" + ", on: " + action.targetUnit.unit + ", for " + action.score + " score.");
                }
                debugitterator++;
            }
        }
#endif

        // Keeps trying actions (starting with highest score) until one succeeds
        int  i = 0;
        bool hasTestedAction = false;

        while (hasTestedAction)
        {
            hasTestedAction = actionList [i].Try(unitManager.currentTurnUnit);
            i++;
        }         // After this we have the highest scored action that has tested successfully (and thus should be executeable).

        if (actionList.Length != 0 && actionList [i] != null)
        {
            if (actionList [i].requiresMovement)
            {
                actionSequence [0] = new AIMoveAction(actionList [i].tileToMoveTo);
                actionSequence [1] = actionList [i];
            }
            else
            {
                actionSequence [0] = actionList [i];
                AIMoveAction newMoveAction = new AIMoveAction(FindPointToMoveTo());
                if (newMoveAction.tileToMoveTo != null && !newMoveAction.tileToMoveTo.Equals(unitManager.currentTurnUnit.currentTile))
                {
                    actionSequence [1] = newMoveAction;
                }
                else
                {
                    actionSequence [1] = null;
                }
            }
        }
        else
        {
            actionSequence [0] = new AIMoveAction(FindPointToMoveTo());
        }

#if UNITY_EDITOR
        if (DebugSettings.debugAIManager)
        {
            Debug.Log("AI Will be doing a " + actionSequence [0] + ", and a " + actionSequence [1]);
        }
#endif

        ContinueAI();          // Decision making complete; execute first action
    }