@ -47,6 +47,7 @@
#include "effectvehicle_base.h"
#include "vehiclelist.h"
#include "bridge_map.h"
#include "tunnelbridge_map.h"
#include "tunnel_map.h"
#include "depot_map.h"
#include "gamelog.h"
@ -546,6 +547,24 @@ CommandCost EnsureNoVehicleOnGround(TileIndex tile)
*/
Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, true);
if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type);
TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
if ((trackbits & TRACK_BIT_ALL) != TRACK_BIT_NONE) {
Ship *s;
FOR_ALL_SHIPS(s) {
if (DistanceManhattan(tile, s->tile) != 1) continue;
/* Don't care about ships on aqueducts. Those kind of tiles don't cause problems. */
/* The same can be applied to locks and ship depots. */
if (IsTileType(s->tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(s->tile) == TRANSPORT_WATER ||
IsTileType(s->tile, MP_WATER) && IsLock(s->tile) || IsShipDepotTile(s->tile)) continue;
if (s->state & DiagdirReachesTracks(DiagdirBetweenTiles(tile, s->tile))) {
if (DiagdirReachesTracks(DiagdirBetweenTiles(s->tile, tile)) & trackbits) {
return_cmd_error(STR_ERROR_SHIP_IN_THE_WAY);
}
}
}
}
return CommandCost();
}