src/rail_map.h
author belugas
Wed, 04 Apr 2007 01:35:16 +0000
changeset 6420 456c275f3313
parent 6393 e1e4939d19b5
child 6540 d30795308feb
permissions -rw-r--r--
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
3101
a44fdf9faef1 (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$ */
a44fdf9faef1 (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
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6248
diff changeset
     3
/** @file rail_map.h Hides the direct accesses to the map array with map accessors */
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6248
diff changeset
     4
3101
a44fdf9faef1 (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
a44fdf9faef1 (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
a44fdf9faef1 (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
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
     8
#include "direction.h"
4041
72276cd8ee2b (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
     9
#include "rail.h"
3101
a44fdf9faef1 (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
    10
#include "tile.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
    11
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
    12
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
    13
enum RailTileType {
6172
e6d7a5b3d63f (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: 6154
diff changeset
    14
	RAIL_TILE_NORMAL   = 0,
e6d7a5b3d63f (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: 6154
diff changeset
    15
	RAIL_TILE_SIGNALS  = 1,
e6d7a5b3d63f (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: 6154
diff changeset
    16
	RAIL_TILE_WAYPOINT = 2,
e6d7a5b3d63f (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: 6154
diff changeset
    17
	RAIL_TILE_DEPOT    = 3,
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
    18
};
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
    19
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
    20
static inline RailTileType GetRailTileType(TileIndex t)
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
    21
{
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
    22
	assert(IsTileType(t, MP_RAILWAY));
6172
e6d7a5b3d63f (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: 6154
diff changeset
    23
	return (RailTileType)GB(_m[t].m5, 6, 2);
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
    24
}
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
    25
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    26
/**
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    27
 * Returns whether this is plain rails, with or without signals. Iow, if this
3792
67c865c9315c (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
    28
 * tiles RailTileType is RAIL_TILE_NORMAL or RAIL_TILE_SIGNALS.
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    29
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    30
static inline bool IsPlainRailTile(TileIndex tile)
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    31
{
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    32
	RailTileType rtt = GetRailTileType(tile);
3792
67c865c9315c (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
    33
	return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS;
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    34
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    35
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    36
/**
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    37
 * Checks if a rail tile has signals.
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    38
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    39
static inline bool HasSignals(TileIndex tile)
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    40
{
3792
67c865c9315c (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
    41
	return GetRailTileType(tile) == RAIL_TILE_SIGNALS;
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    42
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    43
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    44
/**
6172
e6d7a5b3d63f (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: 6154
diff changeset
    45
 * Add/remove the 'has signal' bit from the RailTileType
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    46
 */
6172
e6d7a5b3d63f (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: 6154
diff changeset
    47
static inline void SetHasSignals(TileIndex tile, bool signals)
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    48
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
    49
	assert(IsPlainRailTile(tile));
e6d7a5b3d63f (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: 6154
diff changeset
    50
	SB(_m[tile].m5, 6, 1, signals);
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    51
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    52
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
    53
4182
48dba107ff43 (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
    54
static inline bool IsRailDepot(TileIndex t)
48dba107ff43 (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
    55
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
    56
	return GetRailTileType(t) == RAIL_TILE_DEPOT;
4182
48dba107ff43 (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
    57
}
48dba107ff43 (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
    58
48dba107ff43 (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
    59
4044
8db2992cb412 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    60
static inline bool IsRailWaypoint(TileIndex t)
8db2992cb412 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    61
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
    62
	return GetRailTileType(t) == RAIL_TILE_WAYPOINT;
4044
8db2992cb412 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    63
}
8db2992cb412 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    64
8db2992cb412 (svn r5313) Move IsRailWaypoint() to rail_map.h and remove unused enum
tron
parents: 4041
diff changeset
    65
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
    66
static inline RailType GetRailType(TileIndex t)
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
    67
{
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
    68
	return (RailType)GB(_m[t].m3, 0, 4);
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
    69
}
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
    70
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    71
static inline void SetRailType(TileIndex t, RailType r)
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    72
{
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    73
	SB(_m[t].m3, 0, 4, r);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    74
}
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    75
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
    76
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
    77
static inline TrackBits GetTrackBits(TileIndex tile)
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
    78
{
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
    79
	return (TrackBits)GB(_m[tile].m5, 0, 6);
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
    80
}
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3258
diff changeset
    81
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
    82
static inline void SetTrackBits(TileIndex t, TrackBits b)
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
    83
{
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
    84
	SB(_m[t].m5, 0, 6, b);
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
    85
}
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
    86
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    87
/**
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    88
 * Returns whether the given track is present on the given tile. Tile must be
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    89
 * a plain rail tile (IsPlainRailTile()).
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    90
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    91
static inline bool HasTrack(TileIndex tile, Track track)
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    92
{
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    93
	return HASBIT(GetTrackBits(tile), track);
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    94
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    95
3101
a44fdf9faef1 (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
    96
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
    97
static inline DiagDirection GetRailDepotDirection(TileIndex t)
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
    98
{
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
    99
	return (DiagDirection)GB(_m[t].m5, 0, 2);
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   100
}
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   101
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   102
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   103
static inline Axis GetWaypointAxis(TileIndex t)
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   104
{
4474
973c48d699bd (svn r6259) Extract the axis directly, don't use a trinary operator
tron
parents: 4466
diff changeset
   105
	return (Axis)GB(_m[t].m5, 0, 1);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   106
}
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   107
3453
956365eb1f8a (svn r4286) -Fix: Typo in 4280
celestar
parents: 3448
diff changeset
   108
static inline Track GetRailWaypointTrack(TileIndex t)
3448
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   109
{
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   110
	return AxisToTrack(GetWaypointAxis(t));
3448
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   111
}
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   112
3101
a44fdf9faef1 (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
   113
static inline TrackBits GetRailWaypointBits(TileIndex t)
a44fdf9faef1 (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
   114
{
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
   115
	return TrackToTrackBits(GetRailWaypointTrack(t));
3528
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   116
}
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   117
6182
7337aca829f1 (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6172
diff changeset
   118
static inline WaypointID GetWaypointIndex(TileIndex t)
7337aca829f1 (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6172
diff changeset
   119
{
7337aca829f1 (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6172
diff changeset
   120
	return (WaypointID)_m[t].m2;
7337aca829f1 (svn r8954) -Codechange: remove direct map accesses from non-map-accessor headers.
rubidium
parents: 6172
diff changeset
   121
}
3101
a44fdf9faef1 (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
   122
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   123
enum SignalType {
3238
9ebec0a611ee (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
   124
	SIGTYPE_NORMAL  = 0, // normal signal
9ebec0a611ee (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
   125
	SIGTYPE_ENTRY   = 1, // presignal block entry
9ebec0a611ee (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
   126
	SIGTYPE_EXIT    = 2, // presignal block exit
9ebec0a611ee (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
   127
	SIGTYPE_COMBO   = 3  // presignal inter-block
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   128
};
3238
9ebec0a611ee (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
   129
9ebec0a611ee (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
   130
static inline SignalType GetSignalType(TileIndex t)
9ebec0a611ee (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
   131
{
3792
67c865c9315c (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
   132
	assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
6172
e6d7a5b3d63f (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: 6154
diff changeset
   133
	return (SignalType)GB(_m[t].m2, 0, 2);
3238
9ebec0a611ee (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
   134
}
9ebec0a611ee (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
   135
9ebec0a611ee (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
   136
static inline void SetSignalType(TileIndex t, SignalType s)
9ebec0a611ee (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
   137
{
3792
67c865c9315c (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
   138
	assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
6172
e6d7a5b3d63f (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: 6154
diff changeset
   139
	SB(_m[t].m2, 0, 2, s);
3238
9ebec0a611ee (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
   140
}
9ebec0a611ee (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
   141
3521
addbba7b20ff (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
   142
static inline bool IsPresignalEntry(TileIndex t)
addbba7b20ff (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
   143
{
addbba7b20ff (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
   144
	return GetSignalType(t) == SIGTYPE_ENTRY || GetSignalType(t) == SIGTYPE_COMBO;
addbba7b20ff (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
   145
}
addbba7b20ff (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
   146
addbba7b20ff (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
   147
static inline bool IsPresignalExit(TileIndex t)
addbba7b20ff (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
   148
{
addbba7b20ff (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
   149
	return GetSignalType(t) == SIGTYPE_EXIT || GetSignalType(t) == SIGTYPE_COMBO;
addbba7b20ff (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
   150
}
addbba7b20ff (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
   151
3522
888ac5081c6e (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
   152
static inline void CycleSignalSide(TileIndex t, Track track)
888ac5081c6e (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
   153
{
888ac5081c6e (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
   154
	byte sig;
888ac5081c6e (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
   155
	byte pos = 6;
888ac5081c6e (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
   156
	if (track == TRACK_LOWER || track == TRACK_RIGHT) pos = 4;
888ac5081c6e (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
   157
888ac5081c6e (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
   158
	sig = GB(_m[t].m3, pos, 2);
888ac5081c6e (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
   159
	if (--sig == 0) sig = 3;
888ac5081c6e (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
   160
	SB(_m[t].m3, pos, 2, sig);
888ac5081c6e (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
   161
}
888ac5081c6e (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
   162
3238
9ebec0a611ee (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
   163
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   164
enum SignalVariant {
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   165
	SIG_ELECTRIC  = 0,
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   166
	SIG_SEMAPHORE = 1
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   167
};
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   168
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   169
static inline SignalVariant GetSignalVariant(TileIndex t)
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   170
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
   171
	return (SignalVariant)GB(_m[t].m2, 2, 1);
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   172
}
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   173
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   174
static inline void SetSignalVariant(TileIndex t, SignalVariant v)
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   175
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
   176
	SB(_m[t].m2, 2, 1, v);
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   177
}
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   178
3575
f5b56bd958c0 (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
   179
static inline bool IsSignalPresent(TileIndex t, byte signalbit)
f5b56bd958c0 (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
   180
{
f5b56bd958c0 (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
   181
	return HASBIT(_m[t].m3, signalbit + 4);
f5b56bd958c0 (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
   182
}
f5b56bd958c0 (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
   183
f5b56bd958c0 (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
   184
/** These are states in which a signal can be. Currently these are only two, so
f5b56bd958c0 (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
   185
 * simple boolean logic will do. But do try to compare to this enum instead of
f5b56bd958c0 (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
   186
 * normal boolean evaluation, since that will make future additions easier.
f5b56bd958c0 (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
   187
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   188
enum SignalState {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   189
	SIGNAL_STATE_RED   = 0,
3575
f5b56bd958c0 (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
   190
	SIGNAL_STATE_GREEN = 1,
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   191
};
3575
f5b56bd958c0 (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
   192
f5b56bd958c0 (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
   193
static inline SignalState GetSingleSignalState(TileIndex t, byte signalbit)
f5b56bd958c0 (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
   194
{
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3792
diff changeset
   195
	return (SignalState)HASBIT(_m[t].m2, signalbit + 4);
3575
f5b56bd958c0 (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
   196
}
f5b56bd958c0 (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
   197
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   198
4041
72276cd8ee2b (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
   199
/**
72276cd8ee2b (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
   200
 * Checks for the presence of signals (either way) on the given track on the
72276cd8ee2b (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
   201
 * given rail tile.
72276cd8ee2b (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
   202
 */
72276cd8ee2b (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
   203
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
72276cd8ee2b (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
   204
{
72276cd8ee2b (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
   205
	assert(IsValidTrack(track));
72276cd8ee2b (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
   206
	return
72276cd8ee2b (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
   207
		GetRailTileType(tile) == RAIL_TILE_SIGNALS &&
72276cd8ee2b (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
   208
		(_m[tile].m3 & SignalOnTrack(track)) != 0;
72276cd8ee2b (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
   209
}
72276cd8ee2b (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
   210
72276cd8ee2b (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
   211
/**
72276cd8ee2b (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
   212
 * Checks for the presence of signals along the given trackdir on the given
72276cd8ee2b (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
   213
 * rail tile.
72276cd8ee2b (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
   214
 *
72276cd8ee2b (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
   215
 * Along meaning if you are currently driving on the given trackdir, this is
72276cd8ee2b (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
   216
 * the signal that is facing us (for which we stop when it's red).
72276cd8ee2b (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
   217
 */
72276cd8ee2b (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
   218
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
72276cd8ee2b (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
   219
{
72276cd8ee2b (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
   220
	assert (IsValidTrackdir(trackdir));
72276cd8ee2b (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
   221
	return
72276cd8ee2b (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
   222
		GetRailTileType(tile) == RAIL_TILE_SIGNALS &&
72276cd8ee2b (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
   223
		_m[tile].m3 & SignalAlongTrackdir(trackdir);
72276cd8ee2b (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
   224
}
72276cd8ee2b (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
   225
72276cd8ee2b (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
   226
/**
72276cd8ee2b (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
   227
 * Gets the state of the signal along the given trackdir.
72276cd8ee2b (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
   228
 *
72276cd8ee2b (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
   229
 * Along meaning if you are currently driving on the given trackdir, this is
72276cd8ee2b (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
   230
 * the signal that is facing us (for which we stop when it's red).
72276cd8ee2b (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
   231
 */
72276cd8ee2b (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
   232
static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
72276cd8ee2b (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
   233
{
72276cd8ee2b (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
   234
	assert(IsValidTrackdir(trackdir));
72276cd8ee2b (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
   235
	assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
72276cd8ee2b (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
   236
	return _m[tile].m2 & SignalAlongTrackdir(trackdir) ?
72276cd8ee2b (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
   237
		SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
72276cd8ee2b (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
   238
}
72276cd8ee2b (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
   239
72276cd8ee2b (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
   240
72276cd8ee2b (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
   241
/**
72276cd8ee2b (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
   242
 * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
72276cd8ee2b (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
   243
 */
6154
8f4c65bdf930 (svn r8899) -Fix
tron
parents: 5587
diff changeset
   244
RailType GetTileRailType(TileIndex tile);
4041
72276cd8ee2b (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
   245
72276cd8ee2b (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
   246
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   247
enum RailGroundType {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   248
	RAIL_GROUND_BARREN       =  0,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   249
	RAIL_GROUND_GRASS        =  1,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   250
	RAIL_GROUND_FENCE_NW     =  2,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   251
	RAIL_GROUND_FENCE_SE     =  3,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   252
	RAIL_GROUND_FENCE_SENW   =  4,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   253
	RAIL_GROUND_FENCE_NE     =  5,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   254
	RAIL_GROUND_FENCE_SW     =  6,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   255
	RAIL_GROUND_FENCE_NESW   =  7,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   256
	RAIL_GROUND_FENCE_VERT1  =  8,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   257
	RAIL_GROUND_FENCE_VERT2  =  9,
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   258
	RAIL_GROUND_FENCE_HORIZ1 = 10,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   259
	RAIL_GROUND_FENCE_HORIZ2 = 11,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4182
diff changeset
   260
	RAIL_GROUND_ICE_DESERT   = 12,
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6182
diff changeset
   261
};
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   262
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   263
static inline void SetRailGroundType(TileIndex t, RailGroundType rgt)
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   264
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
   265
	SB(_m[t].m4, 0, 4, rgt);
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   266
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   267
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   268
static inline RailGroundType GetRailGroundType(TileIndex t)
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   269
{
6172
e6d7a5b3d63f (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: 6154
diff changeset
   270
	return (RailGroundType)GB(_m[t].m4, 0, 4);
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   271
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   272
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   273
static inline bool IsSnowRailGround(TileIndex t)
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   274
{
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   275
	return GetRailGroundType(t) == RAIL_GROUND_ICE_DESERT;
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   276
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   277
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   278
3101
a44fdf9faef1 (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
   279
static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r)
a44fdf9faef1 (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
   280
{
a44fdf9faef1 (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
   281
	SetTileType(t, MP_RAILWAY);
a44fdf9faef1 (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
   282
	SetTileOwner(t, o);
a44fdf9faef1 (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
   283
	_m[t].m2 = 0;
a44fdf9faef1 (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
   284
	_m[t].m3 = r;
a44fdf9faef1 (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
   285
	_m[t].m4 = 0;
6172
e6d7a5b3d63f (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: 6154
diff changeset
   286
	_m[t].m5 = RAIL_TILE_NORMAL << 6 | b;
3101
a44fdf9faef1 (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
   287
}
a44fdf9faef1 (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
   288
a44fdf9faef1 (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
   289
a44fdf9faef1 (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
   290
static inline void MakeRailDepot(TileIndex t, Owner o, DiagDirection d, RailType r)
a44fdf9faef1 (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
   291
{
a44fdf9faef1 (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
   292
	SetTileType(t, MP_RAILWAY);
a44fdf9faef1 (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
   293
	SetTileOwner(t, o);
a44fdf9faef1 (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
   294
	_m[t].m2 = 0;
a44fdf9faef1 (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
   295
	_m[t].m3 = r;
a44fdf9faef1 (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
   296
	_m[t].m4 = 0;
6172
e6d7a5b3d63f (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: 6154
diff changeset
   297
	_m[t].m5 = RAIL_TILE_DEPOT << 6 | d;
3101
a44fdf9faef1 (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
   298
}
a44fdf9faef1 (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
   299
a44fdf9faef1 (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
   300
a44fdf9faef1 (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
   301
static inline void MakeRailWaypoint(TileIndex t, Owner o, Axis a, RailType r, uint index)
a44fdf9faef1 (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
   302
{
a44fdf9faef1 (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
   303
	SetTileType(t, MP_RAILWAY);
a44fdf9faef1 (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
   304
	SetTileOwner(t, o);
a44fdf9faef1 (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
   305
	_m[t].m2 = index;
a44fdf9faef1 (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
   306
	_m[t].m3 = r;
a44fdf9faef1 (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
   307
	_m[t].m4 = 0;
6172
e6d7a5b3d63f (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: 6154
diff changeset
   308
	_m[t].m5 = RAIL_TILE_WAYPOINT << 6 | a;
3101
a44fdf9faef1 (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
   309
}
a44fdf9faef1 (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
   310
4666
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4474
diff changeset
   311
#endif /* RAIL_MAP_H */