// Returns a list of actions (from the available actions) that satisfy one or all of our goals required states. List <GoapAction> GetGoalActions(GoapGoal goal) { List <GoapAction> ReturnActions = new List <GoapAction>(); foreach (GoapState state in goal.RequiredWorldState) { foreach (GoapAction action in AvailableActions) { if (action.CanActionRun()) { for (int i = 0; i < action.SatisfiesStates.Count; ++i) { if (GoapState.Compare(state, action.SatisfiesStates[i])) { ReturnActions.Add(action); } } } } } return(ReturnActions); }
// test to see if the actions required states match our current world states. bool TestActionAgainstWorldState(GoapAction action) { if (action.RequiredStates.Count > 0) { foreach (GoapState actionState in action.RequiredStates) { bool currentStateCheck = false; foreach (GoapState worldState in CurrentWorldState) { if (GoapState.Compare(actionState, worldState)) { currentStateCheck = true; } } if (!currentStateCheck) { return(false); } } } return(true); }
// test to see if our current world state matches that of our goals required states. bool TestGoalStateAgainstWorldState(GoapGoal goal) { bool GoalStatesMatch = true; foreach (GoapState goalState in goal.RequiredWorldState) { bool currentStateCheck = false; foreach (GoapState worldState in CurrentWorldState) { if (GoapState.Compare(worldState, goalState)) { currentStateCheck = true; } } if (!currentStateCheck) { GoalStatesMatch = false; break; } } return(GoalStatesMatch); }