]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicletype.h
Rename various get_axle functions to get_fixed_axle
[r2c2.git] / source / libr2c2 / vehicletype.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2010-2011  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         typedef std::vector<Axle> AxleArray;
57
58         struct Bogie
59         {
60                 class Loader: public Msp::DataFile::ObjectLoader<Bogie>
61                 {
62                 public:
63                         Loader(Bogie &);
64                 private:
65                         void axle();
66                         void position(float);
67                 };
68
69                 float position;
70                 AxleArray axles;
71                 std::string object;
72                 bool rotate_object;
73
74                 Bogie();
75         };
76
77         typedef std::vector<Bogie> BogieArray;
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<Rod> RodArray;
131
132 private:
133         ArticleNumber art_nr;
134         std::string name;
135         bool locomotive;
136         std::map<unsigned, std::string> functions;
137         float length;
138         float width;
139         float height;
140         AxleArray axles;
141         BogieArray bogies;
142         RodArray rods;
143         std::string object;
144
145 public:
146         VehicleType(const ArticleNumber &);
147
148         const ArticleNumber &get_article_number() const { return art_nr; }
149         const std::string &get_name() const { return name; }
150         bool is_locomotive() const { return locomotive; }
151         unsigned get_max_function() const;
152         const std::map<unsigned, std::string> &get_functions() const { return functions; }
153         float get_length() const { return length; }
154         float get_width() const { return width; }
155         float get_height() const { return height; }
156         const AxleArray &get_fixed_axles() const { return axles; }
157         const Axle &get_fixed_axle(unsigned) const;
158         const BogieArray &get_bogies() const { return bogies; }
159         const Bogie &get_bogie(unsigned) const;
160         const Axle &get_bogie_axle(unsigned, unsigned) const;
161         const RodArray &get_rods() const { return rods; }
162         const Rod &get_rod(unsigned) const;
163         float get_front_axle_offset() const;
164         float get_back_axle_offset() const;
165         const std::string &get_object() const { return object; }
166 };
167
168 } // namespace R2C2
169
170 #endif