src/road_map.cpp
author smatz
Sun, 16 Dec 2007 15:38:51 +0000
changeset 8083 ad22eade501f
parent 7928 63e18de69e50
child 8088 92fca5b09665
permissions -rw-r--r--
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     1
/* $Id$ */
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     2
6393
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6012
diff changeset
     3
/** @file road_map.cpp */
e1e4939d19b5 (svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents: 6012
diff changeset
     4
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     5
#include "stdafx.h"
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     6
#include "openttd.h"
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
     7
#include "bridge_map.h"
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
     8
#include "functions.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6418
diff changeset
     9
#include "landscape.h"
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    10
#include "road_map.h"
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    11
#include "station.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
    12
#include "tunnel_map.h"
3404
eb8ebfe5df67 (svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents: 3234
diff changeset
    13
#include "station_map.h"
3927
e3bb59b8ce4f (svn r5062) -Fix: town extends road beyond depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents: 3793
diff changeset
    14
#include "depot.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7928
diff changeset
    15
#include "tunnelbridge_map.h"
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    16
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    17
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6453
diff changeset
    18
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt)
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    19
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7370
diff changeset
    20
	if (!HasBit(GetRoadTypes(tile), rt)) return ROAD_NONE;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6453
diff changeset
    21
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    22
	switch (GetTileType(tile)) {
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 6683
diff changeset
    23
		case MP_ROAD:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3404
diff changeset
    24
			switch (GetRoadTileType(tile)) {
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    25
				default:
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6453
diff changeset
    26
				case ROAD_TILE_NORMAL:   return GetRoadBits(tile, rt);
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3404
diff changeset
    27
				case ROAD_TILE_CROSSING: return GetCrossingRoadBits(tile);
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3404
diff changeset
    28
				case ROAD_TILE_DEPOT:    return DiagDirToRoadBits(GetRoadDepotDirection(tile));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    29
			}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    30
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    31
		case MP_STATION:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    32
			if (!IsRoadStopTile(tile)) return ROAD_NONE;
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 5587
diff changeset
    33
			if (IsDriveThroughStopTile(tile)) return (GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y;
3404
eb8ebfe5df67 (svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents: 3234
diff changeset
    34
			return DiagDirToRoadBits(GetRoadStopDir(tile));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    35
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    36
		case MP_TUNNELBRIDGE:
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4777
diff changeset
    37
			if (IsTunnel(tile)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7928
diff changeset
    38
				if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7928
diff changeset
    39
				return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4777
diff changeset
    40
			} else {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7928
diff changeset
    41
				if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 7928
diff changeset
    42
				return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    43
			}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    44
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    45
		default: return ROAD_NONE;
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    46
	}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    47
}
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
    48
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
    49
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6453
diff changeset
    50
TrackBits GetAnyRoadTrackBits(TileIndex tile, RoadType rt)
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
    51
{
4233
5281a2fe51cc (svn r5798) - Fix [r5062]: When expanding a town, the test to check if a tile is a
peter1138
parents: 3977
diff changeset
    52
	uint32 r;
5281a2fe51cc (svn r5798) - Fix [r5062]: When expanding a town, the test to check if a tile is a
peter1138
parents: 3977
diff changeset
    53
6418
e04693bbe82a (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6393
diff changeset
    54
	/* Don't allow local authorities to build roads through road depots or road stops. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7370
diff changeset
    55
	if ((IsTileType(tile, MP_ROAD) && IsTileDepotType(tile, TRANSPORT_ROAD)) || (IsTileType(tile, MP_STATION) && !IsDriveThroughStopTile(tile)) || !HasBit(GetRoadTypes(tile), rt)) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    56
		return TRACK_BIT_NONE;
3927
e3bb59b8ce4f (svn r5062) -Fix: town extends road beyond depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents: 3793
diff changeset
    57
	}
4233
5281a2fe51cc (svn r5798) - Fix [r5062]: When expanding a town, the test to check if a tile is a
peter1138
parents: 3977
diff changeset
    58
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6661
diff changeset
    59
	r = GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(rt));
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6453
diff changeset
    60
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    61
	return (TrackBits)(byte)(r | (r >> 8));
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
    62
}