Autoreplace: Handle trivial replacements of mixed cargo articulated engines

This commit is contained in:
Jonathan G Rennison
2023-09-01 19:20:11 +01:00
parent 568eafe661
commit da35e7bb35
4 changed files with 67 additions and 17 deletions

View File

@@ -291,13 +291,20 @@ bool Vehicle::NeedsServicing() const
/* Is there anything to refit? */
if (union_mask != 0) {
CargoID cargo_type;
/* We cannot refit to mixed cargoes in an automated way */
if (IsArticulatedVehicleCarryingDifferentCargoes(v, &cargo_type)) continue;
/* Did the old vehicle carry anything? */
if (cargo_type != CT_INVALID) {
/* We can't refit the vehicle to carry the cargo we want */
if (!HasBit(available_cargo_types, cargo_type)) continue;
CargoTypes cargo_mask = GetCargoTypesOfArticulatedVehicle(v, &cargo_type);
if (!HasAtMostOneBit(cargo_mask)) {
CargoTypes new_engine_default_cargoes = GetCargoTypesOfArticulatedParts(engine_type);
if ((cargo_mask & new_engine_default_cargoes) != cargo_mask) {
/* We cannot refit to mixed cargoes in an automated way */
continue;
}
/* engine_type is already a mixed cargo type which matches the incoming vehicle by default, no refit required */
} else {
/* Did the old vehicle carry anything? */
if (cargo_type != CT_INVALID) {
/* We can't refit the vehicle to carry the cargo we want */
if (!HasBit(available_cargo_types, cargo_type)) continue;
}
}
}