X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fvehicle.cpp;h=4259c7dcde26a2b0a441210387bf4da011ef8a10;hb=4086edbfae9a04da491cdb349a3bef6af5c132d9;hp=2c31ba19f189467ad07233dc0ff600e87fe6643e;hpb=f8a7788cee0261babfc4c804a58515aad6dfbc3d;p=r2c2.git diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index 2c31ba1..4259c7d 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include "catalogue.h" #include "driver.h" @@ -29,7 +22,7 @@ Vehicle::Vehicle(Layout &l, const VehicleType &t): front_sensor(0), back_sensor(0) { - axles.assign(type.get_axles().begin(), type.get_axles().end()); + axles.assign(type.get_fixed_axles().begin(), type.get_fixed_axles().end()); bogies.assign(type.get_bogies().begin(), type.get_bogies().end()); rods.assign(type.get_rods().begin(), type.get_rods().end()); @@ -48,7 +41,7 @@ Vehicle::~Vehicle() void Vehicle::attach_back(Vehicle &veh) { if(next || veh.prev) - throw InvalidState("Already attached"); + throw attachment_error("already attached"); next = &veh; veh.prev = this; @@ -60,7 +53,7 @@ void Vehicle::attach_back(Vehicle &veh) void Vehicle::attach_front(Vehicle &veh) { if(prev || veh.next) - throw InvalidState("Already attached"); + throw attachment_error("already attached"); prev = &veh; veh.next = this; @@ -72,7 +65,7 @@ void Vehicle::attach_front(Vehicle &veh) void Vehicle::detach_back() { if(!next) - throw InvalidState("Not attached"); + throw attachment_error("not attached"); next->prev = 0; next = 0; @@ -81,7 +74,7 @@ void Vehicle::detach_back() void Vehicle::detach_front() { if(!prev) - throw InvalidState("Not attached"); + throw attachment_error("not attached"); prev->next = 0; prev = 0; @@ -125,33 +118,33 @@ void Vehicle::advance(float d) propagate_position(); } -const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const +const Vehicle::Axle &Vehicle::get_fixed_axle(unsigned i) const { - if(i>=bogies.size()) - throw InvalidParameterValue("Bogie index out of range"); - return bogies[i]; + if(i>=axles.size()) + throw out_of_range("Vehicle::get_fixed_axle"); + return axles[i]; } -const Vehicle::Axle &Vehicle::get_axle(unsigned i) const +const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const { - if(i>=axles.size()) - throw InvalidParameterValue("Axle index out of range"); - return axles[i]; + if(i>=bogies.size()) + throw out_of_range("Vehicle::get_bogie"); + return bogies[i]; } const Vehicle::Axle &Vehicle::get_bogie_axle(unsigned i, unsigned j) const { if(i>=bogies.size()) - throw InvalidParameterValue("Bogie index out of range"); + throw out_of_range("Vehicle::get_bogie_axle"); if(j>=bogies[i].axles.size()) - throw InvalidParameterValue("Axle index out of range"); + throw out_of_range("Vehicle::get_bogie_axle"); return bogies[i].axles[j]; } const Vehicle::Rod &Vehicle::get_rod(unsigned i) const { if(i>=rods.size()) - throw InvalidParameterValue("Rod index out of range"); + throw out_of_range("Vehicle::get_rod"); return rods[i]; } @@ -207,7 +200,7 @@ void Vehicle::update_position_from(const Vehicle &veh) float margin = layout.get_catalogue().get_scale(); float dist = distance(veh.position, position); - if(disttdist+margin) + if(!track_pos.track || disttdist+margin) { track_pos = veh.track_pos; track_pos.advance(sign*tdist); @@ -290,7 +283,7 @@ void Vehicle::update_rods() i->position = i->type->pivot_point; else if(i->type->pivot==VehicleType::Rod::AXLE) { - const Axle &axle = get_axle(i->type->pivot_index); + const Axle &axle = get_fixed_axle(i->type->pivot_index); float c = cos(axle.angle); float s = sin(axle.angle); const Vector &pp = i->type->pivot_point;