rail.h
author miham
Wed, 05 Jul 2006 17:54:35 +0000
changeset 4118 bcc7a71ced09
parent 4077 d4d440dd8925
child 4158 91ff9bb84ced
permissions -rw-r--r--
(svn r5462) WebTranslator2 update to 2006-07-05 19:54:20
bulgarian - 218 fixed, 79 changed by quicksilverbg (20), kokobongo (203), groupsky (74)
french - 1 changed by glx (1)
italian - 14 changed by sidew (14)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
2232
2a0d0328ebbe (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
     3
/** @file rail.h */
2a0d0328ebbe (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
     4
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     5
#ifndef RAIL_H
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     6
#define RAIL_H
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     7
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents: 3132
diff changeset
     8
#include "direction.h"
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     9
#include "tile.h"
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    10
4041
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    11
typedef enum RailTypes {
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    12
	RAILTYPE_RAIL     = 0,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    13
	RAILTYPE_ELECTRIC = 1,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    14
	RAILTYPE_MONO     = 2,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    15
	RAILTYPE_MAGLEV   = 3,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    16
	RAILTYPE_END,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    17
	INVALID_RAILTYPE = 0xFF
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    18
} RailType;
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    19
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    20
typedef byte RailTypeMask;
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    21
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    22
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    23
/** These are used to specify a single track.
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    24
 * Can be translated to a trackbit with TrackToTrackbit */
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    25
typedef enum Track {
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    26
	TRACK_X     = 0,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    27
	TRACK_Y     = 1,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    28
	TRACK_UPPER = 2,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    29
	TRACK_LOWER = 3,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    30
	TRACK_LEFT  = 4,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    31
	TRACK_RIGHT = 5,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    32
	TRACK_END,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    33
	INVALID_TRACK = 0xFF
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    34
} Track;
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    35
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    36
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    37
/** Bitfield corresponding to Track */
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    38
typedef enum TrackBits {
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    39
	TRACK_BIT_NONE  = 0U,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    40
	TRACK_BIT_X     = 1U << TRACK_X,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    41
	TRACK_BIT_Y     = 1U << TRACK_Y,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    42
	TRACK_BIT_UPPER = 1U << TRACK_UPPER,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    43
	TRACK_BIT_LOWER = 1U << TRACK_LOWER,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    44
	TRACK_BIT_LEFT  = 1U << TRACK_LEFT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    45
	TRACK_BIT_RIGHT = 1U << TRACK_RIGHT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    46
	TRACK_BIT_CROSS = TRACK_BIT_X     | TRACK_BIT_Y,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    47
	TRACK_BIT_HORZ  = TRACK_BIT_UPPER | TRACK_BIT_LOWER,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    48
	TRACK_BIT_VERT  = TRACK_BIT_LEFT  | TRACK_BIT_RIGHT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    49
	TRACK_BIT_3WAY_NE = TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    50
	TRACK_BIT_3WAY_SE = TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    51
	TRACK_BIT_3WAY_SW = TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    52
	TRACK_BIT_3WAY_NW = TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    53
	TRACK_BIT_ALL   = TRACK_BIT_CROSS | TRACK_BIT_HORZ | TRACK_BIT_VERT,
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    54
	TRACK_BIT_MASK  = 0x3FU
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    55
} TrackBits;
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    56
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3900
diff changeset
    57
2232
2a0d0328ebbe (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    58
/** These are a combination of tracks and directions. Values are 0-5 in one
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    59
direction (corresponding to the Track enum) and 8-13 in the other direction. */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    60
typedef enum Trackdirs {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    61
	TRACKDIR_X_NE = 0,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    62
	TRACKDIR_Y_SE = 1,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    63
	TRACKDIR_UPPER_E  = 2,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    64
	TRACKDIR_LOWER_E  = 3,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    65
	TRACKDIR_LEFT_S   = 4,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    66
	TRACKDIR_RIGHT_S  = 5,
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    67
	/* Note the two missing values here. This enables trackdir -> track
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    68
	 * conversion by doing (trackdir & 7) */
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    69
	TRACKDIR_X_SW = 8,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    70
	TRACKDIR_Y_NW = 9,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    71
	TRACKDIR_UPPER_W  = 10,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    72
	TRACKDIR_LOWER_W  = 11,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    73
	TRACKDIR_LEFT_N   = 12,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    74
	TRACKDIR_RIGHT_N  = 13,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    75
	TRACKDIR_END,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    76
	INVALID_TRACKDIR  = 0xFF,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    77
} Trackdir;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    78
2232
2a0d0328ebbe (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    79
/** These are a combination of tracks and directions. Values are 0-5 in one
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    80
direction (corresponding to the Track enum) and 8-13 in the other direction. */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    81
typedef enum TrackdirBits {
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3890
diff changeset
    82
	TRACKDIR_BIT_NONE     = 0x0,
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    83
	TRACKDIR_BIT_X_NE     = 0x1,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    84
	TRACKDIR_BIT_Y_SE     = 0x2,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    85
	TRACKDIR_BIT_UPPER_E  = 0x4,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    86
	TRACKDIR_BIT_LOWER_E  = 0x8,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    87
	TRACKDIR_BIT_LEFT_S   = 0x10,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    88
	TRACKDIR_BIT_RIGHT_S  = 0x20,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    89
	/* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    90
	TRACKDIR_BIT_X_SW     = 0x0100,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    91
	TRACKDIR_BIT_Y_NW     = 0x0200,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    92
	TRACKDIR_BIT_UPPER_W  = 0x0400,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    93
	TRACKDIR_BIT_LOWER_W  = 0x0800,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    94
	TRACKDIR_BIT_LEFT_N   = 0x1000,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    95
	TRACKDIR_BIT_RIGHT_N  = 0x2000,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    96
	TRACKDIR_BIT_MASK			= 0x3F3F,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    97
	INVALID_TRACKDIR_BIT  = 0xFFFF,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    98
} TrackdirBits;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    99
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   100
/** This struct contains all the info that is needed to draw and construct tracks.
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   101
 */
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   102
typedef struct RailtypeInfo {
2274
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   103
	/** Struct containing the main sprites. @note not all sprites are listed, but only
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   104
	 *  the ones used directly in the code */
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   105
	struct {
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   106
		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   107
		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   108
		SpriteID ground;       ///< ground sprite for a 3-way switch
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   109
		SpriteID single_y;     ///< single piece of rail in Y direction, without ground
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   110
		SpriteID single_x;     ///< single piece of rail in X direction
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   111
		SpriteID single_n;     ///< single piece of rail in the northern corner
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   112
		SpriteID single_s;     ///< single piece of rail in the southern corner
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   113
		SpriteID single_e;     ///< single piece of rail in the eastern corner
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   114
		SpriteID single_w;     ///< single piece of rail in the western corner
2511
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2472
diff changeset
   115
		SpriteID crossing;     ///< level crossing, rail in X direction
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2472
diff changeset
   116
		SpriteID tunnel;       ///< tunnel sprites base
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   117
	} base_sprites;
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   118
2274
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   119
	/** struct containing the sprites for the rail GUI. @note only sprites referred to
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   120
	 * directly in the code are listed */
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   121
	struct {
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   122
		SpriteID build_ns_rail;      ///< button for building single rail in N-S direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   123
		SpriteID build_x_rail;       ///< button for building single rail in X direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   124
		SpriteID build_ew_rail;      ///< button for building single rail in E-W direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   125
		SpriteID build_y_rail;       ///< button for building single rail in Y direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   126
		SpriteID auto_rail;          ///< button for the autorail construction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   127
		SpriteID build_depot;        ///< button for building depots
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   128
		SpriteID build_tunnel;       ///< button for building a tunnel
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   129
		SpriteID convert_rail;       ///< button for converting rail
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   130
	} gui_sprites;
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   131
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   132
	struct {
2514
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   133
		CursorID rail_ns;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   134
		CursorID rail_swne;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   135
		CursorID rail_ew;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   136
		CursorID rail_nwse;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   137
		CursorID autorail;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   138
		CursorID depot;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   139
		CursorID tunnel;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   140
		CursorID convert;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   141
	} cursor;
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   142
859692ffa65a (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   143
	struct {
2274
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   144
		StringID toolbar_caption;
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   145
	} strings;
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   146
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   147
	/** sprite number difference between a piece of track on a snowy ground and the corresponding one on normal ground */
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   148
	SpriteID snow_offset;
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   149
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   150
	/** bitmask to the OTHER railtypes on which an engine of THIS railtype generates power */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   151
	RailTypeMask powered_railtypes;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   152
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   153
	/** bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   154
	RailTypeMask compatible_railtypes;
2254
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   155
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   156
	/**
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   157
	 * Offset between the current railtype and normal rail. This means that:<p>
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   158
	 * 1) All the sprites in a railset MUST be in the same order. This order
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   159
	 *    is determined by normal rail. Check sprites 1005 and following for this order<p>
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   160
	 * 2) The position where the railtype is loaded must always be the same, otherwise
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   161
	 *    the offset will fail.<p>
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   162
	 * @note: Something more flexible might be desirable in the future.
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   163
	 */
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   164
	SpriteID total_offset;
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   165
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   166
	/**
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   167
	 * Bridge offset
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   168
	 */
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   169
	SpriteID bridge_offset;
3503
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   170
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   171
	/**
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   172
	 * Offset to add to ground sprite when drawing custom waypoints / stations
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   173
	 */
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   174
	byte custom_ground_offset;
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   175
} RailtypeInfo;
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   176
3890
e04bc34bc50c (svn r4946) "Feature": Add a cheat that allows running electric engines on normal rail
celestar
parents: 3792
diff changeset
   177
extern RailtypeInfo _railtypes[RAILTYPE_END];
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   178
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   179
// these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   180
enum {
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   181
	NUM_SSD_ENTRY = 256, // max amount of blocks
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   182
	NUM_SSD_STACK = 32 ,// max amount of blocks to check recursively
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   183
};
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   184
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   185
/**
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   186
 * Maps a Trackdir to the corresponding TrackdirBits value
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   187
 */
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   188
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   189
2232
2a0d0328ebbe (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
   190
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   191
 * These functions check the validity of Tracks and Trackdirs. assert against
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   192
 * them when convenient.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   193
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   194
static inline bool IsValidTrack(Track track) { return track < TRACK_END; }
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   195
static inline bool IsValidTrackdir(Trackdir trackdir) { return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   196
2232
2a0d0328ebbe (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
   197
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   198
 * Functions to map tracks to the corresponding bits in the signal
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   199
 * presence/status bytes in the map. You should not use these directly, but
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   200
 * wrapper functions below instead. XXX: Which are these?
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   201
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   202
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   203
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   204
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   205
 * direction along with the trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   206
 */
1947
32308520a356 (svn r2453) * CodeChange: Declared the lookup arrays in rail.h as extern, so the linker will complain if they are not defined (ie when rail.c is not included).
matthijs
parents: 1944
diff changeset
   207
extern const byte _signal_along_trackdir[TRACKDIR_END];
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   208
static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_trackdir[trackdir];}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   209
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   210
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   211
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   212
 * direction against the trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   213
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   214
static inline byte SignalAgainstTrackdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   215
	extern const byte _signal_against_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   216
	return _signal_against_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   217
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   218
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   219
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   220
 * Maps a Track to the bits that store the status of the two signals that can
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   221
 * be present on the given track.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   222
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   223
static inline byte SignalOnTrack(Track track) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   224
	extern const byte _signal_on_track[TRACK_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   225
	return _signal_on_track[track];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   226
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   227
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   228
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   229
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   230
 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   231
 * TrackdirBits, Direction and DiagDirections.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   232
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   233
 * TODO: Add #unndefs or something similar to remove the arrays used below
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   234
 * from the global scope and expose direct uses of them.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   235
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   236
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   237
/**
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   238
 * Maps a trackdir to the reverse trackdir.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   239
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   240
static inline Trackdir ReverseTrackdir(Trackdir trackdir) {
3500
e087f21dca54 (svn r4351) Simplify ReverseTrackdir() to use a simple arithmetic operation instead of a table lookup
tron
parents: 3498
diff changeset
   241
	return (Trackdir)(trackdir ^ 8);
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   242
}
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   243
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   244
/**
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   245
 * Maps a Track to the corresponding TrackBits value
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   246
 */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   247
static inline TrackBits TrackToTrackBits(Track track) { return (TrackBits)(1 << track); }
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   248
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   249
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   250
 * Returns the Track that a given Trackdir represents
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   251
 */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   252
static inline Track TrackdirToTrack(Trackdir trackdir) { return (Track)(trackdir & 0x7); }
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   253
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   254
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   255
 * Returns a Trackdir for the given Track. Since every Track corresponds to
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   256
 * two Trackdirs, we choose the one which points between NE and S.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   257
 * Note that the actual implementation is quite futile, but this might change
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   258
 * in the future.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   259
 */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   260
static inline Trackdir TrackToTrackdir(Track track) { return (Trackdir)track; }
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   261
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   262
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   263
 * Returns a TrackdirBit mask that contains the two TrackdirBits that
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   264
 * correspond with the given Track (one for each direction).
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   265
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   266
static inline TrackdirBits TrackToTrackdirBits(Track track)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   267
{
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   268
	Trackdir td = TrackToTrackdir(track);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   269
	return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   270
}
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   271
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   272
/**
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   273
 * Discards all directional information from the given TrackdirBits. Any
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   274
 * Track which is present in either direction will be present in the result.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   275
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   276
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   277
{
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   278
	return (TrackBits)(bits | (bits >> 8));
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   279
}
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   280
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   281
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   282
 * Maps a trackdir to the trackdir that you will end up on if you go straight
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   283
 * ahead. This will be the same trackdir for diagonal trackdirs, but a
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   284
 * different (alternating) one for straight trackdirs
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   285
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   286
static inline Trackdir NextTrackdir(Trackdir trackdir)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   287
{
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   288
	extern const Trackdir _next_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   289
	return _next_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   290
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   291
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   292
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   293
 * Maps a track to all tracks that make 90 deg turns with it.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   294
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   295
static inline TrackBits TrackCrossesTracks(Track track)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   296
{
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   297
	extern const TrackBits _track_crosses_tracks[TRACK_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   298
	return _track_crosses_tracks[track];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   299
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   300
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   301
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   302
 * Maps a trackdir to the (4-way) direction the tile is exited when following
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   303
 * that trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   304
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   305
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   306
{
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   307
	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   308
	return _trackdir_to_exitdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   309
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   310
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   311
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   312
 * Maps a track and an (4-way) dir to the trackdir that represents the track
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   313
 * with the exit in the given direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   314
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   315
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   316
{
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   317
	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   318
	return _track_exitdir_to_trackdir[track][diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   319
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   320
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   321
/**
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   322
 * Maps a track and an (4-way) dir to the trackdir that represents the track
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   323
 * with the exit in the given direction.
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   324
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   325
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   326
{
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   327
	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   328
	return _track_enterdir_to_trackdir[track][diagdir];
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   329
}
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   330
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   331
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   332
 * Maps a track and a full (8-way) direction to the trackdir that represents
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   333
 * the track running in the given direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   334
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   335
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   336
{
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   337
	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   338
	return _track_direction_to_trackdir[track][dir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   339
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   340
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   341
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   342
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   343
 * direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   344
 */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   345
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   346
{
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   347
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   348
	return _dir_to_diag_trackdir[diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   349
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   350
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   351
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   352
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   353
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   354
 * Returns all trackdirs that can be reached when entering a tile from a given
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   355
 * (diagonal) direction. This will obviously include 90 degree turns, since no
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   356
 * information is available about the exact angle of entering */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   357
static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) { return _exitdir_reaches_trackdirs[diagdir]; }
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   358
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   359
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   360
 * Returns all tracks that can be reached when entering a tile from a given
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   361
 * (diagonal) direction. This will obviously include 90 degree turns, since no
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   362
 * information is available about the exact angle of entering */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   363
static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   364
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   365
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   366
 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   367
 * entering the next tile. This will include 90 degree turns!
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   368
 */
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   369
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   370
/* Note that there is no direct table for this function (there used to be),
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   371
 * but it uses two simpeler tables to achieve the result */
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   372
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   373
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   374
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   375
 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   376
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   377
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   378
	extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   379
	return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   380
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   381
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   382
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   383
/* Checks if a given Track is diagonal */
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
   384
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   385
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   386
/* Checks if a given Trackdir is diagonal. */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   387
static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); }
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   388
1967
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   389
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   390
/**
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   391
 * Returns a pointer to the Railtype information for a given railtype
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   392
 * @param railtype the rail type which the information is requested for
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   393
 * @return The pointer to the RailtypeInfo
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   394
 */
2236
34daee5dfc60 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   395
static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   396
{
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   397
	assert(railtype < RAILTYPE_END);
2236
34daee5dfc60 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   398
	return &_railtypes[railtype];
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   399
}
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   400
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   401
/**
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   402
 * Checks if an engine of the given RailType can drive on a tile with a given
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   403
 * RailType. This would normally just be an equality check, but for electric
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   404
 * rails (which also support non-electric engines).
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   405
 * @return Whether the engine can drive on this tile.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   406
 * @param  enginetype The RailType of the engine we are considering.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   407
 * @param  tiletype   The RailType of the tile we are considering.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   408
 */
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   409
static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   410
{
2233
ee31c1e1477c (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.
celestar
parents: 2232
diff changeset
   411
	return HASBIT(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   412
}
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   413
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   414
static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   415
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   416
	return HASBIT(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   417
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   418
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   419
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   420
 * Checks if the given tracks overlap, ie form a crossing. Basically this
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   421
 * means when there is more than one track on the tile, exept when there are
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   422
 * two parallel tracks.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   423
 * @param  bits The tracks present.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   424
 * @return Whether the tracks present overlap in any way.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   425
 */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   426
static inline bool TracksOverlap(TrackBits bits)
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   427
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   428
	/* With no, or only one track, there is no overlap */
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   429
	if (bits == 0 || KILL_FIRST_BIT(bits) == 0) return false;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   430
	/* We know that there are at least two tracks present. When there are more
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   431
	 * than 2 tracks, they will surely overlap. When there are two, they will
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   432
	 * always overlap unless they are lower & upper or right & left. */
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3253
diff changeset
   433
	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   434
}
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   435
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   436
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   437
void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   438
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   439
/**
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   440
 * Draws overhead wires and pylons for electric railways.
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   441
 * @param ti The TileInfo struct of the tile being drawn
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   442
 * @see DrawCatenaryRailway
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   443
 */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   444
void DrawCatenary(const TileInfo *ti);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   445
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   446
uint GetRailFoundation(Slope tileh, TrackBits bits);
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   447
#endif /* RAIL_H */