OpenTTD: src/linkgraph/refresh.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
24 class LinkRefresher {
25 public:
26 static void Run(Vehicle *v, bool allow_merge = true, bool is_full_loading = false);
27
28 protected:
33 enum RefreshFlags {
34 USE_NEXT,
35 HAS_CARGO,
36 WAS_REFIT,
37 RESET_REFIT,
38 IN_AUTOREFIT,
39 };
40
44 struct RefitDesc {
45 CargoID cargo;
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;
64 CargoID cargo;
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
85 Vehicle *vehicle;
86 uint capacities[NUM_CARGO];
87 RefitList refit_capacities;
88 HopSet *seen_hops;
89 CargoID cargo;
90 bool allow_merge;
91 bool is_full_loading;
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 */