]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/vehicletype.h
Also store gauge in VehicleType
[r2c2.git] / source / libr2c2 / vehicletype.h
index 33d7d6590dba03fdec299a0e4932a5f1e1528f21..789aeb3e59e7a6e8de0bce6c4b681573c19ff092 100644 (file)
@@ -1,39 +1,40 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010-2011  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #ifndef LIBR2C2_VEHICLETYPE_H_
 #define LIBR2C2_VEHICLETYPE_H_
 
 #include <msp/datafile/objectloader.h>
-#include "articlenumber.h"
 #include "geometry.h"
+#include "objecttype.h"
 
 namespace R2C2 {
 
-class VehicleType
+class VehicleType: public ObjectType
 {
+private:
+       typedef std::map<std::string, unsigned> TagMap;
+
 public:
-       class Loader: public Msp::DataFile::ObjectLoader<VehicleType>
+       class Loader: public Msp::DataFile::DerivedObjectLoader<VehicleType, ObjectType::Loader>
        {
        private:
-               std::map<std::string, unsigned> rod_tags;
+               TagMap rod_tags;
 
        public:
                Loader(VehicleType &);
        private:
+               virtual void finish();
                void axle();
                void bogie();
                void function(unsigned, const std::string &);
+               void gauge(float);
                void height(float);
                void length(float);
-               void rod();
+               void mirror_rods();
+               void rod(const std::string &);
                void width(float);
        };
 
+       struct Bogie;
+
        struct Axle
        {
                class Loader: public Msp::DataFile::ObjectLoader<Axle>
@@ -45,6 +46,9 @@ public:
                        void wheel_diameter(float);
                };
 
+               unsigned index;
+               Bogie *bogie;
+               float local_position;
                float position;
                float wheel_dia;
                bool powered;
@@ -53,109 +57,141 @@ public:
                Axle();
        };
 
-       typedef std::vector<Axle> AxleArray;
-
        struct Bogie
        {
                class Loader: public Msp::DataFile::ObjectLoader<Bogie>
                {
+               private:
+                       VehicleType &parent;
+
                public:
-                       Loader(Bogie &);
+                       Loader(VehicleType &, Bogie &);
                private:
                        void axle();
                        void position(float);
                };
 
+               unsigned index;
                float position;
-               AxleArray axles;
+               unsigned first_axle;
+               std::vector<Axle *> axles;
                std::string object;
                bool rotate_object;
 
                Bogie();
        };
 
-       typedef std::vector<Bogie> BogieArray;
-
-       struct Rod
+       struct RodConstraint
        {
-               enum Anchor
+               enum Type
+               {
+                       MOVE,
+                       SLIDE,
+                       ROTATE
+               };
+
+               enum Target
                {
                        BODY,
+                       BOGIE,
                        AXLE,
-                       BOGIE_AXLE,
                        ROD
                };
 
-               enum Limit
+               class Loader: public Msp::DataFile::ObjectLoader<RodConstraint>
                {
-                       FIXED,
-                       ROTATE,
-                       SLIDE_X
+               private:
+                       TagMap &tags;
+
+               public:
+                       Loader(RodConstraint &, TagMap &);
+               private:
+                       void axis(float, float, float);
+                       void local_position(float, float, float);
+                       void target_axle(unsigned);
+                       void target_position(float, float, float);
+                       void target_rod(const std::string &);
                };
 
+               Type type;
+               Target target;
+               unsigned target_index;
+               Vector target_position;
+               Vector local_position;
+               Vector axis;
+
+               RodConstraint();
+       };
+
+       struct Rod
+       {
                class Loader: public Msp::DataFile::ObjectLoader<Rod>
                {
                private:
-                       const std::map<std::string, unsigned> &tags;
-                       std::string tag;
+                       TagMap &tags;
 
                public:
-                       Loader(Rod &, const std::map<std::string, unsigned> &);
-                       const std::string &get_tag() const { return tag; }
+                       Loader(Rod &, TagMap &);
                private:
-                       void connect(const std::string &, float, float, float, float);
-                       void limit(Limit);
-                       void pivot_body();
-                       void pivot_axle(unsigned);
-                       void pivot_bogie_axle(unsigned, unsigned);
-                       void pivot_rod(const std::string &);
-                       void position(float, float, float);
-                       void set_tag(const std::string &);
+                       template<RodConstraint::Type>
+                       void constraint();
+                       void initial_position(float, float, float);
                };
 
-               Anchor pivot;
-               unsigned pivot_index;
-               unsigned pivot_index2;
-               Vector pivot_point;
-               Limit limit;
-               int connect_index;
-               Vector connect_point;
-               Vector connect_offset;
+               Vector initial_position;
+               std::vector<RodConstraint> constraints;
                std::string object;
                bool mirror_object;
 
                Rod();
        };
 
+       class MirrorParametersLoader: public Msp::DataFile::Loader
+       {
+       public:
+               std::string filter;
+               Angle phase_offset;
+
+               MirrorParametersLoader();
+       private:
+               void filt(const std::string &);
+               void phase_offs(float);
+       };
+
+       typedef std::vector<Axle> AxleArray;
+       typedef std::vector<Bogie> BogieArray;
        typedef std::vector<Rod> RodArray;
+       typedef std::map<unsigned, std::string> FunctionMap;
 
 private:
-       ArticleNumber art_nr;
-       std::string name;
        bool locomotive;
-       std::map<unsigned, std::string> functions;
+       FunctionMap functions;
        bool swap_direction;
+       float gauge;
        float length;
        float width;
        float height;
        AxleArray axles;
+       std::vector<Axle *> fixed_axles;
        BogieArray bogies;
        RodArray rods;
        std::string object;
+       bool rotate_object;
+       float max_speed;
 
 public:
        VehicleType(const ArticleNumber &);
 
-       const ArticleNumber &get_article_number() const { return art_nr; }
-       const std::string &get_name() const { return name; }
        bool is_locomotive() const { return locomotive; }
        unsigned get_max_function() const;
-       const std::map<unsigned, std::string> &get_functions() const { return functions; }
+       const FunctionMap &get_functions() const { return functions; }
        bool get_swap_direction() const { return swap_direction; }
+       float get_gauge() const { return gauge; }
        float get_length() const { return length; }
        float get_width() const { return width; }
        float get_height() const { return height; }
-       const AxleArray &get_fixed_axles() const { return axles; }
+       const AxleArray &get_axles() const { return axles; }
+       const Axle &get_axle(unsigned) const;
        const Axle &get_fixed_axle(unsigned) const;
        const BogieArray &get_bogies() const { return bogies; }
        const Bogie &get_bogie(unsigned) const;
@@ -165,6 +201,8 @@ public:
        float get_front_axle_offset() const;
        float get_back_axle_offset() const;
        const std::string &get_object() const { return object; }
+       bool get_rotate_object() const { return rotate_object; }
+       float get_maximum_speed() const { return max_speed; }
 };
 
 } // namespace R2C2