Changeset - r12991:ff20fa5b1c08
[Not reviewed]
master
0 8 0
rubidium - 15 years ago 2009-09-10 14:37:55
rubidium@openttd.org
(svn r17495) -Codechange: replace 'Depot::Get(GetDepotIndex(tile))->index' with GetDepotIndex(tile)
8 files changed with 17 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_order.cpp
Show inline comments
 
@@ -340,25 +340,25 @@ static const Order *ResolveOrder(Vehicle
 
	switch (::GetOrderTypeByTile(destination)) {
 
		case OT_GOTO_DEPOT: {
 
			OrderDepotTypeFlags odtf = (OrderDepotTypeFlags)(ODTFB_PART_OF_ORDERS | ((order_flags & AIOF_SERVICE_IF_NEEDED) ? ODTFB_SERVICE : 0));
 
			OrderDepotActionFlags odaf = (OrderDepotActionFlags)(ODATF_SERVICE_ONLY | ((order_flags & AIOF_STOP_IN_DEPOT) ? ODATFB_HALT : 0));
 
			OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & AIOF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
 
			/* Check explicitly if the order is to a station (for aircraft) or
 
			 * to a depot (other vehicle types). */
 
			if (::Vehicle::Get(vehicle_id)->type == VEH_AIRCRAFT) {
 
				if (!::IsTileType(destination, MP_STATION)) return false;
 
				order.MakeGoToDepot(::GetStationIndex(destination), odtf, onsf, odaf);
 
			} else {
 
				if (::IsTileType(destination, MP_STATION)) return false;
 
				order.MakeGoToDepot(::Depot::GetByTile(destination)->index, odtf, onsf, odaf);
 
				order.MakeGoToDepot(::GetDepotIndex(destination), odtf, onsf, odaf);
 
			}
 
			break;
 
		}
 

	
 
		case OT_GOTO_STATION:
 
			order.MakeGoToStation(::GetStationIndex(destination));
 
			order.SetLoadType((OrderLoadFlags)GB(order_flags, 5, 3));
 
			order.SetUnloadType((OrderUnloadFlags)GB(order_flags, 2, 3));
 
			order.SetStopLocation(OSL_PLATFORM_FAR_END);
 
			break;
 

	
 
		case OT_GOTO_WAYPOINT:
src/ai/api/ai_vehiclelist.cpp
Show inline comments
 
@@ -54,37 +54,37 @@ AIVehicleList_Depot::AIVehicleList_Depot
 
	VehicleType type;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_STATION: // Aircraft
 
			if (!IsAirport(tile)) return;
 
			type = VEH_AIRCRAFT;
 
			dest = GetStationIndex(tile);
 
			break;
 

	
 
		case MP_RAILWAY:
 
			if (!IsRailDepot(tile)) return;
 
			type = VEH_TRAIN;
 
			dest = Depot::GetByTile(tile)->index;
 
			dest = GetDepotIndex(tile);
 
			break;
 

	
 
		case MP_ROAD:
 
			if (!IsRoadDepot(tile)) return;
 
			type = VEH_ROAD;
 
			dest = Depot::GetByTile(tile)->index;
 
			dest = GetDepotIndex(tile);
 
			break;
 

	
 
		case MP_WATER:
 
			if (!IsShipDepot(tile)) return;
 
			type = VEH_SHIP;
 
			dest = Depot::GetByTile(min(tile, GetOtherShipDepotTile(tile)))->index;
 
			dest = GetDepotIndex(tile);
 
			break;
 

	
 
		default: // No depot
 
			return;
 
	}
 

	
 
	const Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->owner == _current_company && v->IsPrimaryVehicle() && v->type == type) {
 
			const Order *order;
 

	
 
			FOR_VEHICLE_ORDERS(v, order) {
src/order_gui.cpp
Show inline comments
 
@@ -294,56 +294,54 @@ void DrawOrderString(const Vehicle *v, c
 
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
 
{
 
	Order order;
 
	order.next  = NULL;
 
	order.index = 0;
 

	
 
	/* check depot first */
 
	if (_settings_game.order.gotodepot) {
 
		switch (GetTileType(tile)) {
 
			case MP_RAILWAY:
 
				if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
 
					if (IsRailDepot(tile)) {
 
						order.MakeGoToDepot(Depot::GetByTile(tile)->index, ODTFB_PART_OF_ORDERS,
 
						order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
 
								_settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
 
						if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
 
						return order;
 
					}
 
				}
 
				break;
 

	
 
			case MP_ROAD:
 
				if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
 
					order.MakeGoToDepot(Depot::GetByTile(tile)->index, ODTFB_PART_OF_ORDERS,
 
					order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
 
							_settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
 
					if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
 
					return order;
 
				}
 
				break;
 

	
 
			case MP_STATION:
 
				if (v->type != VEH_AIRCRAFT) break;
 
				if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
 
					order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
 
					if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
 
					return order;
 
				}
 
				break;
 

	
 
			case MP_WATER:
 
				if (v->type != VEH_SHIP) break;
 
				if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
 
					TileIndex tile2 = GetOtherShipDepotTile(tile);
 

	
 
					order.MakeGoToDepot(Depot::GetByTile(tile < tile2 ? tile : tile2)->index, ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
 
					order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
 
					if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
 
					return order;
 
				}
 

	
 
			default:
 
				break;
 
		}
 
	}
 

	
 
	/* check waypoint */
 
	if (IsRailWaypointTile(tile) &&
 
			v->type == VEH_TRAIN &&
src/road_cmd.cpp
Show inline comments
 
@@ -1257,25 +1257,25 @@ void DrawRoadDepotSprite(int x, int y, D
 

	
 
/**
 
 * Updates cached nearest town for all road tiles
 
 * @param invalidate are we just invalidating cached data?
 
 * @param ignore town that should be ignored (because we are deleting it now)
 
 * @pre invalidate == true implies _generating_world == true
 
 */
 
void UpdateNearestTownForRoadTiles(bool invalidate)
 
{
 
	assert(!invalidate || _generating_world);
 

	
 
	for (TileIndex t = 0; t < MapSize(); t++) {
 
		if (IsTileType(t, MP_ROAD) && !HasTownOwnedRoad(t)) {
 
		if (IsTileType(t, MP_ROAD) && !IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
 
			TownID tid = (TownID)INVALID_TOWN;
 
			if (!invalidate) {
 
				const Town *town = CalcClosestTownFromTile(t);
 
				if (town != NULL) tid = town->index;
 
			}
 
			SetTownIndex(t, tid);
 
		}
 
	}
 
}
 

	
 
static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y)
 
{
src/roadveh_cmd.cpp
Show inline comments
 
@@ -427,25 +427,25 @@ static RoadFindDepotData FindClosestRoad
 
			break;
 
	}
 

	
 
	return rfdd; // Target not found
 
}
 

	
 
bool RoadVehicle::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
 
{
 
	RoadFindDepotData rfdd = FindClosestRoadDepot(this, 0);
 
	if (rfdd.best_length == UINT_MAX) return false;
 

	
 
	if (location    != NULL) *location    = rfdd.tile;
 
	if (destination != NULL) *destination = Depot::GetByTile(rfdd.tile)->index;
 
	if (destination != NULL) *destination = GetDepotIndex(rfdd.tile);
 

	
 
	return true;
 
}
 

	
 
/** Send a road vehicle to the depot.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
@@ -1841,36 +1841,36 @@ static void CheckIfRoadVehNeedsService(R
 
	/* Only go to the depot if it is not too far out of our way. */
 
	if (rfdd.best_length == UINT_MAX || rfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) {
 
		if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			/* If we were already heading for a depot but it has
 
			 * suddenly moved farther away, we continue our normal
 
			 * schedule? */
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return;
 
	}
 

	
 
	const Depot *depot = Depot::GetByTile(rfdd.tile);
 
	DepotID depot = GetDepotIndex(rfdd.tile);
 

	
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) &&
 
			v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS &&
 
			!Chance16(1, 20)) {
 
		return;
 
	}
 

	
 
	if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 
	ClearSlot(v);
 

	
 
	v->current_order.MakeGoToDepot(depot->index, ODTFB_SERVICE);
 
	v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE);
 
	v->dest_tile = rfdd.tile;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void RoadVehicle::OnNewDay()
 
{
 
	if (!this->IsRoadVehFront()) return;
 

	
 
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
 
	if (this->blocked_ctr == 0) CheckVehicleBreakdown(this);
 

	
 
	AgeVehicle(this);
src/train_cmd.cpp
Show inline comments
 
@@ -2255,25 +2255,25 @@ static TrainFindDepotData FindClosestTra
 
		} break;
 
	}
 

	
 
	return tfdd;
 
}
 

	
 
