(svn r11663) -Codechange: moving of the road related types and functions.
authorrubidium
Tue, 18 Dec 2007 20:38:16 +0000
changeset 8598 14ae80fe4c8f
parent 8597 87f03bc9c8e4
child 8599 b609cdeeff3f
(svn r11663) -Codechange: moving of the road related types and functions.
src/cmd_helper.h
src/main_gui.cpp
src/player.h
src/road.cpp
src/road.h
src/road_cmd.cpp
src/road_func.h
src/road_gui.cpp
src/road_internal.h
src/road_map.h
src/road_type.h
src/station.h
src/station_cmd.cpp
src/town_cmd.cpp
src/track_func.h
src/tunnel_map.h
src/vehicle.h
src/window.h
--- a/src/cmd_helper.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/cmd_helper.h	Tue Dec 18 20:38:16 2007 +0000
@@ -5,7 +5,7 @@
 
 #include "direction_type.h"
 #include "macros.h"
-#include "road.h"
+#include "road_type.h"
 
 
 template<uint N> static inline void ExtractValid();
--- a/src/main_gui.cpp	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/main_gui.cpp	Tue Dec 18 20:38:16 2007 +0000
@@ -19,7 +19,6 @@
 #include "viewport.h"
 #include "gfx.h"
 #include "player.h"
-#include "road.h"
 #include "command.h"
 #include "news.h"
 #include "town.h"
--- a/src/player.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/player.h	Tue Dec 18 20:38:16 2007 +0000
@@ -8,7 +8,7 @@
 #include "oldpool.h"
 #include "aystar.h"
 #include "rail.h"
-#include "road.h"
+#include "road_func.h"
 #include "engine.h"
 #include "livery.h"
 #include "genworld.h"
--- a/src/road.cpp	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/road.cpp	Tue Dec 18 20:38:16 2007 +0000
@@ -4,8 +4,8 @@
 #include "openttd.h"
 #include "functions.h"
 #include "rail_map.h"
-#include "road.h"
 #include "road_map.h"
+#include "road_internal.h"
 #include "water_map.h"
 #include "macros.h"
 
