OpenTTD Source
12.0-beta2
|
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"
19 #include "../saveload/saveload.h"
76 template<
typename Tedge>
93 uint
Capacity()
const {
return this->edge.capacity; }
99 uint
Usage()
const {
return this->edge.usage; }
105 uint32
TravelTime()
const {
return this->edge.travel_time_sum / this->edge.capacity; }
123 Date LastUpdate()
const {
return std::max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
131 template<
typename Tnode,
typename Tedge>
153 uint
Supply()
const {
return this->node.supply; }
159 uint
Demand()
const {
return this->node.demand; }
165 StationID
Station()
const {
return this->node.station; }
187 template <
class Tedge,
class Tedge_wrapper,
class Titer>
206 FakePointer(
const std::pair<NodeID, Tedge_wrapper> &pair) : std::pair<NodeID, Tedge_wrapper>(pair) {}
212 std::pair<NodeID, Tedge_wrapper> *
operator->() {
return this; }
232 this->current = this->base[this->
current].next_edge;
233 return static_cast<Titer &
>(*this);
242 Titer ret(
static_cast<Titer &
>(*
this));
243 this->current = this->base[this->
current].next_edge;
254 template<
class Tother>
257 return this->base == other.base && this->current == other.current;
267 template<
class Tother>
270 return this->base != other.base || this->current != other.current;
279 return std::pair<NodeID, Tedge_wrapper>(this->current, Tedge_wrapper(this->base[this->current]));
287 return FakePointer(this->
operator*());
444 typedef std::vector<BaseNode> NodeVector;
461 inline static uint
Scale(uint val, uint target_age, uint orig_age)
463 return val > 0 ? std::max(1U, val * target_age / orig_age) : 0;
474 void Init(uint size);
505 inline NodeID
Size()
const {
return (NodeID)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.
A connected component of a link graph.
Pool< LinkGraph, LinkGraphID, 32, 0xFFFF > LinkGraphPool
Type of the pool for link graph components.
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.
uint32 TravelTime() const
Get edge's average travel time.
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.
NodeID Size() const
Get the current size of the component.
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 UpdateEdge(NodeID to, uint capacity, uint usage, uint32 time, EdgeUpdateMode mode)
Creates an edge if none exists yet or updates an existing edge.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
EdgeUpdateMode
Special modes for updating links.
friend SaveLoadTable GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
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.
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.
A trimmed down version of what std::span will be in C++20.
Tedge & edge
Actual edge to be used.
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.
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.
void Update(uint capacity, uint usage, uint32 time, EdgeUpdateMode mode)
Update an edge.
Date LastCompression() const
Get date of last compression.
void AddEdge(NodeID to, uint capacity, uint usage, uint32 time, EdgeUpdateMode mode)
Fill an edge with values from a link.
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.
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
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.
uint64 travel_time_sum
Sum of the travel times of the link, in ticks.
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.
friend SaveLoadTable GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
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.