OpenTTD Source: src/landscape.h Source File

OpenTTD Source 14.0-beta3

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 {
24 byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
25 byte highest_value;
26 byte lowest_value;
27 };
28
29 bool IsSnowLineSet();
30 void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
31 byte GetSnowLine();
32 byte HighestSnowLine();
33 byte LowestSnowLine();
34 void ClearSnowLine();
35
36 int GetSlopeZInCorner(Slope tileh, Corner corner);
37 Slope GetFoundationSlope(TileIndex tile, int *z = nullptr);
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
66 inline Slope GetFoundationPixelSlope(TileIndex tile, int *z)
67 {
68 assert(z != nullptr);
69 Slope s = GetFoundationSlope(tile, z);
70 *z *= TILE_HEIGHT;
71 return s;
72 }
73
82 inline Point RemapCoords(int x, int y, int z)
83 {
84 Point pt;
85 pt.x = (y - x) * 2 * ZOOM_LVL_BASE;
86 pt.y = (y + x - z) * ZOOM_LVL_BASE;
87 return pt;
88 }
89
98 inline Point RemapCoords2(int x, int y)
99 {
100 return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
101 }
102
112 inline Point InverseRemapCoords(int x, int y)
113 {
114 Point pt = {(y * 2 - x) >> (2 + ZOOM_LVL_SHIFT), (y * 2 + x) >> (2 + ZOOM_LVL_SHIFT)};
115 return pt;
116 }
117
118 Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
119
120 uint ApplyFoundationToSlope(Foundation f, Slope *s);
129 inline uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
130 {
131 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
132 }
133
134 void DrawFoundation(TileInfo *ti, Foundation f);
135 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
136 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
137
138 void DoClearSquare(TileIndex tile);
139 void RunTileLoop();
140
141 void InitializeLandscape();
142 bool GenerateLandscape(byte mode);
143
144 #endif /* LANDSCAPE_H */
InverseRemapCoords2
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:107
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:427
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:166
SNOW_LINE_DAYS
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Definition: landscape.h:17
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
SnowLine::table
byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
Definition: landscape.h:24
GetSlopePixelZOutsideMap
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:314
GenerateLandscape
bool GenerateLandscape(byte mode)
Definition: landscape.cpp:1560
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetFoundationPixelSlope
Slope GetFoundationPixelSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.h:66
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
GetSlopePixelZOnEdge
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:350
tile_cmd.h
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
geometry_type.hpp
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:611
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
HighestSnowLine
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:624
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle=false)
Return world Z coordinate of a given point of a tile.
Definition: landscape.cpp:299
GetFoundationSlope
Slope GetFoundationSlope(TileIndex tile, int *z=nullptr)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.cpp:379
LowestSnowLine
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:634
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:224
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
SnowLine
Structure describing the height of the snow line each day of the year.
Definition: landscape.h:23
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:332
SetSnowLine
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
Set a variable snow line, as loaded from a newgrf file.
Definition: landscape.cpp:592
SnowLine::lowest_value
byte lowest_value
Lowest snow line of the year.
Definition: landscape.h:26
RemapCoords2
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:98
SnowLine::highest_value
byte highest_value
Highest snow line of the year.
Definition: landscape.h:25
GetSlopePixelZInCorner
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.h:53
IsSnowLineSet
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition: landscape.cpp:582
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
Definition: landscape.cpp:759
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
ClearSnowLine
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:643
InverseRemapCoords
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
ApplyPixelFoundationToSlope
uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:129
RemapCoords
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:82
SNOW_LINE_MONTHS
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:16