src/rail.h
author smatz
Sat, 08 Dec 2007 19:53:30 +0000
changeset 8539 0ba5701ab630
parent 8425 72a71d480c5f
child 8596 27646407e0bc
permissions -rw-r--r--
(svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
2232
0c63dce21e30 (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 */
0c63dce21e30 (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
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     5
#ifndef RAIL_H
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     6
#define RAIL_H
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     7
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5849
diff changeset
     8
#include "gfx.h"
3147
0a09ce6d651a (svn r3767) Move all direction related enums and functions to a separate header
tron
parents: 3132
diff changeset
     9
#include "direction.h"
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    10
#include "tile.h"
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
    11
#include "variables.h"
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    12
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    13
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    14
 * Enumeration for all possible railtypes.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    15
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    16
 * This enumeration defines all 4 possible railtypes.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    17
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
    18
enum RailType {
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    19
	RAILTYPE_BEGIN    = 0,          ///< Used for iterations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    20
	RAILTYPE_RAIL     = 0,          ///< Standard non-electric rails
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    21
	RAILTYPE_ELECTRIC = 1,          ///< Electric rails
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    22
	RAILTYPE_MONO     = 2,          ///< Monorail
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    23
	RAILTYPE_MAGLEV   = 3,          ///< Maglev
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    24
	RAILTYPE_END,                   ///< Used for iterations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    25
	INVALID_RAILTYPE  = 0xFF        ///< Flag for invalid railtype
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
    26
};
4041
caf4fcb4e05b (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
caf4fcb4e05b (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
typedef byte RailTypeMask;
caf4fcb4e05b (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
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    30
/** Allow incrementing of Track variables */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    31
DECLARE_POSTFIX_INCREMENT(RailType);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    32
/** Define basic enum properties */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    33
template <> struct EnumPropsT<RailType> : MakeEnumPropsT<RailType, byte, RAILTYPE_BEGIN, RAILTYPE_END, INVALID_RAILTYPE> {};
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    34
typedef TinyEnumT<RailType> RailTypeByte;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    35
4041
caf4fcb4e05b (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
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    37
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    38
 * These are used to specify a single track.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    39
 * Can be translated to a trackbit with TrackToTrackbit
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    40
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
    41
enum Track {
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    42
	TRACK_BEGIN = 0,        ///< Used for iterations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    43
	TRACK_X     = 0,        ///< Track along the x-axis (north-east to south-west)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    44
	TRACK_Y     = 1,        ///< Track along the y-axis (north-west to south-east)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    45
	TRACK_UPPER = 2,        ///< Track in the upper corner of the tile (north)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    46
	TRACK_LOWER = 3,        ///< Track in the lower corner of the tile (south)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    47
	TRACK_LEFT  = 4,        ///< Track in the left corner of the tile (west)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    48
	TRACK_RIGHT = 5,        ///< Track in the right corner of the tile (east)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    49
	TRACK_END,              ///< Used for iterations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    50
	INVALID_TRACK = 0xFF    ///< Flag for an invalid track
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
    51
};
4041
caf4fcb4e05b (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
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    53
/** Allow incrementing of Track variables */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    54
DECLARE_POSTFIX_INCREMENT(Track);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    55
/** Define basic enum properties */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    56
template <> struct EnumPropsT<Track> : MakeEnumPropsT<Track, byte, TRACK_BEGIN, TRACK_END, INVALID_TRACK> {};
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    57
typedef TinyEnumT<Track> TrackByte;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    58
4041
caf4fcb4e05b (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
    59
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    60
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    61
 * Convert an Axis to the corresponding Track
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    62
 * AXIS_X -> TRACK_X
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    63
 * AXIS_Y -> TRACK_Y
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    64
 * Uses the fact that they share the same internal encoding
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    65
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    66
 * @param a the axis to convert
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    67
 * @return the track corresponding to the axis
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    68
 */
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    69
static inline Track AxisToTrack(Axis a)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    70
{
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    71
	return (Track)a;
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    72
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    73
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    74
4041
caf4fcb4e05b (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
    75
/** Bitfield corresponding to Track */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
    76
enum TrackBits {
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    77
	TRACK_BIT_NONE    = 0U,                                                 ///< No track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    78
	TRACK_BIT_X       = 1U << TRACK_X,                                      ///< X-axis track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    79
	TRACK_BIT_Y       = 1U << TRACK_Y,                                      ///< Y-axis track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    80
	TRACK_BIT_UPPER   = 1U << TRACK_UPPER,                                  ///< Upper track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    81
	TRACK_BIT_LOWER   = 1U << TRACK_LOWER,                                  ///< Lower track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    82
	TRACK_BIT_LEFT    = 1U << TRACK_LEFT,                                   ///< Left track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    83
	TRACK_BIT_RIGHT   = 1U << TRACK_RIGHT,                                  ///< Right track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    84
	TRACK_BIT_CROSS   = TRACK_BIT_X     | TRACK_BIT_Y,                      ///< X-Y-axis cross
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    85
	TRACK_BIT_HORZ    = TRACK_BIT_UPPER | TRACK_BIT_LOWER,                  ///< Upper and lower track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    86
	TRACK_BIT_VERT    = TRACK_BIT_LEFT  | TRACK_BIT_RIGHT,                  ///< Left and right track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    87
	TRACK_BIT_3WAY_NE = TRACK_BIT_X     | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,///< "Arrow" to the north-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    88
	TRACK_BIT_3WAY_SE = TRACK_BIT_Y     | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,///< "Arrow" to the south-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    89
	TRACK_BIT_3WAY_SW = TRACK_BIT_X     | TRACK_BIT_LOWER | TRACK_BIT_LEFT, ///< "Arrow" to the south-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    90
	TRACK_BIT_3WAY_NW = TRACK_BIT_Y     | TRACK_BIT_UPPER | TRACK_BIT_LEFT, ///< "Arrow" to the north-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    91
	TRACK_BIT_ALL     = TRACK_BIT_CROSS | TRACK_BIT_HORZ  | TRACK_BIT_VERT, ///< All possible tracks
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    92
	TRACK_BIT_MASK    = 0x3FU,                                              ///< Bitmask for the first 6 bits
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    93
	TRACK_BIT_WORMHOLE = 0x40U,                                             ///< Bitflag for a wormhole (used for tunnels)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    94
	TRACK_BIT_DEPOT   = 0x80U,                                              ///< Bitflag for a depot
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    95
	INVALID_TRACK_BIT = 0xFF                                                ///< Flag for an invalid trackbits value
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
    96
};
4041
caf4fcb4e05b (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
    97
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    98
/** Define basic enum properties */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    99
template <> struct EnumPropsT<TrackBits> : MakeEnumPropsT<TrackBits, byte, TRACK_BIT_NONE, TRACK_BIT_ALL, INVALID_TRACK_BIT> {};
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   100
typedef TinyEnumT<TrackBits> TrackBitsByte;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   101
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   102
DECLARE_ENUM_AS_BIT_SET(TrackBits);
4041
caf4fcb4e05b (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
   103
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   104
/**
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   105
 * Maps a Track to the corresponding TrackBits value
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   106
 * @param track the track to convert
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   107
 * @return the converted TrackBits value of the track
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   108
 */
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   109
static inline TrackBits TrackToTrackBits(Track track)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   110
{
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   111
	return (TrackBits)(1 << track);
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   112
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   113
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   114
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   115
 * Maps an Axis to the corresponding TrackBits value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   116
 * @param a the axis to convert
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   117
 * @return the converted TrackBits value of the axis
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   118
 */
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   119
static inline TrackBits AxisToTrackBits(Axis a)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   120
{
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   121
	return TrackToTrackBits(AxisToTrack(a));
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   122
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   123
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   124
/**
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   125
 * Returns a single horizontal/vertical trackbit, that is in a specific tile corner.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   126
 *
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   127
 * @param corner The corner of a tile.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   128
 * @return The TrackBits of the track in the corner.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   129
 */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   130
static inline TrackBits CornerToTrackBits(Corner corner)
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   131
{
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   132
	extern const TrackBits _corner_to_trackbits[];
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   133
	assert(IsValidCorner(corner));
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   134
	return _corner_to_trackbits[corner];
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   135
}
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
   136
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   137
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   138
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   139
 * Enumeration for tracks and directions.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   140
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   141
 * These are a combination of tracks and directions. Values are 0-5 in one
6325
f03f94f4d8fc (svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents: 6319
diff changeset
   142
 * direction (corresponding to the Track enum) and 8-13 in the other direction.
f03f94f4d8fc (svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents: 6319
diff changeset
   143
 * 6, 7, 14 and 15 are used to encode the reversing of road vehicles. Those
f03f94f4d8fc (svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents: 6319
diff changeset
   144
 * reversing track dirs are not considered to be 'valid' except in a small
f03f94f4d8fc (svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents: 6319
diff changeset
   145
 * corner in the road vehicle controller.
f03f94f4d8fc (svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents: 6319
diff changeset
   146
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
   147
enum Trackdir {
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   148
	TRACKDIR_BEGIN    =  0,         ///< Used for iterations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   149
	TRACKDIR_X_NE     =  0,         ///< X-axis and direction to north-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   150
	TRACKDIR_Y_SE     =  1,         ///< Y-axis and direction to south-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   151
	TRACKDIR_UPPER_E  =  2,         ///< Upper track and direction to east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   152
	TRACKDIR_LOWER_E  =  3,         ///< Lower track and direction to east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   153
	TRACKDIR_LEFT_S   =  4,         ///< Left track and direction to south
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   154
	TRACKDIR_RIGHT_S  =  5,         ///< Right track and direction to south
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   155
	TRACKDIR_RVREV_NE =  6,         ///< (Road vehicle) reverse direction north-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   156
	TRACKDIR_RVREV_SE =  7,         ///< (Road vehicle) reverse direction south-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   157
	TRACKDIR_X_SW     =  8,         ///< X-axis and direction to south-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   158
	TRACKDIR_Y_NW     =  9,         ///< Y-axis and direction to north-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   159
	TRACKDIR_UPPER_W  = 10,         ///< Upper track and direction to west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   160
	TRACKDIR_LOWER_W  = 11,         ///< Lower track and direction to west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   161
	TRACKDIR_LEFT_N   = 12,         ///< Left track and direction to north
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   162
	TRACKDIR_RIGHT_N  = 13,         ///< Right track and direction to north
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   163
	TRACKDIR_RVREV_SW = 14,         ///< (Road vehicle) reverse direction south-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   164
	TRACKDIR_RVREV_NW = 15,         ///< (Road vehicle) reverse direction north-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   165
	TRACKDIR_END,                   ///< Used for iterations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   166
	INVALID_TRACKDIR  = 0xFF,       ///< Flag for an invalid trackdir
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
   167
};
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   168
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   169
/** Define basic enum properties */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   170
template <> struct EnumPropsT<Trackdir> : MakeEnumPropsT<Trackdir, byte, TRACKDIR_BEGIN, TRACKDIR_END, INVALID_TRACKDIR> {};
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   171
typedef TinyEnumT<Trackdir> TrackdirByte;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   172
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   173
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   174
 * Enumeration of bitmasks for the TrackDirs
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   175
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   176
 * These are a combination of tracks and directions. Values are 0-5 in one
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   177
 * direction (corresponding to the Track enum) and 8-13 in the other direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   178
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
   179
enum TrackdirBits {
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   180
	TRACKDIR_BIT_NONE     = 0x0000, ///< No track build
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   181
	TRACKDIR_BIT_X_NE     = 0x0001, ///< Track x-axis, direction north-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   182
	TRACKDIR_BIT_Y_SE     = 0x0002, ///< Track y-axis, direction south-east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   183
	TRACKDIR_BIT_UPPER_E  = 0x0004, ///< Track upper, direction east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   184
	TRACKDIR_BIT_LOWER_E  = 0x0008, ///< Track lower, direction east
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   185
	TRACKDIR_BIT_LEFT_S   = 0x0010, ///< Track left, direction south
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   186
	TRACKDIR_BIT_RIGHT_S  = 0x0020, ///< Track right, direction south
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   187
	/* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   188
	TRACKDIR_BIT_X_SW     = 0x0100, ///< Track x-axis, direction south-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   189
	TRACKDIR_BIT_Y_NW     = 0x0200, ///< Track y-axis, direction north-west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   190
	TRACKDIR_BIT_UPPER_W  = 0x0400, ///< Track upper, direction west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   191
	TRACKDIR_BIT_LOWER_W  = 0x0800, ///< Track lower, direction west
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   192
	TRACKDIR_BIT_LEFT_N   = 0x1000, ///< Track left, direction north
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   193
	TRACKDIR_BIT_RIGHT_N  = 0x2000, ///< Track right, direction north
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   194
	TRACKDIR_BIT_MASK     = 0x3F3F, ///< Bitmask for bit-operations
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   195
	INVALID_TRACKDIR_BIT  = 0xFFFF, ///< Flag for an invalid trackdirbit value
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
   196
};
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   197
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   198
/** Define basic enum properties */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   199
template <> struct EnumPropsT<TrackdirBits> : MakeEnumPropsT<TrackdirBits, uint16, TRACKDIR_BIT_NONE, TRACKDIR_BIT_MASK, INVALID_TRACKDIR_BIT> {};
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   200
typedef TinyEnumT<TrackdirBits> TrackdirBitsShort;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   201
DECLARE_ENUM_AS_BIT_SET(TrackdirBits);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   202
2233
146e2e405ec1 (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
   203
/** This struct contains all the info that is needed to draw and construct tracks.
146e2e405ec1 (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
   204
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
   205
struct RailtypeInfo {
2274
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   206
	/** Struct containing the main sprites. @note not all sprites are listed, but only
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   207
	 *  the ones used directly in the code */
2233
146e2e405ec1 (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
   208
	struct {
146e2e405ec1 (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
   209
		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
146e2e405ec1 (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
   210
		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
146e2e405ec1 (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
   211
		SpriteID ground;       ///< ground sprite for a 3-way switch
146e2e405ec1 (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
   212
		SpriteID single_y;     ///< single piece of rail in Y direction, without ground
146e2e405ec1 (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
   213
		SpriteID single_x;     ///< single piece of rail in X direction
146e2e405ec1 (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
   214
		SpriteID single_n;     ///< single piece of rail in the northern corner
146e2e405ec1 (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
   215
		SpriteID single_s;     ///< single piece of rail in the southern corner
146e2e405ec1 (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
   216
		SpriteID single_e;     ///< single piece of rail in the eastern corner
146e2e405ec1 (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
   217
		SpriteID single_w;     ///< single piece of rail in the western corner
2511
0a81d9ca79bc (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
   218
		SpriteID crossing;     ///< level crossing, rail in X direction
0a81d9ca79bc (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
   219
		SpriteID tunnel;       ///< tunnel sprites base
2233
146e2e405ec1 (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
   220
	} base_sprites;
146e2e405ec1 (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
   221
2274
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   222
	/** struct containing the sprites for the rail GUI. @note only sprites referred to
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   223
	 * directly in the code are listed */
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   224
	struct {
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   225
		SpriteID build_ns_rail;      ///< button for building single rail in N-S direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   226
		SpriteID build_x_rail;       ///< button for building single rail in X direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   227
		SpriteID build_ew_rail;      ///< button for building single rail in E-W direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   228
		SpriteID build_y_rail;       ///< button for building single rail in Y direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   229
		SpriteID auto_rail;          ///< button for the autorail construction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   230
		SpriteID build_depot;        ///< button for building depots
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   231
		SpriteID build_tunnel;       ///< button for building a tunnel
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   232
		SpriteID convert_rail;       ///< button for converting rail
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   233
	} gui_sprites;
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   234
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   235
	struct {
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   236
		CursorID rail_ns;    ///< Cursor for building rail in N-S direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   237
		CursorID rail_swne;  ///< Cursor for building rail in X direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   238
		CursorID rail_ew;    ///< Cursor for building rail in E-W direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   239
		CursorID rail_nwse;  ///< Cursor for building rail in Y direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   240
		CursorID autorail;   ///< Cursor for autorail tool
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   241
		CursorID depot;      ///< Cursor for building a depot
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   242
		CursorID tunnel;     ///< Cursor for building a tunnel
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   243
		CursorID convert;    ///< Cursor for converting track
2514
8887b1f005c7 (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
   244
	} cursor;
8887b1f005c7 (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
   245
8887b1f005c7 (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
   246
	struct {
2274
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   247
		StringID toolbar_caption;
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   248
	} strings;
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   249
2233
146e2e405ec1 (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
   250
	/** sprite number difference between a piece of track on a snowy ground and the corresponding one on normal ground */
146e2e405ec1 (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
   251
	SpriteID snow_offset;
146e2e405ec1 (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
   252
3355
a653b8e47f27 (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
   253
	/** bitmask to the OTHER railtypes on which an engine of THIS railtype generates power */
a653b8e47f27 (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
   254
	RailTypeMask powered_railtypes;
a653b8e47f27 (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
   255
a653b8e47f27 (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
   256
	/** bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel */
a653b8e47f27 (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
   257
	RailTypeMask compatible_railtypes;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   258
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   259
	/**
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   260
	 * Offset between the current railtype and normal rail. This means that:<p>
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   261
	 * 1) All the sprites in a railset MUST be in the same order. This order
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   262
	 *    is determined by normal rail. Check sprites 1005 and following for this order<p>
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   263
	 * 2) The position where the railtype is loaded must always be the same, otherwise
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   264
	 *    the offset will fail.
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   265
	 * @note: Something more flexible might be desirable in the future.
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   266
	 */
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   267
	SpriteID total_offset;
2536
8c4e298f4886 (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
   268
8c4e298f4886 (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
   269
	/**
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   270
	 * Bridge offset
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   271
	 */
2536
8c4e298f4886 (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
   272
	SpriteID bridge_offset;
3503
425903b204fa (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
   273
425903b204fa (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
   274
	/**
425903b204fa (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
   275
	 * Offset to add to ground sprite when drawing custom waypoints / stations
425903b204fa (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
   276
	 */
425903b204fa (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
   277
	byte custom_ground_offset;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6488
diff changeset
   278
};
2233
146e2e405ec1 (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
   279
146e2e405ec1 (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
   280
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   281
/** these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block */
2008
c9d6585c96c8 (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
   282
enum {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   283
	NUM_SSD_ENTRY = 256, ///< max amount of blocks
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   284
	NUM_SSD_STACK =  32, ///< max amount of blocks to check recursively
2008
c9d6585c96c8 (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
   285
};
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   286
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   287
/**
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   288
 * Maps a Trackdir to the corresponding TrackdirBits value
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   289
 * @param trackdir the track direction to convert
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   290
 * @return the converted TrackdirBits value
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   291
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   292
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   293
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   294
	return (TrackdirBits)(1 << trackdir);
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   295
}
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   296
2232
0c63dce21e30 (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
   297
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   298
 * Removes first Track from TrackBits and returns it
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   299
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   300
 * This function searchs for the first bit in the TrackBits,
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   301
 * remove this bit from the parameter and returns the found
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   302
 * bit as Track value. It returns INVALID_TRACK if the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   303
 * parameter was TRACK_BIT_NONE or INVALID_TRACK_BIT. This
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   304
 * is basically used in while-loops to get up to 6 possible
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   305
 * tracks on a tile until the parameter becomes TRACK_BIT_NONE.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   306
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   307
 * @param tracks The value with the TrackBits
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   308
 * @return The first Track from the TrackBits value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   309
 * @see FindFirstTrack
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   310
 */
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   311
static inline Track RemoveFirstTrack(TrackBits *tracks)
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   312
{
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   313
	if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) {
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   314
		Track first = (Track)FIND_FIRST_BIT(*tracks);
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   315
		ClrBit(*tracks, first);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   316
		return first;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   317
	}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   318
	return INVALID_TRACK;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   319
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   320
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   321
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   322
 * Removes first Trackdir from TrackdirBits and returns it
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   323
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   324
 * This function searchs for the first bit in the TrackdirBits parameter,
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   325
 * remove this bit from the parameter and returns the fnound bit as
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   326
 * Trackdir value. It returns INVALID_TRACKDIR if the trackdirs is
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   327
 * TRACKDIR_BIT_NONE or INVALID_TRACKDIR_BIT. This is basically used in a
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   328
 * while-loop to get all track-directions step by step until the value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   329
 * reaches TRACKDIR_BIT_NONE.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   330
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   331
 * @param trackdirs The value with the TrackdirBits
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   332
 * @return The first Trackdir from the TrackdirBits value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   333
 * @see FindFirstTrackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   334
 */
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   335
static inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   336
{
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   337
	if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) {
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   338
		Trackdir first = (Trackdir)FindFirstBit2x64(*trackdirs);
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   339
		ClrBit(*trackdirs, first);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   340
		return first;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   341
	}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   342
	return INVALID_TRACKDIR;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   343
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   344
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   345
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   346
 * Returns first Track from TrackBits or INVALID_TRACK
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   347
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   348
 * This function returns the first Track found in the TrackBits value as Track-value.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   349
 * It returns INVALID_TRACK if the parameter is TRACK_BIT_NONE or INVALID_TRACK_BIT.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   350
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   351
 * @param tracks The TrackBits value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   352
 * @return The first Track found or INVALID_TRACK
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   353
 * @see RemoveFirstTrack
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   354
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   355
static inline Track FindFirstTrack(TrackBits tracks)
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   356
{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   357
	return (tracks != TRACK_BIT_NONE && tracks != INVALID_TRACK_BIT) ? (Track)FIND_FIRST_BIT(tracks) : INVALID_TRACK;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   358
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   359
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   360
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   361
 * Converts TrackBits to Track.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   362
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   363
 * This function converts a TrackBits value to a Track value. As it
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   364
 * is not possible to convert two or more tracks to one track the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   365
 * parameter must contain only one track or be the INVALID_TRACK_BIT value.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   366
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   367
 * @param tracks The TrackBits value to convert
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   368
 * @return The Track from the value or INVALID_TRACK
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   369
 * @pre tracks must contains only one Track or be INVALID_TRACK_BIT
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   370
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   371
static inline Track TrackBitsToTrack(TrackBits tracks)
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   372
{
8329
77e50bd6ad67 (svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents: 8267
diff changeset
   373
	assert(tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KillFirstBit(tracks & TRACK_BIT_MASK) == TRACK_BIT_NONE));
7651
71d525fb971e (svn r10429) -Fix: VC8 Code Analyzer warning: buffer overrun
KUDr
parents: 6916
diff changeset
   374
	return tracks != INVALID_TRACK_BIT ? (Track)FIND_FIRST_BIT(tracks & TRACK_BIT_MASK) : INVALID_TRACK;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   375
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   376
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   377
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   378
 * Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   379
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   380
 * This function returns the first Trackdir in the given TrackdirBits value or
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   381
 * INVALID_TRACKDIR if the value is TRACKDIR_BIT_NONE. The TrackdirBits must
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   382
 * not be INVALID_TRACKDIR_BIT.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   383
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   384
 * @param trackdirs The TrackdirBits value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   385
 * @return The first Trackdir from the TrackdirBits or INVALID_TRACKDIR on TRACKDIR_BIT_NONE.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   386
 * @pre trackdirs must not be INVALID_TRACKDIR_BIT
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   387
 * @see RemoveFirstTrackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   388
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   389
static inline Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   390
{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   391
	assert((trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   392
	return (trackdirs != TRACKDIR_BIT_NONE) ? (Trackdir)FindFirstBit2x64(trackdirs) : INVALID_TRACKDIR;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   393
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   394
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   395
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   396
 * Checks if a Track is valid.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   397
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   398
 * @param track The value to check
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   399
 * @return true if the given value is a valid track.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   400
 * @note Use this in an assert()
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   401
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   402
static inline bool IsValidTrack(Track track)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   403
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   404
	return track < TRACK_END;
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   405
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   406
2232
0c63dce21e30 (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
   407
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   408
 * Checks if a Trackdir is valid.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   409
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   410
 * @param trackdir The value to check
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   411
 * @return true if the given valie is a valid Trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   412
 * @note Use this in an assert()
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   413
 */
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   414
static inline bool IsValidTrackdir(Trackdir trackdir)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   415
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   416
	return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0;
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   417
}
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   418
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   419
/*
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   420
 * Functions to map tracks to the corresponding bits in the signal
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   421
 * presence/status bytes in the map. You should not use these directly, but
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   422
 * wrapper functions below instead. XXX: Which are these?
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   423
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   424
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   425
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   426
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   427
 * direction along with the trackdir.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   428
 */
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   429
static inline byte SignalAlongTrackdir(Trackdir trackdir)
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   430
{
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   431
	extern const byte _signal_along_trackdir[TRACKDIR_END];
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   432
	return _signal_along_trackdir[trackdir];
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   433
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   434
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   435
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   436
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   437
 * direction against the trackdir.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   438
 */
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   439
static inline byte SignalAgainstTrackdir(Trackdir trackdir)
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   440
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   441
	extern const byte _signal_against_trackdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   442
	return _signal_against_trackdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   443
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   444
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   445
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   446
 * Maps a Track to the bits that store the status of the two signals that can
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   447
 * be present on the given track.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   448
 */
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   449
static inline byte SignalOnTrack(Track track)
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   450
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   451
	extern const byte _signal_on_track[TRACK_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   452
	return _signal_on_track[track];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   453
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   454
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   455
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   456
/*
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   457
 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   458
 * TrackdirBits, Direction and DiagDirections.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   459
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   460
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   461
/**
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   462
 * Maps a trackdir to the reverse trackdir.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   463
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   464
 * Returns the reverse trackdir of a Trackdir value. The reverse trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   465
 * is the same track with the other direction on it.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   466
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   467
 * @param trackdir The Trackdir value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   468
 * @return The reverse trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   469
 * @pre trackdir must not be INVALID_TRACKDIR
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   470
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   471
static inline Trackdir ReverseTrackdir(Trackdir trackdir)
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   472
{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   473
	assert(trackdir != INVALID_TRACKDIR);
3500
70b8e368e43c (svn r4351) Simplify ReverseTrackdir() to use a simple arithmetic operation instead of a table lookup
tron
parents: 3498
diff changeset
   474
	return (Trackdir)(trackdir ^ 8);
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   475
}
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   476
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   477
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   478
 * Returns the Track that a given Trackdir represents
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   479
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   480
 * This function filters the Track which is used in the Trackdir value and
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   481
 * returns it as a Track value.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   482
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   483
 * @param trackdir The trackdir value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   484
 * @return The Track which is used in the value
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   485
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   486
static inline Track TrackdirToTrack(Trackdir trackdir)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   487
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   488
	return (Track)(trackdir & 0x7);
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   489
}
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   490
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   491
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   492
 * Returns a Trackdir for the given Track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   493
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   494
 * Since every Track corresponds to two Trackdirs, we choose the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   495
 * one which points between NE and S. Note that the actual
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   496
 * implementation is quite futile, but this might change
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   497
 * in the future.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   498
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   499
 * @param track The given Track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   500
 * @return The Trackdir from the given Track
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   501
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   502
static inline Trackdir TrackToTrackdir(Track track)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   503
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   504
	return (Trackdir)track;
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   505
}
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   506
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   507
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   508
 * Returns a TrackdirBit mask from a given Track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   509
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   510
 * The TrackdirBit mask contains the two TrackdirBits that
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   511
 * correspond with the given Track (one for each direction).
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   512
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   513
 * @param track The track to get the TrackdirBits from
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   514
 * @return The TrackdirBits which the selected tracks
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   515
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   516
static inline TrackdirBits TrackToTrackdirBits(Track track)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   517
{
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   518
	Trackdir td = TrackToTrackdir(track);
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   519
	return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   520
}
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   521
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   522
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   523
 * Discards all directional information from a TrackdirBits value
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   524
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   525
 * Any Track which is present in either direction will be present in the result.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   526
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   527
 * @param bits The TrackdirBits to get the TrackBits from
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   528
 * @return The TrackBits
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   529
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   530
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   531
{
4281
55f66f81239d (svn r5911) -Fix [FS#215]: Discard upper bits of TrackdirBitsToTrackBits result.
matthijs
parents: 4158
diff changeset
   532
	return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   533
}
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   534
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   535
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   536
 * Maps a trackdir to the trackdir that you will end up on if you go straight
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   537
 * ahead.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   538
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   539
 * This will be the same trackdir for diagonal trackdirs, but a
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   540
 * different (alternating) one for straight trackdirs
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   541
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   542
 * @param trackdir The given trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   543
 * @return The next Trackdir value of the next tile.
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   544
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   545
static inline Trackdir NextTrackdir(Trackdir trackdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   546
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   547
	extern const Trackdir _next_trackdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   548
	return _next_trackdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   549
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   550
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   551
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   552
 * Maps a track to all tracks that make 90 deg turns with it.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   553
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   554
 * For the diagonal directions these are the complement of the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   555
 * direction, for the straight directions these are the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   556
 * two vertical or horizontal tracks, depend on the given direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   557
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   558
 * @param track The given track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   559
 * @return The TrackBits with the tracks marked which cross the given track by 90 deg.
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   560
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   561
static inline TrackBits TrackCrossesTracks(Track track)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   562
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   563
	extern const TrackBits _track_crosses_tracks[TRACK_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   564
	return _track_crosses_tracks[track];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   565
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   566
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   567
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   568
 * Maps a trackdir to the (4-way) direction the tile is exited when following
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   569
 * that trackdir.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   570
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   571
 * For the diagonal directions these are the same directions. For
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   572
 * the straight directions these are the directions from the imagined
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   573
 * base-tile to the bordering tile which will be joined if the given
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   574
 * straight direction is leaved from the base-tile.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   575
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   576
 * @param trackdir The given track direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   577
 * @return The direction which points to the resulting tile if following the Trackdir
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   578
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   579
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   580
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   581
	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   582
	return _trackdir_to_exitdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   583
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   584
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   585
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   586
 * Maps a track and an (4-way) dir to the trackdir that represents the track
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   587
 * with the exit in the given direction.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   588
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   589
 * For the diagonal tracks the resulting track direction are clear for a given
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   590
 * DiagDirection. It either matches the direction or it returns INVALID_TRACKDIR,
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   591
 * as a TRACK_X cannot be applied with DIAG_SE.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   592
 * For the straight tracks the resulting track direction will be the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   593
 * direction which the DiagDirection is pointing. But this will be INVALID_TRACKDIR
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   594
 * if the DiagDirection is pointing 'away' the track.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   595
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   596
 * @param track The track to applie an direction on
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   597
 * @param diagdir The DiagDirection to applie on
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   598
 * @return The resulting track direction or INVALID_TRACKDIR if not possible.
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   599
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   600
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   601
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   602
	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   603
	return _track_exitdir_to_trackdir[track][diagdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   604
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   605
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   606
/**
2008
c9d6585c96c8 (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
   607
 * Maps a track and an (4-way) dir to the trackdir that represents the track
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   608
 * with the entry in the given direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   609
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   610
 * For the diagonal tracks the return value is clear, its either the matching
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   611
 * track direction or INVALID_TRACKDIR.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   612
 * For the straight tracks this returns the track direction which results if
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   613
 * you follow the DiagDirection and then turn by 45 deg left or right on the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   614
 * next tile. The new direction on the new track will be the returning Trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   615
 * value. If the parameters makes no sense like the track TRACK_UPPER and the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   616
 * diraction DIAGDIR_NE (target track cannot be reached) this function returns
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   617
 * INVALID_TRACKDIR.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   618
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   619
 * @param track The target track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   620
 * @param diagdir The direction to "come from"
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   621
 * @return the resulting Trackdir or INVALID_TRACKDIR if not possible.
2008
c9d6585c96c8 (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
   622
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   623
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   624
{
2008
c9d6585c96c8 (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
   625
	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
c9d6585c96c8 (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
   626
	return _track_enterdir_to_trackdir[track][diagdir];
c9d6585c96c8 (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
   627
}
c9d6585c96c8 (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
   628
c9d6585c96c8 (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
   629
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   630
 * Maps a track and a full (8-way) direction to the trackdir that represents
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   631
 * the track running in the given direction.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   632
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   633
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   634
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   635
	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   636
	return _track_direction_to_trackdir[track][dir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   637
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   638
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   639
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   640
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   641
 * direction.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   642
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   643
 * @param diagdir The direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   644
 * @return The resulting Trackdir direction
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   645
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   646
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   647
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   648
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   649
	return _dir_to_diag_trackdir[diagdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   650
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   651
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   652
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   653
 * Returns all trackdirs that can be reached when entering a tile from a given
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   654
 * (diagonal) direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   655
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   656
 * This will obviously include 90 degree turns, since no information is available
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   657
 * about the exact angle of entering
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   658
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   659
 * @param diagdir The joining direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   660
 * @return The TrackdirBits which can be used from the given direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   661
 * @see DiagdirReachesTracks
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   662
 */
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   663
static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   664
{
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   665
	extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   666
	return _exitdir_reaches_trackdirs[diagdir];
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   667
}
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   668
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   669
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   670
 * Returns all tracks that can be reached when entering a tile from a given
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   671
 * (diagonal) direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   672
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   673
 * This will obviously include 90 degree turns, since no
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   674
 * information is available about the exact angle of entering
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   675
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   676
 * @param diagdir The joining irection
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   677
 * @return The tracks which can be used
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   678
 * @see DiagdirReachesTrackdirs
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   679
 */
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   680
static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   681
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   682
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   683
 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   684
 * entering the next tile.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   685
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   686
 * This will include 90 degree turns!
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   687
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   688
 * @param trackdir The track direction which will be leaved
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   689
 * @return The track directions which can be used from this direction (in the next tile)
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   690
 */
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   691
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   692
{
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   693
	extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   694
	return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)];
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   695
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   696
/* Note that there is no direct table for this function (there used to be),
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   697
 * but it uses two simpeler tables to achieve the result */
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   698
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   699
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   700
 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   701
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   702
 * For the diagonal tracks this returns the track direction bits
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   703
 * of the other axis in both directions, which cannot be joined by
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   704
 * the given track direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   705
 * For the straight tracks this returns all possible 90 deg turns
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   706
 * either on the current tile (which no train can joined) or on the
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   707
 * bordering tiles.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   708
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   709
 * @param trackdir The track direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   710
 * @return The TrackdirBits which are (more or less) 90 deg turns.
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   711
 */
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   712
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   713
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   714
	extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   715
	return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   716
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   717
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   718
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   719
 * Checks if a given Track is diagonal
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   720
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   721
 * @param track The given track to check
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   722
 * @return true if diagonal, else false
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   723
 */
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   724
static inline bool IsDiagonalTrack(Track track)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   725
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   726
	return (track == TRACK_X) || (track == TRACK_Y);
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   727
}
2008
c9d6585c96c8 (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
   728
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   729
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   730
 * Checks if a given Trackdir is diagonal.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   731
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   732
 * @param trackdir The given trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   733
 * @return true if the trackdir use a diagonal track
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   734
 */
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   735
static inline bool IsDiagonalTrackdir(Trackdir trackdir)
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   736
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   737
	return IsDiagonalTrack(TrackdirToTrack(trackdir));
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   738
}
1967
c57192f4c121 (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
   739
c57192f4c121 (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
   740
/**
2233
146e2e405ec1 (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
   741
 * Returns a pointer to the Railtype information for a given railtype
146e2e405ec1 (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
   742
 * @param railtype the rail type which the information is requested for
146e2e405ec1 (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
   743
 * @return The pointer to the RailtypeInfo
146e2e405ec1 (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
   744
 */
2236
55f4d7353f52 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   745
static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
2233
146e2e405ec1 (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
   746
{
6488
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   747
	extern RailtypeInfo _railtypes[RAILTYPE_END];
2233
146e2e405ec1 (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
   748
	assert(railtype < RAILTYPE_END);
2236
55f4d7353f52 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   749
	return &_railtypes[railtype];
2233
146e2e405ec1 (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
   750
}
146e2e405ec1 (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
   751
146e2e405ec1 (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
   752
/**
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   753
 * Checks if an engine of the given RailType can drive on a tile with a given
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   754
 * RailType. This would normally just be an equality check, but for electric
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   755
 * rails (which also support non-electric engines).
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   756
 * @return Whether the engine can drive on this tile.
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   757
 * @param  enginetype The RailType of the engine we are considering.
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   758
 * @param  tiletype   The RailType of the tile we are considering.
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   759
 */
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   760
static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   761
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8329
diff changeset
   762
	return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   763
}
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   764
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   765
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   766
 * Checks if an engine of the given RailType got power on a tile with a given
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   767
 * RailType. This would normally just be an equality check, but for electric
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   768
 * rails (which also support non-electric engines).
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   769
 * @return Whether the engine got power on this tile.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   770
 * @param  enginetype The RailType of the engine we are considering.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   771
 * @param  tiletype   The RailType of the tile we are considering.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   772
 */
3355
a653b8e47f27 (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
   773
static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
a653b8e47f27 (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
   774
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8329
diff changeset
   775
	return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
3355
a653b8e47f27 (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
   776
}
a653b8e47f27 (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
   777
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   778
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   779
 * Checks if the given tracks overlap, ie form a crossing. Basically this
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   780
 * means when there is more than one track on the tile, exept when there are
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   781
 * two parallel tracks.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   782
 * @param  bits The tracks present.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   783
 * @return Whether the tracks present overlap in any way.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   784
 */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   785
static inline bool TracksOverlap(TrackBits bits)
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   786
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   787
	/* With no, or only one track, there is no overlap */
8329
77e50bd6ad67 (svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents: 8267
diff changeset
   788
	if (bits == TRACK_BIT_NONE || KillFirstBit(bits) == TRACK_BIT_NONE) return false;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   789
	/* We know that there are at least two tracks present. When there are more
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   790
	 * than 2 tracks, they will surely overlap. When there are two, they will
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   791
	 * always overlap unless they are lower & upper or right & left. */
3258
94a915e7485f (svn r3946) Add short hand names for common track combinations
tron
parents: 3253
diff changeset
   792
	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   793
}
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   794
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   795
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   796
extern int _railtype_cost_multiplier[RAILTYPE_END];
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   797
extern const int _default_railtype_cost_multiplier[RAILTYPE_END];
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   798
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   799
/**
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   800
 * Returns the cost of building the specified railtype.
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   801
 * @param railtype The railtype being built.
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   802
 * @return The cost multiplier.
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   803
 */
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   804
static inline Money RailBuildCost(RailType railtype)
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   805
{
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   806
	assert(railtype < RAILTYPE_END);
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   807
	return (_price.build_rail * _railtype_cost_multiplier[railtype]) >> 3;
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   808
}
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8199
diff changeset
   809
8539
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   810
/**
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   811
 * Calculates the cost of rail conversion
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   812
 * @param from The railtype we are converting from
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   813
 * @param to   The railtype we are converting to
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   814
 * @return Cost per TrackBit
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   815
 */
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   816
static inline Money RailConvertCost(RailType from, RailType to)
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   817
{
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   818
	/* rail -> el. rail
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   819
	 * calculate the price as 5 / 4 of (cost build el. rail) - (cost build rail)
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   820
	 * (the price of workers to get to place is that 1/4)
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   821
	 */
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   822
	if (HasPowerOnRail(from, to)) {
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   823
		return ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   824
	}
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   825
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   826
	/* el. rail -> rail
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   827
	 * calculate the price as 1 / 4 of (cost build el. rail) - (cost build rail)
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   828
	 * (the price of workers is 1 / 4 + price of copper sold to a recycle center)
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   829
	 */
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   830
	if (HasPowerOnRail(to, from)) {
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   831
		return (RailBuildCost(from) - RailBuildCost(to)) >> 2;
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   832
	}
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   833
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   834
	/* make the price the same as remove + build new type */
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   835
	return RailBuildCost(to) + _price.remove_rail;
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   836
}
0ba5701ab630 (svn r11603) -Fix [FS#1481]: make price for railtype conversion more realistic
smatz
parents: 8425
diff changeset
   837
8035
a0200ced6d9f (svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
rubidium
parents: 7892
diff changeset
   838
void *UpdateTrainPowerProc(Vehicle *v, void *data);
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   839
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   840
void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
3355
a653b8e47f27 (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
   841
a653b8e47f27 (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
   842
/**
a653b8e47f27 (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
   843
 * Draws overhead wires and pylons for electric railways.
a653b8e47f27 (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
   844
 * @param ti The TileInfo struct of the tile being drawn
a653b8e47f27 (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
   845
 * @see DrawCatenaryRailway
a653b8e47f27 (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
   846
 */
a653b8e47f27 (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
   847
void DrawCatenary(const TileInfo *ti);
8097
68eefbb4ff46 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 8035
diff changeset
   848
void DrawCatenaryOnTunnel(const TileInfo *ti);
3355
a653b8e47f27 (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
   849
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7651
diff changeset
   850
Foundation GetRailFoundation(Slope tileh, TrackBits bits);
5116
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4549
diff changeset
   851
8267
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8226
diff changeset
   852
void FloodHalftile(TileIndex t);
c600379bd333 (svn r11320) -Codechange: make lower halftiles at coast floodable. Patch by frosch.
rubidium
parents: 8226
diff changeset
   853
5116
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4549
diff changeset
   854
int32 SettingsDisableElrail(int32 p1); ///< _patches.disable_elrail callback
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 4549
diff changeset
   855
2536
8c4e298f4886 (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
   856
#endif /* RAIL_H */