Loading

Revision differences

Old revision #pxgtxqlwkNew revision #pntsd7s9a
2===================================================================  2===================================================================  
3--- src/station_cmd.cpp    (revision 27632)  3--- src/station_cmd.cpp    (revision 27632)  
4+++ src/station_cmd.cpp    (working copy)  4+++ src/station_cmd.cpp    (working copy)  
5@@ -2504,6 +2504,14 @@  5@@ -2504,6 +2504,21 @@
6         return_cmd_error(STR_ERROR_SITE_UNSUITABLE);  6         return_cmd_error(STR_ERROR_SITE_UNSUITABLE);  
7     }  7     }  
8   8   
9+    if (HasTileWaterClass(tile_cur)) {  9+    TileIndex tc = tile_cur;
10+        TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile_cur, TRANSPORT_WATER, 0));  10+    DiagDirection dir_rotate = ReverseDiagDir(direction);
11+        if (((direction == DIAGDIR_SW && (tb & TRACK_BIT_3WAY_NE) != 0) || (direction == DIAGDIR_NW && (tb & TRACK_BIT_3WAY_SE) != 0) || (direction == DIAGDIR_SE && (tb & TRACK_BIT_3WAY_NW) != 0) || (direction == DIAGDIR_NE && (tb & TRACK_BIT_3WAY_SW) != 0) && !IsShipDepotTile(tile_cur) && IsTileType(tile_cur, MP_WATER) && !IsLock(tile_cur))) {  11+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
12+            ret = EnsureNoVehicleOnGround(tile_cur);  12+    if (ret.Failed()) return ret;
13+            if (ret.Failed()) return ret;  13+
14+        }  14+    tc = dir_rotate == DIAGDIR_NE ? tc + TileDiffXY(-1, -1) : dir_rotate == DIAGDIR_NW ? tc + TileDiffXY(1, -1) : dir_rotate == DIAGDIR_SW ? tc + TileDiffXY(1, 1) : tc + TileDiffXY(-1, 1);
15+    }  15+    dir_rotate = ChangeDiagDir(dir_rotate, DIAGDIRDIFF_90RIGHT);
   16+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
   17+    if (ret.Failed()) return ret;
   18+
   19+    tc = dir_rotate == DIAGDIR_NE ? tc + TileDiffXY(-2, 0) : dir_rotate == DIAGDIR_NW ? tc + TileDiffXY(0, -2) : dir_rotate == DIAGDIR_SW ? tc + TileDiffXY(2, 0) : tc + TileDiffXY(0, 2);
   20+    dir_rotate = ReverseDiagDir(dir_rotate);
   21+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
   22+    if (ret.Failed()) return ret;
16+  23+  
17     TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),  24     TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),  
18             _dock_w_chk[direction], _dock_h_chk[direction]);  25             _dock_w_chk[direction], _dock_h_chk[direction]);  
19   26   
  27Index: src/vehicle.cpp  
  28===================================================================  
  29--- src/vehicle.cpp    (revision 27632)  
  30+++ src/vehicle.cpp    (working copy)  
  31@@ -484,6 +484,24 @@  
  32     return CommandCost();  
  33 }  
  34   
  35+/**  
  36+* Ensure there is no ship on the water at the given diagonal direction.  
  37+* @param tile Position to examine.  
  38+* @param diag_dir Diagonal direction  
  39+* @return Succeeded command (water is free) or failed command (a ship is found).  
  40+*/  
  41+CommandCost EnsureNoShipOnDiagDir(TileIndex tile, DiagDirection diag_dir)  
  42+{  
  43+    if (HasTileWaterClass(tile)) {  
  44+        TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));  
  45+        if (((diag_dir == DIAGDIR_NE && (tb & TRACK_BIT_3WAY_NE) != 0) || (diag_dir == DIAGDIR_SE && (tb & TRACK_BIT_3WAY_SE) != 0) || (diag_dir == DIAGDIR_NW && (tb & TRACK_BIT_3WAY_NW) != 0) || (diag_dir == DIAGDIR_SW && (tb & TRACK_BIT_3WAY_SW) != 0) && !IsShipDepotTile(tile) && IsTileType(tile, MP_WATER) && !IsLock(tile))) {  
  46+            CommandCost ret = EnsureNoVehicleOnGround(tile);  
  47+            if (ret.Failed()) return ret;  
  48+        }  
  49+    }  
  50+    return CommandCost();  
  51+}  
  52+  
  53 /** Procedure called for every vehicle found in tunnel/bridge in the hash map */  
  54 static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data)  
  55 {  
  56Index: src/vehicle_func.h  
  57===================================================================  
  58--- src/vehicle_func.h    (revision 27632)  
  59+++ src/vehicle_func.h    (working copy)  
  60@@ -165,6 +165,7 @@  
  61   
  62 CommandCost EnsureNoVehicleOnGround(TileIndex tile);  
  63 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);  
  64+CommandCost EnsureNoShipOnDiagDir(TileIndex tile, DiagDirection diag_dir);  
  65   
  66 extern VehicleID _new_vehicle_id;  
  67 extern uint16 _returned_refit_capacity;  
