src/rail.h
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 6488 07bbbafd4f70
child 6719 4cc327ad39d5
equal deleted inserted replaced
9894:70d78ac95d6c 9895:7bd07f43b0e3
     7 
     7 
     8 #include "gfx.h"
     8 #include "gfx.h"
     9 #include "direction.h"
     9 #include "direction.h"
    10 #include "tile.h"
    10 #include "tile.h"
    11 
    11 
    12 typedef enum RailTypes {
    12 enum RailType {
    13 	RAILTYPE_BEGIN    = 0,
    13 	RAILTYPE_BEGIN    = 0,
    14 	RAILTYPE_RAIL     = 0,
    14 	RAILTYPE_RAIL     = 0,
    15 	RAILTYPE_ELECTRIC = 1,
    15 	RAILTYPE_ELECTRIC = 1,
    16 	RAILTYPE_MONO     = 2,
    16 	RAILTYPE_MONO     = 2,
    17 	RAILTYPE_MAGLEV   = 3,
    17 	RAILTYPE_MAGLEV   = 3,
    18 	RAILTYPE_END,
    18 	RAILTYPE_END,
    19 	INVALID_RAILTYPE  = 0xFF
    19 	INVALID_RAILTYPE  = 0xFF
    20 } RailType;
    20 };
    21 
    21 
    22 typedef byte RailTypeMask;
    22 typedef byte RailTypeMask;
    23 
    23 
    24 /** Allow incrementing of Track variables */
    24 /** Allow incrementing of Track variables */
    25 DECLARE_POSTFIX_INCREMENT(RailType);
    25 DECLARE_POSTFIX_INCREMENT(RailType);
    28 typedef TinyEnumT<RailType> RailTypeByte;
    28 typedef TinyEnumT<RailType> RailTypeByte;
    29 
    29 
    30 
    30 
    31 /** These are used to specify a single track.
    31 /** These are used to specify a single track.
    32  * Can be translated to a trackbit with TrackToTrackbit */
    32  * Can be translated to a trackbit with TrackToTrackbit */
    33 typedef enum Track {
    33 enum Track {
    34 	TRACK_BEGIN = 0,
    34 	TRACK_BEGIN = 0,
    35 	TRACK_X     = 0,
    35 	TRACK_X     = 0,
    36 	TRACK_Y     = 1,
    36 	TRACK_Y     = 1,
    37 	TRACK_UPPER = 2,
    37 	TRACK_UPPER = 2,
    38 	TRACK_LOWER = 3,
    38 	TRACK_LOWER = 3,
    39 	TRACK_LEFT  = 4,
    39 	TRACK_LEFT  = 4,
    40 	TRACK_RIGHT = 5,
    40 	TRACK_RIGHT = 5,
    41 	TRACK_END,
    41 	TRACK_END,
    42 	INVALID_TRACK = 0xFF
    42 	INVALID_TRACK = 0xFF
    43 } Track;
    43 };
    44 
    44 
    45 /** Allow incrementing of Track variables */
    45 /** Allow incrementing of Track variables */
    46 DECLARE_POSTFIX_INCREMENT(Track);
    46 DECLARE_POSTFIX_INCREMENT(Track);
    47 /** Define basic enum properties */
    47 /** Define basic enum properties */
    48 template <> struct EnumPropsT<Track> : MakeEnumPropsT<Track, byte, TRACK_BEGIN, TRACK_END, INVALID_TRACK> {};
    48 template <> struct EnumPropsT<Track> : MakeEnumPropsT<Track, byte, TRACK_BEGIN, TRACK_END, INVALID_TRACK> {};
    59 	return (Track)a;
    59 	return (Track)a;
    60 }
    60 }
    61 
    61 
    62 
    62 
    63 /** Bitfield corresponding to Track */
    63 /** Bitfield corresponding to Track */
    64 typedef enum TrackBits {
    64 enum TrackBits {
    65 	TRACK_BIT_NONE    = 0U,
    65 	TRACK_BIT_NONE    = 0U,
    66 	TRACK_BIT_X       = 1U << TRACK_X,
    66 	TRACK_BIT_X       = 1U << TRACK_X,
    67 	TRACK_BIT_Y       = 1U << TRACK_Y,
    67 	TRACK_BIT_Y       = 1U << TRACK_Y,
    68 	TRACK_BIT_UPPER   = 1U << TRACK_UPPER,
    68 	TRACK_BIT_UPPER   = 1U << TRACK_UPPER,
    69 	TRACK_BIT_LOWER   = 1U << TRACK_LOWER,
    69 	TRACK_BIT_LOWER   = 1U << TRACK_LOWER,
    79 	TRACK_BIT_ALL     = TRACK_BIT_CROSS | TRACK_BIT_HORZ  | TRACK_BIT_VERT,
    79 	TRACK_BIT_ALL     = TRACK_BIT_CROSS | TRACK_BIT_HORZ  | TRACK_BIT_VERT,
    80 	TRACK_BIT_MASK    = 0x3FU,
    80 	TRACK_BIT_MASK    = 0x3FU,
    81 	TRACK_BIT_WORMHOLE = 0x40U,
    81 	TRACK_BIT_WORMHOLE = 0x40U,
    82 	TRACK_BIT_DEPOT   = 0x80U,
    82 	TRACK_BIT_DEPOT   = 0x80U,
    83 	INVALID_TRACK_BIT = 0xFF
    83 	INVALID_TRACK_BIT = 0xFF
    84 } TrackBits;
    84 };
    85 
    85 
    86 /** Define basic enum properties */
    86 /** Define basic enum properties */
    87 template <> struct EnumPropsT<TrackBits> : MakeEnumPropsT<TrackBits, byte, TRACK_BIT_NONE, TRACK_BIT_ALL, INVALID_TRACK_BIT> {};
    87 template <> struct EnumPropsT<TrackBits> : MakeEnumPropsT<TrackBits, byte, TRACK_BIT_NONE, TRACK_BIT_ALL, INVALID_TRACK_BIT> {};
    88 typedef TinyEnumT<TrackBits> TrackBitsByte;
    88 typedef TinyEnumT<TrackBits> TrackBitsByte;
    89 
    89 
   108  * direction (corresponding to the Track enum) and 8-13 in the other direction.
   108  * direction (corresponding to the Track enum) and 8-13 in the other direction.
   109  * 6, 7, 14 and 15 are used to encode the reversing of road vehicles. Those
   109  * 6, 7, 14 and 15 are used to encode the reversing of road vehicles. Those
   110  * reversing track dirs are not considered to be 'valid' except in a small
   110  * reversing track dirs are not considered to be 'valid' except in a small
   111  * corner in the road vehicle controller.
   111  * corner in the road vehicle controller.
   112  */
   112  */
   113 typedef enum Trackdirs {
   113 enum Trackdir {
   114 	TRACKDIR_BEGIN    =  0,
   114 	TRACKDIR_BEGIN    =  0,
   115 	TRACKDIR_X_NE     =  0,
   115 	TRACKDIR_X_NE     =  0,
   116 	TRACKDIR_Y_SE     =  1,
   116 	TRACKDIR_Y_SE     =  1,
   117 	TRACKDIR_UPPER_E  =  2,
   117 	TRACKDIR_UPPER_E  =  2,
   118 	TRACKDIR_LOWER_E  =  3,
   118 	TRACKDIR_LOWER_E  =  3,
   128 	TRACKDIR_RIGHT_N  = 13,
   128 	TRACKDIR_RIGHT_N  = 13,
   129 	TRACKDIR_RVREV_SW = 14,
   129 	TRACKDIR_RVREV_SW = 14,
   130 	TRACKDIR_RVREV_NW = 15,
   130 	TRACKDIR_RVREV_NW = 15,
   131 	TRACKDIR_END,
   131 	TRACKDIR_END,
   132 	INVALID_TRACKDIR  = 0xFF,
   132 	INVALID_TRACKDIR  = 0xFF,
   133 } Trackdir;
   133 };
   134 
   134 
   135 /** Define basic enum properties */
   135 /** Define basic enum properties */
   136 template <> struct EnumPropsT<Trackdir> : MakeEnumPropsT<Trackdir, byte, TRACKDIR_BEGIN, TRACKDIR_END, INVALID_TRACKDIR> {};
   136 template <> struct EnumPropsT<Trackdir> : MakeEnumPropsT<Trackdir, byte, TRACKDIR_BEGIN, TRACKDIR_END, INVALID_TRACKDIR> {};
   137 typedef TinyEnumT<Trackdir> TrackdirByte;
   137 typedef TinyEnumT<Trackdir> TrackdirByte;
   138 
   138 
   139 /** These are a combination of tracks and directions. Values are 0-5 in one
   139 /** These are a combination of tracks and directions. Values are 0-5 in one
   140  * direction (corresponding to the Track enum) and 8-13 in the other direction. */
   140  * direction (corresponding to the Track enum) and 8-13 in the other direction. */
   141 typedef enum TrackdirBits {
   141 enum TrackdirBits {
   142 	TRACKDIR_BIT_NONE     = 0x0000,
   142 	TRACKDIR_BIT_NONE     = 0x0000,
   143 	TRACKDIR_BIT_X_NE     = 0x0001,
   143 	TRACKDIR_BIT_X_NE     = 0x0001,
   144 	TRACKDIR_BIT_Y_SE     = 0x0002,
   144 	TRACKDIR_BIT_Y_SE     = 0x0002,
   145 	TRACKDIR_BIT_UPPER_E  = 0x0004,
   145 	TRACKDIR_BIT_UPPER_E  = 0x0004,
   146 	TRACKDIR_BIT_LOWER_E  = 0x0008,
   146 	TRACKDIR_BIT_LOWER_E  = 0x0008,
   153 	TRACKDIR_BIT_LOWER_W  = 0x0800,
   153 	TRACKDIR_BIT_LOWER_W  = 0x0800,
   154 	TRACKDIR_BIT_LEFT_N   = 0x1000,
   154 	TRACKDIR_BIT_LEFT_N   = 0x1000,
   155 	TRACKDIR_BIT_RIGHT_N  = 0x2000,
   155 	TRACKDIR_BIT_RIGHT_N  = 0x2000,
   156 	TRACKDIR_BIT_MASK     = 0x3F3F,
   156 	TRACKDIR_BIT_MASK     = 0x3F3F,
   157 	INVALID_TRACKDIR_BIT  = 0xFFFF,
   157 	INVALID_TRACKDIR_BIT  = 0xFFFF,
   158 } TrackdirBits;
   158 };
   159 
   159 
   160 /** Define basic enum properties */
   160 /** Define basic enum properties */
   161 template <> struct EnumPropsT<TrackdirBits> : MakeEnumPropsT<TrackdirBits, uint16, TRACKDIR_BIT_NONE, TRACKDIR_BIT_MASK, INVALID_TRACKDIR_BIT> {};
   161 template <> struct EnumPropsT<TrackdirBits> : MakeEnumPropsT<TrackdirBits, uint16, TRACKDIR_BIT_NONE, TRACKDIR_BIT_MASK, INVALID_TRACKDIR_BIT> {};
   162 typedef TinyEnumT<TrackdirBits> TrackdirBitsShort;
   162 typedef TinyEnumT<TrackdirBits> TrackdirBitsShort;
   163 DECLARE_ENUM_AS_BIT_SET(TrackdirBits);
   163 DECLARE_ENUM_AS_BIT_SET(TrackdirBits);
   164 
   164 
   165 /** This struct contains all the info that is needed to draw and construct tracks.
   165 /** This struct contains all the info that is needed to draw and construct tracks.
   166  */
   166  */
   167 typedef struct RailtypeInfo {
   167 struct RailtypeInfo {
   168 	/** Struct containing the main sprites. @note not all sprites are listed, but only
   168 	/** Struct containing the main sprites. @note not all sprites are listed, but only
   169 	 *  the ones used directly in the code */
   169 	 *  the ones used directly in the code */
   170 	struct {
   170 	struct {
   171 		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
   171 		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
   172 		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
   172 		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
   235 
   235 
   236 	/**
   236 	/**
   237 	 * Offset to add to ground sprite when drawing custom waypoints / stations
   237 	 * Offset to add to ground sprite when drawing custom waypoints / stations
   238 	 */
   238 	 */
   239 	byte custom_ground_offset;
   239 	byte custom_ground_offset;
   240 } RailtypeInfo;
   240 };
   241 
   241 
   242 
   242 
   243 // these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
   243 // these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
   244 enum {
   244 enum {
   245 	NUM_SSD_ENTRY = 256, // max amount of blocks
   245 	NUM_SSD_ENTRY = 256, // max amount of blocks