From cef1c47f18591678fbe4df4e0f343b6561cb6b01 Mon Sep 17 00:00:00 2001 From: zuu Date: Sun, 13 Oct 2013 20:11:05 +0000 Subject: (svn r25865) -Codechange: Refactor detecting of depot vehicle type of a tile to a new function, GetDepotVehicleType (cirdan, LordAro) --- src/depot.cpp | 8 +------- src/depot_cmd.cpp | 8 +------- src/depot_map.h | 17 +++++++++++++++++ src/vehicle_cmd.cpp | 9 +-------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/depot.cpp b/src/depot.cpp index 4fb69c8e3..9663f042e 100644 --- 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 index 7027554bd..5fb2b2de2 100644 --- a/src/depot_cmd.cpp +++ b/src/depot_cmd.cpp @@ -76,13 +76,7 @@ CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 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 index b4f7a11ec..e55994869 100644 --- a/src/depot_map.h +++ b/src/depot_map.h @@ -55,4 +55,21 @@ static inline DepotID GetDepotIndex(TileIndex t) 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 index 68e6fff1a..f45bd4b5a 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -85,14 +85,7 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint /* 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); -- cgit v1.2.3-54-g00ecf