X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fvehicle.cpp;h=d1819a0fbe5c9e652b7a165970ab0d54bdd19cae;hb=8b7d4054b05002d82338775ac9b4ee764a8560e4;hp=1699fd8eeef1cf0b89618cb806d3c6623aabc07b;hpb=621c5c938d70ba0d155e0eda91a708db0a52c0dc;p=r2c2.git diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index 1699fd8..d1819a0 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -14,11 +14,10 @@ using namespace Msp; namespace R2C2 { Vehicle::Vehicle(Layout &l, const VehicleType &t): - layout(l), + Object(l), type(t), next(0), prev(0), - direction(0), front_sensor(0), back_sensor(0) { @@ -38,6 +37,14 @@ Vehicle::~Vehicle() layout.remove_vehicle(*this); } +Vehicle *Vehicle::clone(Layout *to_layout) const +{ + Vehicle *veh = new Vehicle((to_layout ? *to_layout : layout), type); + veh->set_position(position); + veh->set_rotation(rotation); + return veh; +} + void Vehicle::attach_back(Vehicle &veh) { if(next || veh.prev) @@ -189,7 +196,7 @@ void Vehicle::update_position() position = tp.pos; position.z += layout.get_catalogue().get_rail_elevation(); - direction = tp.dir; + rotation = tp.dir; } void Vehicle::update_position_from(const Vehicle &veh) @@ -200,7 +207,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); @@ -391,6 +398,29 @@ TrackPoint Vehicle::get_point(const TrackPosition &pos, float tdist, float ratio return get_point(front.get_point().pos, back.get_point().pos, ratio); } +unsigned Vehicle::get_n_link_slots() const +{ + return 2; +} + +Vehicle *Vehicle::get_link(unsigned i) const +{ + if(i>=2) + throw out_of_range("Vehicle::get_link"); + + return (i==0 ? prev : next); +} + +int Vehicle::get_link_slot(const Object &other) const +{ + if(&other==prev) + return 0; + else if(&other==next) + return 1; + else + return -1; +} + Vehicle::Axle::Axle(const VehicleType::Axle &t): type(&t),