From e613107e02c5eb99532452811e8b9341199ceb29 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 18 Oct 2009 17:53:34 +0000 Subject: (svn r17808) -Codechange: remove write 'access' from all of CargoPacket's variables --- src/cargopacket.h | 64 ++++++++++++++++++++++++++++++++++++++++++++--------- src/economy.cpp | 4 ++-- src/station_gui.cpp | 6 ++--- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/cargopacket.h b/src/cargopacket.h index 72eceac8d..471f7a7d0 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -37,11 +37,14 @@ extern const struct SaveLoad *GetCargoPacketDesc(); */ struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> { private: - /* Variables used by the CargoList cache. Only let them be modified via - * the proper accessor functions and/or CargoList itself. */ - Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo - uint16 count; ///< The amount of cargo in this packet - byte days_in_transit; ///< Amount of days this packet has been in transit + Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo + uint16 count; ///< The amount of cargo in this packet + byte days_in_transit; ///< Amount of days this packet has been in transit + SourceTypeByte source_type; ///< Type of \c source_id + SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid + StationID source; ///< The station where the cargo came from first + TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain) + TileIndex loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle /** The CargoList caches, thus needs to know about it. */ template friend class CargoList; @@ -53,12 +56,6 @@ public: /** Maximum number of items in a single cargo packet. */ static const uint16 MAX_COUNT = UINT16_MAX; - SourceTypeByte source_type; ///< Type of \c source_id - SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid - StationID source; ///< The station where the cargo came from first - TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain) - TileIndex loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle - /** * Creates a new cargo packet * @param source the source of the packet @@ -117,6 +114,51 @@ public: return this->days_in_transit; } + /** + * Gets the type of the cargo's source. industry, town or head quarter + * @return the source type + */ + FORCEINLINE SourceType SourceSubsidyType() const + { + return this->source_type; + } + + /** + * Gets the ID of the cargo's source. An IndustryID, TownID or CompanyID + * @return the source ID + */ + FORCEINLINE SourceID SourceSubsidyID() const + { + return this->source_id; + } + + /** + * Gets the ID of the station where the cargo was loaded for the first time + * @return the StationID + */ + FORCEINLINE SourceID SourceStation() const + { + return this->source; + } + + /** + * Gets the coordinates of the cargo's source station + * @return the source station's coordinates + */ + FORCEINLINE TileIndex SourceStationXY() const + { + return this->source_xy; + } + + /** + * Gets the coordinates of the cargo's last loading station + * @return the last loading station's coordinates + */ + FORCEINLINE TileIndex LoadedAtXY() const + { + return this->loaded_at_xy; + } + static void InvalidateAllFrom(SourceType src_type, SourceID src); static void InvalidateAllFrom(StationID sid); diff --git a/src/economy.cpp b/src/economy.cpp index 1cba20776..2fc5c34f9 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1035,7 +1035,7 @@ void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count) } /* Handle end of route payment */ - Money profit = DeliverGoods(count, this->ct, this->current_station, cp->source_xy, cp->DaysInTransit(), this->owner, cp->source_type, cp->source_id); + Money profit = DeliverGoods(count, this->ct, this->current_station, cp->SourceStation(), cp->DaysInTransit(), this->owner, cp->SourceSubsidyType(), cp->SourceSubsidyID()); this->route_profit += profit; /* The vehicle's profit is whatever route profit there is minus feeder shares. */ @@ -1053,7 +1053,7 @@ Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count) Money profit = GetTransportedGoodsIncome( count, /* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */ - DistanceManhattan(cp->loaded_at_xy, Station::Get(this->current_station)->xy), + DistanceManhattan(cp->LoadedAtXY(), Station::Get(this->current_station)->xy), cp->DaysInTransit(), this->ct); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index b0afb4e1a..a02385984 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -827,7 +827,7 @@ struct StationViewWindow : public Window { const StationCargoList::List *packets = st->goods[i].cargo.Packets(); for (StationCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { const CargoPacket *cp = *it; - if (cp->source != station_id) { + if (cp->SourceStation() != station_id) { bool added = false; /* Enable the expand/hide button for this cargo type */ @@ -839,14 +839,14 @@ struct StationViewWindow : public Window { /* Check if we already have this source in the list */ for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) { CargoData *cd = &(*jt); - if (cd->cargo == i && cd->source == cp->source) { + if (cd->cargo == i && cd->source == cp->SourceStation()) { cd->count += cp->Count(); added = true; break; } } - if (!added) cargolist.push_back(CargoData(i, cp->source, cp->Count())); + if (!added) cargolist.push_back(CargoData(i, cp->SourceStation(), cp->Count())); } } } -- cgit v1.2.3-70-g09d2