Make HTN constantly replanning optional (#33023)

Make constant replanning optional
And apply it to our most expensive NPCs
This commit is contained in:
osjarw
2025-04-18 11:16:26 +03:00
committed by GitHub
parent 90359e407c
commit cca5a88be4
5 changed files with 9 additions and 2 deletions

View File

@@ -37,6 +37,9 @@ public sealed partial class HTNComponent : NPCComponent
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float PlanAccumulator = 0f; public float PlanAccumulator = 0f;
[DataField]
public bool ConstantlyReplan = true;
[ViewVariables] [ViewVariables]
public HTNPlanJob? PlanningJob = null; public HTNPlanJob? PlanningJob = null;

View File

@@ -328,7 +328,7 @@ public sealed class HTNSystem : EntitySystem
component.PlanAccumulator -= frameTime; component.PlanAccumulator -= frameTime;
// We'll still try re-planning occasionally even when we're updating in case new data comes in. // We'll still try re-planning occasionally even when we're updating in case new data comes in.
if (component.PlanAccumulator <= 0f) if ((component.ConstantlyReplan || component.Plan is null) && component.PlanAccumulator <= 0f)
{ {
RequestPlan(component); RequestPlan(component);
} }
@@ -462,7 +462,7 @@ public sealed class HTNSystem : EntitySystem
if (component.PlanningJob != null) if (component.PlanningJob != null)
return; return;
component.PlanAccumulator += component.PlanCooldown; component.PlanAccumulator = component.PlanCooldown;
var cancelToken = new CancellationTokenSource(); var cancelToken = new CancellationTokenSource();
var branchTraversal = component.Plan?.BranchTraversalRecord; var branchTraversal = component.Plan?.BranchTraversalRecord;

View File

@@ -332,6 +332,7 @@
- type: Item - type: Item
size: Tiny size: Tiny
- type: HTN - type: HTN
constantlyReplan: false
rootTask: rootTask:
task: MouseCompound task: MouseCompound
- type: Physics - type: Physics
@@ -1681,6 +1682,7 @@
factions: factions:
- Mouse - Mouse
- type: HTN - type: HTN
constantlyReplan: false
rootTask: rootTask:
task: MouseCompound task: MouseCompound
- type: Physics - type: Physics

View File

@@ -70,6 +70,7 @@
factions: factions:
- SimpleHostile - SimpleHostile
- type: HTN - type: HTN
constantlyReplan: false
rootTask: rootTask:
task: GoliathCompound task: GoliathCompound
blackboard: blackboard:

View File

@@ -405,6 +405,7 @@
factions: factions:
- Mouse - Mouse
- type: HTN - type: HTN
constantlyReplan: false
rootTask: rootTask:
task: MouseCompound task: MouseCompound
- type: Physics - type: Physics