road_map.c
author tron
Sun, 21 May 2006 13:51:36 +0000
changeset 3884 793081f80381
parent 3793 7fe24e10ea63
child 3927 e3bb59b8ce4f
permissions -rw-r--r--
(svn r4940) Remove the dubious feature of remembering the last built depot. It serves no real purpose except causing confusion
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
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     3
#include "stdafx.h"
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     4
#include "openttd.h"
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
     5
#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
     6
#include "functions.h"
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     7
#include "road_map.h"
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
     8
#include "station.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
     9
#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
    10
#include "station_map.h"
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    11
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    12
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    13
RoadBits GetAnyRoadBits(TileIndex tile)
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    14
{
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    15
	switch (GetTileType(tile)) {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    16
		case MP_STREET:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3404
diff changeset
    17
			switch (GetRoadTileType(tile)) {
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    18
				default:
3793
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3404
diff changeset
    19
				case ROAD_TILE_NORMAL:   return GetRoadBits(tile);
7fe24e10ea63 (svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents: 3404
diff changeset
    20
				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
    21
				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
    22
			}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    23
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    24
		case MP_STATION:
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
    25
			if (!IsRoadStopTile(tile)) return 0;
eb8ebfe5df67 (svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents: 3234
diff changeset
    26
			return DiagDirToRoadBits(GetRoadStopDir(tile));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    27
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    28
		case MP_TUNNELBRIDGE:
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    29
			if (IsBridge(tile)) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    30
				if (IsBridgeMiddle(tile)) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    31
					if (!IsTransportUnderBridge(tile) ||
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    32
							GetBridgeTransportType(tile) != TRANSPORT_ROAD) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    33
						return 0;
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    34
					}
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    35
					return GetRoadBitsUnderBridge(tile);
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    36
				} else {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    37
					// ending
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3196
diff changeset
    38
					if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return 0;
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
    39
					return DiagDirToRoadBits(ReverseDiagDir(GetBridgeRampDirection(tile)));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    40
				}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    41
			} else {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    42
				// tunnel
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
    43
				if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return 0;
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
    44
				return DiagDirToRoadBits(ReverseDiagDir(GetTunnelDirection(tile)));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    45
			}
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
		default: return 0;
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    48
	}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    49
}
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
    50
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
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
    52
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
    53
{
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
    54
	uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
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
    55
	return (byte)(r | (r >> 8));
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
    56
}