summaryrefslogtreecommitdiff
path: root/src/tunnelbridge_map.h
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2007-12-16 15:38:51 +0000
committersmatz <smatz@openttd.org>2007-12-16 15:38:51 +0000
commit3cee0abdbaf6c867ca71fec4700823f545556936 (patch)
tree3adebd2b8c9a10a6d993c67b0b5920b3598f2bce /src/tunnelbridge_map.h
parentec90ce7e98b29371b0fb139256065ac9991ca289 (diff)
downloadopenttd-3cee0abdbaf6c867ca71fec4700823f545556936.tar.xz
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
Diffstat (limited to 'src/tunnelbridge_map.h')
-rw-r--r--src/tunnelbridge_map.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/tunnelbridge_map.h b/src/tunnelbridge_map.h
new file mode 100644
index 000000000..dda1cc258
--- /dev/null
+++ b/src/tunnelbridge_map.h
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */
+
+#ifndef TUNNELBRIDGE_MAP_H
+#define TUNNELBRIDGE_MAP_H
+
+#include "direction.h" /* DiagDirection */
+#include "core/bitmath_func.hpp" /* GB, HasBit, SB */
+#include "map.h" /* Tile, TileIndex */
+#include "tile.h" /* TileType, IsTileType */
+#include "openttd.h" /* TransportType */
+
+
+/**
+ * Tunnel: Get the direction facing out of the tunnel
+ * Bridge: Get the direction pointing onto the bridge
+ * @param t The tile to analyze
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return the above mentionned direction
+ */
+static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return (DiagDirection)GB(_m[t].m5, 0, 2);
+}
+
+/**
+ * Tunnel: Get the transport type of the tunnel (road or rail)
+ * Bridge: Get the transport type of the bridge's ramp
+ * @param t The tile to analyze
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return the transport type in the tunnel/bridge
+ */
+static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return (TransportType)GB(_m[t].m5, 2, 2);
+}
+
+/**
+ * Tunnel: Is this tunnel entrance in a snowy or desert area?
+ * Bridge: Does the bridge ramp lie in a snow or desert area?
+ * @param t The tile to analyze
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return true if and only if the tile is in a snowy/desert area
+ */
+static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return HasBit(_m[t].m4, 7);
+}
+
+/**
+ * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
+ * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
+ * @param t the tunnel entrance / bridge ramp tile
+ * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
+ * not in snow and not in desert false
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ */
+static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ SB(_m[t].m4, 7, 1, snow_or_desert);
+}
+
+#endif /* TUNNELBRIDGE_MAP_H */