summaryrefslogtreecommitdiff
path: root/src/vehicle_gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vehicle_gui.cpp')
-rw-r--r--src/vehicle_gui.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index d6a1bec67..03ad805c9 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -2730,3 +2730,28 @@ int GetVehicleWidth(Vehicle *v, EngineImageType image_type)
return vehicle_width;
}
+
+/**
+ * Sum the cargo carried by a vehicle by final destination.
+ * @param v The vehicle.
+ * @param sum The cargo summary is added to this.
+ */
+void AddVehicleCargoDestSummary(const Vehicle *v, CargoDestSummary *sum)
+{
+ const VehicleCargoList::List *packets = v->cargo.Packets();
+ for (VehicleCargoList::ConstIterator it = packets->begin(); it != packets->end(); ++it) {
+ const CargoPacket *cp = *it;
+
+ /* Search for an existing list entry. */
+ CargoDestSummary::iterator data;
+ for (data = sum->begin(); data != sum->end(); ++data) {
+ if (data->type == cp->DestinationType() && data->dest == cp->DestinationID()) {
+ data->count += cp->Count();
+ break;
+ }
+ }
+
+ /* Not found, insert new entry. */
+ if (data == sum->end() && cp->DestinationID() != INVALID_SOURCE) sum->push_back(CargoDestSummaryData(cp->DestinationID(), cp->DestinationType(), cp->Count()));
+ }
+}