/// <summary> /// Formulates the plan based on availble actions, world state, etc /// </summary> 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(); if (goal.Contains(new KeyValuePair <string, object>("expandStorage", true))) { Debug.Log("found builder"); } // 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(prefromActionState); } else { // ugh, we couldn't get a plan // Debug.Log("<color=orange>Failed Plan:</color> " + prettyPrint(goal)); dataProvider.PlanFailed(goal, currentActions); fsm.PopState(); // move back to IdleAction state fsm.PushState(idleState); } }; }
public void CrearEstadoIdle() { // Este estado lo usa el agente para calcular un plan idleState = (fsm, gameObj) => { // Planeación goap // Obtener el estado del mundo Dictionary <string, object> worldState = goapData.GetWorldState(); // Obtener la meta del agente Dictionary <string, object> goal = goapData.CreateGoalState(); // Crear un plan Queue <GoapAction> plan = Planeador.ElPlan( gameObject, AccionesDisponibles, worldState, goal); // ¿Logramos tener un plan? if (plan != null) { Debug.Log("Tengo un plan!"); AccionesActuales = plan; goapData.PlanFound(goal, plan); maquinaDeEstados.popState(); // Saca el estado idle maquinaDeEstados.pushState(ActState); // pasa al estado de actuar } else { Debug.Log("No tengo plan :("); goapData.PlanFailed(goal); maquinaDeEstados.popState(); maquinaDeEstados.pushState(idleState); // Vuelva a intentar calcular un plan } }; }
private void CreateIdleState() { IdleState = (fsm, agent) => { Dictionary <Tuple <string, object>, object> WorldState = DataProvider.GetWorldState(); List <KeyValuePair <Tuple <string, object>, object> > Goal = DataProvider.CreateGoalState(); Queue <GOAPAction> Plan = Planner.Plan(agent, AvailableActions, WorldState, Goal); if (Plan != null) { //AddThought("Plan created for goal " + Goal.Keys.First(), Color.DarkBlue); AddThought("Plan created for goal " + Goal[0].Key.ToString(), Color.DarkBlue); CurrentActions = Plan; DataProvider.PlanFound(Goal[0], Plan); fsm.PopState(); fsm.PushState(PerformActionState); } else { DataProvider.PlanFailed(Goal[0]); fsm.PopState(); fsm.PushState(IdleState); } }; }
// private FSM.FSMState 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); } }; }