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(); // switch to PerformAction state fsm.pushState(performActionState); } else { // ugh, we couldn't get a plan Debug.Log("Failed Plan: " + goal); dataProvider.PlanFailed(goal); fsm.popState(); // switch back to IdleAction state fsm.pushState(idleState); } }; }
private void CreateIdleState() { _idleState = (fsm, fsmGameObject) => { // reset data content ResetActionData(); HashSet <KeyValuePair <string, object> > worldStates = _dataProvider.GetWorldStates(); HashSet <KeyValuePair <string, object> > goals = _dataProvider.GetGoals(); // planning _plan = _planner.Plan(this, _actions, worldStates, goals); // if has no plan... if (_plan == null) { _dataProvider.PlanFailed(goals); } else { _dataProvider.PlanFound(goals, _plan); fsm.PopState(); fsm.PushState(_performState); } }; }
private void CreateIdleState() { idleState = (fsm, gameObj) => { // GOAP Planning Dictionary <string, object> worldState = agent.WorldState(); Dictionary <string, object> goal = agent.CreateGoalState(); Queue <GoapAction> plan = GoapPlanner.Plan(gameObject, availableActions, worldState, goal); if (plan != null) { currentPlan = plan; agent.PlanFound(goal, plan); fsm.PopState(); fsm.PushState(performActionState); } else { Debug.Log("<color=orange>Failed Plan:</color>" + goal); agent.PlanFailed(goal); fsm.PopState(); fsm.PushState(idleState); } }; }
private void IdleState() { idle = (fsm, gameObj) => { List <KeyValuePair <string, object> > worldState = goapAgent.GetWorldState(); KeyValuePair <string, object> goal = goapAgent.GetSubGoals(); planner.Reset(); if (!goal.Equals(new KeyValuePair <string, object>())) { Queue <GoapAction> plan = planner.Plan(availableActions, worldState, goal); if (plan != null) { // we have a plan, hooray! currentActions = plan; goapAgent.PlanFound(goal, plan); fsm.popState(); fsm.pushState(act); } else { goapAgent.PlanFailed(goal); fsm.popState(); fsm.pushState(idle); } } else { goapAgent.GameFinished(); } }; }
void CreateIdleState() { _idleState = (fsm, gameObj) => { // GOAP planning // get the world state and the goal we want to plan for var worldState = _dataProvider.GetWorldState(); var 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); } }; }
private void createIdleState() { //this is a lambda expression nameless/anonymous delegate thingy of type FSM.FSMState idleState = (fsm, gameObj) => { //HashSet<KeyValuePair<string, object>> worldState = dataProvider.getWorldState(); //HashSet<KeyValuePair<string, object>> goal = dataProvider.createGoalState(); Profiler.BeginSample("Gathering and ordering goals by priority "); List <Condition> originalState = dataProvider.GetWorldState(); List <Goal> goals = dataProvider.GetGoalState(); goals = OrderByPriority(goals); //Debug.Log("WORLD STATE " + prettyPrint(originalState)); //Debug.Log("GOAL STATE " + prettyPrint(goals)); Profiler.EndSample(); Profiler.BeginSample("Begin Planning -- for loop through goals and calling planner"); Queue <GoapAction> plan = null; foreach (Goal ourGoal in goals) { //this cycles through the goals by priority until it finds one that works with a plan plan = planner_.Plan(ourGoal, availableActions_, originalState, this.gameObject); if (plan != null) { //if you find a plan that works, break and continue on //Debug.Log("<color=cyan>Plan found!:</color>" + prettyPrint(plan) + " for " + gameObj.name); break; } else { } } Profiler.EndSample(); // planner_.Plan(goals, availableActions_, originalState, this.gameObject); Profiler.BeginSample("Checking to see if plan is null/failed and returning to idle if so"); if (plan != null) { currentActions = plan; dataProvider.PlanFound(goals, 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) + " for " + gameObj.name); dataProvider.PlanFailed(goals); fsm.popState(); // move back to IdleAction state fsm.pushState(idleState); } Profiler.EndSample(); }; }
void CreateIdleState() { idleState = (fsm, gameObj) => { 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 { Debug.Log("<color=orange>Failed Plan</color>" + PrettyPrint(goal)); dataProvider.PlanFailed(goal); 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 Dictionary <string, object> worldState = _dataProvider.GetWorldState(); Dictionary <Int64, Int64> resourceState = _dataProvider.GetResourceState(); Dictionary <string, object> goal = _dataProvider.CreateGoalState(); Dictionary <Int64, Int64> resourceGoal = _dataProvider.CreateResourceGoal(); loadActions(); // Plan Queue <GoapAction> plan = _planner.Plan(this, _availableActions, worldState, resourceState, goal, resourceGoal); 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 // Console.WriteLine("<color=orange>Failed Plan:</color>" + PrettyPrint(goal)); _dataProvider.PlanFailed(goal); fsm.popState(); // move back to IdleAction state fsm.pushState(_idleState); } }; }
private void CreatePlanningState() { planningState = (fsm, gameObj) => { Dictionary <string, object> worldState = worldDataProvider.GetWorldState(); Dictionary <string, object> goalState = worldDataProvider.CreateGoalState(); Queue <GAction> plan = planner.Plan(this, availableActions, worldState, goalState); if (plan != null) { currentActions = plan; worldDataProvider.PlanFound(goalState, plan); fsm.PopState(); fsm.PushState(performActionState); } else { Debug.Log("Planning failed! Goal: " + goalState); worldDataProvider.PlanFailed(goalState); fsm.PopState(); fsm.PushState(planningState); } }; }
private void CreateIdleState() { idleState = (fsm, gameObj) => { // GOAP planning // get the world state and the goal we want to plan for Dictionary <string, object> worldState = dataProvider.GetWorldState(); KeyValuePair <string, object> goal = dataProvider.GetCurrentGoal(); // search enable Plan Queue <GoapAction> plan = planner.Plan(gameObject, availableActions, worldState, goal, dataProvider); 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("[" + this.name + "] " + "<color=orange>Plan failed:</color> " + PrettyPrint(goal) + " = NO PLAN"); dataProvider.PlanFailed(goal); fsm.PopState(); // move back to IdleAction state fsm.PushState(idleState); } }; }
//bool isPlanning = false; //HashSet<KeyValuePair<string, object>> worldState; //HashSet<KeyValuePair<string, object>> goal; void CreateIdleState() { idleState = (fsm, gameObj) => { 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 { Debug.Log("<color=orange>Failed Plan</color>" + PrettyPrint(goal)); dataProvider.PlanFailed(goal); fsm.PopState(); fsm.PushState(idleState); } //if (!isPlanning) //{ // worldState = dataProvider.GetWorldState(); // goal = dataProvider.CreateGoalState(); // planner.donePlanning = false; // planner.finalPlan = null; // StartCoroutine(planner.Plan(gameObject, availableActions, worldState, goal, this)); // isPlanning = true; //} //else //{ // if (planner.donePlanning) // { // if (planner.finalPlan != null) // { // currentActions = planner.finalPlan; // dataProvider.PlanFound(goal, planner.finalPlan); // fsm.PopState(); // fsm.PushState(performActionState); // } // else // { // Debug.Log("<color=orange>Failed Plan</color>" + PrettyPrint(goal)); // dataProvider.PlanFailed(goal); // fsm.PopState(); // fsm.PushState(idleState); // } // isPlanning = false; // } //} }; }
/// <summary> /// 创建空闲状态 /// </summary> private void CreateIdleState() { idleState = (fsm, gameObj) => { // GOAP planning // GOAP计划 // 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>失败的计划:</color>" + PrettyPrint(goals)); dataProvider.PlanFailed(goals); //返回空闲操作状态 fsm.popState(); // move back to IdleAction state fsm.pushState(idleState); } }; }
public override void Update(float dt) { Queue <GoapAction> plan = planner.Plan(agent, availableActions, worldState, goal); if (plan != null) { agent.SetCurrentAction(plan); controller.Change("perform_action_state"); } else { Debug.Log("<color=orange>Failed Plan:</color>"); goapData.PlanFailed(goal); controller.Change("idle"); } }
/// <summary> /// Implementation of <see cref="IAction"/> interface. Calls the Plan method of the <see cref="GoapPlanner"/>. /// </summary> public void Execute() { // get the world state and the goal we want to plan for var worldState = _dataProvider.GetWorldState(); var goal = _dataProvider.CreateGoalState(); // Plan var plan = _planner.Plan(_agent.gameObject, _agent.GetAvailableActions(), worldState, goal); if (plan != null)// we have a plan, hooray! { _agent.SetCurrentActions(plan); _dataProvider.PlanFound(goal, plan); } else// ugh, we couldn't get a plan { _dataProvider.PlanFailed(goal); } }
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); } }; }
private void CreateIdleState() { _idleState = (fsm, gameObject) => { Debug.Log("Making plan --"); // GOAP Planning -- What're you gonna do?! // get world state and goal we want to plan for var worldState = _dataProvider.GetWorldState(); var goal = _dataProvider.CreateGoalState(); // PLAN Queue <GOAPAction> plan = _planner.Plan(gameObject, _availableActions, worldState, goal); if (plan != null) { Debug.Log("-- plan made"); // plan created, success _currentActions = plan; _dataProvider.PlanFound(goal, plan); _fsm.PopState(); _fsm.PushState(_performState); } else { Debug.Log("-- plan unable to be made"); // plan could not be created _dataProvider.PlanFailed(goal); _fsm.PopState(); _fsm.PushState(_idleState); } }; }