Loading

Revision differences

Old revision #pye2z1acsNew revision #ph2ugbbgr
4 * @param tile The target tile  4 * @param tile The target tile  
5 * @return true if building here blocks a water connection  5 * @return true if building here blocks a water connection  
6 */  6 */  
7static bool GrowingBlocksWaterConnection(const TileIndex tile)  7static bool GrowingBlocksWaterConnection(TileIndex tile)
8{  8{  
9    if (!IsValidTile(tile) || !IsCoastTile(tile)) return false;  9    if (!IsValidTile(tile) || !IsCoastTile(tile)) return false;  
10  10  
11    const Slope slope = GetTileSlope(tile);  11    Slope slope = GetTileSlope(tile);
   12
12    /* Is this a coast tile with one corner raised ? */  13    /* Is this a coast tile with one corner raised ? */  
13    if (IsSlopeWithOneCornerRaised(slope)) {  14    if (IsSlopeWithOneCornerRaised(slope)) {  
14        const Track main_track_mask = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));  14        Corner corner = GetHighestSlopeCorner(slope);
15        const Track oppo_track_mask = TrackToOppositeTrack(main_track_mask);    
16        const Trackdir main_trackdir = TrackToTrackdir(main_track_mask);    
17        const Trackdir oppo_trackdir = TrackToTrackdir(oppo_track_mask);    
18        const DiagDirection main_dir_1 = TrackdirToExitdir(main_trackdir);    
19        const DiagDirection main_dir_2 = TrackdirToExitdir(ReverseTrackdir(main_trackdir));    
20        const DiagDirection oppo_dir_1 = TrackdirToExitdir(oppo_trackdir);    
21        const DiagDirection oppo_dir_2 = TrackdirToExitdir(ReverseTrackdir(oppo_trackdir));    
22    
23        const TrackBits main_trackbits_mask_1 = DiagdirReachesTracks(main_dir_1);    
24        const TrackBits main_trackbits_mask_2 = DiagdirReachesTracks(main_dir_2);    
25        const TrackBits oppo_trackbits_mask_1 = DiagdirReachesTracks(oppo_dir_1);    
26        const TrackBits oppo_trackbits_mask_2 = DiagdirReachesTracks(oppo_dir_2);    
27    
28        const Corner corner = GetHighestSlopeCorner(slope);    
29        static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };  16        static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };  
30        const TileIndex opposite_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(corner)]));  30        TileIndex opposite_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(corner)]));
31  18  
32        if (IsValidTile(opposite_tile)) {  19        if (IsValidTile(opposite_tile)) {  
33            const TileIndex tile_1 = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(main_dir_1));  33            Track main_track_mask = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));
34            const TileIndex tile_2 = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(main_dir_2));  34            Trackdir main_trackdir = TrackToTrackdir(main_track_mask);
35  22  
36            const TrackBits track_1 = TrackStatusToTrackBits(GetTileTrackStatus(tile_1, TRANSPORT_WATER, 0));  36            DiagDirection main_dir_1 = TrackdirToExitdir(main_trackdir);
37            const TrackBits track_2 = TrackStatusToTrackBits(GetTileTrackStatus(tile_2, TRANSPORT_WATER, 0));  37            DiagDirection main_dir_2 = TrackdirToExitdir(ReverseTrackdir(main_trackdir));
38  25  
39            const TrackBits main_track_1 = main_trackbits_mask_1 & track_1;  26            TileIndex tile_1 = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(main_dir_1));
40            const TrackBits main_track_2 = main_trackbits_mask_2 & track_2;  27            TileIndex tile_2 = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(main_dir_2));
41            const TrackBits oppo_track_1 = oppo_trackbits_mask_1 & track_1;  28
42            const TrackBits oppo_track_2 = oppo_trackbits_mask_2 & track_2;  29            TrackBits track_1 = TrackStatusToTrackBits(GetTileTrackStatus(tile_1, TRANSPORT_WATER, 0));
   30            TrackBits track_2 = TrackStatusToTrackBits(GetTileTrackStatus(tile_2, TRANSPORT_WATER, 0));
   31
   32            TrackBits main_trackbits_mask_1 = DiagdirReachesTracks(main_dir_1);
   33            TrackBits main_trackbits_mask_2 = DiagdirReachesTracks(main_dir_2);
   34
   35            TrackBits main_track_1 = main_trackbits_mask_1 & track_1;
   36            TrackBits main_track_2 = main_trackbits_mask_2 & track_2;
43  37  
44            /* Is there a connection between tile_1 and tile_2 via tile? */  38            /* Is there a connection between tile_1 and tile_2 via tile? */  
45            if (main_track_1 && main_track_2) {  39            if (main_track_1 && main_track_2) {  
46                const TrackBits oppo_trackbits = TrackStatusToTrackBits(GetTileTrackStatus(opposite_tile, TRANSPORT_WATER, 0));  40                TrackBits oppo_trackbits = TrackStatusToTrackBits(GetTileTrackStatus(opposite_tile, TRANSPORT_WATER, 0));
   41                Track oppo_track_mask = TrackToOppositeTrack(main_track_mask);
   42
47                /* Is there a track in the opposite_tile that can be used to try an alternative connection? */  43                /* Is there a track in the opposite_tile that can be used to try an alternative connection? */  
48                if (HasTrack(oppo_trackbits, oppo_track_mask)) {  44                if (HasTrack(oppo_trackbits, oppo_track_mask)) {  
49                    const TrackBits mirror = TRACK_BIT_CROSS | (corner & 1 ? TRACK_BIT_HORZ : TRACK_BIT_VERT);  45                    TrackBits mirror = TRACK_BIT_CROSS | (corner & 1 ? TRACK_BIT_HORZ : TRACK_BIT_VERT);
   46
   47                    Trackdir oppo_trackdir = TrackToTrackdir(oppo_track_mask);
   48
   49                    DiagDirection oppo_dir_1 = TrackdirToExitdir(oppo_trackdir);
   50                    DiagDirection oppo_dir_2 = TrackdirToExitdir(ReverseTrackdir(oppo_trackdir));
   51
   52                    TrackBits oppo_trackbits_mask_1 = DiagdirReachesTracks(oppo_dir_1);
   53                    TrackBits oppo_trackbits_mask_2 = DiagdirReachesTracks(oppo_dir_2);
   54
   55                    TrackBits oppo_track_1 = oppo_trackbits_mask_1 & track_1;
   56                    TrackBits oppo_track_2 = oppo_trackbits_mask_2 & track_2;
   57
50                    /* Is there a connection between tile_1 and tile_2 via opposite_tile? */  58                    /* Is there a connection between tile_1 and tile_2 via opposite_tile? */  
51                    if (oppo_track_1 & (main_track_1 ^ mirror) && oppo_track_2 & (main_track_2 ^ mirror)) {  59                    if (oppo_track_1 & (main_track_1 ^ mirror) && oppo_track_2 & (main_track_2 ^ mirror)) {  
52                        /* There is an alternative connection. Town can grow on tile. */  60                        /* There is an alternative connection. Town can grow on tile. */