diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-04 12:02:00 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-04 12:02:00 +0100 |
commit | 853a9e690eeeb48aa1a13faa66db0a91d5b49390 (patch) | |
tree | 51451d08e10cedda4128c1e29848524a00baf2a7 /advtrains/trainlogic.lua | |
parent | a9d43ce2ca3bfd703428d248c0839e53ffd76f27 (diff) | |
download | advtrains-853a9e690eeeb48aa1a13faa66db0a91d5b49390.tar.gz advtrains-853a9e690eeeb48aa1a13faa66db0a91d5b49390.tar.bz2 advtrains-853a9e690eeeb48aa1a13faa66db0a91d5b49390.zip |
Add Automatic Train Control system
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r-- | advtrains/trainlogic.lua | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 4ac4b29..eb45500 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -119,6 +119,7 @@ advtrains.save = function() file:close() advtrains.save_trackdb() + advtrains.atc.save() end minetest.register_on_shutdown(advtrains.save) @@ -302,6 +303,24 @@ function advtrains.train_step(id, train, dtime) if train.locomotives_in_train==0 then train.tarvelocity=0 end + + --interpret ATC command + if train.atc_brake_target and train.atc_brake_target>=train.velocity then + train.atc_brake_target=nil + end + if train.atc_wait_finish then + if not train.atc_brake_target and train.velocity==train.tarvelocity then + train.atc_wait_finish=nil + end + end + if train.atc_command then + if train.atc_delay<=0 and not train.atc_wait_finish then + advtrains.atc.execute_atc_command(id, train) + else + train.atc_delay=train.atc_delay-dtime + end + end + --make brake adjust the tarvelocity if necessary if train.brake and (math.ceil(train.velocity)-1)<train.tarvelocity then train.tarvelocity=math.max((math.ceil(train.velocity)-1), 0) @@ -318,7 +337,7 @@ function advtrains.train_step(id, train, dtime) if front_off_track or back_off_track or train.recently_collided_with_env then --every wagon has a brake, so not divided by mass. --print("braking with emergency force") applydiff= -(math.min((advtrains.train_emerg_force*dtime), math.abs(diff))) - elseif train.brake then + elseif train.brake or (train.atc_brake_target and train.atc_brake_target<train.velocity) then --print("braking with default force") --no math.min, because it can grow beyond tarvelocity, see up there --dont worry, it will never fall below zero. |