Game State Synchronization
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 (referenced via README.md)
- info.nut (referenced via README.md)
Game State Synchronization in Trans AI refers to the mechanism by which the AI agent perceives, reacts to, and aligns its internal logic with the evolving state of the OpenTTD game world. This involves monitoring town growth, industry production, infrastructure availability, and competitor actions to ensure transport routes remain efficient and profitable.
The synchronization process is governed by the AI's integration with OpenTTD's NoAI framework, utilizing specific libraries to process game data and execute transport strategies such as the "Cargo Concept" (many-to-one delivery).
Sources: README.md:1-15, ROADMAP.md:38-40
Synchronization Architecture
Trans AI operates as an external controller that interacts with the OpenTTD engine. It synchronizes its internal state by polling game data through the OpenTTD AI API and reacting to environmental triggers, such as the activation of infrastructure maintenance settings.
Core Synchronization Components
The AI relies on several external libraries to manage data lists and string manipulations during the synchronization cycle.
| Component | Description | Source |
|---|---|---|
| AILib Common | Provides foundational utilities for game interaction. | README.md:46 |
| AILib List | Essential for managing collections of game objects (towns, industries, vehicles). | README.md:47 |
| AILib String | Handles text processing for station naming and data parsing. | README.md:48 |
| info.nut | Contains metadata used by the game engine to prioritize the AI version. | README.md:36-39 |
State Update Flow
The following diagram illustrates how the AI synchronizes its internal logic with the OpenTTD game state.
The AI detects if "infrastructure maintenance" is activated and adjusts its synchronization logic accordingly, particularly for air routes.
Sources: ROADMAP.md:46-48, README.md:45-48
Transport Route Synchronization
Trans AI synchronizes specific route logic based on the transport medium (Air, Road, Marine, Rail). Each medium has distinct triggers for updating the game state.
Route Logic and Status
| Route Type | Synchronization Focus | Implementation Status |
|---|---|---|
| Air | Town-to-town passenger transport; Airport/Aircraft type availability. | Implemented |
| Road | Bus (Passengers) and Truck (Freight) logistics. | Implemented |
| Marine | Buoy placement and pathfinding for ships. | Implemented |
| Rail | Industry-to-industry raw cargo; Double track logic. | Implemented |
| Chopper | Town-to-oil rig passenger ferry. | Planned |
Sources: ROADMAP.md:4-36
Rail Path Synchronization
The AI synchronizes rail infrastructure based on the complexity of the route. It prioritizes double tracks when buildable but includes fallback logic for single tracks with a two-train limit to prevent deadlocks in the synchronized state.
Sources: ROADMAP.md:33-36
Competitor and Industry Synchronization
Trans AI monitors the broader economic state of the game, including the performance of other companies and the "Cargo Concept" destination mapping.
Merger and Acquisition Sync
The AI can synchronize its state with other companies by accepting merger offers. It attempts to handle negative income from acquired assets to prevent bankruptcy, though this logic is currently under development.
Sources: ROADMAP.md:42-45
Cargo Destination Logic
To maintain the "Cargo Concept," the AI synchronizes routes to ensure multiple production industries target a single destination industry where possible.
Sources: ROADMAP.md:38-41
Version and Release Synchronization
The project uses a rolling release model to ensure players and developers are synchronized with the latest code changes.
- Developer Sync: The
info.nutfile uses a future date versioning strategy. This ensures that a locally cloned repository takes precedence over versions downloaded from the "Bananas" content service. - Automated Sync: GitHub Actions (
rolling-release.yml) automate the build process, ensuring the GitHub release assets are always synchronized with themainbranch.
Sources: README.md:33-42
Summary
Game State Synchronization in Trans AI is a multi-faceted process that aligns vehicle deployment, infrastructure building (like buoys for marine routes or double tracks for rail), and corporate strategy with the real-time conditions of the OpenTTD environment. By utilizing the NoAI libraries and monitoring game settings like infrastructure maintenance, Trans AI maintains a consistent and reactive presence in the game simulation.