summaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-28 15:31:04 +0000
committertron <tron@openttd.org>2005-01-28 15:31:04 +0000
commit3617d243189ec7076bec045d04e4a96ff55a8de8 (patch)
treeefbaeb3426c01178731116a7fca722dc190ac78f /map.c
parent4e6d6578e4e4d17712acff4b0c1f749f405a815d (diff)
downloadopenttd-3617d243189ec7076bec045d04e4a96ff55a8de8.tar.xz
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
These scale a number relative to the map size/circumference. Use them to scale the amount of map objects. Of course at the moment they return just the input, because there are no bigger/smaller maps yet.
Diffstat (limited to 'map.c')
-rw-r--r--map.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/map.c b/map.c
index 81a72b28b..6e9721b3b 100644
--- a/map.c
+++ b/map.c
@@ -54,6 +54,28 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
#endif
+uint ScaleByMapSize(uint n)
+{
+ int shift = (int)MapLogX() - 8 + (int)MapLogY() - 8;
+
+ if (shift < 0)
+ return (n + (1 << -shift) - 1) >> -shift;
+ else
+ return n << shift;
+}
+
+
+uint ScaleByMapSize1D(uint n)
+{
+ int shift = ((int)MapLogX() - 8 + (int)MapLogY() - 8) / 2;
+
+ if (shift < 0)
+ return (n + (1 << -shift) - 1) >> -shift;
+ else
+ return n << shift;
+}
+
+
const TileIndexDiffC _tileoffs_by_dir[] = {
{-1, 0},
{ 0, 1},