mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r26891) -Codechange: Add methods to retrieve flows from a FlowStatMap
This commit is contained in:
parent
f56b8ba69e
commit
9fdb88962f
|
@ -152,7 +152,7 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
|
||||||
ConstEdge edge = lg[ge.node][to->goods[c].node];
|
ConstEdge edge = lg[ge.node][to->goods[c].node];
|
||||||
if (edge.Capacity() > 0) {
|
if (edge.Capacity() > 0) {
|
||||||
this->AddStats(lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
|
this->AddStats(lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
|
||||||
ge.GetSumFlowVia(to->index), from->owner == OWNER_NONE || to->owner == OWNER_NONE,
|
ge.flows.GetFlowVia(to->index), from->owner == OWNER_NONE || to->owner == OWNER_NONE,
|
||||||
this->cached_links[from->index][to->index]);
|
this->cached_links[from->index][to->index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,11 @@ private:
|
||||||
/** Flow descriptions by origin stations. */
|
/** Flow descriptions by origin stations. */
|
||||||
class FlowStatMap : public std::map<StationID, FlowStat> {
|
class FlowStatMap : public std::map<StationID, FlowStat> {
|
||||||
public:
|
public:
|
||||||
|
uint GetFlow() const;
|
||||||
|
uint GetFlowVia(StationID via) const;
|
||||||
|
uint GetFlowFrom(StationID from) const;
|
||||||
|
uint GetFlowFromVia(StationID from, StationID via) const;
|
||||||
|
|
||||||
void AddFlow(StationID origin, StationID via, uint amount);
|
void AddFlow(StationID origin, StationID via, uint amount);
|
||||||
void PassOnFlow(StationID origin, StationID via, uint amount);
|
void PassOnFlow(StationID origin, StationID via, uint amount);
|
||||||
StationIDStack DeleteFlows(StationID via);
|
StationIDStack DeleteFlows(StationID via);
|
||||||
|
@ -268,8 +273,6 @@ struct GoodsEntry {
|
||||||
return HasBit(this->status, GES_RATING);
|
return HasBit(this->status, GES_RATING);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint GetSumFlowVia(StationID via) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the best next hop for a cargo packet from station source.
|
* Get the best next hop for a cargo packet from station source.
|
||||||
* @param source Source of the packet.
|
* @param source Source of the packet.
|
||||||
|
|
|
@ -4457,19 +4457,57 @@ void FlowStatMap::ReleaseFlows(StationID via)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the sum of flows via a specific station from this GoodsEntry.
|
* Get the sum of all flows from this FlowStatMap.
|
||||||
* @param via Remote station to look for.
|
* @return sum of all flows.
|
||||||
* @return a FlowStat with all flows for 'via' added up.
|
|
||||||
*/
|
*/
|
||||||
uint GoodsEntry::GetSumFlowVia(StationID via) const
|
uint FlowStatMap::GetFlow() const
|
||||||
{
|
{
|
||||||
uint ret = 0;
|
uint ret = 0;
|
||||||
for (FlowStatMap::const_iterator i = this->flows.begin(); i != this->flows.end(); ++i) {
|
for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) {
|
||||||
|
ret += (--(i->second.GetShares()->end()))->first;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sum of flows via a specific station from this FlowStatMap.
|
||||||
|
* @param via Remote station to look for.
|
||||||
|
* @return all flows for 'via' added up.
|
||||||
|
*/
|
||||||
|
uint FlowStatMap::GetFlowVia(StationID via) const
|
||||||
|
{
|
||||||
|
uint ret = 0;
|
||||||
|
for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) {
|
||||||
ret += i->second.GetShare(via);
|
ret += i->second.GetShare(via);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sum of flows from a specific station from this FlowStatMap.
|
||||||
|
* @param from Origin station to look for.
|
||||||
|
* @return all flows from 'from' added up.
|
||||||
|
*/
|
||||||
|
uint FlowStatMap::GetFlowFrom(StationID from) const
|
||||||
|
{
|
||||||
|
FlowStatMap::const_iterator i = this->find(from);
|
||||||
|
if (i == this->end()) return 0;
|
||||||
|
return (--(i->second.GetShares()->end()))->first;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the flow from a specific station via a specific other station.
|
||||||
|
* @param from Origin station to look for.
|
||||||
|
* @param via Remote station to look for.
|
||||||
|
* @return flow share originating at 'from' and going to 'via'.
|
||||||
|
*/
|
||||||
|
uint FlowStatMap::GetFlowFromVia(StationID from, StationID via) const
|
||||||
|
{
|
||||||
|
FlowStatMap::const_iterator i = this->find(from);
|
||||||
|
if (i == this->end()) return 0;
|
||||||
|
return i->second.GetShare(via);
|
||||||
|
}
|
||||||
|
|
||||||
extern const TileTypeProcs _tile_type_station_procs = {
|
extern const TileTypeProcs _tile_type_station_procs = {
|
||||||
DrawTile_Station, // draw_tile_proc
|
DrawTile_Station, // draw_tile_proc
|
||||||
GetSlopePixelZ_Station, // get_slope_z_proc
|
GetSlopePixelZ_Station, // get_slope_z_proc
|
||||||
|
|
Loading…
Reference in New Issue