src/rail_map.h
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9271 53e93ef75071
child 10213 23cfd330ccac
permissions -rw-r--r--
update tags
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
     1
/* $Id$ */
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
     2
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6574
diff changeset
     3
/** @file rail_map.h Hides the direct accesses to the map array with map accessors */
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6574
diff changeset
     4
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
     5
#ifndef RAIL_MAP_H
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
     6
#define RAIL_MAP_H
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
     7
8634
5ffca02f9115 (svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents: 8604
diff changeset
     8
#include "rail_type.h"
5ffca02f9115 (svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents: 8604
diff changeset
     9
#include "signal_func.h"
8596
27646407e0bc (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 8424
diff changeset
    10
#include "direction_func.h"
8597
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8596
diff changeset
    11
#include "track_func.h"
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8597
diff changeset
    12
#include "tile_map.h"
9257
02376670f6b6 (svn r12457) -Codechange: Move signal enums on their own header.
belugas
parents: 9128
diff changeset
    13
#include "signal_type.h"
9271
53e93ef75071 (svn r12474) -Codechange: split type related stuff from waypoints from waypoint.h (and openttd.h) to waypoint_type.h.
rubidium
parents: 9257
diff changeset
    14
#include "waypoint_type.h"
3239
45396b9950aa (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
    15
45396b9950aa (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
    16
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    17
/** Different types of Rail-related tiles */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6508
diff changeset
    18
enum RailTileType {
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    19
	RAIL_TILE_NORMAL   = 0, ///< Normal rail tile without signals
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    20
	RAIL_TILE_SIGNALS  = 1, ///< Normal rail tile with signals
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    21
	RAIL_TILE_WAYPOINT = 2, ///< Waypoint (X or Y direction)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    22
	RAIL_TILE_DEPOT    = 3, ///< Depot (one entrance)
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6508
diff changeset
    23
};
3239
45396b9950aa (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
    24
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    25
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    26
 * Returns the RailTileType (normal with or without signals,
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    27
 * waypoint or depot).
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    28
 * @param t the tile to get the information from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    29
 * @pre IsTileType(t, MP_RAILWAY)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    30
 * @return the RailTileType
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    31
 */
3239
45396b9950aa (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
    32
static inline RailTileType GetRailTileType(TileIndex t)
45396b9950aa (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
    33
{
45396b9950aa (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
    34
	assert(IsTileType(t, MP_RAILWAY));
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    35
	return (RailTileType)GB(_m[t].m5, 6, 2);
3239
45396b9950aa (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
    36
}
45396b9950aa (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
    37
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    38
/**
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    39
 * Returns whether this is plain rails, with or without signals. Iow, if this
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3772
diff changeset
    40
 * tiles RailTileType is RAIL_TILE_NORMAL or RAIL_TILE_SIGNALS.
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    41
 * @param t the tile to get the information from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    42
 * @pre IsTileType(t, MP_RAILWAY)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    43
 * @return true if and only if the tile is normal rail (with or without signals)
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    44
 */
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    45
static inline bool IsPlainRailTile(TileIndex t)
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    46
{
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    47
	RailTileType rtt = GetRailTileType(t);
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3772
diff changeset
    48
	return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS;
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    49
}
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    50
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    51
/**
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    52
 * Checks if a rail tile has signals.
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    53
 * @param t the tile to get the information from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    54
 * @pre IsTileType(t, MP_RAILWAY)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    55
 * @return true if and only if the tile has signals
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    56
 */
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    57
static inline bool HasSignals(TileIndex t)
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    58
{
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    59
	return GetRailTileType(t) == RAIL_TILE_SIGNALS;
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    60
}
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    61
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    62
/**
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    63
 * Add/remove the 'has signal' bit from the RailTileType
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    64
 * @param tile the tile to add/remove the signals to/from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    65
 * @param signals whether the rail tile should have signals or not
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    66
 * @pre IsPlainRailTile(tile)
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    67
 */
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    68
static inline void SetHasSignals(TileIndex tile, bool signals)
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    69
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    70
	assert(IsPlainRailTile(tile));
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    71
	SB(_m[tile].m5, 6, 1, signals);
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    72
}
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    73
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    74
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    75
 * Is this tile a rail depot?
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    76
 * @param t the tile to get the information from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    77
 * @pre IsTileType(t, MP_RAILWAY)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    78
 * @return true if and only if the tile is a rail depot
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    79
 */
4182
20d711816338 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4158
diff changeset
    80
static inline bool IsRailDepot(TileIndex t)
20d711816338 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4158
diff changeset
    81
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    82
	return GetRailTileType(t) == RAIL_TILE_DEPOT;
4182
20d711816338 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4158
diff changeset
    83
}
20d711816338 (svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes
tron
parents: 4158
diff changeset
    84
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    85
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    86
 * Is this tile a rail waypoint?
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    87
 * @param t the tile to get the information from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    88
 * @pre IsTileType(t, MP_RAILWAY)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    89
 * @return true if and only if the tile is a rail waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    90
 */
4044
37822ac6f431 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    91
static inline bool IsRailWaypoint(TileIndex t)
37822ac6f431 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    92
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
    93
	return GetRailTileType(t) == RAIL_TILE_WAYPOINT;
4044
37822ac6f431 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    94
}
37822ac6f431 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    95
37822ac6f431 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    96
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    97
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    98
 * Gets the rail type of the given tile
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
    99
 * @param t the tile to get the rail type from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   100
 * @return the rail type of the tile
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   101
 */
3239
45396b9950aa (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
   102
static inline RailType GetRailType(TileIndex t)
45396b9950aa (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
   103
{
45396b9950aa (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
   104
	return (RailType)GB(_m[t].m3, 0, 4);
45396b9950aa (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
   105
}
45396b9950aa (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
   106
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   107
/**
9128
8372a371a3e1 (svn r12239) -Fix [FS#1800] (r9729): inverted comments for SetRailType() and GetTrackBits() (michi_cc)
glx
parents: 9019
diff changeset
   108
 * Sets the rail type of the given tile
8372a371a3e1 (svn r12239) -Fix [FS#1800] (r9729): inverted comments for SetRailType() and GetTrackBits() (michi_cc)
glx
parents: 9019
diff changeset
   109
 * @param t the tile to set the rail type of
8372a371a3e1 (svn r12239) -Fix [FS#1800] (r9729): inverted comments for SetRailType() and GetTrackBits() (michi_cc)
glx
parents: 9019
diff changeset
   110
 * @param r the new rail type for the tile
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   111
 */
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   112
static inline void SetRailType(TileIndex t, RailType r)
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   113
{
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   114
	SB(_m[t].m3, 0, 4, r);
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   115
}
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   116
3239
45396b9950aa (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
   117
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   118
/**
9128
8372a371a3e1 (svn r12239) -Fix [FS#1800] (r9729): inverted comments for SetRailType() and GetTrackBits() (michi_cc)
glx
parents: 9019
diff changeset
   119
 * Gets the track bits of the given tile
8372a371a3e1 (svn r12239) -Fix [FS#1800] (r9729): inverted comments for SetRailType() and GetTrackBits() (michi_cc)
glx
parents: 9019
diff changeset
   120
 * @param t the tile to get the track bits from
8372a371a3e1 (svn r12239) -Fix [FS#1800] (r9729): inverted comments for SetRailType() and GetTrackBits() (michi_cc)
glx
parents: 9019
diff changeset
   121
 * @return the track bits of the tile
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   122
 */
3267
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
   123
static inline TrackBits GetTrackBits(TileIndex tile)
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
   124
{
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
   125
	return (TrackBits)GB(_m[tile].m5, 0, 6);
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
   126
}
591027d10884 (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
   127
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   128
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   129
 * Sets the track bits of the given tile
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   130
 * @param t the tile to set the track bits of
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   131
 * @param b the new track bits for the tile
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   132
 */
3273
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   133
static inline void SetTrackBits(TileIndex t, TrackBits b)
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   134
{
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   135
	SB(_m[t].m5, 0, 6, b);
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   136
}
7303df652359 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   137
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   138
/**
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   139
 * Returns whether the given track is present on the given tile.
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   140
 * @param tile  the tile to check the track presence of
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   141
 * @param track the track to search for on the tile
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   142
 * @pre IsPlainRailTile(tile)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   143
 * @return true if and only if the given track exists on the tile
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   144
 */
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   145
static inline bool HasTrack(TileIndex tile, Track track)
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   146
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8267
diff changeset
   147
	return HasBit(GetTrackBits(tile), track);
3772
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   148
}
4872d75f5172 (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   149
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   150
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   151
 * Returns the direction the depot is facing to
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   152
 * @param t the tile to get the depot facing from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   153
 * @pre IsRailDepotTile(t)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   154
 * @return the direction the depot is facing
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   155
 */
3185
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   156
static inline DiagDirection GetRailDepotDirection(TileIndex t)
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   157
{
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   158
	return (DiagDirection)GB(_m[t].m5, 0, 2);
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   159
}
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   160
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   161
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   162
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   163
 * Returns the axis of the waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   164
 * @param t the tile to get the waypoint axis from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   165
 * @pre IsRailWaypointTile(t)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   166
 * @return the axis of the waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   167
 */
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   168
static inline Axis GetWaypointAxis(TileIndex t)
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   169
{
4474
0f8f3a3d6768 (svn r6259) Extract the axis directly, don't use a trinary operator
tron
parents: 4466
diff changeset
   170
	return (Axis)GB(_m[t].m5, 0, 1);
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   171
}
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   172
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   173
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   174
 * Returns the track of the waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   175
 * @param t the tile to get the waypoint track from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   176
 * @pre IsRailWaypointTile(t)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   177
 * @return the track of the waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   178
 */
3453
4de28826442c (svn r4286) -Fix: Typo in 4280
celestar
parents: 3448
diff changeset
   179
static inline Track GetRailWaypointTrack(TileIndex t)
3448
0bee5179ae86 (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   180
{
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   181
	return AxisToTrack(GetWaypointAxis(t));
3448
0bee5179ae86 (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   182
}
3185
c0ef161f700f (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   183
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   184
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   185
 * Returns the track bits of the waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   186
 * @param t the tile to get the waypoint track bits from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   187
 * @pre IsRailWaypointTile(t)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   188
 * @return the track bits of the waypoint
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   189
 */
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   190
static inline TrackBits GetRailWaypointBits(TileIndex t)
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   191
{
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   192
	return TrackToTrackBits(GetRailWaypointTrack(t));
3528
ca3ce10452d8 (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   193
}
ca3ce10452d8 (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   194
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   195
/**
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   196
 * Returns waypoint index (for the waypoint pool)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   197
 * @param t the tile to get the waypoint index from
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   198
 * @pre IsRailWaypointTile(t)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   199
 * @return the waypoint index
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   200
 */
6508
8bd54af67f0b (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6498
diff changeset
   201
static inline WaypointID GetWaypointIndex(TileIndex t)
8bd54af67f0b (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6498
diff changeset
   202
{
8bd54af67f0b (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6498
diff changeset
   203
	return (WaypointID)_m[t].m2;
8bd54af67f0b (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6498
diff changeset
   204
}
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   205
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   206
static inline SignalType GetSignalType(TileIndex t, Track track)
3238
a100405fe221 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents: 3237
diff changeset
   207
{
3792
2eb8388731bf (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3772
diff changeset
   208
	assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   209
	byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0;
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   210
	return (SignalType)GB(_m[t].m2, pos, 2);
3238
a100405fe221 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents: 3237
diff changeset
   211
}
a100405fe221 (svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
tron
parents: 3237
diff changeset
   212
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   213
static inline void SetSignalType(TileIndex t, Track track, SignalType s)
3521
c5dda2dbd977 (svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents: 3453
diff changeset
   214
{
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   215
	assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   216
	byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0;
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   217
	SB(_m[t].m2, pos, 2, s);
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   218
	if (track == INVALID_TRACK) SB(_m[t].m2, 4, 2, s);
3521
c5dda2dbd977 (svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents: 3453
diff changeset
   219
}
c5dda2dbd977 (svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents: 3453
diff changeset
   220
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   221
static inline bool IsPresignalEntry(TileIndex t, Track track)
3521
c5dda2dbd977 (svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents: 3453
diff changeset
   222
{
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   223
	return GetSignalType(t, track) == SIGTYPE_ENTRY || GetSignalType(t, track) == SIGTYPE_COMBO;
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   224
}
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   225
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   226
static inline bool IsPresignalExit(TileIndex t, Track track)
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   227
{
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   228
	return GetSignalType(t, track) == SIGTYPE_EXIT || GetSignalType(t, track) == SIGTYPE_COMBO;
3521
c5dda2dbd977 (svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents: 3453
diff changeset
   229
}
c5dda2dbd977 (svn r4377) -Add and make use of a function that finds out whether a signal is an entry or and exit signal to a presignal block (as combos act as both)
celestar
parents: 3453
diff changeset
   230
3522
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   231
static inline void CycleSignalSide(TileIndex t, Track track)
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   232
{
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   233
	byte sig;
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   234
	byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 6;
3522
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   235
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   236
	sig = GB(_m[t].m3, pos, 2);
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   237
	if (--sig == 0) sig = 3;
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   238
	SB(_m[t].m3, pos, 2, sig);
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   239
}
25ce619b9a19 (svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
celestar
parents: 3521
diff changeset
   240
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   241
static inline SignalVariant GetSignalVariant(TileIndex t, Track track)
3237
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   242
{
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   243
	byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 6 : 2;
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   244
	return (SignalVariant)GB(_m[t].m2, pos, 1);
3237
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   245
}
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   246
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   247
static inline void SetSignalVariant(TileIndex t, Track track, SignalVariant v)
3237
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   248
{
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   249
	byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 6 : 2;
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   250
	SB(_m[t].m2, pos, 1, v);
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   251
	if (track == INVALID_TRACK) SB(_m[t].m2, 6, 1, v);
3237
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   252
}
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   253
3575
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   254
/** These are states in which a signal can be. Currently these are only two, so
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   255
 * simple boolean logic will do. But do try to compare to this enum instead of
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   256
 * normal boolean evaluation, since that will make future additions easier.
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   257
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6508
diff changeset
   258
enum SignalState {
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   259
	SIGNAL_STATE_RED   = 0, ///< The signal is red
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   260
	SIGNAL_STATE_GREEN = 1, ///< The signal is green
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6508
diff changeset
   261
};
3575
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   262
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   263
/**
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   264
 * Set the states of the signals (Along/AgainstTrackDir)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   265
 * @param tile  the tile to set the states for
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   266
 * @param state the new state
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   267
 */
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   268
static inline void SetSignalStates(TileIndex tile, uint state)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   269
{
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   270
	SB(_m[tile].m4, 4, 4, state);
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   271
}
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   272
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   273
/**
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   274
 * Set the states of the signals (Along/AgainstTrackDir)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   275
 * @param tile  the tile to set the states for
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   276
 * @param state the new state
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   277
 */
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   278
static inline uint GetSignalStates(TileIndex tile)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   279
{
7266
4b75e7b9fa91 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 7249
diff changeset
   280
	return GB(_m[tile].m4, 4, 4);
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   281
}
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   282
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   283
/**
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   284
 * Get the state of a single signal
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   285
 * @param t         the tile to get the signal state for
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   286
 * @param signalbit the signal
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   287
 * @return the state of the signal
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   288
 */
3575
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   289
static inline SignalState GetSingleSignalState(TileIndex t, byte signalbit)
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   290
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8267
diff changeset
   291
	return (SignalState)HasBit(GetSignalStates(t), signalbit);
3575
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   292
}
867df1ec208a (svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
celestar
parents: 3530
diff changeset
   293
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   294
/**
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   295
 * Set whether the given signals are present (Along/AgainstTrackDir)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   296
 * @param tile    the tile to set the present signals for
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   297
 * @param signals the signals that have to be present
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   298
 */
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   299
static inline void SetPresentSignals(TileIndex tile, uint signals)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   300
{
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   301
	SB(_m[tile].m3, 4, 4, signals);
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   302
}
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   303
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   304
/**
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   305
 * Get whether the given signals are present (Along/AgainstTrackDir)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   306
 * @param tile the tile to get the present signals for
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   307
 * @return the signals that are present
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   308
 */
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   309
static inline uint GetPresentSignals(TileIndex tile)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   310
{
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   311
	return GB(_m[tile].m3, 4, 4);
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   312
}
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   313
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   314
/**
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   315
 * Checks whether the given signals is present
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   316
 * @param t         the tile to check on
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   317
 * @param signalbit the signal
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   318
 * @return true if and only if the signal is present
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   319
 */
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   320
static inline bool IsSignalPresent(TileIndex t, byte signalbit)
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   321
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8267
diff changeset
   322
	return HasBit(GetPresentSignals(t), signalbit);
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   323
}
3237
985399d4099d (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   324
4041
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   325
/**
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   326
 * Checks for the presence of signals (either way) on the given track on the
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   327
 * given rail tile.
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   328
 */
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   329
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   330
{
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   331
	assert(IsValidTrack(track));
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   332
	return
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   333
		GetRailTileType(tile) == RAIL_TILE_SIGNALS &&
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   334
		(GetPresentSignals(tile) & SignalOnTrack(track)) != 0;
4041
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   335
}
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   336
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   337
/**
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   338
 * Checks for the presence of signals along the given trackdir on the given
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   339
 * rail tile.
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   340
 *
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   341
 * Along meaning if you are currently driving on the given trackdir, this is
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   342
 * the signal that is facing us (for which we stop when it's red).
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   343
 */
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   344
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   345
{
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   346
	assert (IsValidTrackdir(trackdir));
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   347
	return
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   348
		GetRailTileType(tile) == RAIL_TILE_SIGNALS &&
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   349
		GetPresentSignals(tile) & SignalAlongTrackdir(trackdir);
4041
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   350
}
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   351
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   352
/**
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   353
 * Gets the state of the signal along the given trackdir.
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   354
 *
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   355
 * Along meaning if you are currently driving on the given trackdir, this is
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   356
 * the signal that is facing us (for which we stop when it's red).
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   357
 */
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   358
static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   359
{
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   360
	assert(IsValidTrackdir(trackdir));
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   361
	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
7249
3e6c9df9794d (svn r9988) -Codechange: remove the last direct map accesses, except the ones needed for the savegame saving/loading mechanisms.
rubidium
parents: 7036
diff changeset
   362
	return GetSignalStates(tile) & SignalAlongTrackdir(trackdir) ?
4041
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   363
		SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   364
}
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   365
8734
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   366
/**
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   367
 * Sets the state of the signal along the given trackdir.
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   368
 */
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   369
static inline void SetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir, SignalState state)
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   370
{
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   371
	if (state == SIGNAL_STATE_GREEN) { // set 1
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   372
		SetSignalStates(tile, GetSignalStates(tile) | SignalAlongTrackdir(trackdir));
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   373
	} else {
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   374
		SetSignalStates(tile, GetSignalStates(tile) & ~SignalAlongTrackdir(trackdir));
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   375
	}
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   376
}
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8634
diff changeset
   377
4041
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   378
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   379
/**
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   380
 * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   381
 */
6480
767cfeae4dbf (svn r8899) -Fix
tron
parents: 5838
diff changeset
   382
RailType GetTileRailType(TileIndex tile);
4041
caf4fcb4e05b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 3977
diff changeset
   383
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   384
/** The ground 'under' the rail */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6508
diff changeset
   385
enum RailGroundType {
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   386
	RAIL_GROUND_BARREN       =  0, ///< Nothing (dirt)
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   387
	RAIL_GROUND_GRASS        =  1, ///< Grassy
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   388
	RAIL_GROUND_FENCE_NW     =  2, ///< Grass with a fence at the NW edge
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   389
	RAIL_GROUND_FENCE_SE     =  3, ///< Grass with a fence at the SE edge
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   390
	RAIL_GROUND_FENCE_SENW   =  4, ///< Grass with a fence at the NW and SE edges
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   391
	RAIL_GROUND_FENCE_NE     =  5, ///< Grass with a fence at the NE edge
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   392
	RAIL_GROUND_FENCE_SW     =  6, ///< Grass with a fence at the SW edge
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   393
	RAIL_GROUND_FENCE_NESW   =  7, ///< Grass with a fence at the NE and SW edges
7803
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7266
diff changeset
   394
	RAIL_GROUND_FENCE_VERT1  =  8, ///< Grass with a fence at the eastern side
07d4e0a7a9db (svn r10659) -Codechange: updated documentation around RAIL_GROUND_FENCE_VERT[12] (frosch)
truelight
parents: 7266
diff changeset
   395
	RAIL_GROUND_FENCE_VERT2  =  9, ///< Grass with a fence at the western side
7036
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   396
	RAIL_GROUND_FENCE_HORIZ1 = 10, ///< Grass with a fence at the southern side
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   397
	RAIL_GROUND_FENCE_HORIZ2 = 11, ///< Grass with a fence at the northern side
9f23930e7ded (svn r9729) -Documentation: add some documentation in various places
rubidium
parents: 6889
diff changeset
   398
	RAIL_GROUND_ICE_DESERT   = 12, ///< Icy or sandy
8910
b261b6cb9b21 (svn r11984) -Fix: Also draw corner shores under rail tracks.
frosch
parents: 8734
diff changeset
   399
	RAIL_GROUND_WATER        = 13, ///< Grass with a fence and shore or water on the free halftile
9019
de364e5be143 (svn r12098) -Fix: make snow appear on rail tiles dependant on track height, not on height of the lowest part of the tile
smatz
parents: 8910
diff changeset
   400
	RAIL_GROUND_HALF_SNOW    = 14, ///< Snow only on higher part of slope (steep or one corner raised)
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6508
diff changeset
   401
};
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   402
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   403
static inline void SetRailGroundType(TileIndex t, RailGroundType rgt)
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   404
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
   405
	SB(_m[t].m4, 0, 4, rgt);
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   406
}
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   407
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   408
static inline RailGroundType GetRailGroundType(TileIndex t)
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   409
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
   410
	return (RailGroundType)GB(_m[t].m4, 0, 4);
3523
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   411
}
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   412
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   413
static inline bool IsSnowRailGround(TileIndex t)
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   414
{
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   415
	return GetRailGroundType(t) == RAIL_GROUND_ICE_DESERT;
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   416
}
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   417
168ee460418b (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   418
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   419
static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r)
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   420
{
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   421
	SetTileType(t, MP_RAILWAY);
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   422
	SetTileOwner(t, o);
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   423
	_m[t].m2 = 0;
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   424
	_m[t].m3 = r;
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   425
	_m[t].m4 = 0;
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
   426
	_m[t].m5 = RAIL_TILE_NORMAL << 6 | b;
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   427
}
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   428
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   429
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   430
static inline void MakeRailDepot(TileIndex t, Owner o, DiagDirection d, RailType r)
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   431
{
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   432
	SetTileType(t, MP_RAILWAY);
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   433
	SetTileOwner(t, o);
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   434
	_m[t].m2 = 0;
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   435
	_m[t].m3 = r;
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   436
	_m[t].m4 = 0;
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
   437
	_m[t].m5 = RAIL_TILE_DEPOT << 6 | d;
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   438
}
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   439
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   440
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   441
static inline void MakeRailWaypoint(TileIndex t, Owner o, Axis a, RailType r, uint index)
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   442
{
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   443
	SetTileType(t, MP_RAILWAY);
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   444
	SetTileOwner(t, o);
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   445
	_m[t].m2 = index;
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   446
	_m[t].m3 = r;
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   447
	_m[t].m4 = 0;
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6480
diff changeset
   448
	_m[t].m5 = RAIL_TILE_WAYPOINT << 6 | a;
3101
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   449
}
e2fdb8802c2f (svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
diff changeset
   450
4666
850b5b6e4bac (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4474
diff changeset
   451
#endif /* RAIL_MAP_H */