diff options
author | Erich Eckner <git@eckner.net> | 2018-10-30 11:13:12 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-10-30 15:28:03 +0100 |
commit | a34d095259409cf1454d9777deabbc00bcdb9407 (patch) | |
tree | 9e7c37ed33f5bd6b3c2f41cf248dcb656b2a4afa /src/layer_func.h | |
parent | 6647cb917963c4e0d6d633b7a92af78167050893 (diff) | |
download | openttd-underground-plus-others-original.tar.xz |
underground patch appliedunderground-plus-others-original
Diffstat (limited to 'src/layer_func.h')
-rw-r--r-- | src/layer_func.h | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/src/layer_func.h b/src/layer_func.h new file mode 100644 index 000000000..250e79a3d --- /dev/null +++ b/src/layer_func.h @@ -0,0 +1,159 @@ +/* $Id: layer_func.h 2012-09-07 18:11:11 constructor $ */ + +/* +* Подробое описание см. в layer.cpp +*/ + +/** @file layer_func.h Functions related to layer in maps. */ + +#ifndef LAYER_FUNC_H +#define LAYER_FUNC_H + +#include "map_func.h" +#include "viewport_type.h" + +/* +* +* Инициализация "подземелий" +* Количество слоев "1" равносильно игре без "подземелий" +* +*/ +void InstallLayerSystem(uint size_x, uint size_y, uint layer_count); + +/* Корректировка "подземных" слоев +* (в будущем слои могут менять высоты -- в пределах соседей) */ +void FixUndergroundHeights(); + +#define FOR_ALL_LAYERS(var) for (uint var = 0; var < LayerCount(); var++) + + +/** + * Get the size of the layer along the X + * @return the number of tiles along the X of the layer + */ +static inline uint LayerSizeX() +{ + extern uint _map_size_x; + return _map_size_x; +} + +/** + * Get the size of the layer along the Y + * @return the number of tiles along the Y of the layer + */ +static inline uint LayerSizeY() +{ + extern uint _layer_size_y; + return _layer_size_y; +} + +/** + * Gets the maximum X coordinate within the map, including MP_VOID + * @return the maximum X coordinate + */ +static inline uint LayerMaxX() +{ + return LayerSizeX() - 1; +} + +/** + * Gets the maximum Y coordinate within the map, including MP_VOID + * @return the maximum Y coordinate + */ +static inline uint LayerMaxY() +{ + return LayerSizeY() - 1; +} + +/** + * Get the layer counts + * @return the number of layers + */ +static inline uint LayerCount() +{ + extern uint _layer_count; + return _layer_count; +} + +/** + * Get the layer counts + * @return the number of layers + */ +static inline uint LayerCountLog() +{ + extern uint _layer_count_log; + return _layer_count_log; +} + +/** + * Get the X component of a tile + * @param tile the tile to get the X component of + * @return the X component + */ +static inline uint LayerX(TileIndex tile) +{ + return tile & LayerMaxX(); +} + +/** + * Get the Y component of a tile + * @param tile the tile to get the Y component of + * @return the Y component + */ +static inline uint LayerY(TileIndex tile) +{ + return (tile >> MapLogX()) & LayerMaxY(); +} + +static inline uint LayerIndex(TileIndex tile) +{ + return (tile >> MapLogX()) / LayerSizeY(); +} + +static inline bool IsUnderground(TileIndex tile) +{ + return LayerIndex(tile) != 0; +} + +/** +* Размер слоя. +* Можно прибавить к клетке, чтобы получить клетку ниже +*/ +static inline uint LayerSize() +{ + extern uint _layer_size; + return _layer_size; +} + +/** + * Ищем клетку поверхности для данной (самую верхнюю клетку) + * @param tile the tile to get the Y component of + * @return the Y component + */ +static inline uint TopTile(TileIndex tile) +{ + uint layer = LayerIndex(tile); + return (tile - layer * LayerSize()); +} + +/* Определить верхняя ли клеточка очень просто */ +static inline bool IsTopTile(TileIndex tile) +{ + return (tile < LayerSize()); +} + +/* Ищет клетку над данной. (Для самой верхней вернет нижнюю??) +*/ +static inline uint UpTile(TileIndex tile) +{ + return TILE_MASK(tile - LayerSize()); +} + +/* Ищет клетку под данной. (Для самой нижней вернет верхнюю??) +*/ +static inline uint DownTile(TileIndex tile) +{ + return TILE_MASK(tile + LayerSize()); +} + +#endif /* LAYER_FUNC_H */ |