AI Logging and Debug Interface
Relevant source files
The following files were used as context for generating this wiki page:
The AI Logging and Debug Interface for Trans AI provides the necessary infrastructure for monitoring the AI's decision-making process and internal state during gameplay in OpenTTD. As an AI developed for the OpenTTD "NoAI" framework, Trans AI utilizes standard logging mechanisms to report on its activities across various transport modes, including air, road, marine, and rail routes.
This interface is critical for developers to track the implementation of features defined in the Road Map, such as the "Cargo Concept" (many-to-one delivery) and infrastructure maintenance detection. It allows for the observation of how the AI handles complex tasks like buying competitor companies and transitioning negative income into profitable operations.
Sources: README.md:1-10, ROADMAP.md:1-55
System Architecture and Versioning
The logging system is tied closely to the versioning and build process of the AI. Trans AI uses a rolling release model where the version number (YYMMDD) is integrated into the metadata, allowing developers to correlate logs with specific daily builds or development iterations.
Versioning Logic for Debugging
When running in a development environment (cloned from source), the version in info.nut is set to a future date. This ensures that the logs generated are attributed to the local development version rather than a stable release downloaded from the 'Bananas' content service.
Sources: README.md:46-53, info.nut
Development and Build Flow
The following diagram illustrates how the code moves from development to a release state, which impacts the logging metadata:
The build process is automated via GitHub Actions, ensuring consistent versioning across all logs produced by different builds.
Sources: README.md:54-58, .github/workflows/rolling-release.yml
Key Debugging Areas
Based on the project's development status, logging and debugging are focused on several core transport modules and experimental features.
Route Management Debugging
The AI must log its progress in establishing and maintaining various transport routes. The roadmap indicates different completion statuses that the logging interface must account for:
| Module | Feature | Implementation Status |
|---|---|---|
| Air | Town-to-town passenger transport | Fully Implemented |
| Road | Bus (Passenger) and Truck (Freight) | Fully Implemented |
| Marine | Ship routes with Buoy navigation | Fully Implemented |
| Rail | Double track logic | Fully Implemented |
| Special | Infrastructure Maintenance Detection | Fully Implemented |
Sources: ROADMAP.md:4-46
Cargo Concept Logic
A significant portion of the debug interface is dedicated to the "Cargo Concept," which attempts a many-to-one industry destination strategy. Logs in this section help developers understand why specific industries are chosen as destinations.
The "Cargo Concept" for Road and Marine routes is currently marked at 50% completion, requiring intensive logging to debug the rework of current implementations.
Sources: ROADMAP.md:48-55
Integration with External Libraries
The logging and debugging interface relies on external AI libraries that must be present in the ../ai/library folder. These libraries provide the underlying data structures and string manipulation required for descriptive logging.
Required Dependencies for Logging
- AI Library - Common: Provides basic framework functions.
- AI Library - List: Used for managing lists of industries, vehicles, and tiles.
- AI Library - String: Essential for formatting log messages and status reports.
Sources: README.md:38-44
Error Handling and Competitive Analysis
The debug interface also monitors high-level economic performance. Specifically, it tracks the AI's ability to:
- Accept merger offers from other companies.
- Analyze and rectify negative income from acquired companies to prevent bankruptcy.
Failure to handle these transitions correctly results in critical log entries indicating potential company failure.
Sources: ROADMAP.md:57-61
Conclusion
The AI Logging and Debug Interface in Trans AI is a vital component for tracking the AI's complex multi-modal transport strategies and its adherence to the "Cargo Concept." By leveraging the rolling release versioning and external library dependencies, developers can effectively monitor the AI's progress from town-to-town passenger services to advanced rail and marine freight logistics.