Battlezone Terrain

World

Battlezone uses a left-handed coordinate system with positive X to the right, positive Y up, and positive Z forward. For world coordinates, positive X is east, positive Y is up, and and positive Z is north.

Zones

The Battlezone terrain system was originally based on the Interstate '76 terrain system, and like Interstate '76 divides the world into 128 by 128 zones of 10 by 10 meter grid cells in row-major order. Arranging terrain data this way keeps nearby grid points relatively close in memory, making it much more cache-friendly.

The first entry of a zone is at the southwest corner. Successive entries in a row are at increasing X positions (west to east). Successive rows are at increasing Z positions (south to north).

Zone Map

The zone map is a two-dimensional array of zone indices with each entry corresponding to an absolute position starting at the origin. The zone map provide a level of indirection that hides the details of the terrain layout from game logic and allows zones with no terrain data to reference a default "empty" zone instead of crashing the game.

Battlezone assumes worlds are compact and rectangular. It procedurally generates the terrain zone map based on values in the TRN file, yielding a two-dimensional array of zones in row-major order. The first zone starts at the southwest corner of the map. Successive zones in a row are at increasing X positions (west to east). Succesive rows are at increasing Z positions (south to north)

width = .TRN [Size] Width / 1280
depth = .TRN [Size] Depth / 1280
minX = .TRN [Size] MinX / 1280
minZ = .TRN [Size] MinZ / 1280

fill ZoneMap with an index of -1 (empty)

numZones = 0
for (j = minZ; j < minZ + depth; ++j)
	for (i = minX; i < minX + width; ++i)
		ZoneMap[j][i] = numZones++;

The terrain loader expects the HGT, MAT, and LGT files to contain numZones zones worth of data.

A 5120 meter by 5120 ("large") map has this arrangement of zones:

minX12131415
891011
4567
0123
minZ

All zones outside this region will be empty (flat).

Terrain Files

Terrain data is spread across several files. These were originally accessed as memory-mapped files so they had to be stored separately in addon but 1.5 and later read them as normal assets so they can be packed into ZFS files like any other game asset.