예제 #1
0
 public void CheckWorkers()
 {
     if (WorksQueue.TryDequeue(out ReGoapPlanWork <T, W> checkWork))
     {
         var work = checkWork;
         planner.Plan(work.Agent, work.BlacklistGoal, work.Actions,
                      (newGoal) => onDonePlan(this, work, newGoal));
     }
 }
 public void CheckWorkers()
 {
     if (WorksQueue.Count > 0)
     {
         ReGoapPlanWork <T, W> checkWork;
         lock (WorksQueue)
         {
             checkWork = WorksQueue.Dequeue();
         }
         var work = checkWork;
         planner.Plan(work.Agent, work.BlacklistGoal, work.Actions,
                      (newGoal) => onDonePlan(this, work, newGoal));
     }
 }
예제 #3
0
        public void TestImpossiblePlanDynamicActions()
        {
            var planner = new ReGoapPlanner <string, object>(
                new ReGoapPlannerSettings {
                PlanningEarlyExit = false, UsingDynamicActions = true, MaxIterations = 100, MaxNodesToExpand = 20
            }
                );

            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "BuyFood",
                                              new Dictionary <string, object> {
                { "IntGold", 10 }
            },
                                              new Dictionary <string, object> {
                { "IntGold", -10 }, { "IntFood", 1 }
            },
                                              3);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoMine",
                                              new Dictionary <string, object> {
                { "IntFood", 1 }
            },
                                              new Dictionary <string, object> {
                { "IntGold", 5 }, { "IntFood", -1 }
            },
                                              5);

            ReGoapTestsHelper.GetCustomGoal(gameObject, "GetGold",
                                            new Dictionary <string, object> {
                { "IntGold", 30 }
            });

            var memory = gameObject.AddComponent <ReGoapTestMemory>();

            memory.Init();
            memory.SetStructValue("IntGold", StructValue.CreateIntArithmetic(10));
            memory.SetStructValue("IntFood", StructValue.CreateIntArithmetic(3));

            var agent = gameObject.AddComponent <ReGoapTestAgent>();

            agent.Init();

            var plan = planner.Plan(agent, null, null, null);

            Assert.That(plan, Is.Null);
        }
예제 #4
0
    public void CheckWorkers()
    {
        PlanWork?checkWork = null;

        lock (worksQueue)
        {
            if (worksQueue.Count > 0)
            {
                checkWork = worksQueue.Dequeue();
            }
        }
        if (checkWork != null)
        {
            var work = checkWork.Value;
            planner.Plan(work.Agent, work.BlacklistGoal, work.Actions,
                         (newGoal) => onDonePlan(this, work, newGoal));
        }
    }
예제 #5
0
        protected virtual void CalculateNewGoal(bool forceStart = false)
        {
            if (IsPlanning)
            {
                return;
            }

            if (!forceStart && (Time.time - lastCalculationTime <= CalculationDelay))
            {
                return;
            }
            lastCalculationTime = Time.time;

            UpdatePossibleGoals();

            startedPlanning = true;

            Queue <ReGoapNode> _reGoapNodeList = reGoapPlanner.Plan(this);

            OnDonePlanning(_reGoapNodeList);
        }