X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrain.cpp;h=5f1b46bd950f625fb04581565d7bc849c4a224ad;hb=a20b8421d002629a9f4d97c0c378e9f9cb29e292;hp=93ebebec3c16ef66502da7045fe6df24cf429a4d;hpb=a72309e64614bb1e230f9842d94dc261be1301e6;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 93ebebe..5f1b46b 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -1,13 +1,7 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include -#include +#include +#include #include #include #include "aicontrol.h" @@ -588,7 +582,10 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt) if(controller->get_reverse()!=reverse) { reverse = controller->get_reverse(); - driver.set_loco_reverse(address, reverse); + bool r = reverse; + if(loco_type.get_swap_direction()) + r = !r; + driver.set_loco_reverse(address, r); release_blocks(cur_blocks_end, blocks.end()); reverse_blocks(blocks); @@ -715,8 +712,11 @@ void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev) if(addr==address) { current_speed_step = speed; - if(rev!=reverse) - layout.get_driver().set_loco_reverse(address, reverse); + bool r = reverse; + if(loco_type.get_swap_direction()) + r = !r; + if(rev!=r) + layout.get_driver().set_loco_reverse(address, r); speed_changing = false; pure_speed = false; } @@ -763,7 +763,7 @@ void Train::block_state_changed(Block &block, Block::State state) // Compute speed and update related state float travel_time_secs = (Time::now()-last_entry_time)/Time::sec; - if(pure_speed && speed_quantizer && current_speed_step>0) + if(pure_speed && speed_quantizer && current_speed_step>0 && travel_time_secs>=2) speed_quantizer->learn(current_speed_step, travel_dist/travel_time_secs, travel_time_secs); travel_dist = 0; @@ -1323,7 +1323,7 @@ void Train::Loader::block(unsigned id) { blk = &obj.layout.get_block(id); } - catch(const KeyError &) + catch(const key_error &) { blocks_valid = false; return; @@ -1350,7 +1350,7 @@ void Train::Loader::block_hint(unsigned id) { prev_block = &obj.layout.get_block(id); } - catch(const KeyError &) + catch(const key_error &) { blocks_valid = false; }