An experimental toolset to programmatically and procedurally generate playable maps for TrackMania 2020.
This project was born out of a challenge: could a TrackMania map be generated entirely from code, without ever opening the in-game editor?
My initial goal was to generate a modern TrackMania 2020 .Gbx file directly, but the complexity of the format proved difficult. The breakthrough came from a different approach:
- Generate a map for an older, better-understood game (TrackMania Nations Forever).
- Convert that older map into the modern TrackMania 2020 format using a community-made tool.
This repository contains the scripts to do just that. It includes a Python script that can parse a simple .txt file defining a track's layout, and a procedural generator that creates a random, multi-level "tower" style map. This is currently an alpha version, a proof-of-concept that shows this unique map creation pipeline is possible.
- Procedural Map Generation: Run
gen_map.pyto create a new, randomized tower-style track layout (my_track_layout.txt). - Text-Based Map Definition: The core engine reads a simple
BlockName X Y Z Rotationformat from a text file. - Automated Build Pipeline: The
build.pyscript automates the entire process:- Generates the random map layout.
- Builds the TMNF
.Gbxmap file. - Converts the map to the TM2020 format.
- Moves the final map into your user directory, ready to play.
Follow these steps to set up and run the project.
- Python 3.x
- Required Python libraries:
pygbxandlzo.pip install pygbx lzo
- NationsConverterCLI: This project relies on this essential tool to convert the maps. Download the latest release from its GitHub repository.
-
Clone the repository:
git clone https://github.com/TheMaster1127/programmatically-making-a-trackmania-map cd programmatically-making-a-trackmania-map -
Install the prerequisites as described above.
-
IMPORTANT: Configure Paths Before running, you must update the hardcoded paths in the scripts to match your system.
- In
build.py, update these variables:CONVERTER_EXE = r"C:\path\to\your\NationsConverterCLI.exe" CONVERTER_OUTPUT_DIR = r"C:\path\to\your\NationsConverterCLI\Output" FINAL_MAPS_DIR = r"C:\Users\YourUser\Documents\Trackmania\Maps\My Maps"
- In
gen_map.py, update this variable at the bottom of the file:baseDir = "C:\\path\\to\\your\\project\\folder\\"
- In
-
Run the Build Script: Execute the main build script from your terminal. It will handle everything automatically.
python build.py
If successful, a new, playable map will appear in the
FINAL_MAPS_DIRyou specified.
This project is currently in an alpha stage. It is fully functional as a proof-of-concept but is not yet user-friendly.
Current Limitations:
- Paths and map generation parameters (like the tower height) are hardcoded directly in the Python scripts.
- The random map generator only produces one style of track.
Future Goals:
- Implement a
config.jsonor.inifile to manage paths and settings easily. - Expand the procedural generator to create different styles of maps (e.g., circuits, downhill).
- Add more user-configurable options for map generation (e.g.,
set_tower_height(x)).
This project would not have been possible without the foundational work of others in the TrackMania community. A huge thank you to the creators of these essential tools:
- donadigo/tmtracknn: For the initial Python scripts that provided the base for understanding and manipulating TMNF
.Gbxfiles. - BigBang1112/nations-converter: For the incredible converter tool that makes this entire project viable for modern TrackMania.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.