Beispiel #1
0
    new void Start()
    {
        base.Start();

        GOAP_Goal idle = new GOAP_Goal("storeWood", 1, true);

        mainGoals.Add(idle, 1);
    }
Beispiel #2
0
    private void makePlansforGoals()
    {
        if (hasNoPlan())
        {
            planner = new GOAP_Planner();

            // Order all agent's desired goals and create a plan for each to see which are achievable.
            IOrderedEnumerable <KeyValuePair <GOAP_Goal, int> > orderedGoals = from goal in mainGoals orderby goal.Value descending select goal;
            foreach (KeyValuePair <GOAP_Goal, int> orderedGoal in orderedGoals)
            {
                actionQueue = planner.createPlan(possibleActions, orderedGoal.Key.goals, null);
                if (actionQueue != null)
                {
                    // We have a plan!
                    currentGoal = orderedGoal.Key;

                    break;
                }
            }
        }
    }
Beispiel #3
0
    private void Plan()
    {
        for (int i = 0; i < goals.Count; i++)
        {
            if (goals[i].isValid(this))
            {
                goal = goals[i];
                break;
            }
        }

        if (worldState.CompareState(goal.goalStates) == 0)
        {
            return;
        }

        currentPlan.Clear();
        Stack <SimulationStep> sim = new Stack <SimulationStep>();

        GOAP_Action[] simPlan = new GOAP_Action[maxPlanDepth];

        int minDepth = int.MaxValue;

        sim.Push(new SimulationStep(new GOAP_StatesList(worldState), null, 0));

        List <GOAP_States> targetStates = new List <GOAP_States>(goal.goalStates.states);

        while (sim.Count != 0)
        {
            currentSimData = sim.Pop();
            simPlan[currentSimData.depth] = currentSimData.action;

            if (currentSimData.depth > minDepth)
            {
                continue;
            }

            if (currentSimData.worldState.CompareState(goal.goalStates) == 0 || currentSimData.depth >= maxPlanDepth)
            {
                if (currentSimData.depth < minDepth)
                {
                    currentPlan.Clear();
                    for (int i = 0; i <= currentSimData.depth; i++)
                    {
                        if (simPlan[i] != null)
                        {
                            if (!currentPlan.Contains(simPlan[i]))
                            {
                                currentPlan.Enqueue(simPlan[i]);
                            }
                        }
                    }
                    minDepth = currentSimData.depth;
                }
            }
            else
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    if (actions[i].isValid(this))
                    {
                        GOAP_StatesList newSimState = new GOAP_StatesList(currentSimData.worldState);
                        newSimState.AddStates(actions[i].resultStates);
                        sim.Push(new SimulationStep(newSimState, actions[i], (currentSimData.depth + 1)));
                    }
                }
            }
        }
    }