X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fvehicletype.cpp;h=854308c71ad80cd46861bfa8786021174db40dae;hb=0c1214ad0680c3bf65c1ee5f366dbafabc9d188d;hp=b9c6ed2f72fe093c37043d3504bc226b225abe84;hpb=37af7970d9cefcf40ae58ca06ca8469f56b0cc13;p=r2c2.git diff --git a/source/libr2c2/vehicletype.cpp b/source/libr2c2/vehicletype.cpp index b9c6ed2..854308c 100644 --- a/source/libr2c2/vehicletype.cpp +++ b/source/libr2c2/vehicletype.cpp @@ -1,10 +1,7 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - +#include +#include +#include +#include #include "vehicletype.h" using namespace std; @@ -13,11 +10,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 @@ -27,6 +26,36 @@ unsigned VehicleType::get_max_function() const return (--functions.end())->first; } +const VehicleType::Axle &VehicleType::get_fixed_axle(unsigned i) const +{ + if(i>=axles.size()) + 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 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 out_of_range("VehicleType::get_bogie_axle"); + if(j>=bogies[i].axles.size()) + 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 out_of_range("VehicleType::get_rod"); + return rods[i]; +} + float VehicleType::get_front_axle_offset() const { float front = length/2; @@ -78,7 +107,7 @@ VehicleType::Rod::Rod(): VehicleType::Loader::Loader(VehicleType &vt): - DataFile::ObjectLoader(vt) + DataFile::DerivedObjectLoader(vt) { add("axle", &Loader::axle); add("bogie", &Loader::bogie); @@ -86,12 +115,20 @@ 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); } +void VehicleType::Loader::finish() +{ + obj.shape = new Geometry::TransformedShape( + Geometry::Box(obj.length, obj.width, obj.height), + Transform::translation(Vector(0, 0, obj.height/2))); +} + void VehicleType::Loader::axle() { Axle axl; @@ -198,12 +235,9 @@ VehicleType::Rod::Loader::Loader(Rod &r, const map &t): void VehicleType::Rod::Loader::connect(const string &t, float px, float pz, float ox, float oz) { - map::const_iterator i = tags.find(t); - if(i==tags.end()) - throw KeyError("Unknown rod tag", t); - obj.connect_index = i->second; - obj.connect_point = Point(px/1000, 0, pz/1000); - obj.connect_offset = Point(ox/1000, 0, oz/1000); + 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); } void VehicleType::Rod::Loader::pivot_body() @@ -226,16 +260,13 @@ void VehicleType::Rod::Loader::pivot_bogie_axle(unsigned i, unsigned j) void VehicleType::Rod::Loader::pivot_rod(const string &t) { - map::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) { - obj.pivot_point = Point(x/1000, y/1000, z/1000); + obj.pivot_point = Vector(x/1000, y/1000, z/1000); } void VehicleType::Rod::Loader::set_tag(const string &t) @@ -254,7 +285,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