Expand description
Path finding over the map’s cells: the walkable regions and the A* pathfinder.
regionsgives every walkable cell the number of its connected region. A request between two regions fails at once, without a search.Pathfinderis the A* search, with a cost for each cell type (mode_costs).requestchecks a request as the original does, then searches.nearest_neighbourfinds the allowed cell next to a cell that is nearest to a target.
The original solves paths on a worker thread, and a walker polls for the result. The port solves a path when it is requested; the walker still reads the result on its next update, so the timing is the same.
See Citizens for how citizens use it.
Structs§
- Pathfinder
- The pathfinder: the map’s cells, the cost of each cell type, and the state of the A* search.
Constants§
- MAX_
PATH - Longest path a search returns.
- WALKABLE
- Cell types a walker may enter (0–4, 9–11).
- WATER
- Water and blocking types (5–8): requests touching them skip the region check.
Functions§
- bit
- The bit of a cell type in a type mask such as
WALKABLE. - mode_
costs - Per-type cost tables a mover selects (MoveTo) and whether the search may step diagonally.
- nearest_
neighbour - Of the 8 cells around
cellwhose type is inmask, the one nearest (squared cell distance) totoward; the first found wins ties (x outer, y inner). - regions
- Label connected walkable cells in scan order, starting at 1 (0 = none).
- request
- Validate a request (both end types join the mask; without water types both ends must share a non-zero region), set the mask and search.
- walkable
- Whether a walker may enter a cell of this type (the test
regionslabels by).