]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trainai.h
Redesign the train activation system
[r2c2.git] / source / libr2c2 / trainai.h
1 #ifndef LIBR2C2_TRAINAI_H_
2 #define LIBR2C2_TRAINAI_H_
3
4 #include <string>
5 #include <sigc++/signal.h>
6 #include <msp/core/variant.h>
7 #include <msp/time/timedelta.h>
8 #include <msp/time/timestamp.h>
9
10 namespace R2C2 {
11
12 class Train;
13
14 /**
15 Base class for train AIs.
16
17 AIs can help the user in various ways, ranging from automatically stopping the
18 train at the end of allocated track to autonomously running a train.
19
20 XXX The timestamp should be removed from tick, but Timetable depends on it
21 */
22 class TrainAI
23 {
24 public:
25         struct Message
26         {
27                 std::string type;
28                 Msp::Variant value;
29
30                 Message(const std::string &t): type(t) { }
31
32                 template<typename T>
33                 Message(const std::string &t, const T &v): type(t), value(v) { }
34         };
35
36         sigc::signal<void, const Message &> signal_event;
37
38 protected:
39         Train &train;
40
41         TrainAI(Train &);
42 public:
43         virtual ~TrainAI();
44
45         virtual void message(const Message &) { }
46         virtual void tick(const Msp::Time::TimeDelta &) = 0;
47         virtual bool has_intent_to_move() const { return false; }
48 };
49
50 } // namespace R2C2
51
52 #endif