TERRAIN

From ZDoom Wiki
Jump to navigation Jump to search

The TERRAIN lump is used to add sounds, liquid splashes and damaging effects to certain flats. The most common use is to create splashing sounds (such as water, mud, and lava in Heretic and Hexen), but it can also be used to give the player a custom landing sound when dropping onto a particular flat. For instance, if the player lands on a wood flat one may want to hear a heavy 'clunk' sound, and on a metal flat it will instead be a metallic 'clang' sort of sound. Note that those are only landing sounds, not footsteps.

Entries in the TERRAIN lump are created with the Terrain and Splash blocks. The effects of these blocks are then applied to certain flats using the Floor command.

In ZScript terrain data is stored in the TerrainDef struct and can be obtained from actors with GetFloorTerrain. Splash data is stored in the FSplashDef struct which is currently not exposed to ZScript.

Terrain blocks

Terrain blocks are defined as follows:

Terrain <Unique name>
{
	Splash			<splash block name>
	Footclip		<integer value>
	Liquid			<boolean value>

	Friction		<float value>
	MoveFactor		<float value>

	DamageType		<type>
	DamageAmount		<value>
	DamageTimeMask		<value>
	DamageOnLand		<boolean>
	AllowProtection		<boolean>

	LeftStepSounds		<sound from SNDINFO>
	RightStepSounds		<sound from SNDINFO>
	WalkStepTics		<integer value>
	RunStepTics		<integer value>
}

The <unique name> must be unique to all the other terrain blocks, however you may have a splash block with the same name (so splash water and terrain water can co-exist just fine). The names None and Null should not be used as they are reserved for engine use.

Terrain properties

  • Splash
The name of the associated Splash block attached to this terrain definition. Splashes can play sounds, spawn splash actors, and interact with the NOSPLASHALERT and DONTSPLASH flags.
  • Footclip
The number of pixels relative to the height of an actor that will be clipped off actors that are in the sector that uses this terrain definition on its floor. See Floorclip.
  • Liquid
If set, marks the terrain as being liquid. This can affect projectile behavior based on their use bouncing flags.
  • Friction
A float-point value (1.0 by default) that determines the friction of the floor this terrain is applied to. Larger values are more slippery (ice), and lesser values have more friction, resulting in a "muddy" effect.
  • Movefactor
A custom multiplied for the movement speed of actors in this terrain.
  • DamageAmount
Specifies how much damage the player entering this terrain will receive. (0 by default).
  • DamageType
Allows defining a custom damage type for the damage dealt by this terrain. This correlates directly to damage types defined in ZScript or DECORATE.
  • DamageTimeMask
Determines how often the damage is dealt, based on the current gametic. If none of the current gametic value's bits match the mask, then damage is inflicted. In practice, it is simpler to just assume that using for value a power of two, minus one, will result in damage inflicted every power of two tics. For example, using a damage time mask of 31 results in damage being inflicted every 32 tics. See this forum link for more information.
Starting with GZDoom 4.4.0, the damage interval is calculated by using a modulo operation, instead of a bitwise AND operation. This removes the restriction of only using power of two values minus one as the mask value. To retain the same results from the original way of calculating the interval, the engine adds 1 to the specified mask value before the calculations are performed. This needs to be taken into account for when setting the mask value by subtracting 1 from it. For instance, if a two-second interval (2 * 35 = 70) is desired, then the mask value should be 69, not 70.
  • AllowProtection
If true, PowerIronFeet-based powerups (such as Doom's RadSuit) will protect against the periodic damage.
  • DamageOnLand
Determines whether or not damage is applied upon hitting this terrain, in addition to the periodic damage.
  • RightStepSounds and LeftStepSounds
Allows providing a footstep sound for this terrain; takes a SNDINFO sound name. The sound will not get played automatically, however; authors have to design their own system for playing sounds from terrain—for example, by using GetFloorTerrain and reading its LeftStepSound field, then playing the sound on the actor with A_StartSound.
Note that the internal ZScript field names are RightStepSound and LeftStepSound (with no 's' on the end).
It's possible to define one or both of these fields. If both are defined, they'll be picked interchangebly, otherwise the defined one will be used. For randomization the $random instruction in SNDINFO can be used.
  • StepVolume
The volume of the step sounds (if defined).
  • WalkStepTics and RunStepTics
The frequency of the footstep sound when walking and running, respectively. Just like with the sounds themselves, there's no native system that would utilize this value. Authors would have to add their own system to utilize this, for example by using Level.mapTime % <terrainDefPointer>.walkStepTics to check for frequency.

Splash blocks

Splash blocks are defined as follows:

Splash <unique name>
{
	SmallClass		<small class>
	SmallClip		<clipping of small chunks?>
	SmallSound		<sound (as defined in SNDINFO)>

	BaseClass		<base class>
	ChunkBaseZvel		<z velocity of base>
	ChunkClass		<chunk class>
	ChunkXVelShift		<x velocity of chunks>
	ChunkYVelShift		<y velocity of chunks>
	ChunkZVelShift		<z velocity of chunks>
	Sound			<sound (defined in SNDINFO)>

	noalert			<does not alert monsters of the player's presence>
}

Splash properties

  • SmallClass
An actor class that will spawn when this splash is triggered, provided the actor who triggered the splash has a Mass value below 10.
If this isn't provided, BaseClass will be spawned instead.
  • SmallClip
(Need more info)
  • SmallSound
The sound played when an actor triggers this splash, provided the actor who triggered the splash has a Mass value below 10.
If this isn't provided, Sound will be played instead.
  • BaseClass
Splash actor spawned, if the actor who triggered it has a Mass of 10 or above.
  • ChunkBaseZVel
SmallClass/BaseClass actor will be given this velocity, slightly randomized.
  • Sound
The sound played when an actor triggers this splash, provided the actor who triggered the splash has a Mass value of 10 or above.
  • ChunkClass
An actor class that will spawn in addition to SmallClass/BaseClass when this splash is triggered. Usually this is smaller "drops of liquid", in contrast to the base splash actor. Chunks can be given randomized velocity with:
  • ChunkXVelShift
  • ChunkYVelShift
  • ChunkZVelShift
Note, giving velocity to the chunks via TERRAIN is not obligatory; it's perfectly possible to apply velocity to the chunk actors on spawn directly in ZScript/DECORATE.

A number of predefined splash classes exist, though one may of course create new splashes to use as well.

Note that DamageType 'Ice' will cause IceChunk and IceChunkHead actors to melt and disappear more slowly on this terrain. DamageType 'Lava' or 'Fire' will cause them to melt faster. Furthermore, 'Lava' and 'Fire' are identical: the engine will remap any DamageType 'Lava' to DamageType 'Fire'.

DefaultTerrain block

A DefaultTerrain block can be defined as a normal Terrain block. All floors that are not explicitly tied to a terrain type by the floor command will use the default terrain.

Floor command

Finally we use the floor command to define the actual flats that get the terrain treatment. This is simply:

floor [optional] <flatname> <terrain name>

Where <flatname> is the name of the flat (if a flat is animated it is best to define each frame here) and <terrain name> is the name of the terrain block (defined above) which you want to correspond to <flatname>. The presence of optional tells the engine that the flat is not to be error-logged if it does not exist or is invalid.

Setting <terrain name> to "None" allows to remove an association between a texture and a terrain type.

Examples

This reduces the friction on all floors.

Terrain lowfriction
{
	friction 2.0
}

Defaultterrain lowfriction