aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2023-12-20 00:20:56 +0100
committerorwell <orwell@bleipb.de>2023-12-20 00:20:56 +0100
commit9fac1db45f79e2312415500b6ec9d22a8edb0cdd (patch)
treec0e914b4af11172732cc8a5f6de54bb6e7888f40
parent2884ed3e27b2a850ea21866ba5260d5a41f5f825 (diff)
downloadadvtrains-9fac1db45f79e2312415500b6ec9d22a8edb0cdd.tar.gz
advtrains-9fac1db45f79e2312415500b6ec9d22a8edb0cdd.tar.bz2
advtrains-9fac1db45f79e2312415500b6ec9d22a8edb0cdd.zip
Set maximum train length and prevent coupling if it would exceed
-rw-r--r--advtrains/couple.lua7
-rw-r--r--advtrains/init.lua3
2 files changed, 10 insertions, 0 deletions
diff --git a/advtrains/couple.lua b/advtrains/couple.lua
index 1318c12..b6a445e 100644
--- a/advtrains/couple.lua
+++ b/advtrains/couple.lua
@@ -227,6 +227,13 @@ function advtrains.couple_trains(init_train, invert_init_train, stat_train, stat
local stp = stat_train.trainparts
local stat_wagoncnt = #stp
local stat_trainlen = stat_train.trainlen -- save the train length of stat train, to be added to index
+
+ -- sanity check, prevent coupling if train would be longer than 20 after coupling
+ local tot_len = init_wagoncnt + stat_wagoncnt
+ if tot_len > advtrains.TRAIN_MAX_WAGONS then
+ atwarn("Cannot couple",stat_train.id,"and",init_train.id,"- train would have length",tot_len,"which is above the limit of",advtrains.TRAIN_MAX_WAGONS)
+ return
+ end
if stat_train_opposite then
-- insert wagons in inverse order and set their wagon_flipped state
diff --git a/advtrains/init.lua b/advtrains/init.lua
index a7e5764..9c977eb 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -48,6 +48,9 @@ advtrains.IGNORE_WORLD = false
local NO_SAVE = false
-- Do not save any data to advtrains save files
+advtrains.TRAIN_MAX_WAGONS = 20
+-- Limit on the maximum number of wagons that may be in a train
+
-- ==========================================================================
-- Use a global slowdown factor to slow down train movements. Now a setting