Allow the creation of recursive HTNs #30138
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About the PR
Added a limit to the maximum amount of tasks a plan can consider.
Gave the developers a way to exclude their compound tasks from being checked for recursive tasks by the integration test.
Why / Balance
Recursive tasks make the creation of longer plans a lot easier, and solving multiple problems in a single plan becomes more viable.
However, allowing the creation of recursive tasks may lead to cases where the tasks misbehave and continue extending a plan indefinitely. I solved this problem by setting a limit to how many tasks can be considered, and upon exceeding the amount, the NPC will be disabled, alongside throwing an exception to make the developers aware of the existence of a misbehaving NPC.
Technical details
Added
AllowRecursion
toHTNCompoundPrototype
, setting this to true makes the integration test ignore this task being recursive. This being opt-in ensures that unintentionally recursive tasks aren't merged.Made
HTNPlanJob.Process
keep track of how many tasks have been considered, and throw an exception upon exceeding the limit set inHTNPlanComponent
. If for some reason 1000 tasks isn't enough, it can be overridden on a per-entity basis.I guess I could've done this a lot better if I had better understanding of how the yml serialization works.
Media
Breaking changes
Changelog