rail_map.h
author peter1138
Wed, 17 May 2006 21:26:12 +0000
changeset 3865 b80b50f14fcd
parent 3792 67c865c9315c
child 3900 2c84ed52709d
permissions -rw-r--r--
(svn r4901) - Codechange: change 'SpriteGroup *' to 'struct SpriteGroup *' within StationSpec and GRFFile struct declarations. Now only code which actually references those pointers needs to know about the SpriteGroup struct. Remove some unnecessary lingering header dependencies.
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
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
     3
#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
     4
#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
     5
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
     6
#include "direction.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
     7
#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
     8
9b1030ac7d83 (svn r3913) Move declarations to rail_map.h so rail.h is dependent on rail_map.h and not the other way round
tron
parents: 3238
diff changeset
     9
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
    10
typedef enum RailTileType {
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
    11
	RAIL_TILE_NORMAL         = 0x0,
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
    12
	RAIL_TILE_SIGNALS        = 0x40,
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
    13
	RAIL_TILE_UNUSED         = 0x80, /* XXX: Maybe this could become waypoints? */
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
    14
	RAIL_TILE_DEPOT_WAYPOINT = 0xC0, /* Is really depots and waypoints... */
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
    15
	RAIL_TILE_TYPE_MASK      = 0xC0
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
    16
} RailTileType;
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
    17
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
    18
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
    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
	assert(IsTileType(t, MP_RAILWAY));
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
	return _m[t].m5 & RAIL_TILE_TYPE_MASK;
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
}
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
    23
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    24
/**
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    25
 * 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
    26
 * 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
    27
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    28
static inline bool IsPlainRailTile(TileIndex tile)
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
	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
    31
	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
    32
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    33
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
 * 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
    36
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    37
static inline bool HasSignals(TileIndex tile)
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    38
{
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
    39
	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
    40
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    41
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
    42
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
    43
/** These specify the subtype when the main rail type is
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
    44
 * RAIL_TILE_DEPOT_WAYPOINT */
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
    45
