Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef REFRESH_H
00013 #define REFRESH_H
00014
00015 #include "../cargo_type.h"
00016 #include "../vehicle_base.h"
00017 #include <list>
00018 #include <map>
00019 #include <set>
00020
00024 class LinkRefresher {
00025 public:
00026 static void Run(Vehicle *v, bool allow_merge = true);
00027
00028 protected:
00033 enum RefreshFlags {
00034 USE_NEXT,
00035 HAS_CARGO,
00036 WAS_REFIT,
00037 RESET_REFIT
00038 };
00039
00043 struct RefitDesc {
00044 CargoID cargo;
00045 uint16 capacity;
00046 uint16 remaining;
00047 RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
00048 cargo(cargo), capacity(capacity), remaining(remaining) {}
00049 };
00050
00060 struct Hop {
00061 OrderID from;
00062 OrderID to;
00063 CargoID cargo;
00064
00069 Hop() {NOT_REACHED();}
00070
00077 Hop(OrderID from, OrderID to, CargoID cargo) : from(from), to(to), cargo(cargo) {}
00078 bool operator<(const Hop &other) const;
00079 };
00080
00081 typedef std::list<RefitDesc> RefitList;
00082 typedef std::map<CargoID, uint> CapacitiesMap;
00083 typedef std::set<Hop> HopSet;
00084
00085 Vehicle *vehicle;
00086 CapacitiesMap capacities;
00087 RefitList refit_capacities;
00088 HopSet *seen_hops;
00089 CargoID cargo;
00090 bool allow_merge;
00091
00092 LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge);
00093
00094 void HandleRefit(const Order *next);
00095 void ResetRefit();
00096 void RefreshStats(const Order *cur, const Order *next);
00097 const Order *PredictNextOrder(const Order *cur, const Order *next, uint8 flags);
00098
00099 void RefreshLinks(const Order *cur, const Order *next, uint8 flags);
00100 };
00101
00102 #endif // REFRESH_H