src/road.cpp
branchnoai
changeset 9704 197cb8c6ae17
child 6871 5a9dc001e1ad
equal deleted inserted replaced
9703:d2a6acdbd665 9704:197cb8c6ae17
       
     1 #include "stdafx.h"
       
     2 #include "openttd.h"
       
     3 #include "functions.h"
       
     4 #include "rail_map.h"
       
     5 #include "road.h"
       
     6 #include "road_map.h"
       
     7 #include "water_map.h"
       
     8 #include "macros.h"
       
     9 
       
    10 bool IsPossibleCrossing(const TileIndex tile, Axis ax)
       
    11 {
       
    12 	return (IsTileType(tile, MP_RAILWAY) &&
       
    13 		!HasSignals(tile) &&
       
    14 		GetTrackBits(tile) == (ax == AXIS_X ?  TRACK_BIT_Y : TRACK_BIT_X) &&
       
    15 		GetTileSlope(tile, NULL) == SLOPE_FLAT);
       
    16 }
       
    17 
       
    18 RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
       
    19 {
       
    20 	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
       
    21 		const TileIndex neighbor_tile = TileAddByDiagDir(tile, dir);
       
    22 
       
    23 		/* Get the Roadbit pointing to the neighbor_tile */
       
    24 		const RoadBits target_rb = DiagDirToRoadBits(dir);
       
    25 
       
    26 		/* If the roadbit is in the current plan */
       
    27 		if (org_rb & target_rb) {
       
    28 			bool connective = false;
       
    29 			const RoadBits mirrored_rb = MirrorRoadBits(target_rb);
       
    30 
       
    31 			switch (GetTileType(neighbor_tile)) {
       
    32 				/* Allways connective ones */
       
    33 				case MP_CLEAR: case MP_TREES:
       
    34 					connective = true;
       
    35 					break;
       
    36 
       
    37 				/* The conditionaly connective ones */
       
    38 				case MP_TUNNELBRIDGE:
       
    39 				case MP_STATION:
       
    40 				case MP_ROAD: {
       
    41 					const RoadBits neighbor_rb = GetAnyRoadBits(neighbor_tile, ROADTYPE_ROAD) | GetAnyRoadBits(neighbor_tile, ROADTYPE_TRAM);
       
    42 
       
    43 					/* Accept only connective tiles */
       
    44 					connective = (neighbor_rb & mirrored_rb) || // Neighbor has got the fitting RoadBit
       
    45 							COUNTBITS(neighbor_rb) == 1; // Neighbor has got only one Roadbit
       
    46 
       
    47 				} break;
       
    48 
       
    49 				case MP_RAILWAY:
       
    50 					connective = IsPossibleCrossing(neighbor_tile, DiagDirToAxis(dir));
       
    51 					break;
       
    52 
       
    53 				case MP_WATER:
       
    54 					/* Check for real water tile */
       
    55 					connective = !IsWater(neighbor_tile);
       
    56 					break;
       
    57 
       
    58 				/* The defentetly not connective ones */
       
    59 				default: break;
       
    60 			}
       
    61 
       
    62 			/* If the neighbor tile is inconnective remove the planed road connection to it */
       
    63 			if (!connective) org_rb ^= target_rb;
       
    64 
       
    65 		}
       
    66 	}
       
    67 
       
    68 	return org_rb;
       
    69 }