OpenTTD
refresh.h
Go to the documentation of this file.
1 /* $Id: refresh.h 27614 2016-07-10 12:17:00Z fonsinchen $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef REFRESH_H
13 #define REFRESH_H
14 
15 #include "../cargo_type.h"
16 #include "../vehicle_base.h"
17 #include <vector>
18 #include <map>
19 #include <set>
20 
25 public:
26  static void Run(Vehicle *v, bool allow_merge = true, bool is_full_loading = false);
27 
28 protected:
33  enum RefreshFlags {
39  };
40 
44  struct RefitDesc {
46  uint16 capacity;
47  uint16 remaining;
48  RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
49  cargo(cargo), capacity(capacity), remaining(remaining) {}
50  };
51 
61  struct Hop {
62  OrderID from;
63  OrderID to;
65 
70  Hop() {NOT_REACHED();}
71 
78  Hop(OrderID from, OrderID to, CargoID cargo) : from(from), to(to), cargo(cargo) {}
79  bool operator<(const Hop &other) const;
80  };
81 
82  typedef std::vector<RefitDesc> RefitList;
83  typedef std::set<Hop> HopSet;
84 
87  RefitList refit_capacities;
88  HopSet *seen_hops;
90  bool allow_merge;
92 
93  LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading);
94 
95  bool HandleRefit(CargoID refit_cargo);
96  void ResetRefit();
97  void RefreshStats(const Order *cur, const Order *next);
98  const Order *PredictNextOrder(const Order *cur, const Order *next, uint8 flags, uint num_hops = 0);
99 
100  void RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops = 0);
101 };
102 
103 #endif /* REFRESH_H */
CargoID cargo
Cargo the consist is probably carrying or CT_INVALID if unknown.
Definition: refresh.h:64
OrderID from
Last order where vehicle could interact with cargo or absolute first order.
Definition: refresh.h:62
Consist had a chance to load since the last refit and the refit capacities can be reset...
Definition: refresh.h:37
void RefreshStats(const Order *cur, const Order *next)
Refresh link stats for the given pair of orders.
Definition: refresh.cpp:203
CargoID cargo
Cargo given in last refit order.
Definition: refresh.h:89
bool is_full_loading
If the vehicle is full loading.
Definition: refresh.h:91
Vehicle data structure.
Definition: vehicle_base.h:212
Hop()
Default constructor should not be called but has to be visible for usage in std::set.
Definition: refresh.h:70
uint16 capacity
Capacity the vehicle will have.
Definition: refresh.h:46
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
Definition: refresh.cpp:147
CargoID cargo
Cargo type the vehicle will be carrying.
Definition: refresh.h:45
Consist could leave the last stop where it could interact with cargo carrying cargo (i...
Definition: refresh.h:35
Vehicle * vehicle
Vehicle for which the links should be refreshed.
Definition: refresh.h:85
uint capacities[NUM_CARGO]
Current added capacities per cargo ID in the consist.
Definition: refresh.h:86
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
Definition: refresh.h:90
Hop(OrderID from, OrderID to, CargoID cargo)
Real constructor, only use this one.
Definition: refresh.h:78
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:28
OrderID to
Next order to be processed.
Definition: refresh.h:63
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:88
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:165
Currently doing an autorefit loop. Ignore the first autorefit order.
Definition: refresh.h:38
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:261
A hop the refresh algorithm might evaluate.
Definition: refresh.h:61
LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
Constructor for link refreshing algorithm.
Definition: refresh.cpp:71
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
Definition: refresh.h:87
RefreshFlags
Various flags about properties of the last examined link that might have an influence on the next one...
Definition: refresh.h:33
bool HandleRefit(CargoID refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
Definition: refresh.cpp:92
There was a conditional jump. Try to use the given next order when looking for a new one...
Definition: refresh.h:34
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Simulated cargo type and capacity for prediction of future links.
Definition: refresh.h:44
uint16 remaining
Capacity remaining from before the previous refit.
Definition: refresh.h:47
Consist was refit since the last stop where it could interact with cargo.
Definition: refresh.h:36
Utility to refresh links a consist will visit.
Definition: refresh.h:24