author | rubidium |
Sat, 02 Aug 2008 22:51:07 +0000 | |
changeset 9799 | c91afc4512fe |
parent 9784 | a9cc0dff1667 |
permissions | -rw-r--r-- |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
2 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
3 |
/** @file track_func.h Different conversion functions from one kind of track to another. */ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
4 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
5 |
#ifndef TRACK_FUNC_H |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
6 |
#define TRACK_FUNC_H |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
7 |
|
8113
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
8108
diff
changeset
|
8 |
#include "core/bitmath_func.hpp" |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
9 |
#include "track_type.h" |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
10 |
#include "direction_type.h" |
8108
b42a0e5c67ef
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
8103
diff
changeset
|
11 |
#include "slope_func.h" |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
12 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
13 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
14 |
* Convert an Axis to the corresponding Track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
15 |
* AXIS_X -> TRACK_X |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
16 |
* AXIS_Y -> TRACK_Y |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
17 |
* Uses the fact that they share the same internal encoding |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
18 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
19 |
* @param a the axis to convert |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
20 |
* @return the track corresponding to the axis |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
21 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
22 |
static inline Track AxisToTrack(Axis a) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
23 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
24 |
return (Track)a; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
25 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
26 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
27 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
28 |
* Maps a Track to the corresponding TrackBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
29 |
* @param track the track to convert |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
30 |
* @return the converted TrackBits value of the track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
31 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
32 |
static inline TrackBits TrackToTrackBits(Track track) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
33 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
34 |
return (TrackBits)(1 << track); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
35 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
36 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
37 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
38 |
* Maps an Axis to the corresponding TrackBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
39 |
* @param a the axis to convert |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
40 |
* @return the converted TrackBits value of the axis |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
41 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
42 |
static inline TrackBits AxisToTrackBits(Axis a) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
43 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
44 |
return TrackToTrackBits(AxisToTrack(a)); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
45 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
46 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
47 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
48 |
* Returns a single horizontal/vertical trackbit, that is in a specific tile corner. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
49 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
50 |
* @param corner The corner of a tile. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
51 |
* @return The TrackBits of the track in the corner. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
52 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
53 |
static inline TrackBits CornerToTrackBits(Corner corner) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
54 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
55 |
extern const TrackBits _corner_to_trackbits[]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
56 |
assert(IsValidCorner(corner)); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
57 |
return _corner_to_trackbits[corner]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
58 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
59 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
60 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
61 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
62 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
63 |
* Maps a Trackdir to the corresponding TrackdirBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
64 |
* @param trackdir the track direction to convert |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
65 |
* @return the converted TrackdirBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
66 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
67 |
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
68 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
69 |
return (TrackdirBits)(1 << trackdir); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
70 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
71 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
72 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
73 |
* Removes first Track from TrackBits and returns it |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
74 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
75 |
* This function searchs for the first bit in the TrackBits, |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
76 |
* remove this bit from the parameter and returns the found |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
77 |
* bit as Track value. It returns INVALID_TRACK if the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
78 |
* parameter was TRACK_BIT_NONE or INVALID_TRACK_BIT. This |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
79 |
* is basically used in while-loops to get up to 6 possible |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
80 |
* tracks on a tile until the parameter becomes TRACK_BIT_NONE. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
81 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
82 |
* @param tracks The value with the TrackBits |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
83 |
* @return The first Track from the TrackBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
84 |
* @see FindFirstTrack |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
85 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
86 |
static inline Track RemoveFirstTrack(TrackBits *tracks) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
87 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
88 |
if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) { |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
89 |
Track first = (Track)FIND_FIRST_BIT(*tracks); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
90 |
ClrBit(*tracks, first); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
91 |
return first; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
92 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
93 |
return INVALID_TRACK; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
94 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
95 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
96 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
97 |
* Removes first Trackdir from TrackdirBits and returns it |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
98 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
99 |
* This function searchs for the first bit in the TrackdirBits parameter, |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
100 |
* remove this bit from the parameter and returns the fnound bit as |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
101 |
* Trackdir value. It returns INVALID_TRACKDIR if the trackdirs is |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
102 |
* TRACKDIR_BIT_NONE or INVALID_TRACKDIR_BIT. This is basically used in a |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
103 |
* while-loop to get all track-directions step by step until the value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
104 |
* reaches TRACKDIR_BIT_NONE. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
105 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
106 |
* @param trackdirs The value with the TrackdirBits |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
107 |
* @return The first Trackdir from the TrackdirBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
108 |
* @see FindFirstTrackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
109 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
110 |
static inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
111 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
112 |
if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) { |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
113 |
Trackdir first = (Trackdir)FindFirstBit2x64(*trackdirs); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
114 |
ClrBit(*trackdirs, first); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
115 |
return first; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
116 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
117 |
return INVALID_TRACKDIR; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
118 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
119 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
120 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
121 |
* Returns first Track from TrackBits or INVALID_TRACK |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
122 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
123 |
* This function returns the first Track found in the TrackBits value as Track-value. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
124 |
* It returns INVALID_TRACK if the parameter is TRACK_BIT_NONE or INVALID_TRACK_BIT. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
125 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
126 |
* @param tracks The TrackBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
127 |
* @return The first Track found or INVALID_TRACK |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
128 |
* @see RemoveFirstTrack |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
129 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
130 |
static inline Track FindFirstTrack(TrackBits tracks) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
131 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
132 |
return (tracks != TRACK_BIT_NONE && tracks != INVALID_TRACK_BIT) ? (Track)FIND_FIRST_BIT(tracks) : INVALID_TRACK; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
133 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
134 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
135 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
136 |
* Converts TrackBits to Track. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
137 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
138 |
* This function converts a TrackBits value to a Track value. As it |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
139 |
* is not possible to convert two or more tracks to one track the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
140 |
* parameter must contain only one track or be the INVALID_TRACK_BIT value. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
141 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
142 |
* @param tracks The TrackBits value to convert |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
143 |
* @return The Track from the value or INVALID_TRACK |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
144 |
* @pre tracks must contains only one Track or be INVALID_TRACK_BIT |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
145 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
146 |
static inline Track TrackBitsToTrack(TrackBits tracks) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
147 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
148 |
assert(tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KillFirstBit(tracks & TRACK_BIT_MASK) == TRACK_BIT_NONE)); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
149 |
return tracks != INVALID_TRACK_BIT ? (Track)FIND_FIRST_BIT(tracks & TRACK_BIT_MASK) : INVALID_TRACK; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
150 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
151 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
152 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
153 |
* Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
154 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
155 |
* This function returns the first Trackdir in the given TrackdirBits value or |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
156 |
* INVALID_TRACKDIR if the value is TRACKDIR_BIT_NONE. The TrackdirBits must |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
157 |
* not be INVALID_TRACKDIR_BIT. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
158 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
159 |
* @param trackdirs The TrackdirBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
160 |
* @return The first Trackdir from the TrackdirBits or INVALID_TRACKDIR on TRACKDIR_BIT_NONE. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
161 |
* @pre trackdirs must not be INVALID_TRACKDIR_BIT |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
162 |
* @see RemoveFirstTrackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
163 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
164 |
static inline Trackdir FindFirstTrackdir(TrackdirBits trackdirs) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
165 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
166 |
assert((trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
167 |
return (trackdirs != TRACKDIR_BIT_NONE) ? (Trackdir)FindFirstBit2x64(trackdirs) : INVALID_TRACKDIR; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
168 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
169 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
170 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
171 |
* Checks if a Track is valid. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
172 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
173 |
* @param track The value to check |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
174 |
* @return true if the given value is a valid track. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
175 |
* @note Use this in an assert() |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
176 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
177 |
static inline bool IsValidTrack(Track track) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
178 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
179 |
return track < TRACK_END; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
180 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
181 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
182 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
183 |
* Checks if a Trackdir is valid. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
184 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
185 |
* @param trackdir The value to check |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
186 |
* @return true if the given valie is a valid Trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
187 |
* @note Use this in an assert() |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
188 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
189 |
static inline bool IsValidTrackdir(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
190 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
191 |
return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
192 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
193 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
194 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
195 |
/* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
196 |
* Functions describing logical relations between Tracks, TrackBits, Trackdirs |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
197 |
* TrackdirBits, Direction and DiagDirections. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
198 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
199 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
200 |
/** |
9784
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
201 |
* Find the opposite track to a given track. |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
202 |
* |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
203 |
* TRACK_LOWER -> TRACK_UPPER and vice versa, likewise for left/right. |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
204 |
* TRACK_X is mapped to TRACK_Y and reversed. |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
205 |
* |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
206 |
* @param t the track to convert |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
207 |
* @return the opposite track |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
208 |
*/ |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
209 |
static inline Track TrackToOppositeTrack(Track t) |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
210 |
{ |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
211 |
assert(t != INVALID_TRACK); |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
212 |
return (Track)(t ^ 1); |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
213 |
} |
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
214 |
|
a9cc0dff1667
(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)
rubidium
parents:
9224
diff
changeset
|
215 |
/** |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
216 |
* Maps a trackdir to the reverse trackdir. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
217 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
218 |
* Returns the reverse trackdir of a Trackdir value. The reverse trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
219 |
* is the same track with the other direction on it. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
220 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
221 |
* @param trackdir The Trackdir value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
222 |
* @return The reverse trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
223 |
* @pre trackdir must not be INVALID_TRACKDIR |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
224 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
225 |
static inline Trackdir ReverseTrackdir(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
226 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
227 |
assert(trackdir != INVALID_TRACKDIR); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
228 |
return (Trackdir)(trackdir ^ 8); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
229 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
230 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
231 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
232 |
* Returns the Track that a given Trackdir represents |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
233 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
234 |
* This function filters the Track which is used in the Trackdir value and |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
235 |
* returns it as a Track value. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
236 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
237 |
* @param trackdir The trackdir value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
238 |
* @return The Track which is used in the value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
239 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
240 |
static inline Track TrackdirToTrack(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
241 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
242 |
return (Track)(trackdir & 0x7); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
243 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
244 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
245 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
246 |
* Returns a Trackdir for the given Track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
247 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
248 |
* Since every Track corresponds to two Trackdirs, we choose the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
249 |
* one which points between NE and S. Note that the actual |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
250 |
* implementation is quite futile, but this might change |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
251 |
* in the future. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
252 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
253 |
* @param track The given Track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
254 |
* @return The Trackdir from the given Track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
255 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
256 |
static inline Trackdir TrackToTrackdir(Track track) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
257 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
258 |
return (Trackdir)track; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
259 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
260 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
261 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
262 |
* Returns a TrackdirBit mask from a given Track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
263 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
264 |
* The TrackdirBit mask contains the two TrackdirBits that |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
265 |
* correspond with the given Track (one for each direction). |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
266 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
267 |
* @param track The track to get the TrackdirBits from |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
268 |
* @return The TrackdirBits which the selected tracks |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
269 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
270 |
static inline TrackdirBits TrackToTrackdirBits(Track track) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
271 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
272 |
Trackdir td = TrackToTrackdir(track); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
273 |
return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td))); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
274 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
275 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
276 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
277 |
* Discards all directional information from a TrackdirBits value |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
278 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
279 |
* Any Track which is present in either direction will be present in the result. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
280 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
281 |
* @param bits The TrackdirBits to get the TrackBits from |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
282 |
* @return The TrackBits |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
283 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
284 |
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
285 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
286 |
return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
287 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
288 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
289 |
/** |
8616
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
290 |
* Converts TrackBits to TrackdirBits while allowing both directions. |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
291 |
* |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
292 |
* @param bits The TrackBits |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
293 |
* @return The TrackdirBits containing of bits in both directions. |
8616
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
294 |
*/ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
295 |
static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits) |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
296 |
{ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
297 |
return (TrackdirBits)(bits * 0x101); |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
298 |
} |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
299 |
|
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
300 |
/** |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
301 |
* Returns the present-trackdir-information of a TrackStatus. |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
302 |
* |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
303 |
* @param ts The TrackStatus returned by GetTileTrackStatus() |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
304 |
* @return the present trackdirs |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
305 |
*/ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
306 |
static inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts) |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
307 |
{ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
308 |
return (TrackdirBits)(ts & TRACKDIR_BIT_MASK); |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
309 |
} |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
310 |
|
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
311 |
/** |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
312 |
* Returns the present-track-information of a TrackStatus. |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
313 |
* |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
314 |
* @param ts The TrackStatus returned by GetTileTrackStatus() |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
315 |
* @return the present tracks |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
316 |
*/ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
317 |
static inline TrackBits TrackStatusToTrackBits(TrackStatus ts) |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
318 |
{ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
319 |
return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts)); |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
320 |
} |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
321 |
|
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
322 |
/** |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
323 |
* Returns the red-signal-information of a TrackStatus. |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
324 |
* |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
325 |
* Note: The result may contain red signals for non-present tracks. |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
326 |
* |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
327 |
* @param ts The TrackStatus returned by GetTileTrackStatus() |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
328 |
* @return the The trackdirs that are blocked by red-signals |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
329 |
*/ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
330 |
static inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts) |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
331 |
{ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
332 |
return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK); |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
333 |
} |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
334 |
|
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
335 |
/** |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
336 |
* Builds a TrackStatus |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
337 |
* |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
338 |
* @param trackdirbits present trackdirs |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
339 |
* @param red_signals red signals |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
340 |
* @return the TrackStatus representing the given information |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
341 |
*/ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
342 |
static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals) |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
343 |
{ |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
344 |
return (TrackStatus)(trackdirbits | (red_signals << 16)); |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
345 |
} |
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
346 |
|
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8113
diff
changeset
|
347 |
/** |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
348 |
* Maps a trackdir to the trackdir that you will end up on if you go straight |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
349 |
* ahead. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
350 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
351 |
* This will be the same trackdir for diagonal trackdirs, but a |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
352 |
* different (alternating) one for straight trackdirs |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
353 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
354 |
* @param trackdir The given trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
355 |
* @return The next Trackdir value of the next tile. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
356 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
357 |
static inline Trackdir NextTrackdir(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
358 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
359 |
extern const Trackdir _next_trackdir[TRACKDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
360 |
return _next_trackdir[trackdir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
361 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
362 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
363 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
364 |
* Maps a track to all tracks that make 90 deg turns with it. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
365 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
366 |
* For the diagonal directions these are the complement of the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
367 |
* direction, for the straight directions these are the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
368 |
* two vertical or horizontal tracks, depend on the given direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
369 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
370 |
* @param track The given track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
371 |
* @return The TrackBits with the tracks marked which cross the given track by 90 deg. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
372 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
373 |
static inline TrackBits TrackCrossesTracks(Track track) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
374 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
375 |
extern const TrackBits _track_crosses_tracks[TRACK_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
376 |
return _track_crosses_tracks[track]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
377 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
378 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
379 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
380 |
* Maps a trackdir to the (4-way) direction the tile is exited when following |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
381 |
* that trackdir. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
382 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
383 |
* For the diagonal directions these are the same directions. For |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
384 |
* the straight directions these are the directions from the imagined |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
385 |
* base-tile to the bordering tile which will be joined if the given |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
386 |
* straight direction is leaved from the base-tile. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
387 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
388 |
* @param trackdir The given track direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
389 |
* @return The direction which points to the resulting tile if following the Trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
390 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
391 |
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
392 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
393 |
extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
394 |
return _trackdir_to_exitdir[trackdir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
395 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
396 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
397 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
398 |
* Maps a track and an (4-way) dir to the trackdir that represents the track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
399 |
* with the exit in the given direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
400 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
401 |
* For the diagonal tracks the resulting track direction are clear for a given |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
402 |
* DiagDirection. It either matches the direction or it returns INVALID_TRACKDIR, |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
403 |
* as a TRACK_X cannot be applied with DIAG_SE. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
404 |
* For the straight tracks the resulting track direction will be the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
405 |
* direction which the DiagDirection is pointing. But this will be INVALID_TRACKDIR |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
406 |
* if the DiagDirection is pointing 'away' the track. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
407 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
408 |
* @param track The track to applie an direction on |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
409 |
* @param diagdir The DiagDirection to applie on |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
410 |
* @return The resulting track direction or INVALID_TRACKDIR if not possible. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
411 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
412 |
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
413 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
414 |
extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
415 |
return _track_exitdir_to_trackdir[track][diagdir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
416 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
417 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
418 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
419 |
* Maps a track and an (4-way) dir to the trackdir that represents the track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
420 |
* with the entry in the given direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
421 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
422 |
* For the diagonal tracks the return value is clear, its either the matching |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
423 |
* track direction or INVALID_TRACKDIR. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
424 |
* For the straight tracks this returns the track direction which results if |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
425 |
* you follow the DiagDirection and then turn by 45 deg left or right on the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
426 |
* next tile. The new direction on the new track will be the returning Trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
427 |
* value. If the parameters makes no sense like the track TRACK_UPPER and the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
428 |
* diraction DIAGDIR_NE (target track cannot be reached) this function returns |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
429 |
* INVALID_TRACKDIR. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
430 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
431 |
* @param track The target track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
432 |
* @param diagdir The direction to "come from" |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
433 |
* @return the resulting Trackdir or INVALID_TRACKDIR if not possible. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
434 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
435 |
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
436 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
437 |
extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
438 |
return _track_enterdir_to_trackdir[track][diagdir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
439 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
440 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
441 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
442 |
* Maps a track and a full (8-way) direction to the trackdir that represents |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
443 |
* the track running in the given direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
444 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
445 |
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
446 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
447 |
extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
448 |
return _track_direction_to_trackdir[track][dir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
449 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
450 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
451 |
/** |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
452 |
* Maps a (4-way) direction to the diagonal track incidating with that diagdir |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
453 |
* |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
454 |
* @param diagdir The direction |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
455 |
* @return The resulting Track |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
456 |
*/ |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
457 |
static inline Track DiagDirToDiagTrack(DiagDirection diagdir) |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
458 |
{ |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
459 |
return (Track)(diagdir & 1); |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
460 |
} |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
461 |
|
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
462 |
/** |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
463 |
* Maps a (4-way) direction to the diagonal track bits incidating with that diagdir |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
464 |
* |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
465 |
* @param diagdir The direction |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
466 |
* @return The resulting TrackBits |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
467 |
*/ |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
468 |
static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir) |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
469 |
{ |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
470 |
return TrackToTrackBits(DiagDirToDiagTrack(diagdir)); |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
471 |
} |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
472 |
|
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
473 |
/** |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
474 |
* Maps a (4-way) direction to the diagonal trackdir that runs in that |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
475 |
* direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
476 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
477 |
* @param diagdir The direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
478 |
* @return The resulting Trackdir direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
479 |
*/ |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
8653
diff
changeset
|
480 |
static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir) |
8101
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
481 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
482 |
extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
483 |
return _dir_to_diag_trackdir[diagdir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
484 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
485 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
486 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
487 |
* Returns all trackdirs that can be reached when entering a tile from a given |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
488 |
* (diagonal) direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
489 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
490 |
* This will obviously include 90 degree turns, since no information is available |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
491 |
* about the exact angle of entering |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
492 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
493 |
* @param diagdir The joining direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
494 |
* @return The TrackdirBits which can be used from the given direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
495 |
* @see DiagdirReachesTracks |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
496 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
497 |
static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
498 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
499 |
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
500 |
return _exitdir_reaches_trackdirs[diagdir]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
501 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
502 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
503 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
504 |
* Returns all tracks that can be reached when entering a tile from a given |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
505 |
* (diagonal) direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
506 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
507 |
* This will obviously include 90 degree turns, since no |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
508 |
* information is available about the exact angle of entering |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
509 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
510 |
* @param diagdir The joining irection |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
511 |
* @return The tracks which can be used |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
512 |
* @see DiagdirReachesTrackdirs |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
513 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
514 |
static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); } |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
515 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
516 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
517 |
* Maps a trackdir to the trackdirs that can be reached from it (ie, when |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
518 |
* entering the next tile. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
519 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
520 |
* This will include 90 degree turns! |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
521 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
522 |
* @param trackdir The track direction which will be leaved |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
523 |
* @return The track directions which can be used from this direction (in the next tile) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
524 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
525 |
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
526 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
527 |
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
528 |
return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
529 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
530 |
/* Note that there is no direct table for this function (there used to be), |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
531 |
* but it uses two simpeler tables to achieve the result */ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
532 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
533 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
534 |
* Maps a trackdir to all trackdirs that make 90 deg turns with it. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
535 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
536 |
* For the diagonal tracks this returns the track direction bits |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
537 |
* of the other axis in both directions, which cannot be joined by |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
538 |
* the given track direction. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
539 |
* For the straight tracks this returns all possible 90 deg turns |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
540 |
* either on the current tile (which no train can joined) or on the |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
541 |
* bordering tiles. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
542 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
543 |
* @param trackdir The track direction |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
544 |
* @return The TrackdirBits which are (more or less) 90 deg turns. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
545 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
546 |
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
547 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
548 |
extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
549 |
return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
550 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
551 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
552 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
553 |
* Checks if a given Track is diagonal |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
554 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
555 |
* @param track The given track to check |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
556 |
* @return true if diagonal, else false |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
557 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
558 |
static inline bool IsDiagonalTrack(Track track) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
559 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
560 |
return (track == TRACK_X) || (track == TRACK_Y); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
561 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
562 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
563 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
564 |
* Checks if a given Trackdir is diagonal. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
565 |
* |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
566 |
* @param trackdir The given trackdir |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
567 |
* @return true if the trackdir use a diagonal track |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
568 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
569 |
static inline bool IsDiagonalTrackdir(Trackdir trackdir) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
570 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
571 |
return IsDiagonalTrack(TrackdirToTrack(trackdir)); |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
572 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
573 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
574 |
|
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
575 |
/** |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
576 |
* Checks if the given tracks overlap, ie form a crossing. Basically this |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
577 |
* means when there is more than one track on the tile, exept when there are |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
578 |
* two parallel tracks. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
579 |
* @param bits The tracks present. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
580 |
* @return Whether the tracks present overlap in any way. |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
581 |
*/ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
582 |
static inline bool TracksOverlap(TrackBits bits) |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
583 |
{ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
584 |
/* With no, or only one track, there is no overlap */ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
585 |
if (bits == TRACK_BIT_NONE || KillFirstBit(bits) == TRACK_BIT_NONE) return false; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
586 |
/* We know that there are at least two tracks present. When there are more |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
587 |
* than 2 tracks, they will surely overlap. When there are two, they will |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
588 |
* always overlap unless they are lower & upper or right & left. */ |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
589 |
return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT; |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
590 |
} |
d5357bde8cab
(svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents:
diff
changeset
|
591 |
|
8102
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
592 |
/** |
9799
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
593 |
* Check if a given track is contained within or overlaps some other tracks. |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
594 |
* |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
595 |
* @param tracks Tracks to be testet against |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
596 |
* @param track The track to test |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
597 |
* @return true if the track is already in the tracks or overlaps the tracks. |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
598 |
*/ |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
599 |
static inline bool TrackOverlapsTracks(TrackBits tracks, Track track) |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
600 |
{ |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
601 |
if (HasBit(tracks, track)) return true; |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
602 |
return TracksOverlap(tracks | TrackToTrackBits(track)); |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
603 |
} |
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
604 |
|
c91afc4512fe
(svn r13941) -Codechange [YAPP]: Added YAPP-related penalties to YAPF. (michi_cc)
rubidium
parents:
9784
diff
changeset
|
605 |
/** |
8102
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
606 |
* Checks whether the trackdir means that we are reversing. |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
607 |
* @param dir the trackdir to check |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
608 |
* @return true if it is a reversing road trackdir |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
609 |
*/ |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
610 |
static inline bool IsReversingRoadTrackdir(Trackdir dir) |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
611 |
{ |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
612 |
return (dir & 0x07) >= 6; |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
613 |
} |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
614 |
|
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
615 |
/** |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
616 |
* Checks whether the given trackdir is a straight road |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
617 |
* @param dir the trackdir to check |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
618 |
* @return true if it is a straight road trackdir |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
619 |
*/ |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
620 |
static inline bool IsStraightRoadTrackdir(Trackdir dir) |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
621 |
{ |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
622 |
return (dir & 0x06) == 0; |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
623 |
} |
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8101
diff
changeset
|
624 |
|
8653
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
625 |
/** |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
626 |
* Checks whether a trackdir on a specific slope is going uphill. |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
627 |
* |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
628 |
* Valid for rail and road tracks. |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
629 |
* Valid for tile-slopes (under foundation) and foundation-slopes (on foundation). |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
630 |
* |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
631 |
* @param slope The slope of the tile. |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
632 |
* @param dir The trackdir of interest. |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
633 |
* @return true iff the track goes upwards. |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
634 |
*/ |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
635 |
static inline bool IsUphillTrackdir(Slope slope, Trackdir dir) |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
636 |
{ |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
637 |
extern const TrackdirBits _uphill_trackdirs[]; |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
638 |
return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir); |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
639 |
} |
527a6273a0a8
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
frosch
parents:
8616
diff
changeset
|
640 |
|
8103
cf92483a0abf
(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:
8102
diff
changeset
|
641 |
#endif /* TRACK_FUNC_H */ |