src/road_map.h
author rubidium
Sat, 26 Apr 2008 20:54:56 +0000
branch0.6
changeset 10366 960aae8c20e2
parent 9212 3503ffa351b6
child 9230 1c0a7c2ee6e5
permissions -rw-r--r--
(svn r12907) [0.6] -Backport from trunk r12906:
- Fix: Vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (r12906)
[0.6] -Prepare: for 0.6.1-RC1.
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
6889
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6886
diff changeset
     3
/** @file road_map.h */
f7f6d9cb07a0 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6886
diff changeset
     4
3145
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     5
#ifndef ROAD_MAP_H
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     6
#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
     7
8597
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8428
diff changeset
     8
#include "track_func.h"
87f03bc9c8e4 (svn r11662) -Codechange: move some rail types/related functions around.
rubidium
parents: 8428
diff changeset
     9
#include "rail_type.h"
8709
4187ad809fe7 (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8609
diff changeset
    10
#include "town_type.h"
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
    11
#include "road_func.h"
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8598
diff changeset
    12
#include "tile_map.h"
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
    13
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
    14
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6498
diff changeset
    15
enum RoadTileType {
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3560
diff changeset
    16
	ROAD_TILE_NORMAL,
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3560
diff changeset
    17
	ROAD_TILE_CROSSING,
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3560
diff changeset
    18
	ROAD_TILE_DEPOT
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6498
diff changeset
    19
};
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    20
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3560
diff changeset
    21
static inline RoadTileType GetRoadTileType(TileIndex t)
9025
2f0d4cf64ebc (svn r12104) -Fix (r12103): remember loading indicators transparency settings and make in switchable by Ctrl+9
smatz
parents: 8840
diff changeset
    22
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
    23
	assert(IsTileType(t, MP_ROAD));
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    24
	return (RoadTileType)GB(_m[t].m5, 6, 2);
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
    25
}
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
    26
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    27
static inline bool IsNormalRoad(TileIndex t)
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    28
{
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    29
	return GetRoadTileType(t) == ROAD_TILE_NORMAL;
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    30
}
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    31
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    32
static inline bool IsNormalRoadTile(TileIndex t)
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    33
{
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    34
	return IsTileType(t, MP_ROAD) && IsNormalRoad(t);
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    35
}
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    36
3497
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    37
static inline bool IsLevelCrossing(TileIndex t)
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    38
{
3793
33cdb5bf7b21 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3560
diff changeset
    39
	return GetRoadTileType(t) == ROAD_TILE_CROSSING;
3497
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    40
}
b3b7e1664379 (svn r4348) Move IsLevelCrossing() from rail.h to road_map.h
tron
parents: 3430
diff changeset
    41
