diff --git a/src/depot.cpp b/src/depot.cpp --- a/src/depot.cpp +++ b/src/depot.cpp @@ -44,12 +44,6 @@ Depot::~Depot() DeleteWindowById(WC_VEHICLE_DEPOT, this->xy); /* Delete the depot list */ - VehicleType vt; - switch (GetTileType(this->xy)) { - default: NOT_REACHED(); - case MP_RAILWAY: vt = VEH_TRAIN; break; - case MP_ROAD: vt = VEH_ROAD; break; - case MP_WATER: vt = VEH_SHIP; break; - } + VehicleType vt = GetDepotVehicleType(this->xy); DeleteWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack()); } diff --git a/src/depot_cmd.cpp b/src/depot_cmd.cpp --- a/src/depot_cmd.cpp +++ b/src/depot_cmd.cpp @@ -76,13 +76,7 @@ CommandCost CmdRenameDepot(TileIndex til SetWindowDirty(WC_VEHICLE_DEPOT, d->xy); /* Update the depot list */ - VehicleType vt; - switch (GetTileType(d->xy)) { - default: NOT_REACHED(); - case MP_RAILWAY: vt = VEH_TRAIN; break; - case MP_ROAD: vt = VEH_ROAD; break; - case MP_WATER: vt = VEH_SHIP; break; - } + VehicleType vt = GetDepotVehicleType(d->xy); SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack()); } return CommandCost(); diff --git a/src/depot_map.h b/src/depot_map.h --- a/src/depot_map.h +++ b/src/depot_map.h @@ -55,4 +55,21 @@ static inline DepotID GetDepotIndex(Tile return _m[t].m2; } +/** + * Get the type of vehicles that can use a depot + * @param t The tile + * @pre IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t) || IsTileType(t, MP_STATION) + * @return the type of vehicles that can use the depot + */ +static inline VehicleType GetDepotVehicleType(TileIndex t) +{ + switch (GetTileType(t)) { + default: NOT_REACHED(); + case MP_RAILWAY: return VEH_TRAIN; + case MP_ROAD: return VEH_ROAD; + case MP_WATER: return VEH_SHIP; + case MP_STATION: return VEH_AIRCRAFT; + } +} + #endif /* DEPOT_MAP_H */ diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -85,14 +85,7 @@ CommandCost CmdBuildVehicle(TileIndex ti /* Elementary check for valid location. */ if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR; - VehicleType type; - switch (GetTileType(tile)) { - case MP_RAILWAY: type = VEH_TRAIN; break; - case MP_ROAD: type = VEH_ROAD; break; - case MP_WATER: type = VEH_SHIP; break; - case MP_STATION: type = VEH_AIRCRAFT; break; - default: NOT_REACHED(); // Safe due to IsDepotTile() - } + VehicleType type = GetDepotVehicleType(tile); /* Validate the engine type. */ EngineID eid = GB(p1, 0, 16);