Go to the documentation of this file.
13 #include "../core/pool_type.hpp"
14 #include "../core/smallmap_type.hpp"
15 #include "../core/smallmatrix_type.hpp"
16 #include "../station_base.h"
17 #include "../cargotype.h"
18 #include "../date_func.h"
75 template<
typename Tedge>
92 uint
Capacity()
const {
return this->edge.capacity; }
98 uint
Usage()
const {
return this->edge.usage; }
116 Date LastUpdate()
const {
return std::max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
124 template<
typename Tnode,
typename Tedge>
146 uint
Supply()
const {
return this->node.supply; }
152 uint
Demand()
const {
return this->node.demand; }
158 StationID
Station()
const {
return this->node.station; }
180 template <
class Tedge,
class Tedge_wrapper,
class Titer>
199 FakePointer(
const std::pair<NodeID, Tedge_wrapper> &pair) : std::pair<NodeID, Tedge_wrapper>(pair) {}
205 std::pair<NodeID, Tedge_wrapper> *
operator->() {
return this; }
225 this->current = this->base[this->
current].next_edge;
226 return static_cast<Titer &
>(*this);
235 Titer ret(
static_cast<Titer &
>(*
this));
236 this->current = this->base[this->
current].next_edge;
247 template<
class Tother>
250 return this->base == other.base && this->current == other.current;
260 template<
class Tother>
263 return this->base != other.base || this->current != other.current;
272 return std::pair<NodeID, Tedge_wrapper>(this->current, Tedge_wrapper(this->base[this->current]));
280 return FakePointer(this->
operator*());
437 typedef std::vector<BaseNode> NodeVector;
454 inline static uint
Scale(uint val, uint target_age, uint orig_age)
456 return val > 0 ? std::max(1U, val * target_age / orig_age) : 0;
467 void Init(uint size);
498 inline uint
Size()
const {
return (uint)this->
nodes.size(); }
Tedge * edges
Outgoing edges for wrapped node.
static const byte INVALID_CARGO
Constant representing invalid cargo.
uint32 TileIndex
The index/ID of a Tile.
uint Usage() const
Get edge's usage.
static const uint COMPRESSION_INTERVAL
Minimum number of days between subsequent compressions of a LG.
Edge(BaseEdge &edge)
Constructor.
EdgeMatrix edges
Edges in the component.
void AddEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMode mode)
Fill an edge with values from a link.
A connected component of a link graph.
Pool< LinkGraph, LinkGraphID, 32, 0xFFFF > LinkGraphPool
Type of the pool for link graph components.
void UpdateEdge(NodeID to, uint capacity, uint usage, EdgeUpdateMode mode)
Creates an edge if none exists yet or updates an existing edge.
uint usage
Usage of the link.
NodeVector nodes
Nodes in the component.
Date LastRestrictedUpdate() const
Get the date of the last update to the edge's restricted capacity.
uint demand
Acceptance at the station.
Date LastUpdate() const
Get the date of the last update to any part of the edge's capacity.
void UpdateSupply(uint supply)
Update the node's supply and set last_update to the current date.
EdgeIterator Begin()
Get an iterator pointing to the start of the edges array.
An iterator for non-const edges.
uint supply
Supply at the station.
void Init()
Create an edge.
static uint Scale(uint val, uint target_age, uint orig_age)
Scale a value from a link graph of age orig_age for usage in one of age target_age.
EdgeIterator End()
Get an iterator pointing beyond the end of the edges array.
StationID station
Station ID.
LinkGraph()
Bare constructor, only for save/load.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
EdgeUpdateMode
Special modes for updating links.
Wrapper for an edge (const or not) allowing retrieval, but no modification.
ConstNode(const LinkGraph *lg, NodeID node)
Constructor.
Date last_update
When the supply was last updated.
const friend SaveLoad * GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
BaseEdgeIterator(Tedge *base, NodeID current)
Constructor.
Titer & operator++()
Prefix-increment.
Date LastUpdate() const
Get node's last update.
Date LastUnrestrictedUpdate() const
Get the date of the last update to the edge's unrestricted capacity.
Date _date
Current date in days (day counter)
uint capacity
Capacity of the link.
EdgeWrapper< const BaseEdge > ConstEdge
A constant edge class.
ConstNode operator[](NodeID num) const
Get a const reference to a node with the specified id.
Tedge & edge
Actual edge to be used.
friend void SaveLoad_LinkGraph(LinkGraph &lg)
Save/load a link graph.
std::pair< NodeID, Tedge_wrapper > operator*() const
Dereference with operator*.
uint Demand() const
Get demand of wrapped node.
LinkGraphPool _link_graph_pool
The actual pool with link graphs.
int32 Date
The type to store our dates in.
An edge in the link graph.
uint Size() const
Get the current size of the component.
Wrapper for a node (const or not) allowing retrieval, but no modification.
void UpdateLocation(TileIndex xy)
Update the node's location on the map.
CargoID Cargo() const
Get the cargo ID this component's link graph refers to.
Node operator[](NodeID num)
Get a node with the specified id.
uint Capacity() const
Get edge's capacity.
Base class for iterating across outgoing edges of a node.
ConstEdge operator[](NodeID to) const
Get a ConstEdge.
EdgeIterator(BaseEdge *edges, NodeID current)
Constructor.
StationID Station() const
Get ID of station belonging to wrapped node.
Date LastCompression() const
Get date of last compression.
void ShiftDates(int interval)
Shift all dates by given interval.
Date last_unrestricted_update
When the unrestricted part of the link was last updated.
Base class for all pools.
void Init(TileIndex xy=INVALID_TILE, StationID st=INVALID_STATION, uint demand=0)
Create a node or clear it.
NodeID current
Current offset in edges array.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
FakePointer operator->() const
Dereference with operator->.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
NodeWrapper(Tnode &node, Tedge *edges, NodeID index)
Wrap a node.
static const Date INVALID_DATE
Representation of an invalid date.
CargoID cargo
Cargo of this component's link graph.
const friend SaveLoad * GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
void Update(uint capacity, uint usage, EdgeUpdateMode mode)
Update an edge.
void SetDemand(uint demand)
Set the node's demand.
Date last_compression
Last time the capacities and supplies were compressed.
An iterator for const edges.
Tedge * base
Array of edges being iterated.
TileIndex xy
Location of the station referred to by the node.
void Merge(LinkGraph *other)
Merge a link graph with another one.
ConstEdgeIterator(const BaseEdge *edges, NodeID current)
Constructor.
Date last_restricted_update
When the restricted part of the link was last updated.
Node(LinkGraph *lg, NodeID node)
Constructor.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
LinkGraph(CargoID cargo)
Real constructor.
Titer operator++(int)
Postfix-increment.
std::pair< NodeID, Tedge_wrapper > * operator->()
Retrieve the pair by operator->.
EdgeWrapper(Tedge &edge)
Wrap a an edge.
TileIndex XY() const
Get the location of the station associated with the node.
A "fake" pointer to enable operator-> on temporaries.
Base class for all PoolItems.
ConstEdgeIterator End() const
Get an iterator pointing beyond the end of the edges array.
Edge operator[](NodeID to)
Get an Edge.
NodeID index
ID of wrapped node.
FakePointer(const std::pair< NodeID, Tedge_wrapper > &pair)
Construct a fake pointer from a pair of NodeID and edge.
ConstEdgeIterator Begin() const
Get an iterator pointing to the start of the edges array.
bool operator!=(const Tother &other)
Compare for inequality with some other edge iterator.
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
bool operator==(const Tother &other)
Compare with some other edge iterator.
Tnode & node
Node being wrapped.
NodeID next_edge
Destination of next valid edge starting at the same source node.
uint Supply() const
Get supply of wrapped node.