diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -34,6 +34,42 @@ uint CountArticulatedParts(EngineID engi return i - 1; } + +uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) +{ + static uint16 capacity[NUM_CARGO]; + memset(capacity, 0, sizeof(capacity)); + + if (type == VEH_TRAIN) { + const RailVehicleInfo *rvi = RailVehInfo(engine); + capacity[rvi->cargo_type] = rvi->capacity; + if (rvi->railveh_type == RAILVEH_MULTIHEAD) capacity[rvi->cargo_type] += rvi->capacity; + } else if (type == VEH_ROAD) { + const RoadVehicleInfo *rvi = RoadVehInfo(engine); + capacity[rvi->cargo_type] = rvi->capacity; + } + + if (!HasBit(EngInfo(engine)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity; + + for (uint i = 1; i < MAX_UVALUE(EngineID); i++) { + uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL); + if (callback == CALLBACK_FAILED || callback == 0xFF) break; + + EngineID artic_engine = GetFirstEngineOfType(type) + GB(callback, 0, 7); + + if (type == VEH_TRAIN) { + const RailVehicleInfo *rvi = RailVehInfo(artic_engine); + capacity[rvi->cargo_type] += GetEngineProperty(artic_engine, 0x14, rvi->capacity); + } else if (type == VEH_ROAD) { + const RoadVehicleInfo *rvi = RoadVehInfo(artic_engine); + capacity[rvi->cargo_type] += GetEngineProperty(artic_engine, 0x0F, rvi->capacity); + } + } + + return capacity; +} + + void AddArticulatedParts(Vehicle **vl, VehicleType type) { const Vehicle *v = vl[0]; diff --git a/src/articulated_vehicles.h b/src/articulated_vehicles.h --- a/src/articulated_vehicles.h +++ b/src/articulated_vehicles.h @@ -8,6 +8,7 @@ #include "vehicle_type.h" uint CountArticulatedParts(EngineID engine_type, bool purchase_window); +uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type); void AddArticulatedParts(Vehicle **vl, VehicleType type); #endif /* ARTICULATED_VEHICLES_H */ diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -530,6 +530,26 @@ static const StringID _sort_listing[][11 INVALID_STRING_ID }}; +static int DrawCargoCapacityInfo(int x, int y, EngineID engine, VehicleType type, bool refittable) +{ + uint16 *cap = GetCapacityOfArticulatedParts(engine, type); + + for (uint c = 0; c < NUM_CARGO; c++) { + if (cap[c] == 0) continue; + + SetDParam(0, c); + SetDParam(1, cap[c]); + SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); + DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); + y += 10; + + /* Only show as refittable once */ + refittable = false; + } + + return y; +} + /* Draw rail wagon specific details */ static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi) { @@ -615,13 +635,7 @@ static int DrawRoadVehPurchaseInfo(int x y += 10; /* Cargo type + capacity */ - SetDParam(0, rvi->cargo_type); - SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity)); - SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); - DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); - y += 10; - - return y; + return DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, refittable); } /* Draw ship specific details */ @@ -703,7 +717,7 @@ int DrawVehiclePurchaseInfo(int x, int y const RailVehicleInfo *rvi = RailVehInfo(engine_number); uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity); - refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0); + bool refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0); if (rvi->railveh_type == RAILVEH_WAGON) { y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi); @@ -712,20 +726,18 @@ int DrawVehiclePurchaseInfo(int x, int y } /* Cargo type + capacity, or N/A */ - if (rvi->capacity == 0) { + int new_y = DrawCargoCapacityInfo(x, y, engine_number, VEH_TRAIN, refitable); + + if (new_y == y) { SetDParam(0, CT_INVALID); SetDParam(2, STR_EMPTY); + DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); + y += 10; } else { - int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0); - - SetDParam(0, rvi->cargo_type); - SetDParam(1, (capacity * (CountArticulatedParts(engine_number, true) + 1)) << multihead); - SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY); + y = new_y; } - DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); - y += 10; + break; } - break; case VEH_ROAD: y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number)); refitable = true;