rail.c
author tron
Wed, 08 Mar 2006 15:28:38 +0000
changeset 3166 91e9fc028c95
parent 3147 fc76d566a68e
child 3184 118a520164e4
permissions -rw-r--r--
(svn r3794) Use already available accessor functions instead of GB()
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2133
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2133
diff changeset
     2
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1944
diff changeset
     3
#include "stdafx.h"
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1944
diff changeset
     4
#include "openttd.h"
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     5
#include "rail.h"
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
     6
#include "station.h"
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     7
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
     8
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     9
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    10
 * direction along with the trackdir */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    11
const byte _signal_along_trackdir[] = {
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    12
	0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    13
	0x40, 0x40, 0x40, 0x10, 0x80, 0x20
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    14
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    15
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    16
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    17
 * direction against the trackdir */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    18
const byte _signal_against_trackdir[] = {
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    19
	0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    20
	0x80, 0x80, 0x80, 0x20, 0x40, 0x10
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    21
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    22
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    23
/* Maps a Track to the bits that store the status of the two signals that can
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    24
 * be present on the given track */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    25
const byte _signal_on_track[] = {
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    26
	0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    27
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    28
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    29
/* Maps a diagonal direction to the all trackdirs that are connected to any
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    30
 * track entering in this direction (including those making 90 degree turns)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    31
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    32
const TrackdirBits _exitdir_reaches_trackdirs[] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    33
	TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N,  /* DIAGDIR_NE */
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    34
	TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S  | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    35
	TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    36
	TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W  /* DIAGDIR_NW */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    37
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    38
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    39
const Trackdir _next_trackdir[] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    40
	TRACKDIR_X_NE,  TRACKDIR_Y_SE,  TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    41
	TRACKDIR_X_SW,  TRACKDIR_Y_NW,  TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    42
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    43
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    44
/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    45
const TrackdirBits _track_crosses_trackdirs[] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    46
	TRACKDIR_BIT_Y_SE     | TRACKDIR_BIT_Y_NW,                                                   /* TRACK_X     */
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    47
	TRACKDIR_BIT_X_NE     | TRACKDIR_BIT_X_SW,                                                   /* TRACK_Y     */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    48
	TRACKDIR_BIT_RIGHT_N  | TRACKDIR_BIT_RIGHT_S  | TRACKDIR_BIT_LEFT_N  | TRACKDIR_BIT_LEFT_S,  /* TRACK_UPPER */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    49
	TRACKDIR_BIT_RIGHT_N  | TRACKDIR_BIT_RIGHT_S  | TRACKDIR_BIT_LEFT_N  | TRACKDIR_BIT_LEFT_S,  /* TRACK_LOWER */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    50
	TRACKDIR_BIT_UPPER_W  | TRACKDIR_BIT_UPPER_E  | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT  */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    51
	TRACKDIR_BIT_UPPER_W  | TRACKDIR_BIT_UPPER_E  | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E  /* TRACK_RIGHT */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    52
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    53
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    54
/* Maps a track to all tracks that make 90 deg turns with it. */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    55
const TrackBits _track_crosses_tracks[] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    56
	TRACK_BIT_Y,                       /* TRACK_X     */
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    57
	TRACK_BIT_X,                       /* TRACK_Y     */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    58
	TRACK_BIT_LEFT  | TRACK_BIT_RIGHT, /* TRACK_UPPER */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    59
	TRACK_BIT_LEFT  | TRACK_BIT_RIGHT, /* TRACK_LOWER */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    60
	TRACK_BIT_UPPER | TRACK_BIT_LOWER, /* TRACK_LEFT  */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    61
	TRACK_BIT_UPPER | TRACK_BIT_LOWER  /* TRACK_RIGHT */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    62
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    63
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    64
/* Maps a trackdir to the (4-way) direction the tile is exited when following
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    65
 * that trackdir */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    66
const DiagDirection _trackdir_to_exitdir[] = {
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    67
	DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_SW,DIAGDIR_SE, DIAGDIR_NE,DIAGDIR_NE,
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    68
	DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NW,DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NE,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    69
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    70
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    71
const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    72
	{TRACKDIR_X_NE,     INVALID_TRACKDIR,  TRACKDIR_X_SW,     INVALID_TRACKDIR},
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    73
	{INVALID_TRACKDIR,  TRACKDIR_Y_SE,     INVALID_TRACKDIR,  TRACKDIR_Y_NW},
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    74
	{TRACKDIR_UPPER_E,  INVALID_TRACKDIR,  INVALID_TRACKDIR,  TRACKDIR_UPPER_W},
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    75
	{INVALID_TRACKDIR,  TRACKDIR_LOWER_E,  TRACKDIR_LOWER_W,  INVALID_TRACKDIR},
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    76
	{INVALID_TRACKDIR,  INVALID_TRACKDIR,  TRACKDIR_LEFT_S,   TRACKDIR_LEFT_N},
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    77
	{TRACKDIR_RIGHT_N,  TRACKDIR_RIGHT_S,  INVALID_TRACKDIR,  INVALID_TRACKDIR}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    78
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    79
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    80
const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = { // TODO: replace magic with enums
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    81
	{TRACKDIR_X_NE,     INVALID_TRACKDIR,  TRACKDIR_X_SW,     INVALID_TRACKDIR},
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    82
	{INVALID_TRACKDIR,  TRACKDIR_Y_SE,     INVALID_TRACKDIR,  TRACKDIR_Y_NW},
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    83
	{INVALID_TRACKDIR,  TRACKDIR_UPPER_E,  TRACKDIR_UPPER_W,  INVALID_TRACKDIR},
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    84
	{TRACKDIR_LOWER_E,  INVALID_TRACKDIR,  INVALID_TRACKDIR,  TRACKDIR_LOWER_W},
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    85
	{TRACKDIR_LEFT_N,   TRACKDIR_LEFT_S,   INVALID_TRACKDIR,  INVALID_TRACKDIR},
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    86
	{INVALID_TRACKDIR,  INVALID_TRACKDIR,  TRACKDIR_RIGHT_S,  TRACKDIR_RIGHT_N}
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    87
};
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
    88
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    89
const Trackdir _track_direction_to_trackdir[][DIR_END] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    90
	{INVALID_TRACKDIR, TRACKDIR_X_NE,     INVALID_TRACKDIR, INVALID_TRACKDIR,  INVALID_TRACKDIR, TRACKDIR_X_SW,     INVALID_TRACKDIR, INVALID_TRACKDIR},
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    91
	{INVALID_TRACKDIR, INVALID_TRACKDIR,  INVALID_TRACKDIR, TRACKDIR_Y_SE,     INVALID_TRACKDIR, INVALID_TRACKDIR,  INVALID_TRACKDIR, TRACKDIR_Y_NW},
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    92
	{INVALID_TRACKDIR, INVALID_TRACKDIR,  TRACKDIR_UPPER_E, INVALID_TRACKDIR,  INVALID_TRACKDIR, INVALID_TRACKDIR,  TRACKDIR_UPPER_W, INVALID_TRACKDIR},
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    93
	{INVALID_TRACKDIR, INVALID_TRACKDIR,  TRACKDIR_LOWER_E, INVALID_TRACKDIR,  INVALID_TRACKDIR, INVALID_TRACKDIR,  TRACKDIR_LOWER_W, INVALID_TRACKDIR},
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    94
	{TRACKDIR_LEFT_N,  INVALID_TRACKDIR,  INVALID_TRACKDIR, INVALID_TRACKDIR,  TRACKDIR_LEFT_S,  INVALID_TRACKDIR,  INVALID_TRACKDIR, INVALID_TRACKDIR},
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    95
	{TRACKDIR_RIGHT_N, INVALID_TRACKDIR,  INVALID_TRACKDIR, INVALID_TRACKDIR,  TRACKDIR_RIGHT_S, INVALID_TRACKDIR,  INVALID_TRACKDIR, INVALID_TRACKDIR}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    96
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    97
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    98
const Trackdir _dir_to_diag_trackdir[] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
    99
	TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   100
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   101
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   102
const Trackdir _reverse_trackdir[] = {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
   103
	TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_UPPER_W, TRACKDIR_LOWER_W, TRACKDIR_LEFT_N, TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2548
diff changeset
   104
	TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_UPPER_E, TRACKDIR_LOWER_E, TRACKDIR_LEFT_S, TRACKDIR_RIGHT_S
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   105
};
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   106
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 1950
diff changeset
   107
RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   108
{
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   109
	RailType type = INVALID_RAILTYPE;
2030
5fae89698a6c (svn r2539) * Fix: Mixed up use of trackdirs and directions in GetTileRailType() causes NPF to not consider routes under bridges.
matthijs
parents: 2008
diff changeset
   110
	DiagDirection exitdir = TrackdirToExitdir(trackdir);
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   111
	switch (GetTileType(tile)) {
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   112
		case MP_RAILWAY:
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   113
			/* railway track */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   114
			type = _m[tile].m3 & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   115
			break;
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   116
		case MP_STREET:
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   117
			/* rail/road crossing */
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   118
			if (IsLevelCrossing(tile))
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   119
				type = _m[tile].m4 & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   120
			break;
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   121
		case MP_STATION:
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   122
			if (IsTrainStationTile(tile))
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   123
				type = _m[tile].m3 & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   124
			break;
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   125
		case MP_TUNNELBRIDGE:
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   126
			/* railway tunnel */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   127
			if ((_m[tile].m5 & 0xFC) == 0) type = _m[tile].m3 & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   128
			/* railway bridge ending */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   129
			if ((_m[tile].m5 & 0xC6) == 0x80) type = _m[tile].m3 & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   130
			/* on railway bridge */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   131
			if ((_m[tile].m5 & 0xC6) == 0xC0 && ((DiagDirection)(_m[tile].m5 & 0x1)) == (exitdir & 0x1))
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   132
				type = (_m[tile].m3 >> 4) & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   133
			/* under bridge (any type) */
2133
d7f582b7001d (svn r2643) Get rid of some unnecessary casts
tron
parents: 2049
diff changeset
   134
			if ((_m[tile].m5 & 0xC0) == 0xC0 && (_m[tile].m5 & 0x1U) != (exitdir & 0x1))
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2030
diff changeset
   135
				type = _m[tile].m3 & RAILTYPE_MASK;
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   136
			break;
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   137
		default:
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   138
			break;
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   139
	}
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   140
	return type;
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   141
}