From e01106f66b8b003ebc847470d1291af8ef640c96 Mon Sep 17 00:00:00 2001 From: frosch Date: Fri, 27 Feb 2009 20:40:39 +0000 Subject: (svn r15592) -Fix: Refit-info in purchase list did only check the first articulated part. --- src/articulated_vehicles.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/articulated_vehicles.cpp') diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index ac894f362..a53facf80 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -117,9 +117,33 @@ uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) return capacity; } +/** + * Checks whether any of the articulated parts is refittable + * @param engine the first part + * @return true if refittable + */ +bool IsArticulatedVehicleRefittable(EngineID engine) +{ + if (IsEngineRefittable(engine)) return true; + + const Engine *e = GetEngine(engine); + if (e->type != VEH_TRAIN && e->type != VEH_ROAD) return false; + + if (!HasBit(e->info.callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return false; + + for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { + uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL); + if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break; + + EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), e->type, GB(callback, 0, 7)); + if (IsEngineRefittable(artic_engine)) return true; + } + + return false; +} + /** * Ors the refit_masks of all articulated parts. - * Note: Vehicles with a default capacity of zero are ignored. * @param engine the first part * @param type the vehicle type * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask @@ -146,7 +170,6 @@ uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool i /** * Ands the refit_masks of all articulated parts. - * Note: Vehicles with a default capacity of zero are ignored. * @param engine the first part * @param type the vehicle type * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask -- cgit v1.2.3-54-g00ecf