File diff r13023:9f6499c8d4fb → r13024:48c81d0b078a
src/vehicle.cpp
Show inline comments
 
@@ -84,13 +84,13 @@ bool Vehicle::NeedsAutorenewing(const Co
 

	
 
void VehicleServiceInDepot(Vehicle *v)
 
{
 
	v->date_of_last_service = _date;
 
	v->breakdowns_since_last_service = 0;
 
	v->reliability = Engine::Get(v->engine_type)->reliability;
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
 
	SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
 
}
 

	
 
bool Vehicle::NeedsServicing() const
 
{
 
	if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
 

	
 
@@ -514,13 +514,13 @@ void Vehicle::PreDestructor()
 
	if (this->IsPrimaryVehicle()) {
 
		DeleteWindowById(WC_VEHICLE_VIEW, this->index);
 
		DeleteWindowById(WC_VEHICLE_ORDERS, this->index);
 
		DeleteWindowById(WC_VEHICLE_REFIT, this->index);
 
		DeleteWindowById(WC_VEHICLE_DETAILS, this->index);
 
		DeleteWindowById(WC_VEHICLE_TIMETABLE, this->index);
 
		InvalidateWindow(WC_COMPANY, this->owner);
 
		SetWindowDirty(WC_COMPANY, this->owner);
 
	}
 
	InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0);
 

	
 
	this->cargo.Truncate(0);
 
	DeleteVehicleOrders(this);
 
	DeleteDepotHighlightOfVehicle(this);
 
@@ -821,13 +821,13 @@ Vehicle *CheckClickOnVehicle(const ViewP
 
	return found;
 
}
 

	
 
void DecreaseVehicleValue(Vehicle *v)
 
{
 
	v->value -= v->value >> 8;
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
	SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
 
}
 

	
 
static const byte _breakdown_chance[64] = {
 
	  3,   3,   3,   3,   3,   3,   3,   3,
 
	  4,   4,   5,   5,   6,   6,   7,   7,
 
	  8,   8,   9,   9,  10,  10,  11,  11,
 
@@ -841,13 +841,13 @@ static const byte _breakdown_chance[64] 
 
void CheckVehicleBreakdown(Vehicle *v)
 
{
 
	int rel, rel_old;
 

	
 
	/* decrease reliability */
 
	v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0);
 
	if ((rel_old >> 8) != (rel >> 8)) InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
	if ((rel_old >> 8) != (rel >> 8)) SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
 

	
 
	if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) ||
 
			_settings_game.difficulty.vehicle_breakdowns < 1 ||
 
			v->cur_speed < 5 || _game_mode == GM_MENU) {
 
		return;
 
	}
 
@@ -881,13 +881,13 @@ void AgeVehicle(Vehicle *v)
 
	int age = v->age - v->max_age;
 
	if (age == DAYS_IN_LEAP_YEAR * 0 || age == DAYS_IN_LEAP_YEAR * 1 ||
 
			age == DAYS_IN_LEAP_YEAR * 2 || age == DAYS_IN_LEAP_YEAR * 3 || age == DAYS_IN_LEAP_YEAR * 4) {
 
		v->reliability_spd_dec <<= 1;
 
	}
 

	
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
	SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
 

	
 
	/* Don't warn about non-primary or not ours vehicles or vehicles that are crashed */
 
	if (v->Previous() != NULL || v->owner != _local_company || (v->vehstatus & VS_CRASHED) != 0) return;
 

	
 
	/* Don't warn if a renew is active */
 
	if (Company::Get(v->owner)->settings.engine_renew && Engine::Get(v->engine_type)->company_avail != 0) return;
 