3560
4389ae5ad967 (svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents: 3518
diff changeset
    42
static inline bool IsLevelCrossingTile(TileIndex t)
4389ae5ad967 (svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents: 3518
diff changeset
    43
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
    44
	return IsTileType(t, MP_ROAD) && IsLevelCrossing(t);
3560
4389ae5ad967 (svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents: 3518
diff changeset
    45
}
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
    46
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    47
static inline bool IsRoadDepot(TileIndex t)
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    48
{
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    49
	return GetRoadTileType(t) == ROAD_TILE_DEPOT;
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    50
}
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    51
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    52
static inline bool IsRoadDepotTile(TileIndex t)
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    53
{
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    54
	return IsTileType(t, MP_ROAD) && IsRoadDepot(t);
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    55
}
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    56
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    57
static inline RoadBits GetRoadBits(TileIndex t, RoadType rt)
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
    58
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    59
	assert(IsNormalRoad(t));
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    60
	switch (rt) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    61
		default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    62
		case ROADTYPE_ROAD: return (RoadBits)GB(_m[t].m4, 0, 4);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    63
		case ROADTYPE_TRAM: return (RoadBits)GB(_m[t].m4, 4, 4);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    64
		case ROADTYPE_HWAY: return (RoadBits)GB(_m[t].m6, 2, 4);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    65
	}
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    66
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    67
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    68
static inline RoadBits GetAllRoadBits(TileIndex tile)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    69
{
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    70
	return GetRoadBits(tile, ROADTYPE_ROAD) | GetRoadBits(tile, ROADTYPE_TRAM) | GetRoadBits(tile, ROADTYPE_HWAY);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    71
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    72
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    73
static inline void SetRoadBits(TileIndex t, RoadBits r, RoadType rt)
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    74
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
    75
	assert(IsNormalRoad(t)); // XXX incomplete
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    76
	switch (rt) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    77
		default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    78
		case ROADTYPE_ROAD: SB(_m[t].m4, 0, 4, r); break;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    79
		case ROADTYPE_TRAM: SB(_m[t].m4, 4, 4, r); break;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    80
		case ROADTYPE_HWAY: SB(_m[t].m6, 2, 4, r); break;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    81
	}
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    82
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
    83
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    84
static inline RoadTypes GetRoadTypes(TileIndex t)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    85
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
    86
	if (IsTileType(t, MP_ROAD)) {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    87
		return (RoadTypes)GB(_me[t].m7, 5, 3);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    88
	} else {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    89
		return (RoadTypes)GB(_m[t].m3, 0, 3);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    90
	}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    91
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    92
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    93
static inline void SetRoadTypes(TileIndex t, RoadTypes rt)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    94
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
    95
	if (IsTileType(t, MP_ROAD)) {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    96
		SB(_me[t].m7, 5, 3, rt);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    97
	} else {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    98
		assert(IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE));
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
    99
		SB(_m[t].m3, 0, 2, rt);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   100
	}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   101
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   102
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   103
static inline bool HasTileRoadType(TileIndex t, RoadType rt)
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   104
{
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   105
	return HasBit(GetRoadTypes(t), rt);
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   106
}
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   107
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   108
static inline Owner GetRoadOwner(TileIndex t, RoadType rt)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   109
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
   110
	if (!IsTileType(t, MP_ROAD)) return GetTileOwner(t);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   111
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   112
	switch (GetRoadTileType(t)) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   113
		default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   114
		case ROAD_TILE_NORMAL:
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   115
			switch (rt) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   116
				default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   117
				case ROADTYPE_ROAD: return (Owner)GB( _m[t].m1, 0, 5);
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   118
				case ROADTYPE_TRAM: {
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   119
					/* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   120
					 * to OWNER_TOWN makes it use one bit less */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   121
					Owner o = (Owner)GB( _m[t].m5, 0, 4);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   122
					return o == OWNER_TOWN ? OWNER_NONE : o;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   123
				}
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   124
				case ROADTYPE_HWAY: return (Owner)GB(_me[t].m7, 0, 5);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   125
			}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   126
		case ROAD_TILE_CROSSING:
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   127
			switch (rt) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   128
				default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   129
				case ROADTYPE_ROAD: return (Owner)GB( _m[t].m4, 0, 5);
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   130
				case ROADTYPE_TRAM: {
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   131
					/* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   132
					 * to OWNER_TOWN makes it use one bit less */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   133
					Owner o = (Owner)GB( _m[t].m5, 0, 4);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   134
					return o == OWNER_TOWN ? OWNER_NONE : o;
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   135
				}
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   136
				case ROADTYPE_HWAY: return (Owner)GB(_me[t].m7, 0, 5);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   137
			}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   138
		case ROAD_TILE_DEPOT: return GetTileOwner(t);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   139
	}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   140
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   141
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   142
static inline void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   143
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
   144
	if (!IsTileType(t, MP_ROAD)) return SetTileOwner(t, o);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   145
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   146
	switch (GetRoadTileType(t)) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   147
		default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   148
		case ROAD_TILE_NORMAL:
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   149
			switch (rt) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   150
				default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   151
				case ROADTYPE_ROAD: SB( _m[t].m1, 0, 5, o); break;
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   152
				case ROADTYPE_TRAM: SB( _m[t].m5, 0, 4, o == OWNER_NONE ? OWNER_TOWN : o); break;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   153
				case ROADTYPE_HWAY: SB(_me[t].m7, 0, 5, o); break;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   154
			}
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   155
			break;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   156
		case ROAD_TILE_CROSSING:
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   157
			switch (rt) {
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   158
				default: NOT_REACHED();
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   159
				case ROADTYPE_ROAD: SB( _m[t].m4, 0, 5, o); break;
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   160
				/* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   161
				 * to OWNER_TOWN makes it use one bit less */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   162
				case ROADTYPE_TRAM: SB( _m[t].m5, 0, 4, o == OWNER_NONE ? OWNER_TOWN : o); break;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   163
				case ROADTYPE_HWAY: SB(_me[t].m7, 0, 5, o); break;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   164
			}
