Example #1
0
    private void createIdleState()
    {
        idleState = (fsm, obj) => {
            //Get the world state and goals
            HashSet <KeyValuePair <string, object> > worldState = dataProvider.getWorldState();
            HashSet <KeyValuePair <string, object> > goal       = dataProvider.createGoalState();
            //Get the plan
            Queue <AbstractGOAPAction> plan = planner.plan(gameObject, availableActions, worldState, goal);
            if (plan != null)
            {
                //Set the actions to the actions in the plan
                currentActions = plan;
                //Tell agent it found a plan
                dataProvider.planFound(goal, plan);

                //Pop the idlestate
                fsm.popState();
                //Start performing actions
                fsm.pushState(performActionState);
            }
            else
            {
                //Tell agent plan failed
                dataProvider.planFailed(goal);
                //Try to find a new plan
                fsm.popState();
                fsm.pushState(idleState);
            }
        };
    }
    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();

            // Plan
            Queue <GoapAction> plan = planner.plan(gameObject, availableActions, worldState, goal);
            if (plan != null)
            {
                // we have a plan, hooray!
                currentActions = plan;
                dataProvider.planFound(goal, plan);

                fsm.popState();                 // move to PerformAction state
                fsm.pushState(performActionState);
            }
            else
            {
                // ugh, we couldn't get a plan
                Debug.Log("<color=orange>Failed Plan:</color>" + prettyPrint(goal));
                dataProvider.planFailed(goal);
                fsm.popState();                  // move back to IdleAction state
                fsm.pushState(idleState);
            }
        };
    }
Example #3
0
    // Creating states for the GOAP FSM.

    private void createIdleState()
    {
        idleState = (fsm, gameObj) =>
        {
            // Get world state and goal from data provider.
            Dictionary <string, object> worldState = dataProvider.getWorldState();
            Dictionary <string, object> goal       = dataProvider.createGoalState();

            Queue <GoapAction> plan = planner.plan(gameObj, availableActions, worldState, goal);
            if (plan != null)
            {
                // Found a plan. Providing it to the data provider.
                currentActions = plan;
                dataProvider.planFound(goal, plan);

                // Move FSM to performAction state.
                fsm.popState();
                fsm.pushState(performActionState);
            }
            else
            {
                // No plan found for goal.
                Debug.Log("<color=orange>Failed plan:</color> " + prettyPrint(goal));
                dataProvider.planFailed(goal);

                // Going back to idleState.
                fsm.popState();
                fsm.pushState(idleState);
            }
        };
    }
    private void createIdleState()
    {
        idleState = (fsm, gameObj) => {
            // Get the world state and the goal
            Dictionary <string, object> worldState = dataProvider.getWorldState();
            Dictionary <string, object> goal       = dataProvider.createGoalState();

            // Generate the plan using GOAP Planner
            Queue <GoapAction> plan = planner.plan(gameObject, availableActions, worldState, goal);
            if (isSelected)
            {
                setMetrics();
            }
            if (plan != null)
            {
                // Plan found
                currentActions = plan;
                if (isSelected)
                {
                    generatePlanPanel();
                }
                dataProvider.planFound(goal, plan);
                fsm.popState(); // move to PerformAction state
                fsm.pushState(performActionState);
            }
            else
            {
                // No plan
                Debug.Log("<color=orange>Failed Plan:</color>" + prettyPrint(goal));
                dataProvider.planFailed(goal);
                fsm.popState(); // move back to IdleAction state
                fsm.pushState(idleState);
            }
        };
    }
Example #5
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();

            // Plan
            // MAYBE ONLY DO THIS ONCE EVERY n SECONDS
            if (!hasPlan)
            {
                planner.plan(gameObject, availableActions, worldState, goal);
            }

            if (plan != null && hasPlan)
            {
                // need to find the targets for our actions here before trying to do anything
                foreach (var item in plan)
                {
                    foreach (var pre in item.Preconditions)
                    {
                        Debug.Log("Precondition: " + pre.Key + " " + pre.Value);
                    }

                    item.checkProceduralPrecondition(gameObject);
                }

                // we have a plan, hooray!
                currentActions = plan;
                dataProvider.planFound(goal, plan);
                //doOnce = true;
                fsm.popState();                 // move to PerformAction state
                fsm.pushState(performActionState);
            }

            else
            {
                // ugh, we couldn't get a plan
                Debug.Log("<color=orange>Failed Plan:</color>" + prettyPrint(goal));
                dataProvider.planFailed(goal);
                fsm.popState();                  // move back to IdleAction state
                fsm.pushState(idleState);
            }
        };
    }
Example #6
0
    private void createIdleState()
    {
        idleState = (fsm, gameObj) =>
        {
            // GOAP planning

            // get the world state and the goal we want to plan for
            var worldState = dataProvider.getWorldState();
            var goals      = dataProvider.createGoalState();

            // search enable Plan
            Queue <GoapAction>          plan     = null;
            KeyValuePair <string, bool> lastGoal = new KeyValuePair <string, bool>();
            foreach (var goal in goals)
            {
                lastGoal = goal;
                plan     = planner.plan(gameObject, availableActions, worldState, goal, dataProvider);
                if (plan != null)
                {
                    break;
                }
            }
            if (plan != null)
            {
                // we have a plan, hooray!
                currentActions = plan;
                dataProvider.planFound(lastGoal, plan);

                fsm.popState(); // move to PerformAction state
                fsm.pushState(performActionState);
            }
            else
            {
                // ugh, we couldn't get a plan
                Debug.Log("<color=orange>Failed Plan:</color>" + prettyPrint(goals));
                dataProvider.planFailed(goals);
                fsm.popState(); // move back to IdleAction state
                fsm.pushState(idleState);
            }
        };
    }
Example #7
0
 private void UpdateAgentState()
 {
     _worldState = dataProvider.getWorldState();
     _goal       = dataProvider.createGoalState();
 }