# HG changeset patch # Parent 1c0964d1d047cbae76eb84112815a8fa8fd7e740 diff --git a/src/map.h b/src/map.h --- a/src/map.h +++ b/src/map.h @@ -16,7 +16,6 @@ #include "path.h" #include "geometry.h" #include "sprite_store.h" -#include "bitmath.h" #include @@ -360,17 +359,6 @@ public: }; /** - * Does the instance data indicate a valid path (that is, a voxel with an actual path tile)? - * @param instance_data Instance data to examine. - * @return Whether the instance data indicates a valid path. - * @pre The instance must be #SRI_PATH - */ -static inline bool HasValidPath(uint16 instance_data) -{ - return instance_data != PATH_INVALID; -} - -/** * Does the given voxel contain a valid path? * @param v %Voxel to examine. * @return @c true if the voxel contains a valid path, else \c false. @@ -382,30 +370,6 @@ static inline bool HasValidPath(const Vo } /** - * Extract the imploded path slope from the instance data. - * @param instance_data Instance data to examine. - * @return Imploded slope of the path. - * @pre instance data must be a valid path. - */ -static inline PathSprites GetImplodedPathSlope(uint16 instance_data) -{ - return (PathSprites)GB(instance_data, 0, 6); -} - -/** - * Change the path slope in the path instance data. - * @param instance_data Previous instance data. - * @param slope New imploded path slope. - * @return New instance data of a path. - * @pre instance data must be a valid path. - */ -static inline uint16 SetImplodedPathSlope(uint16 instance_data, uint8 slope) -{ - SB(instance_data, 0, 6, slope); - return instance_data; -} - -/** * Get the slope of the path (imploded value). * @param v %Voxel to examine. * @return Imploded slope of the path. @@ -420,28 +384,6 @@ static inline PathSprites GetImplodedPat return ps; } -/** - * Get the path type from the path voxel instance data. - * @param instance_data Instance data to examine. - * @return Type of path. - * @pre instance data must be a valid path. - */ -static inline PathType GetPathType(uint16 instance_data) -{ - return (PathType)GB(instance_data, 6, 2); -} - -/** - * Construct instance data for a valid path. - * @param slope Imploded slope of the path. - * @param path_type Type of the path. - * @return Instance data of a valid path. - */ -static inline uint16 MakePathInstanceData(uint8 slope, PathType path_type) -{ - return slope | (path_type << 6); -} - /** Possible ownerships of a tile. */ enum TileOwner { OWN_NONE, ///< Tile not owned by the park and not for sale. diff --git a/src/path.cpp b/src/path.cpp --- a/src/path.cpp +++ b/src/path.cpp @@ -240,6 +240,17 @@ uint8 GetPathExits(const Voxel *v) } /** + * If the path instance data has decoration, would it be visible? + * @param instance_data Instance data to examine. + * @return Path decoration is or could be visible. + */ +bool IsPathDecorationVisible(uint16 instance_data) +{ + uint8 exp_slope = _path_expand[GetImplodedPathSlope(instance_data)]; + return (exp_slope & PATHMASK_EDGES) != PATHMASK_EDGES; +} + +/** * Walk over a queue path from the given entry edge at the given position. * If it leads to a new voxel edge, the provided position and edge is update with the exit point. * @param voxel_pos [inout] Start voxel position before the queue path, updated to last voxel position. diff --git a/src/path.h b/src/path.h --- a/src/path.h +++ b/src/path.h @@ -7,12 +7,23 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FreeRCT. If not, see . */ -/** @file path.h %Path definitions. */ +/** + * @file path.h %Path definitions. + * + * Path instance data has the following structure: + * - bit 0..5 Imploded slope of the path. @see HasValidPath, GetImplodedPathSlope, SetImplodedPathSlope + * - bit 6..7 Path type. @see GetPathType + * - bit 8..11 Amount of litter. If no litter bin or demolished litter bin, values above 3 count as 3, and are lying on the path itself. + * - bit 12 Unused. + * - bit 13..14 Path decoration (litter bin, benches, or lamp posts. @see PathDecoration + * - bit 15 Path decoration has been demolished. Only valid if the decoration is visible to the user. + */ #ifndef PATH_H #define PATH_H #include "tile.h" +#include "bitmath.h" /** * Available path sprites. @@ -118,6 +129,168 @@ enum PathStatus { PAS_QUEUE_PATH, ///< %Path to queue on. }; +/** Path decoration. */ +enum PathDecoration { + PDEC_NONE, ///< Path has no decoration. + PDEC_LITTERBIN, ///< Path has litter bins. + PDEC_BENCH, ///< Path has benches. + PDEC_LAMPPOST, ///< Path has lamp posts. +}; + +/** + * Does the instance data indicate a valid path (that is, a voxel with an actual path tile)? + * @param instance_data Instance data to examine. + * @return Whether the instance data indicates a valid path. + * @pre The instance must be #SRI_PATH + */ +static inline bool HasValidPath(uint16 instance_data) +{ + return GB(instance_data, 0, 6) != PATH_INVALID; +} + +/** + * Extract the imploded path slope from the instance data. + * @param instance_data Instance data to examine. + * @return Imploded slope of the path. + * @pre instance data must be a valid path. + */ +static inline PathSprites GetImplodedPathSlope(uint16 instance_data) +{ + return (PathSprites)GB(instance_data, 0, 6); +} + +/** + * Change the path slope in the path instance data. + * @param instance_data Previous instance data. + * @param slope New imploded path slope. + * @return New instance data of a path. + * @pre instance data must be a valid path. + */ +static inline uint16 SetImplodedPathSlope(uint16 instance_data, uint8 slope) +{ + SB(instance_data, 0, 6, slope); + return instance_data; +} + +/** + * Get the path type from the path voxel instance data. + * @param instance_data Instance data to examine. + * @return Type of path. + * @pre instance data must be a valid path. + */ +static inline PathType GetPathType(uint16 instance_data) +{ + return (PathType)GB(instance_data, 6, 2); +} + +/** + * Get the decoration of path instance data. + * @param instance_data Instance data to examine. + * @return The decoration of the path. + * @pre instance data must be a valid path, decoration must be visible to the user. + */ +static inline PathDecoration GetPathDecoration(uint16 instance_data) +{ + return (PathDecoration)GB(instance_data, 13, 2); +} + +/** + * Set the decoration of the path. + * @param instance_data Instance data to update. + * @param decoration Path decoration to set. + * @return Modified instance data. + * @pre instance data must be a valid path, decoration must be visible to the user. + */ +static inline uint16 SetPathDecoration(uint16 instance_data, PathDecoration decoration) +{ + SB(instance_data, 13, 2, decoration); + return instance_data; +} + +/** + * Get the 'demolished' bit of path instance data. + * @param instance_data Instance data to examine. + * @return The 'demolished' bit of the path. + * @pre instance data must be a valid path, decoration must be visible to the user. + */ +static inline bool GetPathDemolished(uint16 instance_data) +{ + return GB(instance_data, 15, 1) != 0; +} + +/** + * Set the 'demolished' bit of path instance data. + * @param instance_data Instance data to update. + * @param demolished New state of the 'demolished' bit of the path. + * @return Modified instance data. + * @pre instance data must be a valid path, decoration must be visible to the user. + */ +static inline uint16 SetPathDemolished(uint16 instance_data, bool demolished) +{ + SB(instance_data, 15, 1, demolished); + return instance_data; +} + +bool IsPathDecorationVisible(uint16 instance_data); + +/** + * Is the path instance_data demolished, and is it visible to the user? + * @param instance_data Instance data to examine. + * @return Demolished state of the path, as observable by the user. + */ +static inline bool GetVisiblePathDemolished(uint16 instance_data) +{ + if (!IsPathDecorationVisible(instance_data)) return false; + return GetPathDemolished(instance_data); +} + +/** + * Get the litter data from the path instance data. + * @param instance_data Instance data to examine. + * @return Value of the litter data in the path. + */ +static inline uint GetPathLitter(uint16 instance_data) +{ + return GB(instance_data, 8, 4); +} + +/** + * Set the litter data in the path instance data. + * @param instance_data Previous instance data. + * @param litter New value for the litter data. + * @return New instance data of a path. + */ +static inline uint16 SetPathLitter(uint16 instance_data, uint litter) +{ + SB(instance_data, 8, 4, std::min(0xFu, litter)); + return instance_data; +} + +/** + * How much litter is visible to the user (on the path). + * @param instance_data Instance data to examine. + * @return Amount of visible litter on the path. + */ +static inline uint GetVisiblePathLitter(uint16 instance_data) +{ + int litter = GetPathLitter(instance_data); + if (GetPathDecoration(instance_data) == PDEC_LITTERBIN && !GetPathDemolished(instance_data)) { + return std::max(0, litter - 12); + } + return std::min(3, litter); +} + +/** + * Construct instance data for a valid path without litter, path decorations, and not demolished. + * @param slope Imploded slope of the path. + * @param path_type Type of the path. + * @return Instance data of a valid path. + */ +static inline uint16 MakePathInstanceData(uint8 slope, PathType path_type) +{ + return slope | (path_type << 6); +} + extern const PathSprites _path_up_from_edge[EDGE_COUNT]; extern const PathSprites _path_down_from_edge[EDGE_COUNT]; extern const uint8 _path_expand[];