7158
ffb31324aa5e (svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
rubidium
parents: 7157
diff changeset
   165
			break;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   166
		case ROAD_TILE_DEPOT: return SetTileOwner(t, o);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   167
	}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   168
}
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   169
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   170
/** Which directions are disallowed ? */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   171
enum DisallowedRoadDirections {
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   172
	DRD_NONE,       ///< None of the directions are disallowed
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   173
	DRD_SOUTHBOUND, ///< All southbound traffic is disallowed
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   174
	DRD_NORTHBOUND, ///< All northbound traffic is disallowed
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   175
	DRD_BOTH,       ///< All directions are disallowed
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   176
	DRD_END
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   177
};
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   178
DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   179
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   180
/**
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   181
 * Gets the disallowed directions
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   182
 * @param t the tile to get the directions from
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   183
 * @return the disallowed directions
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   184
 */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   185
static inline DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   186
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   187
	assert(IsNormalRoad(t));
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   188
	return (DisallowedRoadDirections)GB(_m[t].m5, 4, 2);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   189
}
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   190
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   191
/**
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   192
 * Sets the disallowed directions
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   193
 * @param t   the tile to set the directions for
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   194
 * @param drd the disallowed directions
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   195
 */
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   196
static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirections drd)
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   197
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   198
	assert(IsNormalRoad(t));
