diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "station_base.h" #include "core/pool_func.hpp" +#include "economy_base.h" /* Initialize the cargopacket-pool */ CargoPacketPool _cargopacket_pool("CargoPacket"); @@ -26,7 +27,6 @@ CargoPacket::CargoPacket(StationID sourc this->count = count; this->days_in_transit = 0; this->feeder_share = 0; - this->paid_for = false; } /* @@ -99,9 +99,10 @@ void CargoList::Truncate(uint count) InvalidateCache(); } -bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, uint data) +bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, CargoPayment *payment, uint data) { assert(mta == MTA_FINAL_DELIVERY || dest != NULL); + assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL); CargoList tmp; while (!packets.empty() && count > 0) { @@ -114,20 +115,25 @@ bool CargoList::MoveTo(CargoList *dest, if (cp->source == data) { tmp.Append(cp); } else { + payment->PayFinalDelivery(cp, cp->count); count -= cp->count; delete cp; } - break; + continue; // of the loop + case MTA_CARGO_LOAD: cp->loaded_at_xy = data; - /* When cargo is moved into another vehicle you have *always* paid for it */ - cp->paid_for = false; - /* FALL THROUGH */ - case MTA_OTHER: - count -= cp->count; - dest->packets.push_back(cp); + break; + + case MTA_TRANSFER: + payment->PayTransfer(cp, cp->count); + break; + + case MTA_UNLOAD: break; } + count -= cp->count; + dest->packets.push_back(cp); } else { /* Can move only part of the packet, so split it into two pieces */ if (mta != MTA_FINAL_DELIVERY) { @@ -142,11 +148,13 @@ bool CargoList::MoveTo(CargoList *dest, cp_new->days_in_transit = cp->days_in_transit; cp_new->feeder_share = fs; - /* When cargo is moved into another vehicle you have *always* paid for it */ - cp_new->paid_for = (mta == MTA_CARGO_LOAD) ? false : cp->paid_for; cp_new->count = count; dest->packets.push_back(cp_new); + + if (mta == MTA_TRANSFER) payment->PayTransfer(cp_new, count); + } else { + payment->PayFinalDelivery(cp, count); } cp->count -= count; @@ -158,7 +166,7 @@ bool CargoList::MoveTo(CargoList *dest, if (mta == MTA_FINAL_DELIVERY && !tmp.Empty()) { /* There are some packets that could not be delivered at the station, put them back */ - tmp.MoveTo(this, UINT_MAX); + tmp.MoveTo(this, UINT_MAX, MTA_UNLOAD, NULL); tmp.packets.clear(); } @@ -172,7 +180,6 @@ void CargoList::InvalidateCache() { empty = packets.empty(); count = 0; - unpaid_cargo = false; feeder_share = 0; source = INVALID_STATION; days_in_transit = 0; @@ -182,7 +189,6 @@ void CargoList::InvalidateCache() uint dit = 0; for (List::const_iterator it = packets.begin(); it != packets.end(); it++) { count += (*it)->count; - unpaid_cargo |= !(*it)->paid_for; dit += (*it)->days_in_transit * (*it)->count; feeder_share += (*it)->feeder_share; }