Vehicle Selection and Purchasing Logic
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- ROADMAP.md
- license.txt
- .github/workflows/rolling-release.yml
- info.nut (Referenced via versioning and development build logic)
Vehicle Selection and Purchasing Logic in Trans AI governs how the artificial intelligence identifies, selects, and acquires transportation units to facilitate cargo movement between towns and industries. The system is designed to support a multi-modal transport network including road, rail, air, and marine routes, while adhering to the Cargo Concept strategy.
The logic operates within the OpenTTD environment, utilizing specific Squirrel-based libraries (AILib) to interface with game mechanics. It aims to optimize transport efficiency by selecting vehicle types—such as buses for passengers and trucks for freight—based on the available infrastructure and route requirements.
Sources: README.md:1-12, ROADMAP.md:1-25
Multi-Modal Vehicle Selection Strategy
Trans AI categorizes its purchasing logic based on the infrastructure type. Each route type has a specific set of rules for which vehicles are prioritized and purchased.
Road and Tram Vehicles
For road-based infrastructure, the AI differentiates between passenger and freight requirements. It utilizes both standard road vehicles and trams where applicable.
- Passenger Transport: Primarily uses buses (road) or tram-buses (tram track) for town-to-town connections.
- Freight Transport: Utilizes trucks or tram-trucks for industry-to-industry or industry-to-town routes. The AI notes that mail trucks are the most common available tram-based freight option.
Sources: ROADMAP.md:10-20
Rail Vehicle Logic
The rail system implements a specialized logic for track configuration and vehicle volume.
- Track Capacity: The system defaults to double-track builds. If double-track is not buildable, it falls back to a single-track configuration.
- Operational Limit: On single-track routes, the purchasing logic limits the number of operating trains to a maximum of two to prevent gridlock.
- Cargo Focus: Currently prioritized for raw cargo transport between industries.
Sources: ROADMAP.md:26-34
Air and Marine Vehicles
Air and marine selection is focused on high-capacity or specialized geographic needs.
- Aircraft: Selection includes standard airplanes for town-to-town passenger service and choppers specifically for town-to-oil rig transport.
- Ships: Used for both passengers/mail and freight cargoes. The purchasing logic is coupled with buoy placement logic to ensure valid pathfinding for the purchased vessels.
Sources: ROADMAP.md:5-9, ROADMAP.md:21-25
Vehicle Purchase Workflow
The purchasing process is triggered after route validation and infrastructure placement. The following diagram illustrates the high-level decision flow for vehicle acquisition.
The AI evaluates route capacity and infrastructure constraints before executing a purchase command via the AI Library.
Sources: ROADMAP.md:5-34, README.md:50-55
Specialized Purchasing Features
Cargo Concept (Many-to-One)
Trans AI implements a "Many-to-one" logic where it attempts to use a single industry as a destination for specific cargo types. This influences vehicle purchasing by concentrating fleet requirements on specific hubs rather than distributing them across various destinations.
Sources: ROADMAP.md:37-43, README.md:1-10
Competitor Acquisition
The logic extends beyond purchasing new vehicles to acquiring existing fleets through company mergers.
- Merger Acceptance: The AI can accept merger offers from competitors.
- Fleet Management: Once acquired, the AI attempts to convert negative-income vehicles into profitable units to avoid bankruptcy.
Sources: ROADMAP.md:46-51
Requirements and Dependencies
The purchasing logic relies on external AI libraries to execute commands within the OpenTTD engine.
| Library | Purpose in Purchasing |
|---|---|
| AILib Common | Basic AI functions and standard wrappers. |
| AILib List | Handling lists of available vehicles and their properties. |
| AILib String | Formatting vehicle names or handling string-based cargo types. |
Sources: README.md:48-55
Infrastructure Maintenance Integration
The AI's purchasing behavior is modified by the "Infrastructure Maintenance" game setting. If activated, the AI adjusts its vehicle selection—particularly for air routes—to ensure the revenue generated by the vehicles covers the maintenance costs of the airports and tracks.
Sources: ROADMAP.md:52-55
The Vehicle Selection and Purchasing Logic serves as the operational core of Trans AI, ensuring that the appropriate transport units are deployed across various terrains and cargo types. By balancing infrastructure constraints (like single-track limits) with strategic goals (like the Cargo Concept), the system maintains economic viability within the game.