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