]> git.tdb.fi Git - r2c2.git/commitdiff
Use different stopping margin depending on whether the next track is a turnout
authorMikko Rasa <tdb@tdb.fi>
Fri, 18 Feb 2011 05:19:04 +0000 (05:19 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 18 Feb 2011 05:19:04 +0000 (05:19 +0000)
source/libr2c2/aicontrol.cpp
source/libr2c2/train.cpp

index 782993752ab94cd504261b5522a7211b936b92b5..d1a69aac11f04717d10d13c4e5fea365ec8d7cba 100644 (file)
@@ -100,7 +100,7 @@ void AIControl::tick(const Time::TimeDelta &dt)
        float brake_dist = next_ctrl->get_braking_distance();
        float approach_margin = 50*scale;
        float approach_speed = 5*scale;
-       float margin = 10*scale;
+       float margin = 1*scale;
 
        State old_state = state;
 
index 218b6861da183b0d24c3279046c4dc122aaae9ba..122ea9b18795ffcc64f4de01d065bd5d1fb46369 100644 (file)
@@ -443,8 +443,7 @@ void Train::unplace()
 
 bool Train::free_block(Block &block)
 {
-       float margin = 10*layout.get_catalogue().get_scale();
-       if(get_reserved_distance_until(&block, false)<controller->get_braking_distance()*1.3+margin)
+       if(get_reserved_distance_until(&block, false)<controller->get_braking_distance()*1.3)
                return false;
 
        unsigned nsens = 0;
@@ -534,7 +533,15 @@ int Train::get_entry_to_block(Block &block) const
 
 float Train::get_reserved_distance() const
 {
-       return get_reserved_distance_until(0, false);
+       if(blocks.empty())
+               return 0;
+
+       float margin = 0;
+       TrackIter next = blocks.back().next().track_iter();
+       if(next->get_type().is_turnout())
+               margin = 15*layout.get_catalogue().get_scale();
+
+       return max(get_reserved_distance_until(0, false)-margin, 0.0f);
 }
 
 void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)