summaryrefslogtreecommitdiff
path: root/rail.h
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-07-29 21:36:02 +0000
committercelestar <celestar@openttd.org>2005-07-29 21:36:02 +0000
commit1736566e22687b7ed9cf6c641eefc6fccd5611d6 (patch)
tree3d9611ff23a8c68f99d623aedf85fe4c50d203ea /rail.h
parent3868b151a92adb6e64d7a80fd238f4ec622ebec9 (diff)
downloadopenttd-1736566e22687b7ed9cf6c641eefc6fccd5611d6.tar.xz
(svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
Diffstat (limited to 'rail.h')
-rw-r--r--rail.h43
1 files changed, 36 insertions, 7 deletions
diff --git a/rail.h b/rail.h
index 0c1505ad3..387fc3fb4 100644
--- a/rail.h
+++ b/rail.h
@@ -139,6 +139,30 @@ typedef enum SignalStates {
SIGNAL_STATE_GREEN = 1,
} SignalState;
+/** This struct contains all the info that is needed to draw and construct tracks.
+ */
+typedef struct RailtypeInfo {
+ struct {
+ SpriteID track_y; ///< single piece of rail in Y direction, with ground
+ SpriteID track_ns; ///< two pieces of rail in North and South corner (East-West direction)
+ SpriteID ground; ///< ground sprite for a 3-way switch
+ SpriteID single_y; ///< single piece of rail in Y direction, without ground
+ SpriteID single_x; ///< single piece of rail in X direction
+ SpriteID single_n; ///< single piece of rail in the northern corner
+ SpriteID single_s; ///< single piece of rail in the southern corner
+ SpriteID single_e; ///< single piece of rail in the eastern corner
+ SpriteID single_w; ///< single piece of rail in the western corner
+ } base_sprites;
+
+ /** sprite number difference between a piece of track on a snowy ground and the corresponding one on normal ground */
+ SpriteID snow_offset;
+
+ /** bitmask to the OTHER railtypes that can be used by an engine of THIS railtype */
+ byte compatible_railtypes;
+} RailtypeInfo;
+
+RailtypeInfo railtypes[RAILTYPE_END];
+
// these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
enum {
NUM_SSD_ENTRY = 256, // max amount of blocks
@@ -500,6 +524,17 @@ static inline TransportType GetCrossingTransportType(TileIndex tile, Track track
}
/**
+ * Returns a pointer to the Railtype information for a given railtype
+ * @param railtype the rail type which the information is requested for
+ * @return The pointer to the RailtypeInfo
+ */
+static inline RailtypeInfo *GetRailTypeInfo(RailType railtype)
+{
+ assert(railtype < RAILTYPE_END);
+ return &railtypes[railtype];
+}
+
+/**
* Checks if an engine of the given RailType can drive on a tile with a given
* RailType. This would normally just be an equality check, but for electric
* rails (which also support non-electric engines).
@@ -509,13 +544,7 @@ static inline TransportType GetCrossingTransportType(TileIndex tile, Track track
*/
static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
{
- static const bool EquivRailTypes[RAILTYPE_END][RAILTYPE_END] = {
- { true, false, false },
- { false, true, false },
- { false, false, true },
- };
-
- return EquivRailTypes[enginetype][tiletype];
+ return HASBIT(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
}
#endif // RAIL_H