Fix: base cargo payment on load/unload tile, instead of station sign location (#11281)

pull/611/head
Patric Stout 8 months ago committed by GitHub
parent ba67f39db6
commit 9c49a61249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -107,7 +107,7 @@ bool CargoDelivery::operator()(CargoPacket *cp)
{ {
uint remove = this->Preprocess(cp); uint remove = this->Preprocess(cp);
this->source->RemoveFromMeta(cp, VehicleCargoList::MTA_DELIVER, remove); this->source->RemoveFromMeta(cp, VehicleCargoList::MTA_DELIVER, remove);
this->payment->PayFinalDelivery(cp, remove); this->payment->PayFinalDelivery(cp, remove, this->current_tile);
return this->Postprocess(cp, remove); return this->Postprocess(cp, remove);
} }
@ -120,6 +120,7 @@ bool CargoLoad::operator()(CargoPacket *cp)
{ {
CargoPacket *cp_new = this->Preprocess(cp); CargoPacket *cp_new = this->Preprocess(cp);
if (cp_new == nullptr) return false; if (cp_new == nullptr) return false;
cp_new->SetSourceXY(this->current_tile);
this->source->RemoveFromCache(cp_new, cp_new->Count()); this->source->RemoveFromCache(cp_new, cp_new->Count());
this->destination->Append(cp_new, VehicleCargoList::MTA_KEEP); this->destination->Append(cp_new, VehicleCargoList::MTA_KEEP);
return cp_new == cp; return cp_new == cp;
@ -134,6 +135,7 @@ bool CargoReservation::operator()(CargoPacket *cp)
{ {
CargoPacket *cp_new = this->Preprocess(cp); CargoPacket *cp_new = this->Preprocess(cp);
if (cp_new == nullptr) return false; if (cp_new == nullptr) return false;
cp_new->SetSourceXY(this->current_tile);
this->source->reserved_count += cp_new->Count(); this->source->reserved_count += cp_new->Count();
this->source->RemoveFromCache(cp_new, cp_new->Count()); this->source->RemoveFromCache(cp_new, cp_new->Count());
this->destination->Append(cp_new, VehicleCargoList::MTA_LOAD); this->destination->Append(cp_new, VehicleCargoList::MTA_LOAD);

@ -38,10 +38,11 @@ public:
/** Action of final delivery of cargo. */ /** Action of final delivery of cargo. */
class CargoDelivery : public CargoRemoval<VehicleCargoList> { class CargoDelivery : public CargoRemoval<VehicleCargoList> {
protected: protected:
TileIndex current_tile; ///< Current tile cargo delivery is happening.
CargoPayment *payment; ///< Payment object where payments will be registered. CargoPayment *payment; ///< Payment object where payments will be registered.
public: public:
CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment) : CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment, TileIndex current_tile) :
CargoRemoval<VehicleCargoList>(source, max_move), payment(payment) {} CargoRemoval<VehicleCargoList>(source, max_move), current_tile(current_tile), payment(payment) {}
bool operator()(CargoPacket *cp); bool operator()(CargoPacket *cp);
}; };
@ -77,17 +78,19 @@ public:
/** Action of loading cargo from a station onto a vehicle. */ /** Action of loading cargo from a station onto a vehicle. */
class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> { class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
protected:
TileIndex current_tile; ///< Current tile cargo loading is happening.
public: public:
CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move) : CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex current_tile) :
CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move) {} CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), current_tile(current_tile) {}
bool operator()(CargoPacket *cp); bool operator()(CargoPacket *cp);
}; };
/** Action of reserving cargo from a station to be loaded onto a vehicle. */ /** Action of reserving cargo from a station to be loaded onto a vehicle. */
class CargoReservation : public CargoLoad { class CargoReservation : public CargoLoad {
public: public:
CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move) : CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex current_tile) :
CargoLoad(source, destination, max_move) {} CargoLoad(source, destination, max_move, current_tile) {}
bool operator()(CargoPacket *cp); bool operator()(CargoPacket *cp);
}; };

