* Update an edge. If mode contains UM_REFRESH refresh the edge to have at * least the given capacity and usage, otherwise add the capacity, usage and travel time. * In any case set the respective update timestamp(s), according to the given * mode. * @param capacity Capacity to be added/updated. * @param usage Usage to be added. * @param travel_time Travel time to be added, in ticks. * @para
| 215 | * @param mode Update mode to be applied. |
| 216 | */ |
| 217 | void LinkGraph::BaseEdge::Update(uint capacity, uint usage, uint32_t travel_time, EdgeUpdateModes modes) |
| 218 | { |
| 219 | assert(this->capacity > 0); |
| 220 | assert(capacity >= usage); |
| 221 | |
| 222 | if (modes.Test(EdgeUpdateMode::Increase)) { |
| 223 | if (this->travel_time_sum == 0) { |
| 224 | this->travel_time_sum = static_cast<uint64_t>(this->capacity + capacity) * travel_time; |
| 225 | } else if (travel_time == 0) { |
| 226 | this->travel_time_sum += this->travel_time_sum / this->capacity * capacity; |
| 227 | } else { |
| 228 | this->travel_time_sum += static_cast<uint64_t>(travel_time) * capacity; |
| 229 | } |
| 230 | this->capacity += capacity; |
| 231 | this->usage += usage; |
| 232 | } else if (modes.Test(EdgeUpdateMode::Refresh)) { |
| 233 | if (this->travel_time_sum == 0) { |
| 234 | this->capacity = std::max(this->capacity, capacity); |
| 235 | this->travel_time_sum = static_cast<uint64_t>(travel_time) * this->capacity; |
| 236 | } else if (capacity > this->capacity) { |
| 237 | this->travel_time_sum = this->travel_time_sum / this->capacity * capacity; |
| 238 | this->capacity = capacity; |
| 239 | } |
| 240 | this->usage = std::max(this->usage, usage); |
| 241 | } |
| 242 | if (modes.Test(EdgeUpdateMode::Unrestricted)) this->last_unrestricted_update = TimerGameEconomy::date; |
| 243 | if (modes.Test(EdgeUpdateMode::Restricted)) this->last_restricted_update = TimerGameEconomy::date; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Resize the component and fill it with empty nodes and edges. Used when |