diff options
author | peter1138 <peter1138@openttd.org> | 2008-02-14 07:25:24 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2008-02-14 07:25:24 +0000 |
commit | 3371d0244963f6f9d077761c0897baab4d91f891 (patch) | |
tree | 4e1c1e1e7e281723915de9307d1471df65126a4c | |
parent | 539c635efdafa91683839d1439953d6fdf514eb9 (diff) | |
download | openttd-3371d0244963f6f9d077761c0897baab4d91f891.tar.xz |
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
-rw-r--r-- | src/articulated_vehicles.cpp | 36 | ||||
-rw-r--r-- | src/articulated_vehicles.h | 1 | ||||
-rw-r--r-- | src/build_vehicle_gui.cpp | 46 |
3 files changed, 66 insertions, 17 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index c2ca4c7ec..c4947bc3b 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -34,6 +34,42 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window) 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 index c448532bb..6db647df1 100644 --- 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 index 2922f301b..1ddfb0d62 100644 --- 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, int y, EngineID engine_number, const R 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, uint w, EngineID engine_number) 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, uint w, EngineID engine_number) } /* 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; + } case VEH_ROAD: y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number)); refitable = true; |