rail.h
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 9928 cc7b6d3bea3e
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
     3
/** @file rail.h */
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
     4
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     5
#ifndef RAIL_H
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     6
#define RAIL_H
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     7
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     8
#include "tile.h"
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     9
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    10
/*
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    11
 * Some enums for accesing the map bytes for rail tiles
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    12
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    13
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    14
/** These types are used in the map5 byte for rail tiles. Use GetRailTileType() to
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    15
 * get these values */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    16
typedef enum RailTileTypes {
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    17
	RAIL_TYPE_NORMAL         = 0x0,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    18
	RAIL_TYPE_SIGNALS        = 0x40,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    19
	RAIL_TYPE_UNUSED         = 0x80, /* XXX: Maybe this could become waypoints? */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    20
	RAIL_TYPE_DEPOT_WAYPOINT = 0xC0, /* Is really depots and waypoints... */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    21
	RAIL_TILE_TYPE_MASK      = 0xC0,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    22
} RailTileType;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    23
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    24
enum { /* DEPRECATED TODO: Rewrite all uses of this */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    25
	RAIL_TYPE_SPECIAL = 0x80, /* This used to say "If this bit is set, then it's
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    26
														 * not a regular track.", but currently, you
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    27
														 * should rather view map5[6..7] as one type,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    28
														 * containing a value from RailTileTypes above.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    29
														 * This value is only maintained for backwards
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    30
														 * compatibility */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    31
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    32
	/* There used to be RAIL_BIT_* enums here, they moved to (for now) npf.c as
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    33
	 * TRACK_BIT_* */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    34
};
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    35
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    36
/** These subtypes are used in the map5 byte when the main rail type is
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    37
 * RAIL_TYPE_DEPOT_WAYPOINT */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    38
