* Build up the cargo view for WAITING mode and a specific cargo. * @param cargo Cargo to show. * @param packets The current station's cargo list for that cargo. * @param entry The CargoDataEntry to save the result in. */
| 1604 | * @param entry The CargoDataEntry to save the result in. |
| 1605 | */ |
| 1606 | void BuildCargoList(CargoType cargo, const StationCargoList &packets, CargoDataEntry *entry) |
| 1607 | { |
| 1608 | const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(cargo); |
| 1609 | for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) { |
| 1610 | const CargoPacket *cp = *it; |
| 1611 | StationID next = it.GetKey(); |
| 1612 | |
| 1613 | const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation()); |
| 1614 | if (source_entry == nullptr) { |
| 1615 | this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count()); |
| 1616 | continue; |
| 1617 | } |
| 1618 | |
| 1619 | const CargoDataEntry *via_entry = source_entry->Retrieve(next); |
| 1620 | if (via_entry == nullptr) { |
| 1621 | this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count()); |
| 1622 | continue; |
| 1623 | } |
| 1624 | |
| 1625 | uint remaining = cp->Count(); |
| 1626 | for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End();) { |
| 1627 | CargoDataEntry &dest_entry = **dest_it; |
| 1628 | |
| 1629 | /* Advance iterator here instead of in the for statement to test whether this is the last entry */ |
| 1630 | ++dest_it; |
| 1631 | |
| 1632 | uint val; |
| 1633 | if (dest_it == via_entry->End()) { |
| 1634 | /* Allocate all remaining waiting cargo to the last destination to avoid |
| 1635 | * waiting cargo being "lost", and the displayed total waiting cargo |
| 1636 | * not matching GoodsEntry::TotalCount() */ |
| 1637 | val = remaining; |
| 1638 | } else { |
| 1639 | val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry.GetCount(), via_entry->GetCount())); |
| 1640 | remaining -= val; |
| 1641 | } |
| 1642 | this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, dest_entry.GetStation(), val); |
| 1643 | } |
| 1644 | } |
| 1645 | this->ShowCargo(entry, cargo, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount()); |
| 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * Build up the cargo view for all cargoes. |
nothing calls this directly
no test coverage detected