# heightmap.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "variables.h"`
`#include "heightmap.h"`
`#include "clear_map.h"`
`#include "void_map.h"`
`#include "debug.h"`
`#include "gui.h"`
`#include "saveload.h"`
`#include "bmp.h"`
`#include "gfx_func.h"`
`#include "core/alloc_func.hpp"`
`#include "fios.h"`
`#include "settings_type.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Functions
static byte | RGBToGrayscale (byte red, byte green, byte blue)
| Convert RGB colors to Grayscale using 29.9% Red, 58.7% Green, 11.4% Blue (average luminosity formula) -- Dalestan This in fact is the NTSC Color Space -- TrueLight.
static void | ReadHeightmapBMPImageData (byte *map, BmpInfo *info, BmpData *data)
| The BMP Heightmap loader.
static bool | ReadHeightmapBMP (char *filename, uint *x, uint *y, byte **map)
| Reads the heightmap and/or size of the heightmap from a BMP file.
static void | GrayscaleToMapHeights (uint img_width, uint img_height, byte *map)
| Converts a given grayscale map to something that fits in OTTD map system and create a map of that data.
static void | FixSlopes ()
| This function takes care of the fact that land in OpenTTD can never differ more than 1 in height.
static bool | ReadHeightMap (char *filename, uint *x, uint *y, byte **map)
| Reads the heightmap with the correct file reader.
bool | GetHeightmapDimensions (char *filename, uint *x, uint *y)
| Get the dimensions of a heightmap.
void | LoadHeightmap (char *filename)
| Load a heightmap from file and change the map in his current dimensions to a landscape representing the heightmap.
void | FlatEmptyWorld (byte tile_height)
| Make an empty world where all tiles are of height 'tile_height'.

## Detailed Description

Definition in file heightmap.cpp.

## Function Documentation

void FlatEmptyWorld | ( | byte | tile_height | ) |

Make an empty world where all tiles are of height 'tile_height'.

Parameters:

  | tile_height | of the desired new empty world

Definition at line 448 of file heightmap.cpp.

References FixSlopes(), MapSizeX(), MapSizeY(), MarkWholeScreenDirty(), SetTileHeight(), and TileXY().

Referenced by _GenerateWorld().

bool GetHeightmapDimensions | ( | char * | filename,
|  | uint * | x,
|  | uint * | y |
| ) |  |  |

Get the dimensions of a heightmap.

Parameters:

  | filename | to query
  | x | dimension x
  | y | dimension y

Returns:
  Returns false if loading of the image failed.

Definition at line 426 of file heightmap.cpp.

References ReadHeightMap().

static void GrayscaleToMapHeights | ( | uint | img_width,
|  | uint | img_height,
|  | byte * | map |
| ) |  |  | `[static]`

Converts a given grayscale map to something that fits in OTTD map system and create a map of that data.

Parameters:

  | img_width | the with of the image in pixels/tiles
  | img_height | the height of the image in pixels/tiles
  | map | the input map

Definition at line 287 of file heightmap.cpp.

References CLEAR_GRASS, DistanceFromEdge(), HM_CLOCKWISE, HM_COUNTER_CLOCKWISE, MakeClear(), MapSizeX(), MapSizeY(), SetTileHeight(), and TileXY().

Referenced by LoadHeightmap().

void LoadHeightmap | ( | char * | filename | ) |

Load a heightmap from file and change the map in his current dimensions to a landscape representing the heightmap.

It converts pixels to height. The brighter, the higher.

Parameters:

  | filename | of the heighmap file to be imported

Definition at line 431 of file heightmap.cpp.

References FixSlopes(), GrayscaleToMapHeights(), MarkWholeScreenDirty(), and ReadHeightMap().

static bool ReadHeightmapBMP | ( | char * | filename,
|  | uint * | x,
|  | uint * | y,
|  | byte ** | map |
| ) |  |  | `[static]`

Reads the heightmap and/or size of the heightmap from a BMP file.

If map == NULL only the size of the BMP is read, otherwise a map with grayscale pixels is allocated and assigned to *map.

Definition at line 226 of file heightmap.cpp.

References ReadHeightmapBMPImageData().

Referenced by ReadHeightMap().

static void ReadHeightmapBMPImageData | ( | byte * | map,
|  | BmpInfo * | info,
|  | BmpData * | data |
| ) |  |  | `[static]`

The BMP Heightmap loader.

For a non-gray palette of size 16 we assume that the order of the palette determines the height; the first entry is the sea (level 0), the second one level 1, etc.

For a palette of size 2 we assume that the order of the palette determines the height; the first entry is the sea (level 0), the second one is the land (level 1)

Definition at line 169 of file heightmap.cpp.

References RGBToGrayscale().

Referenced by ReadHeightmapBMP().