]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/vehicletype.h
Split vehicle placement code to a separate class
[r2c2.git] / source / libr2c2 / vehicletype.h
index 949195dd1091aabf8c4cb9776ab5d3888c527d5f..31b6992a134773c474cf1ab2868b054ccbcaca83 100644 (file)
@@ -1,23 +1,16 @@
-/* $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
 {
 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;
@@ -25,6 +18,7 @@ public:
        public:
                Loader(VehicleType &);
        private:
+               virtual void finish();
                void axle();
                void bogie();
                void function(unsigned, const std::string &);
@@ -34,6 +28,8 @@ public:
                void width(float);
        };
 
+       struct Bogie;
+
        struct Axle
        {
                class Loader: public Msp::DataFile::ObjectLoader<Axle>
@@ -45,6 +41,9 @@ public:
                        void wheel_diameter(float);
                };
 
+               unsigned index;
+               Bogie *bogie;
+               float local_position;
                float position;
                float wheel_dia;
                bool powered;
@@ -53,29 +52,30 @@ 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
        {
                enum Anchor
@@ -127,13 +127,12 @@ public:
                Rod();
        };
 
+       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;
        FunctionMap functions;
        bool swap_direction;
@@ -141,15 +140,15 @@ private:
        float width;
        float height;
        AxleArray axles;
+       std::vector<Axle *> fixed_axles;
        BogieArray bogies;
        RodArray rods;
        std::string object;
+       bool rotate_object;
 
 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 FunctionMap &get_functions() const { return functions; }
@@ -157,7 +156,8 @@ public:
        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;
@@ -167,6 +167,7 @@ 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; }
 };
 
 } // namespace R2C2