20Index: src/water_cmd.cpp  68Index: src/water_cmd.cpp  
21===================================================================  69===================================================================  
22--- src/water_cmd.cpp    (revision 27632)  70--- src/water_cmd.cpp    (revision 27632)  
23+++ src/water_cmd.cpp    (working copy)  71+++ src/water_cmd.cpp    (working copy)  
24@@ -135,6 +135,39 @@  24@@ -135,6 +135,24 @@
25         cost.AddCost(ret);  73         cost.AddCost(ret);  
26     }  74     }  
27   75   
28+    TrackBits tb;  28+    DiagDirection dir_rotate = axis == AXIS_X ? DIAGDIR_SE : DIAGDIR_NE;
29+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  77+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  
30+    if (HasTileWaterClass(tc)) {  30+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
31+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  31+    if (ret.Failed()) return ret;
32+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_NE) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_SE) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  32+
33+            ret = EnsureNoVehicleOnGround(tc);    
34+            if (ret.Failed()) return ret;    
35+        }    
36+    }    
37+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  81+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  
38+    if (HasTileWaterClass(tc)) {  38+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
39+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  39+    if (ret.Failed()) return ret;
40+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_NE) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_SE) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  40+
41+            ret = EnsureNoVehicleOnGround(tc);  41+    dir_rotate = ReverseDiagDir(dir_rotate);
42+            if (ret.Failed()) return ret;    
43+        }    
44+    }    
45+    tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  86+    tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  
46+    if (HasTileWaterClass(tc)) {  46+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
47+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  47+    if (ret.Failed()) return ret;
48+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_SW) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_NW) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  48+
49+            ret = EnsureNoVehicleOnGround(tc);    
50+            if (ret.Failed()) return ret;    
51+        }    
52+    }    
53+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  90+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  
54+    if (HasTileWaterClass(tc)) {  54+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
55+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  55+    if (ret.Failed()) return ret;
56+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_SW) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_NW) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  56+
57+            ret = EnsureNoVehicleOnGround(tc);    
58+            if (ret.Failed()) return ret;    
59+        }    
60+    }    
61     if (flags & DC_EXEC) {  94     if (flags & DC_EXEC) {  
62         Depot *depot = new Depot(tile);  95         Depot *depot = new Depot(tile);  
63         depot->build_date = _date;  96         depot->build_date = _date;  
64@@ -372,6 +405,41 @@  64@@ -372,6 +390,25 @@
65     DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));  98     DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));  
66     if (dir == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);  99     if (dir == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);  
67   100   
68+    Axis axis = DiagDirToAxis(dir);  101+    Axis axis = DiagDirToAxis(dir);  
69+    TrackBits tb;  69+    DiagDirection dir_rotate = (dir == DIAGDIR_NE || dir == DIAGDIR_NW) ? ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT) : ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT);
70+    CommandCost ret;    
71+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(-1, -1) : TileDiffXY(1, -1));  103+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(-1, -1) : TileDiffXY(1, -1));  
72+    if (HasTileWaterClass(tc)) {  72+    CommandCost ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
73+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  73+    if (ret.Failed()) return ret;
74+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_NE) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_SE) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  74+
75+            ret = EnsureNoVehicleOnGround(tc);    
76+            if (ret.Failed()) return ret;    
77+        }    
78+    }    
79+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, -1) : TileDiffXY(1, 1));  107+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, -1) : TileDiffXY(1, 1));  
80+    if (HasTileWaterClass(tc)) {  80+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
81+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  81+    if (ret.Failed()) return ret;
82+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_NE) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_SE) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  82+
83+            ret = EnsureNoVehicleOnGround(tc);  83+    dir_rotate = ReverseDiagDir(dir_rotate);
84+            if (ret.Failed()) return ret;    
85+        }    
86+    }    
87+    tc = tile + (axis == AXIS_X ? TileDiffXY(-1, 1) : TileDiffXY(-1, -1));  112+    tc = tile + (axis == AXIS_X ? TileDiffXY(-1, 1) : TileDiffXY(-1, -1));  
88+    if (HasTileWaterClass(tc)) {  88+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
89+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  89+    if (ret.Failed()) return ret;
90+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_SW) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_NW) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  90+
91+            ret = EnsureNoVehicleOnGround(tc);    
92+            if (ret.Failed()) return ret;    
93+        }    
94+    }    
95+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, 1) : TileDiffXY(-1, 1));  116+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, 1) : TileDiffXY(-1, 1));  
96+    if (HasTileWaterClass(tc)) {  96+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);
97+        tb = TrackStatusToTrackBits(GetTileTrackStatus(tc, TRANSPORT_WATER, 0));  97+    if (ret.Failed()) return ret;
98+        if (((axis == AXIS_Y && (tb & TRACK_BIT_3WAY_SW) != 0) || (axis == AXIS_X && (tb & TRACK_BIT_3WAY_NW) != 0) && !IsShipDepotTile(tc) && IsTileType(tc, MP_WATER) && !IsLock(tc))) {  98+
99+            ret = EnsureNoVehicleOnGround(tc);    
100+            if (ret.Failed()) return ret;    
101+        }    
102+    }    
103     return DoBuildLock(tile, dir, flags);  120     return DoBuildLock(tile, dir, flags);  
104 } 121 }