OpenTTD Source 20251005-master-ga617d009cc
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
23struct SnowLine {
25 uint8_t highest_value = 0;
26 uint8_t lowest_value = UINT8_MAX;
27};
28
29bool IsSnowLineSet();
30void SetSnowLine(std::unique_ptr<SnowLine> &&snow_line);
31uint8_t GetSnowLine();
32uint8_t HighestSnowLine();
33uint8_t LowestSnowLine();
34void ClearSnowLine();
35
37
38int GetSlopeZInCorner(Slope tileh, Corner corner);
39std::tuple<Slope, int> GetFoundationSlope(TileIndex tile);
40
41uint GetPartialPixelZ(int x, int y, Slope corners);
42int GetSlopePixelZ(int x, int y, bool ground_vehicle = false);
43int GetSlopePixelZOutsideMap(int x, int y);
44void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2);
45
55inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
56{
57 return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
58}
59
67inline std::tuple<Slope, int> GetFoundationPixelSlope(TileIndex tile)
68{
69 auto [s, z] = GetFoundationSlope(tile);
70 return {s, z * TILE_HEIGHT};
71}
72
81inline Point RemapCoords(int x, int y, int z)
82{
83 Point pt;
84 pt.x = (y - x) * 2 * ZOOM_BASE;
85 pt.y = (y + x - z) * ZOOM_BASE;
86 return pt;
87}
88
97inline Point RemapCoords2(int x, int y)
98{
99 return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
100}
101
111inline Point InverseRemapCoords(int x, int y)
112{
113 Point pt = {(y * 2 - x) >> (2 + ZOOM_BASE_SHIFT), (y * 2 + x) >> (2 + ZOOM_BASE_SHIFT)};
114 return pt;
115}
116
117Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
118
129{
130 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
131}
132
134bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
135bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
136
137void DoClearSquare(TileIndex tile);
138void RunTileLoop();
139
140void InitializeLandscape();
141bool GenerateLandscape(uint8_t mode);
142
143#endif /* LANDSCAPE_H */
DiagDirection
Enumeration for diagonal directions.
All geometry types in OpenTTD.
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.
void SetSnowLine(std::unique_ptr< SnowLine > &&snow_line)
Set a variable snow line, as loaded from a newgrf file.
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:67
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:81
uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.h:128
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:97
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:55
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:111
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
bool IsMapSurroundedByWater()
Check if all tiles on the map edge should be considered water borders.
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition landscape.h:16
bool GenerateLandscape(uint8_t mode)
Corner
Enumeration of tile corners.
Definition slope_type.h:22
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
T y
Y coordinate.
T x
X coordinate.
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:30
Generic 'commands' that can be performed on all tiles.
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18