protected virtual void OnDonePlanning(IReGoapGoal <T, W> newGoal) { CurrentReGoapPlanWorker = null; if (newGoal == null) { if (currentGoal == null) { ReGoapLogger.LogWarning("GoapAgent " + this + " could not find a plan."); } return; } if (currentActionState != null) { currentActionState.Action.Exit(null); } currentActionState = null; currentGoal = newGoal; var plan = currentGoal.GetPlan(); startingPlan = plan.ToList(); ClearPlanValues(); foreach (var actionState in startingPlan) { actionState.Action.PostPlanCalculations(this); } currentGoal.Run(WarnGoalEnd); PushAction(); }
public virtual void WarnGoalEnd(IReGoapGoal <T, W> goal) { if (goal != currentGoal) { ReGoapLogger.LogWarning(string.Format("[GoapAgent] Goal {0} warned for end but is not current goal.", goal)); return; } CalculateNewGoal(); }
public virtual void WarnActionFailure(IReGoapAction <T, W> thisAction) { if (currentActionState != null && thisAction != currentActionState.Action) { ReGoapLogger.LogWarning(string.Format("[GoapAgent] Action {0} warned for failure but is not current action.", thisAction)); return; } if (BlackListGoalOnFailure) { goalBlacklist[currentGoal] = Time.time + currentGoal.GetErrorDelay(); } CalculateNewGoal(true); }
// called in another thread private void OnDonePlan(ReGoapPlannerThread <T, W> plannerThread, ReGoapPlanWork <T, W> work, IReGoapGoal <T, W> newGoal) { work.NewGoal = newGoal; lock (doneWorks) { doneWorks.Add(work); } if (work.NewGoal != null && ReGoapLogger.Instance.Level == ReGoapLogger.DebugLevel.Full) { ReGoapLogger.Log("[GoapPlannerManager] Done calculating plan, actions list:"); var i = 0; foreach (var action in work.NewGoal.GetPlan()) { ReGoapLogger.Log(string.Format("{0}: {1}", i++, action.Action)); } } }
protected virtual void Awake() { ReGoapNode <T, W> .Warmup(NodeWarmupCount); ReGoapState <T, W> .Warmup(StatesWarmupCount); ReGoapLogger.Instance.Level = LogLevel; if (Instance != null) { Destroy(this); var errorString = "[GoapPlannerManager] Trying to instantiate a new manager but there can be only one per scene."; ReGoapLogger.LogError(errorString); throw new UnityException(errorString); } Instance = this; doneWorks = new List <ReGoapPlanWork <T, W> >(); ReGoapPlannerThread <T, W> .WorksQueue = new Queue <ReGoapPlanWork <T, W> >(); planners = new ReGoapPlannerThread <T, W> [ThreadsCount]; threads = new Thread[ThreadsCount]; if (MultiThread) { ReGoapLogger.Log(String.Format("[GoapPlannerManager] Running in multi-thread mode ({0} threads).", ThreadsCount)); for (int i = 0; i < ThreadsCount; i++) { planners[i] = new ReGoapPlannerThread <T, W>(PlannerSettings, OnDonePlan); var thread = new Thread(planners[i].MainLoop); thread.Start(); threads[i] = thread; } } // no threads run else { ReGoapLogger.Log("[GoapPlannerManager] Running in single-thread mode."); planners[0] = new ReGoapPlannerThread <T, W>(PlannerSettings, OnDonePlan); } }