Skip to content

Units shouldn't route through rival cities #371

Description

@QuintillusCFC

While play-testing another change, I noticed an AI-controlled Carthaginian settler trying to go through Athens.

image

From the console output I can tell that it is trying to reach the tile indicated with the purple star. It's been stuck at the same tile for a few turns and the obvious conclusion is that it is trying to go north through Athens.

We should exclude rival cities from our routing calculations, likely by setting the distance to infinite (unless there's a future option enable to allow passage through friendly cities, like in Civ4. We could add that check in at this point so things are flexible, even if it always returns false for now).

This is a small incremental step towards better routing. I've listed it as a bug since the settler gets permanently stuck (well, unless the city gets destroyed perhaps), though I expect many of those improvements (e.g. respecting lack of right of passage once we have borders) will be improvements.

There are also a few other non-related units-getting-stuck issues, many of which I suspect are due to the unit's goal no longer being achievable, rather than pathing.

This may optionally be added to Carthage, or done later for Dutch.

Activity

  1. added this to the Unit Pathing milestone on Oct 16, 2022
  2. Kright commented on Oct 18, 2022

    @Kright
    Collaborator

    You can add another walker, which checks that tile hasn't enemy city.
    https://github.com/C7-Game/Prototype/blob/Development/C7Engine/AI/Pathing/EdgeWalker.cs
    This walker could be passed to DijkstraAlgorithm here: https://github.com/C7-Game/Prototype/blob/Development/C7Engine/AI/Pathing/DijkstrasAlgorithm.cs#L23

  3. WildWeazel commented on Oct 21, 2022

    @WildWeazel
    Member

    What actually happens when the AI tries to do this? Does the unit lose/waste its MP? Is the AI waiting for the path to clear?

  4. QuintillusCFC commented on Oct 22, 2022

    @QuintillusCFC
    MemberAuthor

    What actually happens when the AI tries to do this? Does the unit lose/waste its MP? Is the AI waiting for the path to clear?

    It gets the city tile as the next tile on its path, and tries to move there, but can't, so it stays where it is.

    I believe that the next turn it gets the tile after the city on its path, which it also can't move to because it doesn't neighbor that tile, so it stays put.

    There will be future enhancements required too, around paths becoming invalid after they are assigned. #213 is related to that problem.

  5. TomWerner commented on Jan 19, 2025

    @TomWerner
    Contributor

    I've an easy way to reproduce this issue, we can modify the default save to put an enemy city right next to our start, and give ourselves a warrior.

    If you start the game via "new game", wait one turn, and then try to walk to the other side of the American city, we try to path right through the city.

    https://github.com/C7-Game/Prototype/compare/twrner/patch-for-non-defending-units?expand=1

  6. Billytifft commented on Sep 23, 2026

    @Billytifft
    Contributor

    Verified this is fixed by the intent-based movement refactor: a rival city tile is rejected as an intermediate path node for human and AI units, at peace and at war, while remaining targetable as an attack destination. Non-combat units can never enter rival cities at all.

    Added 7 regression tests in PR #1002 locking in the behavior. I recommend closing this as fixed once the PR merges.

  7. added 2 commits that reference this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions