OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
13 #include "../core/pool_type.hpp"
14 #include "../station_base.h"
15 #include "../cargotype.h"
16 #include "../timer/timer_game_economy.h"
17 #include "../saveload/saveload.h"
76 return this->dest_node < rhs;
140 return std::binary_search(this->edges.begin(), this->edges.end(), dest);
149 const BaseEdge &operator[](NodeID to)
const
156 std::vector<BaseEdge>::iterator GetEdge(NodeID dest)
158 return std::lower_bound(this->edges.begin(), this->edges.end(), dest);
161 std::vector<BaseEdge>::const_iterator GetEdge(NodeID dest)
const
163 return std::lower_bound(this->edges.begin(), this->edges.end(), dest);
167 typedef std::vector<BaseNode> NodeVector;
186 inline static uint
Scale(uint val, TimerGameEconomy::Date target_age, TimerGameEconomy::Date orig_age)
188 return val > 0 ? std::max(1U, val * target_age.base() / orig_age.base()) : 0;
199 void Init(uint size);
200 void ShiftDates(TimerGameEconomy::Date interval);
230 inline NodeID
Size()
const {
return (NodeID)this->
nodes.size(); }
void SetDemand(uint demand)
Set the node's demand.
A connected component of a link graph.
Pool< LinkGraph, LinkGraphID, 32, 0xFFFF > LinkGraphPool
Type of the pool for link graph components.
TimerGameEconomy::Date last_unrestricted_update
When the unrestricted part of the link was last updated.
void UpdateLocation(TileIndex xy)
Update the node's location on the map.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
uint usage
Usage of the link.
NodeVector nodes
Nodes in the component.
uint demand
Acceptance at the station.
Class for calculation jobs to be run on link graphs.
NodeID dest_node
Destination of the edge.
static constexpr TimerGameEconomy::Date STALE_LINK_DEPOT_TIMEOUT
Number of days before deleting links served only by vehicles stopped in depot.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
uint supply
Supply at the station.
bool HasEdgeTo(NodeID dest) const
Check if an edge to a destination is present.
StationID station
Station ID.
Templated helper to make a type-safe 'typedef' representing a single POD value.
NodeID Size() const
Get the current size of the component.
void UpdateEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Creates an edge if none exists yet or updates an existing edge.
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.
const BaseNode & operator[](NodeID num) const
Get a const reference to a node with the specified id.
EdgeUpdateMode
Special modes for updating links.
TimerGameEconomy::Date last_restricted_update
When the restricted part of the link was last updated.
friend SaveLoadTable GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
TimerGameEconomy::Date last_update
When the supply was last updated.
static constexpr TimerGameEconomy::Date COMPRESSION_INTERVAL
Minimum number of days between subsequent compressions of a LG.
TimerGameEconomy::Date last_compression
Last time the capacities and supplies were compressed.
uint capacity
Capacity of the link.
LinkGraphPool _link_graph_pool
The actual pool with link graphs.
An edge in the link graph.
CargoID Cargo() const
Get the cargo ID this component's link graph refers to.
BaseNode(TileIndex xy=INVALID_TILE, StationID st=INVALID_STATION, uint demand=0)
Create a node or clear it.
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.
TimerGameEconomy::Date LastCompression() const
Get date of last compression.
std::vector< BaseEdge > edges
Sorted list of outgoing edges from this node.
BaseNode & operator[](NodeID num)
Get a node with the specified id.
TimerGameEconomy::Date LastUpdate() const
Get the date of the last update to any part of the edge's capacity.
bool operator<(const BaseEdge &rhs) const
Comparison operator based on dest_node.
Base class for all pools.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates by given interval.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
void UpdateSupply(uint supply)
Update the node's supply and set last_update to the current date.
CargoID cargo
Cargo of this component's link graph.
uint32_t TravelTime() const
Get edge's average travel time.
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
void Update(uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Update an edge.
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Representation of an invalid date.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
TileIndex xy
Location of the station referred to by the node.
void Merge(LinkGraph *other)
Merge a link graph with another one.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
uint64_t travel_time_sum
Sum of the travel times of the link, in ticks.
friend SaveLoadTable GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
LinkGraph(CargoID cargo)
Real constructor.
void AddEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Fill an edge with values from a link.
Base class for all PoolItems.
Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months...
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
BaseEdge(NodeID dest_node=INVALID_NODE)
Create an edge.
static Date date
Current date in days (day counter).