]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicletype.h
Add a common base class for tangible objects
[r2c2.git] / source / libr2c2 / vehicletype.h
1 #ifndef LIBR2C2_VEHICLETYPE_H_
2 #define LIBR2C2_VEHICLETYPE_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "geometry.h"
6 #include "objecttype.h"
7
8 namespace R2C2 {
9
10 class VehicleType: public ObjectType
11 {
12 public:
13         class Loader: public Msp::DataFile::DerivedObjectLoader<VehicleType, ObjectType::Loader>
14         {
15         private:
16                 std::map<std::string, unsigned> rod_tags;
17
18         public:
19                 Loader(VehicleType &);
20         private:
21                 void axle();
22                 void bogie();
23                 void function(unsigned, const std::string &);
24                 void height(float);
25                 void length(float);
26                 void rod();
27                 void width(float);
28         };
29
30         struct Axle
31         {
32                 class Loader: public Msp::DataFile::ObjectLoader<Axle>
33                 {
34                 public:
35                         Loader(Axle &);
36                 private:
37                         void position(float);
38                         void wheel_diameter(float);
39                 };
40
41                 float position;
42                 float wheel_dia;
43                 bool powered;
44                 std::string object;
45
46                 Axle();
47         };
48
49         typedef std::vector<Axle> AxleArray;
50
51         struct Bogie
52         {
53                 class Loader: public Msp::DataFile::ObjectLoader<Bogie>
54                 {
55                 public:
56                         Loader(Bogie &);
57                 private:
58                         void axle();
59                         void position(float);
60                 };
61
62                 float position;
63                 AxleArray axles;
64                 std::string object;
65                 bool rotate_object;
66
67                 Bogie();
68         };
69
70         typedef std::vector<Bogie> BogieArray;
71
72         struct Rod
73         {
74                 enum Anchor
75                 {
76                         BODY,
77                         AXLE,
78                         BOGIE_AXLE,
79                         ROD
80                 };
81
82                 enum Limit
83                 {
84                         FIXED,
85                         ROTATE,
86                         SLIDE_X
87                 };
88
89                 class Loader: public Msp::DataFile::ObjectLoader<Rod>
90                 {
91                 private:
92                         const std::map<std::string, unsigned> &tags;
93                         std::string tag;
94
95                 public:
96                         Loader(Rod &, const std::map<std::string, unsigned> &);
97                         const std::string &get_tag() const { return tag; }
98                 private:
99                         void connect(const std::string &, float, float, float, float);
100                         void limit(Limit);
101                         void pivot_body();
102                         void pivot_axle(unsigned);
103                         void pivot_bogie_axle(unsigned, unsigned);
104                         void pivot_rod(const std::string &);
105                         void position(float, float, float);
106                         void set_tag(const std::string &);
107                 };
108
109                 Anchor pivot;
110                 unsigned pivot_index;
111                 unsigned pivot_index2;
112                 Vector pivot_point;
113                 Limit limit;
114                 int connect_index;
115                 Vector connect_point;
116                 Vector connect_offset;
117                 std::string object;
118                 bool mirror_object;
119
120                 Rod();
121         };
122
123         typedef std::vector<Rod> RodArray;
124
125         typedef std::map<unsigned, std::string> FunctionMap;
126
127 private:
128         bool locomotive;
129         FunctionMap functions;
130         bool swap_direction;
131         float length;
132         float width;
133         float height;
134         AxleArray axles;
135         BogieArray bogies;
136         RodArray rods;
137         std::string object;
138         bool rotate_object;
139
140 public:
141         VehicleType(const ArticleNumber &);
142
143         bool is_locomotive() const { return locomotive; }
144         unsigned get_max_function() const;
145         const FunctionMap &get_functions() const { return functions; }
146         bool get_swap_direction() const { return swap_direction; }
147         float get_length() const { return length; }
148         float get_width() const { return width; }
149         float get_height() const { return height; }
150         const AxleArray &get_fixed_axles() const { return axles; }
151         const Axle &get_fixed_axle(unsigned) const;
152         const BogieArray &get_bogies() const { return bogies; }
153         const Bogie &get_bogie(unsigned) const;
154         const Axle &get_bogie_axle(unsigned, unsigned) const;
155         const RodArray &get_rods() const { return rods; }
156         const Rod &get_rod(unsigned) const;
157         float get_front_axle_offset() const;
158         float get_back_axle_offset() const;
159         const std::string &get_object() const { return object; }
160         bool get_rotate_object() const { return rotate_object; }
161 };
162
163 } // namespace R2C2
164
165 #endif