Table of Contents

Animals

The animals as a seperate model type and wildlife animals are a new feature in Transport Fever 2. Basically they are models as any other object in the game but they have some unique events and a special metadata block.

Metadata

In addition to the general .mdl properties, animals use the cameraConfig block as players can follow animals in first person view. Furthermore, there is a metadata block called animal:

function data()
return {
  -- bounding box
  -- collider
  -- lods
 
  metadata = {
    description = {
      description = _("salmon-description"),
      name = _("Salmon"),
    },
    cameraConfig = {...},
    animal = {
      config = {...},
      flockName = "",
      flockFormationFn = "models/model/animal/animal.flock.salmon",
      movement = {...},
      movementTypes = {...},
      suitableAreas = {...},
    },
  },
  version = 1,
}
end

The name is shown as the default name if the user clicks on an animal. It can be translated in a strings.lua file.

The cameraConfig block is used for the first person view. To learn how to define camera views, read the relevant section in the model definition documentation.

The animal block is described below.

Config


highlighted area around predators

The config block contains several general properties for animals:

Flocks

Birds and Fishes may travel around in flock formations. If an animal has a configured flock, it will move in this group. Otherwise the animal will move alone.

The flock formations have a name that is specified in flockName. The formation is configured in an external .script file. This is referenced in flockFormationFn. The path is relative to the res folder. If the reference is “models/model/animal/animal.flock.salmon”, then the actual file is in “res/models/model/animal/animal.script”. The function for the flock has no parameter and a list of vectors with x,y and z values is expected. These vectors are relative to the flock origin.

The external file looks like this:

function data()
return {
  flock = {
    salmon = function() ... end
  },
  ...
}
end

Movement

The movement block describes some restrictions regarding where the animals move:

Movement Types

It is possible to define several movement types. For example, land animals can stay around (idle), walk and run. For each of the movement types, there is a block in the movementTypes list with the following properties:

Suitable Areas

The suitableAreas block is used to limit the occurance and movement of animals to certain areas. There are several terrain related factors as well as factors related to other animals. All factors are mapped to scores. The overall sum of scores summarizes the likelyhood of the animal existing in a certain spot. If an animal gets into an area with negative score, it will try to run away. If it fails to leave the non suitable area it will eventually die.

It is possible to analyze the score factor maps with the ingame debug tools.

Events

The events of animals are mostly defined by their movementTypes. The most common events are: