road_map.h
author tron
Mon, 10 Apr 2006 20:38:59 +0000
changeset 3497 b3b7e1664379
parent 3430 b283bb956a36
child 3518 53847cf852c6
permissions -rw-r--r--
(svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     1
/* $Id$ */
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     2
3145
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     3
#ifndef ROAD_MAP_H
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     4
#define ROAD_MAP_H
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     5
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     6
#include "macros.h"
3099
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
     7
#include "rail.h"
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
     8
#include "tile.h"
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     9
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    10
typedef enum RoadBits {
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    11
	ROAD_NW  = 1,
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    12
	ROAD_SW  = 2,
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    13
	ROAD_SE  = 4,
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    14
	ROAD_NE  = 8,
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    15
	ROAD_X   = ROAD_SW | ROAD_NE,
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    16
	ROAD_Y   = ROAD_NW | ROAD_SE,
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    17
	ROAD_ALL = ROAD_X  | ROAD_Y
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    18
} RoadBits;
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    19
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    20
static inline RoadBits ComplementRoadBits(RoadBits r)
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    21
{
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    22
	return ROAD_ALL ^ r;
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    23
}
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    24
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    25
static inline RoadBits DiagDirToRoadBits(DiagDirection d)
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    26
{
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    27
	return 1 << (3 ^ d);
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    28
}
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    29
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    30
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    31
typedef enum RoadType {
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    32
	ROAD_NORMAL,
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    33
	ROAD_CROSSING,
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    34
	ROAD_DEPOT
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    35
} RoadType;
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    36
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    37
static inline RoadType GetRoadType(TileIndex t)
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    38
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    39
	assert(IsTileType(t, MP_STREET));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    40
	return GB(_m[t].m5, 4, 4);
3150
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3146
diff changeset
    41
}
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3146
diff changeset
    42
3497
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    43
static inline bool IsLevelCrossing(TileIndex t)
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    44
{
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    45
	return GetRoadType(t) == ROAD_CROSSING;
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    46
}
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    47
3150
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3146
diff changeset
    48
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    49
static inline RoadBits GetRoadBits(TileIndex t)
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    50
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    51
	assert(GetRoadType(t) == ROAD_NORMAL);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    52
	return GB(_m[t].m5, 0, 4);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    53
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    54
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    55
static inline void SetRoadBits(TileIndex t, RoadBits r)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    56
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    57
	assert(GetRoadType(t) == ROAD_NORMAL); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    58
	SB(_m[t].m5, 0, 4, r);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    59
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    60
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    61
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    62
static inline Axis GetCrossingRoadAxis(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    63
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    64
	assert(GetRoadType(t) == ROAD_CROSSING);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    65
	return (Axis)GB(_m[t].m5, 3, 1);
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    66
}
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    67
3070
512f72481fd9 (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    68
static inline RoadBits GetCrossingRoadBits(TileIndex tile)
512f72481fd9 (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    69
{
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    70
	return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
3070
512f72481fd9 (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    71
}
512f72481fd9 (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    72
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    73
static inline TrackBits GetCrossingRailBits(TileIndex tile)
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    74
{
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    75
	return GetCrossingRoadAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X;
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    76
}
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    77
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    78
3274
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    79
// TODO swap owner of road and rail
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    80
static inline Owner GetCrossingRoadOwner(TileIndex t)
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    81
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    82
	assert(GetRoadType(t) == ROAD_CROSSING);
3274
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    83
	return (Owner)_m[t].m3;
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    84
}
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    85
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    86
static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    87
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    88
	assert(GetRoadType(t) == ROAD_CROSSING);
3274
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    89
	_m[t].m3 = o;
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    90
}
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    91
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    92
static inline void UnbarCrossing(TileIndex t)
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    93
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    94
	assert(GetRoadType(t) == ROAD_CROSSING);
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    95
	CLRBIT(_m[t].m5, 2);
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    96
}
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    97
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    98
static inline void BarCrossing(TileIndex t)
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    99
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   100
	assert(GetRoadType(t) == ROAD_CROSSING);
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   101
	SETBIT(_m[t].m5, 2);
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   102
}
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   103
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   104
static inline bool IsCrossingBarred(TileIndex t)
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   105
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   106
	assert(GetRoadType(t) == ROAD_CROSSING);
3322
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   107
	return HASBIT(_m[t].m5, 2);