--- a/src/road.h	Tue Dec 18 20:10:21 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/* $Id$ */
-
-/** @file road.h */
-
-#ifndef ROAD_H
-#define ROAD_H
-
-#include "helpers.hpp"
-
-/**
- * The different roadtypes we support
- *
- * @note currently only ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
- */
-enum RoadType {
-	ROADTYPE_ROAD = 0,      ///< Basic road type
-	ROADTYPE_TRAM = 1,      ///< Trams
-	ROADTYPE_HWAY = 2,      ///< Only a placeholder. Not sure what we are going to do with this road type.
-	ROADTYPE_END,           ///< Used for iterations
-	INVALID_ROADTYPE = 0xFF ///< flag for invalid roadtype
-};
-DECLARE_POSTFIX_INCREMENT(RoadType);
-
-/**
- * The different roadtypes we support, but then a bitmask of them
- * @note currently only roadtypes with ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
- */
-enum RoadTypes {
-	ROADTYPES_NONE     = 0,                                                 ///< No roadtypes
-	ROADTYPES_ROAD     = 1 << ROADTYPE_ROAD,                                ///< Road
-	ROADTYPES_TRAM     = 1 << ROADTYPE_TRAM,                                ///< Trams
-	ROADTYPES_HWAY     = 1 << ROADTYPE_HWAY,                                ///< Highway (or whatever substitute)
-	ROADTYPES_ROADTRAM = ROADTYPES_ROAD | ROADTYPES_TRAM,                   ///< Road + trams
-	ROADTYPES_ROADHWAY = ROADTYPES_ROAD | ROADTYPES_HWAY,                   ///< Road + highway (or whatever substitute)
-	ROADTYPES_TRAMHWAY = ROADTYPES_TRAM | ROADTYPES_HWAY,                   ///< Trams + highway (or whatever substitute)
-	ROADTYPES_ALL      = ROADTYPES_ROAD | ROADTYPES_TRAM | ROADTYPES_HWAY,  ///< Road + trams + highway (or whatever substitute)
-};
-DECLARE_ENUM_AS_BIT_SET(RoadTypes);
-
-/**
- * Whether the given roadtype is valid.
- * @param rt the roadtype to check for validness
- * @return true if and only if valid
- */
-static inline bool IsValidRoadType(RoadType rt)
-{
-	return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
-}
-
-/**
- * Are the given bits pointing to valid roadtypes?
- * @param rts the roadtypes to check for validness
- * @return true if and only if valid
- */
-static inline bool AreValidRoadTypes(RoadTypes rts)
-{
-	return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM);
-}
-
-/**
- * Maps a RoadType to the corresponding RoadTypes value
- *
- * @param rt the roadtype to get the roadtypes from
- * @return the roadtypes with the given roadtype
- */
-static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
-{
-	return (RoadTypes)(1 << rt);
-}
-
-/**
- * Returns the RoadTypes which are not present in the given RoadTypes
- *
- * This function returns the complement of a given RoadTypes.
- *
- * @param r The given RoadTypes
- * @return The complement of the given RoadTypes
- * @note The unused value ROADTYPES_HWAY will be used, too.
- */
-static inline RoadTypes ComplementRoadTypes(RoadTypes r)
-{
-	return (RoadTypes)(ROADTYPES_ALL ^ r);
-}
-
-/**
- * Enumeration for the road parts on a tile.
- *
- * This enumeration defines the possible road parts which
- * can be build on a tile.
- */
-enum RoadBits {
-	ROAD_NONE = 0U,                  ///< No road-part is build
-	ROAD_NW   = 1U,                  ///< North-west part
-	ROAD_SW   = 2U,                  ///< South-west part
-	ROAD_SE   = 4U,                  ///< South-east part
-	ROAD_NE   = 8U,                  ///< North-east part
-	ROAD_X    = ROAD_SW | ROAD_NE,   ///< Full road along the x-axis (south-west + north-east)
-	ROAD_Y    = ROAD_NW | ROAD_SE,   ///< Full road along the y-axis (north-west + south-east)
-	ROAD_ALL  = ROAD_X  | ROAD_Y     ///< Full 4-way crossing
-};
-
-DECLARE_ENUM_AS_BIT_SET(RoadBits);
-
-/**
- * Calculate the complement of a RoadBits value
- *
- * Simply flips all bits in the RoadBits value to get the complement
- * of the RoadBits.
- *
- * @param r The given RoadBits value
- * @return the complement
- */
-static inline RoadBits ComplementRoadBits(RoadBits r)
-{
-	return (RoadBits)(ROAD_ALL ^ r);
-}
-
-/**
- * Calculate the mirrored RoadBits
- *
- * Simply move the bits to their new position.
- *
- * @param r The given RoadBits value
- * @return the mirrored
- */
-static inline RoadBits MirrorRoadBits(RoadBits r)
-{
-	return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
-}
-
-/**
- * Calculate rotated RoadBits
- *
- * Move the Roadbits clockwise til they are in their final position.
- *
- * @param r The given RoadBits value
- * @param rot The given Rotation angle
- * @return the rotated
- */
-static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
-{
-	for (; rot > (DiagDirDiff)0; rot--){
-		r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
-	}
-	return r;
-}
-
-/**
- * Create the road-part which belongs to the given DiagDirection
- *
- * This function returns a RoadBits value which belongs to
- * the given DiagDirection.
- *
- * @param d The DiagDirection
- * @return The result RoadBits which the selected road-part set
- */
-static inline RoadBits DiagDirToRoadBits(DiagDirection d)
-{
-	return (RoadBits)(ROAD_NW << (3 ^ d));
-}
-
-/**
- * Return if the tile is a valid tile for a crossing.
- *
- * @note function is overloaded
- * @param tile the curent tile
- * @param ax the axis of the road over the rail
- * @return true if it is a valid tile
- */
-bool IsPossibleCrossing(const TileIndex tile, Axis ax);
-
-/**
- * Checks whether the trackdir means that we are reversing.
- * @param dir the trackdir to check
- * @return true if it is a reversing road trackdir
- */
-static inline bool IsReversingRoadTrackdir(Trackdir dir)
-{
-	return (dir & 0x07) >= 6;
-}
-
-/**
- * Checks whether the given trackdir is a straight road
- * @param dir the trackdir to check
- * @return true if it is a straight road trackdir
- */
-static inline bool IsStraightRoadTrackdir(Trackdir dir)
-{
-	return (dir & 0x06) == 0;
-}
-
-/**
- * Clean up unneccesary RoadBits of a planed tile.
- * @param tile current tile
- * @param org_rb planed RoadBits
- * @return optimised RoadBits
- */
-RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb);
-
-/**
- * Is it allowed to remove the given road bits from the given tile?
- * @param tile      the tile to remove the road from
- * @param remove    the roadbits that are going to be removed
- * @param owner     the actual owner of the roadbits of the tile
- * @param edge_road are the removed bits from a town?
- * @param rt        the road type to remove the bits from
- * @return true when it is allowed to remove the road bits
- */
-bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt);
-
-/**
- * Draw the catenary for tram road bits
- * @param ti   information about the tile (position, slope)
- * @param tram the roadbits to draw the catenary for
- */
-void DrawTramCatenary(TileInfo *ti, RoadBits tram);
-
-#endif /* ROAD_H */
--- a/src/road_cmd.cpp	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/road_cmd.cpp	Tue Dec 18 20:38:16 2007 +0000
@@ -9,6 +9,7 @@
 #include "cmd_helper.h"
 #include "rail_map.h"
 #include "road_map.h"
