Mercurial > hg > openttd
changeset 13299:366acecbae41 draft
(svn r17808) -Codechange: remove write 'access' from all of CargoPacket's variables
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 18 Oct 2009 17:53:34 +0000 |
parents | f590f261c90a |
children | 84f45cafda07 |
files | src/cargopacket.h src/economy.cpp src/station_gui.cpp |
diffstat | 3 files changed, 58 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -37,11 +37,14 @@ */ 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 <class Tinst> friend class CargoList; @@ -53,12 +56,6 @@ /** 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 @@ 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);
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -1035,7 +1035,7 @@ } /* 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 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);
--- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -827,7 +827,7 @@ 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 @@ /* 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())); } } }