Route Finding and Pathing Mechanics
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Route finding and pathing mechanics in Trans AI govern how the agent identifies, constructs, and manages transportation networks across various terrain types in OpenTTD. The system is designed to handle multiple transport modes, including air, road, marine, and rail, to move passengers and freight between towns and industries.
The core objective of these mechanics is to implement a "Cargo Concept" (many-to-one), where the AI attempts to consolidate cargo destinations to optimize efficiency. The system adapts its pathing logic based on game settings, such as infrastructure maintenance, and utilizes external libraries to facilitate list management and string manipulation during route calculation.
Sources: README.md:1-10, ROADMAP.md:32-35
Multi-Modal Pathing Logic
Trans AI categorizes its pathing mechanics by the specific requirements of the transport medium. Each mode has distinct rules for connecting origins and destinations.
Air and Marine Pathing
Air and marine routes utilize a point-to-point or node-based navigation system.
- Air Routes: The AI identifies towns capable of supporting airports. It distinguishes between standard aircraft for town-to-town transit and choppers specifically for town-to-oil rig connections.
- Marine Routes: Navigation is managed through the placement of buoys. These buoys act as waypoints to ensure ships can find proper paths across water bodies to reach towns or industries.
Sources: ROADMAP.md:4-10, ROADMAP.md:19-22
Road and Rail Infrastructure
Land-based pathing is more complex, requiring the AI to navigate terrain for track and road placement.
- Road/Tram: Pathing supports both passenger transport (town-to-town) and freight (industry-to-industry). Tram pathing includes specific logic for mail-carrying vehicles.
- Rail Trackage: The AI prioritizes double-track routes. If the environment or financial constraints prevent double tracks, the system falls back to single-track pathing with a logic gate limiting operations to two trains to prevent deadlocks.
Sources: ROADMAP.md:12-17, ROADMAP.md:24-30
Pathing Architecture and Dependencies
The AI does not implement all pathing logic from scratch; it relies on standardized libraries to manage the data structures required for route finding.
The diagram shows the relationship between Trans AI, its required libraries, and the high-level flow of identifying route nodes.
Sources: README.md:42-46, ROADMAP.md:1-2
Implementation Status and Features
| Route Type | Feature | Implementation Status | Pathing Specifics |
|---|---|---|---|
| Air | Town-to-Town | Completed | Airport-to-Airport navigation |
| Air | Town-to-Oil Rig | In Progress | Specialized Chopper pathing |
| Marine | Buoy Navigation | Completed | Waypoint-based marine routing |
| Road | Freight/Passenger | Completed | Multi-stop bus and truck routing |
| Rail | Industry-to-Industry | Completed | Raw cargo transport logic |
| Rail | Double Track | Completed | Fallback to single track if restricted |
Sources: ROADMAP.md:4-30
Pathing Optimization Strategies
The AI utilizes specific strategies to refine its pathing and network efficiency:
- Cargo Concept (Many-to-One): The AI restricts destination variety to simplify pathing networks. This logic is currently being reworked for road and marine routes to improve efficiency.
- Infrastructure Awareness: The pathing system detects if "infrastructure maintenance" is enabled. If active, the AI adjusts its build patterns, particularly for air routes, to ensure financial viability.
- CargoDist Support: Future updates aim to integrate with the CargoDist API, which will fundamentally change pathing from point-to-point to a demand-driven network model.
Sources: ROADMAP.md:32-48, README.md:5-9
Maintenance and Versioning in Development
As a rolling release project, the pathing logic is subject to daily updates. Developers working on the pathing engine use a versioning override in info.nut (setting a future date) to ensure local experimental pathing logic takes priority over stable versions during testing.
Sources: README.md:48-54, info.nut
Summary
Route Finding and Pathing Mechanics in Trans AI provide a multi-modal framework for navigating OpenTTD environments. By leveraging external libraries for list and string management and adhering to the "Cargo Concept," the AI creates structured networks for aircraft, ships, trains, and road vehicles. Significant focus is placed on fallback mechanisms (like single-track rail) and environment-aware build strategies (like infrastructure maintenance detection) to maintain operational stability.