Fix Locomotor.CanMoveFreelyInto when using ignoreSelf. #21165
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.
The ignoreSelf flag is intended to allow the current actor to be ignored when checking for blocking actors. This check worked correctly for cells occupied by a single actor. When a cell was occupied by multiple actors, the check was only working if the current actor happened to be the first actor. This is incorrect, if the current actor is anywhere in the cell then this flag should apply.
This flag failing to be as effective as intended meant that checks in methods such as PathFinder.FindPathToTargetCells would consider the source cell inaccessible, when it should have considered the cell accessible. This is a disaster for performance as an inaccessible cell requires a slow fallback path that performs a local path search. This means pathfinding was unexpectedly slow when this occurred. One scenario is force attacking with a group of infantry sharing the same cell. They should benefit from this check to do a fast path search, but failed to benefit from this check and the search would be slow instead.
Applying the flag correctly resolves the performance impact.
This resolves poor performance in #21132, where the AI is trying to order many units at once, and in particular groups of infantry cause a large slowdown due to this bug. Note attempting to run the replay with this PR applied will cause a desync. This is expected as the paths the pathfinder returns will be different.
Testcase:
/path-debug
command.With this PR applied, you will see a search that looks like this. The green lines indicate the hierarchical pathfinder has been used. This is good as it makes the path search cheaper. You can see a reasonable amount of yellow lines that show the explored route. This is also the same outcome you will get if you force-attack when the unit is standing on its own.
Without this PR, the search will look like this. No green lines means the hierarchical pathfinder did not get used. The local pathfinder had to do everything on its own. You will see more yellow lines indicating it had to explore more cells. More explored cells = more expensive.