fa5d46929db9 (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   108
}
3274
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
   109
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   110
#define IsOnDesert IsOnSnow
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   111
static inline bool IsOnSnow(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   112
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   113
	return HASBIT(_m[t].m4, 7);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   114
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   115
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   116
#define ToggleDesert ToggleSnow
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   117
static inline void ToggleSnow(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   118
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   119
	TOGGLEBIT(_m[t].m4, 7);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   120
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   121
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   122
typedef enum RoadGroundType {
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   123
	RGT_BARREN,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   124
	RGT_GRASS,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   125
	RGT_PAVED,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   126
	RGT_LIGHT,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   127
	RGT_NOT_IN_USE, /* Has something to do with fund buildings */
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   128
	RGT_ALLEY,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   129
	RGT_ROADWORK_GRASS,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   130
	RGT_ROADWORK_PAVED,
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   131
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   132
	RGT_ROADWORK_OFFSET = RGT_ROADWORK_GRASS - RGT_GRASS
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   133
} RoadGroundType;
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   134
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   135
static inline RoadGroundType GetGroundType(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   136
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   137
	return (RoadGroundType)GB(_m[t].m4, 4, 3);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   138
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   139
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   140
static inline void SetGroundType(TileIndex t, RoadGroundType rgt)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   141
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   142
	SB(_m[t].m4, 4, 3, rgt);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   143
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   144
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   145
static inline bool HasRoadWorks(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   146
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   147
	return GetGroundType(t) >= RGT_ROADWORK_GRASS;
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   148
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   149
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   150
static inline bool IncreaseRoadWorksCounter(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   151
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   152
	AB(_m[t].m4, 0, 4, 1);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   153
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   154
	return GB(_m[t].m4, 0, 4) == 15;
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   155
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   156
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   157
static inline void StartRoadWorks(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   158
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   159
	assert(!HasRoadWorks(t));
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   160
	/* Remove any trees or lamps in case or roadwork */
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   161
	SetGroundType(t, min(GetGroundType(t), RGT_PAVED) + RGT_ROADWORK_OFFSET);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   162
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   163
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   164
static inline void TerminateRoadWorks(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   165
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   166
	assert(HasRoadWorks(t));
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   167
	SetGroundType(t, GetGroundType(t) - RGT_ROADWORK_OFFSET);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   168
	/* Stop the counter */
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   169
	SB(_m[t].m4, 0, 4, 0);
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   170
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   171
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   172
static inline bool HasPavement(TileIndex t)
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   173
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   174
	return GetGroundType(t) >= RGT_PAVED && GetGroundType(t) != RGT_ROADWORK_GRASS;
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   175
}
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   176
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   177
static inline DiagDirection GetRoadDepotDirection(TileIndex t)
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   178
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   179
	assert(GetRoadType(t) == ROAD_DEPOT);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   180
	return (DiagDirection)GB(_m[t].m5, 0, 2);
3167
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   181
}
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   182
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   183
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   184
/**
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   185
 * Returns the RoadBits on an arbitrary tile
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   186
 * Special behavior:
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   187
 * - road depots: entrance is treated as road piece
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   188
 * - road tunnels: entrance is treated as road piece
3196
29717e930f9a (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
   189
 * - bridge ramps: start of the ramp is treated as road piece
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   190
 * - bridge middle parts: bridge itself is ignored
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   191
 */
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   192
RoadBits GetAnyRoadBits(TileIndex);
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   193
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   194
3150
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3146
diff changeset
   195
TrackBits GetAnyRoadTrackBits(TileIndex tile);
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3146
diff changeset
   196
025fe8cd7104 (svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents: 3146
diff changeset
   197
3099
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   198
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, uint town)
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   199
{
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   200
	SetTileType(t, MP_STREET);
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   201
	SetTileOwner(t, owner);
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   202
	_m[t].m2 = town;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   203
	_m[t].m3 = 0;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   204
	_m[t].m4 = 0 << 7 | 0 << 4 | 0;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   205
	_m[t].m5 = ROAD_NORMAL << 4 | bits;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   206
}
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   207
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   208
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   209
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   210
{
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   211
	SetTileType(t, MP_STREET);
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   212
	SetTileOwner(t, rail);
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   213
	_m[t].m2 = town;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   214
	_m[t].m3 = road;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   215
	_m[t].m4 = 0 << 7 | 0 << 4 | rt;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   216
	_m[t].m5 = ROAD_CROSSING << 4 | roaddir << 3 | 0 << 2;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   217
}
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   218
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   219
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   220
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir)
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   221
{
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   222
	SetTileType(t, MP_STREET);
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   223
	SetTileOwner(t, owner);
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   224
	_m[t].m2 = 0;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   225
	_m[t].m3 = 0;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   226
	_m[t].m4 = 0;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   227
	_m[t].m5 = ROAD_DEPOT << 4 | dir;
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   228
}
374e275300e3 (svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
tron
parents: 3070
diff changeset
   229
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   230
#endif