Example #1
0
    /********************************************
    *			GETTERS/SETTERS
    ********************************************/

    public override float GetHeuristicDistance(AgentHuman ai, AStarNode aStarNode, bool firstRun)
    {
        //If we are on the first run then we know that we have no node so we need to setup the first node
        AStarGOAPNode node = (AStarGOAPNode)aStarNode;

        if (firstRun)
        {
            //Copy the WS satisfaction conditions to the nodes goal state
            node.GoalState.Reset();
            Goal.SetWSSatisfactionForPlanning(node.GoalState);
            Goal.ChangeCurrentWSForPlanning(node.CurrentState);
        }
        else
        {
            //Now we know that the node being checked is an action.
            //We need to get the action and apply it
            GOAPAction action = Map.GetAction(aStarNode.NodeID);
            //if(action.ValidateWSPreconditions(node.CurrentState,node.GoalState))
            {
                //if(action.ValidateWSEffects(ai,&node.CurrentState,&node.GoalState))
                {
                    //action.AddInvalidPreconditionsToGoal(ai,&node.CurrentState,&node.GoalState);
                    //action.ApplyWSEffects(ai,&node.CurrentState,&node.GoalState);
                    action.SolvePlanWSVariable(node.CurrentState, node.GoalState);
                    action.SetPlanWSPreconditions(node.GoalState);
                }
            }
        }

        //  if (Owner.debugGOAP) Debug.Log("GetHeuristicDistance1 : goal" + node.GoalState.ToString());
        //  if (Owner.debugGOAP) Debug.Log("GetHeuristicDistance1 : current" + node.CurrentState.ToString());

        MergeStates(ai, node.CurrentState, node.GoalState);

        //       if (Owner.debugGOAP) Debug.Log("GetHeuristicDistance2 : goal" + node.GoalState.ToString());
//        if (Owner.debugGOAP) Debug.Log("GetHeuristicDistance2 : current" + node.CurrentState.ToString());

        return(node.GoalState.GetNumWorldStateDifferences(node.CurrentState));
    }