|
OpenTTD Source 20260218-master-g2123fca5ea
|
A connected component of a link graph. More...
#include <linkgraph.h>
Data Structures | |
| struct | BaseEdge |
| An edge in the link graph. More... | |
| struct | BaseNode |
| Node of the link graph. More... | |
Public Types | |
| typedef std::vector< BaseNode > | NodeVector |
Public Member Functions | |
| LinkGraph (LinkGraphID index, CargoType cargo=INVALID_CARGO) | |
| Real constructor. | |
| void | Init (uint size) |
| Resize the component and fill it with empty nodes and edges. | |
| void | ShiftDates (TimerGameEconomy::Date interval) |
| Shift all dates by given interval. | |
| void | Compress () |
| void | Merge (LinkGraph *other) |
| Merge a link graph with another one. | |
| BaseNode & | operator[] (NodeID num) |
| Get a node with the specified id. | |
| const BaseNode & | operator[] (NodeID num) const |
| Get a const reference to a node with the specified id. | |
| NodeID | Size () const |
| Get the current size of the component. | |
| TimerGameEconomy::Date | LastCompression () const |
| Get date of last compression. | |
| CargoType | Cargo () const |
| Get the cargo type this component's link graph refers to. | |
| uint | Monthly (uint base) const |
| Scale a value to its monthly equivalent, based on last compression. | |
| NodeID | AddNode (const Station *st) |
| Add a node to the component and create empty edges associated with it. | |
| void | RemoveNode (NodeID id) |
| Remove a node from the link graph by overwriting it with the last node. | |
Static Public Member Functions | |
| static uint | Scale (uint val, TimerGameEconomy::Date target_age, TimerGameEconomy::Date orig_age) |
| Scale a value from a link graph of age orig_age for usage in one of age target_age. | |
Static Public Attributes | |
| static const uint | MIN_TIMEOUT_DISTANCE = 32 |
| Minimum effective distance for timeout calculation. | |
| static constexpr TimerGameEconomy::Date | STALE_LINK_DEPOT_TIMEOUT {1024} |
| Number of days before deleting links served only by vehicles stopped in depot. | |
| static constexpr TimerGameEconomy::Date | COMPRESSION_INTERVAL {256} |
| Minimum number of days between subsequent compressions of a LG. | |
Protected Attributes | |
| CargoType | cargo = INVALID_CARGO |
| Cargo of this component's link graph. | |
| TimerGameEconomy::Date | last_compression {} |
| Last time the capacities and supplies were compressed. | |
| NodeVector | nodes {} |
| Nodes in the component. | |
Friends | |
| class | SlLinkgraphNode |
| class | SlLinkgraphEdge |
| class | LinkGraphJob |
| SaveLoadTable | GetLinkGraphDesc () |
| Get a SaveLoad array for a link graph. | |
| SaveLoadTable | GetLinkGraphJobDesc () |
| Get a SaveLoad array for a link graph job. | |
A connected component of a link graph.
Contains a complete set of stations connected by links as nodes and edges. Each component also holds a copy of the link graph settings at the time of its creation. The global settings might change between the creation and join time so we can't rely on them.
Definition at line 37 of file linkgraph.h.
| typedef std::vector<BaseNode> LinkGraph::NodeVector |
Definition at line 171 of file linkgraph.h.
|
inline |
Real constructor.
Definition at line 200 of file linkgraph.h.
References _link_graph_pool, cargo, and last_compression.
Referenced by LinkGraph::BaseNode::BaseNode(), GetLinkGraphDesc, and Merge().
| NodeID LinkGraph::AddNode | ( | const Station * | st | ) |
Add a node to the component and create empty edges associated with it.
Set the station's last_component to this component. Calculate the distances to all other nodes. The distances to all nodes are important as the demand calculator relies on their availability.
| st | New node's station. |
Definition at line 150 of file linkgraph.cpp.
References GoodsEntry::Acceptance, cargo, Station::goods, nodes, Size(), GoodsEntry::status, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and BaseStation::xy.
Referenced by IncreaseStats(), and Merge().
|
inline |
Get the cargo type this component's link graph refers to.
Definition at line 246 of file linkgraph.h.
References cargo.
Referenced by LinkGraphJob::Cargo().
| void LinkGraph::Compress | ( | ) |
Definition at line 67 of file linkgraph.cpp.
| void LinkGraph::Init | ( | uint | size | ) |
Resize the component and fill it with empty nodes and edges.
Used when loading from save games. The component is expected to be empty before.
| size | New size of the component. |
Definition at line 254 of file linkgraph.cpp.
Referenced by SlLinkgraphNode::Load().
|
inline |
Get date of last compression.
Definition at line 240 of file linkgraph.h.
References last_compression.
Referenced by DeleteStaleLinks(), and LinkGraphJob::LastCompression().
| void LinkGraph::Merge | ( | LinkGraph * | other | ) |
Merge a link graph with another one.
| other | LinkGraph to be merged into this one. |
Definition at line 91 of file linkgraph.cpp.
References AddNode(), LinkGraph::BaseEdge::capacity, cargo, TimerGameEconomy::date, SpecializedStation< Station, false >::Get(), Station::goods, last_compression, LinkGraph(), nodes, Scale(), Size(), LinkGraph::BaseEdge::travel_time_sum, and LinkGraph::BaseEdge::usage.
Referenced by IncreaseStats().
|
inline |
Scale a value to its monthly equivalent, based on last compression.
| base | Value to be scaled. |
Definition at line 253 of file linkgraph.h.
References TimerGameEconomy::date, and last_compression.
Referenced by LinkGraphOverlay::AddLinks(), StationViewWindow::DrawCargoRatings(), and LinkGraphOverlay::RebuildCache().
|
inline |
Get a node with the specified id.
| num | ID of the node. |
Definition at line 221 of file linkgraph.h.
References nodes.
|
inline |
Get a const reference to a node with the specified id.
| num | ID of the node. |
Definition at line 228 of file linkgraph.h.
References nodes.
| void LinkGraph::RemoveNode | ( | NodeID | id | ) |
Remove a node from the link graph by overwriting it with the last node.
| id | ID of the node to be removed. |
Definition at line 117 of file linkgraph.cpp.
References cargo, SpecializedStation< Station, false >::Get(), Station::goods, nodes, and Size().
Referenced by Station::~Station().
|
inlinestatic |
Scale a value from a link graph of age orig_age for usage in one of age target_age.
Make sure that the value stays > 0 if it was > 0 before.
| val | Value to be scaled. |
| target_age | Age of the target link graph. |
| orig_age | Age of the original link graph. |
Definition at line 190 of file linkgraph.h.
Referenced by Merge().
| void LinkGraph::ShiftDates | ( | TimerGameEconomy::Date | interval | ) |
Shift all dates by given interval.
This is useful if the date has been modified with the cheat menu.
| interval | Number of days to be added or subtracted. |
Definition at line 54 of file linkgraph.cpp.
References TimerGameConst< struct Economy >::INVALID_DATE, last_compression, LinkGraph::BaseNode::last_update, nodes, and Size().
|
inline |
Get the current size of the component.
Definition at line 234 of file linkgraph.h.
References nodes.
Referenced by AddNode(), AfterLoadLinkGraphs(), IncreaseStats(), Init(), Merge(), RemoveNode(), SlLinkgraphNode::Save(), ShiftDates(), LinkGraphJob::Size(), LinkGraphSchedule::SpawnNext(), and Station::~Station().
|
friend |
Get a SaveLoad array for a link graph.
Definition at line 136 of file linkgraph_sl.cpp.
References cargo, last_compression, LinkGraph(), SL_MIN_VERSION, SLE_VAR, SLEG_CONDVAR, SLEG_STRUCTLIST, and SLV_SAVELOAD_LIST_LENGTH.
|
friend |
Get a SaveLoad array for a link graph job.
The settings struct is derived from the global settings saveload array. The exact entries are calculated when the function is called the first time. It's necessary to keep a copy of the settings for each link graph job so that you can change the settings while in-game and still not mess with current link graph runs. Of course the settings have to be saved and loaded, too, to avoid desyncs.
Definition at line 180 of file linkgraph_sl.cpp.
References GetSaveLoadFromSettingTable(), settings, SLE_VAR, and SLEG_STRUCT.
|
friend |
Definition at line 266 of file linkgraph.h.
|
friend |
Definition at line 265 of file linkgraph.h.
|
friend |
Definition at line 264 of file linkgraph.h.
|
protected |
Cargo of this component's link graph.
Definition at line 268 of file linkgraph.h.
Referenced by AddNode(), Cargo(), GetLinkGraphDesc, LinkGraph(), Merge(), and RemoveNode().
|
staticconstexpr |
Minimum number of days between subsequent compressions of a LG.
Definition at line 180 of file linkgraph.h.
Referenced by DeleteStaleLinks().
|
protected |
Last time the capacities and supplies were compressed.
Definition at line 269 of file linkgraph.h.
Referenced by GetLinkGraphDesc, LastCompression(), LinkGraph(), Merge(), Monthly(), and ShiftDates().
|
static |
Minimum effective distance for timeout calculation.
Definition at line 174 of file linkgraph.h.
Referenced by DeleteStaleLinks().
|
protected |
Nodes in the component.
Definition at line 270 of file linkgraph.h.
Referenced by AddNode(), Init(), SlLinkgraphNode::Load(), Merge(), operator[](), operator[](), RemoveNode(), SlLinkgraphNode::Save(), ShiftDates(), and Size().
|
staticconstexpr |
Number of days before deleting links served only by vehicles stopped in depot.
Definition at line 177 of file linkgraph.h.
Referenced by DeleteStaleLinks().