(svn r27724) -Cleanup: Remove pointless usage of IsOpenTTDBaseGRF. System GRFs are...
[openttd.git] / src / landscape.h
blobcb08d9d9ec25912c411ab2a1f92939bb40152384
1 /* $Id$ */
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 */
10 /** @file landscape.h Functions related to OTTD's landscape. */
12 #ifndef LANDSCAPE_H
13 #define LANDSCAPE_H
15 #include "core/geometry_type.hpp"
16 #include "tile_cmd.h"
18 static const uint SNOW_LINE_MONTHS = 12; ///< Number of months in the snow line table.
19 static const uint SNOW_LINE_DAYS = 32; ///< Number of days in each month in the snow line table.
21 /**
22 * Structure describing the height of the snow line each day of the year
23 * @ingroup SnowLineGroup
25 struct SnowLine {
26 byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]; ///< Height of the snow line each day of the year
27 byte highest_value; ///< Highest snow line of the year
28 byte lowest_value; ///< Lowest snow line of the year
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();
38 int GetSlopeZInCorner(Slope tileh, Corner corner);
39 Slope GetFoundationSlope(TileIndex tile, int *z = NULL);
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);
45 /**
46 * Determine the Z height of a corner relative to TileZ.
48 * @pre The slope must not be a halftile slope.
50 * @param tileh The slope.
51 * @param corner The corner.
52 * @return Z position of corner relative to TileZ.
54 static inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
56 return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
59 /**
60 * Get slope of a tile on top of a (possible) foundation
61 * If a tile does not have a foundation, the function returns the same as GetTilePixelSlope.
63 * @param tile The tile of interest.
64 * @param z returns the z of the foundation slope. (Can be NULL, if not needed)
65 * @return The slope on top of the foundation.
67 static inline Slope GetFoundationPixelSlope(TileIndex tile, int *z)
69 assert(z != NULL);
70 Slope s = GetFoundationSlope(tile, z);
71 *z *= TILE_HEIGHT;
72 return s;
75 /**
76 * Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
77 * @param x X world or tile coordinate (runs in SW direction in the 2D view).
78 * @param y Y world or tile coordinate (runs in SE direction in the 2D view).
79 * @param z Z world or tile coordinate (runs in N direction in the 2D view).
80 * @return Equivalent coordinate in the 2D view.
81 * @see RemapCoords2
83 static inline Point RemapCoords(int x, int y, int z)
85 Point pt;
86 pt.x = (y - x) * 2 * ZOOM_LVL_BASE;
87 pt.y = (y + x - z) * ZOOM_LVL_BASE;
88 return pt;
91 /**
92 * Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
93 * Same as #RemapCoords, except the Z coordinate is read from the map.
94 * @param x X world or tile coordinate (runs in SW direction in the 2D view).
95 * @param y Y world or tile coordinate (runs in SE direction in the 2D view).
96 * @return Equivalent coordinate in the 2D view.
97 * @see RemapCoords
99 static inline Point RemapCoords2(int x, int y)
101 return RemapCoords(x, y, GetSlopePixelZ(x, y));
105 * Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
106 * Function assumes <tt>z == 0</tt>. For other values of \p z, add \p z to \a y before the call.
107 * @param x X coordinate of the 2D coordinate.
108 * @param y Y coordinate of the 2D coordinate.
109 * @return X and Y components of equivalent world or tile coordinate.
110 * @note Inverse of #RemapCoords function. Smaller values may get rounded.
112 static inline Point InverseRemapCoords(int x, int y)
114 Point pt = {(y * 2 - x) >> (2 + ZOOM_LVL_SHIFT), (y * 2 + x) >> (2 + ZOOM_LVL_SHIFT)};
115 return pt;
118 uint ApplyFoundationToSlope(Foundation f, Slope *s);
120 * Applies a foundation to a slope.
122 * @pre Foundation and slope must be valid combined.
123 * @param f The #Foundation.
124 * @param s The #Slope to modify.
125 * @return Increment to the tile Z coordinate.
127 static inline uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
129 return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
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);
136 void DoClearSquare(TileIndex tile);
137 void RunTileLoop();
139 void InitializeLandscape();
140 void GenerateLandscape(byte mode);
142 #endif /* LANDSCAPE_H */