You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spent some time looking in to #7025 and it's actually a touch more complex than expected. The AI code limits the guard range with various hardcoded multipliers based on the offending object (weapon, hostile ship, asteroid, etc) and in one instance has an actual hardcoded distance in meters. These values also take in to account the size of the guardee. So it's really pretty complex.
I felt a Guard Tight order would further muddy this up by adding more hardcoded values or multipliers and it wouldn't be easily tunable or readily apparent what the actual difference is for players or mission designers.
After some experimentation I landed on a design that is maybe a touch overly simplistic in some ways but also more configurable. I've added a set-guard-range sexp that works as a clamp for the guard order ranges. The game will use the normal hardcoded logic but if the guard range is > 0 for the guardee ship then it will clamp the calculated range to the guard range. This can be done per-ship which gives mission designers flexibility to tune the guard range based on context. There is not any checking for positive values so you could probably get some pretty interesting AI behavior if the range is set to a value that's too small for the guardee ship class (50m for an Orion might be strange). However, I felt that adding a bunch of dynamic checks was overkill here and mission designers are smart enough to set realistic ranges.
This setup has the advantage of allowing the opposite as well. With set-guard-range you could expand the guard distance if the mission design calls for that sort of thing. Bonus!
wookieejedi
added
enhancement
A new feature or upgrade of an existing feature to add additional functionality.
ai
A feature or issue related to the AI algorithms
labels
Mar 2, 2026
I realized I should have asked this here just to save any other reviewers the same question:
With the math on the PR looking good I was now looking at where other places that MAX_GUARD_DIST is used, and another are 4 other spots (2 sets of 2 uses). I'm guessing you likely looked at those already, but if not would it make sense to use ai_guard_threshold( there or perhaps not?
I realized I should have asked this here just to save any other reviewers the same question: With the math on the PR looking good I was now looking at where other places that MAX_GUARD_DIST is used, and another are 4 other spots (2 sets of 2 uses). I'm guessing you likely looked at those already, but if not would it make sense to use ai_guard_threshold( there or perhaps not?
I honestly can't remember why I chose to leave those out. I'll need to do some additional testing. I'm going to set this to draft until I can verify.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aiA feature or issue related to the AI algorithmsenhancementA new feature or upgrade of an existing feature to add additional functionality.
2 participants
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.
I spent some time looking in to #7025 and it's actually a touch more complex than expected. The AI code limits the guard range with various hardcoded multipliers based on the offending object (weapon, hostile ship, asteroid, etc) and in one instance has an actual hardcoded distance in meters. These values also take in to account the size of the guardee. So it's really pretty complex.
I felt a Guard Tight order would further muddy this up by adding more hardcoded values or multipliers and it wouldn't be easily tunable or readily apparent what the actual difference is for players or mission designers.
After some experimentation I landed on a design that is maybe a touch overly simplistic in some ways but also more configurable. I've added a
set-guard-rangesexp that works as a clamp for the guard order ranges. The game will use the normal hardcoded logic but if the guard range is > 0 for the guardee ship then it will clamp the calculated range to the guard range. This can be done per-ship which gives mission designers flexibility to tune the guard range based on context. There is not any checking for positive values so you could probably get some pretty interesting AI behavior if the range is set to a value that's too small for the guardee ship class (50m for an Orion might be strange). However, I felt that adding a bunch of dynamic checks was overkill here and mission designers are smart enough to set realistic ranges.This setup has the advantage of allowing the opposite as well. With set-guard-range you could expand the guard distance if the mission design calls for that sort of thing. Bonus!
Fixes #7025