X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Faicontrol.cpp;h=59126d8505b193cafea380401b5c7db0edf3ffc4;hb=1efb7d0debe9e6e9b480eb16381c1b90d0fb7d17;hp=2d48bf764a3f498047a078a34965461fc2985c2d;hpb=90f9efba8d88f41c7a180734b7bcbdd1501d995e;p=r2c2.git diff --git a/source/libr2c2/aicontrol.cpp b/source/libr2c2/aicontrol.cpp index 2d48bf7..59126d8 100644 --- a/source/libr2c2/aicontrol.cpp +++ b/source/libr2c2/aicontrol.cpp @@ -32,9 +32,24 @@ AIControl::~AIControl() delete next_ctrl; } +const char *AIControl::enumerate_controls(unsigned index) const +{ + if(index==0) + return target_speed.name.c_str(); + else + { + for(--index;; ++index) + { + const char *ret = next_ctrl->enumerate_controls(index-1); + if(!ret || ret!=target_speed.name) + return ret; + } + } +} + void AIControl::set_control(const string &n, float v) { - if(n=="speed") + if(n==target_speed.name) { if(v && !train.is_active()) train.set_active(true); @@ -57,7 +72,7 @@ void AIControl::set_control(const string &n, float v) const Controller::Control &AIControl::get_control(const string &n) const { - if(n=="speed") + if(n==target_speed.name) return target_speed; else return next_ctrl->get_control(n); @@ -85,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; @@ -109,7 +124,7 @@ void AIControl::tick(const Time::TimeDelta &dt) speed_limit = 0; else if(state==APPROACH) speed_limit = approach_speed; - else if(state==FOLLOW) + else if(state==FOLLOW && train.get_preceding_train()->is_active()) speed_limit = train.get_preceding_train()->get_speed(); if(speed_limit>=0 && target_speed.value>speed_limit)