OpenTTD

landscape.h
Go to the documentation of this file.
1 /* $Id: landscape.h 23735 2012-01-03 20:26:05Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef LANDSCAPE_H
13 #define LANDSCAPE_H
14
15 #include "core/geometry_type.hpp"
16 #include "tile_cmd.h"
17
18 static const uint SNOW_LINE_MONTHS = 12;
19 static const uint SNOW_LINE_DAYS = 32;
20
25 struct SnowLine {
26 byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
27 byte highest_value;
28 byte lowest_value;
29 };
30
31 bool IsSnowLineSet();
32 void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
33 byte GetSnowLine();
34 byte HighestSnowLine();
35 byte LowestSnowLine();
36 void ClearSnowLine();
37
38 int GetSlopeZInCorner(Slope tileh, Corner corner);
39 Slope GetFoundationSlope(TileIndex tile, int *z = NULL);
40
41 uint GetPartialPixelZ(int x, int y, Slope corners);
42 int GetSlopePixelZ(int x, int y);
43 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2);
44
54 static inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
55 {
56 return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
57 }
58
67 static inline Slope GetFoundationPixelSlope(TileIndex tile, int *z)
68 {
69 assert(z != NULL);
70 Slope s = GetFoundationSlope(tile, z);
71 *z *= TILE_HEIGHT;
72 return s;
73 }
74
83 static inline Point RemapCoords(int x, int y, int z)
84 {
85 Point pt;
86 pt.x = (y - x) * 2 * ZOOM_LVL_BASE;
87 pt.y = (y + x - z) * ZOOM_LVL_BASE;
88 return pt;
89 }
90
99 static inline Point RemapCoords2(int x, int y)
100 {
101 return RemapCoords(x, y, GetSlopePixelZ(x, y));
102 }
103
112 static 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 uint ApplyFoundationToSlope(Foundation f, Slope *s);
127 static inline uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
128 {
129 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
130 }
131
132 void DrawFoundation(TileInfo *ti, Foundation f);
133 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
134 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
135
136 void DoClearSquare(TileIndex tile);
137 void RunTileLoop();
138
139 void InitializeLandscape();
140 void GenerateLandscape(byte mode);
141
142 #endif /* LANDSCAPE_H */
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:24
SnowLine::table
byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
Definition: landscape.h:26
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
LowestSnowLine
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:588
RemapCoords
static 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:83
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:545
IsSnowLineSet
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition: landscape.cpp:535
GetSlopeZInCorner
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:295
SNOW_LINE_MONTHS
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:18
GetFoundationPixelSlope
static 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, the function returns the same as GetTilePixelSlope.
Definition: landscape.h:67
GenerateLandscape
void GenerateLandscape(byte mode)
Definition: landscape.cpp:1211
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:313
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:152
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:95
ApplyPixelFoundationToSlope
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:127
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:390
ClearSnowLine
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:597
SnowLine
Structure describing the height of the snow line each day of the year.
Definition: landscape.h:25
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
SnowLine::lowest_value
byte lowest_value
Lowest snow line of the year.
Definition: landscape.h:28
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:80
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks...
Definition: landscape.cpp:721
SnowLine::highest_value
byte highest_value
Highest snow line of the year.
Definition: landscape.h:27
GetSlopePixelZInCorner
static int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.h:54
GetFoundationSlope
Slope GetFoundationSlope(TileIndex tile, int *z=NULL)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation, the function returns the same as GetTileSlope.
Definition: landscape.cpp:342
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
InverseRemapCoords
static Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
geometry_type.hpp
All geometry types in OpenTTD.
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:564
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:99
SNOW_LINE_DAYS
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Definition: landscape.h:19
RemapCoords2
static 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:99
tile_cmd.h
Generic &#39;commands&#39; that can be performed on all tiles.
HighestSnowLine
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:578