OpenTTD
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 #include <vector>
16 #include <map>
17 #include <set>
18 
23 public:
24  static void Run(Vehicle *v, bool allow_merge = true, bool is_full_loading = false);
25 
26 protected:
31  enum RefreshFlags {
37  };
38 
42  struct RefitDesc {
44  uint16 capacity;
45  uint16 remaining;
46  RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
47  cargo(cargo), capacity(capacity), remaining(remaining) {}
48  };
49 
59  struct Hop {
60  OrderID from;
61  OrderID to;
63 
68  Hop() {NOT_REACHED();}
69 
76  Hop(OrderID from, OrderID to, CargoID cargo) : from(from), to(to), cargo(cargo) {}
77  bool operator<(const Hop &other) const;
78  };
79 
80  typedef std::vector<RefitDesc> RefitList;
81  typedef std::set<Hop> HopSet;
82 
85  RefitList refit_capacities;
86  HopSet *seen_hops;
88  bool allow_merge;
90 
91  LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading);
92 
93  bool HandleRefit(CargoID refit_cargo);
94  void ResetRefit();
95  void RefreshStats(const Order *cur, const Order *next);
96  const Order *PredictNextOrder(const Order *cur, const Order *next, uint8 flags, uint num_hops = 0);
97 
98  void RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops = 0);
99 };
100 
101 #endif /* REFRESH_H */
CargoID cargo
Cargo the consist is probably carrying or CT_INVALID if unknown.
Definition: refresh.h:62
OrderID from
Last order where vehicle could interact with cargo or absolute first order.
Definition: refresh.h:60
Consist had a chance to load since the last refit and the refit capacities can be reset...
Definition: refresh.h:35
void RefreshStats(const Order *cur, const Order *next)
Refresh link stats for the given pair of orders.
Definition: refresh.cpp:201
CargoID cargo
Cargo given in last refit order.
Definition: refresh.h:87
bool is_full_loading
If the vehicle is full loading.
Definition: refresh.h:89
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
Vehicle data structure.
Definition: vehicle_base.h:210
Hop()
Default constructor should not be called but has to be visible for usage in std::set.
Definition: refresh.h:68
uint16 capacity
Capacity the vehicle will have.
Definition: refresh.h:44
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
Definition: refresh.cpp:145
CargoID cargo
Cargo type the vehicle will be carrying.
Definition: refresh.h:43
Consist could leave the last stop where it could interact with cargo carrying cargo (i...
Definition: refresh.h:33
Vehicle * vehicle
Vehicle for which the links should be refreshed.
Definition: refresh.h:83
uint capacities[NUM_CARGO]
Current added capacities per cargo ID in the consist.
Definition: refresh.h:84
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
Definition: refresh.h:88
Hop(OrderID from, OrderID to, CargoID cargo)
Real constructor, only use this one.
Definition: refresh.h:76
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
OrderID to
Next order to be processed.
Definition: refresh.h:61
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
const Order * PredictNextOrder(const Order *cur, const Order *next, uint8 flags, uint num_hops=0)
Predict the next order the vehicle will execute and resolve conditionals by recursion and return next...
Definition: refresh.cpp:163
Currently doing an autorefit loop. Ignore the first autorefit order.
Definition: refresh.h:36
void RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops=0)
Iterate over orders starting at cur and next and refresh links associated with them.
Definition: refresh.cpp:259
A hop the refresh algorithm might evaluate.
Definition: refresh.h:59
LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
Constructor for link refreshing algorithm.
Definition: refresh.cpp:69
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
Definition: refresh.h:85
RefreshFlags
Various flags about properties of the last examined link that might have an influence on the next one...
Definition: refresh.h:31
bool HandleRefit(CargoID refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
Definition: refresh.cpp:90
There was a conditional jump. Try to use the given next order when looking for a new one...
Definition: refresh.h:32
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Simulated cargo type and capacity for prediction of future links.
Definition: refresh.h:42
uint16 remaining
Capacity remaining from before the previous refit.
Definition: refresh.h:45
Consist was refit since the last stop where it could interact with cargo.
Definition: refresh.h:34
Utility to refresh links a consist will visit.
Definition: refresh.h:22