+#include "road_internal.h"
 #include "sprite.h"
 #include "table/sprites.h"
 #include "table/strings.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/road_func.h	Tue Dec 18 20:38:16 2007 +0000
@@ -0,0 +1,114 @@
+/* $Id$ */
+
+/** @file road_func.h Functions related to roads. */
+
+#ifndef ROAD_FUNC_H
+#define ROAD_FUNC_H
+
+#include "road_type.h"
+
+/**
+ * Whether the given roadtype is valid.
+ * @param rt the roadtype to check for validness
+ * @return true if and only if valid
+ */
+static inline bool IsValidRoadType(RoadType rt)
+{
+	return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
+}
+
+/**
+ * Are the given bits pointing to valid roadtypes?
+ * @param rts the roadtypes to check for validness
+ * @return true if and only if valid
+ */
+static inline bool AreValidRoadTypes(RoadTypes rts)
+{
+	return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM);
+}
+
+/**
+ * Maps a RoadType to the corresponding RoadTypes value
+ *
+ * @param rt the roadtype to get the roadtypes from
+ * @return the roadtypes with the given roadtype
+ */
+static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
+{
+	return (RoadTypes)(1 << rt);
+}
+
+/**
+ * Returns the RoadTypes which are not present in the given RoadTypes
+ *
+ * This function returns the complement of a given RoadTypes.
+ *
+ * @param r The given RoadTypes
+ * @return The complement of the given RoadTypes
+ * @note The unused value ROADTYPES_HWAY will be used, too.
+ */
+static inline RoadTypes ComplementRoadTypes(RoadTypes r)
+{
+	return (RoadTypes)(ROADTYPES_ALL ^ r);
+}
+
+
+/**
+ * Calculate the complement of a RoadBits value
+ *
+ * Simply flips all bits in the RoadBits value to get the complement
+ * of the RoadBits.
+ *
+ * @param r The given RoadBits value
+ * @return the complement
+ */
+static inline RoadBits ComplementRoadBits(RoadBits r)
+{
+	return (RoadBits)(ROAD_ALL ^ r);
+}
+
+/**
+ * Calculate the mirrored RoadBits
+ *
+ * Simply move the bits to their new position.
+ *
+ * @param r The given RoadBits value
+ * @return the mirrored
+ */
+static inline RoadBits MirrorRoadBits(RoadBits r)
+{
+	return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
+}
+
+/**
+ * Calculate rotated RoadBits
+ *
+ * Move the Roadbits clockwise til they are in their final position.
+ *
+ * @param r The given RoadBits value
+ * @param rot The given Rotation angle
+ * @return the rotated
+ */
+static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
+{
+	for (; rot > (DiagDirDiff)0; rot--){
+		r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
+	}
+	return r;
+}
+
+/**
+ * Create the road-part which belongs to the given DiagDirection
+ *
+ * This function returns a RoadBits value which belongs to
+ * the given DiagDirection.
+ *
+ * @param d The DiagDirection
+ * @return The result RoadBits which the selected road-part set
+ */
+static inline RoadBits DiagDirToRoadBits(DiagDirection d)
+{
+	return (RoadBits)(ROAD_NW << (3 ^ d));
+}
+
+#endif /* ROAD_FUNC_H */
--- a/src/road_gui.cpp	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/road_gui.cpp	Tue Dec 18 20:38:16 2007 +0000
@@ -17,7 +17,6 @@
 #include "sound.h"
 #include "command.h"
 #include "variables.h"
