summaryrefslogtreecommitdiff
path: root/src/map_func.h
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-11-21 15:24:28 +0100
committerErich Eckner <git@eckner.net>2022-01-16 21:58:17 +0100
commit5d00438a858bb4a404d2b5d5c6f9d9fa9e58663f (patch)
tree6b94e2ceb69d1a9d8453f8553aa4139d0ee9b0f4 /src/map_func.h
parentb7fac710bafe0bb9173700c52d21343a42dae0db (diff)
downloadopenttd-5d00438a858bb4a404d2b5d5c6f9d9fa9e58663f.tar.xz
ScaleByMapSize should not scale by layerCount(), too - and we need to move some lines from layer_func.h to map_func.h to avoid cyclic includes
Diffstat (limited to 'src/map_func.h')
-rw-r--r--src/map_func.h60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/map_func.h b/src/map_func.h
index e8ab9036e..e00251243 100644
--- a/src/map_func.h
+++ b/src/map_func.h
@@ -114,6 +114,64 @@ static inline uint MapMaxY()
}
/**
+ * 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;
+}
+
+/**
* Scales the given value by the map size, where the given value is
* for a 256 by 256 map.
* @param n the value to scale
@@ -123,7 +181,7 @@ static inline uint ScaleByMapSize(uint n)
{
/* Subtract 12 from shift in order to prevent integer overflow
* for large values of n. It's safe since the min mapsize is 64x64. */
- return CeilDiv(n << (MapLogX() + MapLogY() - 12), 1 << 4);
+ return CeilDiv(n << (MapLogX() + MapLogY() - LayerCountLog() - 12), 1 << 4);
}