summaryrefslogtreecommitdiff
path: root/depot.h
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-07-16 23:47:37 +0000
committercelestar <celestar@openttd.org>2005-07-16 23:47:37 +0000
commit9ca761b06534ed191b0624a6c7049db296997a73 (patch)
treeb32b3e56573203f32982f2fc2b3966529a6d1857 /depot.h
parent64f6839816221873b9a5327fe038533a7d3b8a98 (diff)
downloadopenttd-9ca761b06534ed191b0624a6c7049db296997a73.tar.xz
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
(i.e. spans two height levels) and use it throughout the code. -Codechange: Add CanBuildDepotByTileh to find if a tile is suitable to build a depot on it. Wraps some bitmagic which seems quite unreadable at first glance
Diffstat (limited to 'depot.h')
-rw-r--r--depot.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/depot.h b/depot.h
index f60124a2c..a08fadb12 100644
--- a/depot.h
+++ b/depot.h
@@ -1,6 +1,9 @@
#ifndef DEPOT_H
#define DEPOT_H
+/** @file depot.h Header files for depots (not hangars)
+ * @see depot.c */
+
#include "pool.h"
#include "tile.h"
@@ -112,6 +115,28 @@ static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type
}
}
+/**
+ Find out if the slope of the tile is suitable to build a depot of given direction
+ @param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise
+ @param tileh The slope of the tile in question
+ @return true if the construction is possible
+
+
+ This is checked by the ugly 0x4C >> direction magic, which does the following:
+ 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
+ So: for direction (only the significant bits are shown)<p>
+ 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
+ 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
+ 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
+ 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
+ So ((0x4C >> p2) & tileh) determines whether the depot can be built on the current tileh
+*/
+static inline bool CanBuildDepotByTileh(uint32 direction, uint tileh)
+{
+ return (0x4C >> direction) & tileh;
+}
+
+
Depot *GetDepotByTile(TileIndex tile);
void InitializeDepot(void);
Depot *AllocateDepot(void);