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(); }
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Class for calculation jobs to be run on link graphs.
A connected component of a link graph.
LinkGraph(CargoID cargo)
Real constructor.
const BaseNode & operator[](NodeID num) const
Get a const reference to a node with the specified id.
void Merge(LinkGraph *other)
Merge a link graph with another one.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
CargoID cargo
Cargo of this component's link graph.
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
NodeVector nodes
Nodes in the component.
friend SaveLoadTable GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates by given interval.
TimerGameEconomy::Date LastCompression() const
Get date of last compression.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
NodeID Size() const
Get the current size of the component.
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
BaseNode & operator[](NodeID num)
Get a node with the specified id.
static constexpr TimerGameEconomy::Date STALE_LINK_DEPOT_TIMEOUT
Number of days before deleting links served only by vehicles stopped in depot.
static constexpr TimerGameEconomy::Date COMPRESSION_INTERVAL
Minimum number of days between subsequent compressions of a LG.
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.
CargoID Cargo() const
Get the cargo ID this component's link graph refers to.
friend SaveLoadTable GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
TimerGameEconomy::Date last_compression
Last time the capacities and supplies were compressed.
LinkGraph()
Bare constructor, only for save/load.
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Representation of an invalid date.
Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months...
static Date date
Current date in days (day counter).
Pool< LinkGraph, LinkGraphID, 32, 0xFFFF > LinkGraphPool
Type of the pool for link graph components.
LinkGraphPool _link_graph_pool
The actual pool with link graphs.
Declaration of link graph types used for cargo distribution.
EdgeUpdateMode
Special modes for updating links.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
An edge in the link graph.
TimerGameEconomy::Date last_restricted_update
When the restricted part of the link was last updated.
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.
uint32_t TravelTime() const
Get edge's average travel time.
uint64_t travel_time_sum
Sum of the travel times of the link, in ticks.
NodeID dest_node
Destination of the edge.
uint usage
Usage of the link.
BaseEdge(NodeID dest_node=INVALID_NODE)
Create an edge.
TimerGameEconomy::Date last_unrestricted_update
When the unrestricted part of the link was last updated.
void Update(uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Update an edge.
uint capacity
Capacity of the link.
StationID station
Station ID.
void SetDemand(uint demand)
Set the node's demand.
TimerGameEconomy::Date last_update
When the supply was last updated.
void AddEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Fill an edge with values from a link.
void UpdateLocation(TileIndex xy)
Update the node's location on the map.
std::vector< BaseEdge > edges
Sorted list of outgoing edges from this node.
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.
uint supply
Supply at the station.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
TileIndex xy
Location of the station referred to by the node.
uint demand
Acceptance at the station.
BaseNode(TileIndex xy=INVALID_TILE, StationID st=INVALID_STATION, uint demand=0)
Create a node or clear it.
bool HasEdgeTo(NodeID dest) const
Check if an edge to a destination is present.
void UpdateSupply(uint supply)
Update the node's supply and set last_update to the current date.
Base class for all PoolItems.
Base class for all pools.
Templated helper to make a type-safe 'typedef' representing a single POD value.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.