]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trainai.h
TrainAI framework
[r2c2.git] / source / libr2c2 / trainai.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2011  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_TRAINAI_H_
9 #define LIBR2C2_TRAINAI_H_
10
11 #include <string>
12 #include <sigc++/signal.h>
13 #include <msp/core/variant.h>
14 #include <msp/time/timedelta.h>
15 #include <msp/time/timestamp.h>
16
17 namespace R2C2 {
18
19 class Train;
20
21 /**
22 Base class for train AIs.
23
24 AIs can help the user in various ways, ranging from automatically stopping the
25 train at the end of allocated track to autonomously running a train.
26
27 XXX The timestamp should be removed from tick, but Timetable depends on it
28 */
29 class TrainAI
30 {
31 public:
32         struct Message
33         {
34                 std::string type;
35                 Msp::Variant value;
36
37                 Message(const std::string &t): type(t) { }
38
39                 template<typename T>
40                 Message(const std::string &t, const T &v): type(t), value(v) { }
41         };
42
43         sigc::signal<void, const Message &> signal_event;
44
45 protected:
46         Train &train;
47         std::string tag;
48
49         TrainAI(Train &);
50 public:
51         virtual ~TrainAI();
52
53         void set_tag(const std::string &);
54         const std::string &get_tag() const { return tag; }
55
56         virtual void message(const Message &) { }
57         virtual void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &) { }
58 };
59
60 } // namespace R2C2
61
62 #endif