| 88 | * in a separate thread. |
| 89 | */ |
| 90 | struct BaseNode { |
| 91 | uint supply = 0; ///< Supply at the station. |
| 92 | uint demand = 0; ///< Acceptance at the station. |
| 93 | StationID station = StationID::Invalid(); ///< Station ID. |
| 94 | TileIndex xy = INVALID_TILE; ///< Location of the station referred to by the node. |
| 95 | TimerGameEconomy::Date last_update{}; ///< When the supply was last updated. |
| 96 | |
| 97 | std::vector<BaseEdge> edges; ///< Sorted list of outgoing edges from this node. |
| 98 | |
| 99 | BaseNode(TileIndex xy = INVALID_TILE, StationID st = StationID::Invalid(), uint demand = 0); |
| 100 | |
| 101 | /** |
| 102 | * Update the node's supply and set last_update to the current date. |
| 103 | * @param supply Supply to be added. |
| 104 | */ |
| 105 | void UpdateSupply(uint supply) |
| 106 | { |
| 107 | this->supply += supply; |
| 108 | this->last_update = TimerGameEconomy::date; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Update the node's location on the map. |
| 113 | * @param xy New location. |
| 114 | */ |
| 115 | void UpdateLocation(TileIndex xy) |
| 116 | { |
| 117 | this->xy = xy; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Set the node's demand. |
| 122 | * @param demand New demand for the node. |
| 123 | */ |
| 124 | void SetDemand(uint demand) |
| 125 | { |
| 126 | this->demand = demand; |
| 127 | } |
| 128 | |
| 129 | void AddEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes); |
| 130 | void UpdateEdge(NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes); |
| 131 | void RemoveEdge(NodeID to); |
| 132 | |
| 133 | /** |
| 134 | * Check if an edge to a destination is present. |
| 135 | * @param dest Wanted edge destination. |
| 136 | * @return True if an edge is present. |
| 137 | */ |
| 138 | bool HasEdgeTo(NodeID dest) const |
| 139 | { |
| 140 | return std::binary_search(this->edges.begin(), this->edges.end(), dest); |
| 141 | } |
| 142 | |
| 143 | BaseEdge &operator[](NodeID to) |
| 144 | { |
| 145 | assert(this->HasEdgeTo(to)); |
| 146 | return *GetEdge(to); |
| 147 | } |