|
@@ -325,50 +325,49 @@ struct RefitResult {
|
|
|
* This is the vehicle-type independent part of the CmdRefitXXX functions.
|
|
|
* @param v The vehicle to refit.
|
|
|
* @param only_this Whether to only refit this vehicle, or to check the rest of them.
|
|
|
* @param num_vehicles Number of vehicles to refit (not counting articulated parts). Zero means the whole chain.
|
|
|
* @param new_cid Cargotype to refit to
|
|
|
* @param new_subtype Cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
|
|
|
* @param flags Command flags
|
|
|
* @param auto_refit Refitting is done as automatic refitting outside a depot.
|
|
|
* @return Refit cost.
|
|
|
*/
|
|
|
static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
|
|
|
{
|
|
|
CommandCost cost(v->GetExpenseType(false));
|
|
|
uint total_capacity = 0;
|
|
|
uint total_mail_capacity = 0;
|
|
|
num_vehicles = num_vehicles == 0 ? UINT8_MAX : num_vehicles;
|
|
|
|
|
|
VehicleSet vehicles_to_refit;
|
|
|
if (!only_this) {
|
|
|
GetVehicleSet(vehicles_to_refit, v, num_vehicles);
|
|
|
/* In this case, we need to check the whole chain. */
|
|
|
v = v->First();
|
|
|
}
|
|
|
|
|
|
static SmallVector<RefitResult, 16> refit_result;
|
|
|
refit_result.clear();
|
|
|
std::vector<RefitResult> refit_result;
|
|
|
|
|
|
v->InvalidateNewGRFCacheOfChain();
|
|
|
byte actual_subtype = new_subtype;
|
|
|
for (; v != NULL; v = (only_this ? NULL : v->Next())) {
|
|
|
/* Reset actual_subtype for every new vehicle */
|
|
|
if (!v->IsArticulatedPart()) actual_subtype = new_subtype;
|
|
|
|
|
|
if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end() && !only_this) continue;
|
|
|
|
|
|
const Engine *e = v->GetEngine();
|
|
|
if (!e->CanCarryCargo()) continue;
|
|
|
|
|
|
/* If the vehicle is not refittable, or does not allow automatic refitting,
|
|
|
* count its capacity nevertheless if the cargo matches */
|
|
|
bool refittable = HasBit(e->info.refit_mask, new_cid) && (!auto_refit || HasBit(e->info.misc_flags, EF_AUTO_REFIT));
|
|
|
if (!refittable && v->cargo_type != new_cid) continue;
|
|
|
|
|
|
/* Determine best fitting subtype if requested */
|
|
|
if (actual_subtype == 0xFF) {
|
|
|
actual_subtype = GetBestFittingSubType(v, v, new_cid);
|
|
|
}
|
|
|
|
|
|
/* Back up the vehicle's cargo type */
|
|
|
CargoID temp_cid = v->cargo_type;
|