Table of Contents

Bridges and Tunnels

Bridges and tunnels for streets and tracks are defined with config files too.

Bridges

A bridge configuration files specifies a set of parameters to define the properties, dimension, features, and visuals of bridges. They are stored in .bridge.lua filesand have the following format:

function data()
return {
  -- property definitions
 
  materialsToReplace = { ... },
  assetsToReplace = { ... },
 
  updateScript = {...}
}
end

Property Definitions

The bridge properties start with the common metadata properties:

  description = {
    name = _("Stone bridge"),
    icon = "stone.tga",
  },
  availability = {
    yearFrom = 0,
    yearTo = 0,
  },
  menuCategory = {
    categories = {
      {
        filterCategories = {"special"},
        order = 5000,
      },
    },
  },
 
  cost = 200.0,
  maintenanceCost = 10.0,
  costFactors = { 10.0, 2.5, 1.0 },
 
  carriers = { "RAIL" , "ROAD"},
  speedLimit = 90.0 / 3.6,
  isAutoSelectable = true,

Their meaning is as follows:

There are several properties available to control the pillars:

  pillarLen = 3,
  pillarWidth = 5,
 
  pillarMinDist = 12.0,
  pillarMaxDist = 48.0,
  pillarTargetDist = 12.0,
  ignoreWaterCollision = false,
 
  pillarGroundTexture = "/terrain/materials/dirt/dirt.gtex",
  pillarGroundTextureOffset = 10.0,
 
  abutmentLen = 3,
  abutmentWidth = 4,
 
  noParallelStripSubdivision = false,
  autoGeneration = false,

Another property is noParallelStripSubdivision. If it is set to true, the updateFn will be called for the whole bridge instead of seperate segements. Be aware that bridge segments are limited to a length of 100 meters, so this property might be relevant for bridges with large gaps between pillars. If set to false or the property is unset, the updateScript will be called several times. Larger pillar distances then will result in no pillars.

To prevent bridge types from being used during map generation and automated spawning of new roads, the autoGeneration flag can be set to false.

Material & Assets Override

ballast material is replaced

To adjust the optics of the street or track on the bridge, it is possible to override materials and assets as well as the sidewalkHeight.

The materialsToReplace list is used to overwrite materials defined in the street and track configuration. See there for further details on the purposes of the different types.

The assetsToReplace list allows removing or replacing materials:

