1
0
Fork 0

Codechange: Remove owner from CargoPayment. (#14411)

Owner can instead be looked up from the CargoPayment's vehicle.

This reduces the size of each CargoPayment slightly.
pull/14392/head
Peter Nelson 2025-07-03 23:11:12 +01:00 committed by GitHub
parent febba930b0
commit 16b0371c1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 10 deletions

View File

@ -466,9 +466,6 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
auto &unitidgen = new_company->freeunits[v->type]; auto &unitidgen = new_company->freeunits[v->type];
v->unitnumber = unitidgen.UseID(unitidgen.NextID()); v->unitnumber = unitidgen.UseID(unitidgen.NextID());
} }
/* Invalidate the vehicle's cargo payment "owner cache". */
if (v->cargo_payment != nullptr) v->cargo_payment->owner = nullptr;
} }
} }
@ -1218,12 +1215,8 @@ CargoPayment::~CargoPayment()
*/ */
void CargoPayment::PayFinalDelivery(CargoType cargo, const CargoPacket *cp, uint count, TileIndex current_tile) void CargoPayment::PayFinalDelivery(CargoType 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 */ /* Handle end of route payment */
Money profit = DeliverGoods(count, cargo, this->current_station, cp->GetDistance(current_tile), cp->GetPeriodsInTransit(), this->owner, cp->GetSource()); Money profit = DeliverGoods(count, cargo, this->current_station, cp->GetDistance(current_tile), cp->GetPeriodsInTransit(), Company::Get(this->front->owner), cp->GetSource());
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. */

View File

@ -11,7 +11,6 @@
#define ECONOMY_BASE_H #define ECONOMY_BASE_H
#include "cargopacket.h" #include "cargopacket.h"
#include "company_type.h"
/** Type of pool to store cargo payments in; little over 1 million. */ /** Type of pool to store cargo payments in; little over 1 million. */
using CargoPaymentPool = Pool<CargoPayment, CargoPaymentID, 512>; using CargoPaymentPool = Pool<CargoPayment, CargoPaymentID, 512>;
@ -24,7 +23,6 @@ extern CargoPaymentPool _cargo_payment_pool;
struct CargoPayment : CargoPaymentPool::PoolItem<&_cargo_payment_pool> { struct CargoPayment : CargoPaymentPool::PoolItem<&_cargo_payment_pool> {
/* CargoPaymentID index member of CargoPaymentPool is 4 bytes. */ /* CargoPaymentID index member of CargoPaymentPool is 4 bytes. */
StationID current_station = StationID::Invalid(); ///< NOSAVE: The current station StationID current_station = StationID::Invalid(); ///< NOSAVE: The current station
Company *owner = nullptr; ///< NOSAVE: The owner of the vehicle
Vehicle *front = nullptr; ///< The front vehicle to do the payment of Vehicle *front = nullptr; ///< The front vehicle to do the payment of
Money route_profit = 0; ///< The amount of money to add/remove from the bank account Money route_profit = 0; ///< The amount of money to add/remove from the bank account