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 {
28  byte lowest_value;
29 };
30 
31 bool IsSnowLineSet();
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 
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
Enumeration of tile corners.
Definition: slope_type.h:24
byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]
Height of the snow line each day of the year.
Definition: landscape.h:26
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:588
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
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
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition: landscape.cpp:535
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:295
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
Definition: landscape.h:18
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
void GenerateLandscape(byte mode)
Definition: landscape.cpp:1211
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
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:152
Foundation
Enumeration for Foundations.
Definition: slope_type.h:95
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:127
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:390
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:597
Structure describing the height of the snow line each day of the year.
Definition: landscape.h:25
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
byte lowest_value
Lowest snow line of the year.
Definition: landscape.h:28
DiagDirection
Enumeration for diagonal directions.
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks...
Definition: landscape.cpp:721
byte highest_value
Highest snow line of the year.
Definition: landscape.h:27
static int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.h:54
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
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
All geometry types in OpenTTD.
Coordinates of a point in 2D.
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:564
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:99
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Definition: landscape.h:19
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
Generic &#39;commands&#39; that can be performed on all tiles.
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:578