Overview

Terrain files (*.ter) represent a single terrain to be used by a world. This file format is generated by ZeroEditor and used during the munge process to create the tern chunk within *.lvl files.

Structure

Name Size (bytes) Description
Terrain Header 2820/2821 (v21/22) Header storing general information about the terrain
Terrain Blocks Variable See Terrain Blocks
End-Of-File Block Variable See End-Of-File Block

Terrain Header

The Terrain Header is always 2821 bytes in length.

Data Type Size (bytes) Description
byte [4] 4 Terrain Header Marker (TERR)
long int 4 .TER file version number (21 for SWBF, 22 for SWBFII)
short int [4] 8 Terrain extents
Example: -8, -8, 8, 8 for a 16x16 map
long int 4 Unknown (usually 164)
float [16] 64 Tile-range for each texture layer
0.031 (1/32): the texture spans 32 meters. This is stored as 1/X of the value in ZeroEditor
byte [16] 16 Mapping for each texture-layer. 0 is normal
byte [64] 64 Unknown. Possibly 16 floats for texture-layer rotations
float 4 Map height multiplier
float 4 Grid-scale. Distance between points
long int 4 Unknown (usually 1)
long int 4 Full map size stored in the .TER file. The same or bigger than the map extents
long int 4 Terrain options set in the editor as mask. Allows toggling of certain features (i.e. for space maps)
0 — None
1 — Terrain
2 — Water
4 — Foliage
byte 1 Unknown (0F) Only exists in SWBF II (version 22) terrain
TextureLayer [16] 1024 TextureLayers
WaterLayer [16] 1088 WaterLayers
char [16][32] 512 Road decal texture names
long int 4 4x4 terrain blocks covered by decals (?)
byte[8] 8 Unknown data possibly related to the road decals

Terrain Blocks

The Terrain Header is 2820 (SWBF) or 2821 (SWBFII) bytes in length.

Name Data Type Size
Height signed short Full map size * Full map size * 2
Height value for every point on the grid. This value will be multiplied with the map scale multiplier
Color byte [4] Full map size * Full map size * 4
Color values for every point on the grid. 4 bytes (from 0 to 255) corresponding to the RGBA channels
Color 2 byte [4] Full map size * Full map size * 4
Color values for every point on the grid. 4 bytes (from 0 to 255) corresponding to the RGBA channels
Texture byte [16] Full map size * Full map size * 16
One byte (0-255) for each TextureLayer indicating the transparency of the corresponding texture layer
Blend Heights byte [?] Full map size * Full map size * 2
Last used blend heights for every block, possibly lower-left and upper-right values of the blend tool
Blend Heights byte [?] Full map size * Full map size * 2
Last used blend heights for every block, possibly lower-left and upper-right values of the blend tool
Water byte Full map size * Full map size * 2
See WaterInfo below
Foliage byte Full map size * Full map size / 2
See Foliage below
Unknown byte Variable
Structure unknown

Terrain Structs

TextureLayer

Data Type Size (bytes) Description
char [32] 32 Diffuse texture name
char [32] 32 Detail texture name

WaterLayer

Data Type Size (bytes) Description
float [2] 8 Water height value (twice)
byte [8] 8 Unknown, always zero
float [2] 8 UV animation velocity
float [2] 8 UV animation repeat.
byte [4] 4 RGBA color values
char [32] 32 Water texture name

WaterInfo

Data Type Size (bytes) Description
byte 1 TextureLayer id mask for layers 0 - 7
1 — Layer 0
2 — Layer 1
4 — Layer 2
8 — Layer 3
16 — Layer 4
32 — Layer 5
64 — Layer 6
128 — Layer 7
byte 1 TextureLayer id mask for layers 8 - 15
1 — Layer 8
2 — Layer 9
4 — Layer 10
8 — Layer 11
16 — Layer 12
32 — Layer 13
64 — Layer 14
128 — Layer 15
byte 1 WaterLayer id (0 - 15)
byte 1 Unknown

Foliage

Always stored as 1024x1024 no matter the terrain size set in ZeroEditor.

Every value is a mask of the foliage layers applied to 8 vertices.

128 — Layer 3 for the first four vertices (first square/block)
64 — Layer 2
32 — Layer 1
16 — Layer 0
8 — Layer 3 for the second four vertices (second square/block)
4 — Layer 2
2 — Layer 1
1 — Layer 0

So in hex representation the byte could be cut in half to represent the two blocks of vertices.

End-of-file Block

Can be empty

Data Type Size (bytes) Description
int 4 Length of the block
int 4 Number of items. Can be zero, in which case there are no further fields and this block ends
int 4 Number of (sub-)items?