diff options
author | orwell96 <orwell@bleipb.de> | 2019-01-21 22:41:57 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2019-01-21 22:41:57 +0100 |
commit | f162ebf63f00339dd1b698c051e7b6301bb2c508 (patch) | |
tree | 33da1977e38d69af39d1898b0fc2eb581f7b7945 /advtrains | |
parent | e915b61da6f18efa49b6afacb7e9ca181d59cc5c (diff) | |
download | advtrains-f162ebf63f00339dd1b698c051e7b6301bb2c508.tar.gz advtrains-f162ebf63f00339dd1b698c051e7b6301bb2c508.tar.bz2 advtrains-f162ebf63f00339dd1b698c051e7b6301bb2c508.zip |
Avoid division through zero in get_acceleration
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/trainlogic.lua | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 1406080..a5323a9 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -185,6 +185,10 @@ function advtrains.get_acceleration(train, lever) local acc_all = t_accel_all[lever] local acc_eng = t_accel_eng[lever] local nwagons = #train.trainparts + if nwagons == 0 then + -- empty train! avoid division through zero + return -1 + end local acc = acc_all + (acc_eng*train.locomotives_in_train)/nwagons return acc end |