OpenTTD
landscape.h
Go to the documentation of this file.
1 /* $Id$ */
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 int GetSlopePixelZOutsideMap(int x, int y);
44 void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2);
45 
55 static inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
56 {
57  return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
58 }
59 
68 static inline Slope GetFoundationPixelSlope(TileIndex tile, int *z)
69 {
70  assert(z != NULL);
71  Slope s = GetFoundationSlope(tile, z);
72  *z *= TILE_HEIGHT;
73  return s;
74 }
75 
84 static inline Point RemapCoords(int x, int y, int z)
85 {
86  Point pt;
87  pt.x = (y - x) * 2 * ZOOM_LVL_BASE;
88  pt.y = (y + x - z) * ZOOM_LVL_BASE;
89  return pt;
90 }
91 
100 static inline Point RemapCoords2(int x, int y)
101 {
102  return RemapCoords(x, y, GetSlopePixelZ(x, y));
103 }
104 
114 static inline Point InverseRemapCoords(int x, int y)
115 {
116  Point pt = {(y * 2 - x) >> (2 + ZOOM_LVL_SHIFT), (y * 2 + x) >> (2 + ZOOM_LVL_SHIFT)};
117  return pt;
118 }
119 
120 Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = NULL);
121 
132 {
133  return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
134 }
135 
136 void DrawFoundation(TileInfo *ti, Foundation f);
137 bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
138 bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
139 
140 void DoClearSquare(TileIndex tile);
141 void RunTileLoop();
142 
143 void InitializeLandscape();
144 void GenerateLandscape(byte mode);
145 
146 #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:670
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:84
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
Set a variable snow line, as loaded from a newgrf file.
Definition: landscape.cpp:627
bool IsSnowLineSet()
Has a snow line table already been loaded.
Definition: landscape.cpp:617
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.cpp:377
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:68
void GenerateLandscape(byte mode)
Definition: landscape.cpp:1295
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:395
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:217
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:131
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:472
void ClearSnowLine()
Clear the variable snow line table and free the memory.
Definition: landscape.cpp:679
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
Point InverseRemapCoords2(int x, int y, bool clamp_to_map=false, bool *clamped=NULL)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.cpp:105
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:803
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:55
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:424
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
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:359
static Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:114
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:646
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:164
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:100
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:660