src/road_func.h
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9230 1c0a7c2ee6e5
permissions -rw-r--r--
update tags
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
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8424
diff changeset
     3
/** @file road_func.h Functions related to roads. */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
     4
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8424
diff changeset
     5
#ifndef ROAD_FUNC_H
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8424
diff changeset
     6
#define ROAD_FUNC_H
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
     7
8609
8c0c3e9dd6a0 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8598
diff changeset
     8
#include "core/bitmath_func.hpp"
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8424
diff changeset
     9
#include "road_type.h"
8634
5ffca02f9115 (svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents: 8609
diff changeset
    10
#include "direction_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8732
diff changeset
    11
#include "player_type.h"
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    12
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    13
/**
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    14
 * Whether the given roadtype is valid.
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    15
 * @param rt the roadtype to check for validness
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    16
 * @return true if and only if valid
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    17
 */
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    18
static inline bool IsValidRoadType(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: 6889
diff changeset
    19
{
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7157
diff changeset
    20
	return rt == ROADTYPE_ROAD || rt == ROADTYPE_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: 6889
diff changeset
    21
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    22
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    23
/**
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    24
 * Are the given bits pointing to valid roadtypes?
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    25
 * @param rts the roadtypes to check for validness
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    26
 * @return true if and only if valid
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    27
 */
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    28
static inline bool AreValidRoadTypes(RoadTypes rts)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    29
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8137
diff changeset
    30
	return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_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: 6889
diff changeset
    31
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    32
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    33
/**
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    34
 * Maps a RoadType to the corresponding RoadTypes value
7891
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    35
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    36
 * @param rt the roadtype to get the roadtypes from
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    37
 * @return the roadtypes with the given roadtype
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    38
 */
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    39
static inline RoadTypes RoadTypeToRoadTypes(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: 6889
diff changeset
    40
{
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    41
	return (RoadTypes)(1 << rt);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    42
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    43
7891
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    44
/**
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    45
 * Returns the RoadTypes which are not present in the given RoadTypes
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    46
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    47
 * This function returns the complement of a given RoadTypes.
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    48
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    49
 * @param r The given RoadTypes
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    50
 * @return The complement of the given RoadTypes
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    51
 * @note The unused value ROADTYPES_HWAY will be used, too.
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    52
 */
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    53
static inline RoadTypes ComplementRoadTypes(RoadTypes r)
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    54
{
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    55
	return (RoadTypes)(ROADTYPES_ALL ^ r);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    56
}
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6889
diff changeset
    57
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    58
7891
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    59
/**
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    60
 * Calculate the complement of a RoadBits value
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    61
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    62
 * Simply flips all bits in the RoadBits value to get the complement
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    63
 * of the RoadBits.
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    64
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    65
 * @param r The given RoadBits value
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    66
 * @return the complement
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    67
 */
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    68
static inline RoadBits ComplementRoadBits(RoadBits r)
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    69
{
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3795
diff changeset
    70
	return (RoadBits)(ROAD_ALL ^ r);
3103
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    71
}
fb7f22d3bc9b (svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
tron
parents: 3099
diff changeset
    72
7891
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
    73
/**
8137
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    74
 * Calculate the mirrored RoadBits
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    75
 *
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    76
 * Simply move the bits to their new position.
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    77
 *
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    78
 * @param r The given RoadBits value
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    79
 * @return the mirrored
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    80
 */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    81
static inline RoadBits MirrorRoadBits(RoadBits r)
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    82
{
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    83
	return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    84
}
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    85
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    86
/**
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    87
 * Calculate rotated RoadBits
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    88
 *
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    89
 * Move the Roadbits clockwise til they are in their final position.
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    90
 *
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    91
 * @param r The given RoadBits value
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    92
 * @param rot The given Rotation angle
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    93
 * @return the rotated
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    94
 */
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    95
static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    96
{
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    97
	for (; rot > (DiagDirDiff)0; rot--){
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    98
		r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
    99
	}
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
   100
	return r;
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
   101
}
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
   102
67a9579abd74 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 8062
diff changeset
   103
/**
9230
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   104
 * Check if we've got a straight road
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   105
 *
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   106
 * @param r The given RoadBits
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   107
 * @return true if we've got a straight road
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   108
 */
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   109
static inline bool IsStraightRoad(RoadBits r)
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   110
{
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   111
	return (r == ROAD_X || r == ROAD_Y);
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   112
}
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   113
1c0a7c2ee6e5 (svn r12419) -Cleanup: of the internal road-piece building and removing.
skidd13
parents: 9212
diff changeset
   114
/**
7891
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   115
 * Create the road-part which belongs to the given DiagDirection
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   116
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   117
 * This function returns a RoadBits value which belongs to
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   118
 * the given DiagDirection.
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   119
 *
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   120
 * @param d The DiagDirection
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   121
 * @return The result RoadBits which the selected road-part set
5aac5be5fc2c (svn r10764) -Documentation: [FS#1099]: of road.h. Based on a patch by Progman.
rubidium
parents: 7187
diff changeset
   122
 */
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   123
static inline RoadBits DiagDirToRoadBits(DiagDirection d)
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   124
{
8062
9eb6efa04d44 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents: 7891
diff changeset
   125
	return (RoadBits)(ROAD_NW << (3 ^ d));
3146
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   126
}
36523d434783 (svn r3766) Add a function to get the RoadBits from an arbitrary tile
tron
parents: 3145
diff changeset
   127
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   128
/**
9212
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   129
 * Create the road-part which belongs to the given Axis
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   130
 *
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   131
 * This function returns a RoadBits value which belongs to
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   132
 * the given Axis.
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   133
 *
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   134
 * @param a The Axis
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   135
 * @return The result RoadBits which the selected road-part set
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   136
 */
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   137
static inline RoadBits AxisToRoadBits(Axis a)
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   138
{
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   139
	return a == AXIS_X ? ROAD_X : ROAD_Y;
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   140
}
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   141
3503ffa351b6 (svn r12390) -Fix [FS#1851]: trams failing to turn on bridge heads/tunnel entrances.
rubidium
parents: 8840
diff changeset
   142
/**
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   143
 * Finds out, whether given player has all given RoadTypes available
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   144
 * @param PlayerID ID of player
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   145
 * @param rts RoadTypes to test
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   146
 * @return true if player has all requested RoadTypes available
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   147
 */
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   148
bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts);
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   149
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   150
/**
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   151
 * Validate functions for rail building.
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   152
 * @param rt road type to check.
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   153
 * @return true if the current player may build the road.
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   154
 */
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   155
bool ValParamRoadType(const RoadType rt);
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   156
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   157
/**
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   158
 * Get the road types the given player can build.
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   159
 * @param p the player to get the roadtypes for.
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   160
 * @return the road types.
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   161
 */
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   162
RoadTypes GetPlayerRoadtypes(const PlayerID p);
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8634
diff changeset
   163
8840
81cfba69eddd (svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
smatz
parents: 8838
diff changeset
   164
void UpdateLevelCrossing(TileIndex tile, bool sound = true);
8838
1549b7f9d0a8 (svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
smatz
parents: 8750
diff changeset
   165
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8424
diff changeset
   166
#endif /* ROAD_FUNC_H */