]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/train.h
b84844aa050a999ddeeb5b93cb8ce97c5666ab46
[r2c2.git] / source / libmarklin / train.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_TRAIN_H_
9 #define LIBMARKLIN_TRAIN_H_
10
11 #include <sigc++/signal.h>
12 #include <sigc++/trackable.h>
13 #include <msp/time/timestamp.h>
14 #include "block.h"
15
16 namespace Marklin {
17
18 class Locomotive;
19 class Sensor;
20 class TrafficManager;
21
22 class Train: public sigc::trackable
23 {
24 public:
25         class Loader: public Msp::DataFile::BasicLoader<Train>
26         {
27         public:
28                 Loader(Train &);
29         };
30
31 private:
32         struct BlockRef
33         {
34                 Block *block;
35                 unsigned entry;
36
37                 BlockRef(Block *s, unsigned e): block(s), entry(e) { }
38         };
39
40         TrafficManager &trfc_mgr;
41         std::string name;
42         Locomotive &loco;
43         std::list<BlockRef> cur_blocks;
44         std::list<BlockRef> rsv_blocks;
45         unsigned target_speed;
46         Msp::Time::TimeStamp try_reserve;
47         std::string status;
48
49         Msp::Time::TimeStamp last_entry_time;
50         float travel_dist;
51         unsigned travel_speed;
52         bool pure_speed;
53         float speed_scale;
54         float speed_scale_weight;
55
56         Track *cur_track;
57         unsigned cur_track_ep;
58         float offset;
59         Point pos;
60
61 public:
62         sigc::signal<void, const std::string &> signal_name_changed;
63         sigc::signal<void, const std::string &> signal_status_changed;
64
65         Train(TrafficManager &, Locomotive &);
66
67         void set_name(const std::string &);
68         void set_speed(unsigned);
69         const std::string &get_name() const { return name; }
70         Locomotive &get_locomotive() const { return loco; }
71         const std::string &get_status() const { return status; }
72         const Point &get_position() const { return pos; }
73         void place(Block *, unsigned);
74         bool free_block(Block *);
75         void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
76         void save(std::list<Msp::DataFile::Statement> &) const;
77 private:
78         void sensor_event(bool, Sensor *);
79         unsigned reserve_more();
80         void update_speed();
81         void set_status(const std::string &);
82         void set_position(const Block::Endpoint &);
83 };
84
85 } // namespace Marklin
86
87 #endif