rail.h
author tron
Sun, 23 Apr 2006 13:48:16 +0000
changeset 3636 a36cc46e754d
parent 3575 f5b56bd958c0
child 3772 f2cf079d7afe
permissions -rw-r--r--
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2049
diff changeset
     2
2232
2a0d0328ebbe (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 */
2a0d0328ebbe (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
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     5
#ifndef RAIL_H
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     6
#define RAIL_H
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
     7
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents: 3132
diff changeset
     8
#include "direction.h"
3239
9b1030ac7d83 (svn r3913) Move declarations to rail_map.h so rail.h is dependent on rail_map.h and not the other way round
tron
parents: 3238
diff changeset
     9
#include "rail_map.h"
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    10
#include "tile.h"
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    11
2232
2a0d0328ebbe (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
    12
/** These are a combination of tracks and directions. Values are 0-5 in one
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    13
direction (corresponding to the Track enum) and 8-13 in the other direction. */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    14
typedef enum Trackdirs {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    15
	TRACKDIR_X_NE = 0,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    16
	TRACKDIR_Y_SE = 1,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    17
	TRACKDIR_UPPER_E  = 2,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    18
	TRACKDIR_LOWER_E  = 3,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    19
	TRACKDIR_LEFT_S   = 4,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    20
	TRACKDIR_RIGHT_S  = 5,
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    21
	/* Note the two missing values here. This enables trackdir -> track
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
    22
	 * conversion by doing (trackdir & 7) */
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    23
	TRACKDIR_X_SW = 8,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    24
	TRACKDIR_Y_NW = 9,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    25
	TRACKDIR_UPPER_W  = 10,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    26
	TRACKDIR_LOWER_W  = 11,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    27
	TRACKDIR_LEFT_N   = 12,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    28
	TRACKDIR_RIGHT_N  = 13,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    29
	TRACKDIR_END,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    30
	INVALID_TRACKDIR  = 0xFF,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    31
} Trackdir;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    32
2232
2a0d0328ebbe (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
    33
/** These are a combination of tracks and directions. Values are 0-5 in one
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    34
direction (corresponding to the Track enum) and 8-13 in the other direction. */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
    35
typedef enum TrackdirBits {
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    36
	TRACKDIR_BIT_X_NE     = 0x1,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    37
	TRACKDIR_BIT_Y_SE     = 0x2,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    38
	TRACKDIR_BIT_UPPER_E  = 0x4,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    39
	TRACKDIR_BIT_LOWER_E  = 0x8,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    40
	TRACKDIR_BIT_LEFT_S   = 0x10,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    41
	TRACKDIR_BIT_RIGHT_S  = 0x20,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    42
	/* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    43
	TRACKDIR_BIT_X_SW     = 0x0100,
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
    44
	TRACKDIR_BIT_Y_NW     = 0x0200,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    45
	TRACKDIR_BIT_UPPER_W  = 0x0400,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    46
	TRACKDIR_BIT_LOWER_W  = 0x0800,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    47
	TRACKDIR_BIT_LEFT_N   = 0x1000,
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    48
	TRACKDIR_BIT_RIGHT_N  = 0x2000,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    49
	TRACKDIR_BIT_MASK			= 0x3F3F,
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2536
diff changeset
    50
	INVALID_TRACKDIR_BIT  = 0xFFFF,
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    51
} TrackdirBits;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
    52
2233
ee31c1e1477c (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
    53
/** This struct contains all the info that is needed to draw and construct tracks.
ee31c1e1477c (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
    54
 */
ee31c1e1477c (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
    55
typedef struct RailtypeInfo {
2274
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    56
	/** Struct containing the main sprites. @note not all sprites are listed, but only
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    57
	 *  the ones used directly in the code */
2233
ee31c1e1477c (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
    58
	struct {
ee31c1e1477c (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
    59
		SpriteID track_y;      ///< single piece of rail in Y direction, with ground
ee31c1e1477c (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
    60
		SpriteID track_ns;     ///< two pieces of rail in North and South corner (East-West direction)
ee31c1e1477c (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
    61
		SpriteID ground;       ///< ground sprite for a 3-way switch
ee31c1e1477c (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
    62
		SpriteID single_y;     ///< single piece of rail in Y direction, without ground
ee31c1e1477c (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
    63
		SpriteID single_x;     ///< single piece of rail in X direction
ee31c1e1477c (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
    64
		SpriteID single_n;     ///< single piece of rail in the northern corner
ee31c1e1477c (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
    65
		SpriteID single_s;     ///< single piece of rail in the southern corner
ee31c1e1477c (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
    66
		SpriteID single_e;     ///< single piece of rail in the eastern corner
ee31c1e1477c (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
    67
		SpriteID single_w;     ///< single piece of rail in the western corner
2511
3eb6cb6b750d (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
    68
		SpriteID crossing;     ///< level crossing, rail in X direction
3eb6cb6b750d (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
    69
		SpriteID tunnel;       ///< tunnel sprites base
2233
ee31c1e1477c (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
    70
	} base_sprites;
ee31c1e1477c (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
    71
2274
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    72
	/** struct containing the sprites for the rail GUI. @note only sprites referred to
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    73
	 * directly in the code are listed */
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    74
	struct {
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    75
		SpriteID build_ns_rail;      ///< button for building single rail in N-S direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    76
		SpriteID build_x_rail;       ///< button for building single rail in X direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    77
		SpriteID build_ew_rail;      ///< button for building single rail in E-W direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    78
		SpriteID build_y_rail;       ///< button for building single rail in Y direction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    79
		SpriteID auto_rail;          ///< button for the autorail construction
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    80
		SpriteID build_depot;        ///< button for building depots
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    81
		SpriteID build_tunnel;       ///< button for building a tunnel
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    82
		SpriteID convert_rail;       ///< button for converting rail
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    83
	} gui_sprites;
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    84
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    85
	struct {
2514
859692ffa65a (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
    86
		CursorID rail_ns;
859692ffa65a (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
    87
		CursorID rail_swne;
859692ffa65a (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
    88
		CursorID rail_ew;
859692ffa65a (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
    89
		CursorID rail_nwse;
859692ffa65a (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
    90
		CursorID autorail;
859692ffa65a (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
    91
		CursorID depot;
859692ffa65a (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
    92
		CursorID tunnel;
859692ffa65a (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
    93
		CursorID convert;
859692ffa65a (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
    94
	} cursor;
859692ffa65a (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
    95
859692ffa65a (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
    96
	struct {
2274
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    97
		StringID toolbar_caption;
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    98
	} strings;
2c99425c1086 (svn r2798) -Codechange: Unified the rail toolbars into one that is modified by
celestar
parents: 2254
diff changeset
    99
2233
ee31c1e1477c (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
   100
	/** sprite number difference between a piece of track on a snowy ground and the corresponding one on normal ground */
ee31c1e1477c (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
   101
	SpriteID snow_offset;
ee31c1e1477c (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
   102
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   103
	/** bitmask to the OTHER railtypes on which an engine of THIS railtype generates power */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   104
	RailTypeMask powered_railtypes;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   105
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   106
	/** bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   107
	RailTypeMask compatible_railtypes;
2254
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   108
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   109
	/**
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   110
	 * Offset between the current railtype and normal rail. This means that:<p>
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   111
	 * 1) All the sprites in a railset MUST be in the same order. This order
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   112
	 *    is determined by normal rail. Check sprites 1005 and following for this order<p>
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   113
	 * 2) The position where the railtype is loaded must always be the same, otherwise
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   114
	 *    the offset will fail.<p>
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   115
	 * @note: Something more flexible might be desirable in the future.
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   116
	 */
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2236
diff changeset
   117
	SpriteID total_offset;
2536
634914d741b4 (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
   118
634914d741b4 (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
   119
	/**
634914d741b4 (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
   120
	  * Bridge offset
634914d741b4 (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
   121
	  */
634914d741b4 (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
   122
	SpriteID bridge_offset;
3503
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   123
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   124
	/**
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   125
	 * Offset to add to ground sprite when drawing custom waypoints / stations
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   126
	 */
44f50afb0a75 (svn r4354) [Elrail][NewGRF] Codechange: Drawing of custom waypoints with custom ground sprites used the index of the rail type as an offset. With the introduction of elrails this offset is incorrect, so instead there is now a lookup table within the RailTypeInfo struct to explicitly list the offset.
peter1138
parents: 3500
diff changeset
   127
	byte custom_ground_offset;
2233
ee31c1e1477c (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
   128
} RailtypeInfo;
ee31c1e1477c (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
   129
2236
34daee5dfc60 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   130
extern const RailtypeInfo _railtypes[RAILTYPE_END];
2233
ee31c1e1477c (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
   131
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   132
// these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   133
enum {
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   134
	NUM_SSD_ENTRY = 256, // max amount of blocks
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   135
	NUM_SSD_STACK = 32 ,// max amount of blocks to check recursively
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   136
};
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   137
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   138
/**
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   139
 * Maps a Trackdir to the corresponding TrackdirBits value
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   140
 */
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   141
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   142
2232
2a0d0328ebbe (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
   143
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   144
 * These functions check the validity of Tracks and Trackdirs. assert against
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   145
 * them when convenient.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   146
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   147
static inline bool IsValidTrack(Track track) { return track < TRACK_END; }
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   148
static inline bool IsValidTrackdir(Trackdir trackdir) { return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   149
2232
2a0d0328ebbe (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
   150
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   151
 * Functions to map tracks to the corresponding bits in the signal
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   152
 * presence/status bytes in the map. You should not use these directly, but
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   153
 * wrapper functions below instead. XXX: Which are these?
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   154
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   155
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   156
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   157
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   158
 * direction along with the trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   159
 */
1947
32308520a356 (svn r2453) * CodeChange: Declared the lookup arrays in rail.h as extern, so the linker will complain if they are not defined (ie when rail.c is not included).
matthijs
parents: 1944
diff changeset
   160
extern const byte _signal_along_trackdir[TRACKDIR_END];
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   161
static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_trackdir[trackdir];}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   162
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   163
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   164
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   165
 * direction against the trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   166
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   167
static inline byte SignalAgainstTrackdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   168
	extern const byte _signal_against_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   169
	return _signal_against_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   170
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   171
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   172
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   173
 * Maps a Track to the bits that store the status of the two signals that can
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   174
 * be present on the given track.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   175
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   176
static inline byte SignalOnTrack(Track track) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   177
	extern const byte _signal_on_track[TRACK_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   178
	return _signal_on_track[track];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   179
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   180
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   181
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   182
 * Some functions to query rail tiles
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   183
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   184
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   185
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   186
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   187
 * Checks if a rail tile has signals.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   188
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   189
static inline bool HasSignals(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   190
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   191
	return GetRailTileType(tile) == RAIL_TYPE_SIGNALS;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   192
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   193
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   194
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   195
 * Returns the RailTileSubtype of a given rail tile with type
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   196
 * RAIL_TYPE_DEPOT_WAYPOINT
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   197
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   198
static inline RailTileSubtype GetRailTileSubtype(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   199
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   200
	assert(GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT);
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2032
diff changeset
   201
	return (RailTileSubtype)(_m[tile].m5 & RAIL_SUBTYPE_MASK);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   202
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   203
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   204
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   205
 * Returns whether this is plain rails, with or without signals. Iow, if this
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   206
 * tiles RailTileType is RAIL_TYPE_NORMAL or RAIL_TYPE_SIGNALS.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   207
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   208
static inline bool IsPlainRailTile(TileIndex tile)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   209
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   210
	RailTileType rtt = GetRailTileType(tile);
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   211
	return rtt == RAIL_TYPE_NORMAL || rtt == RAIL_TYPE_SIGNALS;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   212
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   213
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   214
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   215
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   216
 * Returns whether the given track is present on the given tile. Tile must be
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   217
 * a plain rail tile (IsPlainRailTile()).
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   218
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   219
static inline bool HasTrack(TileIndex tile, Track track)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   220
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   221
	assert(IsValidTrack(track));
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   222
	return HASBIT(GetTrackBits(tile), track);
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   223
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   224
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   225
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   226
 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   227
 * TrackdirBits, Direction and DiagDirections.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   228
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   229
 * TODO: Add #unndefs or something similar to remove the arrays used below
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   230
 * from the global scope and expose direct uses of them.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   231
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   232
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   233
/**
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   234
 * Maps a trackdir to the reverse trackdir.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   235
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   236
static inline Trackdir ReverseTrackdir(Trackdir trackdir) {
3500
e087f21dca54 (svn r4351) Simplify ReverseTrackdir() to use a simple arithmetic operation instead of a table lookup
tron
parents: 3498
diff changeset
   237
	return (Trackdir)(trackdir ^ 8);
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   238
}
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   239
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   240
/**
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   241
 * Maps a Track to the corresponding TrackBits value
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   242
 */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   243
static inline TrackBits TrackToTrackBits(Track track) { return (TrackBits)(1 << track); }
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   244
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   245
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   246
 * Returns the Track that a given Trackdir represents
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   247
 */
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   248
static inline Track TrackdirToTrack(Trackdir trackdir) { return (Track)(trackdir & 0x7); }
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   249
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   250
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   251
 * Returns a Trackdir for the given Track. Since every Track corresponds to
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   252
 * two Trackdirs, we choose the one which points between NE and S.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   253
 * Note that the actual implementation is quite futile, but this might change
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   254
 * in the future.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   255
 */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   256
static inline Trackdir TrackToTrackdir(Track track) { return (Trackdir)track; }
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   257
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   258
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   259
 * Returns a TrackdirBit mask that contains the two TrackdirBits that
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   260
 * correspond with the given Track (one for each direction).
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   261
 */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   262
static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = TrackToTrackdir(track); return TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td));}
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   263
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   264
/**
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   265
 * Discards all directional information from the given TrackdirBits. Any
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   266
 * Track which is present in either direction will be present in the result.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   267
 */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   268
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) { return bits | (bits >> 8); }
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   269
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   270
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   271
 * Maps a trackdir to the trackdir that you will end up on if you go straight
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   272
 * ahead. This will be the same trackdir for diagonal trackdirs, but a
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   273
 * different (alternating) one for straight trackdirs
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   274
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   275
static inline Trackdir NextTrackdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   276
	extern const Trackdir _next_trackdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   277
	return _next_trackdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   278
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   279
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   280
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   281
 * Maps a track to all tracks that make 90 deg turns with it.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   282
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   283
static inline TrackBits TrackCrossesTracks(Track track) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   284
	extern const TrackBits _track_crosses_tracks[TRACK_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   285
	return _track_crosses_tracks[track];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   286
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   287
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   288
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   289
 * Maps a trackdir to the (4-way) direction the tile is exited when following
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   290
 * that trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   291
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   292
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   293
	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   294
	return _trackdir_to_exitdir[trackdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   295
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   296
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   297
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   298
 * Maps a track and an (4-way) dir to the trackdir that represents the track
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   299
 * with the exit in the given direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   300
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   301
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   302
	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   303
	return _track_exitdir_to_trackdir[track][diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   304
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   305
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   306
/**
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   307
 * Maps a track and an (4-way) dir to the trackdir that represents the track
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   308
 * with the exit in the given direction.
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   309
 */
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   310
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) {
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   311
	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   312
	return _track_enterdir_to_trackdir[track][diagdir];
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   313
}
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   314
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   315
/**
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   316
 * Maps a track and a full (8-way) direction to the trackdir that represents
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   317
 * the track running in the given direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   318
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   319
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   320
	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   321
	return _track_direction_to_trackdir[track][dir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   322
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   323
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   324
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   325
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   326
 * direction.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   327
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   328
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   329
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   330
	return _dir_to_diag_trackdir[diagdir];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   331
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   332
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   333
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   334
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   335
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   336
 * Returns all trackdirs that can be reached when entering a tile from a given
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   337
 * (diagonal) direction. This will obviously include 90 degree turns, since no
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   338
 * information is available about the exact angle of entering */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   339
static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) { return _exitdir_reaches_trackdirs[diagdir]; }
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   340
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   341
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   342
 * Returns all tracks that can be reached when entering a tile from a given
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   343
 * (diagonal) direction. This will obviously include 90 degree turns, since no
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   344
 * information is available about the exact angle of entering */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   345
static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   346
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   347
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   348
 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   349
 * entering the next tile. This will include 90 degree turns!
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   350
 */
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   351
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   352
/* Note that there is no direct table for this function (there used to be),
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   353
 * but it uses two simpeler tables to achieve the result */
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   354
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   355
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   356
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   357
 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   358
 */
1948
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   359
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   360
	extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   361
	return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
d95a69e8c560 (svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents: 1947
diff changeset
   362
}
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   363
2008
cdb444f6d43c (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
   364
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   365
/* Checks if a given Track is diagonal */
3102
f9ca4379db9d (svn r3697) Rename DIAG1/DIAG2 to X resp. Y as this conveys a bit better in which direction a pieces of rail goes
tron
parents: 2989
diff changeset
   366
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); }
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   367
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   368
/* Checks if a given Trackdir is diagonal. */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   369
static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); }
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   370
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   371
/*
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   372
 * Functions quering signals on tiles.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   373
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   374
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   375
/**
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   376
 * Checks for the presence of signals (either way) on the given track on the
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   377
 * given rail tile.
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   378
 */
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   379
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   380
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   381
	assert(IsValidTrack(track));
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   382
	return
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   383
		GetRailTileType(tile) == RAIL_TYPE_SIGNALS &&
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   384
		(_m[tile].m3 & SignalOnTrack(track)) != 0;
1944
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   385
}
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   386
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   387
/**
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   388
 * Checks for the presence of signals along the given trackdir on the given
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   389
 * rail tile.
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   390
 *
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   391
 * Along meaning if you are currently driving on the given trackdir, this is
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   392
 * the signal that is facing us (for which we stop when it's red).
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   393
 */
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   394
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   395
{
dd9cba5fab2a (svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents: 1942
diff changeset
   396
	assert (IsValidTrackdir(trackdir));
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   397
	return
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   398
		GetRailTileType(tile) == RAIL_TYPE_SIGNALS &&
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   399
		_m[tile].m3 & SignalAlongTrackdir(trackdir);
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   400
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   401
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   402
/**
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   403
 * Gets the state of the signal along the given trackdir.
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   404
 *
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   405
 * Along meaning if you are currently driving on the given trackdir, this is
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   406
 * the signal that is facing us (for which we stop when it's red).
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   407
 */
3520
a288391e66a3 (svn r4376) -Codechange Renamed GetSignalState to GetSignalStateByTrackdir
celestar
parents: 3503
diff changeset
   408
static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   409
{
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   410
	assert(IsValidTrackdir(trackdir));
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   411
	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   412
	return _m[tile].m2 & SignalAlongTrackdir(trackdir) ?
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   413
		SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   414
}
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   415
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff changeset
   416
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   417
/**
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   418
 * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   419
 * Note that there is no check if the given trackdir is actually present on
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   420
 * the tile!
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   421
 * The given trackdir is used when there are (could be) multiple rail types on
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   422
 * one tile.
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   423
 */
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   424
RailType GetTileRailType(TileIndex tile, Trackdir trackdir);
1950
aeb6067adc30 (svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents: 1948
diff changeset
   425
1967
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   426
a01f4d5dd957 (svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents: 1950
diff changeset
   427
/**
2233
ee31c1e1477c (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
   428
 * Returns a pointer to the Railtype information for a given railtype
ee31c1e1477c (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
   429
 * @param railtype the rail type which the information is requested for
ee31c1e1477c (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
   430
 * @return The pointer to the RailtypeInfo
ee31c1e1477c (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
   431
 */
2236
34daee5dfc60 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   432
static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
2233
ee31c1e1477c (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
   433
{
ee31c1e1477c (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
   434
	assert(railtype < RAILTYPE_END);
2236
34daee5dfc60 (svn r2756) Renamed railtypes into _railtypes
ludde
parents: 2233
diff changeset
   435
	return &_railtypes[railtype];
2233
ee31c1e1477c (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
   436
}
ee31c1e1477c (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
   437
ee31c1e1477c (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
   438
/**
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   439
 * Checks if an engine of the given RailType can drive on a tile with a given
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   440
 * RailType. This would normally just be an equality check, but for electric
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   441
 * rails (which also support non-electric engines).
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   442
 * @return Whether the engine can drive on this tile.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   443
 * @param  enginetype The RailType of the engine we are considering.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   444
 * @param  tiletype   The RailType of the tile we are considering.
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   445
 */
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   446
static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   447
{
2233
ee31c1e1477c (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
   448
	return HASBIT(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
2006
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   449
}
9d5d7fd428c2 (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 2001
diff changeset
   450
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   451
static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   452
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   453
	return HASBIT(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   454
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   455
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   456
/**
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   457
 * Checks if the given tracks overlap, ie form a crossing. Basically this
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   458
 * means when there is more than one track on the tile, exept when there are
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   459
 * two parallel tracks.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   460
 * @param  bits The tracks present.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   461
 * @return Whether the tracks present overlap in any way.
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   462
 */
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   463
static inline bool TracksOverlap(TrackBits bits)
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   464
{
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   465
  /* With no, or only one track, there is no overlap */
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   466
  if (bits == 0 || KILL_FIRST_BIT(bits) == 0) return false;
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   467
  /* We know that there are at least two tracks present. When there are more
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   468
   * than 2 tracks, they will surely overlap. When there are two, they will
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   469
   * always overlap unless they are lower & upper or right & left. */
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3253
diff changeset
   470
	return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
2782
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   471
}
c7190cbfd309 (svn r3329) - Doc: Some documentation cleanups.
matthijs
parents: 2548
diff changeset
   472
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   473
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2514
diff changeset
   474
void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   475
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   476
/**
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   477
 * Draws overhead wires and pylons for electric railways.
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   478
 * @param ti The TileInfo struct of the tile being drawn
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   479
 * @see DrawCatenaryRailway
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   480
 */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   481
void DrawCatenary(const TileInfo *ti);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3267
diff changeset
   482
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3575
diff changeset
   483
uint GetRailFoundation(Slope tileh, TrackBits bits);
2536
634914d741b4 (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
   484
#endif /* RAIL_H */