]> git.tdb.fi Git - r2c2.git/commitdiff
Fix vacated distance calculation when moving backwards
authorMikko Rasa <tdb@tdb.fi>
Sat, 2 Oct 2010 11:41:44 +0000 (11:41 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 2 Oct 2010 11:41:44 +0000 (11:41 +0000)
Be consistent with vehicle placement when placing a train

source/libmarklin/train.cpp

index d87d3768a7e0a482db808d934cd5f5211f389197..c3affef1fdb48dbb0fbe18ff7d9adefda12a9b70 100644 (file)
@@ -272,7 +272,7 @@ void Train::place(Block &block, unsigned entry)
        else
        {
                const Block::Endpoint &bep = block.get_endpoints()[entry];
-               vehicles.front()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
+               vehicles.back()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
        }
 }
 
@@ -435,7 +435,10 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
                unsigned entry = bep.track_ep;
 
                bool found = false;
-               float dist = veh.get_offset()-veh.get_type().get_length()/2;
+               float dist = veh.get_offset();
+               if(reverse)
+                       dist = veh.get_track()->get_type().get_path_length(veh.get_track()->get_active_path())-dist;
+               dist -= veh.get_type().get_length()/2;
                while(1)
                {
                        if(track==veh.get_track())