diff options
author | rubidium <rubidium@openttd.org> | 2013-02-17 14:17:06 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2013-02-17 14:17:06 +0000 |
commit | 71bbc130fc3bde400bcf2d46e0d57d974acc83aa (patch) | |
tree | f51b0879b596d64a2baf426ba3796f5056345dc4 /src/cargopacket.h | |
parent | 2795ed5b091fa5580976547b3669bac78cd595ce (diff) | |
download | openttd-71bbc130fc3bde400bcf2d46e0d57d974acc83aa.tar.xz |
(svn r25009) -Codechange: refactor bits of cargo packet (lists) to reduce duplicated code (fonsinchen)
Diffstat (limited to 'src/cargopacket.h')
-rw-r--r-- | src/cargopacket.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/cargopacket.h b/src/cargopacket.h index 1e2093134..c23df8800 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -64,6 +64,19 @@ public: CargoPacket *Split(uint new_size); void Merge(CargoPacket *cp); + void Reduce(uint count); + + /** + * Sets the tile where the packet was loaded last. + * @param load_place Tile where the packet was loaded last. + */ + void SetLoadPlace(TileIndex load_place) { this->loaded_at_xy = load_place; } + + /** + * 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; } /** * Gets the number of 'items' in this packet. @@ -85,6 +98,17 @@ public: } /** + * Gets part of the amount of money already paid to earlier vehicles in + * the feeder chain. + * @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 + { + return this->feeder_share * part / static_cast<uint>(this->count); + } + + /** * Gets the number of days this cargo has been in transit. * This number isn't really in days, but in 2.5 days (CARGO_AGING_TICKS = 185 ticks) and * it is capped at 255. @@ -170,8 +194,12 @@ public: typedef std::list<CargoPacket *> List; /** The iterator for our container. */ typedef List::iterator Iterator; + /** The reverse iterator for our container. */ + typedef List::reverse_iterator ReverseIterator; /** The const iterator for our container. */ typedef List::const_iterator ConstIterator; + /** The const reverse iterator for our container. */ + typedef List::const_reverse_iterator ConstReverseIterator; /** Kind of actions that could be done with packets on move. */ enum MoveToAction { @@ -189,7 +217,9 @@ protected: void AddToCache(const CargoPacket *cp); - void RemoveFromCache(const CargoPacket *cp); + void RemoveFromCache(const CargoPacket *cp, uint count); + + static bool TryMerge(CargoPacket *cp, CargoPacket *icp); public: /** Create the cargo list. */ @@ -265,7 +295,7 @@ protected: Money feeder_share; ///< Cache for the feeder share. void AddToCache(const CargoPacket *cp); - void RemoveFromCache(const CargoPacket *cp); + void RemoveFromCache(const CargoPacket *cp, uint count); public: /** The super class ought to know what it's doing. */ |