rail.h
author tron
Fri, 29 Jul 2005 18:22:04 +0000
changeset 2230 e461b07aead7
parent 2186 db48cf29b983
child 2232 2a0d0328ebbe
permissions -rw-r--r--
(svn r2750) -Fix: Tree tiles above the snow line got redrawn disproportionately often
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     3
#ifndef RAIL_H
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     4
#define RAIL_H
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     5
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     6
#include "tile.h"
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     7
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     8
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     9
 * Some enums for accesing the map bytes for rail tiles
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    10
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    11
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    12
/* These types are used in the map5 byte for rail tiles. Use GetRailTileType() to
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    13
 * get these values */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    14
typedef enum RailTileTypes {
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    15
	RAIL_TYPE_NORMAL         = 0x0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    16
	RAIL_TYPE_SIGNALS        = 0x40,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    17
	RAIL_TYPE_UNUSED         = 0x80, /* XXX: Maybe this could become waypoints? */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    18
	RAIL_TYPE_DEPOT_WAYPOINT = 0xC0, /* Is really depots and waypoints... */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    19
	RAIL_TILE_TYPE_MASK      = 0xC0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    20
} RailTileType;
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
enum { /* DEPRECATED TODO: Rewrite all uses of this */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    23
	RAIL_TYPE_SPECIAL = 0x80, /* This used to say "If this bit is set, then it's
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    24
														 * not a regular track.", but currently, you
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    25
														 * should rather view map5[6..7] as one type,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    26
														 * containing a value from RailTileTypes above.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    27
														 * This value is only maintained for backwards
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    28
														 * compatibility */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    29
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    30
	/* There used to be RAIL_BIT_* enums here, they moved to (for now) npf.c as
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    31
	 * TRACK_BIT_* */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    32
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    33
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    34
/* These subtypes are used in the map5 byte when the main rail type is
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    35
 * RAIL_TYPE_DEPOT_WAYPOINT */
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
    36
typedef enum RailTileSubtypes {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    37
	RAIL_SUBTYPE_DEPOT    = 0x00,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    38
	RAIL_SUBTYPE_WAYPOINT = 0x04,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    39
	RAIL_SUBTYPE_MASK     = 0x3C,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    40
} RailTileSubtype;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    41
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
    42
typedef enum SignalTypes {
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: 2032
diff changeset
    43
	/* Stored in m4[0..1] for MP_RAILWAY */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    44
  SIGTYPE_NORMAL  = 0,        // normal signal
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    45
  SIGTYPE_ENTRY   = 1,        // presignal block entry
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    46
  SIGTYPE_EXIT    = 2,        // presignal block exit
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    47
  SIGTYPE_COMBO   = 3,        // presignal inter-block
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
    48
	SIGTYPE_PBS     = 4,        // pbs signal
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    49
	SIGTYPE_END,
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
    50
	SIGTYPE_MASK    = 7,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    51
} SignalType;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    52
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
    53
typedef enum RailTypes {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    54
	RAILTYPE_RAIL   = 0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    55
	RAILTYPE_MONO   = 1,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    56
	RAILTYPE_MAGLEV = 2,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    57
	RAILTYPE_END,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    58
	RAILTYPE_MASK   = 0x3,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    59
	INVALID_RAILTYPE = 0xFF,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    60
} RailType;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    61
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    62
enum {
2001
e23f26507476 (svn r2507) -Fix: Forgot to change an enum in rail.h in r2499 (thanks blathijs for
celestar
parents: 1967
diff changeset
    63
	SIG_SEMAPHORE_MASK = 1 << 3,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    64
};
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    65
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    66
/* These are used to specify a single track. Can be translated to a trackbit
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    67
 * with TrackToTrackbit */
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
    68
typedef enum Tracks {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    69
  TRACK_DIAG1 = 0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    70
  TRACK_DIAG2 = 1,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    71
  TRACK_UPPER = 2,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    72
  TRACK_LOWER = 3,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    73
  TRACK_LEFT  = 4,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    74
  TRACK_RIGHT = 5,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    75
  TRACK_END,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    76
  INVALID_TRACK = 0xFF,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    77
} Track;
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
/* These are the bitfield variants of the above */
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
    80
typedef enum TrackBits {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    81
  TRACK_BIT_DIAG1 = 1,  // 0
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    82
  TRACK_BIT_DIAG2 = 2,  // 1
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    83
  TRACK_BIT_UPPER = 4,  // 2
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    84
  TRACK_BIT_LOWER = 8,  // 3
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    85
  TRACK_BIT_LEFT  = 16, // 4
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    86
  TRACK_BIT_RIGHT = 32, // 5
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    87
	TRACK_BIT_MASK  = 0x3F,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    88
} TrackBits;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    89
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    90
/* These are a combination of tracks and directions. Values are 0-5 in one
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    91
direction (corresponding to the Track enum) and 8-13 in the other direction. */
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
typedef enum Trackdirs {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    93
  TRACKDIR_DIAG1_NE = 0,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    94
  TRACKDIR_DIAG2_SE = 1,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    95
  TRACKDIR_UPPER_E  = 2,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    96
  TRACKDIR_LOWER_E  = 3,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    97
  TRACKDIR_LEFT_S   = 4,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    98
  TRACKDIR_RIGHT_S  = 5,
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    99
	/* Note the two missing values here. This enables trackdir -> track
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   100
	 * conversion by doing (trackdir & 7) */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   101
  TRACKDIR_DIAG1_SW = 8,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   102
  TRACKDIR_DIAG2_NW = 9,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   103
  TRACKDIR_UPPER_W  = 10,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   104
  TRACKDIR_LOWER_W  = 11,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   105
  TRACKDIR_LEFT_N   = 12,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   106
  TRACKDIR_RIGHT_N  = 13,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   107
  TRACKDIR_END,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   108
  INVALID_TRACKDIR  = 0xFF,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   109
} Trackdir;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   110
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   111
/* These are a combination of tracks and directions. Values are 0-5 in one
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   112
direction (corresponding to the Track enum) and 8-13 in the other direction. */
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
   113
typedef enum TrackdirBits {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   114
  TRACKDIR_BIT_DIAG1_NE = 0x1,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   115
  TRACKDIR_BIT_DIAG2_SE = 0x2,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   116
  TRACKDIR_BIT_UPPER_E  = 0x4,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   117
  TRACKDIR_BIT_LOWER_E  = 0x8,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   118
  TRACKDIR_BIT_LEFT_S   = 0x10,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   119
  TRACKDIR_BIT_RIGHT_S  = 0x20,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   120
	/* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   121
  TRACKDIR_BIT_DIAG1_SW = 0x0100,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   122
  TRACKDIR_BIT_DIAG2_NW = 0x0200,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   123
  TRACKDIR_BIT_UPPER_W  = 0x0400,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   124
  TRACKDIR_BIT_LOWER_W  = 0x0800,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   125
  TRACKDIR_BIT_LEFT_N   = 0x1000,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   126
  TRACKDIR_BIT_RIGHT_N  = 0x2000,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   127
	TRACKDIR_BIT_MASK			= 0x3F3F,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   128
  INVALID_TRACKDIR_BIT  = 0xFFFF,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   129
} TrackdirBits;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   130
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   131
/* These are states in which a signal can be. Currently these are only two, so
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   132
 * simple boolean logic will do. But do try to compare to this enum instead of
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   133
 * normal boolean evaluation, since that will make future additions easier.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   134
 */
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
   135
typedef enum SignalStates {
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
   136
	SIGNAL_STATE_RED = 0,
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
   137
	SIGNAL_STATE_GREEN = 1,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   138
} SignalState;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   139
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
   140
// these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
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
   141
enum {
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
   142
	NUM_SSD_ENTRY = 256, // max amount of blocks
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
   143
	NUM_SSD_STACK = 32 ,// max amount of blocks to check recursively
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
   144
};
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   145
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   146
/**
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   147
 * Maps a Trackdir to the corresponding TrackdirBits value
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   148
 */
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   149
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   150
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   151
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   152
 * These functions check the validity of Tracks and Trackdirs. assert against
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   153
 * them when convenient.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   154
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   155
static inline bool IsValidTrack(Track track) { return track < TRACK_END; }
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   156
static inline bool IsValidTrackdir(Trackdir trackdir) { return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   157
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   158
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   159
 * Functions to map tracks to the corresponding bits in the signal
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   160
 * presence/status bytes in the map. You should not use these directly, but
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   161
 * wrapper functions below instead. XXX: Which are these?
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   162
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   163
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   164
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   165
 * 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
   166
 * direction along with the trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   167
 */
1947
32308520a356 (svn r2453) * CodeChange: Declared the lookup arrays in rail.h as extern, so the linker will complain if they are not defined (ie when rail.c is not included).
matthijs
parents: 1944
diff changeset
   168
extern const byte _signal_along_trackdir[TRACKDIR_END];
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   169
static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_trackdir[trackdir];}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   170
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   171
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   172
 * 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
   173
 * direction against the trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   174
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   175
static inline byte SignalAgainstTrackdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   176
	extern const byte _signal_against_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   177
	return _signal_against_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   178
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   179
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   180
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   181
 * 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
   182
 * be present on the given track.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   183
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   184
static inline byte SignalOnTrack(Track track) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   185
	extern const byte _signal_on_track[TRACK_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   186
	return _signal_on_track[track];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   187
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   188
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   189
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   190
 * Some functions to query rail tiles
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   191
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   192
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   193
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   194
 * Returns the RailTileType of a given rail tile. (ie normal, with signals,
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   195
 * depot, etc.)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   196
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   197
static inline RailTileType GetRailTileType(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   198
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   199
	assert(IsTileType(tile, MP_RAILWAY));
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: 2032
diff changeset
   200
	return (_m[tile].m5 & RAIL_TILE_TYPE_MASK);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   201
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   202
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   203
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   204
 * Returns the rail type of the given rail tile (ie rail, mono, maglev).
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   205
 */
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: 2032
diff changeset
   206
static inline RailType GetRailType(TileIndex tile) { return (RailType)(_m[tile].m3 & RAILTYPE_MASK); }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   207
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   208
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   209
 * Checks if a rail tile has signals.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   210
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   211
static inline bool HasSignals(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   212
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   213
	return GetRailTileType(tile) == RAIL_TYPE_SIGNALS;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   214
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   215
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   216
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   217
 * Returns the RailTileSubtype of a given rail tile with type
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   218
 * RAIL_TYPE_DEPOT_WAYPOINT
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   219
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   220
static inline RailTileSubtype GetRailTileSubtype(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   221
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   222
	assert(GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT);
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: 2032
diff changeset
   223
	return (RailTileSubtype)(_m[tile].m5 & RAIL_SUBTYPE_MASK);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   224
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   225
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   226
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   227
 * Returns whether this is plain rails, with or without signals. Iow, if this
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   228
 * tiles RailTileType is RAIL_TYPE_NORMAL or RAIL_TYPE_SIGNALS.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   229
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   230
static inline bool IsPlainRailTile(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   231
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   232
	RailTileType rtt = GetRailTileType(tile);
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   233
	return rtt == RAIL_TYPE_NORMAL || rtt == RAIL_TYPE_SIGNALS;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   234
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   235
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   236
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   237
 * Returns the tracks present on the given plain rail tile (IsPlainRailTile())
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   238
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   239
static inline TrackBits GetTrackBits(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   240
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   241
	assert(GetRailTileType(tile) == RAIL_TYPE_NORMAL || GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
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: 2032
diff changeset
   242
	return (TrackBits)(_m[tile].m5 & TRACK_BIT_MASK);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   243
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   244
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   245
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   246
 * Returns whether the given track is present on the given tile. Tile must be
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   247
 * a plain rail tile (IsPlainRailTile()).
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   248
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   249
static inline bool HasTrack(TileIndex tile, Track track)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   250
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   251
	assert(IsValidTrack(track));
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   252
	return HASBIT(GetTrackBits(tile), track);
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   253
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   254
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   255
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   256
 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   257
 * TrackdirBits, Direction and DiagDirections.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   258
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   259
 * TODO: Add #unndefs or something similar to remove the arrays used below
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   260
 * from the global scope and expose direct uses of them.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   261
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   262
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   263
/**
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
   264
 * Maps a trackdir to the reverse 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
   265
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   266
static inline Trackdir ReverseTrackdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   267
	extern const Trackdir _reverse_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   268
	return _reverse_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   269
}
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
   270
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
   271
/*
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
   272
 * Maps a Track to the corresponding TrackBits value
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
   273
 */
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
   274
static inline TrackBits TrackToTrackBits(Track track) { return (TrackBits)(1 << track); }
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
   275
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
   276
/* Returns the Track that a given Trackdir represents */
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
   277
static inline Track TrackdirToTrack(Trackdir trackdir) { return (Track)(trackdir & 0x7); }
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
   278
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
   279
/* Returns a Trackdir for the given Track. Since every Track corresponds to
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
   280
 * two Trackdirs, we choose the one which points between NE and S.
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
   281
 * Note that the actual implementation is quite futile, but this might change
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
   282
 * in the future.
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
   283
 */
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
   284
static inline Trackdir TrackToTrackdir(Track track) { return (Trackdir)track; }
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
   285
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
   286
/* Returns a TrackdirBit mask that contains the two TrackdirBits that
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
   287
 * correspond with the given Track (one for each direction).
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
   288
 */
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
   289
static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = TrackToTrackdir(track); return TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td));}
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
   290
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
   291
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   292
 * Maps a trackdir to the trackdir that you will end up on if you go straight
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   293
 * ahead. This will be the same trackdir for diagonal trackdirs, but a
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   294
 * different (alternating) one for straight trackdirs
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   295
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   296
static inline Trackdir NextTrackdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   297
	extern const Trackdir _next_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   298
	return _next_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   299
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   300
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   301
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   302
 * 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
   303
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   304
static inline TrackBits TrackCrossesTracks(Track track) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   305
	extern const TrackBits _track_crosses_tracks[TRACK_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   306
	return _track_crosses_tracks[track];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   307
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   308
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   309
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   310
 * 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
   311
 * that trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   312
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   313
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   314
	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   315
	return _trackdir_to_exitdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   316
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   317
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   318
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   319
 * Maps a track and an (4-way) dir to the trackdir that represents the track
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   320
 * with the exit in the given direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   321
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   322
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   323
	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   324
	return _track_exitdir_to_trackdir[track][diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   325
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   326
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   327
/**
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
   328
 * Maps a track and an (4-way) dir to the trackdir that represents the track
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
   329
 * with the exit in the given direction.
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
   330
 */
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
   331
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) {
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
   332
	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
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
   333
	return _track_enterdir_to_trackdir[track][diagdir];
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
   334
}
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
   335
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
   336
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   337
 * Maps a track and a full (8-way) direction to the trackdir that represents
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   338
 * the track running in the given direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   339
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   340
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   341
	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   342
	return _track_direction_to_trackdir[track][dir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   343
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   344
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   345
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   346
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   347
 * direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   348
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   349
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   350
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   351
	return _dir_to_diag_trackdir[diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   352
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   353
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   354
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   355
 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   356
 * entering the next tile. This
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   357
 */
1947
32308520a356 (svn r2453) * CodeChange: Declared the lookup arrays in rail.h as extern, so the linker will complain if they are not defined (ie when rail.c is not included).
matthijs
parents: 1944
diff changeset
   358
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   359
/* Note that there is no direct table for this function (there used to be),
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   360
 * but it uses two simpeler tables to achieve the result */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   361
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; }
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   362
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   363
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   364
 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   365
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   366
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   367
	extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   368
	return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   369
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   370
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   371
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   372
 * Maps a (4-way) direction to the reverse.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   373
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   374
static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   375
	extern const DiagDirection _reverse_diagdir[DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   376
	return _reverse_diagdir[diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   377
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   378
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
   379
/**
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
   380
 * Maps a (8-way) direction to a (4-way) DiagDirection
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
   381
 */
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
   382
static inline DiagDirection DirToDiagdir(Direction dir) {
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
   383
	assert(dir < DIR_END);
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
   384
	return (DiagDirection)(dir >> 1);
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
   385
}
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
   386
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   387
/* Checks if a given Track is diagonal */
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
   388
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_DIAG1) || (track == TRACK_DIAG2); }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   389
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   390
/* Checks if a given Trackdir is diagonal. */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   391
static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); }
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   392
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   393
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   394
 * Functions quering signals on tiles.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   395
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   396
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   397
/**
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
   398
 * Checks for the presence of signals (either way) on the given track on the
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
   399
 * given rail tile.
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   400
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   401
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   402
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   403
	assert(IsValidTrack(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: 2032
diff changeset
   404
	return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_m[tile].m3 & SignalOnTrack(track)) != 0));
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
   405
}
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
   406
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
   407
/**
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
   408
 * Checks for the presence of signals along the given trackdir on the given
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
   409
 * rail tile.
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
   410
 *
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
   411
 * Along meaning if you are currently driving on the given trackdir, this is
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
   412
 * the signal that is facing us (for which we stop when it's red).
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
   413
 */
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
   414
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir 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
   415
{
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
   416
	assert (IsValidTrackdir(trackdir));
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: 2032
diff changeset
   417
	return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_m[tile].m3 & SignalAlongTrackdir(trackdir));
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   418
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   419
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   420
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   421
 * Gets the state of the signal along the given trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   422
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   423
 * Along meaning if you are currently driving on the given trackdir, this is
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   424
 * the signal that is facing us (for which we stop when it's red).
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   425
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   426
static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   427
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   428
	assert(IsValidTrackdir(trackdir));
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   429
	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
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: 2032
diff changeset
   430
	return ((_m[tile].m2 & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   431
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   432
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   433
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   434
 * Gets the type of signal on a given track on a given rail tile with signals.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   435
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   436
 * Note that currently, the track argument is not used, since
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   437
 * signal types cannot be mixed. This function is trying to be
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   438
 * future-compatible, though.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   439
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   440
static inline SignalType GetSignalType(TileIndex tile, Track track)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   441
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   442
	assert(IsValidTrack(track));
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   443
	assert(GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
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: 2032
diff changeset
   444
	return (SignalType)(_m[tile].m4 & SIGTYPE_MASK);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   445
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   446
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   447
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   448
 * Checks if this tile contains semaphores (returns true) or normal signals
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   449
 * (returns false) on the given track. Does not check if there are actually
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   450
 * signals on the track, you should use HasSignalsOnTrack() for that.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   451
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   452
 * Note that currently, the track argument is not used, since
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   453
 * semaphores/electric signals cannot be mixed. This function is trying to be
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   454
 * future-compatible, though.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   455
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   456
static inline bool HasSemaphores(TileIndex tile, Track track)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   457
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   458
	assert(IsValidTrack(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: 2032
diff changeset
   459
	return (_m[tile].m4 & SIG_SEMAPHORE_MASK);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   460
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   461
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   462
/**
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   463
 * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   464
 * Note that there is no check if the given trackdir is actually present on
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   465
 * the tile!
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   466
 * The given trackdir is used when there are (could be) multiple rail types on
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   467
 * one tile.
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   468
 */
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   469
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
   470
1967
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   471
/**
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   472
 * Returns whether the given tile is a level crossing.
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   473
 */
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   474
static inline bool IsLevelCrossing(TileIndex tile)
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   475
{
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: 2032
diff changeset
   476
	return (_m[tile].m5 & 0xF0) == 0x10;
1967
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   477
}
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   478
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   479
/**
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   480
 * Gets the transport type of the given track on the given crossing tile.
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   481
 * @return  The transport type of the given track, either TRANSPORT_ROAD,
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   482
 * TRANSPORT_RAIL.
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   483
 */
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   484
static inline TransportType GetCrossingTransportType(TileIndex tile, Track track)
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   485
{
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   486
	/* XXX: Nicer way to write this? */
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   487
	switch(track)
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   488
	{
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   489
		/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   490
		case TRACK_DIAG1:
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: 2032
diff changeset
   491
			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
1967
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   492
		case TRACK_DIAG2:
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: 2032
diff changeset
   493
			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL);
1967
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   494
		default:
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   495
			assert(0);
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   496
	}
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   497
	return INVALID_TRANSPORT;
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   498
}
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   499
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   500
/**
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   501
 * Checks if an engine of the given RailType can drive on a tile with a given
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   502
 * RailType. This would normally just be an equality check, but for electric
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   503
 * rails (which also support non-electric engines).
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   504
 * @return Whether the engine can drive on this tile.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   505
 * @param  enginetype The RailType of the engine we are considering.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   506
 * @param  tiletype   The RailType of the tile we are considering.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   507
 */
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   508
static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   509
{
2032
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   510
	static const bool EquivRailTypes[RAILTYPE_END][RAILTYPE_END] = {
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   511
	{ true, false, false },
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   512
	{ false, true, false },
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   513
	{ false, false, true },
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   514
	};
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   515
25f8f4da05a0 (svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents: 2008
diff changeset
   516
	return EquivRailTypes[enginetype][tiletype];
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   517
}
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   518
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   519
#endif // RAIL_H