MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / IncreaseStats

Function IncreaseStats

src/station_cmd.cpp:4262–4306  ·  view source on GitHub ↗

* Increase capacity for a link stat given by station cargo and next hop. * @param st Station to get the link stats from. * @param cargo Cargo to increase stat for. * @param next_station_id Station the consist will be travelling to next. * @param capacity Capacity to add to link stat. * @param usage Usage to add to link stat. * @param mode Update mode to be applied. */

Source from the content-addressed store, hash-verified

4260 * @param mode Update mode to be applied.
4261 */
4262void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes)
4263{
4264 GoodsEntry &ge1 = st->goods[cargo];
4265 Station *st2 = Station::Get(next_station_id);
4266 GoodsEntry &ge2 = st2->goods[cargo];
4267 LinkGraph *lg = nullptr;
4268 if (ge1.link_graph == LinkGraphID::Invalid()) {
4269 if (ge2.link_graph == LinkGraphID::Invalid()) {
4270 if (LinkGraph::CanAllocateItem()) {
4271 lg = new LinkGraph(cargo);
4272 LinkGraphSchedule::instance.Queue(lg);
4273 ge2.link_graph = lg->index;
4274 ge2.node = lg->AddNode(st2);
4275 } else {
4276 Debug(misc, 0, "Can't allocate link graph");
4277 }
4278 } else {
4279 lg = LinkGraph::Get(ge2.link_graph);
4280 }
4281 if (lg) {
4282 ge1.link_graph = lg->index;
4283 ge1.node = lg->AddNode(st);
4284 }
4285 } else if (ge2.link_graph == LinkGraphID::Invalid()) {
4286 lg = LinkGraph::Get(ge1.link_graph);
4287 ge2.link_graph = lg->index;
4288 ge2.node = lg->AddNode(st2);
4289 } else {
4290 lg = LinkGraph::Get(ge1.link_graph);
4291 if (ge1.link_graph != ge2.link_graph) {
4292 LinkGraph *lg2 = LinkGraph::Get(ge2.link_graph);
4293 if (lg->Size() < lg2->Size()) {
4294 LinkGraphSchedule::instance.Dequeue(lg);
4295 lg2->Merge(lg); // Updates GoodsEntries of lg
4296 lg = lg2;
4297 } else {
4298 LinkGraphSchedule::instance.Dequeue(lg2);
4299 lg->Merge(lg2); // Updates GoodsEntries of lg2
4300 }
4301 }
4302 }
4303 if (lg != nullptr) {
4304 (*lg)[ge1.node].UpdateEdge(ge2.node, capacity, usage, time, modes);
4305 }
4306}
4307
4308/**
4309 * Increase capacity for all link stats associated with vehicles in the given consist.

Callers 2

BeginLoadingMethod · 0.85
RefreshStatsMethod · 0.85

Calls 9

InvalidFunction · 0.85
QueueMethod · 0.80
DequeueMethod · 0.80
UpdateEdgeMethod · 0.80
StoredCountMethod · 0.80
AddNodeMethod · 0.45
SizeMethod · 0.45
MergeMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected