Пример #1
0
    private void createIdleState()
    {
        idleState = (fsm, gameObj) => {
            // GOAP planning

            // Get the world state and the goal we want to plan for
            HashSet <KeyValuePair <string, object> > worldState = dataProvider.getWorldState();
            HashSet <KeyValuePair <string, object> > goal       = dataProvider.createGoalState();

            // Make a plan with the actions the AI wants to do in order
            Queue <GOAPAction> plan = planner.plan(gameObject, availableActions, worldState, goal);
            if (plan != null)
            {
                // We have a plan!
                currentActions = plan;
                dataProvider.planFound(goal, plan);

                fsm.popState();                    // Clear current state
                fsm.pushState(performActionState); // Change to performActionState
            }
            else
            {
                // We don't have a plan
                dataProvider.planFailed(goal);
                fsm.popState();
                fsm.pushState(idleState);                  // Back to square one
            }
        };
    }
Пример #2
0
    private void createIdleState()
    {
        idleState = (fsm, obj) => {
            HashSet <KeyValuePair <string, object> > worldState = dataProvider.getWorldState();
            HashSet <KeyValuePair <string, object> > goal       = dataProvider.createGoalState();

            Queue <GOAPAction> plan = planner.plan(gameObject, availableActions, worldState, goal);
            if (plan != null)
            {
                currentActions = plan;
                dataProvider.planFound(goal, plan);

                fsm.popState();
                fsm.pushState(performActionState);
            }
            else
            {
                dataProvider.planFailed(goal);
                fsm.popState();
                fsm.pushState(idleState);
            }
        };
    }