X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Faicontrol.cpp;h=f1f16bf1850a511c25059aa247356ec4445fbcee;hb=91131237203bffe734219ab8b82b9d17f5d7a87d;hp=e5bed9ce3ba3ee71a61676f196ef673693ec667a;hpb=d3a7a9e9ad694d52ccca8b6038501772fdc1dfd5;p=r2c2.git diff --git a/source/libr2c2/aicontrol.cpp b/source/libr2c2/aicontrol.cpp index e5bed9c..f1f16bf 100644 --- a/source/libr2c2/aicontrol.cpp +++ b/source/libr2c2/aicontrol.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 "aicontrol.h" #include "catalogue.h" #include "layout.h" @@ -23,14 +16,11 @@ AIControl::AIControl(Train &t): state(NORMAL), need_update(false) { - train.signal_arrived.connect(sigc::mem_fun(this, &AIControl::arrived)); + train.signal_ai_event.connect(sigc::mem_fun(this, &AIControl::event)); } 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)); @@ -59,7 +49,7 @@ void AIControl::message(const Message &msg) set_reverse(!reverse); } -void AIControl::tick(const Time::TimeStamp &, const Time::TimeDelta &) +void AIControl::tick(const Time::TimeDelta &) { float scale = train.get_layout().get_catalogue().get_scale(); float rsv_dist = train.get_reserved_distance(); @@ -90,7 +80,7 @@ void AIControl::tick(const Time::TimeStamp &, 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) @@ -106,14 +96,17 @@ void AIControl::tick(const Time::TimeStamp &, 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::arrived() +void AIControl::event(TrainAI &, const Message &ev) { - set_target_speed(0); + if(ev.type=="arrived") + set_target_speed(0); } } // namespace R2C2