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