@ -34,15 +34,13 @@ CargoPacket::CargoPacket()
* Creates a new cargo packet. * Creates a new cargo packet.
* *
* @param first_station Source station of the packet. * @param first_station Source station of the packet.
* @param source_xy Source location of the packet.
* @param count Number of cargo entities to put in this packet. * @param count Number of cargo entities to put in this packet.
* @param source_type 'Type' of source the packet comes from (for subsidies). * @param source_type 'Type' of source the packet comes from (for subsidies).
* @param source_id Actual source of the packet (for subsidies). * @param source_id Actual source of the packet (for subsidies).
* @pre count != 0 * @pre count != 0
*/ */
CargoPacket::CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) : CargoPacket::CargoPacket(StationID first_station,uint16_t count, SourceType source_type, SourceID source_id) :
count(count), count(count),
source_xy(source_xy),
source_id(source_id), source_id(source_id),
source_type(source_type), source_type(source_type),
first_station(first_station) first_station(first_station)
@ -431,9 +429,10 @@ void VehicleCargoList::AgeCargo()
* @param order_flags OrderUnloadFlags that will apply to the unload operation. * @param order_flags OrderUnloadFlags that will apply to the unload operation.
* @param ge GoodsEntry for getting the flows. * @param ge GoodsEntry for getting the flows.
* @param payment Payment object for registering transfers. * @param payment Payment object for registering transfers.
* @param current_tile Current tile the cargo handling is happening on.
* return If any cargo will be unloaded. * return If any cargo will be unloaded.
*/ */
bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment) bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile)
{ {
this->AssertCountConsistency(); this->AssertCountConsistency();
assert(this->action_counts[MTA_LOAD] == 0); assert(this->action_counts[MTA_LOAD] == 0);
@ -509,7 +508,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID
case MTA_TRANSFER: case MTA_TRANSFER:
this->packets.push_front(cp); this->packets.push_front(cp);
/* Add feeder share here to allow reusing field for next station. */ /* Add feeder share here to allow reusing field for next station. */
share = payment->PayTransfer(cp, cp->count); share = payment->PayTransfer(cp, cp->count, current_tile);
cp->AddFeederShare(share); cp->AddFeederShare(share);
this->feeder_share += share; this->feeder_share += share;
cp->next_hop = cargo_next; cp->next_hop = cargo_next;
@ -616,9 +615,10 @@ uint VehicleCargoList::Shift(uint max_move, VehicleCargoList *dest)
* @param dest StationCargoList to add transferred cargo to. * @param dest StationCargoList to add transferred cargo to.
* @param max_move Maximum amount of cargo to move. * @param max_move Maximum amount of cargo to move.
* @param payment Payment object to register payments in. * @param payment Payment object to register payments in.
* @param current_tile Current tile the cargo handling is happening on.
* @return Amount of cargo actually unloaded. * @return Amount of cargo actually unloaded.
*/ */
uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPayment *payment) uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile)
{ {
uint moved = 0; uint moved = 0;
if (this->action_counts[MTA_TRANSFER] > 0) { if (this->action_counts[MTA_TRANSFER] > 0) {
@ -628,7 +628,7 @@ uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPaymen
} }
if (this->action_counts[MTA_TRANSFER] == 0 && this->action_counts[MTA_DELIVER] > 0 && moved < max_move) { if (this->action_counts[MTA_TRANSFER] == 0 && this->action_counts[MTA_DELIVER] > 0 && moved < max_move) {
uint move = std::min(this->action_counts[MTA_DELIVER], max_move - moved); uint move = std::min(this->action_counts[MTA_DELIVER], max_move - moved);
this->ShiftCargo(CargoDelivery(this, move, payment)); this->ShiftCargo(CargoDelivery(this, move, payment, current_tile));
moved += move; moved += move;
} }
return moved; return moved;
@ -806,11 +806,12 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_
* @param max_move Maximum amount of cargo to reserve. * @param max_move Maximum amount of cargo to reserve.
* @param dest VehicleCargoList to reserve for. * @param dest VehicleCargoList to reserve for.
* @param next_station Next station(s) the loading vehicle will visit. * @param next_station Next station(s) the loading vehicle will visit.
* @param current_tile Current tile the cargo handling is happening on.
* @return Amount of cargo actually reserved. * @return Amount of cargo actually reserved.
*/ */
uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next_station) uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next_station, TileIndex current_tile)
{ {
return this->ShiftCargo(CargoReservation(this, dest, max_move), next_station, true); return this->ShiftCargo(CargoReservation(this, dest, max_move, current_tile), next_station, true);
} }
/** /**
@ -819,12 +820,13 @@ uint StationCargoList::Reserve(uint max_move, VehicleCargoList *dest, StationIDS
* @param max_move Amount of cargo to load. * @param max_move Amount of cargo to load.
* @param dest Vehicle cargo list where the cargo resides. * @param dest Vehicle cargo list where the cargo resides.
* @param next_station Next station(s) the loading vehicle will visit. * @param next_station Next station(s) the loading vehicle will visit.
* @param current_tile Current tile the cargo handling is happening on.
* @return Amount of cargo actually loaded. * @return Amount of cargo actually loaded.
* @note Vehicles may or may not reserve, depending on their orders. The two * @note Vehicles may or may not reserve, depending on their orders. The two
* modes of loading are exclusive, though. If cargo is reserved we don't * modes of loading are exclusive, though. If cargo is reserved we don't
* need to load unreserved cargo. * need to load unreserved cargo.
*/ */
uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStack next_station) uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStack next_station, TileIndex current_tile)
{ {
uint move = std::min(dest->ActionCount(VehicleCargoList::MTA_LOAD), max_move); uint move = std::min(dest->ActionCount(VehicleCargoList::MTA_LOAD), max_move);
if (move > 0) { if (move > 0) {
@ -832,7 +834,7 @@ uint StationCargoList::Load(uint max_move, VehicleCargoList *dest, StationIDStac
dest->Reassign<VehicleCargoList::MTA_LOAD, VehicleCargoList::MTA_KEEP>(move); dest->Reassign<VehicleCargoList::MTA_LOAD, VehicleCargoList::MTA_KEEP>(move);
return move; return move;
} else { } else {
return this->ShiftCargo(CargoLoad(this, dest, max_move), next_station, true); return this->ShiftCargo(CargoLoad(this, dest, max_move, current_tile), next_station, true);
} }
} }

@ -44,7 +44,7 @@ private:
Money feeder_share{0}; ///< Value of feeder pickup to be paid for on delivery of cargo. Money feeder_share{0}; ///< Value of feeder pickup to be paid for on delivery of cargo.
TileIndex source_xy{0}; ///< The origin of the cargo. TileIndex source_xy{INVALID_TILE}; ///< The origin of the cargo.
SourceID source_id{INVALID_SOURCE}; ///< Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid. SourceID source_id{INVALID_SOURCE}; ///< Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
SourceType source_type{SourceType::Industry}; ///< Type of \c source_id. SourceType source_type{SourceType::Industry}; ///< Type of \c source_id.
@ -62,7 +62,7 @@ public:
static const uint16_t MAX_COUNT = UINT16_MAX; static const uint16_t MAX_COUNT = UINT16_MAX;
CargoPacket(); CargoPacket();
CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id); CargoPacket(StationID first_station, uint16_t count, SourceType source_type, SourceID source_id);
CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share); CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share);
CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original); CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original);
@ -82,6 +82,25 @@ public:
this->next_hop = next_hop; this->next_hop = next_hop;
} }
/**
* Set the origin of the packet.
*
* Can only be set once.
*
* When a packet is created, it is moved to a station. But at that moment
* in time it is not known yet at which tile the cargo will be picked up.
* As this tile is used for payment information, we delay setting the
* source_xy till first pickup.
*
* @param tile Tile the cargo is being picked up from.
*/
void SetSourceXY(TileIndex tile)
{
if (this->source_xy == INVALID_TILE) {
this->source_xy = tile;
}
}
/** /**
* Adds some feeder share to the packet. * Adds some feeder share to the packet.
* @param new_share Feeder share to be added. * @param new_share Feeder share to be added.
@ -161,12 +180,15 @@ public:
} }
/** /**
* Gets the coordinates of the cargo's source. * Get the current distance the cargo has traveled.
* @return Source coordinates of cargo. *
* @param current_tile Current tile of the cargo.
* @return uint The distance (in tiles) traveled.
*/ */
inline TileIndex GetSourceXY() const inline uint GetDistance(TileIndex current_tile) const
{ {
return this->source_xy; assert(this->source_xy != INVALID_TILE);
return DistanceManhattan(this->source_xy, current_tile);
} }
/** /**
@ -386,7 +408,7 @@ public:
void InvalidateCache(); void InvalidateCache();
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment); bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile);
/** /**
* Marks all cargo in the vehicle as to be kept. This is mostly useful for * Marks all cargo in the vehicle as to be kept. This is mostly useful for
@ -406,7 +428,7 @@ public:
template<MoveToAction Tfrom, MoveToAction Tto> template<MoveToAction Tfrom, MoveToAction Tto>
uint Reassign(uint max_move); uint Reassign(uint max_move);
uint Return(uint max_move, StationCargoList *dest, StationID next_station); uint Return(uint max_move, StationCargoList *dest, StationID next_station);
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment); uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile);
uint Shift(uint max_move, VehicleCargoList *dest); uint Shift(uint max_move, VehicleCargoList *dest);
uint Truncate(uint max_move = UINT_MAX); uint Truncate(uint max_move = UINT_MAX);
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge); uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
@ -423,6 +445,7 @@ public:
return cp1->source_xy == cp2->source_xy && return cp1->source_xy == cp2->source_xy &&
cp1->periods_in_transit == cp2->periods_in_transit && cp1->periods_in_transit == cp2->periods_in_transit &&
cp1->source_type == cp2->source_type && cp1->source_type == cp2->source_type &&
cp1->first_station == cp2->first_station &&
cp1->source_id == cp2->source_id; cp1->source_id == cp2->source_id;
} }
}; };
@ -520,8 +543,8 @@ public:
* amount of cargo to be moved. Second parameter is destination (if * amount of cargo to be moved. Second parameter is destination (if
* applicable), return value is amount of cargo actually moved. */ * applicable), return value is amount of cargo actually moved. */
uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next); uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile);
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next); uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile);
uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr); uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr);
uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge); uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
@ -537,6 +560,7 @@ public:
return cp1->source_xy == cp2->source_xy && return cp1->source_xy == cp2->source_xy &&
cp1->periods_in_transit == cp2->periods_in_transit && cp1->periods_in_transit == cp2->periods_in_transit &&
cp1->source_type == cp2->source_type && cp1->source_type == cp2->source_type &&
cp1->first_station == cp2->first_station &&
cp1->source_id == cp2->source_id; cp1->source_id == cp2->source_id;
} }
}; };

