]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/aicontrol.cpp
Export AI control parameters over the network
[r2c2.git] / source / libr2c2 / aicontrol.cpp
index 97b7209cf47539f892ddfa5872b21d053eed949f..e3ab1e47bf2886615c9cf7051be4b4e81a24395c 100644 (file)
@@ -21,9 +21,6 @@ AIControl::AIControl(Train &t):
 
 void AIControl::set_target_speed(float s)
 {
-       if(s && !train.is_active())
-               train.set_active(true);
-
        target_speed = s;
        need_update = true;
        signal_event.emit(Message("target-speed-changed", target_speed));
@@ -32,6 +29,9 @@ void AIControl::set_target_speed(float s)
 void AIControl::set_reverse(bool r)
 {
        pending_reverse = r;
+       if(r==reverse)
+               return;
+
        if(train.get_controller().get_speed())
                set_target_speed(0);
        else
@@ -83,7 +83,7 @@ void AIControl::tick(const Time::TimeDelta &)
                        speed_limit = 0;
                else if(state==APPROACH)
                        speed_limit = approach_speed;
-               else if(state==FOLLOW && train.get_preceding_train()->is_active())
+               else if(state==FOLLOW && train.get_preceding_train()->get_block_allocator().is_active())
                        speed_limit = train.get_preceding_train()->get_speed();
 
                if(speed_limit>=0 && target_speed>speed_limit)
@@ -99,9 +99,11 @@ void AIControl::tick(const Time::TimeDelta &)
                reverse = pending_reverse;
                train.set_control("reverse", reverse);
        }
+}
 
-       if(!target_speed && !train.get_controller().get_speed() && train.is_active())
-               train.set_active(false);
+bool AIControl::has_intent_to_move() const
+{
+       return target_speed;
 }
 
 void AIControl::event(TrainAI &, const Message &ev)