Fix #13053: Payment transfers incorrect for non-passenger cargos. (#13054)

CargoPayment required cargo type to be set as state via SetCargo(). This was error prone as CargoPayment is per consist but cargo type can vary per vehicle part. Additionally if SetCargo was not called then the default "uninitialised" state was cargo slot 0, passengers.

Instead of trying to make sure it is set correctly, remove cargo type from CargoPayment and always pass it explicitly to the PayTransfer/PayFinalDelivery methods.
This commit is contained in:
Peter Nelson
2024-11-03 18:53:01 +00:00
committed by GitHub
parent cbde825785
commit a91d889646
6 changed files with 23 additions and 27 deletions

View File

@@ -1231,18 +1231,19 @@ CargoPayment::~CargoPayment()
/**
* Handle payment for final delivery of the given cargo packet.
* @param cargo The cargo type of the cargo.
* @param cp The cargo packet 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, TileIndex current_tile)
void CargoPayment::PayFinalDelivery(CargoID cargo, const CargoPacket *cp, uint count, TileIndex current_tile)
{
if (this->owner == nullptr) {
this->owner = Company::Get(this->front->owner);
}
/* Handle end of route payment */
Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetDistance(current_tile), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID());
Money profit = DeliverGoods(count, cargo, this->current_station, cp->GetDistance(current_tile), cp->GetPeriodsInTransit(), this->owner, cp->GetSourceType(), cp->GetSourceID());
this->route_profit += profit;
/* The vehicle's profit is whatever route profit there is minus feeder shares. */
@@ -1251,12 +1252,13 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count, TileIndex
/**
* Handle payment for transfer of the given cargo packet.
* @param cargo The cargo type of the cargo.
* @param cp The cargo packet to pay for; actual payment won't be made!.
* @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.
*/
Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count, TileIndex current_tile)
Money CargoPayment::PayTransfer(CargoID cargo, 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 */
@@ -1264,7 +1266,7 @@ Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count, TileIndex cur
count,
cp->GetDistance(current_tile),
cp->GetPeriodsInTransit(),
this->ct);
cargo);
profit = profit * _settings_game.economy.feeder_payment_share / 100;
@@ -1304,7 +1306,7 @@ void PrepareUnload(Vehicle *front_v)
HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE),
front_v->last_station_visited, next_station,
front_v->current_order.GetUnloadType(), ge,
front_v->cargo_payment,
v->cargo_type, front_v->cargo_payment,
v->GetCargoTile());
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
}
@@ -1692,9 +1694,6 @@ static void LoadUnloadVehicle(Vehicle *front)
uint amount_unloaded = _settings_game.order.gradual_loading ? std::min(cargo_count, GetLoadAmount(v)) : cargo_count;
bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here?
assert(payment != nullptr);
payment->SetCargo(v->cargo_type);
if (!HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE) && v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER) > 0) {
/* The station does not accept our goods anymore. */
if (front->current_order.GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) {
@@ -1732,7 +1731,8 @@ static void LoadUnloadVehicle(Vehicle *front)
}
}
amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment, v->GetCargoTile());
assert(payment != nullptr);
amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, v->cargo_type, payment, v->GetCargoTile());
remaining = v->cargo.UnloadCount() > 0;
if (amount_unloaded > 0) {
dirty_vehicle = true;