diff --git a/Content.Server/NPC/HTN/HTNPlanJob.cs b/Content.Server/NPC/HTN/HTNPlanJob.cs index 9c62f5840a..8a57d52a66 100644 --- a/Content.Server/NPC/HTN/HTNPlanJob.cs +++ b/Content.Server/NPC/HTN/HTNPlanJob.cs @@ -56,16 +56,16 @@ public sealed class HTNPlanJob : Job // hence we'll store it here. var appliedStates = new List?>(); - var tasksToProcess = new Queue(); + var tasksToProcess = new Stack(); var finalPlan = new List(); - tasksToProcess.Enqueue(_rootTask); + tasksToProcess.Push(_rootTask); // How many primitive tasks we've added since last record. var primitiveCount = 0; int tasksProcessed = 0; - while (tasksToProcess.TryDequeue(out var currentTask)) + while (tasksToProcess.TryPop(out var currentTask)) { if (tasksProcessed++ > _rootTask.MaximumTasks) throw new Exception("HTN Planner exceeded maximum tasks"); @@ -161,7 +161,7 @@ public sealed class HTNPlanJob : Job /// /// Goes through each compound task branch and tries to find an appropriate one. /// - private bool TryFindSatisfiedMethod(HTNCompoundTask compoundId, Queue tasksToProcess, NPCBlackboard blackboard, ref int mtrIndex) + private bool TryFindSatisfiedMethod(HTNCompoundTask compoundId, Stack tasksToProcess, NPCBlackboard blackboard, ref int mtrIndex) { var compound = _protoManager.Index(compoundId.Task); @@ -182,9 +182,9 @@ public sealed class HTNPlanJob : Job if (!isValid) continue; - foreach (var task in branch.Tasks) + foreach (var task in branch.Tasks.AsEnumerable().Reverse()) { - tasksToProcess.Enqueue(task); + tasksToProcess.Push(task); } return true; @@ -198,7 +198,7 @@ public sealed class HTNPlanJob : Job /// private void RestoreTolastDecomposedTask( Stack decompHistory, - Queue tasksToProcess, + Stack tasksToProcess, List?> appliedStates, List finalPlan, ref int primitiveCount, @@ -223,7 +223,7 @@ public sealed class HTNPlanJob : Job primitiveCount = lastDecomp.PrimitiveCount; blackboard = lastDecomp.Blackboard; - tasksToProcess.Enqueue(lastDecomp.CompoundTask); + tasksToProcess.Push(lastDecomp.CompoundTask); } ///