@@ -957,57 +957,57 @@ void VehicleEnterDepot(Vehicle *v)
 
	/* Always work with the front of the vehicle */
 
	assert(v == v->First());
 

	
 
	switch (v->type) {
 
		case VEH_TRAIN: {
 
			Train *t = Train::From(v);
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
			SetWindowClassesDirty(WC_TRAINS_LIST);
 
			/* Clear path reservation */
 
			SetDepotReservation(t->tile, false);
 
			if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(t->tile);
 

	
 
			UpdateSignalsOnSegment(t->tile, INVALID_DIAGDIR, t->owner);
 
			t->load_unload_time_rem = 0;
 
			ClrBit(t->flags, VRF_TOGGLE_REVERSE);
 
			TrainConsistChanged(t, true);
 
			break;
 
		}
 

	
 
		case VEH_ROAD:
 
			InvalidateWindowClasses(WC_ROADVEH_LIST);
 
			SetWindowClassesDirty(WC_ROADVEH_LIST);
 
			break;
 

	
 
		case VEH_SHIP:
 
			InvalidateWindowClasses(WC_SHIPS_LIST);
 
			SetWindowClassesDirty(WC_SHIPS_LIST);
 
			Ship::From(v)->state = TRACK_BIT_DEPOT;
 
			RecalcShipStuff(v);
 
			break;
 

	
 
		case VEH_AIRCRAFT:
 
			InvalidateWindowClasses(WC_AIRCRAFT_LIST);
 
			SetWindowClassesDirty(WC_AIRCRAFT_LIST);
 
			HandleAircraftEnterHangar(Aircraft::From(v));
 
			break;
 
		default: NOT_REACHED();
 
	}
 

	
 
	if (v->type != VEH_TRAIN) {
 
		/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters.
 
		 * We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */
 
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
	}
 
	InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
	SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	v->vehstatus |= VS_HIDDEN;
 
	v->cur_speed = 0;
 

	
 
	VehicleServiceInDepot(v);
 

	
 
	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
 

	
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
		SetWindowDirty(WC_VEHICLE_VIEW, v->index);
 

	
 
		const Order *real_order = v->GetOrder(v->cur_order_index);
 
		Order t = v->current_order;
 
		v->current_order.MakeDummy();
 

	
 
		/* Test whether we are heading for this depot. If not, do nothing.
 
@@ -1432,16 +1432,16 @@ void Vehicle::BeginLoading()
 
	}
 

	
 
	Station::Get(this->last_station_visited)->loading_vehicles.push_back(this);
 

	
 
	PrepareUnload(this);
 

	
 
	InvalidateWindow(GetWindowClassForVehicleType(this->type), this->owner);
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
	InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
 
	InvalidateWindow(WC_STATION_VIEW, this->last_station_visited);
 
	SetWindowDirty(GetWindowClassForVehicleType(this->type), this->owner);
 
	SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
	SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
 
	SetWindowDirty(WC_STATION_VIEW, this->last_station_visited);
 

	
 
	Station::Get(this->last_station_visited)->MarkTilesDirty(true);
 
	this->cur_speed = 0;
 
	this->MarkDirty();
 
}
 

	
 
@@ -1514,25 +1514,25 @@ CommandCost Vehicle::SendToDepot(DoComma
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
 
			if (flags & DC_EXEC) {
 
				this->current_order.SetDepotOrderType(ODTF_MANUAL);
 
				this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT);
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
				SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
			}
 
			return CommandCost();
 
		}
 

	
 
		if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
 
		if (flags & DC_EXEC) {
 
			/* If the orders to 'goto depot' are in the orders list (forced servicing),
 
			 * then skip to the next order; effectively cancelling this forced service */
 
			if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->IncrementOrderIndex();
 

	
 
			this->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
			SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return CommandCost();
 
	}
 

	
 
	TileIndex location;
 
	DestinationID destination;
 
@@ -1543,13 +1543,13 @@ CommandCost Vehicle::SendToDepot(DoComma
 
	if (flags & DC_EXEC) {
 
		if (this->current_order.IsType(OT_LOADING)) this->LeaveStation();
 

	
 
		this->dest_tile = location;
 
		this->current_order.MakeGoToDepot(destination, ODTF_MANUAL);
 
		if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT);
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
		SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 

	
 
		/* If there is no depot in front, reverse automatically (trains only) */
 
		if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 

	
 
		if (this->type == VEH_AIRCRAFT) {
 
			Aircraft *a = Aircraft::From(this);
 
@@ -1642,14 +1642,14 @@ void StopAllVehicles()
 
{
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		/* Code ripped from CmdStartStopTrain. Can't call it, because of
 
		 * ownership problems, so we'll duplicate some code, for now */
 
		v->vehstatus |= VS_STOPPED;
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
		SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
 
	}
 
}
 

	
 
void VehiclesYearlyLoop()
 
{
 
	Vehicle *v;
 
@@ -1669,13 +1669,13 @@ void VehiclesYearlyLoop()
 
				}
 
				AI::NewEvent(v->owner, new AIEventVehicleUnprofitable(v->index));
 
			}
 

	
 
			v->profit_last_year = v->profit_this_year;
 
			v->profit_this_year = 0;
 
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
			SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
 
		}
 
	}
 
}
 

	
 

	
 
/**