Don't route through rival cities or onto foreign-unit tiles - #1002
Open
Billytifft wants to merge 1 commit into
Open
Billytifft wants to merge 1 commit into
Billytifft wants to merge 1 commit into
Conversation
This was referenced Sep 23, 2026
This was
linked to
issues
Sep 28, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two related AI-routing fixes around foreign barriers, in one small PR:
#371 — Units shouldn't route through rival cities. Verified the intent-based movement refactor already rejects rival city tiles as intermediate path nodes. Added 7 regression tests locking in the behavior for human and AI units (peace and war): cities are avoided in the middle of a path, but remain targetable as an attack destination; non-combat units can never enter them.
#213 — Settler AI stuck forever when destination is unreachable. The original crash (
"Could not get next part of path"exception) is already gone —TryToMoveAlongPathrepaths and fails gracefully withResult.Error. But a reproduction test found the settler still gets effectively stuck:SettlerLocationAI.GetScoredSettlerCandidatesre-picks a destination the settler can't reach (e.g., a rival unit parked on it), so it re-evaluates the same impossible task every turn and never builds. Fixed by excluding tiles occupied by foreign units from settlement candidates.Changes
C7Engine/AI/UnitAI/SettlerLocationAI.cs— exclude foreign-unit-occupied tiles from settlement candidates (If Settler AI can't complete the next step in its path, it gives up and stays where it is forever #213)EngineTests/AI/UnitAI/SettlerDestinationBlockedTest.cs— 2 tests: no longer retargets unreachable destination; fails gracefully when blocked mid-journey (If Settler AI can't complete the next step in its path, it gives up and stays where it is forever #213)EngineTests/AI/Pathing/RivalCityRoutingTest.cs— 7 regression tests for rival-city routing (Units shouldn't route through rival cities #371)Verification
dotnet build— 0 errorsdotnet test— 83 passed, 0 faileddotnet format ... whitespace --verify-no-changes— clean