typedef enum RailTileSubtypes {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    39
	RAIL_SUBTYPE_DEPOT    = 0x00,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    40
	RAIL_SUBTYPE_WAYPOINT = 0x04,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    41
	RAIL_SUBTYPE_MASK     = 0x3C,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    42
} RailTileSubtype;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    43
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    44
typedef enum SignalTypes {
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
    45
	/* Stored in m4[0..1] for MP_RAILWAY */
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    46
	SIGTYPE_NORMAL  = 0,        // normal signal
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    47
	SIGTYPE_ENTRY   = 1,        // presignal block entry
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    48
	SIGTYPE_EXIT    = 2,        // presignal block exit
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    49
	SIGTYPE_COMBO   = 3,        // presignal inter-block
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    50
	SIGTYPE_END,
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
    51
	SIGTYPE_MASK    = 3,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    52
} SignalType;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    53
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    54
typedef enum RailTypes {
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    55
	RAILTYPE_RAIL   = 0,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    56
	RAILTYPE_MONO   = 1,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    57
	RAILTYPE_MAGLEV = 2,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    58
	RAILTYPE_END,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    59
	RAILTYPE_MASK   = 0x3,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    60
	INVALID_RAILTYPE = 0xFF,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    61
} RailType;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    62
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    63
enum {
2916
8f1aa489701f (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2911
diff changeset
    64
	SIG_SEMAPHORE_MASK = 1 << 2,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    65
};
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    66
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    67
/** These are used to specify a single track. Can be translated to a trackbit
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    68
 * with TrackToTrackbit */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    69
typedef enum Tracks {
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    70
	TRACK_DIAG1 = 0,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    71
	TRACK_DIAG2 = 1,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    72
	TRACK_UPPER = 2,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    73
	TRACK_LOWER = 3,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    74
	TRACK_LEFT  = 4,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    75
	TRACK_RIGHT = 5,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    76
	TRACK_END,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    77
	INVALID_TRACK = 0xFF,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    78
} Track;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    79
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    80
/** These are the bitfield variants of the above */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    81
typedef enum TrackBits {
2890
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    82
	TRACK_BIT_DIAG1 = 1U,    // 0
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    83
	TRACK_BIT_DIAG2 = 2U,    // 1
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    84
	TRACK_BIT_UPPER = 4U,    // 2
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    85
	TRACK_BIT_LOWER = 8U,    // 3
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    86
	TRACK_BIT_LEFT  = 16U,   // 4
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    87
	TRACK_BIT_RIGHT = 32U,   // 5
7b97d5eff224 (svn r3443) - Fix signed/unsigned comparison warning when compiling with gcc 2.95 (tokai)
peter1138
parents: 2817
diff changeset
    88
	TRACK_BIT_MASK  = 0x3FU,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    89
} TrackBits;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    90
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
    91
/** These are a combination of tracks and directions. Values are 0-5 in one
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    92
direction (corresponding to the Track enum) and 8-13 in the other direction. */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    93
typedef enum Trackdirs {
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    94
	TRACKDIR_DIAG1_NE = 0,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    95
	TRACKDIR_DIAG2_SE = 1,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    96
	TRACKDIR_UPPER_E  = 2,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    97
	TRACKDIR_LOWER_E  = 3,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    98
	TRACKDIR_LEFT_S   = 4,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    99
	TRACKDIR_RIGHT_S  = 5,
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   100
	/* Note the two missing values here. This enables trackdir -> track
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   101
	 * conversion by doing (trackdir & 7) */
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   102
	TRACKDIR_DIAG1_SW = 8,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   103
	TRACKDIR_DIAG2_NW = 9,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   104
	TRACKDIR_UPPER_W  = 10,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   105
	TRACKDIR_LOWER_W  = 11,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   106
	TRACKDIR_LEFT_N   = 12,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   107
	TRACKDIR_RIGHT_N  = 13,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   108
	TRACKDIR_END,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   109
	INVALID_TRACKDIR  = 0xFF,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   110
} Trackdir;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   111
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
   112
/** These are a combination of tracks and directions. Values are 0-5 in one
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   113
direction (corresponding to the Track enum) and 8-13 in the other direction. */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   114
typedef enum TrackdirBits {
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   115
	TRACKDIR_BIT_DIAG1_NE = 0x1,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   116
	TRACKDIR_BIT_DIAG2_SE = 0x2,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   117
	TRACKDIR_BIT_UPPER_E  = 0x4,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   118
	TRACKDIR_BIT_LOWER_E  = 0x8,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   119
	TRACKDIR_BIT_LEFT_S   = 0x10,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   120
	TRACKDIR_BIT_RIGHT_S  = 0x20,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   121
	/* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   122
	TRACKDIR_BIT_DIAG1_SW = 0x0100,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   123
	TRACKDIR_BIT_DIAG2_NW = 0x0200,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   124
	TRACKDIR_BIT_UPPER_W  = 0x0400,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   125
	TRACKDIR_BIT_LOWER_W  = 0x0800,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   126
	TRACKDIR_BIT_LEFT_N   = 0x1000,
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   127
	TRACKDIR_BIT_RIGHT_N  = 0x2000,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   128
	TRACKDIR_BIT_MASK			= 0x3F3F,
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   129
	INVALID_TRACKDIR_BIT  = 0xFFFF,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   130
} TrackdirBits;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   131
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
   132
/** These are states in which a signal can be. Currently these are only two, so
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   133
 * simple boolean logic will do. But do try to compare to this enum instead of
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   134
 * normal boolean evaluation, since that will make future additions easier.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   135
 */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   136
typedef enum SignalStates {
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   137
	SIGNAL_STATE_RED = 0,
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   138
	SIGNAL_STATE_GREEN = 1,
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   139
} SignalState;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   140
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   141
/** This struct contains all the info that is needed to draw and construct tracks.
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   142
 */
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   143
typedef struct RailtypeInfo {
2274
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   144
	/** Struct containing the main sprites. @note not all sprites are listed, but only
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   145
	 *  the ones used directly in the code */
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   146
	struct {
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   147
		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   148
		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   149
		SpriteID ground;       ///< ground sprite for a 3-way switch
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   150
		SpriteID single_y;     ///< single piece of rail in Y direction, without ground
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   151
		SpriteID single_x;     ///< single piece of rail in X direction
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   152
		SpriteID single_n;     ///< single piece of rail in the northern corner
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   153
		SpriteID single_s;     ///< single piece of rail in the southern corner
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   154
		SpriteID single_e;     ///< single piece of rail in the eastern corner
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   155
		SpriteID single_w;     ///< single piece of rail in the western corner
2511
0a81d9ca79bc (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2472
diff changeset
   156
		SpriteID crossing;     ///< level crossing, rail in X direction
0a81d9ca79bc (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2472
diff changeset
   157
		SpriteID tunnel;       ///< tunnel sprites base
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   158
	} base_sprites;
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   159
2274
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   160
	/** struct containing the sprites for the rail GUI. @note only sprites referred to
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   161
	 * directly in the code are listed */
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   162
	struct {
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   163
		SpriteID build_ns_rail;      ///< button for building single rail in N-S direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   164
		SpriteID build_x_rail;       ///< button for building single rail in X direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   165
		SpriteID build_ew_rail;      ///< button for building single rail in E-W direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   166
		SpriteID build_y_rail;       ///< button for building single rail in Y direction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   167
		SpriteID auto_rail;          ///< button for the autorail construction
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   168
		SpriteID build_depot;        ///< button for building depots
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   169
		SpriteID build_tunnel;       ///< button for building a tunnel
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   170
		SpriteID convert_rail;       ///< button for converting rail
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   171
	} gui_sprites;
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   172
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   173
	struct {
2514
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   174
		CursorID rail_ns;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   175
		CursorID rail_swne;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   176
		CursorID rail_ew;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   177
		CursorID rail_nwse;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   178
		CursorID autorail;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   179
		CursorID depot;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   180
		CursorID tunnel;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   181
		CursorID convert;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   182
	} cursor;
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   183
8887b1f005c7 (svn r3040) Don't deduce the cursor sprites when building rails from magic numbers, but fetch them from the central rail info array.
tron
parents: 2511
diff changeset
   184
	struct {
2274
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   185
		StringID toolbar_caption;
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   186
	} strings;
d94004c14b6c (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
   187
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   188
	/** sprite number difference between a piece of track on a snowy ground and the corresponding one on normal ground */
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   189
	SpriteID snow_offset;
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   190
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   191
	/** bitmask to the OTHER railtypes that can be used by an engine of THIS railtype */
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   192
	byte compatible_railtypes;
2254
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   193
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   194
	/**
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   195
	 * Offset between the current railtype and normal rail. This means that:<p>
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   196
	 * 1) All the sprites in a railset MUST be in the same order. This order
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   197
	 *    is determined by normal rail. Check sprites 1005 and following for this order<p>
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   198
	 * 2) The position where the railtype is loaded must always be the same, otherwise
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   199
	 *    the offset will fail.<p>
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   200
	 * @note: Something more flexible might be desirable in the future.
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   201
	 */
72f8883ff3ac (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   202
	SpriteID total_offset;
2536
8c4e298f4886 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   203
8c4e298f4886 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   204
	/**
8c4e298f4886 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   205
	  * Bridge offset
8c4e298f4886 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   206
	  */
8c4e298f4886 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   207
	SpriteID bridge_offset;
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   208
} RailtypeInfo;
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   209
2236
55f4d7353f52 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   210
extern const RailtypeInfo _railtypes[RAILTYPE_END];
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   211
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   212
// these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   213
enum {
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   214
	NUM_SSD_ENTRY = 256, // max amount of blocks
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   215
	NUM_SSD_STACK = 32 ,// max amount of blocks to check recursively
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   216
};
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   217
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   218
/**
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   219
 * Maps a Trackdir to the corresponding TrackdirBits value
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   220
 */
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   221
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   222
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
   223
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   224
 * These functions check the validity of Tracks and Trackdirs. assert against
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   225
 * them when convenient.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   226
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   227
static inline bool IsValidTrack(Track track) { return track < TRACK_END; }
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   228
static inline bool IsValidTrackdir(Trackdir trackdir) { return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; }
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   229
2232
0c63dce21e30 (svn r2752) -Doc: Added some doxygen stuff to rail.h. I'm gonna mess around with this file and wanted to get rid of this first
celestar
parents: 2186
diff changeset
   230
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   231
 * Functions to map tracks to the corresponding bits in the signal
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   232
 * presence/status bytes in the map. You should not use these directly, but
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   233
 * wrapper functions below instead. XXX: Which are these?
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   234
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   235
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   236
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   237
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   238
 * direction along with the trackdir.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   239
 */
1947
9ee32f167208 (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
   240
extern const byte _signal_along_trackdir[TRACKDIR_END];
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   241
static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_trackdir[trackdir];}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   242
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   243
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   244
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   245
 * direction against the trackdir.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   246
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   247
static inline byte SignalAgainstTrackdir(Trackdir trackdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   248
	extern const byte _signal_against_trackdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   249
	return _signal_against_trackdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   250
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   251
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   252
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   253
 * Maps a Track to the bits that store the status of the two signals that can
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   254
 * be present on the given track.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   255
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   256
static inline byte SignalOnTrack(Track track) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   257
	extern const byte _signal_on_track[TRACK_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   258
	return _signal_on_track[track];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   259
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   260
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   261
/*
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   262
 * Some functions to query rail tiles
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   263
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   264
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   265
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   266
 * Returns the RailTileType of a given rail tile. (ie normal, with signals,
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   267
 * depot, etc.)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   268
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   269
static inline RailTileType GetRailTileType(TileIndex tile)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   270
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   271
	assert(IsTileType(tile, MP_RAILWAY));
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
   272
	return _m[tile].m5 & RAIL_TILE_TYPE_MASK;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   273
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   274
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   275
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   276
 * Returns the rail type of the given rail tile (ie rail, mono, maglev).
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   277
 */
2049
ad0d49c916d4 (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
   278
static inline RailType GetRailType(TileIndex tile) { return (RailType)(_m[tile].m3 & RAILTYPE_MASK); }
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   279
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   280
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   281
 * Checks if a rail tile has signals.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   282
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   283
static inline bool HasSignals(TileIndex tile)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   284
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   285
	return GetRailTileType(tile) == RAIL_TYPE_SIGNALS;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   286
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   287
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   288
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   289
 * Returns the RailTileSubtype of a given rail tile with type
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   290
 * RAIL_TYPE_DEPOT_WAYPOINT
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   291
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   292
static inline RailTileSubtype GetRailTileSubtype(TileIndex tile)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   293
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   294
	assert(GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT);
2049
ad0d49c916d4 (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
   295
	return (RailTileSubtype)(_m[tile].m5 & RAIL_SUBTYPE_MASK);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   296
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   297
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   298
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   299
 * Returns whether this is plain rails, with or without signals. Iow, if this
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   300
 * tiles RailTileType is RAIL_TYPE_NORMAL or RAIL_TYPE_SIGNALS.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   301
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   302
static inline bool IsPlainRailTile(TileIndex tile)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   303
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   304
	RailTileType rtt = GetRailTileType(tile);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   305
	return rtt == RAIL_TYPE_NORMAL || rtt == RAIL_TYPE_SIGNALS;
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   306
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   307
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   308
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   309
 * Returns the tracks present on the given plain rail tile (IsPlainRailTile())
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   310
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   311
static inline TrackBits GetTrackBits(TileIndex tile)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   312
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   313
	assert(GetRailTileType(tile) == RAIL_TYPE_NORMAL || GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
2049
ad0d49c916d4 (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
   314
	return (TrackBits)(_m[tile].m5 & TRACK_BIT_MASK);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   315
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   316
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   317
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   318
 * Returns whether the given track is present on the given tile. Tile must be
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   319
 * a plain rail tile (IsPlainRailTile()).
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   320
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   321
static inline bool HasTrack(TileIndex tile, Track track)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   322
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   323
	assert(IsValidTrack(track));
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   324
	return HASBIT(GetTrackBits(tile), track);
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   325
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   326
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   327
/*
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   328
 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   329
 * TrackdirBits, Direction and DiagDirections.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   330
 *
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   331
 * TODO: Add #unndefs or something similar to remove the arrays used below
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   332
 * from the global scope and expose direct uses of them.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   333
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   334
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   335
/**
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   336
 * Maps a trackdir to the reverse trackdir.
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   337
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   338
static inline Trackdir ReverseTrackdir(Trackdir trackdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   339
	extern const Trackdir _reverse_trackdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   340
	return _reverse_trackdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   341
}
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   342
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   343
/**
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   344
 * Maps a Track to the corresponding TrackBits value
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   345
 */
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   346
static inline TrackBits TrackToTrackBits(Track track) { return (TrackBits)(1 << track); }
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   347
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   348
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   349
 * Returns the Track that a given Trackdir represents
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   350
 */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   351
static inline Track TrackdirToTrack(Trackdir trackdir) { return (Track)(trackdir & 0x7); }
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   352
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   353
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   354
 * Returns a Trackdir for the given Track. Since every Track corresponds to
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   355
 * two Trackdirs, we choose the one which points between NE and S.
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   356
 * Note that the actual implementation is quite futile, but this might change
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   357
 * in the future.
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   358
 */
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   359
static inline Trackdir TrackToTrackdir(Track track) { return (Trackdir)track; }
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   360
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   361
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   362
 * Returns a TrackdirBit mask that contains the two TrackdirBits that
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   363
 * correspond with the given Track (one for each direction).
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   364
 */
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   365
static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = TrackToTrackdir(track); return TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td));}
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   366
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   367
/**
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   368
 * Discards all directional information from the given TrackdirBits. Any
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   369
 * Track which is present in either direction will be present in the result.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   370
 */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   371
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) { return bits | (bits >> 8); }
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   372
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   373
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   374
 * Maps a trackdir to the trackdir that you will end up on if you go straight
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   375
 * ahead. This will be the same trackdir for diagonal trackdirs, but a
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   376
 * different (alternating) one for straight trackdirs
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   377
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   378
static inline Trackdir NextTrackdir(Trackdir trackdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   379
	extern const Trackdir _next_trackdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   380
	return _next_trackdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   381
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   382
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   383
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   384
 * Maps a track to all tracks that make 90 deg turns with it.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   385
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   386
static inline TrackBits TrackCrossesTracks(Track track) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   387
	extern const TrackBits _track_crosses_tracks[TRACK_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   388
	return _track_crosses_tracks[track];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   389
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   390
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   391
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   392
 * Maps a trackdir to the (4-way) direction the tile is exited when following
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   393
 * that trackdir.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   394
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   395
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   396
	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   397
	return _trackdir_to_exitdir[trackdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   398
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   399
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   400
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   401
 * Maps a track and an (4-way) dir to the trackdir that represents the track
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   402
 * with the exit in the given direction.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   403
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   404
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   405
	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   406
	return _track_exitdir_to_trackdir[track][diagdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   407
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   408
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   409
/**
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   410
 * Maps a track and an (4-way) dir to the trackdir that represents the track
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   411
 * with the exit in the given direction.
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   412
 */
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   413
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) {
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   414
	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   415
	return _track_enterdir_to_trackdir[track][diagdir];
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   416
}
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   417
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   418
/**
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   419
 * Maps a track and a full (8-way) direction to the trackdir that represents
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   420
 * the track running in the given direction.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   421
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   422
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   423
	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   424
	return _track_direction_to_trackdir[track][dir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   425
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   426
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   427
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   428
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   429
 * direction.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   430
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   431
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   432
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   433
	return _dir_to_diag_trackdir[diagdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   434
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   435
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   436
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   437
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   438
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   439
 * Returns all trackdirs that can be reached when entering a tile from a given
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   440
 * (diagonal) direction. This will obviously include 90 degree turns, since no
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   441
 * information is available about the exact angle of entering */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   442
static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) { return _exitdir_reaches_trackdirs[diagdir]; }
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   443
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   444
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   445
 * Returns all tracks that can be reached when entering a tile from a given
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   446
 * (diagonal) direction. This will obviously include 90 degree turns, since no
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   447
 * information is available about the exact angle of entering */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   448
static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   449
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   450
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   451
 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   452
 * entering the next tile. This will include 90 degree turns!
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   453
 */
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   454
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; }
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   455
/* Note that there is no direct table for this function (there used to be),
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   456
 * but it uses two simpeler tables to achieve the result */
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   457
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   458
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   459
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   460
 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   461
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   462
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   463
	extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   464
	return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   465
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   466
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   467
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   468
 * Maps a (4-way) direction to the reverse.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   469
 */
1948
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   470
static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) {
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   471
	extern const DiagDirection _reverse_diagdir[DIAGDIR_END];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   472
	return _reverse_diagdir[diagdir];
e5f34b543a3c (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   473
}
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   474
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   475
/**
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   476
 * Maps a (8-way) direction to a (4-way) DiagDirection
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   477
 */
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   478
static inline DiagDirection DirToDiagdir(Direction dir) {
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   479
	assert(dir < DIR_END);
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   480
	return (DiagDirection)(dir >> 1);
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   481
}
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   482
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   483
/* Checks if a given Track is diagonal */
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   484
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_DIAG1) || (track == TRACK_DIAG2); }
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   485
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   486
/* Checks if a given Trackdir is diagonal. */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   487
static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); }
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   488
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   489
/*
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   490
 * Functions quering signals on tiles.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   491
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   492
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   493
/**
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   494
 * Checks for the presence of signals (either way) on the given track on the
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   495
 * given rail tile.
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   496
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   497
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   498
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   499
	assert(IsValidTrack(track));
2049
ad0d49c916d4 (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
   500
	return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_m[tile].m3 & SignalOnTrack(track)) != 0));
1944
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   501
}
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   502
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   503
/**
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   504
 * Checks for the presence of signals along the given trackdir on the given
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   505
 * rail tile.
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   506
 *
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   507
 * Along meaning if you are currently driving on the given trackdir, this is
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   508
 * the signal that is facing us (for which we stop when it's red).
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   509
 */
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   510
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   511
{
012fa5e69118 (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   512
	assert (IsValidTrackdir(trackdir));
2049
ad0d49c916d4 (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
   513
	return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_m[tile].m3 & SignalAlongTrackdir(trackdir));
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   514
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   515
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   516
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   517
 * Gets the state of the signal along the given trackdir.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   518
 *
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   519
 * Along meaning if you are currently driving on the given trackdir, this is
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   520
 * the signal that is facing us (for which we stop when it's red).
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   521
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   522
static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   523
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   524
	assert(IsValidTrackdir(trackdir));
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   525
	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
2049
ad0d49c916d4 (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
   526
	return ((_m[tile].m2 & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   527
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   528
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   529
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   530
 * Gets the type of signal on a given track on a given rail tile with signals.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   531
 *
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   532
 * Note that currently, the track argument is not used, since
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   533
 * signal types cannot be mixed. This function is trying to be
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   534
 * future-compatible, though.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   535
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   536
static inline SignalType GetSignalType(TileIndex tile, Track track)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   537
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   538
	assert(IsValidTrack(track));
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   539
	assert(GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
2049
ad0d49c916d4 (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
   540
	return (SignalType)(_m[tile].m4 & SIGTYPE_MASK);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   541
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   542
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   543
/**
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   544
 * Checks if this tile contains semaphores (returns true) or normal signals
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   545
 * (returns false) on the given track. Does not check if there are actually
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   546
 * signals on the track, you should use HasSignalsOnTrack() for that.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   547
 *
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   548
 * Note that currently, the track argument is not used, since
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   549
 * semaphores/electric signals cannot be mixed. This function is trying to be
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   550
 * future-compatible, though.
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   551
 */
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   552
static inline bool HasSemaphores(TileIndex tile, Track track)
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   553
{
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   554
	assert(IsValidTrack(track));
9928
cc7b6d3bea3e (svn r3958) Change HASBIT() to return 0/1 instead of 0/value of tested bit. Backport of r3747 from trunk
Darkvater
parents: 2916
diff changeset
   555
	return (_m[tile].m4 & SIG_SEMAPHORE_MASK) != 0;
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   556
}
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   557
1950
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   558
/**
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   559
 * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   560
 * Note that there is no check if the given trackdir is actually present on
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   561
 * the tile!
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   562
 * The given trackdir is used when there are (could be) multiple rail types on
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   563
 * one tile.
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   564
 */
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   565
RailType GetTileRailType(TileIndex tile, Trackdir trackdir);
1950
6e4d384034d9 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   566
1967
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   567
/**
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   568
 * Returns whether the given tile is a level crossing.
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   569
 */
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   570
static inline bool IsLevelCrossing(TileIndex tile)
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   571
{
2049
ad0d49c916d4 (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
   572
	return (_m[tile].m5 & 0xF0) == 0x10;
1967
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   573
}
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   574
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   575
/**
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   576
 * Gets the transport type of the given track on the given crossing tile.
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   577
 * @return  The transport type of the given track, either TRANSPORT_ROAD,
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   578
 * TRANSPORT_RAIL.
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   579
 */
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   580
static inline TransportType GetCrossingTransportType(TileIndex tile, Track track)
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   581
{
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   582
	/* XXX: Nicer way to write this? */
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   583
	switch(track)
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   584
	{
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   585
		/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   586
		case TRACK_DIAG1:
2049
ad0d49c916d4 (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
   587
			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
1967
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   588
		case TRACK_DIAG2:
2049
ad0d49c916d4 (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
   589
			return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL);
1967
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   590
		default:
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   591
			assert(0);
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   592
	}
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   593
	return INVALID_TRANSPORT;
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   594
}
c57192f4c121 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   595
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   596
/**
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   597
 * Returns a pointer to the Railtype information for a given railtype
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   598
 * @param railtype the rail type which the information is requested for
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   599
 * @return The pointer to the RailtypeInfo
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   600
 */
2236
55f4d7353f52 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   601
static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   602
{
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   603
	assert(railtype < RAILTYPE_END);
2236
55f4d7353f52 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   604
	return &_railtypes[railtype];
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   605
}
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   606
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   607
/**
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   608
 * Checks if an engine of the given RailType can drive on a tile with a given
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   609
 * RailType. This would normally just be an equality check, but for electric
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   610
 * rails (which also support non-electric engines).
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   611
 * @return Whether the engine can drive on this tile.
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   612
 * @param  enginetype The RailType of the engine we are considering.
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   613
 * @param  tiletype   The RailType of the tile we are considering.
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   614
 */
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   615
static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   616
{
2233
146e2e405ec1 (svn r2753) -Codechange: Introduced a new struct "RailtypeInfo" to store rail type specific information. Begun populating it with a bunch of sprites, more to come later. This should result in cleaner, more compact code which allows easy introduction of new railtypes.
celestar
parents: 2232
diff changeset
   617
	return HASBIT(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   618
}
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   619
2782
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   620
/**
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   621
 * Checks if the given tracks overlap, ie form a crossing. Basically this
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   622
 * means when there is more than one track on the tile, exept when there are
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   623
 * two parallel tracks.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   624
 * @param  bits The tracks present.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   625
 * @return Whether the tracks present overlap in any way.
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   626
 */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   627
static inline bool TracksOverlap(TrackBits bits)
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   628
{
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   629
  /* With no, or only one track, there is no overlap */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   630
  if (bits == 0 || KILL_FIRST_BIT(bits) == 0)
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   631
    return false;
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   632
  /* We know that there are at least two tracks present. When there are more
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   633
   * than 2 tracks, they will surely overlap. When there are two, they will
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   634
   * always overlap unless they are lower & upper or right & left. */
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   635
  if ((bits == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) || (bits == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)))
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   636
    return false;
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   637
  return true;
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   638
}
b8453c2cb0ed (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   639
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   640
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   641
void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
2536
8c4e298f4886 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2520
diff changeset
   642
#endif /* RAIL_H */