public void Init(IGoapPlanner planner, GoapState goalState, GoapNode <T> parent, IGoapAction action)
        {
            m_expandList.Clear();

            m_planner = planner;
            m_parent  = parent;
            m_action  = action;


            if (m_parent != null)
            {
                m_currentState = parent.GetState().Clone();
                m_gCost        = parent.GetCost();
            }
            else
            {
                m_currentState = m_planner.GetAgent().GetMemory().GetWorldState().Clone();
            }


            if (action != null)
            {
                m_gCost += action.GetCost();

                GoapState preconditions = action.GetPreConditions(goalState);
                m_targetState = goalState + preconditions;

                GoapState effects = action.GetPostEffects(goalState);
                m_currentState.AddFromState(effects);


                //Did this action's effect fulfill any of the goals?
                m_targetState.RemoveCompletedConditions(effects);

                //Did the world fulfill any of the goals?
                m_targetState.RemoveCompletedConditions(m_planner.GetAgent().GetMemory().GetWorldState());
            }
            else
            {
                var diff = GoapState.Instantiate();
                goalState.CreateStateWithMissingDifferences(m_currentState, ref diff);
                m_targetState = diff;
            }


            //Cost is equal to the amount of extra actions
            m_hCost = m_targetState.Count;
        }
Exemple #2
0
 public BaseGoapMemory()
 {
     m_state = GoapState.Instantiate();
 }
 public BaseGoapAction()
 {
     m_postEffects   = GoapState.Instantiate();
     m_preConditions = GoapState.Instantiate();
     m_canInterrupt  = true;
 }
Exemple #4
0
 public BaseGoapGoal()
 {
     m_goalState = GoapState.Instantiate();
 }