OpenTTD Source: src/landscape.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
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
36bool IsMapSurroundedByWater();
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
55 inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
56{
57 return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
58}
59
67 inline std::tuple<Slope, int> GetFoundationPixelSlope(TileIndex tile)
68{
69 auto [s, z] = GetFoundationSlope(tile);
70 return {s, z * TILE_HEIGHT};
71}
72
81 inline 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
97 inline Point RemapCoords2(int x, int y)
98{
99 return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
100}
101
111 inline 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
117 Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
118
119uint ApplyFoundationToSlope(Foundation f, Slope &s);
128 inline uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
129{
130 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
131}
132
133void DrawFoundation(TileInfo *ti, Foundation f);
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
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
geometry_type.hpp
All geometry types in OpenTTD.
LowestSnowLine
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition landscape.cpp:629
GetSnowLine
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
Definition landscape.cpp:606
IsSnowLineSet
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition landscape.cpp:586
ClearSnowLine
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition landscape.cpp:638
SetSnowLine
void SetSnowLine(std::unique_ptr< SnowLine > &&snow_line)
Set a variable snow line, as loaded from a newgrf file.
Definition landscape.cpp:596
HighestSnowLine
uint8_t HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition landscape.cpp:619
GetFoundationPixelSlope
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
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition landscape.cpp:232
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:322
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
Definition landscape.cpp:798
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:115
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:81
ApplyPixelFoundationToSlope
uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.h:128
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition landscape.cpp:429
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.cpp:340
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:97
GetFoundationSlope
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:386
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:307
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:358
GetSlopePixelZInCorner
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.h:55
SNOW_LINE_DAYS
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Definition landscape.h:17
InverseRemapCoords
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition landscape.h:111
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.cpp:174
IsMapSurroundedByWater
bool IsMapSurroundedByWater()
Check if all tiles on the map edge should be considered water borders.
Definition landscape.cpp:647
SNOW_LINE_MONTHS
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition landscape.h:16
GenerateLandscape
bool GenerateLandscape(uint8_t mode)
Definition landscape.cpp:1606
Corner
Corner
Enumeration of tile corners.
Definition slope_type.h:22
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
SnowLine
Structure describing the height of the snow line each day of the year.
Definition landscape.h:23
SnowLine::highest_value
uint8_t highest_value
Highest snow line of the year.
Definition landscape.h:25
SnowLine::lowest_value
uint8_t lowest_value
Lowest snow line of the year.
Definition landscape.h:26
SnowLine::table
uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
Definition landscape.h:24
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
tile_cmd.h
Generic 'commands' that can be performed on all tiles.
TILE_HEIGHT
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18