Avoid division through zero in get_acceleration

This commit is contained in:
orwell96 2019-01-21 22:41:57 +01:00
parent e915b61da6
commit f162ebf63f
1 changed files with 4 additions and 0 deletions

View File

@ -185,6 +185,10 @@ function advtrains.get_acceleration(train, lever)
local acc_all = t_accel_all[lever] local acc_all = t_accel_all[lever]
local acc_eng = t_accel_eng[lever] local acc_eng = t_accel_eng[lever]
local nwagons = #train.trainparts 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 local acc = acc_all + (acc_eng*train.locomotives_in_train)/nwagons
return acc return acc
end end