OpenTTD Source: src/landscape.h Source File

OpenTTD Source 15.0-beta1

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 uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
25 uint8_t highest_value;
26 uint8_t lowest_value;
27};
28
29bool IsSnowLineSet();
30void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
31uint8_t GetSnowLine();
32uint8_t HighestSnowLine();
33uint8_t LowestSnowLine();
34void ClearSnowLine();
35
36int GetSlopeZInCorner(Slope tileh, Corner corner);
37std::tuple<Slope, int> GetFoundationSlope(TileIndex tile);
38
39uint GetPartialPixelZ(int x, int y, Slope corners);
40int GetSlopePixelZ(int x, int y, bool ground_vehicle = false);
41int GetSlopePixelZOutsideMap(int x, int y);
42void 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
117uint ApplyFoundationToSlope(Foundation f, Slope &s);
126 inline uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
127{
128 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
129}
130
131void DrawFoundation(TileInfo *ti, Foundation f);
132bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
133bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
134
135void DoClearSquare(TileIndex tile);
136void RunTileLoop();
137
138void InitializeLandscape();
139bool GenerateLandscape(uint8_t mode);
140
141#endif /* LANDSCAPE_H */
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:73
geometry_type.hpp
All geometry types in OpenTTD.
SetSnowLine
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
LowestSnowLine
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition landscape.cpp:632
GetSnowLine
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
Definition landscape.cpp:609
IsSnowLineSet
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition landscape.cpp:580
ClearSnowLine
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition landscape.cpp:641
HighestSnowLine
uint8_t HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition landscape.cpp:622
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:65
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition landscape.cpp:228
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:318
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
Definition landscape.cpp:769
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:111
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:79
ApplyPixelFoundationToSlope
uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.h:126
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition landscape.cpp:425
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.cpp:336
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:95
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:382
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:303
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:354
GetSlopePixelZInCorner
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.h:53
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:109
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.cpp:170
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:1551
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
Corner
Corner
Enumeration of tile corners.
Definition slope_type.h:22
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
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:43
tile_cmd.h
Generic 'commands' that can be performed on all tiles.
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18