OpenTTD Source 20260621-master-g720d10536d
refresh.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef REFRESH_H
11#define REFRESH_H
12
13#include "../cargo_type.h"
14#include "../vehicle_base.h"
15
20public:
21 static void Run(Vehicle *v, bool allow_merge = true, bool is_full_loading = false);
22
23protected:
35
38
42 struct RefitDesc {
44 uint16_t capacity;
45 uint16_t remaining;
46 RefitDesc(CargoType cargo, uint16_t capacity, uint16_t remaining) :
48 };
49
59 struct Hop {
63
68 Hop() {NOT_REACHED();}
69
77
78 constexpr auto operator<=>(const Hop &) const noexcept = default;
79 };
80
81 typedef std::vector<RefitDesc> RefitList;
82 typedef std::set<Hop> HopSet;
83
86 RefitList refit_capacities;
87 HopSet *seen_hops;
91
93
94 bool HandleRefit(CargoType refit_cargo);
95 void ResetRefit();
98
99 void RefreshLinks(VehicleOrderID cur, VehicleOrderID next, RefreshFlags flags, uint num_hops = 0);
100};
101
102#endif /* REFRESH_H */
Types related to cargoes...
CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
Enum-as-bit-set wrapper.
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
Definition refresh.h:89
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
Definition refresh.cpp:123
VehicleOrderID PredictNextOrder(VehicleOrderID cur, VehicleOrderID next, RefreshFlags flags, uint num_hops=0)
Predict the next order the vehicle will execute and resolve conditionals by recursion and return next...
Definition refresh.cpp:141
void RefreshLinks(VehicleOrderID cur, VehicleOrderID next, RefreshFlags flags, uint num_hops=0)
Iterate over orders starting at cur and next and refresh links associated with them.
Definition refresh.cpp:249
void RefreshStats(VehicleOrderID cur, VehicleOrderID next)
Refresh link stats for the given pair of orders.
Definition refresh.cpp:181
bool HandleRefit(CargoType refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
Definition refresh.cpp:68
Vehicle * vehicle
Vehicle for which the links should be refreshed.
Definition refresh.h:84
RefreshFlag
Various flags about properties of the last examined link that might have an influence on the next one...
Definition refresh.h:28
@ UseNext
There was a conditional jump. Try to use the given next order when looking for a new one.
Definition refresh.h:29
@ WasRefit
Consist was refit since the last stop where it could interact with cargo.
Definition refresh.h:31
@ HasCargo
Consist could leave the last stop where it could interact with cargo carrying cargo (i....
Definition refresh.h:30
@ InAutorefit
Currently doing an autorefit loop. Ignore the first autorefit order.
Definition refresh.h:33
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
Definition refresh.h:86
LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
Constructor for link refreshing algorithm.
Definition refresh.cpp:49
CargoType cargo
Cargo given in last refit order.
Definition refresh.h:88
EnumBitSet< RefreshFlag, uint8_t > RefreshFlags
Bitset of RefreshFlag elements.
Definition refresh.h:37
CargoArray capacities
Current added capacities per cargo type in the consist.
Definition refresh.h:85
HopSet * seen_hops
Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Re...
Definition refresh.h:87
bool is_full_loading
If the vehicle is full loading.
Definition refresh.h:90
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
Definition refresh.cpp:26
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related).
Definition order_type.h:18
Class for storing amounts of cargo.
Definition cargo_type.h:118
A hop the refresh algorithm might evaluate.
Definition refresh.h:59
VehicleOrderID from
Last order where vehicle could interact with cargo or absolute first order.
Definition refresh.h:60
Hop()
Default constructor should not be called but has to be visible for usage in std::set.
Definition refresh.h:68
Hop(VehicleOrderID from, VehicleOrderID to, CargoType cargo)
Real constructor, only use this one.
Definition refresh.h:76
CargoType cargo
Cargo the consist is probably carrying or INVALID_CARGO if unknown.
Definition refresh.h:62
VehicleOrderID to
Next order to be processed.
Definition refresh.h:61
CargoType cargo
Cargo type the vehicle will be carrying.
Definition refresh.h:43
uint16_t remaining
Capacity remaining from before the previous refit.
Definition refresh.h:45
uint16_t capacity
Capacity the vehicle will have.
Definition refresh.h:44
Vehicle data structure.
Base class for all vehicles.