OpenTTD Source: src/heightmap.cpp File Reference

OpenTTD Source 1.11.0-RC1

Functions
heightmap.cpp File Reference
`#include "stdafx.h"`
`#include "heightmap.h"`
`#include "clear_map.h"`
`#include "void_map.h"`
`#include "error.h"`
`#include "saveload/saveload.h"`
`#include "bmp.h"`
`#include "gfx_func.h"`
`#include "fios.h"`
`#include "fileio_func.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`
`#include <png.h>`

Go to the source code of this file.

## Functions
static byte | RGBToGrayscale (byte red, byte green, byte blue)
| Convert RGB colours to Grayscale using 29.9% Red, 58.7% Green, 11.4% Blue (average luminosity formula, NTSC Colour Space)
static void | ReadHeightmapPNGImageData (byte *map, png_structp png_ptr, png_infop info_ptr)
| The PNG Heightmap loader. More...
static bool | ReadHeightmapPNG (const char *filename, uint *x, uint *y, byte **map)
| Reads the heightmap and/or size of the heightmap from a PNG file. More...
static void | ReadHeightmapBMPImageData (byte *map, BmpInfo *info, BmpData *data)
| The BMP Heightmap loader. More...
static bool | ReadHeightmapBMP (const char *filename, uint *x, uint *y, byte **map)
| Reads the heightmap and/or size of the heightmap from a BMP file. More...
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. More...
void | FixSlopes ()
| This function takes care of the fact that land in OpenTTD can never differ more than 1 in height.
static bool | ReadHeightMap (DetailedFileType dft, const char *filename, uint *x, uint *y, byte **map)
| Reads the heightmap with the correct file reader. More...
bool | GetHeightmapDimensions (DetailedFileType dft, const char *filename, uint *x, uint *y)
| Get the dimensions of a heightmap. More...
void | LoadHeightmap (DetailedFileType dft, const char *filename)
| Load a heightmap from file and change the map in his current dimensions to a landscape representing the heightmap. More...
void | FlatEmptyWorld (byte tile_height)
| Make an empty world where all tiles are of height 'tile_height'. More...

## Detailed Description

Creating of maps from heightmaps.

Definition in file heightmap.cpp.

## Function Documentation

## ◆ FlatEmptyWorld()

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 510 of file heightmap.cpp.

References _settings_game, GameSettings::construction, FixSlopes(), ConstructionSettings::freeform_edges, MapSizeX(), MapSizeY(), MarkWholeScreenDirty(), SetTileHeight(), and TileXY().

## ◆ GetHeightmapDimensions()

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

Get the dimensions of a heightmap.

Parameters

  dft | Type of image file.
  filename | to query
  x | dimension x
  y | dimension y

Returns
  Returns false if loading of the image failed.

Definition at line 477 of file heightmap.cpp.

## ◆ GrayscaleToMapHeights()

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 294 of file heightmap.cpp.

References _settings_game, GameSettings::game_creation, and GameCreationSettings::heightmap_rotation.

## ◆ LoadHeightmap()

void LoadHeightmap | ( | DetailedFileType | dft,
|  | const 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

  dft | Type of image file.
  filename | of the heightmap file to be imported

Definition at line 489 of file heightmap.cpp.

## ◆ ReadHeightMap()

static bool ReadHeightMap | ( | DetailedFileType | dft,
|  | const char * | filename,
|  | uint * | x,
|  | uint * | y,
|  | byte ** | map
| ) |  |
| static

Reads the heightmap with the correct file reader.

Parameters

  | dft | Type of image file.
  | filename | Name of the file to load.
  [out] | x | Length of the image.
  [out] | y | Height of the image.
  [in,out] | map | If not `nullptr`, destination to store the loaded block of image data.

Returns
  Whether loading was successful.

Definition at line 453 of file heightmap.cpp.

## ◆ ReadHeightmapBMP()

static bool ReadHeightmapBMP | ( | const char * | filename,
|  | uint * | x,
|  | uint * | y,
|  | byte ** | map
| ) |  |
| static

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

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

Definition at line 233 of file heightmap.cpp.

## ◆ ReadHeightmapBMPImageData()

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 176 of file heightmap.cpp.

## ◆ ReadHeightmapPNG()

static bool ReadHeightmapPNG | ( | const char * | filename,
|  | uint * | x,
|  | uint * | y,
|  | byte ** | map
| ) |  |
| static

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

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

Definition at line 103 of file heightmap.cpp.

## ◆ ReadHeightmapPNGImageData()

static void ReadHeightmapPNGImageData | ( | byte * | map,
|  | png_structp | png_ptr,
|  | png_infop | info_ptr
| ) |  |
| static

The PNG 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.

Definition at line 44 of file heightmap.cpp.