bool Train::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
 
{
 
	TrainFindDepotData tfdd = FindClosestTrainDepot(this, 0);
 
	if (tfdd.best_length == UINT_MAX) return false;
 

	
 
	if (location    != NULL) *location    = tfdd.tile;
 
	if (destination != NULL) *destination = Depot::GetByTile(tfdd.tile)->index;
 
	if (destination != NULL) *destination = GetDepotIndex(tfdd.tile);
 
	if (reverse     != NULL) *reverse     = tfdd.reverse;
 

	
 
	return true;
 
}
 

	
 
/** Send a train to a depot
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
@@ -4517,33 +4517,33 @@ static void CheckIfTrainNeedsService(Tra
 
	/* Only go to the depot if it is not too far out of our way. */
 
	if (tfdd.best_length == UINT_MAX || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) {
 
		if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			/* If we were already heading for a depot but it has
 
			 * suddenly moved farther away, we continue our normal
 
			 * schedule? */
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return;
 
	}
 

	
 
	const Depot *depot = Depot::GetByTile(tfdd.tile);
 
	DepotID depot = GetDepotIndex(tfdd.tile);
 

	
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) &&
 
			v->current_order.GetDestination() != depot->index &&
 
			v->current_order.GetDestination() != depot &&
 
			!Chance16(3, 16)) {
 
		return;
 
	}
 

	
 
	v->current_order.MakeGoToDepot(depot->index, ODTFB_SERVICE);
 
	v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE);
 
	v->dest_tile = tfdd.tile;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void Train::OnNewDay()
 
