MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CountCargoWaiting

Method CountCargoWaiting

src/script/api/script_station.cpp:47–72  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

45
46template <bool Tfrom, bool Tvia>
47/* static */ SQInteger ScriptStation::CountCargoWaiting(StationID station_id,
48 StationID from_station_id, StationID via_station_id, CargoType cargo_type)
49{
50 if (!ScriptStation::IsCargoRequestValid<Tfrom, Tvia>(station_id, from_station_id,
51 via_station_id, cargo_type)) {
52 return -1;
53 }
54
55 const ::GoodsEntry &goods = ::Station::Get(station_id)->goods[cargo_type];
56 if (!goods.HasData()) return 0;
57
58 const StationCargoList &cargo_list = goods.GetData().cargo;
59 if (!Tfrom && !Tvia) return cargo_list.TotalCount();
60
61 uint16_t cargo_count = 0;
62 std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range = Tvia ?
63 cargo_list.Packets()->equal_range(via_station_id) :
64 std::make_pair(StationCargoList::ConstIterator(cargo_list.Packets()->begin()),
65 StationCargoList::ConstIterator(cargo_list.Packets()->end()));
66 for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) {
67 const CargoPacket *cp = *it;
68 if (!Tfrom || cp->GetFirstStation() == from_station_id) cargo_count += cp->Count();
69 }
70
71 return cargo_count;
72}
73
74/* static */ SQInteger ScriptStation::GetCargoWaiting(StationID station_id, CargoType cargo_type)
75{

Callers

nothing calls this directly

Calls 8

equal_rangeMethod · 0.80
PacketsMethod · 0.80
HasDataMethod · 0.45
TotalCountMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetFirstStationMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected