diff options
author | frosch <frosch@openttd.org> | 2009-02-27 20:40:39 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-02-27 20:40:39 +0000 |
commit | e01106f66b8b003ebc847470d1291af8ef640c96 (patch) | |
tree | 7419f11ae37834876be39c85f17576ba1dd82c3e /src | |
parent | 729972847269e3661e2647f18061f1a02d010d0c (diff) | |
download | openttd-e01106f66b8b003ebc847470d1291af8ef640c96.tar.xz |
(svn r15592) -Fix: Refit-info in purchase list did only check the first articulated part.
Diffstat (limited to 'src')
-rw-r--r-- | src/articulated_vehicles.cpp | 27 | ||||
-rw-r--r-- | src/articulated_vehicles.h | 1 | ||||
-rw-r--r-- | src/build_vehicle_gui.cpp | 34 | ||||
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 6 |
5 files changed, 51 insertions, 18 deletions
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 @@ -118,8 +118,32 @@ uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) } /** + * 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 diff --git a/src/articulated_vehicles.h b/src/articulated_vehicles.h index 66f2e7f2f..02e546364 100644 --- a/src/articulated_vehicles.h +++ b/src/articulated_vehicles.h @@ -14,5 +14,6 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type); uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type); uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type); bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *cargo_type); +bool IsArticulatedVehicleRefittable(EngineID engine); #endif /* ARTICULATED_VEHICLES_H */ diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 888091e04..a365ae025 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -567,12 +567,11 @@ static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number) DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING); y += 10; - /* Cargo type + capacity */ - return DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, IsEngineRefittable(engine_number)); + return y; } /* Draw ship specific details */ -static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi) +static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi, bool refittable) { const Engine *e = GetEngine(engine_number); @@ -585,7 +584,7 @@ static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const Ship /* Cargo type + capacity */ SetDParam(0, e->GetDefaultCargoType()); SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity)); - SetDParam(2, IsEngineRefittable(engine_number) ? STR_9842_REFITTABLE : STR_EMPTY); + SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); y += 10; @@ -598,7 +597,7 @@ static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const Ship } /* Draw aircraft specific details */ -static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi) +static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi, bool refittable) { const Engine *e = GetEngine(engine_number); CargoID cargo = e->GetDefaultCargoType(); @@ -619,7 +618,7 @@ static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const * callback, then the capacity shown is likely to be incorrect. */ SetDParam(0, cargo); SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi)); - SetDParam(2, STR_9842_REFITTABLE); + SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); } y += 10; @@ -644,14 +643,12 @@ int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number) const Engine *e = GetEngine(engine_number); YearMonthDay ymd; ConvertDateToYMD(e->intro_date, &ymd); - bool refittable = IsEngineRefittable(engine_number); + bool refittable = IsArticulatedVehicleRefittable(engine_number); switch (e->type) { default: NOT_REACHED(); case VEH_TRAIN: { const RailVehicleInfo *rvi = RailVehInfo(engine_number); - refittable &= GetEngineProperty(engine_number, 0x14, rvi->capacity) > 0; - if (rvi->railveh_type == RAILVEH_WAGON) { y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi); } else { @@ -671,14 +668,27 @@ int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number) } break; } - case VEH_ROAD: + case VEH_ROAD: { y = DrawRoadVehPurchaseInfo(x, y, engine_number); + + /* Cargo type + capacity, or N/A */ + int new_y = DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, refittable); + + if (new_y == y) { + SetDParam(0, CT_INVALID); + SetDParam(2, STR_EMPTY); + DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING); + y += 10; + } else { + y = new_y; + } break; + } case VEH_SHIP: - y = DrawShipPurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number)); + y = DrawShipPurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number), refittable); break; case VEH_AIRCRAFT: - y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number)); + y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number), refittable); break; } diff --git a/src/engine.cpp b/src/engine.cpp index d48b23bff..eb9c51fd4 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -716,6 +716,7 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company) /** * Check if an engine is refittable. + * Note: Likely you want to use IsArticulatedVehicleRefittable(). * @param engine index of the engine to check. * @return true if the engine is refittable. */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index b3a6c385a..ef2a05835 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -29,6 +29,7 @@ #include "timetable.h" #include "vehiclelist.h" #include "settings_type.h" +#include "articulated_vehicles.h" #include "table/sprites.h" #include "table/strings.h" @@ -447,7 +448,7 @@ uint ShowAdditionalText(int x, int y, uint w, EngineID engine) uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine) { /* List of cargo types of this engine */ - uint32 cmask = EngInfo(engine)->refit_mask; + uint32 cmask = GetUnionOfArticulatedRefitMasks(engine, GetEngine(engine)->type, false); /* List of cargo types available in this climate */ uint32 lmask = _cargo_mask; char string[512]; @@ -1667,9 +1668,6 @@ static bool IsVehicleRefitable(const Vehicle *v) if (!v->IsStoppedInDepot()) return false; do { - /* Skip this vehicle if it has no capacity */ - if (v->cargo_cap == 0) continue; - if (IsEngineRefittable(v->engine_type)) return true; } while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL); |