assetsToReplace = {
  ["street_light"] = {
    name = "/assets/streets/street_light_eu_b.mdl",
    offset = 8.0,
    distance = 16.0,
    prob = 1.0,
    offsetOrth = 3.0,
    randRot = false,
    oneSideOnly = false,
    alignToElevation = false,
    avoidFaceEdges = false,
  }, 
  ["fireplug"] = { }, 

The keys of the struct need to be the same as used in the .street.lua. If an empts list is assigned to a key (as in the fireplug entry), the asset will be skipped completely.

Update Script

The updateScript references a function in a .script.lua file that is used to construct the bridge from individual model parts. It is common to forward some metadata next to the reference which is then available as captureParams in the function.

When called, the update function receives the mentioned captureParams and a second set of params containing the bridge configuration that shall be built. It has the following values:

The collision types that can be used to prevent railings are:

It is expected that the result contains two lists:

return {
  pillarModels = { 
    { -- pillar 1
      { -- row 1
        { id = "bridge/stone/pillar_btm_side.mdl", transf = { ... } }, 
        { id = "bridge/stone/pillar_btm_rep.mdl", transf = { ... } },
        { id = "bridge/stone/pillar_btm_side2.mdl", transf = { ... } },
      },
      ... -- more rows
    },
    ... -- more pillars and abutments if needed
  },
  railingModels = {
    { -- section 1
      { -- row 1
        { id = "bridge/stone/railing_end_side.mdl", transf = { ... } }, 
        { id = "bridge/stone/railing_end_rep.mdl", transf = { ... } },
        { id = "bridge/stone/railing_end_rep.mdl", transf = { ... } },
      },
      ... -- more rows
    },
    ... -- more sections
  },
}

Bridge Util

To ease the configuration of simple bridges, the /infrastructure/bridges/bridgeutil2.lua offers a prefabricated update function makeDefaultUpdateFn, which is also used by several of the vanilla bridges. This function gets a config struct as captureParams. The contents of this struct are described below.

Each model reference in the next sections is actually a struct of the following structure:

{
  "/infrastructure/bridge/steel/b_12_end_rep_l.mdl",
  { { 0, -1.6, -1.7 }, { 12, 0, 9 } },
}

The first entry in the struct is the actual reference of a model and the second entry is the bounding box data of the model.

Pillars

Bridge pillars consist of three mandatory layers, of which the middle layer can be repeated several times:

An additional pillarMain layer list can be added that is used on top of the pillarTop layer and above the track or street bed.

All four lists may vary in length. Possible lengths are:

1 model reference This model is set in the middle as a pillar.
2 model references The first model is used for the edges of the pillar (rotated once accordingly), the second model is placed next to each other for the middle of the pillar and scaled slightly until it fills the required width.
3 model references The first model is used for one side of the pillar, the second model is placed next to each other for the middle of the pillar and scaled slightly until it fills the required width and the third model is used for the other side, but not rotated.
Abutments

Bridge abutments are defined in a similar way as the pillars. They consist of three mandatory layers, of which the middle layer can be repeated several times:

All three lists may vary in length like the ones of the pillars.

Railings

The bridge railing also consists of several rows that are placed next to each other:

All three lists may vary in length. There can be either 5 or 8 models in the list. If only 5 elements are included, the elements 1-3 are used as a substitute for 6-8 in a rotated version. The purpose of the elements are:

  1. side element
  2. side element with no roof because of a collision on the other side
  3. side element with no railing and roof because of a colission on this side, e.g. a track switch
  4. middle element (that is repeated to fill the bridge width)
  5. middle element with no roof because of a collision on at least one of the sides
  6. other side element
  7. other side element with no roof because of a collision on the other side
  8. other side element with no railing and roof because of a colission on this side
Other Parameters

There are additional parameters for bridge configurations:

Tunnels

A tunnel configuration files specifies a set of parameters to define the properties, dimension, features, and visuals of tracks. They are stored in .tunnel.lua files.

Configuration

The file has the following format:

function data()
return {  
  description = {
    name = _("Standard tunnel"),
    icon = "tunnel_a.tga",
  },
  availability = {
    yearFrom = 0,
    yearTo = 1950,
  },
  menuCategory = {
    categories = {
      {
        filterCategories = {"special"},
        order = 5000,
      },
    },
  },
 
  cost = 200.0,
  maintenanceCost = 10.0,
  costFactors = { 10.0, 2.5, 1.0 },
 
  carriers = { "RAIL" , "ROAD"},
 
  padding = 2,
  height = 10.03,
 
  updateScript = {
    fileName = "tunnel.script@tunnel.updateFn",
    params = config
  },
}
end

Many properties are the same as for the bridges. Their meaning is as follows:

It is also possible to overwrite materials and assets as described for bridges above.

Additionally there are functional properties specifically for tunnels. The padding describes the offset from the side of the outer lanes to the walls. It is used to calculate the split point of tunnels with diverging tracks/roads. The height defines the minimum height of the terrain at the position of the tunnel. It is not possible to lower terrain above the tunnel lower than that with terrain tools.

Update Script

The updateScript references a function in a .script.lua file that is used to construct the tunnel from individual model parts. It is common to forward some metadata next to the reference which is then available as captureParams in the function.

When called, the update function receives the mentioned captureParams and a second set of params containing the bridge configuration that shall be built. The params are the same as described for bridges above. There are two properties in the railingIntervals for tunnels:

It is expected that the result contains a result.railingModels list. Each element of the list corresponds to one of the params.railingIntervals entries, thus both lists have the same length. The elements are lists themselves containing all the rows of models for each railing section.

Default Update Script

The vanilla tunnels use the script in content/infrastructure/tunnel/tunnel.script.lua@tunnel. It expects a config struct as captureParams:

updateScript = {
  fileName = "tunnel.script@tunnel.updateFn",
  params = {
    railingBegin = { ... },
    railingRepeat = { ... },
    railingEnd = { ... },
    portalsConfig = { tunnel_a_startportal_rgt, tunnel_a_startportal_rep, tunnel_a_startportal_lft },
    endPortalsConfig = { tunnel_a_endportal_rgt, tunnel_a_endportal_rep, tunnel_a_endportal_lft },
    deadConfig = { tunnel_a_dead_rgt, tunnel_a_dead_rep, tunnel_a_dead_lft, tunnel_a_dead_rgt_end, tunnel_a_dead_lft_end },
    assetsConfig = {
      { tunnel_a_m1_side_lft[1], tunnel_a_m1_add_lamp_lft1[1], 15, 3},
      { tunnel_a_m1_side_rgt[1], tunnel_a_m1_add_lamp_rgt1[1], 20, 5},
      { tunnel_a_m1_side_lft[1], tunnel_a_m1_add_lamp_lft2[1], 13, 0},
      { tunnel_a_m1_side_rgt[1], tunnel_a_m1_add_lamp_rgt2[1], 16, 0},
    }
  }
}

Here the properties are the following: