OpenTTD Source  20241124-master-g9399a92a4f
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 
13 #include "core/geometry_type.hpp"
14 #include "tile_cmd.h"
15 
16 static const uint SNOW_LINE_MONTHS = 12;
17 static const uint SNOW_LINE_DAYS = 32;
18 
23 struct SnowLine {
25  uint8_t highest_value;
26  uint8_t lowest_value;
27 };
28 
29 bool IsSnowLineSet();
30 void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
31 uint8_t GetSnowLine();
32 uint8_t HighestSnowLine();
33 uint8_t LowestSnowLine();
34 void ClearSnowLine();
35 
36 int GetSlopeZInCorner(Slope tileh, Corner corner);
37 std::tuple<Slope, int> GetFoundationSlope(TileIndex tile);
38 
39 uint GetPartialPixelZ(int x, int y, Slope corners);
40 int GetSlopePixelZ(int x, int y, bool ground_vehicle = false);
41 int GetSlopePixelZOutsideMap(int x, int y);
42 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2);
43 
53 inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
54 {
55  return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
56 }
57 
65 inline std::tuple<Slope, int> GetFoundationPixelSlope(TileIndex tile)
66 {
67  auto [s, z] = GetFoundationSlope(tile);
68  return {s, z * TILE_HEIGHT};
69 }
70 
79 inline 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 
95 inline Point RemapCoords2(int x, int y)
96 {
97  return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
98 }
99 
109 inline 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 
115 Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
116 
127 {
128  return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
129 }
130 
131 void DrawFoundation(TileInfo *ti, Foundation f);
132 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
133 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
134 
135 void DoClearSquare(TileIndex tile);
136 void RunTileLoop();
137 
138 void InitializeLandscape();
139 bool 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.
Definition: landscape.cpp:590
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:632
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:609
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition: landscape.cpp:580
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:641
uint8_t HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:622
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:228
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"...
Definition: landscape.cpp:318
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
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
Definition: landscape.cpp:769
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.
Definition: landscape.cpp:111
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.
Definition: landscape.cpp:425
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:336
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
int GetSlopePixelZ(int x, int y, bool ground_vehicle=false)
Return world Z coordinate of a given point of a tile.
Definition: landscape.cpp:303
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int &z1, int &z2)
Determine the Z height of the corners of a specific tile edge.
Definition: landscape.cpp:354
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
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,...
Definition: landscape.cpp:382
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.
Definition: landscape.cpp:170
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:16
bool GenerateLandscape(uint8_t mode)
Definition: landscape.cpp:1551
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