3 This file is part of R²C²
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef LIBR2C2_TRAIN_H_
9 #define LIBR2C2_TRAIN_H_
11 #include <sigc++/signal.h>
12 #include <sigc++/trackable.h>
13 #include <msp/time/timestamp.h>
15 #include "blockiter.h"
16 #include "controller.h"
27 class Train: public sigc::trackable
30 class Loader: public Msp::DataFile::BasicLoader<Train>
39 virtual void finish();
41 void block_hint(unsigned);
42 void name(const std::string &);
43 void real_speed(unsigned, float, float);
44 void route(const std::string &);
46 void vehicle(ArticleNumber);
49 sigc::signal<void, const std::string &> signal_name_changed;
50 sigc::signal<void, const std::string &, float> signal_control_changed;
51 sigc::signal<void, unsigned, bool> signal_function_changed;
52 sigc::signal<void, const Route *> signal_route_changed;
53 sigc::signal<void, Block &> signal_advanced;
54 sigc::signal<void> signal_arrived;
55 sigc::signal<void, const std::string &> signal_status_changed;
63 RouteRef(const Route *, unsigned = 0);
72 void add(float, float);
75 typedef std::list<BlockIter> BlockList;
78 const VehicleType &loco_type;
83 const Train *yielding_to;
84 const Train *preceding_train;
85 std::vector<Vehicle *> vehicles;
87 BlockList::iterator cur_blocks_end;
88 BlockList::iterator clear_blocks_end;
92 Controller *controller;
95 unsigned current_speed_step;
98 Msp::Time::TimeStamp stop_timeout;
100 std::list<RouteRef> routes;
104 Msp::Time::TimeStamp last_entry_time;
107 std::vector<RealSpeed> real_speed;
108 bool accurate_position;
109 float overshoot_dist;
112 Train(Layout &, const VehicleType &, unsigned, const std::string &);
115 Layout &get_layout() const { return layout; }
116 const VehicleType &get_locomotive_type() const { return loco_type; }
117 unsigned get_address() const { return address; }
118 const std::string &get_protocol() const { return protocol; }
119 void set_name(const std::string &);
120 const std::string &get_name() const { return name; }
121 void set_priority(int);
122 void yield_to(const Train &);
123 int get_priority() const { return priority; }
124 const Train *get_preceding_train() const { return preceding_train; }
125 Controller &get_controller() const { return *controller; }
127 void add_vehicle(const VehicleType &);
128 void remove_vehicle(unsigned);
129 unsigned get_n_vehicles() const;
130 Vehicle &get_vehicle(unsigned);
131 const Vehicle &get_vehicle(unsigned) const;
133 void set_control(const std::string &, float);
134 void set_active(bool);
135 void set_function(unsigned, bool);
136 float get_control(const std::string &) const;
137 float get_speed() const;
138 bool is_active() const { return active; }
139 bool get_function(unsigned) const;
140 unsigned get_functions() const { return functions; }
142 void set_timetable(Timetable *);
143 Timetable *get_timetable() { return timetable; }
145 bool set_route(const Route *);
147 bool go_to(const Zone &);
148 bool divert(Track &);
149 const Route *get_route() const;
150 void place(Block &, unsigned);
152 bool is_placed() const { return !blocks.empty(); }
153 bool free_block(Block &);
154 void free_noncritical_blocks();
155 int get_entry_to_block(Block &) const;
156 float get_reserved_distance() const;
158 const std::string &get_status() const { return status; }
160 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
162 void save(std::list<Msp::DataFile::Statement> &) const;
164 void control_changed(const Controller::Control &);
165 void loco_speed_event(unsigned, unsigned, bool);
166 void loco_func_event(unsigned, unsigned, bool);
167 void sensor_event(unsigned, bool);
168 void turnout_path_changed(Track &);
169 void halt_event(bool);
170 void block_reserved(const Block &, const Train *);
172 void check_turnout_paths(bool);
173 float get_reserved_distance_until(const Block *, bool) const;
174 float get_real_speed(unsigned) const;
175 unsigned find_speed_step(float) const;
176 float get_travel_speed() const;
177 void set_status(const std::string &);
178 void release_blocks();
179 void release_blocks(BlockList::iterator, BlockList::iterator);
180 void reverse_blocks(BlockList &) const;
181 bool advance_route(std::list<RouteRef>::iterator &, Track &);
182 Route *create_lead_route(Route *, const Route *);
183 bool is_valid_diversion(const Route &, const TrackIter &);