/* $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 */