2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file landscape.h Functions related to OTTD's landscape. */
|
2007-03-20 13:47:00 +00:00
|
|
|
|
2007-04-12 13:07:15 +00:00
|
|
|
#ifndef LANDSCAPE_H
|
|
|
|
#define LANDSCAPE_H
|
|
|
|
|
2007-12-22 23:30:28 +00:00
|
|
|
#include "core/geometry_type.hpp"
|
2007-12-25 23:42:52 +00:00
|
|
|
#include "tile_cmd.h"
|
2023-07-03 22:34:52 +00:00
|
|
|
#include <vector>
|
2007-12-21 22:50:51 +00:00
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
static const uint SNOW_LINE_MONTHS = 12; ///< Number of months in the snow line table.
|
|
|
|
static const uint SNOW_LINE_DAYS = 32; ///< Number of days in each month in the snow line table.
|
2007-03-20 13:47:00 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Structure describing the height of the snow line each day of the year
|
2010-08-01 19:44:49 +00:00
|
|
|
* @ingroup SnowLineGroup
|
|
|
|
*/
|
2007-03-20 13:47:00 +00:00
|
|
|
struct SnowLine {
|
2008-10-19 15:39:12 +00:00
|
|
|
byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]; ///< Height of the snow line each day of the year
|
|
|
|
byte highest_value; ///< Highest snow line of the year
|
2009-02-23 20:03:38 +00:00
|
|
|
byte lowest_value; ///< Lowest snow line of the year
|
2007-03-20 13:47:00 +00:00
|
|
|
};
|
|
|
|
|
2009-05-21 22:43:25 +00:00
|
|
|
bool IsSnowLineSet();
|
2007-03-20 13:47:00 +00:00
|
|
|
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
|
2021-02-21 22:02:58 +00:00
|
|
|
byte GetSnowLineUncached();
|
|
|
|
void UpdateCachedSnowLine();
|
2022-04-29 16:10:18 +00:00
|
|
|
void UpdateCachedSnowLineBounds();
|
2009-05-21 22:43:25 +00:00
|
|
|
void ClearSnowLine();
|
2007-04-12 13:07:15 +00:00
|
|
|
|
2021-02-21 22:02:58 +00:00
|
|
|
inline byte GetSnowLine()
|
|
|
|
{
|
|
|
|
extern byte _cached_snowline;
|
|
|
|
return _cached_snowline;
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:10:18 +00:00
|
|
|
inline byte HighestSnowLine()
|
|
|
|
{
|
|
|
|
extern byte _cached_highest_snowline;
|
|
|
|
return _cached_highest_snowline;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline byte LowestSnowLine()
|
|
|
|
{
|
|
|
|
extern byte _cached_lowest_snowline;
|
|
|
|
return _cached_lowest_snowline;
|
|
|
|
}
|
|
|
|
|
2022-04-30 23:41:08 +00:00
|
|
|
inline byte HighestTreePlacementSnowLine()
|
|
|
|
{
|
|
|
|
extern byte _cached_tree_placement_highest_snowline;
|
|
|
|
return _cached_tree_placement_highest_snowline;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline byte LowestTreePlacementSnowLine()
|
|
|
|
{
|
2022-05-05 16:17:24 +00:00
|
|
|
return LowestSnowLine();
|
2022-04-30 23:41:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 10:20:24 +00:00
|
|
|
int GetSlopeZInCorner(Slope tileh, Corner corner);
|
2023-02-25 22:12:31 +00:00
|
|
|
Slope GetFoundationSlopeFromTileSlope(TileIndex tile, Slope tileh, int *z = nullptr);
|
2019-04-10 21:07:06 +00:00
|
|
|
Slope GetFoundationSlope(TileIndex tile, int *z = nullptr);
|
2011-11-04 10:20:24 +00:00
|
|
|
|
2011-11-04 10:18:13 +00:00
|
|
|
uint GetPartialPixelZ(int x, int y, Slope corners);
|
2023-03-12 17:14:44 +00:00
|
|
|
int GetSlopePixelZ(int x, int y, bool ground_vehicle = false);
|
2019-01-13 19:58:48 +00:00
|
|
|
int GetSlopePixelZOutsideMap(int x, int y);
|
2011-11-04 10:18:13 +00:00
|
|
|
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2);
|
2011-11-04 10:20:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine the Z height of a corner relative to TileZ.
|
|
|
|
*
|
|
|
|
* @pre The slope must not be a halftile slope.
|
|
|
|
*
|
|
|
|
* @param tileh The slope.
|
|
|
|
* @param corner The corner.
|
|
|
|
* @return Z position of corner relative to TileZ.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
|
2011-11-04 10:20:24 +00:00
|
|
|
{
|
|
|
|
return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param tile The tile of interest.
|
2019-04-10 21:07:06 +00:00
|
|
|
* @param z returns the z of the foundation slope. (Can be nullptr, if not needed)
|
2011-11-04 10:20:24 +00:00
|
|
|
* @return The slope on top of the foundation.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline Slope GetFoundationPixelSlope(TileIndex tile, int *z)
|
2011-11-04 10:20:24 +00:00
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(z != nullptr);
|
2011-11-04 10:20:24 +00:00
|
|
|
Slope s = GetFoundationSlope(tile, z);
|
2011-11-04 10:23:48 +00:00
|
|
|
*z *= TILE_HEIGHT;
|
2011-11-04 10:20:24 +00:00
|
|
|
return s;
|
|
|
|
}
|
2007-04-12 13:07:15 +00:00
|
|
|
|
2010-02-06 09:30:30 +00:00
|
|
|
/**
|
|
|
|
* Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
|
|
|
|
* @param x X world or tile coordinate (runs in SW direction in the 2D view).
|
|
|
|
* @param y Y world or tile coordinate (runs in SE direction in the 2D view).
|
|
|
|
* @param z Z world or tile coordinate (runs in N direction in the 2D view).
|
|
|
|
* @return Equivalent coordinate in the 2D view.
|
|
|
|
* @see RemapCoords2
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline Point RemapCoords(int x, int y, int z)
|
2007-04-12 13:07:15 +00:00
|
|
|
{
|
|
|
|
Point pt;
|
2011-11-24 12:38:48 +00:00
|
|
|
pt.x = (y - x) * 2 * ZOOM_LVL_BASE;
|
|
|
|
pt.y = (y + x - z) * ZOOM_LVL_BASE;
|
2007-04-12 13:07:15 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2010-02-06 09:30:30 +00:00
|
|
|
/**
|
|
|
|
* Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
|
|
|
|
* Same as #RemapCoords, except the Z coordinate is read from the map.
|
|
|
|
* @param x X world or tile coordinate (runs in SW direction in the 2D view).
|
|
|
|
* @param y Y world or tile coordinate (runs in SE direction in the 2D view).
|
|
|
|
* @return Equivalent coordinate in the 2D view.
|
|
|
|
* @see RemapCoords
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline Point RemapCoords2(int x, int y)
|
2007-04-12 13:07:15 +00:00
|
|
|
{
|
2023-03-12 17:14:44 +00:00
|
|
|
return RemapCoords(x, y, GetSlopePixelZ(x, y, false));
|
2007-04-12 13:07:15 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 13:14:40 +00:00
|
|
|
/**
|
|
|
|
* Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
|
|
|
|
* Function assumes <tt>z == 0</tt>. For other values of \p z, add \p z to \a y before the call.
|
|
|
|
* @param x X coordinate of the 2D coordinate.
|
|
|
|
* @param y Y coordinate of the 2D coordinate.
|
|
|
|
* @return X and Y components of equivalent world or tile coordinate.
|
|
|
|
* @note Inverse of #RemapCoords function. Smaller values may get rounded.
|
2019-01-13 19:52:04 +00:00
|
|
|
* @see InverseRemapCoords2
|
2010-02-06 13:14:40 +00:00
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline Point InverseRemapCoords(int x, int y)
|
2010-02-06 13:14:40 +00:00
|
|
|
{
|
2011-11-24 12:38:48 +00:00
|
|
|
Point pt = {(y * 2 - x) >> (2 + ZOOM_LVL_SHIFT), (y * 2 + x) >> (2 + ZOOM_LVL_SHIFT)};
|
2010-02-06 13:14:40 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
Point InverseRemapCoords2(int x, int y, bool clamp_to_map = false, bool *clamped = nullptr);
|
2019-01-13 19:52:04 +00:00
|
|
|
|
2011-11-04 10:20:24 +00:00
|
|
|
uint ApplyFoundationToSlope(Foundation f, Slope *s);
|
|
|
|
/**
|
|
|
|
* Applies a foundation to a slope.
|
|
|
|
*
|
|
|
|
* @pre Foundation and slope must be valid combined.
|
|
|
|
* @param f The #Foundation.
|
|
|
|
* @param s The #Slope to modify.
|
|
|
|
* @return Increment to the tile Z coordinate.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
|
2011-11-04 10:20:24 +00:00
|
|
|
{
|
|
|
|
return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
void DrawFoundation(TileInfo *ti, Foundation f);
|
2010-01-03 22:44:57 +00:00
|
|
|
bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
|
|
|
|
bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
|
2007-04-12 13:07:15 +00:00
|
|
|
|
|
|
|
void DoClearSquare(TileIndex tile);
|
2023-06-17 18:32:33 +00:00
|
|
|
void SetupTileLoopCounts();
|
|
|
|
void RunTileLoop(bool apply_day_length = false);
|
2023-02-09 21:39:04 +00:00
|
|
|
void RunAuxiliaryTileLoop();
|
2007-04-12 13:07:15 +00:00
|
|
|
|
|
|
|
void InitializeLandscape();
|
2024-01-22 22:35:25 +00:00
|
|
|
bool GenerateLandscape(byte mode);
|
2007-04-12 13:07:15 +00:00
|
|
|
|
|
|
|
#endif /* LANDSCAPE_H */
|