]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicletype.h
Store all axles in a single array
[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                 virtual void finish();
22                 void axle();
23                 void bogie();
24                 void function(unsigned, const std::string &);
25                 void height(float);
26                 void length(float);
27                 void rod();
28                 void width(float);
29         };
30
31         struct Bogie;
32
33         struct Axle
34         {
35                 class Loader: public Msp::DataFile::ObjectLoader<Axle>
36                 {
37                 public:
38                         Loader(Axle &);
39                 private:
40                         void position(float);
41                         void wheel_diameter(float);
42                 };
43
44                 unsigned index;
45                 Bogie *bogie;
46                 float local_position;
47                 float position;
48                 float wheel_dia;
49                 bool powered;
50                 std::string object;
51
52                 Axle();
53         };
54
55         struct Bogie
56         {
57                 class Loader: public Msp::DataFile::ObjectLoader<Bogie>
58                 {
59                 private:
60                         VehicleType &parent;
61
62                 public:
63                         Loader(VehicleType &, Bogie &);
64                 private:
65                         void axle();
66                         void position(float);
67                 };
68
69                 unsigned index;
70                 float position;
71                 unsigned first_axle;
72                 std::vector<Axle *> axles;
73                 std::string object;
74                 bool rotate_object;
75
76                 Bogie();
77         };
78
79         struct Rod
80         {
81                 enum Anchor
82                 {
83                         BODY,
84                         AXLE,
85                         BOGIE_AXLE,
86                         ROD
87                 };
88
89                 enum Limit
90                 {
91                         FIXED,
92                         ROTATE,
93                         SLIDE_X
94                 };
95
96                 class Loader: public Msp::DataFile::ObjectLoader<Rod>
97                 {
98                 private:
99                         const std::map<std::string, unsigned> &tags;
100                         std::string tag;
101
102                 public:
103                         Loader(Rod &, const std::map<std::string, unsigned> &);
104                         const std::string &get_tag() const { return tag; }
105                 private:
106                         void connect(const std::string &, float, float, float, float);
107                         void limit(Limit);
108                         void pivot_body();
109                         void pivot_axle(unsigned);
110                         void pivot_bogie_axle(unsigned, unsigned);
111                         void pivot_rod(const std::string &);
112                         void position(float, float, float);
113                         void set_tag(const std::string &);
114                 };
115
116                 Anchor pivot;
117                 unsigned pivot_index;
118                 unsigned pivot_index2;
119                 Vector pivot_point;
120                 Limit limit;
121                 int connect_index;
122                 Vector connect_point;
123                 Vector connect_offset;
124                 std::string object;
125                 bool mirror_object;
126
127                 Rod();
128         };
129
130         typedef std::vector<Axle> AxleArray;
131         typedef std::vector<Bogie> BogieArray;
132         typedef std::vector<Rod> RodArray;
133         typedef std::map<unsigned, std::string> FunctionMap;
134
135 private:
136         bool locomotive;
137         FunctionMap functions;
138         bool swap_direction;
139         float length;
140         float width;
141         float height;
142         AxleArray axles;
143         std::vector<Axle *> fixed_axles;
144         BogieArray bogies;
145         RodArray rods;
146         std::string object;
147         bool rotate_object;
148
149 public:
150         VehicleType(const ArticleNumber &);
151
152         bool is_locomotive() const { return locomotive; }
153         unsigned get_max_function() const;
154         const FunctionMap &get_functions() const { return functions; }
155         bool get_swap_direction() const { return swap_direction; }
156         float get_length() const { return length; }
157         float get_width() const { return width; }
158         float get_height() const { return height; }
159         const AxleArray &get_axles() const { return axles; }
160         const Axle &get_axle(unsigned) const;
161         const Axle &get_fixed_axle(unsigned) const;
162         const BogieArray &get_bogies() const { return bogies; }
163         const Bogie &get_bogie(unsigned) const;
164         const Axle &get_bogie_axle(unsigned, unsigned) const;
165         const RodArray &get_rods() const { return rods; }
166         const Rod &get_rod(unsigned) const;
167         float get_front_axle_offset() const;
168         float get_back_axle_offset() const;
169         const std::string &get_object() const { return object; }
170         bool get_rotate_object() const { return rotate_object; }
171 };
172
173 } // namespace R2C2
174
175 #endif