Loading

10_add_path_litter_decora

  1. # HG changeset patch
  2. # Parent 1c0964d1d047cbae76eb84112815a8fa8fd7e740
  3.  
  4. diff --git a/src/map.h b/src/map.h
  5. --- a/src/map.h
  6. +++ b/src/map.h
  7. @@ -16,7 +16,6 @@
  8.  #include "path.h"
  9.  #include "geometry.h"
  10.  #include "sprite_store.h"
  11. -#include "bitmath.h"
  12.  
  13.  #include <map>
  14.  
  15. @@ -360,17 +359,6 @@ public:
  16.  };
  17.  
  18.  /**
  19. - * Does the instance data indicate a valid path (that is, a voxel with an actual path tile)?
  20. - * @param instance_data Instance data to examine.
  21. - * @return Whether the instance data indicates a valid path.
  22. - * @pre The instance must be #SRI_PATH
  23. - */
  24. -static inline bool HasValidPath(uint16 instance_data)
  25. -{
  26. -   return instance_data != PATH_INVALID;
  27. -}
  28. -
  29. -/**
  30.   * Does the given voxel contain a valid path?
  31.   * @param v %Voxel to examine.
  32.   * @return @c true if the voxel contains a valid path, else \c false.
  33. @@ -382,30 +370,6 @@ static inline bool HasValidPath(const Vo
  34.  }
  35.  
  36.  /**
  37. - * Extract the imploded path slope from the instance data.
  38. - * @param instance_data Instance data to examine.
  39. - * @return Imploded slope of the path.
  40. - * @pre instance data must be a valid path.
  41. - */
  42. -static inline PathSprites GetImplodedPathSlope(uint16 instance_data)
  43. -{
  44. -   return (PathSprites)GB(instance_data, 0, 6);
  45. -}
  46. -
  47. -/**
  48. - * Change the path slope in the path instance data.
  49. - * @param instance_data Previous instance data.
  50. - * @param slope New imploded path slope.
  51. - * @return New instance data of a path.
  52. - * @pre instance data must be a valid path.
  53. - */
  54. -static inline uint16 SetImplodedPathSlope(uint16 instance_data, uint8 slope)
  55. -{
  56. -   SB(instance_data, 0, 6, slope);
  57. -   return instance_data;
  58. -}
  59. -
  60. -/**
  61.   * Get the slope of the path (imploded value).
  62.   * @param v %Voxel to examine.
  63.   * @return Imploded slope of the path.
  64. @@ -420,28 +384,6 @@ static inline PathSprites GetImplodedPat
  65.     return ps;
  66.  }
  67.  
  68. -/**
  69. - * Get the path type from the path voxel instance data.
  70. - * @param instance_data Instance data to examine.
  71. - * @return Type of path.
  72. - * @pre instance data must be a valid path.
  73. - */
  74. -static inline PathType GetPathType(uint16 instance_data)
  75. -{
  76. -   return (PathType)GB(instance_data, 6, 2);
  77. -}
  78. -
  79. -/**
  80. - * Construct instance data for a valid path.
  81. - * @param slope Imploded slope of the path.
  82. - * @param path_type Type of the path.
  83. - * @return Instance data of a valid path.
  84. - */
  85. -static inline uint16 MakePathInstanceData(uint8 slope, PathType path_type)
  86. -{
  87. -   return slope | (path_type << 6);
  88. -}
  89. -
  90.  /** Possible ownerships of a tile. */
  91.  enum TileOwner {
  92.     OWN_NONE,     ///< Tile not owned by the park and not for sale.
  93. diff --git a/src/path.cpp b/src/path.cpp
  94. --- a/src/path.cpp
  95. +++ b/src/path.cpp
  96. @@ -240,6 +240,17 @@ uint8 GetPathExits(const Voxel *v)
  97.  }
  98.  
  99.  /**
  100. + * If the path instance data has decoration, would it be visible?
  101. + * @param instance_data Instance data to examine.
  102. + * @return Path decoration is or could be visible.
  103. + */
  104. +bool IsPathDecorationVisible(uint16 instance_data)
  105. +{
  106. +   uint8 exp_slope = _path_expand[GetImplodedPathSlope(instance_data)];
  107. +   return (exp_slope & PATHMASK_EDGES) != PATHMASK_EDGES;
  108. +}
  109. +
  110. +/**
  111.   * Walk over a queue path from the given entry edge at the given position.
  112.   * If it leads to a new voxel edge, the provided position and edge is update with the exit point.
  113.   * @param voxel_pos [inout] Start voxel position before the queue path, updated to last voxel position.
  114. diff --git a/src/path.h b/src/path.h
  115. --- a/src/path.h
  116. +++ b/src/path.h
  117. @@ -7,12 +7,23 @@
  118.   * 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 <http://www.gnu.org/licenses/>.
  119.   */
  120.  
  121. -/** @file path.h %Path definitions. */
  122. +/**
  123. + * @file path.h %Path definitions.
  124. + *
  125. + * Path instance data has the following structure:
  126. + * - bit 0..5 Imploded slope of the path. @see HasValidPath, GetImplodedPathSlope, SetImplodedPathSlope
  127. + * - bit 6..7 Path type. @see GetPathType
  128. + * - 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.
  129. + * - bit 12 Unused.
  130. + * - bit 13..14 Path decoration (litter bin, benches, or lamp posts. @see PathDecoration
  131. + * - bit 15 Path decoration has been demolished. Only valid if the decoration is visible to the user.
  132. + */
  133.  
  134.  #ifndef PATH_H
  135.  #define PATH_H
  136.  
  137.  #include "tile.h"
  138. +#include "bitmath.h"
  139.  
  140.  /**
  141.   * Available path sprites.
  142. @@ -118,6 +129,168 @@ enum PathStatus {
  143.     PAS_QUEUE_PATH,  ///< %Path to queue on.
  144.  };
  145.  
  146. +/** Path decoration. */
  147. +enum PathDecoration {
  148. +   PDEC_NONE,      ///< Path has no decoration.
  149. +   PDEC_LITTERBIN, ///< Path has litter bins.
  150. +   PDEC_BENCH,     ///< Path has benches.
  151. +   PDEC_LAMPPOST,  ///< Path has lamp posts.
  152. +};
  153. +
  154. +/**
  155. + * Does the instance data indicate a valid path (that is, a voxel with an actual path tile)?
  156. + * @param instance_data Instance data to examine.
  157. + * @return Whether the instance data indicates a valid path.
  158. + * @pre The instance must be #SRI_PATH
  159. + */
  160. +static inline bool HasValidPath(uint16 instance_data)
  161. +{
  162. +   return GB(instance_data, 0, 6) != PATH_INVALID;
  163. +}
  164. +
  165. +/**
  166. + * Extract the imploded path slope from the instance data.
  167. + * @param instance_data Instance data to examine.
  168. + * @return Imploded slope of the path.
  169. + * @pre instance data must be a valid path.
  170. + */
  171. +static inline PathSprites GetImplodedPathSlope(uint16 instance_data)
  172. +{
  173. +   return (PathSprites)GB(instance_data, 0, 6);
  174. +}
  175. +
  176. +/**
  177. + * Change the path slope in the path instance data.
  178. + * @param instance_data Previous instance data.
  179. + * @param slope New imploded path slope.
  180. + * @return New instance data of a path.
  181. + * @pre instance data must be a valid path.
  182. + */
  183. +static inline uint16 SetImplodedPathSlope(uint16 instance_data, uint8 slope)
  184. +{
  185. +   SB(instance_data, 0, 6, slope);
  186. +   return instance_data;
  187. +}
  188. +
  189. +/**
  190. + * Get the path type from the path voxel instance data.
  191. + * @param instance_data Instance data to examine.
  192. + * @return Type of path.
  193. + * @pre instance data must be a valid path.
  194. + */
  195. +static inline PathType GetPathType(uint16 instance_data)
  196. +{
  197. +   return (PathType)GB(instance_data, 6, 2);
  198. +}
  199. +
  200. +/**
  201. + * Get the decoration of path instance data.
  202. + * @param instance_data Instance data to examine.
  203. + * @return The decoration of the path.
  204. + * @pre instance data must be a valid path, decoration must be visible to the user.
  205. + */
  206. +static inline PathDecoration GetPathDecoration(uint16 instance_data)
  207. +{
  208. +   return (PathDecoration)GB(instance_data, 13, 2);
  209. +}
  210. +
  211. +/**
  212. + * Set the decoration of the path.
  213. + * @param instance_data Instance data to update.
  214. + * @param decoration Path decoration to set.
  215. + * @return Modified instance data.
  216. + * @pre instance data must be a valid path, decoration must be visible to the user.
  217. + */
  218. +static inline uint16 SetPathDecoration(uint16 instance_data, PathDecoration decoration)
  219. +{
  220. +   SB(instance_data, 13, 2, decoration);
  221. +   return instance_data;
  222. +}
  223. +
  224. +/**
  225. + * Get the 'demolished' bit of path instance data.
  226. + * @param instance_data Instance data to examine.
  227. + * @return The 'demolished' bit of the path.
  228. + * @pre instance data must be a valid path, decoration must be visible to the user.
  229. + */
  230. +static inline bool GetPathDemolished(uint16 instance_data)
  231. +{
  232. +   return GB(instance_data, 15, 1) != 0;
  233. +}
  234. +
  235. +/**
  236. + * Set the 'demolished' bit of path instance data.
  237. + * @param instance_data Instance data to update.
  238. + * @param demolished New state of the 'demolished' bit of the path.
  239. + * @return Modified instance data.
  240. + * @pre instance data must be a valid path, decoration must be visible to the user.
  241. + */
  242. +static inline uint16 SetPathDemolished(uint16 instance_data, bool demolished)
  243. +{
  244. +   SB(instance_data, 15, 1, demolished);
  245. +   return instance_data;
  246. +}
  247. +
  248. +bool IsPathDecorationVisible(uint16 instance_data);
  249. +
  250. +/**
  251. + * Is the path instance_data demolished, and is it visible to the user?
  252. + * @param instance_data Instance data to examine.
  253. + * @return Demolished state of the path, as observable by the user.
  254. + */
  255. +static inline bool GetVisiblePathDemolished(uint16 instance_data)
  256. +{
  257. +   if (!IsPathDecorationVisible(instance_data)) return false;
  258. +   return GetPathDemolished(instance_data);
  259. +}
  260. +
  261. +/**
  262. + * Get the litter data from the path instance data.
  263. + * @param instance_data Instance data to examine.
  264. + * @return Value of the litter data in the path.
  265. + */
  266. +static inline uint GetPathLitter(uint16 instance_data)
  267. +{
  268. +   return GB(instance_data, 8, 4);
  269. +}
  270. +
  271. +/**
  272. + * Set the litter data in the path instance data.
  273. + * @param instance_data Previous instance data.
  274. + * @param litter New value for the litter data.
  275. + * @return New instance data of a path.
  276. + */
  277. +static inline uint16 SetPathLitter(uint16 instance_data, uint litter)
  278. +{
  279. +   SB(instance_data, 8, 4, std::min(0xFu, litter));
  280. +   return instance_data;
  281. +}
  282. +
  283. +/**
  284. + * How much litter is visible to the user (on the path).
  285. + * @param instance_data Instance data to examine.
  286. + * @return Amount of visible litter on the path.
  287. + */
  288. +static inline uint GetVisiblePathLitter(uint16 instance_data)
  289. +{
  290. +   int litter = GetPathLitter(instance_data);
  291. +   if (GetPathDecoration(instance_data) == PDEC_LITTERBIN && !GetPathDemolished(instance_data)) {
  292. +       return std::max(0, litter - 12);
  293. +   }
  294. +   return std::min(3, litter);
  295. +}
  296. +
  297. +/**
  298. + * Construct instance data for a valid path without litter, path decorations, and not demolished.
  299. + * @param slope Imploded slope of the path.
  300. + * @param path_type Type of the path.
  301. + * @return Instance data of a valid path.
  302. + */
  303. +static inline uint16 MakePathInstanceData(uint8 slope, PathType path_type)
  304. +{
  305. +   return slope | (path_type << 6);
  306. +}
  307. +
  308.  extern const PathSprites _path_up_from_edge[EDGE_COUNT];
  309.  extern const PathSprites _path_down_from_edge[EDGE_COUNT];
  310.  extern const uint8 _path_expand[];

Comments