Changeset - r13282:5abfbbdbe99a
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-10-18 14:30:37
rubidium@openttd.org
(svn r17801) -Codechange: for StationCargoLists the 'loaded_at_xy' does not matter when merging CargoPackets
2 files changed with 32 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.cpp
Show inline comments
 
@@ -108,13 +108,13 @@ template <class Tinst>
 
void CargoList<Tinst>::Append(CargoPacket *cp)
 
{
 
	assert(cp != NULL);
 

	
 
	for (List::iterator it = this->packets.begin(); it != this->packets.end(); it++) {
 
		CargoPacket *icp = *it;
 
		if (icp->SameSource(cp) && icp->count + cp->count <= CargoPacket::MAX_COUNT) {
 
		if (Tinst::AreMergable(icp, cp) && icp->count + cp->count <= CargoPacket::MAX_COUNT) {
 
			icp->count        += cp->count;
 
			icp->feeder_share += cp->feeder_share;
 

	
 
			this->AddToCache(cp);
 
			delete cp;
 
			return;
src/cargopacket.h
Show inline comments
 
@@ -112,26 +112,12 @@ public:
 
	FORCEINLINE byte DaysInTransit() const
 
	{
 
		return this->days_in_transit;
 
	}
 

	
 

	
 
	/**
 
	 * 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
 
	 */
 
	FORCEINLINE bool SameSource(const CargoPacket *cp) const
 
	{
 
		return this->source_xy    == cp->source_xy &&
 
				this->days_in_transit == cp->days_in_transit &&
 
				this->source_type     == cp->source_type &&
 
				this->source_id       == cp->source_id;
 
	}
 

	
 
	static void InvalidateAllFrom(SourceType src_type, SourceID src);
 
};
 

	
 
/**
 
 * Iterate over all _valid_ cargo packets from the given start
 
 * @param var   the variable used as "iterator"
 
@@ -298,18 +284,49 @@ public:
 
	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt);
 

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

	
 
	/**
 
	 * Are two the two CargoPackets mergeable in the context of
 
	 * a list of CargoPackets for a Vehicle?
 
	 * @param cp1 the first CargoPacket
 
	 * @param cp2 the second CargoPacket
 
	 * @return true if they are mergeable
 
	 */
 
	static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
 
	{
 
		return cp1->source_xy    == cp2->source_xy &&
 
				cp1->days_in_transit == cp2->days_in_transit &&
 
				cp1->source_type     == cp2->source_type &&
 
				cp1->source_id       == cp2->source_id &&
 
				cp1->loaded_at_xy    == cp2->loaded_at_xy;
 
	}
 
};
 

	
 
/**
 
 * CargoList that is used for stations.
 
 */
 
class StationCargoList : public CargoList<StationCargoList> {
 
public:
 
	/** The stations, via GoodsEntry, have a CargoList. */
 
	friend const struct SaveLoad *GetGoodsDesc();
 

	
 
	/**
 
	 * Are two the two CargoPackets mergeable in the context of
 
	 * a list of CargoPackets for a Vehicle?
 
	 * @param cp1 the first CargoPacket
 
	 * @param cp2 the second CargoPacket
 
	 * @return true if they are mergeable
 
	 */
 
	static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
 
	{
 
		return cp1->source_xy    == cp2->source_xy &&
 
				cp1->days_in_transit == cp2->days_in_transit &&
 
				cp1->source_type     == cp2->source_type &&
 
				cp1->source_id       == cp2->source_id;
 
	}
 
};
 

	
 
#endif /* CARGOPACKET_H */
0 comments (0 inline, 0 general)