Loading

Revision differences

Old revision #pfrpc7gorNew 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,9 @@  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+    ret = EnsureNoShipOnDiagDir(tile_cur, ReverseDiagDir(direction));  14+    TileIndex tc = tile_cur;
   15+    DiagDirection dir_rotate = ReverseDiagDir(direction);
   16+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
   17+    if (ret.Failed()) return ret;
   18+
   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);
   20+    dir_rotate = ChangeDiagDir(dir_rotate, DIAGDIRDIFF_90RIGHT);
   21+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
   22+    if (ret.Failed()) return ret;
   23+
   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);
   25+    dir_rotate = ReverseDiagDir(dir_rotate);
   26+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
10+    if (ret.Failed()) return ret;  27+    if (ret.Failed()) return ret;  
11+  28+  
12     TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),  29     TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),  
  
21 }  38 }  
22   39   
23+/**  40+/**  
24+* Ensure there is no ship on the water at the given diagonal direction.  24+* Ensure there is no ship coming from or going to the given diagonal direction.
25+* @param tile Position to examine.  42+* @param tile Position to examine.  
26+* @param diag_dir Diagonal direction  43+* @param diag_dir Diagonal direction  
27+* @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).  
28+*/  45+*/  
29+CommandCost EnsureNoShipOnDiagDir(TileIndex tile, DiagDirection diag_dir)  29+CommandCost EnsureNoShipFromDiagDir(TileIndex tile, DiagDirection diag_dir)
30+{  47+{  
31+    if (HasTileWaterClass(tile)) {  48+    if (HasTileWaterClass(tile)) {  
32+        TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));  49+        TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));  
33+        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))) {  33+        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)) {
34+            CommandCost ret = EnsureNoVehicleOnGround(tile);  51+            CommandCost ret = EnsureNoVehicleOnGround(tile);  
35+            if (ret.Failed()) return ret;  52+            if (ret.Failed()) return ret;  
36+        }  53+        }  
  
49   66   
50 CommandCost EnsureNoVehicleOnGround(TileIndex tile);  67 CommandCost EnsureNoVehicleOnGround(TileIndex tile);  
51 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);  68 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);  
52+CommandCost EnsureNoShipOnDiagDir(TileIndex tile, DiagDirection diag_dir);  52+CommandCost EnsureNoShipFromDiagDir(TileIndex tile, DiagDirection diag_dir);
53   70   
54 extern VehicleID _new_vehicle_id;  71 extern VehicleID _new_vehicle_id;  
55 extern uint16 _returned_refit_capacity;  72 extern uint16 _returned_refit_capacity;  
  
63   80   
64+    DiagDirection dir_rotate = axis == AXIS_X ? DIAGDIR_SE : DIAGDIR_NE;  81+    DiagDirection dir_rotate = axis == AXIS_X ? DIAGDIR_SE : DIAGDIR_NE;  
65+    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));  
66+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  66+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
67+    if (ret.Failed()) return ret;  84+    if (ret.Failed()) return ret;  
68+  85+  
69+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  86+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  
70+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  70+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
71+    if (ret.Failed()) return ret;  88+    if (ret.Failed()) return ret;  
72+  89+  
73+    dir_rotate = ReverseDiagDir(dir_rotate);  90+    dir_rotate = ReverseDiagDir(dir_rotate);  
74+    tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  91+    tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  
75+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  75+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
76+    if (ret.Failed()) return ret;  93+    if (ret.Failed()) return ret;  
77+  94+  
78+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  95+    tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));  
79+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  79+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
80+    if (ret.Failed()) return ret;  97+    if (ret.Failed()) return ret;  
81+  98+  
82     if (flags & DC_EXEC) {  99     if (flags & DC_EXEC) {  
  
89+    Axis axis = DiagDirToAxis(dir);  106+    Axis axis = DiagDirToAxis(dir);  
90+    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);  
91+    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));  
92+    CommandCost ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  92+    CommandCost ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
93+    if (ret.Failed()) return ret;  110+    if (ret.Failed()) return ret;  
94+  111+  
95+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, -1) : TileDiffXY(1, 1));  112+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, -1) : TileDiffXY(1, 1));  
96+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  96+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
97+    if (ret.Failed()) return ret;  114+    if (ret.Failed()) return ret;  
98+  115+  
99+    dir_rotate = ReverseDiagDir(dir_rotate);  116+    dir_rotate = ReverseDiagDir(dir_rotate);  
100+    tc = tile + (axis == AXIS_X ? TileDiffXY(-1, 1) : TileDiffXY(-1, -1));  117+    tc = tile + (axis == AXIS_X ? TileDiffXY(-1, 1) : TileDiffXY(-1, -1));  
101+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  101+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
102+    if (ret.Failed()) return ret;  119+    if (ret.Failed()) return ret;  
103+  120+  
104+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, 1) : TileDiffXY(-1, 1));  121+    tc = tile + (axis == AXIS_X ? TileDiffXY(1, 1) : TileDiffXY(-1, 1));  
105+    ret = EnsureNoShipOnDiagDir(tc, dir_rotate);  105+    ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
106+    if (ret.Failed()) return ret;  123+    if (ret.Failed()) return ret;  
107+  124+  
108     return DoBuildLock(tile, dir, flags);  125     return DoBuildLock(tile, dir, flags);