Changeset - r20333:a5be8ec53733
[Not reviewed]
master
0 3 0
fonsinchen - 11 years ago 2013-06-09 12:49:47
fonsinchen@openttd.org
(svn r25346) -Codechange: Glue between stations and flow stats
3 files changed with 47 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/station.cpp
Show inline comments
 
@@ -94,12 +94,17 @@ Station::~Station()
 
		if (lg != NULL) {
 
			lg->RemoveNode(this->goods[c].node);
 
			if (lg->Size() == 0) {
 
				delete lg;
 
			}
 
		}
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			GoodsEntry *ge = &st->goods[c];
 
			ge->flows.DeleteFlows(this->index);
 
		}
 
	}
 

	
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		/* Forget about this station if this station is removed */
 
		if (v->last_station_visited == this->index) {
src/station_base.h
Show inline comments
 
@@ -193,12 +193,13 @@ struct GoodsEntry {
 

	
 
	byte amount_fract;      ///< Fractional part of the amount in the cargo list
 
	StationCargoList cargo; ///< The cargo packets of cargo waiting in this station
 

	
 
	LinkGraphID link_graph; ///< Link graph this station belongs to.
 
	NodeID node;            ///< ID of node in link graph referring to this goods entry.
 
	FlowStatMap flows;      ///< Planned flows through this station.
 

	
 
	/**
 
	 * Reports whether a vehicle has ever tried to load the cargo at this station.
 
	 * This does not imply that there was cargo available for loading. Refer to GES_PICKUP for that.
 
	 * @return true if vehicle tried to load.
 
	 */
 
@@ -209,12 +210,39 @@ struct GoodsEntry {
 
	 * @return true if the cargo has a rating, i.e. pickup has been attempted.
 
	 */
 
	inline bool HasRating() const
 
	{
 
		return HasBit(this->acceptance_pickup, GES_PICKUP);
 
	}
 

	
 
	uint GetSumFlowVia(StationID via) const;
 

	
 
	/**
 
	 * Get the best next hop for a cargo packet from station source.
 
	 * @param source Source of the packet.
 
	 * @return The chosen next hop or INVALID_STATION if none was found.
 
	 */
 
	inline StationID GetVia(StationID source) const
 
	{
 
		FlowStatMap::const_iterator flow_it(this->flows.find(source));
 
		return flow_it != this->flows.end() ? flow_it->second.GetVia() : INVALID_STATION;
 
	}
 

	
 
	/**
 
	 * Get the best next hop for a cargo packet from station source, optionally
 
	 * excluding one or two stations.
 
	 * @param source Source of the packet.
 
	 * @param excluded If this station would be chosen choose the second best one instead.
 
	 * @param excluded2 Second station to be excluded, if != INVALID_STATION.
 
	 * @return The chosen next hop or INVALID_STATION if none was found.
 
	 */
 
	inline StationID GetVia(StationID source, StationID excluded, StationID excluded2 = INVALID_STATION) const
 
	{
 
		FlowStatMap::const_iterator flow_it(this->flows.find(source));
 
		return flow_it != this->flows.end() ? flow_it->second.GetVia(excluded, excluded2) : INVALID_STATION;
 
	}
 
};
 

	
 
/** All airport-related information. Only valid if tile != INVALID_TILE. */
 
struct Airport : public TileArea {
 
	Airport() : TileArea(INVALID_TILE, 0, 0) {}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -4158,12 +4158,26 @@ void FlowStatMap::DeleteFlows(StationID 
 
		} else {
 
			++f_it;
 
		}
 
	}
 
}
 

	
 
/**
 
 * Get the sum of flows via a specific station from this GoodsEntry.
 
 * @param via Remote station to look for.
 
 * @return a FlowStat with all flows for 'via' added up.
 
 */
 
uint GoodsEntry::GetSumFlowVia(StationID via) const
 
{
 
	uint ret = 0;
 
	for (FlowStatMap::const_iterator i = this->flows.begin(); i != this->flows.end(); ++i) {
 
		ret += i->second.GetShare(via);
 
	}
 
	return ret;
 
}
 

	
 
extern const TileTypeProcs _tile_type_station_procs = {
 
	DrawTile_Station,           // draw_tile_proc
 
	GetSlopePixelZ_Station,     // get_slope_z_proc
 
	ClearTile_Station,          // clear_tile_proc
 
	NULL,                       // add_accepted_cargo_proc
 
	GetTileDesc_Station,        // get_tile_desc_proc
0 comments (0 inline, 0 general)