(svn r25009) -Codechange: refactor bits of cargo packet (lists) to reduce duplicated code (fonsinchen)

This commit is contained in:
rubidium
2013-02-17 14:17:06 +00:00
parent 84ca041564
commit 4301d77d65
3 changed files with 90 additions and 32 deletions

View File

@@ -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.
@@ -84,6 +97,17 @@ public:
return this->feeder_share;
}
/**
* 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
@@ -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. */