(svn r5115) Move helper functions to where they belong 0.4
authortron
Mon, 05 Jun 2006 08:30:58 +0000
branch0.4
changeset 10032 fcf09abbde96
parent 10031 97ad14cf1b70
child 10033 cce7f27e214d
(svn r5115) Move helper functions to where they belong
bridge_map.h
direction.h
pathfind.c
rail_map.h
tunnel_map.h
tunnelbridge_cmd.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bridge_map.h	Mon Jun 05 08:30:58 2006 +0000
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+#ifndef BRIDGE_MAP_H
+#define BRIDGE_MAP_H
+
+#include "direction.h"
+#include "macros.h"
+#include "map.h"
+#include "rail.h"
+#include "tile.h"
+
+
+static inline bool IsBridge(TileIndex t)
+{
+	assert(IsTileType(t, MP_TUNNELBRIDGE));
+	return HASBIT(_m[t].m5, 7);
+}
+
+static inline bool IsBridgeTile(TileIndex t)
+{
+	return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
+}
+
+
+static inline bool IsBridgeRamp(TileIndex t)
+{
+	assert(IsBridgeTile(t));
+	return !HASBIT(_m[t].m5, 6);
+}
+
+static inline bool IsBridgeMiddle(TileIndex t)
+{
+	assert(IsBridgeTile(t));
+	return HASBIT(_m[t].m5, 6);
+}
+
+
+/**
+ * Get the direction pointing onto the bridge
+ */
+static inline DiagDirection GetBridgeRampDirection(TileIndex t)
+{
+	assert(IsBridgeRamp(t));
+	/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
+	 * bridges to a DiagDirection
+	 */
+	return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);
+}
+
+
+static inline Axis GetBridgeAxis(TileIndex t)
+{
+	assert(IsBridgeMiddle(t));
+	return (Axis)GB(_m[t].m5, 0, 1);
+}
+
+
+static inline bool IsTransportUnderBridge(TileIndex t)
+{
+	assert(IsBridgeMiddle(t));
+	return HASBIT(_m[t].m5, 5);
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/direction.h	Mon Jun 05 08:30:58 2006 +0000
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+#ifndef DIRECTION_H
+#define DIRECTION_H
+
+
+/* the 2 axis */
+typedef enum Axis {
+	AXIS_X = 0,
+	AXIS_Y = 1,
+	AXIS_END
+} Axis;
+
+
+static inline Axis DiagDirToAxis(uint d)
+{
+	return (Axis)(d & 1);
+}
+
+
+/*
+ * Converts an Axis to a DiagDirection
+ * Points always in the positive direction, i.e. S[EW]
+ */
+static inline uint AxisToDiagDir(Axis a)
+{
+	return (uint)(2 - a);
+}
+
+#endif
--- a/pathfind.c	Sun Jun 04 22:34:52 2006 +0000
+++ b/pathfind.c	Mon Jun 05 08:30:58 2006 +0000
@@ -2,10 +2,12 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "bridge_map.h"
 #include "functions.h"
 #include "map.h"
 #include "tile.h"
 #include "rail.h"
+#include "rail_map.h"
 #include "pathfind.h"
 #include "debug.h"
 #include "variables.h"
@@ -672,12 +674,6 @@
 	DIAG_FACTOR,DIAG_FACTOR,STR_FACTOR,STR_FACTOR,STR_FACTOR,STR_FACTOR,0,0
 };
 
-static inline bool IsBridgeMiddle(TileIndex t) {return HASBIT(_m[t].m5, 6);}
-static inline uint GetBridgeAxis(TileIndex t) {return GB(_m[t].m5, 0, 1);}
-static inline uint DiagDirToAxis(DiagDirection d) {return (d & 1);}
-static inline bool IsBridge(TileIndex t) {return HASBIT(_m[t].m5, 7);}
-static inline bool IsBridgeTile(TileIndex t) {return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);}
-static inline RailType GetRailTypeCrossing(TileIndex t) {return (RailType)GB(_m[t].m4, 0, 4);}
 
 // new more optimized pathfinder for trains...
 // Tile is the tile the train is at.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rail_map.h	Mon Jun 05 08:30:58 2006 +0000
@@ -0,0 +1,14 @@
+/* $Id$ */
+
+#ifndef RAIL_MAP_H
+#define RAIL_MAP_H
+
+#include "tile.h"
+
+// TODO remove this by moving to the same bits as GetRailType()
+static inline RailType GetRailTypeCrossing(TileIndex t)
+{
+	return (RailType)GB(_m[t].m4, 0, 4);
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tunnel_map.h	Mon Jun 05 08:30:58 2006 +0000
@@ -0,0 +1,23 @@
+/* $Id$ */
+
+#ifndef TUNNEL_MAP_H
+#define TUNNEL_MAP_H
+
+#include "macros.h"
+#include "map.h"
+
+
+static inline bool IsTunnel(TileIndex t)
+{
+	assert(IsTileType(t, MP_TUNNELBRIDGE));
+	return !HASBIT(_m[t].m5, 7);
+}
+
+
+static inline uint GetTunnelDirection(TileIndex t)
+{
+	assert(IsTunnelTile(t));
+	return (uint)GB(_m[t].m5, 0, 2);
+}
+
+#endif
--- a/tunnelbridge_cmd.c	Sun Jun 04 22:34:52 2006 +0000
+++ b/tunnelbridge_cmd.c	Mon Jun 05 08:30:58 2006 +0000
@@ -7,11 +7,13 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "bridge_map.h"
 #include "table/sprites.h"
 #include "table/strings.h"
 #include "functions.h"
 #include "map.h"
 #include "tile.h"
+#include "tunnel_map.h"
 #include "vehicle.h"
 #include "viewport.h"
 #include "command.h"
@@ -1200,13 +1202,6 @@
 	}
 }
 
-static inline bool IsTunnel(TileIndex t) {return !HASBIT(_m[t].m5, 7);}
-static inline uint DiagDirToAxis(DiagDirection d) {return (d & 1);}
-static inline DiagDirection GetTunnelDirection(TileIndex t) {return (DiagDirection)GB(_m[t].m5, 0, 2);}
-static inline bool IsBridgeRamp(TileIndex t) {return !HASBIT(_m[t].m5, 6);}
-static inline DiagDirection GetBridgeRampDirection(TileIndex t) {return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);}
-static inline bool IsTransportUnderBridge(TileIndex t) {return HASBIT(_m[t].m5, 5);}
-static inline uint GetBridgeAxis(TileIndex t) {return GB(_m[t].m5, 0, 1);}
 
 static uint GetSlopeZ_TunnelBridge(const TileInfo* ti)
 {