OpenTTD Source 20241224-master-gf74b0cf984
landscape.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef LANDSCAPE_H
11#define LANDSCAPE_H
12
14#include "tile_cmd.h"
15
16static const uint SNOW_LINE_MONTHS = 12;
17static const uint SNOW_LINE_DAYS = 32;
18
28
29bool IsSnowLineSet();
30void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
31uint8_t GetSnowLine();
32uint8_t HighestSnowLine();
33uint8_t LowestSnowLine();
34void ClearSnowLine();
35
36int GetSlopeZInCorner(Slope tileh, Corner corner);
37std::tuple<Slope, int> GetFoundationSlope(TileIndex tile);
38
39uint GetPartialPixelZ(int x, int y, Slope corners);
40int GetSlopePixelZ(int x, int y, bool ground_vehicle = false);
41int GetSlopePixelZOutsideMap(int x, int y);
42void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2);
43
53inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
54{
55 return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
56}
57
65inline std::tuple<Slope, int> GetFoundationPixelSlope(TileIndex tile)
66{
67 auto [s, z] = GetFoundationSlope(tile);
68 return {s, z * TILE_HEIGHT};
69}
70
79inline Point RemapCoords(int x, int y, int z)
80{
81 Point pt;
82 pt.x = (y - x) * 2 * ZOOM_BASE;
83 pt.y = (y + x - z) * ZOOM_BASE;
84 return pt;
85}
86
95inline Point RemapCoords2(int x, int y)
96{
97 return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
98}
99
109inline Point InverseRemapCoords(int x, int y)
110{
111 Point pt = {(y * 2 - x) >> (2 + ZOOM_BASE_SHIFT), (y * 2 + x) >> (2 + ZOOM_BASE_SHIFT)};
112 return pt;
113}
114
115Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
116
127{
128 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
129}
130
132bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
133bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
134
135void DoClearSquare(TileIndex tile);
136void RunTileLoop();
137
138void InitializeLandscape();
139bool GenerateLandscape(uint8_t mode);
140
141#endif /* LANDSCAPE_H */
DiagDirection
Enumeration for diagonal directions.
All geometry types in OpenTTD.
void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
Set a variable snow line, as loaded from a newgrf file.
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
bool IsSnowLineSet()
Has a snow line table already been loaded.
void ClearSnowLine()
Clear the variable snow line table and free the memory.
uint8_t HighestSnowLine()
Get the highest possible snow line height, either variable or static.
std::tuple< Slope, int > GetFoundationPixelSlope(TileIndex tile)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition landscape.h:65
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
int GetSlopePixelZOutsideMap(int x, int y)
Return world z coordinate of a given point of a tile, also for tiles outside the map (virtual "black"...
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
Point InverseRemapCoords2(int x, int y, bool clamp_to_map=false, bool *clamped=nullptr)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition landscape.h:79
uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.h:126
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition landscape.h:95
std::tuple< Slope, int > GetFoundationSlope(TileIndex tile)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
int GetSlopePixelZ(int x, int y, bool ground_vehicle=false)
Return world Z coordinate of a given point of a tile.
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2)
Determine the Z height of the corners of a specific tile edge.
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.h:53
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Definition landscape.h:17
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition landscape.h:109
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition landscape.h:16
bool GenerateLandscape(uint8_t mode)
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
Corner
Enumeration of tile corners.
Definition slope_type.h:22
Coordinates of a point in 2D.
Structure describing the height of the snow line each day of the year.
Definition landscape.h:23
uint8_t highest_value
Highest snow line of the year.
Definition landscape.h:25
uint8_t lowest_value
Lowest snow line of the year.
Definition landscape.h:26
uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
Definition landscape.h:24
Tile information, used while rendering the tile.
Definition tile_cmd.h:43
Generic 'commands' that can be performed on all tiles.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18