Skip to content

Exporting the terrain

The terrain is the level’s heightmap: the height of the ground at every point, without buildings. With it the server refuses a position more than [validation] max_below_terrain metres under the ground (cellars and mines are allowed for) or max_above_terrain over it (towers and cliffs), and pulls the client back to where it last stood - a fly hack or a fall through the world ends there. A game mode gets GetTerrainHeight, the ground under any point; a spawn or a teleport with z below 0 lands on it.

Without it the terrain check is off for that level and the function answers nil.

The Windows server folder carries the tool for it: run tools/KcdMp.ExportHeightmap.exe on the machine that has the game and the KCD:MP client (Steam running, the game closed). The terrain lives in the engine, so the tool starts the game once per level through the KCD:MP launcher, samples the terrain when the level is loaded and closes it again - about a minute per level; the files land in the server folder’s data/heightmaps/. Leave the game alone while it runs.

KcdMp.ExportHeightmap [--level <name>|all] [--step <metres>] [--game <folder>] [--client <folder>]

All three levels by default; --level klaster does one. --step 2 samples every 2 metres instead of 4 (a finer map, four times the size). The game is found through Steam or --game; the KCD:MP client is looked for next to the tool, then --client, then asked for in a dialog. --help prints the same.

By hand, from inside the game: stand in the world on the level, open the KCD:MP console (F9, where the server allows it) and run KcdMp_heightmap. The file heightmap-<level>.hmap lands in your KCD:MP data folder (%LOCALAPPDATA%\KcdMp) in under a second; the client log there says so, with how many samples it holds. The default samples every 4 metres over the level’s 4096 × 4096 m (about 2 MB); KcdMp_heightmap 2 samples every 2 metres, KcdMp_heightmap 4 0 0 8192 8192 covers a larger area.

The tool puts the files where the server reads them. For a file made by hand, or for a server on Linux, put it in the server’s data folder - the one that holds the player records - under heightmaps/, named after the level (klaster.hmap), and point the configuration at it:

[validation]
heightmap = "data/heightmaps/{level}.hmap"
max_below_terrain = 6.0
max_above_terrain = 60.0

{level} is replaced by the level the server runs, so one line serves every level you export. The server log confirms the map at start (heightmap: ... samples every 4 m ...) or says why it could not use it.

With the collision geometry as well, the floor under a player - a bridge, an upper storey - counts as the ground, so max_above_terrain can be a storey’s worth (10) rather than a tower’s.

One heightmap per level per game build: after a game update, export it again.