diff options
author | alberth <alberth@openttd.org> | 2014-09-18 19:53:22 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2014-09-18 19:53:22 +0000 |
commit | bc84c52b304e07986a04a519f08c0ec7f8179c3a (patch) | |
tree | bb31f553b56b69a0e10e59f9c45556815d0a594f /src/articulated_vehicles.cpp | |
parent | 4ff3ab1357a8d169379fe41e77ae8ae59a539047 (diff) | |
download | openttd-bc84c52b304e07986a04a519f08c0ec7f8179c3a.tar.xz |
(svn r26849) -Fix[FS#6113]: Better display of refit information in articulated vehicles.
Diffstat (limited to 'src/articulated_vehicles.cpp')
-rw-r--r-- | src/articulated_vehicles.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 859d9a750..c000da03b 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -163,6 +163,41 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine) } /** + * Get the default cargoes and refits of an articulated vehicle. + * The refits are linked to a cargo rather than an articulated part to prevent a long list of parts. + * @param engine Model to investigate. + * @param[out] cargoes Total amount of units that can be transported, summed by cargo. + * @param[out] refits Whether a (possibly partial) refit for each cargo is possible. + */ +void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, uint32 *refits) +{ + cargoes->Clear(); + *refits = 0; + + const Engine *e = Engine::Get(engine); + + CargoID cargo_type; + uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type); + if (cargo_type < NUM_CARGO && cargo_capacity > 0) { + (*cargoes)[cargo_type] += cargo_capacity; + if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type); + } + + if (!e->IsGroundVehicle() || !HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return; + + for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { + EngineID artic_engine = GetNextArticulatedPart(i, engine); + if (artic_engine == INVALID_ENGINE) break; + + cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type); + if (cargo_type < NUM_CARGO && cargo_capacity > 0) { + (*cargoes)[cargo_type] += cargo_capacity; + if (IsEngineRefittable(artic_engine)) SetBit(*refits, cargo_type); + } + } +} + +/** * Checks whether any of the articulated parts is refittable * @param engine the first part * @return true if refittable |