road_map.c
author bjarni
Thu, 23 Mar 2006 23:54:43 +0000
changeset 3311 138e38fa6fda
parent 3234 a2791a480b71
child 3404 eb8ebfe5df67
permissions -rw-r--r--
(svn r4074) -Feature: [Makefile] the makefile can now detect if iconv is present in the system
if detected, WITH_ICONV will be defined in the C code
WITH_ICONV is also added to Makefile.config
OSX do not use this flag setting in Makefile.config, as it is set at compile time based on target OS version
the actual C code is not changed as the current iconv code is hardcoded for OSX and would break if any other OS got iconv
This detection system is by request of Darkvater
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"
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    10
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
RoadBits GetAnyRoadBits(TileIndex tile)
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    13
{
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    14
	switch (GetTileType(tile)) {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    15
		case MP_STREET:
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    16
			switch (GetRoadType(tile)) {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    17
				default:
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    18
				case ROAD_NORMAL:   return GetRoadBits(tile);
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    19
				case ROAD_CROSSING: return GetCrossingRoadBits(tile);
3167
8323c2ccd029 (svn r3795) Add a function to request the orientation of a depot
tron
parents: 3154
diff changeset
    20
				case ROAD_DEPOT:    return DiagDirToRoadBits(GetRoadDepotDirection(tile));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    21
			}
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
		case MP_STATION:
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    24
			if (!IsRoadStationTile(tile)) return 0;
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    25
			return DiagDirToRoadBits(GetRoadStationDir(tile));
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    26
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    27
		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
    28
			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
    29
				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
    30
					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
    31
							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
    32
						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
    33
					}
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
					return GetRoadBitsUnderBridge(tile);
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    35
				} else {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    36
					// 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
    37
					if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return 0;
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3167
diff changeset
    38
					return DiagDirToRoadBits(ReverseDiagDir(GetBridgeRampDirection(tile)));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    39
				}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    40
			} else {
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    41
				// tunnel
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
    42
				if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return 0;
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
    43
				return DiagDirToRoadBits(ReverseDiagDir(GetTunnelDirection(tile)));
3146
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    44
			}
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
		default: return 0;
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    47
	}
8d95593c5ff0 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents:
diff changeset
    48
}
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
    49
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
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
    52
{
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
	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
    54
	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
    55
}