Changeset - r20821:e1ecbf7996ac
[Not reviewed]
master
0 4 0
zuu - 11 years ago 2013-10-13 20:11:05
zuu@openttd.org
(svn r25865) -Codechange: Refactor detecting of depot vehicle type of a tile to a new function, GetDepotVehicleType (cirdan, LordAro)
4 files changed with 20 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/depot.cpp
Show inline comments
 
@@ -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());
 
}
src/depot_cmd.cpp
Show inline comments
 
@@ -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();
src/depot_map.h
Show inline comments
 
@@ -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 */
src/vehicle_cmd.cpp
Show inline comments
 
@@ -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);
0 comments (0 inline, 0 general)