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 const TrackChain *destination;
61 std::vector<const TrackChain *> waypoints;
62 bool destination_changed;
63 std::vector<TrainRouteMetric *> metrics;
65 std::list<SequencePoint> sequence_points;
66 unsigned current_sequence;
67 bool sequence_check_pending;
68 Msp::Time::TimeDelta delay;
69 Msp::Time::TimeDelta duration;
70 Msp::RefPtr<TrainRoutePlanner> planner;
76 void set_priority(int);
77 int get_priority() const { return priority; }
79 bool set_route(const Route *);
80 const Route *get_route() const;
81 unsigned get_current_sequence() const { return current_sequence; }
86 void set_destination(const TrackChain &);
87 const TrackChain *get_destination() const { return destination; }
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 start_planning(Layout &);