typedef enum RailTileSubtypes {
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
    46
	RAIL_SUBTYPE_DEPOT    = 0x00,
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
    47
	RAIL_SUBTYPE_WAYPOINT = 0x04,
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
    48
	RAIL_SUBTYPE_MASK     = 0x3C
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
    49
} RailTileSubtype;
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
    50
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
 * Returns the RailTileSubtype of a given rail tile with type
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
    53
 * RAIL_TILE_DEPOT_WAYPOINT
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    54
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    55
static inline RailTileSubtype GetRailTileSubtype(TileIndex tile)
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    56
{
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
    57
	assert(GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT);
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    58
	return (RailTileSubtype)(_m[tile].m5 & RAIL_SUBTYPE_MASK);
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    59
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
    60
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
    61
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
    62
typedef enum RailTypes {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3273
diff changeset
    63
	RAILTYPE_RAIL     = 0,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3273
diff changeset
    64
	RAILTYPE_ELECTRIC = 1,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3273
diff changeset
    65
	RAILTYPE_MONO     = 2,
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3273
diff changeset
    66
	RAILTYPE_MAGLEV   = 3,
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
    67
	RAILTYPE_END,
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
	INVALID_RAILTYPE = 0xFF
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
} RailType;
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
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3273
diff changeset
    71
typedef byte RailTypeMask;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3273
diff changeset
    72
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
    73
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
    74
{
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
    75
	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
    76
}
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
    77
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    78
// TODO remove this by moving to the same bits as GetRailType()
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    79
static inline RailType GetRailTypeCrossing(TileIndex t)
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    80
{
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    81
	return (RailType)GB(_m[t].m4, 0, 4);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    82
}
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    83
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    84
static inline RailType GetRailTypeOnBridge(TileIndex t)
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    85
{
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    86
	return (RailType)GB(_m[t].m3, 4, 4);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    87
}
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    88
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    89
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
    90
{
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    91
	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
    92
}
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    93
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    94
// TODO remove this by moving to the same bits as SetRailType()
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    95
static inline void SetRailTypeCrossing(TileIndex t, RailType r)
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    96
{
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    97
	SB(_m[t].m4, 0, 4, r);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    98
}
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
    99
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   100
static inline void SetRailTypeOnBridge(TileIndex t, RailType r)
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   101
{
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   102
	SB(_m[t].m3, 4, 4, r);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   103
}
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3239
diff changeset
   104
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
   105
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
   106
/** These are used to specify a single track.
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
   107
 * Can be translated to a trackbit with TrackToTrackbit */
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
   108
typedef enum Track {
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
   109
	TRACK_X     = 0,
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
   110
	TRACK_Y     = 1,
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
   111
	TRACK_UPPER = 2,
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
   112
	TRACK_LOWER = 3,
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
   113
	TRACK_LEFT  = 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
   114
	TRACK_RIGHT = 5,
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
   115
	TRACK_END,
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
   116
	INVALID_TRACK = 0xFF
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
   117
} Track;
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
   118
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
   119
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
   120
/** Bitfield corresponding to Track */
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
   121
typedef enum TrackBits {
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
   122
	TRACK_BIT_X     = 1U << TRACK_X,
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
   123
	TRACK_BIT_Y     = 1U << TRACK_Y,
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
   124
	TRACK_BIT_UPPER = 1U << TRACK_UPPER,
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
   125
	TRACK_BIT_LOWER = 1U << TRACK_LOWER,
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
   126
	TRACK_BIT_LEFT  = 1U << TRACK_LEFT,
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
   127
	TRACK_BIT_RIGHT = 1U << TRACK_RIGHT,
3258
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   128
	TRACK_BIT_CROSS = TRACK_BIT_X     | TRACK_BIT_Y,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   129
	TRACK_BIT_HORZ  = TRACK_BIT_UPPER | TRACK_BIT_LOWER,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   130
	TRACK_BIT_VERT  = TRACK_BIT_LEFT  | TRACK_BIT_RIGHT,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   131
	TRACK_BIT_3WAY_NE = TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   132
	TRACK_BIT_3WAY_SE = TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   133
	TRACK_BIT_3WAY_SW = TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   134
	TRACK_BIT_3WAY_NW = TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
1c079364726d (svn r3946) Add short hand names for common track combinations
tron
parents: 3242
diff changeset
   135
	TRACK_BIT_ALL   = TRACK_BIT_CROSS | TRACK_BIT_HORZ | TRACK_BIT_VERT,
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
   136
	TRACK_BIT_MASK  = 0x3FU
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
   137
} TrackBits;
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
   138
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
   139
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
   140
{
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
   141
	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
   142
}
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
   143
3273
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   144
static inline void SetTrackBits(TileIndex t, TrackBits b)
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   145
{
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   146
	SB(_m[t].m5, 0, 6, b);
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   147
}
3089ecca8e21 (svn r3985) Make CmdBuildSingleRail() a bit more comprehensible
tron
parents: 3267
diff changeset
   148
3772
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   149
/**
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   150
 * 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
   151
 * a plain rail tile (IsPlainRailTile()).
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   152
 */
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   153
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
   154
{
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   155
	return HASBIT(GetTrackBits(tile), track);
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   156
}
f2cf079d7afe (svn r4764) Move some functions from rail.h to rail_map.h
tron
parents: 3575
diff changeset
   157
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
   158
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   159
static inline DiagDirection GetRailDepotDirection(TileIndex t)
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   160
{
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   161
	return (DiagDirection)GB(_m[t].m5, 0, 2);
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   162
}
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   163
3453
956365eb1f8a (svn r4286) -Fix: Typo in 4280
celestar
parents: 3448
diff changeset
   164
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
   165
{
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   166
	return HASBIT(_m[t].m5, 0) ? TRACK_Y : TRACK_X;
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   167
}
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3102
diff changeset
   168
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
   169
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
   170
{
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
   171
	return _m[t].m5 & 1 ? TRACK_BIT_Y : TRACK_BIT_X;
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
   172
}
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
   173
3448
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   174
static inline void SetCustomWaypointSprite(TileIndex t)
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   175
{
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   176
	SETBIT(_m[t].m3, 4);
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   177
}
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   178
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   179
static inline void ClearCustomWaypointSprite(TileIndex t)
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   180
{
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   181
	CLRBIT(_m[t].m3, 4);
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   182
}
bc96e486627d (svn r4280) -Codechange: Add and make use of map accessors concerning railway waypoints
celestar
parents: 3355
diff changeset
   183
3530
29d16a8c45cb (svn r4386) -Codechange: Add and make use of IsCustomWaypoint
celestar
parents: 3528
diff changeset
   184
static inline bool IsCustomWaypoint(TileIndex t)
29d16a8c45cb (svn r4386) -Codechange: Add and make use of IsCustomWaypoint
celestar
parents: 3528
diff changeset
   185
{
29d16a8c45cb (svn r4386) -Codechange: Add and make use of IsCustomWaypoint
celestar
parents: 3528
diff changeset
   186
	return HASBIT(_m[t].m3, 4);
29d16a8c45cb (svn r4386) -Codechange: Add and make use of IsCustomWaypoint
celestar
parents: 3528
diff changeset
   187
}
29d16a8c45cb (svn r4386) -Codechange: Add and make use of IsCustomWaypoint
celestar
parents: 3528
diff changeset
   188
3528
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   189
static inline Axis GetWaypointAxis(TileIndex t)
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   190
{
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   191
	return HASBIT(_m[t].m5, 0) ? AXIS_Y : AXIS_X;
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   192
}
42e939a5e21a (svn r4384) -Codechange: rail drawing code
celestar
parents: 3523
diff changeset
   193
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
   194
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
   195
typedef enum SignalType {
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
   196
	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
   197
	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
   198
	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
   199
	SIGTYPE_COMBO   = 3  // presignal inter-block
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
   200
} SignalType;
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
   201
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
   202
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
   203
{
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
   204
	assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
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
   205
	return (SignalType)GB(_m[t].m4, 0, 2);
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
   206
}
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
   207
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
   208
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
   209
{
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
   210
	assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
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
   211
	SB(_m[t].m4, 0, 2, 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
   212
}
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
   213
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
   214
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
   215
{
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
   216
	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
   217
}
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
   218
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
   219
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
   220
{
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
   221
	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
   222
}
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
   223
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
   224
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
   225
{
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
   226
	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
   227
	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
   228
	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
   229
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
   230
	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
   231
	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
   232
	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
   233
}
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
   234
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
   235
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   236
typedef enum SignalVariant {
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   237
	SIG_ELECTRIC  = 0,
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   238
	SIG_SEMAPHORE = 1
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   239
} SignalVariant;
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   240
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   241
static inline SignalVariant GetSignalVariant(TileIndex t)
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   242
{
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   243
	return (SignalVariant)GB(_m[t].m4, 2, 1);
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   244
}
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   245
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   246
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
   247
{
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   248
	SB(_m[t].m4, 2, 1, v);
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   249
}
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   250
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
   251
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
   252
{
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
   253
	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
   254
}
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
   255
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
   256
/** 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
   257
 * 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
   258
 * 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
   259
 */
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
   260
typedef enum SignalStates {
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
   261
	SIGNAL_STATE_RED = 0,
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
   262
	SIGNAL_STATE_GREEN = 1,
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
   263
} SignalState;
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
   264
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
   265
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
   266
{
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
   267
	return HASBIT(_m[t].m2, 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
   268
}
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
   269
3237
2cf19f9603b2 (svn r3911) Add functions to retrieve/set the signal variant (electric/semaphore)
tron
parents: 3185
diff changeset
   270
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   271
typedef enum RailGroundType {
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   272
	RAIL_MAP2LO_GROUND_MASK = 0xF,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   273
	RAIL_GROUND_BARREN = 0,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   274
	RAIL_GROUND_GRASS = 1,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   275
	RAIL_GROUND_FENCE_NW = 2,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   276
	RAIL_GROUND_FENCE_SE = 3,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   277
	RAIL_GROUND_FENCE_SENW = 4,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   278
	RAIL_GROUND_FENCE_NE = 5,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   279
	RAIL_GROUND_FENCE_SW = 6,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   280
	RAIL_GROUND_FENCE_NESW = 7,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   281
	RAIL_GROUND_FENCE_VERT1 = 8,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   282
	RAIL_GROUND_FENCE_VERT2 = 9,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   283
	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
   284
	RAIL_GROUND_FENCE_HORIZ2 = 11,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   285
	RAIL_GROUND_ICE_DESERT = 12,
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   286
} RailGroundType;
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   287
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   288
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
   289
{
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
   290
	if (GetRailTileType(t) == RAIL_TILE_DEPOT_WAYPOINT) {
3523
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   291
		SB(_m[t].m4, 0, 4, rgt);
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   292
		return;
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   293
	}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   294
	SB(_m[t].m2, 0, 4, rgt);
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   295
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   296
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   297
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
   298
{
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   299
	/* TODO Unify 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
   300
	if (GetRailTileType(t) == RAIL_TILE_DEPOT_WAYPOINT) return 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
   301
	return GB(_m[t].m2, 0, 4);
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   302
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   303
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   304
static inline bool IsBarrenRailGround(TileIndex t)
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   305
{
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   306
	return GetRailGroundType(t) == RAIL_GROUND_BARREN;
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   307
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   308
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   309
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
   310
{
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   311
	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
   312
}
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   313
549603ffba5d (svn r4379) -Codechange: Add and make use of map accessor functions concerning rail ground types
celestar
parents: 3522
diff changeset
   314
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
   315
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
   316
{
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
   317
	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
   318
	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
   319
	_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
   320
	_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
   321
	_m[t].m4 = 0;
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
   322
	_m[t].m5 = RAIL_TILE_NORMAL | 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
   323
}
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
   324
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
   325
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
   326
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
   327
{
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
   328
	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
   329
	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
   330
	_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
   331
	_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
   332
	_m[t].m4 = 0;
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
   333
	_m[t].m5 = RAIL_TILE_DEPOT_WAYPOINT | RAIL_SUBTYPE_DEPOT | 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
   334
}
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
   335
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
   336
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
   337
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
   338
{
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
   339
	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
   340
	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
   341
	_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
   342
	_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
   343
	_m[t].m4 = 0;
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
   344
	_m[t].m5 = RAIL_TILE_DEPOT_WAYPOINT | RAIL_SUBTYPE_WAYPOINT | 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
   345
}
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
   346
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
   347
#endif