{
 
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
 

	
 
	if (this->IsFrontEngine()) {
 
		CheckVehicleBreakdown(this);
 
		AgeVehicle(this);
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -1168,27 +1168,25 @@ void ShowVehicleListWindow(const Vehicle
 
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, StationID station)
 
{
 
	ShowVehicleListWindowLocal(company, VLW_STATION_LIST, vehicle_type, station);
 
}
 

	
 
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileIndex depot_tile)
 
{
 
	uint16 depot_airport_index;
 

	
 
	if (vehicle_type == VEH_AIRCRAFT) {
 
		depot_airport_index = GetStationIndex(depot_tile);
 
	} else {
 
		Depot *depot = Depot::GetByTile(depot_tile);
 
		if (depot == NULL) return; // no depot to show
 
		depot_airport_index = depot->index;
 
		depot_airport_index = GetDepotIndex(depot_tile);
 
	}
 
	ShowVehicleListWindowLocal(company, VLW_DEPOT_LIST, vehicle_type, depot_airport_index);
 
}
 

	
 

	
 
/* Unified vehicle GUI - Vehicle Details Window */
 

	
 
/** Constants of vehicle details widget indices */
 
enum VehicleDetailsWindowWidgets {
 
	VLD_WIDGET_CLOSEBOX = 0,
 
	VLD_WIDGET_CAPTION,
 
	VLD_WIDGET_RENAME_VEHICLE,
src/water_cmd.cpp
Show inline comments
 
@@ -175,25 +175,25 @@ static CommandCost RemoveShipDepot(TileI
 
	if (!IsShipDepot(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	TileIndex tile2 = GetOtherShipDepotTile(tile);
 

	
 
	/* do not check for ship on tile when company goes bankrupt */
 
	if (!(flags & DC_BANKRUPT)) {
 
		if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Kill the depot, which is registered at the northernmost tile. Use that one */
 
		delete Depot::GetByTile(tile2 < tile ? tile2 : tile);
 
		delete Depot::GetByTile(tile);
 

	
 
		MakeWaterKeepingClass(tile,  GetTileOwner(tile));
 
		MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile2);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
 
}
 

	
 
/** build a shiplift */
 
static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, DoCommandFlag flags)
0 comments (0 inline, 0 general)