(svn r25865) -Codechange: Refactor detecting of depot vehicle type of a tile to a new function, GetDepotVehicleType (cirdan, LordAro)

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
zuu 11 years ago
parent 12ddbb7cb1
commit cef1c47f18

@ -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());
}

@ -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();

@ -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 */

@ -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);

Loading…
Cancel
Save