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

Function TruncateCargo

src/station_cmd.cpp:3951–3967  ·  view source on GitHub ↗

* Truncate the cargo by a specific amount. * @param cs The type of cargo to perform the truncation for. * @param ge The goods entry, of the station, to truncate. * @param amount The amount to truncate the cargo by. */

Source from the content-addressed store, hash-verified

3949 * @param amount The amount to truncate the cargo by.
3950 */
3951static void TruncateCargo(const CargoSpec *cs, GoodsEntry *ge, uint amount = UINT_MAX)
3952{
3953 /* If truncating also punish the source stations' ratings to
3954 * decrease the flow of incoming cargo. */
3955
3956 if (!ge->HasData()) return;
3957
3958 StationCargoAmountMap waiting_per_source;
3959 ge->GetData().cargo.Truncate(amount, &waiting_per_source);
3960 for (StationCargoAmountMap::iterator i(waiting_per_source.begin()); i != waiting_per_source.end(); ++i) {
3961 Station *source_station = Station::GetIfValid(i->first);
3962 if (source_station == nullptr) continue;
3963
3964 GoodsEntry &source_ge = source_station->goods[cs->Index()];
3965 source_ge.max_waiting_cargo = std::max(source_ge.max_waiting_cargo, i->second);
3966 }
3967}
3968
3969/**
3970 * Periodic update of a station's rating.

Callers 1

UpdateStationRatingFunction · 0.85

Calls 5

TruncateMethod · 0.80
HasDataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected