]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicletype.h
Use a typedef for the function map in VehicleType
[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         typedef std::map<unsigned, std::string> FunctionMap;
133
134 private:
135         ArticleNumber art_nr;
136         std::string name;
137         bool locomotive;
138         FunctionMap functions;
139         bool swap_direction;
140         float length;
141         float width;
142         float height;
143         AxleArray axles;
144         BogieArray bogies;
145         RodArray rods;
146         std::string object;
147
148 public:
149         VehicleType(const ArticleNumber &);
150
151         const ArticleNumber &get_article_number() const { return art_nr; }
152         const std::string &get_name() const { return name; }
153         bool is_locomotive() const { return locomotive; }
154         unsigned get_max_function() const;
155         const FunctionMap &get_functions() const { return functions; }
156         bool get_swap_direction() const { return swap_direction; }
157         float get_length() const { return length; }
158         float get_width() const { return width; }
159         float get_height() const { return height; }
160         const AxleArray &get_fixed_axles() const { return axles; }
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 };
171
172 } // namespace R2C2
173
174 #endif