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)]
public float PlanAccumulator = 0f;
[DataField]
public bool ConstantlyReplan = true;
[ViewVariables]
public HTNPlanJob? PlanningJob = null;

View File

@@ -328,7 +328,7 @@ public sealed class HTNSystem : EntitySystem
component.PlanAccumulator -= frameTime;
// 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);
}
@@ -462,7 +462,7 @@ public sealed class HTNSystem : EntitySystem
if (component.PlanningJob != null)
return;
component.PlanAccumulator += component.PlanCooldown;
component.PlanAccumulator = component.PlanCooldown;
var cancelToken = new CancellationTokenSource();
var branchTraversal = component.Plan?.BranchTraversalRecord;

View File

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

View File

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

View File

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