Train Fever

Train Fever

33 ratings
Creating AI Buildings
By DasMatze
This will teach you how to create your own buildings which automatically appear inside the cities.
   
Award
Favorite
Favorited
Unfavorite
Step 1: Install the Mesh Buildings Enabler
Download the Mesh Buildings Enabler here:
http://www.train-fever.net/filebase/index.php/Entry/154-Mesh-Buildings-Enabler/
If it's you're first time on that website, you'll probably see some EULA text in German. Translate it via Google and accept it to be guided to the download.

Here's a mirror in case you want to miss out on that great website stuffed with mods: https://www.dropbox.com/s/i0liu0vtkg517do/dasmatze_meshbuildingsenabler.zip?dl=1
Step 2: Create the Mesh
First of all you need to know what type of building you want to create. There are residential, commercial, industrial and leisure buildings in the game. Next you need to choose a size. It must always be dividable through eight. Here are the sizes for the default lots:
Width
Depth
Small
16m
24m
Medium
24m
24m
Large
32m
32m
Very Large
48m
40m
The width is the y-axis in the modeler and the x-axis in the game. The depth is the x-axis in the modeler and the y-axis in the game. The house gets always placed in the center of the lot with the positive x-axis (in the modeler) facing the road. The axes mentioned refer to a right-handed, z-up system.

Next you need to choose a capacity of workers/residents/customers for your lot. Here you can see the capacities of the default lots:
Residential
Commercial
Industrial
Leisure
Small
1-4
1-16
1-8
1-16
Medium
5-10
17-40
9-20
17-40
Large
11-18
41-72
21-36
41-72
Very Large
19-100
73-400
37-200
73-400
Since the house can be placed on a sloped road, you should create a foundation for your building, that goes a few meters into the ground.
Step 3: Placement of files
Files should be placed here:

MESHES (.msh / .msh.blob):
– res\models\mesh\building\{YourSetName} (if you create a set of buildings)
– res\models\mesh\building\residential
– res\models\mesh\building\commercial
– res\models\mesh\building\industrial
– res\models\mesh\building\leisure

TEXTURES (.tga):
– res\textures\models\building\{YourSetName} (if you create a set of buildings)
– res\textures\models\building\residential
– res\textures\models\building\commercial
– res\textures\models\building\industrial
– res\textures\models\building\leisure

MATERIALS (.mtl):
– res\models\material\building\{YourSetName} (if you create a set of buildings)
– res\models\material\building\residential
– res\models\material\building\commercial
– res\models\material\building\industrial
– res\models\material\building\leisure

MODELS (.mdl):
– res\models\model\building\{YourSetName} (if you create a set of buildings)
– res\models\model\building\residential
– res\models\model\building\commercial
– res\models\model\building\industrial
– res\models\model\building\leisure

BUILDING UTILITY DATA (.bud):
– res\config\building\bud\meshbuildings\{YourSetName} (if you create a set of buildings)
– res\config\building\bud\meshbuildings\residential
– res\config\building\bud\meshbuildings\commercial
– res\config\building\bud\meshbuildings\industrial
– res\config\building\bud\meshbuildings\leisure
Step 4: Create your Model
A typical .mdl file for a model looks like this:

function data() return{ boundingInfo = { bbMax = { 7.9, 11.9, 8.5, }, bbMin = { -7.9, -11.9, 0, }, }, collider = { params = { }, type = "MESH", }, lods = { { children = { { id = "building/residential0/mymesh.msh", transf = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, type = "MESH", }, }, matConfigs = { { 0, }, }, static = false, visibleFrom = 0, visibleTo = 2500, }, }, metadata = { }, } end

The bounding box is (as always) very important. If it's too big, the model will not be displayed / the building will not be chosen. Always make it 0.5m to 1m in each direction smaller than the ground size is. Is the size of one direction not equal to the opposite direction, the model will be centered so that the bounding box is centered.

Also of importance is the “visibleTo” value. Buildings should be displayed even when fully zoomed out. So turn it up real high (as in the example above) and make the mesh either very low-poly or create multiple LODs.
Step 5: Create the Building Utility Data
Now comes the part which is probably new to you. Create a .bud text file with the following content in the appropriate folder (see step 2):

local dasmatze_meshbuildings = require "dasmatze_meshbuildings" function data() result = dasmatze_meshbuildings.create() result.availability.yearFrom = 1800 result.availability.yearTo = 99999 result.type = "RESIDENTIAL" result.capacity = { 1, 4 } result.parcelWidth = { 3, 3 } result.parcelDepth = { 3, 3 } result.params.assetCenter = "building/residential0/mymodel.mdl" result.params.assetGarden = { "asset/park_fountain_1.mdl", "asset/park_fountain_2.mdl" }
result.params.assetTree = { "all" }
result.params.assetProbGarden = .0
result.params.assetProbTree = .0
result.params.matWall = { "wall_stone1.btd", "wall_stone2.btd" }
result.params.shapeGridSize = 6.0 return result; end

The italic and underlined lines are completely optional. If you leave them out, the default parameters are used most of the time.

"result.availability.yearFrom" and "result.availability.yearTo" must not be 0 otherwise they might crash the game. Use a very high number if you want to make it available almost forever.

Here are the rest of the parameters:
Parameter
Description
result.type = "RESIDENTIAL"
The type of the lot. Possible values are RESIDENTIAL, COMMERCIAL, INDUSTRIAL and LEISURE
result.capacity = { 1, 4 }
The capacity of the lot. A random value between the first value (low value) and the second value (high value) is chosen when a building gets built. It always fits the cities needs.
result.parcelWidth = { 3, 3 }
The width of the lot. Caluclated by width divided by eight. No decimal values are allowed. If the value is too high, the chance of it appearing sinks drastically. See the data table in step 1 for default sizes which are always appearing. Both values should be the same.
result.parcelDepth = { 3, 3 }
The width of the lot. Caluclated by width divided by eight. No decimal values are allowed. If the value is above six, it will never appear. See the data table in step 1 for default sizes which are always appearing. Both values should be the same.
result.params.assetCenter = ""
The model you created which gets placed in the center of the lot.
result.params.assetGarden = { }
An array of garden assets (.mdl) placed randomly in the part of the lot that is not blocked by the bounding box of the building's mdl file. By default no assets are used.
result.params.assetTree = { }
An array of possible tree models you want to use on your lot.
result.params.assetProbGarden = .0
Not sure what this does, but the higher the number, the more garden assets are placed. It's probably a value between 0 and 1. By default it won't spawn any garden assets.
result.params.assetProbTree = .0
Not sure what this does, but the higher the number, the more trees are placed. It's probably a value between 0 and 1. By default it won't spawn any trees.
result.params.matWall = { }
An array of walls from the folder "res\config\building\btd\wall" which are placed at the edges of the lot beneath the ground (so that there is a wall when the house is placed on a sloped road and floats in the air). By default, there won't be any walls.
result.params.shapeGridSize = 6.0
This defines how accurate the terrain gets leveled around the building. The higher the value, the more precise it'll be. Six is a good value to work with.
Step 6: Test it in the Game
If you did everything right, you should have a a custom building in the game.



Congratulations! The Train Fever Community awaits some cool buildings from you now.

If you have any trouble concerning this tutorial / mod, leave a comment / reply here!
1 Comments
teejaybra 12 Jan, 2019 @ 10:08pm 
Dont work