From ab9b5ac0b2cfaaa88f2c814104d3f103377d5948 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sat, 29 Apr 2023 16:47:10 +1000 Subject: [PATCH] Remove deprecated NPC debug buttons (#15824) --- Content.Client/NPC/NPCWindow.xaml | 3 +- Content.Client/NPC/NPCWindow.xaml.cs | 4 +++ Content.Server/NPC/HTN/HTNSystem.cs | 52 +++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Content.Client/NPC/NPCWindow.xaml b/Content.Client/NPC/NPCWindow.xaml index 664f15600c..68e58eca46 100644 --- a/Content.Client/NPC/NPCWindow.xaml +++ b/Content.Client/NPC/NPCWindow.xaml @@ -3,12 +3,11 @@ xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" Title="NPC debug" MinSize="200 200"> - + - diff --git a/Content.Client/NPC/NPCWindow.xaml.cs b/Content.Client/NPC/NPCWindow.xaml.cs index 968c761cc1..af8779c513 100644 --- a/Content.Client/NPC/NPCWindow.xaml.cs +++ b/Content.Client/NPC/NPCWindow.xaml.cs @@ -1,3 +1,4 @@ +using Content.Client.NPC.HTN; using Content.Client.UserInterface.Controls; using Content.Shared.NPC; using Robust.Client.AutoGenerated; @@ -13,14 +14,17 @@ public sealed partial class NPCWindow : FancyWindow RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); var sysManager = IoCManager.Resolve(); + var htn = sysManager.GetEntitySystem(); var path = sysManager.GetEntitySystem(); + NPCThonk.Pressed = htn.EnableOverlay; PathCrumbs.Pressed = (path.Modes & PathfindingDebugMode.Breadcrumbs) != 0x0; PathPolys.Pressed = (path.Modes & PathfindingDebugMode.Polys) != 0x0; PathNeighbors.Pressed = (path.Modes & PathfindingDebugMode.PolyNeighbors) != 0x0; PathRouteCosts.Pressed = (path.Modes & PathfindingDebugMode.RouteCosts) != 0x0; PathRoutes.Pressed = (path.Modes & PathfindingDebugMode.Routes) != 0x0; + NPCThonk.OnToggled += args => htn.EnableOverlay = args.Pressed; PathCrumbs.OnToggled += args => path.Modes ^= PathfindingDebugMode.Breadcrumbs; PathPolys.OnToggled += args => path.Modes ^= PathfindingDebugMode.Polys; PathNeighbors.OnToggled += args => path.Modes ^= PathfindingDebugMode.PolyNeighbors; diff --git a/Content.Server/NPC/HTN/HTNSystem.cs b/Content.Server/NPC/HTN/HTNSystem.cs index ad4cbf27d3..8ed8708c1f 100644 --- a/Content.Server/NPC/HTN/HTNSystem.cs +++ b/Content.Server/NPC/HTN/HTNSystem.cs @@ -223,11 +223,10 @@ public sealed class HTNSystem : EntitySystem { text.AppendLine($"BTR: {string.Join(", ", comp.Plan.BranchTraversalRecord)}"); text.AppendLine($"tasks:"); - - foreach (var task in comp.Plan.Tasks) - { - text.AppendLine($"- {task.ID}"); - } + var root = _prototypeManager.Index(comp.RootTask); + var btr = new List(); + var level = -1; + AppendDebugText(root, text, comp.Plan.BranchTraversalRecord, btr, ref level); } RaiseNetworkEvent(new HTNMessage() @@ -247,6 +246,49 @@ public sealed class HTNSystem : EntitySystem } } + private void AppendDebugText(HTNTask task, StringBuilder text, List planBtr, List btr, ref int level) + { + // If it's the selected BTR then highlight. + for (var i = 0; i < btr.Count; i++) + { + text.Append('-'); + } + + text.Append(' '); + + if (task is HTNPrimitiveTask primitive) + { + text.AppendLine(primitive.ID); + return; + } + + if (task is HTNCompoundTask compound) + { + level++; + text.AppendLine(compound.ID); + var branches = _compoundBranches[compound]; + + for (var i = 0; i < branches.Length; i++) + { + var branch = branches[i]; + btr.Add(i); + text.AppendLine($" branch {string.Join(" ", btr)}:"); + + foreach (var sub in branch) + { + AppendDebugText(sub, text, planBtr, btr, ref level); + } + + btr.RemoveAt(btr.Count - 1); + } + + level--; + return; + } + + throw new NotImplementedException(); + } + private void Update(HTNComponent component, float frameTime) { // If we're not planning then countdown to next one.