OpenTTD Source 20250521-master-g82876c25e0
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 <http://www.gnu.org/licenses/>.
6 */
7
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:
28 enum class RefreshFlag : uint8_t {
29 UseNext,
30 HasCargo,
31 WasRefit,
34 };
35
36 using RefreshFlags = EnumBitSet<RefreshFlag, uint8_t>;
37
48
58 struct Hop {
62
67 Hop() {NOT_REACHED();}
68
76
77 constexpr auto operator<=>(const Hop &) const noexcept = default;
78 };
79
80 typedef std::vector<RefitDesc> RefitList;
81 typedef std::set<Hop> HopSet;
82
85 RefitList refit_capacities;
86 HopSet *seen_hops;
90
92
93 bool HandleRefit(CargoType refit_cargo);
94 void ResetRefit();
95 void RefreshStats(const Order *cur, const Order *next);
96 const Order *PredictNextOrder(const Order *cur, const Order *next, RefreshFlags flags, uint num_hops = 0);
97
98 void RefreshLinks(const Order *cur, const Order *next, RefreshFlags flags, uint num_hops = 0);
99};
100
101#endif /* REFRESH_H */
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:23
Enum-as-bit-set wrapper.
Utility to refresh links a consist will visit.
Definition refresh.h:19
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
Definition refresh.h:88
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
Definition refresh.cpp:123
bool HandleRefit(CargoType refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
Definition refresh.cpp:68
void RefreshLinks(const Order *cur, const Order *next, RefreshFlags flags, uint num_hops=0)
Iterate over orders starting at cur and next and refresh links associated with them.
Definition refresh.cpp:243
Vehicle * vehicle
Vehicle for which the links should be refreshed.
Definition refresh.h:83
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.
@ WasRefit
Consist was refit since the last stop where it could interact with cargo.
@ HasCargo
Consist could leave the last stop where it could interact with cargo carrying cargo (i....
@ InAutorefit
Currently doing an autorefit loop. Ignore the first autorefit order.
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
Definition refresh.h:85
const Order * PredictNextOrder(const Order *cur, const Order *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
CargoType cargo
Cargo given in last refit order.
Definition refresh.h:87
CargoArray capacities
Current added capacities per cargo type in the consist.
Definition refresh.h:84
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:86
bool is_full_loading
If the vehicle is full loading.
Definition refresh.h:89
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
void RefreshStats(const Order *cur, const Order *next)
Refresh link stats for the given pair of orders.
Definition refresh.cpp:179
Class for storing amounts of cargo.
Definition cargo_type.h:113
A hop the refresh algorithm might evaluate.
Definition refresh.h:58
OrderID from
Last order where vehicle could interact with cargo or absolute first order.
Definition refresh.h:59
Hop(OrderID from, OrderID to, CargoType cargo)
Real constructor, only use this one.
Definition refresh.h:75
OrderID to
Next order to be processed.
Definition refresh.h:60
Hop()
Default constructor should not be called but has to be visible for usage in std::set.
Definition refresh.h:67
CargoType cargo
Cargo the consist is probably carrying or INVALID_CARGO if unknown.
Definition refresh.h:61
Simulated cargo type and capacity for prediction of future links.
Definition refresh.h:41
CargoType cargo
Cargo type the vehicle will be carrying.
Definition refresh.h:42
uint16_t remaining
Capacity remaining from before the previous refit.
Definition refresh.h:44
uint16_t capacity
Capacity the vehicle will have.
Definition refresh.h:43
Vehicle data structure.