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
 
@@ -41,15 +41,9 @@ Depot::~Depot()
 
	RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
 

	
 
	/* Delete the depot-window */
 
	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
 
@@ -73,17 +73,11 @@ CommandCost CmdRenameDepot(TileIndex til
 

	
 
		/* Update the orders and depot */
 
		SetWindowClassesDirty(WC_VEHICLE_ORDERS);
 
		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
 
@@ -52,7 +52,24 @@ static inline DepotID GetDepotIndex(Tile
 
{
 
	/* Hangars don't have a Depot class, thus store no DepotID. */
 
	assert(IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(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 */
src/vehicle_cmd.cpp
Show inline comments
 
@@ -82,20 +82,13 @@ CommandCost CmdBuildAircraft   (TileInde
 
 */
 
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* 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);
 
	if (!IsEngineBuildable(eid, type, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type);
 

	
 
	const Engine *e = Engine::Get(eid);
0 comments (0 inline, 0 general)