File diff r10313:fbac66248923 → r10314:db6cfacd8639
src/vehicle.cpp
Show inline comments
 
@@ -1513,96 +1513,100 @@ CommandCost SendAllVehiclesToDepot(Vehic
 
 * @param v The Vehicle to check. For trains, use the first engine.
 
 * @param color The string to show depending on if we are unloading or loading
 
 * @return A percentage of how full the Vehicle is.
 
 */
 
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *color)
 
{
 
	int count = 0;
 
	int max = 0;
 
	int cars = 0;
 
	int unloading = 0;
 
	bool loading = false;
 

	
 
	const Vehicle *u = v;
 
	const Station *st = v->last_station_visited != INVALID_STATION ? GetStation(v->last_station_visited) : NULL;
 

	
 
	/* Count up max and used */
 
	for (; v != NULL; v = v->Next()) {
 
		count += v->cargo.Count();
 
		max += v->cargo_cap;
 
		if (v->cargo_cap != 0 && color != NULL) {
 
			unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
 
			loading |= !(u->current_order.GetUnloadType() & OUFB_UNLOAD) && st->goods[v->cargo_type].days_since_pickup != 255;
 
			cars++;
 
		}
 
	}
 

	
 
	if (color != NULL) {
 
		if (unloading == 0 && loading) {
 
			*color = STR_PERCENT_UP;
 
		} else if (cars == unloading || !loading) {
 
			*color = STR_PERCENT_DOWN;
 
		} else {
 
			*color = STR_PERCENT_UP_DOWN;
 
		}
 
	}
 

	
 
	/* Train without capacity */
 
	if (max == 0) return 100;
 

	
 
	/* Return the percentage */
 
	return (count * 100) / max;
 
}
 

	
 
void VehicleEnterDepot(Vehicle *v)
 
{
 
	switch (v->type) {
 
		case VEH_TRAIN:
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
			/* Clear path reservation */
 
			SetDepotWaypointReservation(v->tile, false);
 
			if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(v->tile);
 

	
 
			if (!IsFrontEngine(v)) v = v->First();
 
			UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
 
			v->load_unload_time_rem = 0;
 
			ClrBit(v->u.rail.flags, VRF_TOGGLE_REVERSE);
 
			TrainConsistChanged(v, true);
 
			break;
 

	
 
		case VEH_ROAD:
 
			InvalidateWindowClasses(WC_ROADVEH_LIST);
 
			if (!IsRoadVehFront(v)) v = v->First();
 
			break;
 

	
 
		case VEH_SHIP:
 
			InvalidateWindowClasses(WC_SHIPS_LIST);
 
			v->u.ship.state = TRACK_BIT_DEPOT;
 
			RecalcShipStuff(v);
 
			break;
 

	
 
		case VEH_AIRCRAFT:
 
			InvalidateWindowClasses(WC_AIRCRAFT_LIST);
 
			HandleAircraftEnterHangar(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);
 

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

	
 
		Order t = v->current_order;
 
		v->current_order.MakeDummy();
 

	
 
		if (t.IsRefit()) {
 
			_current_company = v->owner;
 
			CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));