-#include "road.h"
 #include "road_cmd.h"
 #include "road_map.h"
 #include "station_map.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/road_internal.h	Tue Dec 18 20:38:16 2007 +0000
@@ -0,0 +1,34 @@
+/* $Id$ */
+
+/** @file road_internal.h Functions used internally by the roads. */
+
+#ifndef ROAD_INTERNAL_H
+#define ROAD_INTERNAL_H
+
+/**
+ * Clean up unneccesary RoadBits of a planed tile.
+ * @param tile current tile
+ * @param org_rb planed RoadBits
+ * @return optimised RoadBits
+ */
+RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb);
+
+/**
+ * Is it allowed to remove the given road bits from the given tile?
+ * @param tile      the tile to remove the road from
+ * @param remove    the roadbits that are going to be removed
+ * @param owner     the actual owner of the roadbits of the tile
+ * @param edge_road are the removed bits from a town?
+ * @param rt        the road type to remove the bits from
+ * @return true when it is allowed to remove the road bits
+ */
+bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt);
+
+/**
+ * Draw the catenary for tram road bits
+ * @param ti   information about the tile (position, slope)
+ * @param tram the roadbits to draw the catenary for
+ */
+void DrawTramCatenary(TileInfo *ti, RoadBits tram);
+
+#endif /* ROAD_INTERNAL_H */
--- a/src/road_map.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/road_map.h	Tue Dec 18 20:38:16 2007 +0000
@@ -8,7 +8,7 @@
 #include "macros.h"
 #include "track_func.h"
 #include "rail_type.h"
-#include "road.h"
+#include "road_func.h"
 #include "tile.h"
 
 
@@ -305,6 +305,16 @@
  */
 TrackBits GetAnyRoadTrackBits(TileIndex tile, RoadType rt);
 
+/**
+ * Return if the tile is a valid tile for a crossing.
+ *
+ * @note function is overloaded
+ * @param tile the curent tile
+ * @param ax the axis of the road over the rail
+ * @return true if it is a valid tile
+ */
+bool IsPossibleCrossing(const TileIndex tile, Axis ax);
+
 
 static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram, Owner hway)
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/road_type.h	Tue Dec 18 20:38:16 2007 +0000
@@ -0,0 +1,59 @@
+/* $Id$ */
+
+/** @file road.h Enums and other types related to roads. */
+
+#ifndef ROAD_TYPE_H
+#define ROAD_TYPE_H
+
+#include "core/enum_type.hpp"
+
+/**
+ * The different roadtypes we support
+ *
+ * @note currently only ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
+ */
+enum RoadType {
+	ROADTYPE_ROAD = 0,      ///< Basic road type
+	ROADTYPE_TRAM = 1,      ///< Trams
+	ROADTYPE_HWAY = 2,      ///< Only a placeholder. Not sure what we are going to do with this road type.
+	ROADTYPE_END,           ///< Used for iterations
+	INVALID_ROADTYPE = 0xFF ///< flag for invalid roadtype
+};
+DECLARE_POSTFIX_INCREMENT(RoadType);
+
+/**
+ * The different roadtypes we support, but then a bitmask of them
+ * @note currently only roadtypes with ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
+ */
+enum RoadTypes {
+	ROADTYPES_NONE     = 0,                                                 ///< No roadtypes
+	ROADTYPES_ROAD     = 1 << ROADTYPE_ROAD,                                ///< Road
+	ROADTYPES_TRAM     = 1 << ROADTYPE_TRAM,                                ///< Trams
+	ROADTYPES_HWAY     = 1 << ROADTYPE_HWAY,                                ///< Highway (or whatever substitute)
+	ROADTYPES_ROADTRAM = ROADTYPES_ROAD | ROADTYPES_TRAM,                   ///< Road + trams
+	ROADTYPES_ROADHWAY = ROADTYPES_ROAD | ROADTYPES_HWAY,                   ///< Road + highway (or whatever substitute)
+	ROADTYPES_TRAMHWAY = ROADTYPES_TRAM | ROADTYPES_HWAY,                   ///< Trams + highway (or whatever substitute)
+	ROADTYPES_ALL      = ROADTYPES_ROAD | ROADTYPES_TRAM | ROADTYPES_HWAY,  ///< Road + trams + highway (or whatever substitute)
+};
+DECLARE_ENUM_AS_BIT_SET(RoadTypes);
+
+
+/**
+ * Enumeration for the road parts on a tile.
+ *
+ * This enumeration defines the possible road parts which
+ * can be build on a tile.
+ */
+enum RoadBits {
+	ROAD_NONE = 0U,                  ///< No road-part is build
+	ROAD_NW   = 1U,                  ///< North-west part
+	ROAD_SW   = 2U,                  ///< South-west part
+	ROAD_SE   = 4U,                  ///< South-east part
+	ROAD_NE   = 8U,                  ///< North-east part
+	ROAD_X    = ROAD_SW | ROAD_NE,   ///< Full road along the x-axis (south-west + north-east)
+	ROAD_Y    = ROAD_NW | ROAD_SE,   ///< Full road along the y-axis (north-west + south-east)
+	ROAD_ALL  = ROAD_X  | ROAD_Y     ///< Full 4-way crossing
+};
+DECLARE_ENUM_AS_BIT_SET(RoadBits);
+
+#endif /* ROAD_TYPE_H */
--- a/src/station.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/station.h	Tue Dec 18 20:38:16 2007 +0000
@@ -10,7 +10,7 @@
 #include "oldpool.h"
 #include "sprite.h"
 #include "tile.h"
