Changeset - r12047:1b4e9d68f490
[Not reviewed]
master
0 2 0
smatz - 15 years ago 2009-05-29 15:46:55
smatz@openttd.org
(svn r16459) -Codechange: move definition of several cargopacket accessors to header file
2 files changed with 12 insertions and 49 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.cpp
Show inline comments
 
@@ -26,17 +26,12 @@ CargoPacket::CargoPacket(StationID sourc
 
	this->count           = count;
 
	this->days_in_transit = 0;
 
	this->feeder_share    = 0;
 
	this->paid_for        = false;
 
}
 

	
 
bool CargoPacket::SameSource(const CargoPacket *cp) const
 
{
 
	return this->source_xy == cp->source_xy && this->days_in_transit == cp->days_in_transit && this->paid_for == cp->paid_for;
 
}
 

	
 
/*
 
 *
 
 * Cargo list implementation
 
 *
 
 */
 

	
 
@@ -45,59 +40,24 @@ CargoList::~CargoList()
 
	while (!packets.empty()) {
 
		delete packets.front();
 
		packets.pop_front();
 
	}
 
}
 

	
 
const CargoList::List *CargoList::Packets() const
 
{
 
	return &packets;
 
}
 

	
 
void CargoList::AgeCargo()
 
{
 
	if (empty) return;
 

	
 
	uint dit = 0;
 
	for (List::const_iterator it = packets.begin(); it != packets.end(); it++) {
 
		if ((*it)->days_in_transit != 0xFF) (*it)->days_in_transit++;
 
		dit += (*it)->days_in_transit * (*it)->count;
 
	}
 
	days_in_transit = dit / count;
 
}
 

	
 
bool CargoList::Empty() const
 
{
 
	return empty;
 
}
 

	
 
uint CargoList::Count() const
 
{
 
	return count;
 
}
 

	
 
bool CargoList::UnpaidCargo() const
 
{
 
	return unpaid_cargo;
 
}
 

	
 
Money CargoList::FeederShare() const
 
{
 
	return feeder_share;
 
}
 

	
 
StationID CargoList::Source() const
 
{
 
	return source;
 
}
 

	
 
uint CargoList::DaysInTransit() const
 
{
 
	return days_in_transit;
 
}
 

	
 
void CargoList::Append(CargoPacket *cp)
 
{
 
	assert(cp != NULL);
 

	
 
	for (List::iterator it = packets.begin(); it != packets.end(); it++) {
 
		if ((*it)->SameSource(cp) && (*it)->count + cp->count <= 65535) {
src/cargopacket.h
Show inline comments
 
@@ -45,13 +45,16 @@ struct CargoPacket : CargoPacketPool::Po
 
	/**
 
	 * Checks whether the cargo packet is from (exactly) the same source
 
	 * in time and location.
 
	 * @param cp the cargo packet to compare to
 
	 * @return true if and only if days_in_transit and source_xy are equal
 
	 */
 
	bool SameSource(const CargoPacket *cp) const;
 
	FORCEINLINE bool SameSource(const CargoPacket *cp) const
 
	{
 
		return this->source_xy == cp->source_xy && this->days_in_transit == cp->days_in_transit && this->paid_for == cp->paid_for;
 
	}
 
};
 

	
 
/**
 
 * Iterate over all _valid_ cargo packets from the given start
 
 * @param var   the variable used as "iterator"
 
 * @param start the cargo packet ID of the first packet to iterate over
 
@@ -92,62 +95,62 @@ private:
 
	uint days_in_transit; ///< Cache for the number of days in transit
 

	
 
public:
 
	friend const struct SaveLoad *GetGoodsDesc();
 

	
 
	/** Create the cargo list */
 
	CargoList() { this->InvalidateCache(); }
 
	FORCEINLINE CargoList() { this->InvalidateCache(); }
 
	/** And destroy it ("frees" all cargo packets) */
 
	~CargoList();
 

	
 
	/**
 
	 * Returns a pointer to the cargo packet list (so you can iterate over it etc).
 
	 * @return pointer to the packet list
 
	 */
 
	const CargoList::List *Packets() const;
 
	FORCEINLINE const CargoList::List *Packets() const { return &this->packets; }
 

	
 
	/**
 
	 * Ages the all cargo in this list
 
	 */
 
	void AgeCargo();
 

	
 
	/**
 
	 * Checks whether this list is empty
 
	 * @return true if and only if the list is empty
 
	 */
 
	bool Empty() const;
 
	FORCEINLINE bool Empty() const { return this->empty; }
 

	
 
	/**
 
	 * Returns the number of cargo entities in this list
 
	 * @return the before mentioned number
 
	 */
 
	uint Count() const;
 
	FORCEINLINE uint Count() const { return this->count; }
 

	
 
	/**
 
	 * Is there some cargo that has not been paid for?
 
	 * @return true if and only if there is such a cargo
 
	 */
 
	bool UnpaidCargo() const;
 
	FORCEINLINE bool UnpaidCargo() const { return this->unpaid_cargo; }
 

	
 
	/**
 
	 * Returns total sum of the feeder share for all packets
 
	 * @return the before mentioned number
 
	 */
 
	Money FeederShare() const;
 
	FORCEINLINE Money FeederShare() const { return this->feeder_share; }
 

	
 
	/**
 
	 * Returns source of the first cargo packet in this list
 
	 * @return the before mentioned source
 
	 */
 
	StationID Source() const;
 
	FORCEINLINE StationID Source() const { return this->source; }
 

	
 
	/**
 
	 * Returns average number of days in transit for a cargo entity
 
	 * @return the before mentioned number
 
	 */
 
	uint DaysInTransit() const;
 
	FORCEINLINE uint DaysInTransit() const { return this->days_in_transit; }
 

	
 

	
 
	/**
 
	 * Appends the given cargo packet
 
	 * @warning After appending this packet may not exist anymore!
 
	 * @note Do not use the cargo packet anymore after it has been appended to this CargoList!
0 comments (0 inline, 0 general)