7260
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   199
	assert(drd < DRD_END);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   200
	SB(_m[t].m5, 4, 2, drd);
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   201
}
23cd58b6bf51 (svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
rubidium
parents: 7158
diff changeset
   202
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   203
static inline Axis GetCrossingRoadAxis(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   204
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   205
	assert(IsLevelCrossing(t));
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   206
	return (Axis)GB(_m[t].m4, 6, 1);
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
   207
}
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
   208
9094
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   209
static inline Axis GetCrossingRailAxis(TileIndex t)
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   210
{
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   211
	assert(IsLevelCrossing(t));
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   212
	return OtherAxis((Axis)GetCrossingRoadAxis(t));
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   213
}
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   214
3070
512f72481fd9 (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
   215
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
   216
{
3272
7e556f209503 (svn r3984) Add a function to get the road axis of a level crossing
tron
parents: 3196
diff changeset
   217
	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
   218
}
512f72481fd9 (svn r3659) Add function to get the road bits of a level crossing
tron
parents: 3069
diff changeset
   219
9094
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   220
static inline Track GetCrossingRailTrack(TileIndex tile)
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   221
{
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   222
	return AxisToTrack(GetCrossingRailAxis(tile));
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   223
}
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   224
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
   225
static inline TrackBits GetCrossingRailBits(TileIndex tile)
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
   226
{
9094
58d1cddf1af6 (svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
smatz
parents: 9059
diff changeset
   227
	return AxisToTrackBits(GetCrossingRailAxis(tile));
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
   228
}
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
   229
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   230
static inline bool IsCrossingBarred(TileIndex t)
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   231
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   232
	assert(IsLevelCrossing(t));
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   233
	return HasBit(_m[t].m4, 5);
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   234
}
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   235
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   236
static inline void SetCrossingBarred(TileIndex t, bool barred)
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   237
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   238
	assert(IsLevelCrossing(t));
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   239
	SB(_m[t].m4, 5, 1, barred);
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   240
}
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
   241
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
   242
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
   243
{
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   244
	SetCrossingBarred(t, false);
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
   245
}
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
   246
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
   247
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
   248
{
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8709
diff changeset
   249
	SetCrossingBarred(t, true);
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
   250
}
3274
e3fd60498b38 (svn r3986) Add [GS]etCrossingRoadOwner
tron
parents: 3272
diff changeset
   251
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   252
#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
   253
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
   254
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7866
diff changeset
   255
	return HasBit(_m[t].m3, 7);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   256
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   257
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   258
#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
   259
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
   260
{
8428
f8300c908bd9 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 8427
diff changeset
   261
	ToggleBit(_m[t].m3, 7);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   262
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   263
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   264
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6498
diff changeset
   265
enum Roadside {
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   266
	ROADSIDE_BARREN           = 0,
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   267
	ROADSIDE_GRASS            = 1,
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   268
	ROADSIDE_PAVED            = 2,
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   269
	ROADSIDE_STREET_LIGHTS    = 3,
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   270
	ROADSIDE_TREES            = 5,
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   271
	ROADSIDE_GRASS_ROAD_WORKS = 6,
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   272
	ROADSIDE_PAVED_ROAD_WORKS = 7
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6498
diff changeset
   273
};
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   274
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   275
static inline Roadside GetRoadside(TileIndex tile)
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   276
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 5726
diff changeset
   277
	return (Roadside)GB(_m[tile].m3, 4, 3);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   278
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   279
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   280
static inline void SetRoadside(TileIndex tile, Roadside s)
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   281
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 5726
diff changeset
   282
	SB(_m[tile].m3, 4, 3, s);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   283
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   284
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   285
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
   286
{
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   287
	return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   288
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   289
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   290
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
   291
{
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 5726
diff changeset
   292
	AB(_m[t].m3, 0, 4, 1);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   293
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 5726
diff changeset
   294
	return GB(_m[t].m3, 0, 4) == 15;
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   295
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   296
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   297
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
   298
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   299
	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
   300
	/* Remove any trees or lamps in case or roadwork */
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   301
	switch (GetRoadside(t)) {
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   302
		case ROADSIDE_BARREN:
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   303
		case ROADSIDE_GRASS:  SetRoadside(t, ROADSIDE_GRASS_ROAD_WORKS); break;
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   304
		default:              SetRoadside(t, ROADSIDE_PAVED_ROAD_WORKS); break;
4045
e85dc17faa9f (svn r5314) -Regression: When road works started on a road tile with barren roadside the road side turned into trees (caused by r4258)
tron
parents: 4000
diff changeset
   305
	}
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   306
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   307
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   308
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
   309
{
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   310
	assert(HasRoadWorks(t));
4048
e773f441eb4f (svn r5317) s/RGT_/ROADSIDE_/ and some minor changes
tron
parents: 4045
diff changeset
   311
	SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   312
	/* Stop the counter */
6498
aff910a05c6e (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 5726
diff changeset
   313
	SB(_m[t].m3, 0, 4, 0);
3430
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   314
}
b283bb956a36 (svn r4258) -Codechange: Add and make use of map accessors dealing with road ground types (including roadworks).
celestar
parents: 3369
diff changeset
   315
3069
0e6aca11c3da (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
diff changeset
   316
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   317
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
   318
{
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9025
diff changeset
   319
	assert(IsRoadDepot(t));
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3322
diff changeset
   320
	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
   321
}
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   322
197b5ee5a831 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3150
diff changeset
   323
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   324
/**
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   325
 * Returns the RoadBits on an arbitrary tile
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6574
diff changeset
   326
 * Special behaviour:
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   327
 * - 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
   328
 * - road tunnels: entrance is treated as road piece
3196
29717e930f9a (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
   329
 * - 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
   330
 * - bridge middle parts: bridge itself is ignored
9212
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 9094
diff changeset
   331
 *
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 9094
diff changeset
   332
 * If straight_tunnel_bridge_entrance is set a ROAD_X or ROAD_Y
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 9094
diff changeset
   333
 * for bridge ramps and tunnel entrances is returned depending
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 9094
diff changeset
   334
 * on the orientation of the tunnel or bridge.
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   335
 * @param tile the tile to get the road bits for
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   336
 * @param rt   the road type to get the road bits form
9212
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 9094
diff changeset
   337
 * @param stbe whether to return straight road bits for tunnels/bridges.
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   338
 * @return the road bits of the given tile
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   339
 */
9212
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 9094
diff changeset
   340
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance = false);
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   341
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   342
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   343
 * Get the accessible track bits for the given tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   344
 * Special behaviour:
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   345
 *  - road depots: no track bits
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   346
 *  - non-drive-through stations: no track bits
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   347
 * @param tile the tile to get the track bits for
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   348
 * @return the track bits for the given tile
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6889
diff changeset
   349
 */
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   350
TrackBits GetAnyRoadTrackBits(TileIndex tile, RoadType rt);
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
   351
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   352
/**
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   353
 * Return if the tile is a valid tile for a crossing.
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   354
 *
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   355
 * @note function is overloaded
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   356
 * @param tile the curent tile
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   357
 * @param ax the axis of the road over the rail
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   358
 * @return true if it is a valid tile
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   359
 */
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   360
bool IsPossibleCrossing(const TileIndex tile, Axis ax);
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8597
diff changeset
   361
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
   362
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   363
static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram, Owner hway)
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
   364
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
   365
	SetTileType(t, MP_ROAD);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   366
	SetTileOwner(t, road);
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
   367
	_m[t].m2 = town;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   368
	_m[t].m3 = 0;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7866
diff changeset
   369
	_m[t].m4 = (HasBit(rot, ROADTYPE_TRAM) ? bits : 0) << 4 | (HasBit(rot, ROADTYPE_ROAD) ? bits : 0);
7274
7b29469b978b (svn r10014) -Fix: roads became automatically one way in the scenario editor.
rubidium
parents: 7260
diff changeset
   370
	_m[t].m5 = ROAD_TILE_NORMAL << 6;
7b29469b978b (svn r10014) -Fix: roads became automatically one way in the scenario editor.
rubidium
parents: 7260
diff changeset
   371
	SetRoadOwner(t, ROADTYPE_TRAM, tram);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7866
diff changeset
   372
	SB(_m[t].m6, 2, 4, HasBit(rot, ROADTYPE_HWAY) ? bits : 0);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   373
	_me[t].m7 = rot << 5 | hway;
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
   374
}
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
   375
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
   376
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   377
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner hway, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town)
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
   378
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
   379
	SetTileType(t, MP_ROAD);
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
   380
	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
   381
	_m[t].m2 = town;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   382
	_m[t].m3 = rat;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   383
	_m[t].m4 = roaddir << 6 | road;
7274
7b29469b978b (svn r10014) -Fix: roads became automatically one way in the scenario editor.
rubidium
parents: 7260
diff changeset
   384
	_m[t].m5 = ROAD_TILE_CROSSING << 6;
7b29469b978b (svn r10014) -Fix: roads became automatically one way in the scenario editor.
rubidium
parents: 7260
diff changeset
   385
	SetRoadOwner(t, ROADTYPE_TRAM, tram);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   386
	SB(_m[t].m6, 2, 4, 0);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   387
	_me[t].m7 = rot << 5 | hway;
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
   388
}
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
   389
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
   390
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   391
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir, RoadType rt)
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
   392
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7274
diff changeset
   393
	SetTileType(t, MP_ROAD);
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
   394
	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
   395
	_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
   396
	_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
   397
	_m[t].m4 = 0;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   398
	_m[t].m5 = ROAD_TILE_DEPOT << 6 | dir;
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   399
	SB(_m[t].m6, 2, 4, 0);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6914
diff changeset
   400
	_me[t].m7 = RoadTypeToRoadTypes(rt) << 5;
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
   401
}
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
   402
4666
850b5b6e4bac (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4158
diff changeset
   403
#endif /* ROAD_MAP_H */