* Unloads cargo at the given station. Deliver or transfer, depending on the * ranges defined by designation_counts. * @param dest StationCargoList to add transferred cargo to. * @param max_move Maximum amount of cargo to move. * @param cargo The cargo type of the cargo. * @param payment Payment object to register payments in. * @param current_tile Current tile the cargo handling is happening
| 624 | * @return Amount of cargo actually unloaded. |
| 625 | */ |
| 626 | uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoType cargo, CargoPayment *payment, TileIndex current_tile) |
| 627 | { |
| 628 | uint moved = 0; |
| 629 | if (this->action_counts[MTA_TRANSFER] > 0) { |
| 630 | uint move = std::min(this->action_counts[MTA_TRANSFER], max_move); |
| 631 | this->ShiftCargo(CargoTransfer(this, dest, move, current_tile)); |
| 632 | moved += move; |
| 633 | } |
| 634 | if (this->action_counts[MTA_TRANSFER] == 0 && this->action_counts[MTA_DELIVER] > 0 && moved < max_move) { |
| 635 | uint move = std::min(this->action_counts[MTA_DELIVER], max_move - moved); |
| 636 | this->ShiftCargo(CargoDelivery(this, move, cargo, payment, current_tile)); |
| 637 | moved += move; |
| 638 | } |
| 639 | return moved; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Truncates the cargo in this list to the given amount. It leaves the |
no test coverage detected