74 feeder_share(feeder_share),
76 days_in_transit(days_in_transit),
80 loaded_at_xy(loaded_at_xy)
98 this->
count -= new_size;
119 assert(count < this->count);
121 this->count -=
count;
158 template <
class Tinst,
class Tcont>
161 for (
Iterator it(this->packets.begin()); it != this->packets.end(); ++it) {
170 template <
class Tinst,
class Tcont>
173 this->packets.clear();
182 template <
class Tinst,
class Tcont>
185 assert(count <= cp->count);
186 this->count -= count;
195 template <
class Tinst,
class Tcont>
198 this->count += cp->
count;
203 template <
class Tinst,
class Tcont>
207 this->cargo_days_in_transit = 0;
209 for (
ConstIterator it(this->packets.begin()); it != this->packets.end(); it++) {
210 static_cast<Tinst *
>(
this)->AddToCache(*it);
221 template <
class Tinst,
class Tcont>
224 if (Tinst::AreMergable(icp, cp) &&
266 uint sum = cp->
count;
288 template<
class Taction>
292 while (it != this->
packets.end() && action.MaxMove() > 0) {
310 template<
class Taction>
313 if (this->
packets.empty())
return;
316 while (action.MaxMove() > 0) {
424 StationID current_station,
bool accepted,
StationIDStack next_station)
426 if (cargo_next == INVALID_STATION) {
428 }
else if (cargo_next == current_station) {
430 }
else if (next_station.
Contains(cargo_next)) {
460 bool force_unload = (order_flags &
OUFB_UNLOAD) != 0;
463 while (sum < this->
count) {
467 StationID cargo_next = INVALID_STATION;
471 }
else if (force_unload && accepted && cp->
source != current_station) {
473 }
else if (force_transfer) {
477 FlowStatMap::const_iterator flow_it(ge->
flows.find(cp->
source));
478 if (flow_it == ge->
flows.end()) {
479 cargo_next = INVALID_STATION;
481 FlowStat new_shares = flow_it->second;
488 cargo_next = INVALID_STATION;
490 cargo_next = new_shares.
GetVia();
496 if (cp->
source == INVALID_STATION && !ge->
flows.empty()) {
499 bool restricted =
false;
500 FlowStatMap::const_iterator flow_it(ge->
flows.find(cp->
source));
501 if (flow_it == ge->
flows.end()) {
502 cargo_next = INVALID_STATION;
504 cargo_next = flow_it->second.GetViaWithRestricted(restricted);
510 cargo_next = flow_it->second.GetVia();
518 if (deliver == this->
packets.end()) --deliver;
521 this->
packets.insert(deliver, cp);
560 template<VehicleCargoList::MoveToAction Tfrom, VehicleCargoList::MoveToAction Tto>
564 assert_tcompile(Tfrom - Tto == 1 || Tto - Tfrom == 1);
579 uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER>(uint max_move, TileOrStationID next_station)
581 max_move =
min(this->action_counts[MTA_DELIVER], max_move);
584 for (Iterator it(this->packets.begin()); sum < this->action_counts[MTA_TRANSFER] + max_move;) {
587 if (sum <= this->action_counts[MTA_TRANSFER])
continue;
588 if (sum > this->action_counts[MTA_TRANSFER] + max_move) {
589 CargoPacket *cp_split = cp->
Split(sum - this->action_counts[MTA_TRANSFER] + max_move);
590 sum -= cp_split->
Count();
591 this->packets.insert(it, cp_split);
596 this->action_counts[MTA_DELIVER] -= max_move;
597 this->action_counts[MTA_TRANSFER] += max_move;
623 max_move =
min(this->
count, max_move);
660 max_move =
min(this->
count, max_move);
699 StationCargoPacketMap::List &list = this->
packets[next];
700 for (StationCargoPacketMap::List::reverse_iterator it(list.rbegin());
701 it != list.rend(); it++) {
721 template <
class Taction>
725 for (
Iterator it(range.first); it != range.second && it.GetKey() == next;) {
726 if (action.MaxMove() == 0)
return false;
751 template <
class Taction>
754 uint max_move = action.MaxMove();
757 if (action.MaxMove() == 0)
break;
759 if (include_invalid && action.MaxMove() > 0) {
762 return max_move - action.MaxMove();
775 max_move =
min(max_move, this->
count);
776 uint prev_count = this->
count;
779 bool do_count = cargo_per_source != NULL;
780 while (max_move > moved) {
783 if (prev_count > max_move &&
RandomRange(prev_count) < prev_count - max_move) {
784 if (do_count && loop == 0) {
790 uint diff = max_move - moved;
791 if (cp->
count > diff) {
798 if (do_count) (*cargo_per_source)[cp->
source] -= diff;
801 if (do_count) (*cargo_per_source)[cp->
source] += cp->
count;
806 if (do_count && loop > 0) {
874 template uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_KEEP>(uint, TileOrStationID);