]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/vehicletype.cpp
Handle sensors in a separate class
[r2c2.git] / source / libr2c2 / vehicletype.cpp
index 52dc7b0f45edf2f99fd9fc0257ef3bbb982fbbda..973070ceafc158fe2fddfd4fb966115c5c1ca2a6 100644 (file)
@@ -1,10 +1,5 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010-2011  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
+#include <msp/core/maputils.h>
+#include <msp/strings/format.h>
 #include "vehicletype.h"
 
 using namespace std;
@@ -13,11 +8,13 @@ using namespace Msp;
 namespace R2C2 {
 
 VehicleType::VehicleType(const ArticleNumber &an):
-       art_nr(an),
+       ObjectType(an),
        locomotive(false),
+       swap_direction(false),
        length(0),
        width(0),
-       height(0)
+       height(0),
+       rotate_object(false)
 { }
 
 unsigned VehicleType::get_max_function() const
@@ -30,30 +27,30 @@ unsigned VehicleType::get_max_function() const
 const VehicleType::Axle &VehicleType::get_fixed_axle(unsigned i) const
 {
        if(i>=axles.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_fixed_axle");
        return axles[i];
 }
 
 const VehicleType::Bogie &VehicleType::get_bogie(unsigned i) const
 {
        if(i>=bogies.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_bogie");
        return bogies[i];
 }
 
 const VehicleType::Axle &VehicleType::get_bogie_axle(unsigned i, unsigned j) const
 {
        if(i>=bogies.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_bogie_axle");
        if(j>=bogies[i].axles.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_bogie_axle");
        return bogies[i].axles[j];
 }
 
 const VehicleType::Rod &VehicleType::get_rod(unsigned i) const
 {
        if(i>=rods.size())
-               throw InvalidParameterValue("Rod index out of range");
+               throw out_of_range("VehicleType::get_rod");
        return rods[i];
 }
 
@@ -108,7 +105,7 @@ VehicleType::Rod::Rod():
 
 
 VehicleType::Loader::Loader(VehicleType &vt):
-       DataFile::ObjectLoader<VehicleType>(vt)
+       DataFile::DerivedObjectLoader<VehicleType, ObjectType::Loader>(vt)
 {
        add("axle",       &Loader::axle);
        add("bogie",      &Loader::bogie);
@@ -116,9 +113,10 @@ VehicleType::Loader::Loader(VehicleType &vt):
        add("height",     &Loader::height);
        add("length",     &Loader::length);
        add("locomotive", &VehicleType::locomotive);
-       add("name",       &VehicleType::name);
        add("object",     &VehicleType::object);
        add("rod",        &Loader::rod);
+       add("rotate_object", &VehicleType::rotate_object);
+       add("swap_direction", &VehicleType::swap_direction);
        add("width",      &Loader::width);
 }
 
@@ -228,10 +226,7 @@ VehicleType::Rod::Loader::Loader(Rod &r, const map<string, unsigned> &t):
 
 void VehicleType::Rod::Loader::connect(const string &t, float px, float pz, float ox, float oz)
 {
-       map<string, unsigned>::const_iterator i = tags.find(t);
-       if(i==tags.end())
-               throw KeyError("Unknown rod tag", t);
-       obj.connect_index = i->second;
+       obj.connect_index = get_item(tags, t);
        obj.connect_point = Vector(px/1000, 0, pz/1000);
        obj.connect_offset = Vector(ox/1000, 0, oz/1000);
 }
@@ -256,11 +251,8 @@ void VehicleType::Rod::Loader::pivot_bogie_axle(unsigned i, unsigned j)
 
 void VehicleType::Rod::Loader::pivot_rod(const string &t)
 {
-       map<string, unsigned>::const_iterator i = tags.find(t);
-       if(i==tags.end())
-               throw KeyError("Unknown rod tag", t);
+       obj.pivot_index = get_item(tags, t);
        obj.pivot = ROD;
-       obj.pivot_index = i->second;
 }
 
 void VehicleType::Rod::Loader::position(float x, float y, float z)
@@ -284,7 +276,7 @@ void operator>>(const LexicalConverter &c, VehicleType::Rod::Limit &l)
        else if(s=="SLIDE_X")
                l = VehicleType::Rod::SLIDE_X;
        else
-               throw LexicalError("Invalid value for Rod::Limit");
+               throw lexical_error(format("conversion of '%s' to Rod::Limit", s));
 }
 
 } // namespace R2C2