public bool IsBeatInPlan(Beat beat) { return(Beats.Contains(beat)); }
private void GeneratePlans(Beat TargetBeat)
private IEnumerator GeneratePlans(Beat TargetBeat) #endif { _currentPlan = null; UnityEngine.Profiling.Profiler.BeginSample("Gather viable beats"); List <Beat> starterBeats = new List <Beat>(_beatSet); for (int idx = starterBeats.Count - 1; idx >= 0; idx--) { if (!IsBeatViable(starterBeats[idx]) || starterBeats[idx] == _currentBeat) { starterBeats.RemoveAt(idx); } } List <Beat> beatSet = new List <Beat>(); foreach (Beat beat in _beatSet) { if (beat.RepetitionsPerformed < beat.MaxRepetitions) { beatSet.Add(beat); } } UnityEngine.Profiling.Profiler.EndSample(); //Gather viable beats #if !DEBUG_PLANNER yield return(null); #endif UnityEngine.Profiling.Profiler.BeginSample("Setup jobs"); int numPlans = starterBeats.Count; if (numPlans > 0) { GoalOrientedActionPlanner[] jobs = new GoalOrientedActionPlanner[numPlans]; for (int idx = 0; idx < numPlans; idx++) { jobs[idx] = new GoalOrientedActionPlanner() { State = _worldState.GetCurrentWorldState(), Beats = beatSet, TargetBeat = TargetBeat, StartBeat = starterBeats[idx], Archetype = _worldState.Archetype, }; jobs[idx].Execute(); #if !DEBUG_PLANNER yield return(null); #endif } UnityEngine.Profiling.Profiler.EndSample(); //Setup jobs #if !DEBUG_PLANNER yield return(null); #endif //!DEBUG_PLANNER Plan bestPlan = jobs[0].NarrativePlan; foreach (GoalOrientedActionPlanner job in jobs) { if ((bestPlan == null && job.NarrativePlan != null) || (job.NarrativePlan != null && job.NarrativePlan.Score < bestPlan.Score)) { bestPlan = job.NarrativePlan; } } _currentPlan = bestPlan; if (_currentPlan == null) { Debug.LogError("No plan found to beat " + TargetBeat.Title); } } else { Debug.LogError("Couldn't generate any plans as there are no viable starter beats"); } OnFinished.InvokeSafe(); }
private bool IsBeatViable(Beat beat) { return(!beat.ExceededMaxRepititions && beat.MeetsPreconditions(_worldState)); }