]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trainai.h
Read MFX locomotive name
[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 class TrainAI
21 {
22 public:
23         struct Message
24         {
25                 std::string type;
26                 Msp::Variant value;
27
28                 Message(const std::string &t): type(t) { }
29
30                 template<typename T>
31                 Message(const std::string &t, const T &v): type(t), value(v) { }
32         };
33
34         sigc::signal<void, const Message &> signal_event;
35
36 protected:
37         Train &train;
38
39         TrainAI(Train &);
40 public:
41         virtual ~TrainAI();
42
43         virtual void message(const Message &) { }
44         virtual void tick(const Msp::Time::TimeDelta &) = 0;
45         virtual bool has_intent_to_move() const { return false; }
46 };
47
48 } // namespace R2C2
49
50 #endif