# refresh.h

Go to the documentation of this file.

    00001 /* $Id: refresh.h 26283 2014-01-28 19:49:43Z fonsinchen $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    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, uint num_hops = 0);
    00098
    00099   void RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops = 0);
    00100 };
    00101
    00102 #endif // REFRESH_H