Loading

Revision differences

Old revision #pol6ejtzlNew revision #pmf3ej2io
6 */  6 */  
7static bool PeterNGrowingBlocksWaterConnection(TileIndex tile)  7static bool PeterNGrowingBlocksWaterConnection(TileIndex tile)  
8{  8{  
9    if (!IsValidTile(tile)) return false;  9    if (!IsValidTile(tile) || !IsCoastTile(tile)) return false;
10    if (!IsCoastTile(tile)) return false;    
11  10  
12    Slope slope = GetTileSlope(tile);  11    Slope slope = GetTileSlope(tile);  
13  12  
  
17    Track track = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));  16    Track track = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));  
18    Trackdir trackdir = TrackToTrackdir(track);  17    Trackdir trackdir = TrackToTrackdir(track);  
19  18  
20    DiagDirection dir_a = TrackdirToExitdir(trackdir);  20    /* Test opposite tile is valid */
21    DiagDirection dir_b = TrackdirToExitdir(ReverseTrackdir(trackdir));    
22    
23    TileIndex tile_a = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_a));    
24    TileIndex tile_b = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_b));    
25    
26    Corner corner = GetHighestSlopeCorner(slope);    
27    static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };  20    static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };  
28  28    TileIndex tile_o = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(GetHighestSlopeCorner(slope))]));
29    /* Test adjacent tiles are valid */    
30    TileIndex tile_a = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_a));    
31    if (!IsValidTile(tile_a)) return false;    
32    TileIndex tile_b = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_b));    
33    if (!IsValidTile(tile_b)) return false;    
34    TileIndex tile_o = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(corner)]));    
35    if (!IsValidTile(tile_o)) return false;  22    if (!IsValidTile(tile_o)) return false;  
36  23  
37    /* Test adjacent tiles are traversible. */  24    /* Test adjacent tiles are traversible. */  
38    if (TrackStatusToTrackBits(GetTileTrackStatus(tile_a, TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;  38    if (TrackStatusToTrackBits(GetTileTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(trackdir))), TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
39    if (TrackStatusToTrackBits(GetTileTrackStatus(tile_b, TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;  39    if (TrackStatusToTrackBits(GetTileTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(ReverseTrackdir(trackdir)))), TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
40  27  
41    /* If they are, test opposite tile has connecting track. */  28    /* If they are, test opposite tile has connecting track. */  
42    TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile_o, TRANSPORT_WATER, 0));  42    if (HasBit(TrackStatusToTrackBits(GetTileTrackStatus(tile_o, TRANSPORT_WATER, 0)), TrackToOppositeTrack(track))) return false;
43    if (HasBit(trackbits, TrackToOppositeTrack(track))) return false;    
44  30  
45    /* Over building would block a route, so deny it. */  31    /* Over building would block a route, so deny it. */  
46    return true;  32    return true;