src/track_func.h
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9149 cd335504407b
child 10546 07ab34af246e
permissions -rw-r--r--
update tags
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
8597
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8596
diff changeset
     3
/** @file track_func.h Different conversion functions from one kind of track to another. */
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
     4
8597
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8596
diff changeset
     5
#ifndef TRACK_FUNC_H
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8596
diff changeset
     6
#define TRACK_FUNC_H
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
     7
8609
8c0c3e9dd6a0 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8604
diff changeset
     8
#include "core/bitmath_func.hpp"
8597
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8596
diff changeset
     9
#include "track_type.h"
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8596
diff changeset
    10
#include "direction_type.h"
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8599
diff changeset
    11
#include "slope_func.h"
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
    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
 * Convert an Axis to the corresponding Track
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    15
 * AXIS_X -> TRACK_X
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    16
 * AXIS_Y -> TRACK_Y
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    17
 * 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
    18
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    19
 * @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
    20
 * @return the track corresponding to the axis
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    21
 */
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    22
static inline Track AxisToTrack(Axis a)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    23
{
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    24
	return (Track)a;
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    25
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    26
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    27
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
    28
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    29
/**
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    30
 * 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
    31
 * @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
    32
 * @return the converted TrackBits value of the track
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    33
 */
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    34
static inline TrackBits TrackToTrackBits(Track track)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    35
{
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    36
	return (TrackBits)(1 << track);
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    37
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    38
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    39
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    40
 * 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
    41
 * @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
    42
 * @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
    43
 */
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    44
static inline TrackBits AxisToTrackBits(Axis a)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    45
{
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    46
	return TrackToTrackBits(AxisToTrack(a));
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    47
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    48
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    49
/**
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    50
 * 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
    51
 *
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    52
 * @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
    53
 * @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
    54
 */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    55
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
    56
{
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    57
	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
    58
	assert(IsValidCorner(corner));
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    59
	return _corner_to_trackbits[corner];
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    60
}
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8097
diff changeset
    61
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
    62
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    63
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    64
/**
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    65
 * 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
    66
 * @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
    67
 * @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
    68
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    69
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
    70
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    71
	return (TrackdirBits)(1 << trackdir);
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    72
}
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    73
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
    74
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    75
 * 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
    76
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    77
 * 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
    78
 * 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
    79
 * 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
    80
 * 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
    81
 * 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
    82
 * 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
    83
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    84
 * @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
    85
 * @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
    86
 * @see FindFirstTrack
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    87
 */
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
    88
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
    89
{
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
    90
	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
    91
		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
    92
		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
    93
		return first;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    94
	}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    95
	return INVALID_TRACK;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    96
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    97
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    98
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
    99
 * 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
   100
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   101
 * 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
   102
 * 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
   103
 * 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
   104
 * 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
   105
 * 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
   106
 * reaches TRACKDIR_BIT_NONE.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   107
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   108
 * @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
   109
 * @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
   110
 * @see FindFirstTrackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   111
 */
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   112
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
   113
{
5849
58039c9dc565 (svn r8052) - Codechange: RemoveFirstTrack() and RemoveFirstTrackdir() now accept pointer to TrackBits/TrackdirBits instead of reference.
KUDr
parents: 5838
diff changeset
   114
	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
   115
		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
   116
		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
   117
		return first;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   118
	}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   119
	return INVALID_TRACKDIR;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   120
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   121
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   122
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   123
 * 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
   124
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   125
 * 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
   126
 * 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
   127
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   128
 * @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
   129
 * @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
   130
 * @see RemoveFirstTrack
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   131
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   132
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
   133
{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   134
	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
   135
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   136
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
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
 * Converts TrackBits to Track.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   139
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   140
 * 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
   141
 * 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
   142
 * 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
   143
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   144
 * @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
   145
 * @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
   146
 * @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
   147
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   148
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
   149
{
8329
77e50bd6ad67 (svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents: 8267
diff changeset
   150
	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
   151
	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
   152
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   153
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   154
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   155
 * 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
   156
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   157
 * 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
   158
 * 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
   159
 * 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
   160
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   161
 * @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
   162
 * @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
   163
 * @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
   164
 * @see RemoveFirstTrackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   165
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   166
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
   167
{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   168
	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
   169
	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
   170
}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   171
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
 * 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
   174
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   175
 * @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
   176
 * @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
   177
 * @note Use this in an assert()
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   178
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   179
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
   180
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   181
	return track < TRACK_END;
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   182
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   183
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
   184
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   185
 * 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
   186
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   187
 * @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
   188
 * @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
   189
 * @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
   190
 */
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   191
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
   192
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   193
	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
   194
}
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   195
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   196
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   197
/*
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   198
 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   199
 * TrackdirBits, Direction and DiagDirections.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   200
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   201
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   202
/**
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
   203
 * 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
   204
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   205
 * 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
   206
 * 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
   207
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   208
 * @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
   209
 * @return The reverse trackdir
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   210
 * @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
   211
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   212
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
   213
{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
   214
	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
   215
	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
   216
}
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
   217
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   218
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   219
 * 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
   220
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   221
 * 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
   222
 * 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
   223
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   224
 * @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
   225
 * @return The Track which is used in the value
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   226
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   227
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
   228
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   229
	return (Track)(trackdir & 0x7);
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   230
}
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
   231
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   232
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   233
 * 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
   234
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   235
 * 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
   236
 * 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
   237
 * 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
   238
 * in the future.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   239
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   240
 * @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
   241
 * @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
   242
 */
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   243
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
   244
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   245
	return (Trackdir)track;
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   246
}
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
   247
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   248
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   249
 * 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
   250
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   251
 * 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
   252
 * 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
   253
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   254
 * @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
   255
 * @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
   256
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   257
static inline TrackdirBits TrackToTrackdirBits(Track track)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   258
{
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   259
	Trackdir td = TrackToTrackdir(track);
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   260
	return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   261
}
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
   262
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
   263
/**
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   264
 * 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
   265
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   266
 * 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
   267
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   268
 * @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
   269
 * @return The TrackBits
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   270
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   271
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   272
{
4281
55f66f81239d (svn r5911) -Fix [FS#215]: Discard upper bits of TrackdirBitsToTrackBits result.
matthijs
parents: 4158
diff changeset
   273
	return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   274
}
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   275
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   276
/**
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   277
 * Converts TrackBits to TrackdirBits while allowing both directions.
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   278
 *
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   279
 * @param bits The TrackBits
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   280
 * @return The TrackDirBits containing of bits in both directions.
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   281
 */
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   282
static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   283
{
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   284
	return (TrackdirBits)(bits * 0x101);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   285
}
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   286
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   287
/**
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   288
 * Returns the present-trackdir-information of a TrackStatus.
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   289
 *
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   290
 * @param ts The TrackStatus returned by GetTileTrackStatus()
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   291
 * @return the present trackdirs
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   292
 */
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   293
static inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   294
{
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   295
	return (TrackdirBits)(ts & TRACKDIR_BIT_MASK);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   296
}
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   297
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   298
/**
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   299
 * Returns the present-track-information of a TrackStatus.
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   300
 *
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   301
 * @param ts The TrackStatus returned by GetTileTrackStatus()
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   302
 * @return the present tracks
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   303
 */
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   304
static inline TrackBits TrackStatusToTrackBits(TrackStatus ts)
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   305
{
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   306
	return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts));
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   307
}
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   308
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   309
/**
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   310
 * Returns the red-signal-information of a TrackStatus.
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   311
 *
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   312
 * Note: The result may contain red signals for non-present tracks.
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   313
 *
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   314
 * @param ts The TrackStatus returned by GetTileTrackStatus()
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   315
 * @return the The trackdirs that are blocked by red-signals
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   316
 */
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   317
static inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   318
{
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   319
	return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK);
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   320
}
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   321
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   322
/**
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   323
 * Builds a TrackStatus
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   324
 *
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   325
 * @param trackdirbits present trackdirs
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   326
 * @param red_signals red signals
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   327
 * @return the TrackStatus representing the given information
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   328
 */
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   329
static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   330
{
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   331
	return (TrackStatus)(trackdirbits | (red_signals << 16));
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   332
}
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   333
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8609
diff changeset
   334
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   335
 * 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
   336
 * ahead.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   337
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   338
 * 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
   339
 * 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
   340
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   341
 * @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
   342
 * @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
   343
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   344
static inline Trackdir NextTrackdir(Trackdir trackdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   345
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   346
	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
   347
	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
   348
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   349
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   350
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   351
 * 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
   352
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   353
 * 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
   354
 * 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
   355
 * 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
   356
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   357
 * @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
   358
 * @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
   359
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   360
static inline TrackBits TrackCrossesTracks(Track track)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   361
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   362
	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
   363
	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
   364
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   365
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   366
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   367
 * 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
   368
 * that trackdir.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   369
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   370
 * 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
   371
 * 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
   372
 * 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
   373
 * 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
   374
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   375
 * @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
   376
 * @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
   377
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   378
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   379
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   380
	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
   381
	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
   382
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   383
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   384
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   385
 * 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
   386
 * 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
   387
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   388
 * 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
   389
 * 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
   390
 * 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
   391
 * 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
   392
 * 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
   393
 * 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
   394
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   395
 * @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
   396
 * @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
   397
 * @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
   398
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   399
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   400
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   401
	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
   402
	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
   403
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   404
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   405
/**
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
   406
 * 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
   407
 * 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
   408
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   409
 * 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
   410
 * 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
   411
 * 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
   412
 * 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
   413
 * 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
   414
 * 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
   415
 * 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
   416
 * INVALID_TRACKDIR.
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
 * @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
   419
 * @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
   420
 * @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
   421
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   422
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   423
{
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
   424
	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
   425
	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
   426
}
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
   427
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
   428
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   429
 * 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
   430
 * the track running in the given direction.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   431
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   432
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   433
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   434
	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
   435
	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
   436
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   437
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   438
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   439
 * 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
   440
 * direction.
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   441
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   442
 * @param diagdir The direction
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   443
 * @return The resulting Trackdir direction
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   444
 */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   445
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   446
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   447
	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
   448
	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
   449
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   450
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   451
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   452
 * 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
   453
 * (diagonal) direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   454
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   455
 * 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
   456
 * 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
   457
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   458
 * @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
   459
 * @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
   460
 * @see DiagdirReachesTracks
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   461
 */
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
   462
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
   463
{
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   464
	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
   465
	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
   466
}
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   467
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   468
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   469
 * 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
   470
 * (diagonal) direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   471
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   472
 * 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
   473
 * 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
   474
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   475
 * @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
   476
 * @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
   477
 * @see DiagdirReachesTrackdirs
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   478
 */
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   479
static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   480
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   481
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   482
 * 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
   483
 * entering the next tile.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   484
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   485
 * 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
   486
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   487
 * @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
   488
 * @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
   489
 */
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
   490
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
   491
{
07bbbafd4f70 (svn r8912) -Codechange: coding style cleanup and moving of two global externs into the functions that use them.
rubidium
parents: 6482
diff changeset
   492
	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
   493
	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
   494
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   495
/* 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
   496
 * but it uses two simpeler tables to achieve the result */
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   497
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   498
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   499
 * 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
   500
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   501
 * 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
   502
 * 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
   503
 * the given track direction.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   504
 * 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
   505
 * 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
   506
 * bordering tiles.
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   507
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   508
 * @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
   509
 * @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
   510
 */
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
   511
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
   512
{
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   513
	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
   514
	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
   515
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   516
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   517
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   518
 * 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
   519
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   520
 * @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
   521
 * @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
   522
 */
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   523
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
   524
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   525
	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
   526
}
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
   527
7892
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   528
/**
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   529
 * 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
   530
 *
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   531
 * @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
   532
 * @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
   533
 */
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   534
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
   535
{
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   536
	return IsDiagonalTrack(TrackdirToTrack(trackdir));
af0701f35fdf (svn r10765) -Documentation [FS#1100]: of rail.h. Based on a patch by Progman.
rubidium
parents: 7831
diff changeset
   537
}
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
   538
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
   539
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   540
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   541
 * Checks if the given tracks overlap, ie form a crossing. Basically this
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   542
 * 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
   543
 * two parallel tracks.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   544
 * @param  bits The tracks present.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   545
 * @return Whether the tracks present overlap in any way.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   546
 */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   547
static inline bool TracksOverlap(TrackBits bits)
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   548
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4041
diff changeset
   549
	/* 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
   550
	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
   551
	/* 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
   552
	 * 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
   553
	 * 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
   554
	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   555
}
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   556
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   557
/**
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   558
 * Checks whether the trackdir means that we are reversing.
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   559
 * @param dir the trackdir to check
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   560
 * @return true if it is a reversing road trackdir
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   561
 */
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   562
static inline bool IsReversingRoadTrackdir(Trackdir dir)
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   563
{
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   564
	return (dir & 0x07) >= 6;
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   565
}
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   566
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   567
/**
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   568
 * Checks whether the given trackdir is a straight road
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   569
 * @param dir the trackdir to check
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   570
 * @return true if it is a straight road trackdir
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   571
 */
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   572
static inline bool IsStraightRoadTrackdir(Trackdir dir)
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   573
{
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   574
	return (dir & 0x06) == 0;
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   575
}
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   576
9149
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   577
/**
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   578
 * Checks whether a trackdir on a specific slope is going uphill.
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   579
 *
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   580
 * Valid for rail and road tracks.
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   581
 * Valid for tile-slopes (under foundation) and foundation-slopes (on foundation).
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   582
 *
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   583
 * @param slope The slope of the tile.
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   584
 * @param dir The trackdir of interest.
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   585
 * @return true iff the track goes upwards.
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   586
 */
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   587
static inline bool IsUphillTrackdir(Slope slope, Trackdir dir)
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   588
{
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   589
	extern const TrackdirBits _uphill_trackdirs[];
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   590
	return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir);
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   591
}
cd335504407b (svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents: 9112
diff changeset
   592
8599
b609cdeeff3f (svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents: 8598
diff changeset
   593
#endif /* TRACK_FUNC_H */