File diff r20077:1122c5c64e88 → r20078:a7a34cf316df
src/economy.cpp
Show inline comments
 
@@ -1438,13 +1438,12 @@ static void LoadUnloadVehicle(Vehicle *f
 

	
 
		/* This order has a refit, if this is the first vehicle part carrying cargo and the whole vehicle is empty, try refitting. */
 
		if (front->current_order.IsRefit() && artic_part == 1 && IsArticulatedVehicleEmpty(v) &&
 
				(v->type != VEH_AIRCRAFT || (Aircraft::From(v)->IsNormalAircraft() && v->Next()->cargo.Count() == 0))) {
 
			Vehicle *v_start = v->GetFirstEnginePart();
 
			CargoID new_cid = front->current_order.GetRefitCargo();
 
			byte new_subtype = front->current_order.GetRefitSubtype();
 

	
 
			/* Remove old capacity from consist capacity */
 
			consist_capleft[v_start->cargo_type] -= v_start->cargo_cap;
 
			for (Vehicle *w = v_start; w->HasArticulatedPart(); ) {
 
				w = w->GetNextArticulatedPart();
 
				consist_capleft[w->cargo_type] -= w->cargo_cap;
 
@@ -1468,25 +1467,24 @@ static void LoadUnloadVehicle(Vehicle *f
 
				FOR_EACH_SET_CARGO_ID(cid, refit_mask) {
 
					/* Consider refitting to this cargo, if other vehicles of the consist cannot
 
					 * already take the cargo without refitting */
 
					if ((int)st->goods[cid].cargo.Count() > (int)consist_capleft[cid] + amount) {
 
						/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
 
						 * the returned refit capacity will be greater than zero. */
 
						new_subtype = GetBestFittingSubType(v, v, cid);
 
						DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
						DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
						if (_returned_refit_capacity > 0) {
 
							amount = st->goods[cid].cargo.Count() - consist_capleft[cid];
 
							new_cid = cid;
 
						}
 
					}
 
				}
 
			}
 

	
 
			/* Refit if given a valid cargo. */
 
			if (new_cid < NUM_CARGO) {
 
				CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
				CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
				if (cost.Succeeded()) front->profit_this_year -= cost.GetCost() << 8;
 
				ge = &st->goods[v->cargo_type];
 
			}
 

	
 
			/* Add new capacity to consist capacity and reserve cargo */
 
			w = v_start;