1 #ifndef LIBR2C2_TRAIN_H_
2 #define LIBR2C2_TRAIN_H_
4 #include <sigc++/signal.h>
5 #include <sigc++/trackable.h>
6 #include <msp/datafile/objectloader.h>
7 #include <msp/time/timestamp.h>
10 #include "controller.h"
20 class Train: public sigc::trackable
23 class Loader: public Msp::DataFile::ObjectLoader<Train>
32 virtual void finish();
34 void block_hint(unsigned);
35 void name(const std::string &);
36 void quantized_speed();
39 void vehicle(ArticleNumber);
42 sigc::signal<void, const std::string &> signal_name_changed;
43 sigc::signal<void, const std::string &, float> signal_control_changed;
44 sigc::signal<void, unsigned, bool> signal_function_changed;
45 sigc::signal<void, TrainAI &, const TrainAI::Message &> signal_ai_event;
46 sigc::signal<void, Block &> signal_advanced;
49 typedef std::list<BlockIter> BlockList;
52 const VehicleType &loco_type;
56 const Train *preceding_train;
57 std::vector<Vehicle *> vehicles;
59 BlockList::iterator cur_blocks_end;
64 Controller *controller;
65 std::list<TrainAI *> ais;
67 unsigned current_speed_step;
70 Msp::Time::TimeStamp stop_timeout;
73 Msp::Time::TimeStamp last_entry_time;
76 SpeedQuantizer *speed_quantizer;
77 bool accurate_position;
81 Train(Layout &, const VehicleType &, unsigned, const std::string &);
84 Layout &get_layout() const { return layout; }
85 const VehicleType &get_locomotive_type() const { return loco_type; }
86 unsigned get_address() const { return address; }
87 const std::string &get_protocol() const { return protocol; }
88 void set_name(const std::string &);
89 const std::string &get_name() const { return name; }
90 const Train *get_preceding_train() const { return preceding_train; }
91 Controller &get_controller() const { return *controller; }
93 void add_vehicle(const VehicleType &);
94 void remove_vehicle(unsigned);
95 unsigned get_n_vehicles() const;
96 Vehicle &get_vehicle(unsigned);
97 const Vehicle &get_vehicle(unsigned) const;
99 void set_control(const std::string &, float);
100 void set_active(bool);
101 void set_function(unsigned, bool);
102 float get_control(const std::string &) const;
103 float get_speed() const;
104 float get_quantized_speed() const;
105 unsigned get_speed_step() const { return current_speed_step; }
106 bool is_active() const { return active; }
107 bool get_function(unsigned) const;
108 unsigned get_functions() const { return functions; }
110 void add_ai(TrainAI &);
111 void remove_ai(TrainAI &);
112 void ai_message(const TrainAI::Message &);
115 T *get_ai_of_type() const
117 for(std::list<TrainAI *>::const_iterator i=ais.begin(); i!=ais.end(); ++i)
118 if(T *ai = dynamic_cast<T *>(*i))
123 void place(Block &, unsigned);
125 bool is_placed() const { return !blocks.empty(); }
126 void stop_at(Block *);
127 bool free_block(Block &);
128 void free_noncritical_blocks();
129 const BlockIter &get_head_block() const;
130 const BlockIter &get_tail_block() const;
131 int get_entry_to_block(const Block &) const;
132 float get_reserved_distance() const;
134 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
136 void save(std::list<Msp::DataFile::Statement> &) const;
138 void control_changed(const Controller::Control &);
139 void loco_speed_event(unsigned, unsigned, bool);
140 void loco_func_event(unsigned, unsigned, bool);
141 void block_state_changed(Block &, Block::State);
142 void turnout_path_changed(Track &);
143 void halt_event(bool);
144 void block_reserved(const Block &, const Train *);
148 float get_reserved_distance_until(const Block *, bool) const;
149 void release_blocks();
150 void release_blocks(BlockList::iterator, BlockList::iterator);
151 void reverse_blocks(BlockList &) const;