]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Remove deprecated NPC debug buttons (#15824)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 29 Apr 2023 06:47:10 +0000 (16:47 +1000)
committerGitHub <noreply@github.com>
Sat, 29 Apr 2023 06:47:10 +0000 (16:47 +1000)
Content.Client/NPC/NPCWindow.xaml
Content.Client/NPC/NPCWindow.xaml.cs
Content.Server/NPC/HTN/HTNSystem.cs

index 664f15600c99621ef407b2714461354805339daa..68e58eca465e6d196b71fffc9fdb5ab8eb3f7cbd 100644 (file)
@@ -3,12 +3,11 @@
             xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
             Title="NPC debug"
             MinSize="200 200">
-    <BoxContainer Name="Options" Orientation="Vertical">
+    <BoxContainer Name="Options" Orientation="Vertical" Margin="8 8">
         <controls:StripeBack>
             <Label Text="NPC" HorizontalAlignment="Center"/>
         </controls:StripeBack>
         <BoxContainer Name="NPCBox" Orientation="Vertical">
-            <CheckBox Name="NPCPath" Text="Path"/>
             <CheckBox Name="NPCThonk" Text="Thonk"/>
         </BoxContainer>
         <controls:StripeBack>
index 968c761cc1a67a9c0fa883d894b5e2a04340502b..af8779c51338ecdd87247cf6cb9016693c4e5dc6 100644 (file)
@@ -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<IEntitySystemManager>();
+        var htn = sysManager.GetEntitySystem<HTNSystem>();
         var path = sysManager.GetEntitySystem<PathfindingSystem>();
 
+        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;
index ad4cbf27d30466823456e913d123a596ef659422..8ed8708c1f609978aeb1f64cf39e7f48d0c7117b 100644 (file)
@@ -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<HTNCompoundTask>(comp.RootTask);
+                            var btr = new List<int>();
+                            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<int> planBtr, List<int> 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.