Update: Translations from eints
[openttd-github.git] / src / landscape.h
blob98221c5019b0902e71668d6e33ee96bc312b8e27
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 */
8 /** @file landscape.h Functions related to OTTD's landscape. */
10 #ifndef LANDSCAPE_H
11 #define LANDSCAPE_H
13 #include "core/geometry_type.hpp"
14 #include "tile_cmd.h"
16 static const uint SNOW_LINE_MONTHS = 12; ///< Number of months in the snow line table.
17 static const uint SNOW_LINE_DAYS = 32; ///< Number of days in each month in the snow line table.
19 /**
20 * Structure describing the height of the snow line each day of the year
21 * @ingroup SnowLineGroup
23 struct SnowLine {
24 uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]; ///< Height of the snow line each day of the year
25 uint8_t highest_value; ///< Highest snow line of the year
26 uint8_t lowest_value; ///< Lowest snow line of the year
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();
36 int GetSlopeZInCorner(Slope tileh, Corner corner);
37 std::tuple<Slope, int> GetFoundationSlope(TileIndex tile);
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);
44 /**
45 * Determine the Z height of a corner relative to TileZ.
47 * @pre The slope must not be a halftile slope.
49 * @param tileh The slope.
50 * @param corner The corner.
51 * @return Z position of corner relative to TileZ.
53 inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
55 return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
58 /**
59 * Get slope of a tile on top of a (possible) foundation
60 * If a tile does not have a foundation, the function returns the same as GetTilePixelSlope.
62 * @param tile The tile of interest.
63 * @return The slope on top of the foundation and the z of the foundation.
65 inline std::tuple<Slope, int> GetFoundationPixelSlope(TileIndex tile)
67 auto [s, z] = GetFoundationSlope(tile);
68 return {s, z * TILE_HEIGHT};
71 /**
72 * Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
73 * @param x X world or tile coordinate (runs in SW direction in the 2D view).
74 * @param y Y world or tile coordinate (runs in SE direction in the 2D view).
75 * @param z Z world or tile coordinate (runs in N direction in the 2D view).
76 * @return Equivalent coordinate in the 2D view.
77 * @see RemapCoords2
79 inline Point RemapCoords(int x, int y, int z)
81 Point pt;
82 pt.x = (y - x) * 2 * ZOOM_BASE;
83 pt.y = (y + x - z) * ZOOM_BASE;
84 return pt;
87 /**
88 * Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
89 * Same as #RemapCoords, except the Z coordinate is read from the map.
90 * @param x X world or tile coordinate (runs in SW direction in the 2D view).
91 * @param y Y world or tile coordinate (runs in SE direction in the 2D view).
92 * @return Equivalent coordinate in the 2D view.
93 * @see RemapCoords
95 inline Point RemapCoords2(int x, int y)
97 return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
101 * Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
102 * Function assumes <tt>z == 0</tt>. For other values of \p z, add \p z to \a y before the call.
103 * @param x X coordinate of the 2D coordinate.
104 * @param y Y coordinate of the 2D coordinate.
105 * @return X and Y components of equivalent world or tile coordinate.
106 * @note Inverse of #RemapCoords function. Smaller values may get rounded.
107 * @see InverseRemapCoords2
109 inline Point InverseRemapCoords(int x, int y)
111 Point pt = {(y * 2 - x) >> (2 + ZOOM_BASE_SHIFT), (y * 2 + x) >> (2 + ZOOM_BASE_SHIFT)};
112 return pt;
115 Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
117 uint ApplyFoundationToSlope(Foundation f, Slope &s);
119 * Applies a foundation to a slope.
121 * @pre Foundation and slope must be valid combined.
122 * @param f The #Foundation.
123 * @param s The #Slope to modify.
124 * @return Increment to the tile Z coordinate.
126 inline uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
128 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
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);
135 void DoClearSquare(TileIndex tile);
136 void RunTileLoop();
138 void InitializeLandscape();
139 bool GenerateLandscape(uint8_t mode);
141 #endif /* LANDSCAPE_H */