Autoreplace: Add support for multi-cargo ships

This commit is contained in:
Jonathan G Rennison
2023-09-01 23:35:42 +01:00
parent 69b2ca9983
commit 7c28ee0213
7 changed files with 218 additions and 21 deletions

View File

@@ -288,6 +288,22 @@ bool Vehicle::NeedsServicing() const
/* Check refittability */
CargoTypes available_cargo_types, union_mask;
GetArticulatedRefitMasks(new_engine, true, &union_mask, &available_cargo_types);
/* Is this a multi-cargo ship? */
if (union_mask != 0 && v->type == VEH_SHIP && v->Next() != nullptr) {
CargoTypes cargoes = 0;
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
if (u->cargo_type != CT_INVALID && u->GetEngine()->CanCarryCargo()) {
SetBit(cargoes, u->cargo_type);
}
}
if (!HasAtMostOneBit(cargoes)) {
/* Ship has more than one cargo, special handling */
if (!AutoreplaceMultiPartShipWouldSucceed(new_engine, v, cargoes)) continue;
union_mask = 0;
}
}
/* Is there anything to refit? */
if (union_mask != 0) {
CargoID cargo_type;