aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua4
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