mirror of https://github.com/OpenTTD/OpenTTD
(svn r12137) -Fix [FS#1769]: Show cargo capacity for articulated vehicles correctly in the purchase list. Multiple cargo types can also now been shown.
parent
539c635efd
commit
3371d02449
|
@ -34,6 +34,42 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
|
||||||
return i - 1;
|
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)
|
void AddArticulatedParts(Vehicle **vl, VehicleType type)
|
||||||
{
|
{
|
||||||
const Vehicle *v = vl[0];
|
const Vehicle *v = vl[0];
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "vehicle_type.h"
|
#include "vehicle_type.h"
|
||||||
|
|
||||||
uint CountArticulatedParts(EngineID engine_type, bool purchase_window);
|
uint CountArticulatedParts(EngineID engine_type, bool purchase_window);
|
||||||
|
uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type);
|
||||||
void AddArticulatedParts(Vehicle **vl, VehicleType type);
|
void AddArticulatedParts(Vehicle **vl, VehicleType type);
|
||||||
|
|
||||||
#endif /* ARTICULATED_VEHICLES_H */
|
#endif /* ARTICULATED_VEHICLES_H */
|
||||||
|
|
|
@ -530,6 +530,26 @@ static const StringID _sort_listing[][11] = {{
|
||||||
INVALID_STRING_ID
|
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 */
|
/* Draw rail wagon specific details */
|
||||||
static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
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;
|
y += 10;
|
||||||
|
|
||||||
/* Cargo type + capacity */
|
/* Cargo type + capacity */
|
||||||
SetDParam(0, rvi->cargo_type);
|
return DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, refittable);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw ship specific details */
|
/* 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);
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
||||||
uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
|
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) {
|
if (rvi->railveh_type == RAILVEH_WAGON) {
|
||||||
y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
|
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 */
|
/* 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(0, CT_INVALID);
|
||||||
SetDParam(2, STR_EMPTY);
|
SetDParam(2, STR_EMPTY);
|
||||||
|
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
|
||||||
|
y += 10;
|
||||||
} else {
|
} else {
|
||||||
int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
y = new_y;
|
||||||
|
|
||||||
SetDParam(0, rvi->cargo_type);
|
|
||||||
SetDParam(1, (capacity * (CountArticulatedParts(engine_number, true) + 1)) << multihead);
|
|
||||||
SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
|
|
||||||
}
|
}
|
||||||
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
|
|
||||||
y += 10;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case VEH_ROAD:
|
case VEH_ROAD:
|
||||||
y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
|
y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
|
||||||
refitable = true;
|
refitable = true;
|
||||||
|
|
Loading…
Reference in New Issue