* 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. */
| 3949 | * @param amount The amount to truncate the cargo by. |
| 3950 | */ |
| 3951 | static 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. |