From 30172fc03784cd6251602d81d4e0a85b0198ef5c Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 9 Sep 2023 23:21:21 +0200 Subject: [PATCH] Codechange: cleanup CargoPacket in terms of variable/function names (#11278) Over the years, things got reused and changed, making the current names somewhat unclear in what they actually mean and do. --- src/aircraft_gui.cpp | 4 +- src/cargoaction.cpp | 8 +-- src/cargopacket.cpp | 70 +++++++++++++------------- src/cargopacket.h | 71 +++++++++++++++------------ src/economy.cpp | 10 ++-- src/newgrf_engine.cpp | 2 +- src/newgrf_station.cpp | 2 +- src/roadveh_gui.cpp | 8 +-- src/saveload/cargopacket_sl.cpp | 8 +-- src/script/api/script_station.cpp | 2 +- src/script/api/script_stationlist.cpp | 4 +- src/ship_gui.cpp | 4 +- src/station_gui.cpp | 8 +-- src/train_gui.cpp | 4 +- 14 files changed, 106 insertions(+), 99 deletions(-) diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index 4192fd2473..1e7c8e62c1 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -56,10 +56,10 @@ void DrawAircraftDetails(const Aircraft *v, const Rect &r) /* Cargo names (fix pluralness) */ SetDParam(0, u->cargo_type); SetDParam(1, cargo_count); - SetDParam(2, u->cargo.Source()); + SetDParam(2, u->cargo.GetFirstStation()); DrawString(r.left, r.right, y, STR_VEHICLE_DETAILS_CARGO_FROM); y += FONT_HEIGHT_NORMAL; - feeder_share += u->cargo.FeederShare(); + feeder_share += u->cargo.GetFeederShare(); } } } diff --git a/src/cargoaction.cpp b/src/cargoaction.cpp index a1263a3014..8601ba81c8 100644 --- a/src/cargoaction.cpp +++ b/src/cargoaction.cpp @@ -167,7 +167,7 @@ bool CargoTransfer::operator()(CargoPacket *cp) if (cp_new == nullptr) return false; this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count()); /* No transfer credits here as they were already granted during Stage(). */ - this->destination->Append(cp_new, cp_new->NextStation()); + this->destination->Append(cp_new, cp_new->GetNextStation()); return cp_new == cp; } @@ -194,7 +194,7 @@ bool StationCargoReroute::operator()(CargoPacket *cp) { CargoPacket *cp_new = this->Preprocess(cp); if (cp_new == nullptr) cp_new = cp; - StationID next = this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2); + StationID next = this->ge->GetVia(cp_new->GetFirstStation(), this->avoid, this->avoid2); assert(next != this->avoid && next != this->avoid2); if (this->source != this->destination) { this->source->RemoveFromCache(cp_new, cp_new->Count()); @@ -217,8 +217,8 @@ bool VehicleCargoReroute::operator()(CargoPacket *cp) { CargoPacket *cp_new = this->Preprocess(cp); if (cp_new == nullptr) cp_new = cp; - if (cp_new->NextStation() == this->avoid || cp_new->NextStation() == this->avoid2) { - cp->SetNextStation(this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2)); + if (cp_new->GetNextStation() == this->avoid || cp_new->GetNextStation() == this->avoid2) { + cp->SetNextStation(this->ge->GetVia(cp_new->GetFirstStation(), this->avoid, this->avoid2)); } if (this->source != this->destination) { this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count()); diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 5718ac86a5..592940d25b 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -32,23 +32,21 @@ CargoPacket::CargoPacket() /** * Creates a new cargo packet. - * @param source 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 source_type 'Type' of source the packet comes from (for subsidies). - * @param source_id Actual source of the packet (for subsidies). + * @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 source_type 'Type' of source the packet comes from (for subsidies). + * @param source_id Actual source of the packet (for subsidies). * @pre count != 0 * @note We have to zero memory ourselves here because we are using a 'new' * that, in contrary to all other pools, does not memset to 0. */ -CargoPacket::CargoPacket(StationID source, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) : +CargoPacket::CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id) : count(count), - periods_in_transit(0), - feeder_share(0), source_xy(source_xy), source_id(source_id), - source(source), - source_type(source_type) + source_type(source_type), + first_station(first_station) { assert(count != 0); } @@ -56,24 +54,24 @@ CargoPacket::CargoPacket(StationID source, TileIndex source_xy, uint16_t count, /** * Creates a new cargo packet. Initializes the fields that cannot be changed later. * Used when loading or splitting packets. - * @param count Number of cargo entities to put in this packet. + * @param count Number of cargo entities to put in this packet. * @param periods_in_transit Number of cargo aging periods the cargo has been in transit. - * @param source Station the cargo was initially loaded. - * @param source_xy Station location the cargo was initially loaded. - * @param feeder_share Feeder share the packet has already accumulated. - * @param source_type 'Type' of source the packet comes from (for subsidies). - * @param source_id Actual source of the packet (for subsidies). + * @param first_station Station the cargo was initially loaded. + * @param source_xy Station location the cargo was initially loaded. + * @param feeder_share Feeder share the packet has already accumulated. + * @param source_type 'Type' of source the packet comes from (for subsidies). + * @param source_id Actual source of the packet (for subsidies). * @note We have to zero memory ourselves here because we are using a 'new' * that, in contrary to all other pools, does not memset to 0. */ -CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID source, TileIndex source_xy, Money feeder_share, SourceType source_type, SourceID source_id) : +CargoPacket::CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share, SourceType source_type, SourceID source_id) : count(count), periods_in_transit(periods_in_transit), feeder_share(feeder_share), source_xy(source_xy), source_id(source_id), - source(source), - source_type(source_type) + source_type(source_type), + first_station(first_station) { assert(count != 0); } @@ -87,8 +85,8 @@ CargoPacket *CargoPacket::Split(uint new_size) { if (!CargoPacket::CanAllocateItem()) return nullptr; - Money fs = this->FeederShare(new_size); - CargoPacket *cp_new = new CargoPacket(new_size, this->periods_in_transit, this->source, this->source_xy, fs, this->source_type, this->source_id); + Money fs = this->GetFeederShare(new_size); + CargoPacket *cp_new = new CargoPacket(new_size, this->periods_in_transit, this->first_station, this->source_xy, fs, this->source_type, this->source_id); this->feeder_share -= fs; this->count -= new_size; return cp_new; @@ -112,7 +110,7 @@ void CargoPacket::Merge(CargoPacket *cp) void CargoPacket::Reduce(uint count) { assert(count < this->count); - this->feeder_share -= this->FeederShare(count); + this->feeder_share -= this->GetFeederShare(count); this->count -= count; } @@ -135,7 +133,7 @@ void CargoPacket::Reduce(uint count) /* static */ void CargoPacket::InvalidateAllFrom(StationID sid) { for (CargoPacket *cp : CargoPacket::Iterate()) { - if (cp->source == sid) cp->source = INVALID_STATION; + if (cp->first_station == sid) cp->first_station = INVALID_STATION; } } @@ -176,7 +174,7 @@ template void CargoList::RemoveFromCache(const CargoPacket *cp, uint count) { assert(count <= cp->count); - this->count -= count; + this->count -= count; this->cargo_periods_in_transit -= static_cast(cp->periods_in_transit) * count; } @@ -188,7 +186,7 @@ void CargoList::RemoveFromCache(const CargoPacket *cp, uint count) template void CargoList::AddToCache(const CargoPacket *cp) { - this->count += cp->count; + this->count += cp->count; this->cargo_periods_in_transit += static_cast(cp->periods_in_transit) * cp->count; } @@ -329,7 +327,7 @@ void VehicleCargoList::PopCargo(Taction action) */ void VehicleCargoList::RemoveFromCache(const CargoPacket *cp, uint count) { - this->feeder_share -= cp->FeederShare(count); + this->feeder_share -= cp->GetFeederShare(count); this->Parent::RemoveFromCache(cp, count); } @@ -399,7 +397,7 @@ void VehicleCargoList::AgeCargo() StationID current_station, bool accepted, StationIDStack next_station) { if (cargo_next == INVALID_STATION) { - return (accepted && cp->source != current_station) ? MTA_DELIVER : MTA_KEEP; + return (accepted && cp->first_station != current_station) ? MTA_DELIVER : MTA_KEEP; } else if (cargo_next == current_station) { return MTA_DELIVER; } else if (next_station.Contains(cargo_next)) { @@ -443,13 +441,13 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID MoveToAction action = MTA_LOAD; if (force_keep) { action = MTA_KEEP; - } else if (force_unload && accepted && cp->source != current_station) { + } else if (force_unload && accepted && cp->first_station != current_station) { action = MTA_DELIVER; } else if (force_transfer) { action = MTA_TRANSFER; /* We cannot send the cargo to any of the possible next hops and * also not to the current station. */ - FlowStatMap::const_iterator flow_it(ge->flows.find(cp->source)); + FlowStatMap::const_iterator flow_it(ge->flows.find(cp->first_station)); if (flow_it == ge->flows.end()) { cargo_next = INVALID_STATION; } else { @@ -468,11 +466,11 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID } else { /* Rewrite an invalid source station to some random other one to * avoid keeping the cargo in the vehicle forever. */ - if (cp->source == INVALID_STATION && !ge->flows.empty()) { - cp->source = ge->flows.begin()->first; + if (cp->first_station == INVALID_STATION && !ge->flows.empty()) { + cp->first_station = ge->flows.begin()->first; } bool restricted = false; - FlowStatMap::const_iterator flow_it(ge->flows.find(cp->source)); + FlowStatMap::const_iterator flow_it(ge->flows.find(cp->first_station)); if (flow_it == ge->flows.end()) { cargo_next = INVALID_STATION; } else { @@ -757,7 +755,7 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_ CargoPacket *cp = *it; if (prev_count > max_move && RandomRange(prev_count) < prev_count - max_move) { if (do_count && loop == 0) { - (*cargo_per_source)[cp->source] += cp->count; + (*cargo_per_source)[cp->first_station] += cp->count; } ++it; continue; @@ -770,16 +768,16 @@ uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_ moved += diff; } if (loop > 0) { - if (do_count) (*cargo_per_source)[cp->source] -= diff; + if (do_count) (*cargo_per_source)[cp->first_station] -= diff; return moved; } else { - if (do_count) (*cargo_per_source)[cp->source] += cp->count; + if (do_count) (*cargo_per_source)[cp->first_station] += cp->count; ++it; } } else { it = this->packets.erase(it); if (do_count && loop > 0) { - (*cargo_per_source)[cp->source] -= cp->count; + (*cargo_per_source)[cp->first_station] -= cp->count; } moved += cp->count; this->RemoveFromCache(cp, cp->count); diff --git a/src/cargopacket.h b/src/cargopacket.h index 3cc46a9446..12b8babbe9 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -39,14 +39,17 @@ extern SaveLoadTable GetCargoPacketDesc(); */ struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> { private: - uint16_t count; ///< The amount of cargo in this packet. - uint16_t periods_in_transit; ///< Amount of cargo aging periods this packet has been in transit. - Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo. - TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain). - StationID next_station; ///< Station where the cargo wants to go next. - SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid. - StationID source; ///< The station where the cargo came from first. - SourceType source_type; ///< Type of \c source_id. + uint16_t count{0}; ///< The amount of cargo in this packet. + uint16_t periods_in_transit{0}; ///< Amount of cargo aging periods this packet has been in transit. + + 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. + 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. + + StationID first_station{INVALID_STATION}; ///< The station where the cargo came from first. + StationID next_station{INVALID_STATION}; ///< Station where the cargo wants to go next. /** The CargoList caches, thus needs to know about it. */ template friend class CargoList; @@ -59,7 +62,7 @@ public: static const uint16_t MAX_COUNT = UINT16_MAX; CargoPacket(); - CargoPacket(StationID source, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id); + CargoPacket(StationID first_station, TileIndex source_xy, uint16_t count, SourceType source_type, SourceID source_id); CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID source, TileIndex source_xy, Money feeder_share = 0, SourceType source_type = SourceType::Industry, SourceID source_id = INVALID_SOURCE); /** Destroy the packet. */ @@ -73,13 +76,19 @@ public: * Sets the station where the packet is supposed to go next. * @param next_station Next station the packet should go to. */ - void SetNextStation(StationID next_station) { this->next_station = next_station; } + void SetNextStation(StationID next_station) + { + this->next_station = next_station; + } /** * Adds some feeder share to the packet. * @param new_share Feeder share to be added. */ - void AddFeederShare(Money new_share) { this->feeder_share += new_share; } + void AddFeederShare(Money new_share) + { + this->feeder_share += new_share; + } /** * Gets the number of 'items' in this packet. @@ -95,7 +104,7 @@ public: * the feeder chain. * @return Feeder share. */ - inline Money FeederShare() const + inline Money GetFeederShare() const { return this->feeder_share; } @@ -106,7 +115,7 @@ public: * @param part Amount of cargo to get the share for. * @return Feeder share for the given amount of cargo. */ - inline Money FeederShare(uint part) const + inline Money GetFeederShare(uint part) const { return this->feeder_share * part / static_cast(this->count); } @@ -118,7 +127,7 @@ public: * value is capped at UINT16_MAX. * @return Length this cargo has been in transit. */ - inline uint16_t PeriodsInTransit() const + inline uint16_t GetPeriodsInTransit() const { return this->periods_in_transit; } @@ -127,7 +136,7 @@ public: * Gets the type of the cargo's source. industry, town or head quarter. * @return Source type. */ - inline SourceType SourceSubsidyType() const + inline SourceType GetSourceType() const { return this->source_type; } @@ -136,7 +145,7 @@ public: * Gets the ID of the cargo's source. An IndustryID, TownID or CompanyID. * @return Source ID. */ - inline SourceID SourceSubsidyID() const + inline SourceID GetSourceID() const { return this->source_id; } @@ -145,16 +154,16 @@ public: * Gets the ID of the station where the cargo was loaded for the first time. * @return StationID. */ - inline StationID SourceStation() const + inline StationID GetFirstStation() const { - return this->source; + return this->first_station; } /** - * Gets the coordinates of the cargo's source station. - * @return Source station's coordinates. + * Gets the coordinates of the cargo's source. + * @return Source coordinates of cargo. */ - inline TileIndex SourceStationXY() const + inline TileIndex GetSourceXY() const { return this->source_xy; } @@ -163,7 +172,7 @@ public: * Gets the ID of station the cargo wants to go next. * @return Next station for this packets. */ - inline StationID NextStation() const + inline StationID GetNextStation() const { return this->next_station; } @@ -297,19 +306,19 @@ public: friend class VehicleCargoReroute; /** - * Returns source of the first cargo packet in this list. - * @return The before mentioned source. + * Returns the first station of the first cargo packet in this list. + * @return The before mentioned station. */ - inline StationID Source() const + inline StationID GetFirstStation() const { - return this->count == 0 ? INVALID_STATION : this->packets.front()->source; + return this->count == 0 ? INVALID_STATION : this->packets.front()->first_station; } /** * Returns total sum of the feeder share for all packets. * @return The before mentioned number. */ - inline Money FeederShare() const + inline Money GetFeederShare() const { return this->feeder_share; } @@ -469,12 +478,12 @@ public: } /** - * Returns source of the first cargo packet in this list. - * @return The before mentioned source. + * Returns first station of the first cargo packet in this list. + * @return The before mentioned station. */ - inline StationID Source() const + inline StationID GetFirstStation() const { - return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->source; + return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->first_station; } /** diff --git a/src/economy.cpp b/src/economy.cpp index b2bad75ceb..1dce13e603 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1233,11 +1233,11 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count) } /* Handle end of route payment */ - Money profit = DeliverGoods(count, this->ct, this->current_station, cp->SourceStationXY(), cp->PeriodsInTransit(), this->owner, cp->SourceSubsidyType(), cp->SourceSubsidyID()); + Money profit = DeliverGoods(count, this->ct, this->current_station, cp->GetSourceXY(), 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. */ - this->visual_profit += profit - cp->FeederShare(count); + this->visual_profit += profit - cp->GetFeederShare(count); } /** @@ -1248,12 +1248,12 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count) */ Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count) { - Money profit = -cp->FeederShare(count) + GetTransportedGoodsIncome( + Money profit = -cp->GetFeederShare(count) + GetTransportedGoodsIncome( count, /* 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 */ - DistanceManhattan(cp->SourceStationXY(), Station::Get(this->current_station)->xy), - cp->PeriodsInTransit(), + DistanceManhattan(cp->GetSourceXY(), Station::Get(this->current_station)->xy), + cp->GetPeriodsInTransit(), this->ct); profit = profit * _settings_game.economy.feeder_payment_share / 100; diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index d0e9685df9..15464e5262 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -823,7 +823,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec case 0x3B: return GB(v->cargo_cap, 8, 8); case 0x3C: return ClampTo(v->cargo.StoredCount()); case 0x3D: return GB(ClampTo(v->cargo.StoredCount()), 8, 8); - case 0x3E: return v->cargo.Source(); + case 0x3E: return v->cargo.GetFirstStation(); case 0x3F: return ClampTo(v->cargo.PeriodsInTransit()); case 0x40: return ClampTo(v->age); case 0x41: return GB(ClampTo(v->age), 8, 8); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 560bd29f93..cf9ddd9817 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -445,7 +445,7 @@ uint32_t Station::GetNewGRFVariable(const ResolverObject &object, byte variable, case 1: return GB(std::min(g->cargo.TotalCount(), 4095u), 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7); case 2: return g->time_since_pickup; case 3: return g->rating; - case 4: return g->cargo.Source(); + case 4: return g->cargo.GetFirstStation(); case 5: return g->cargo.PeriodsInTransit(); case 6: return g->last_speed; case 7: return g->last_age; diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 7c5cdb76b3..301b0c90a7 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -81,9 +81,9 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r) if (u->cargo.StoredCount() > 0) { SetDParam(0, u->cargo_type); SetDParam(1, u->cargo.StoredCount()); - SetDParam(2, u->cargo.Source()); + SetDParam(2, u->cargo.GetFirstStation()); str = STR_VEHICLE_DETAILS_CARGO_FROM; - feeder_share += u->cargo.FeederShare(); + feeder_share += u->cargo.GetFeederShare(); } DrawString(r.left, r.right, y, str); y += FONT_HEIGHT_NORMAL; @@ -100,9 +100,9 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r) if (v->cargo.StoredCount() > 0) { SetDParam(0, v->cargo_type); SetDParam(1, v->cargo.StoredCount()); - SetDParam(2, v->cargo.Source()); + SetDParam(2, v->cargo.GetFirstStation()); str = STR_VEHICLE_DETAILS_CARGO_FROM; - feeder_share += v->cargo.FeederShare(); + feeder_share += v->cargo.GetFeederShare(); } DrawString(r.left, r.right, y, str); y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal; diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp index 40fb25fe68..0332b8a4b9 100644 --- a/src/saveload/cargopacket_sl.cpp +++ b/src/saveload/cargopacket_sl.cpp @@ -33,7 +33,7 @@ const CargoPacketList *packets = v->cargo.Packets(); for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) { CargoPacket *cp = *it; - cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile; + cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : v->tile; } } @@ -49,7 +49,7 @@ const StationCargoPacketMap *packets = ge->cargo.Packets(); for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) { CargoPacket *cp = *it; - cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy; + cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : st->xy; } } } @@ -58,7 +58,7 @@ if (IsSavegameVersionBefore(SLV_120)) { /* CargoPacket's source should be either INVALID_STATION or a valid station */ for (CargoPacket *cp : CargoPacket::Iterate()) { - if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION; + if (!Station::IsValidID(cp->first_station)) cp->first_station = INVALID_STATION; } } @@ -86,7 +86,7 @@ SaveLoadTable GetCargoPacketDesc() { static const SaveLoad _cargopacket_desc[] = { - SLE_VAR(CargoPacket, source, SLE_UINT16), + SLE_VARNAME(CargoPacket, first_station, "source", SLE_UINT16), SLE_VAR(CargoPacket, source_xy, SLE_UINT32), SLE_VAR(CargoPacket, count, SLE_UINT16), SLE_CONDVARNAME(CargoPacket, periods_in_transit, "days_in_transit", SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_MORE_CARGO_AGE), diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp index ed153a4605..83bfde2958 100644 --- a/src/script/api/script_station.cpp +++ b/src/script/api/script_station.cpp @@ -69,7 +69,7 @@ template StationCargoList::ConstIterator(cargo_list.Packets()->end())); for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) { const CargoPacket *cp = *it; - if (!Tfrom || cp->SourceStation() == from_station_id) cargo_count += cp->Count(); + if (!Tfrom || cp->GetFirstStation() == from_station_id) cargo_count += cp->Count(); } return cargo_count; diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp index 5ccb6a0609..dd254f19cb 100644 --- a/src/script/api/script_stationlist.cpp +++ b/src/script/api/script_stationlist.cpp @@ -179,7 +179,7 @@ void ScriptStationList_CargoWaiting::Add(StationID station_id, CargoID cargo, St StationCargoList::ConstIterator iter = collector.GE()->cargo.Packets()->begin(); StationCargoList::ConstIterator end = collector.GE()->cargo.Packets()->end(); for (; iter != end; ++iter) { - collector.Update((*iter)->SourceStation(), iter.GetKey(), (*iter)->Count()); + collector.Update((*iter)->GetFirstStation(), iter.GetKey(), (*iter)->Count()); } } @@ -218,7 +218,7 @@ ScriptStationList_CargoWaitingViaByFrom::ScriptStationList_CargoWaitingViaByFrom std::pair range = collector.GE()->cargo.Packets()->equal_range(via); for (StationCargoList::ConstIterator iter = range.first; iter != range.second; ++iter) { - collector.Update((*iter)->SourceStation(), iter.GetKey(), (*iter)->Count()); + collector.Update((*iter)->GetFirstStation(), iter.GetKey(), (*iter)->Count()); } } diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp index d5991c9b93..7ff8ac20c8 100644 --- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -79,13 +79,13 @@ void DrawShipDetails(const Vehicle *v, const Rect &r) if (v->cargo.StoredCount() > 0) { SetDParam(0, v->cargo_type); SetDParam(1, v->cargo.StoredCount()); - SetDParam(2, v->cargo.Source()); + SetDParam(2, v->cargo.GetFirstStation()); str = STR_VEHICLE_DETAILS_CARGO_FROM; } DrawString(r.left, r.right, y, str); y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal; /* Draw Transfer credits text */ - SetDParam(0, v->cargo.FeederShare()); + SetDParam(0, v->cargo.GetFeederShare()); DrawString(r.left, r.right, y, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE); } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 1411f9a60e..87f64167f5 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1591,15 +1591,15 @@ struct StationViewWindow : public Window { const CargoPacket *cp = *it; StationID next = it.GetKey(); - const CargoDataEntry *source_entry = source_dest->Retrieve(cp->SourceStation()); + const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation()); if (source_entry == nullptr) { - this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count()); + this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count()); continue; } const CargoDataEntry *via_entry = source_entry->Retrieve(next); if (via_entry == nullptr) { - this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count()); + this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count()); continue; } @@ -1620,7 +1620,7 @@ struct StationViewWindow : public Window { val = std::min(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount())); remaining -= val; } - this->ShowCargo(cargo, i, cp->SourceStation(), next, dest_entry->GetStation(), val); + this->ShowCargo(cargo, i, cp->GetFirstStation(), next, dest_entry->GetStation(), val); } } this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount()); diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 00d2703e55..fc2a8b1583 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -291,7 +291,7 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *su item->capacity += v->cargo_cap; item->amount += v->cargo.StoredCount(); - if (item->source == INVALID_STATION) item->source = v->cargo.Source(); + if (item->source == INVALID_STATION) item->source = v->cargo.GetFirstStation(); } while ((v = v->Next()) != nullptr && v->IsArticulatedPart()); } @@ -440,7 +440,7 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t v for (const Vehicle *u = v; u != nullptr; u = u->Next()) { act_cargo[u->cargo_type] += u->cargo.StoredCount(); max_cargo[u->cargo_type] += u->cargo_cap; - feeder_share += u->cargo.FeederShare(); + feeder_share += u->cargo.GetFeederShare(); } /* draw total cargo tab */