Let the player see where a unit can walk #20

Merged
icub3d merged 1 commit from 5-pathfinding-and-movement-range into main 2026-09-13 17:03:51 +00:00
Owner

Routing lives in src/world/path.rs with no ECS in sight: a Terrain view over the
map plus the columns units occupy, reachable to flood-fill a movement allowance, and
route for A* to a distant goal. One search body serves both, so the step rules and the
tie-break are stated once rather than twice with a chance to disagree.

Determinism is the point of the tie-break. A heap keyed on (priority, push order, node) breaks ties by discovery order, and a tile is never re-parented by an equal-cost
rival — so the same start and goal give the identical route, not merely an equal-length
one. That is what replay and PvP need, and what a player who walks the same path twice
expects to see.

Steps cost one and may cross one unit of height (MAX_STEP). What elevation costs is
an M2 question; this is the floor it will be built on.

src/world/movement.rs is the thin ECS layer over that search: left-click selects the
unit under the cursor, since the camera already owns right and middle. One flood fill
answers both halves of the overlay — the tiles offered and the route to the one hovered
come from the same search, so a unit can never walk a different way than the line
promised. Three shapes, not three colours, per § Visual Style: a square on the selected
unit's tile, a diamond on each tile it can reach, and a line to the cursor ending in an
arrowhead.

A move can be previewed but not made; executing one is an action, and actions arrive
with resolution (#7).

Verification

cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test (114
passing) are clean. There is no display in this environment, so the overlay's appearance
is unverified — when you run it, look at whether the diamonds stop where the movement
allowance says they should, and whether the arrowhead lands on the tile under the cursor
rather than one off it.

Closes #5

🤖 Generated with Claude Code

https://claude.ai/code/session_01TA4hJHkRSU3XBxZYtMKXdh

Routing lives in `src/world/path.rs` with no ECS in sight: a `Terrain` view over the map plus the columns units occupy, `reachable` to flood-fill a movement allowance, and `route` for A* to a distant goal. One search body serves both, so the step rules and the tie-break are stated once rather than twice with a chance to disagree. Determinism is the point of the tie-break. A heap keyed on `(priority, push order, node)` breaks ties by discovery order, and a tile is never re-parented by an equal-cost rival — so the same start and goal give the identical route, not merely an equal-length one. That is what replay and PvP need, and what a player who walks the same path twice expects to see. Steps cost one and may cross one unit of height (`MAX_STEP`). What elevation *costs* is an M2 question; this is the floor it will be built on. `src/world/movement.rs` is the thin ECS layer over that search: left-click selects the unit under the cursor, since the camera already owns right and middle. One flood fill answers both halves of the overlay — the tiles offered and the route to the one hovered come from the same search, so a unit can never walk a different way than the line promised. Three shapes, not three colours, per § Visual Style: a square on the selected unit's tile, a diamond on each tile it can reach, and a line to the cursor ending in an arrowhead. A move can be previewed but not made; executing one is an action, and actions arrive with resolution (#7). ## Verification `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, and `cargo test` (114 passing) are clean. There is no display in this environment, so the overlay's appearance is unverified — when you run it, look at whether the diamonds stop where the movement allowance says they should, and whether the arrowhead lands on the tile under the cursor rather than one off it. Closes #5 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01TA4hJHkRSU3XBxZYtMKXdh
Routing lives in `src/world/path.rs` with no ECS in sight: a `Terrain` view
over the map plus the columns units occupy, `reachable` to flood-fill a
movement allowance, and `route` for A* to a distant goal. One search body
serves both, so the step rules and the tie-break are stated once rather than
twice with a chance to disagree.

Determinism is the point of the tie-break. A heap keyed on `(priority, push
order, node)` breaks ties by discovery order, and a tile is never re-parented
by an equal-cost rival. The same start and goal therefore give the identical
route, not merely an equal-length one — which is what replay and PvP need, and
what a player who walks the same path twice expects to see.

Steps cost one and may cross one unit of height (`MAX_STEP`). What elevation
*costs* is an M2 question; this is the floor it will be built on.

`src/world/movement.rs` is the thin ECS layer over that search: left-click
selects the unit under the cursor, since the camera already owns right and
middle. One flood fill answers both halves of the overlay — the tiles offered
and the route to the one hovered come from the same search, so a unit can never
walk a different way than the line promised.

Three shapes, not three colours, per § Visual Style: a square on the selected
unit's tile, a diamond on each tile it can reach, and a line to the cursor
ending in an arrowhead. A move can be previewed but not made; executing one is
an action, and actions arrive with resolution (#7).

Closes #5

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TA4hJHkRSU3XBxZYtMKXdh
icub3d merged commit 04fee29550 into main 2026-09-13 17:03:51 +00:00
icub3d deleted branch 5-pathfinding-and-movement-range 2026-09-13 17:03:52 +00:00
Sign in to join this conversation.
No description provided.