@ -1096,7 +1096,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
* @param num_pieces amount of cargo delivered * @param num_pieces amount of cargo delivered
* @param cargo_type the type of cargo that is delivered * @param cargo_type the type of cargo that is delivered
* @param dest Station the cargo has been unloaded * @param dest Station the cargo has been unloaded
* @param source_tile The origin of the cargo for distance calculation * @param distance The distance the cargo has traveled.
* @param periods_in_transit Travel time in cargo aging periods * @param periods_in_transit Travel time in cargo aging periods
* @param company The company delivering the cargo * @param company The company delivering the cargo
* @param src_type Type of source of cargo (industry, town, headquarters) * @param src_type Type of source of cargo (industry, town, headquarters)
@ -1104,7 +1104,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
* @return Revenue for delivering cargo * @return Revenue for delivering cargo
* @note The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery * @note The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery
*/ */
static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, TileIndex source_tile, uint16_t periods_in_transit, Company *company, SourceType src_type, SourceID src) static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, uint distance, uint16_t periods_in_transit, Company *company, SourceType src_type, SourceID src)
{ {
assert(num_pieces > 0); assert(num_pieces > 0);
@ -1131,7 +1131,7 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, Ti
st->town->received[cs->town_effect].new_act += accepted_total; st->town->received[cs->town_effect].new_act += accepted_total;
/* Determine profit */ /* Determine profit */
Money profit = GetTransportedGoodsIncome(accepted_total, DistanceManhattan(source_tile, st->xy), periods_in_transit, cargo_type); Money profit = GetTransportedGoodsIncome(accepted_total, distance, periods_in_transit, cargo_type);
/* Update the cargo monitor. */ /* Update the cargo monitor. */
AddCargoDelivery(cargo_type, company->index, accepted_total - accepted_ind, src_type, src, st); AddCargoDelivery(cargo_type, company->index, accepted_total - accepted_ind, src_type, src, st);
@ -1225,15 +1225,16 @@ CargoPayment::~CargoPayment()
* Handle payment for final delivery of the given cargo packet. * Handle payment for final delivery of the given cargo packet.
* @param cp The cargo packet to pay for. * @param cp The cargo packet to pay for.
* @param count The number of packets to pay for. * @param count The number of packets to pay for.
* @param current_tile Current tile the payment is happening on.
*/ */
void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count) void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count, TileIndex current_tile)
{ {
if (this->owner == nullptr) { if (this->owner == nullptr) {
this->owner = Company::Get(this->front->owner); this->owner = Company::Get(this->front->owner);
} }
/* Handle end of route payment */ /* Handle end of route payment */
Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetSourceXY(), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID()); Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetDistance(current_tile), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID());
this->route_profit += profit; this->route_profit += profit;
/* The vehicle's profit is whatever route profit there is minus feeder shares. */ /* The vehicle's profit is whatever route profit there is minus feeder shares. */
@ -1244,15 +1245,16 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
* Handle payment for transfer of the given cargo packet. * Handle payment for transfer of the given cargo packet.
* @param cp The cargo packet to pay for; actual payment won't be made!. * @param cp The cargo packet to pay for; actual payment won't be made!.
* @param count The number of packets to pay for. * @param count The number of packets to pay for.
* @param current_tile Current tile the payment is happening on.
* @return The amount of money paid for the transfer. * @return The amount of money paid for the transfer.
*/ */
Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count) Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count, TileIndex current_tile)
{ {
/* Pay transfer vehicle the difference between the payment for the journey from
* the source to the current point, and the sum of the previous transfer payments */
Money profit = -cp->GetFeederShare(count) + GetTransportedGoodsIncome( Money profit = -cp->GetFeederShare(count) + GetTransportedGoodsIncome(
count, count,
/* pay transfer vehicle the difference between the payment for the journey from cp->GetDistance(current_tile),
* the source to the current point, and the sum of the previous transfer payments */
DistanceManhattan(cp->GetSourceXY(), Station::Get(this->current_station)->xy),
cp->GetPeriodsInTransit(), cp->GetPeriodsInTransit(),
this->ct); this->ct);
@ -1294,7 +1296,8 @@ void PrepareUnload(Vehicle *front_v)
HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE), HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE),
front_v->last_station_visited, next_station, front_v->last_station_visited, next_station,
front_v->current_order.GetUnloadType(), ge, front_v->current_order.GetUnloadType(), ge,
front_v->cargo_payment); front_v->cargo_payment,
v->tile);
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING); if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
} }
} }
@ -1469,7 +1472,7 @@ struct FinalizeRefitAction
{ {
if (this->do_reserve) { if (this->do_reserve) {
this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), this->st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, this->next_station); &v->cargo, this->next_station, v->tile);
} }
this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount(); this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount();
return true; return true;
@ -1560,7 +1563,7 @@ struct ReserveCargoAction {
{ {
if (v->cargo_cap > v->cargo.RemainingCount() && MayLoadUnderExclusiveRights(st, v)) { if (v->cargo_cap > v->cargo.RemainingCount() && MayLoadUnderExclusiveRights(st, v)) {
st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), st->goods[v->cargo_type].cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(),
&v->cargo, *next_station); &v->cargo, *next_station, v->tile);
} }
return true; return true;
@ -1721,7 +1724,7 @@ static void LoadUnloadVehicle(Vehicle *front)
} }
} }
amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment); amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment, v->tile);
remaining = v->cargo.UnloadCount() > 0; remaining = v->cargo.UnloadCount() > 0;
if (amount_unloaded > 0) { if (amount_unloaded > 0) {
dirty_vehicle = true; dirty_vehicle = true;
@ -1791,7 +1794,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO); if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
if (_settings_game.order.gradual_loading) cap_left = std::min(cap_left, GetLoadAmount(v)); if (_settings_game.order.gradual_loading) cap_left = std::min(cap_left, GetLoadAmount(v));
uint loaded = ge->cargo.Load(cap_left, &v->cargo, next_station); uint loaded = ge->cargo.Load(cap_left, &v->cargo, next_station, v->tile);
if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) { if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
/* Remember if there are reservations left so that we don't stop /* Remember if there are reservations left so that we don't stop
* loading before they're loaded. */ * loading before they're loaded. */

@ -37,8 +37,8 @@ struct CargoPayment : CargoPaymentPool::PoolItem<&_cargo_payment_pool> {
CargoPayment(Vehicle *front); CargoPayment(Vehicle *front);
~CargoPayment(); ~CargoPayment();
Money PayTransfer(const CargoPacket *cp, uint count); Money PayTransfer(const CargoPacket *cp, uint count, TileIndex current_tile);
void PayFinalDelivery(const CargoPacket *cp, uint count); void PayFinalDelivery(const CargoPacket *cp, uint count, TileIndex current_tile);
/** /**
* Sets the currently handled cargo type. * Sets the currently handled cargo type.

@ -4039,7 +4039,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
if (amount == 0) return 0; if (amount == 0) return 0;
StationID next = ge.GetVia(st->index); StationID next = ge.GetVia(st->index);
ge.cargo.Append(new CargoPacket(st->index, st->xy, amount, source_type, source_id), next); ge.cargo.Append(new CargoPacket(st->index, amount, source_type, source_id), next);
LinkGraph *lg = nullptr; LinkGraph *lg = nullptr;
if (ge.link_graph == INVALID_LINK_GRAPH) { if (ge.link_graph == INVALID_LINK_GRAPH) {
if (LinkGraph::CanAllocateItem()) { if (LinkGraph::CanAllocateItem()) {

Loading…
Cancel
Save