1 #ifndef LIBR2C2_TRAINROUTER_H_
2 #define LIBR2C2_TRAINROUTER_H_
5 #include <msp/datafile/objectloader.h>
14 class TrainRouteMetric;
15 class TrainRoutePlanner;
17 class TrainRouter: public TrainAI
20 class Loader: public Msp::DataFile::ObjectLoader<TrainRouter>
23 Loader(TrainRouter &);
25 void route(const std::string &);
31 Train *preceding_train;
33 unsigned sequence_out;
35 SequencePoint(Block &, unsigned);
37 bool is_cleared() const;
41 typedef std::list<const Route *> RouteList;
51 sigc::signal<void, const Route *> signal_route_changed;
52 sigc::signal<void, const TrackChain *> signal_arrived;
53 sigc::signal<void, const TrackChain *> signal_waypoint_reached;
58 RouteList::iterator reserving_route;
60 std::vector<const TrackChain *> waypoints;
61 bool waypoints_changed;
62 std::vector<TrainRouteMetric *> metrics;
64 std::list<SequencePoint> sequence_points;
65 unsigned current_sequence;
66 bool sequence_check_pending;
67 Msp::Time::TimeDelta delay;
68 Msp::Time::TimeDelta duration;
69 Msp::RefPtr<TrainRoutePlanner> planner;
75 void set_priority(int);
76 int get_priority() const { return priority; }
78 bool set_route(const Route *);
79 const Route *get_route() const;
80 unsigned get_current_sequence() const { return current_sequence; }
82 void use_planned_route();
86 void set_destination(const TrackChain &);
87 const TrackChain *get_destination() const { return waypoints.empty() ? 0 : waypoints.back(); }
88 void add_waypoint(const TrackChain &);
89 unsigned get_n_waypoints() const { return waypoints.size(); }
90 const TrackChain &get_waypoint(unsigned) const;
91 const TrainRouteMetric &get_metric(int = -1) const;
92 void set_departure_delay(const Msp::Time::TimeDelta &);
93 const Msp::Time::TimeDelta &get_departure_delay() const { return delay; }
94 void set_trip_duration(const Msp::Time::TimeDelta &);
95 const Msp::Time::TimeDelta &get_trip_duration() const { return duration; }
97 virtual void message(const Message &);
98 virtual void tick(const Msp::Time::TimeDelta &);
100 void save(std::list<Msp::DataFile::Statement> &) const;
103 void block_reserved(Block &, Train *);
104 void train_advanced(Block &);
105 void train_rear_advanced(Block &);
107 void create_metrics();
108 bool create_lead_route();
109 bool is_valid_for_track(const Route &, const TrackIter &) const;
110 bool advance_to_track(RouteList::iterator &, const TrackIter &);
112 static void get_routers(Layout &, std::vector<TrainRouter *> &);
113 static void start_planning(Layout &);
114 static void apply_plan(Layout &, TrainRoutePlanner &);