road_map.h
author celestar
Sun, 09 Apr 2006 17:50:00 +0000
changeset 3486 9596268c8674
parent 3430 fcc344e41319
child 3497 154080838ed1
permissions -rw-r--r--
(svn r4337) -Fix: A problem where GetRailType was called instead of GetRailTileType. Thanks to glx for noticing
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     1
/* $Id$ */
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     2
3145
e833d7a78887 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     3
#ifndef ROAD_MAP_H
e833d7a78887 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     4
#define ROAD_MAP_H
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     5
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     6
#include "macros.h"
3099
571719b2cee3 (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"
571719b2cee3 (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
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
     9
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    10
typedef enum RoadBits {
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    11
	ROAD_NW  = 1,
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    12
	ROAD_SW  = 2,
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    13
	ROAD_SE  = 4,
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    14
	ROAD_NE  = 8,
9a1fd047b595 (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,
9a1fd047b595 (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,
9a1fd047b595 (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
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    18
} RoadBits;
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    19
3103
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    20
static inline RoadBits ComplementRoadBits(RoadBits r)
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    21
{
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    22
	return ROAD_ALL ^ r;
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    23
}
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    24
3146
8d95593c5ff0 (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)
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    26
{
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    27
	return 1 << (3 ^ d);
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    28
}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    29
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    30
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    31
typedef enum RoadType {
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    32
	ROAD_NORMAL,
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    33
	ROAD_CROSSING,
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    34
	ROAD_DEPOT
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    35
} RoadType;
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    36
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    37
static inline RoadType GetRoadType(TileIndex t)
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    38
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    39
	assert(IsTileType(t, MP_STREET));
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    40
	return GB(_m[t].m5, 4, 4);
3150
729951cb5448 (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
}
729951cb5448 (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
729951cb5448 (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
    43
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    44
static inline RoadBits GetRoadBits(TileIndex t)
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    45
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    46
	assert(GetRoadType(t) == ROAD_NORMAL);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    47
	return GB(_m[t].m5, 0, 4);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    48
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    49
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    50
static inline void SetRoadBits(TileIndex t, RoadBits r)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    51
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    52
	assert(GetRoadType(t) == ROAD_NORMAL); // XXX incomplete
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    53
	SB(_m[t].m5, 0, 4, r);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    54
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    55
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    56
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    57
static inline Axis GetCrossingRoadAxis(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    58
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    59
	assert(GetRoadType(t) == ROAD_CROSSING);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    60
	return (Axis)GB(_m[t].m5, 3, 1);
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    61
}
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    62
3070
980529af506f (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    63
static inline RoadBits GetCrossingRoadBits(TileIndex tile)
980529af506f (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    64
{
3272
b3e2d8e19937 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    65
	return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
3070
980529af506f (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    66
}
980529af506f (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
    67
3103
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    68
static inline TrackBits GetCrossingRailBits(TileIndex tile)
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    69
{
3272
b3e2d8e19937 (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 ? TRACK_BIT_Y : TRACK_BIT_X;
3103
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    71
}
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    72
c0681c720481 (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    73
3274
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    74
// TODO swap owner of road and rail
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    75
static inline Owner GetCrossingRoadOwner(TileIndex t)
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    76
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    77
	assert(GetRoadType(t) == ROAD_CROSSING);
3274
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    78
	return (Owner)_m[t].m3;
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    79
}
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    80
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    81
static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    82
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    83
	assert(GetRoadType(t) == ROAD_CROSSING);
3274
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    84
	_m[t].m3 = o;
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    85
}
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
    86
3322
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    87
static inline void UnbarCrossing(TileIndex t)
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    88
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    89
	assert(GetRoadType(t) == ROAD_CROSSING);
3322
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    90
	CLRBIT(_m[t].m5, 2);
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    91
}
41b4d25b126d (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
41b4d25b126d (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
static inline void BarCrossing(TileIndex t)
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
    94
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    95
	assert(GetRoadType(t) == ROAD_CROSSING);
3322
41b4d25b126d (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
	SETBIT(_m[t].m5, 2);
41b4d25b126d (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
}
41b4d25b126d (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
41b4d25b126d (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
static inline bool IsCrossingBarred(TileIndex t)
41b4d25b126d (svn r4088) -Codechange: Introduce {Unb,B}arCrossing and IsCrossingBarred to put and get the status of a level crossing
celestar
parents: 3274
diff changeset
   100
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   101
	assert(GetRoadType(t) == ROAD_CROSSING);
3322
41b4d25b126d (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
	return HASBIT(_m[t].m5, 2);
41b4d25b126d (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
}
3274
555f8f5006fb (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
   104
3430
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   105
#define IsOnDesert IsOnSnow
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   106
static inline bool IsOnSnow(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   107
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   108
	return HASBIT(_m[t].m4, 7);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   109
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   110
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   111
#define ToggleDesert ToggleSnow
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   112
static inline void ToggleSnow(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   113
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   114
	TOGGLEBIT(_m[t].m4, 7);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   115
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   116
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   117
typedef enum RoadGroundType {
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   118
	RGT_BARREN,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   119
	RGT_GRASS,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   120
	RGT_PAVED,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   121
	RGT_LIGHT,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   122
	RGT_NOT_IN_USE, /* Has something to do with fund buildings */
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   123
	RGT_ALLEY,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   124
	RGT_ROADWORK_GRASS,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   125
	RGT_ROADWORK_PAVED,
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   126
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   127
	RGT_ROADWORK_OFFSET = RGT_ROADWORK_GRASS - RGT_GRASS
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   128
} RoadGroundType;
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   129
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   130
static inline RoadGroundType GetGroundType(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   131
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   132
	return (RoadGroundType)GB(_m[t].m4, 4, 3);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   133
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   134
fcc344e41319 (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 void SetGroundType(TileIndex t, RoadGroundType rgt)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   136
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   137
	SB(_m[t].m4, 4, 3, rgt);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   138
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   139
fcc344e41319 (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 bool HasRoadWorks(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   141
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   142
	return GetGroundType(t) >= RGT_ROADWORK_GRASS;
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   143
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   144
fcc344e41319 (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 IncreaseRoadWorksCounter(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   146
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   147
	AB(_m[t].m4, 0, 4, 1);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   148
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   149
	return GB(_m[t].m4, 0, 4) == 15;
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   150
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   151
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   152
static inline void StartRoadWorks(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   153
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   154
	assert(!HasRoadWorks(t));
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   155
	/* Remove any trees or lamps in case or roadwork */
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   156
	SetGroundType(t, min(GetGroundType(t), RGT_PAVED) + RGT_ROADWORK_OFFSET);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   157
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   158
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   159
static inline void TerminateRoadWorks(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   160
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   161
	assert(HasRoadWorks(t));
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   162
	SetGroundType(t, GetGroundType(t) - RGT_ROADWORK_OFFSET);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   163
	/* Stop the counter */
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   164
	SB(_m[t].m4, 0, 4, 0);
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   165
}
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   166
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   167
static inline bool HasPavement(TileIndex t)
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   168
{
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   169
	return GetGroundType(t) >= RGT_PAVED && GetGroundType(t) != RGT_ROADWORK_GRASS;
fcc344e41319 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   170
}
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   171
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   172
static inline DiagDirection GetRoadDepotDirection(TileIndex t)
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   173
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   174
	assert(GetRoadType(t) == ROAD_DEPOT);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   175
	return (DiagDirection)GB(_m[t].m5, 0, 2);
3167
8323c2ccd029 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   176
}
8323c2ccd029 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   177
8323c2ccd029 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   178
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   179
/**
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   180
 * Returns the RoadBits on an arbitrary tile
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   181
 * Special behavior:
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   182
 * - road depots: entrance is treated as road piece
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   183
 * - road tunnels: entrance is treated as road piece
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
   184
 * - bridge ramps: start of the ramp is treated as road piece
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   185
 * - bridge middle parts: bridge itself is ignored
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   186
 */
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   187
RoadBits GetAnyRoadBits(TileIndex);
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   188
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   189
3150
729951cb5448 (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
   190
TrackBits GetAnyRoadTrackBits(TileIndex tile);
729951cb5448 (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
   191
729951cb5448 (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
   192
3099
571719b2cee3 (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
   193
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, uint town)
571719b2cee3 (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
   194
{
571719b2cee3 (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
   195
	SetTileType(t, MP_STREET);
571719b2cee3 (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
   196
	SetTileOwner(t, owner);
571719b2cee3 (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
   197
	_m[t].m2 = town;
571719b2cee3 (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
	_m[t].m3 = 0;
571719b2cee3 (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
	_m[t].m4 = 0 << 7 | 0 << 4 | 0;
571719b2cee3 (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
	_m[t].m5 = ROAD_NORMAL << 4 | bits;
571719b2cee3 (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
}
571719b2cee3 (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
571719b2cee3 (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
571719b2cee3 (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
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
571719b2cee3 (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
{
571719b2cee3 (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
	SetTileType(t, MP_STREET);
571719b2cee3 (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
	SetTileOwner(t, rail);
571719b2cee3 (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
	_m[t].m2 = town;
571719b2cee3 (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
	_m[t].m3 = road;
571719b2cee3 (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
	_m[t].m4 = 0 << 7 | 0 << 4 | rt;
571719b2cee3 (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
	_m[t].m5 = ROAD_CROSSING << 4 | roaddir << 3 | 0 << 2;
571719b2cee3 (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
}
571719b2cee3 (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
571719b2cee3 (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
571719b2cee3 (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
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir)
571719b2cee3 (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
{
571719b2cee3 (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
	SetTileType(t, MP_STREET);
571719b2cee3 (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
	SetTileOwner(t, owner);
571719b2cee3 (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
	_m[t].m2 = 0;
571719b2cee3 (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
	_m[t].m3 = 0;
571719b2cee3 (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
	_m[t].m4 = 0;
571719b2cee3 (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
	_m[t].m5 = ROAD_DEPOT << 4 | dir;
571719b2cee3 (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
}
571719b2cee3 (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
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   225
#endif