-#include "road.h"
+#include "road_type.h"
 #include "newgrf_station.h"
 #include "cargopacket.h"
 #include <list>
--- a/src/station_cmd.cpp	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/station_cmd.cpp	Tue Dec 18 20:38:16 2007 +0000
@@ -39,7 +39,8 @@
 #include "date.h"
 #include "helpers.hpp"
 #include "misc/autoptr.hpp"
-#include "road.h"
+#include "road_type.h"
+#include "road_internal.h" /* For drawing catenary/checking road removal */
 #include "cargotype.h"
 #include "strings.h"
 #include "autoslope.h"
--- a/src/town_cmd.cpp	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/town_cmd.cpp	Tue Dec 18 20:38:16 2007 +0000
@@ -8,6 +8,7 @@
 #include "debug.h"
 #include "strings.h"
 #include "road_map.h"
+#include "road_internal.h" /* Cleaning up road bits */
 #include "table/strings.h"
 #include "table/sprites.h"
 #include "map.h"
--- a/src/track_func.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/track_func.h	Tue Dec 18 20:38:16 2007 +0000
@@ -494,4 +494,24 @@
 	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
 }
 
+/**
+ * Checks whether the trackdir means that we are reversing.
+ * @param dir the trackdir to check
+ * @return true if it is a reversing road trackdir
+ */
+static inline bool IsReversingRoadTrackdir(Trackdir dir)
+{
+	return (dir & 0x07) >= 6;
+}
+
+/**
+ * Checks whether the given trackdir is a straight road
+ * @param dir the trackdir to check
+ * @return true if it is a straight road trackdir
+ */
+static inline bool IsStraightRoadTrackdir(Trackdir dir)
+{
+	return (dir & 0x06) == 0;
+}
+
 #endif /* RAIL_H */
--- a/src/tunnel_map.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/tunnel_map.h	Tue Dec 18 20:38:16 2007 +0000
@@ -8,8 +8,8 @@
 #include "direction_func.h"
 #include "macros.h"
 #include "map.h"
-#include "rail.h"
-#include "road.h"
+#include "rail_type.h"
+#include "road_type.h"
 
 
 /**
--- a/src/vehicle.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/vehicle.h	Tue Dec 18 20:38:16 2007 +0000
@@ -7,8 +7,9 @@
 
 #include "oldpool.h"
 #include "order.h"
-#include "rail.h"
-#include "road.h"
+#include "track_type.h"
+#include "rail_type.h"
+#include "road_type.h"
 #include "cargopacket.h"
 #include "texteff.hpp"
 
--- a/src/window.h	Tue Dec 18 20:10:21 2007 +0000
+++ b/src/window.h	Tue Dec 18 20:38:16 2007 +0000
@@ -8,8 +8,8 @@
 #include "macros.h"
 #include "string.h"
 #include "order.h"
-#include "rail.h"
-#include "road.h"
+#include "rail_type.h"
+#include "road_type.h"
 #include "airport.h"
 #include "vehicle.h"
 #include "viewport.h"