Loading

Revision differences

Old revision #pntsd7s9aNew revision #prgjo8rdm
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,21 @@  5@@ -2500,10 +2500,25 @@
   6     if (ret.Failed()) return ret;
   7 
   8     tile_cur += TileOffsByDiagDir(direction);
   9-    if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {
   10+    if (!IsTileType(tile_cur, MP_WATER) || (!IsTileFlat(tile_cur) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile_cur)))) {
6         return_cmd_error(STR_ERROR_SITE_UNSUITABLE);  11         return_cmd_error(STR_ERROR_SITE_UNSUITABLE);  
7     }  12     }  
8   13   
9+    TileIndex tc = tile_cur;  14+    TileIndex tc = tile_cur;  
10+    DiagDirection dir_rotate = ReverseDiagDir(direction);  15+    DiagDirection dir_rotate = ReverseDiagDir(direction);  
11+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  11+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
12+    if (ret.Failed()) return ret;  17+    if (ret.Failed()) return ret;  
13+  18+  
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);  19+    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+    dir_rotate = ChangeDiagDir(dir_rotate, DIAGDIRDIFF_90RIGHT);  20+    dir_rotate = ChangeDiagDir(dir_rotate, DIAGDIRDIFF_90RIGHT);  
16+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  16+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
17+    if (ret.Failed()) return ret;  22+    if (ret.Failed()) return ret;  
18+  23+  
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);  24+    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);  25+    dir_rotate = ReverseDiagDir(dir_rotate);  
21+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  21+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
22+    if (ret.Failed()) return ret;  27+    if (ret.Failed()) return ret;  
23+  28+  
24     TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),  29     TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),  
  
33 }  38 }  
34   39   
35+/**  40+/**  
36+* Ensure there is no ship on the water at the given diagonal direction.  36+* Ensure there is no ship coming from or going to the given diagonal direction.
37+* @param tile Position to examine.  42+* @param tile Position to examine.  
38+* @param diag_dir Diagonal direction  43+* @param diag_dir Diagonal direction  
39+* @return Succeeded command (water is free) or failed command (a ship is found).  44+* @return Succeeded command (water is free) or failed command (a ship is found).  
40+*/  45+*/  
41+CommandCost EnsureNoShipOnDiagDir(TileIndex tile, DiagDirection diag_dir)  41+CommandCost EnsureNoShipFromDiagDir(TileIndex tile, DiagDirection diag_dir)
42+{  47+{  
43+    if (HasTileWaterClass(tile)) {  48+    if (HasTileWaterClass(tile)) {  
44+        TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));  49+        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))) {  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);  51+            CommandCost ret = EnsureNoVehicleOnGround(tile);  
47+            if (ret.Failed()) return ret;  52+            if (ret.Failed()) return ret;  
48+        }  53+        }  
  
61   66   
62 CommandCost EnsureNoVehicleOnGround(TileIndex tile);  67 CommandCost EnsureNoVehicleOnGround(TileIndex tile);  
63 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);  68 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);  
64+CommandCost EnsureNoShipOnDiagDir(TileIndex tile, DiagDirection diag_dir);  64+CommandCost EnsureNoShipFromDiagDir(TileIndex tile, DiagDirection diag_dir);
65   70   
66 extern VehicleID _new_vehicle_id;  71 extern VehicleID _new_vehicle_id;  
67 extern uint16 _returned_refit_capacity;  72 extern uint16 _returned_refit_capacity;  
  
75   80   
76+    DiagDirection dir_rotate = axis == AXIS_X ? DIAGDIR_SE : DIAGDIR_NE;  81+    DiagDirection dir_rotate = axis == AXIS_X ? DIAGDIR_SE : DIAGDIR_NE;  
77+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  82+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  
78+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  78+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
79+    if (ret.Failed()) return ret;  84+    if (ret.Failed()) return ret;  
80+  85+  
81+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  86+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  
82+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  82+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
83+    if (ret.Failed()) return ret;  88+    if (ret.Failed()) return ret;  
84+  89+  
85+    dir_rotate = ReverseDiagDir(dir_rotate);  90+    dir_rotate = ReverseDiagDir(dir_rotate);  
86+    tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  91+    tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  
87+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  87+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
88+    if (ret.Failed()) return ret;  93+    if (ret.Failed()) return ret;  
89+  94+  
90+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  95+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  
91+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  91+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
92+    if (ret.Failed()) return ret;  97+    if (ret.Failed()) return ret;  
93+  98+  
94     if (flags & DC_EXEC) {  99     if (flags & DC_EXEC) {  
  
101+    Axis axis = DiagDirToAxis(dir);  106+    Axis axis = DiagDirToAxis(dir);  
102+    DiagDirection dir_rotate = (dir == DIAGDIR_NE || dir == DIAGDIR_NW) ? ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT) : ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT);  107+    DiagDirection dir_rotate = (dir == DIAGDIR_NE || dir == DIAGDIR_NW) ? ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT) : ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT);  
103+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(-1, -1) : TileDiffXY(1, -1));  108+    TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(-1, -1) : TileDiffXY(1, -1));  
104+    CommandCost ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  104+    CommandCost ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
105+    if (ret.Failed()) return ret;  110+    if (ret.Failed()) return ret;  
106+  111+  
107+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, -1) : TileDiffXY(1, 1));  112+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, -1) : TileDiffXY(1, 1));  
108+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  108+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
109+    if (ret.Failed()) return ret;  114+    if (ret.Failed()) return ret;  
110+  115+  
111+    dir_rotate = ReverseDiagDir(dir_rotate);  116+    dir_rotate = ReverseDiagDir(dir_rotate);  
112+    tc = tile + (axis == AXIS_X ? TileDiffXY(-1, 1) : TileDiffXY(-1, -1));  117+    tc = tile + (axis == AXIS_X ? TileDiffXY(-1, 1) : TileDiffXY(-1, -1));  
113+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  113+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
114+    if (ret.Failed()) return ret;  119+    if (ret.Failed()) return ret;  
115+  120+  
116+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, 1) : TileDiffXY(-1, 1));  121+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, 1) : TileDiffXY(-1, 1));  
117+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  117+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
118+    if (ret.Failed()) return ret;  123+    if (ret.Failed()) return ret;  
119+  124+  
120     return DoBuildLock(tile, dir, flags);  125     return DoBuildLock(tile, dir, flags);