summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-31 20:52:38 +0000
committerrubidium <rubidium@openttd.org>2007-08-31 20:52:38 +0000
commit2cd15f732c7b112ebdf1ddbdc7feffb8d7c25166 (patch)
treea07237e50c275d462dbd4bcccd061d7fad21e8f4
parenta06b8a510bae0715d671e8272f64299d4fed034d (diff)
downloadopenttd-2cd15f732c7b112ebdf1ddbdc7feffb8d7c25166.tar.xz
(svn r11027) -Fix: do not unconditionally assume that a tile has a depot.
-rw-r--r--src/depot.h18
-rw-r--r--src/vehicle.cpp2
2 files changed, 18 insertions, 2 deletions
diff --git a/src/depot.h b/src/depot.h
index 70a12d0bc..926f1fa85 100644
--- a/src/depot.h
+++ b/src/depot.h
@@ -12,6 +12,7 @@
#include "road_map.h"
#include "rail_map.h"
#include "water_map.h"
+#include "station_map.h"
struct Depot;
DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
@@ -63,7 +64,7 @@ static inline bool IsTileDepotType(TileIndex tile, TransportType type)
return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT;
case TRANSPORT_ROAD:
- return IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_DEPOT;
+ return IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_DEPOT;
case TRANSPORT_WATER:
return IsTileType(tile, MP_WATER) && GetWaterTileType(tile) == WATER_TILE_DEPOT;
@@ -74,6 +75,21 @@ static inline bool IsTileDepotType(TileIndex tile, TransportType type)
}
}
+/**
+ * Is the given tile a tile with a depot on it?
+ * @param tile the tile to check
+ * @return true if and only if there is a depot on the tile.
+ */
+static inline bool IsDepotTile(TileIndex tile)
+{
+ switch (GetTileType(tile)) {
+ case MP_ROAD: return GetRoadTileType(tile) == ROAD_TILE_DEPOT;
+ case MP_WATER: return GetWaterTileType(tile) == WATER_TILE_DEPOT;
+ case MP_RAILWAY: return GetRailTileType(tile) == RAIL_TILE_DEPOT;
+ case MP_STATION: return IsHangar(tile);
+ default: return false;
+ }
+}
/**
* Find out if the slope of the tile is suitable to build a depot of given direction
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 003f21b47..fc4b1ebff 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1634,7 +1634,7 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uin
CommandCost cost;
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
- if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
+ if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);