aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
authorY. Wang <y5nw@protonmail.com>2024-09-20 12:45:20 +0000
committerorwell <orwell@bleipb.de>2024-11-09 22:10:06 +0100
commitb075d8e3336dfb2755dd1b9dc29c5320a155013b (patch)
tree065aa5602afac4b54b1555e44bce4446b59215ea /advtrains/trainlogic.lua
parent66868e2eefe97b7a6d35fa3fecc895b9c7bbc4cc (diff)
downloadadvtrains-b075d8e3336dfb2755dd1b9dc29c5320a155013b.tar.gz
advtrains-b075d8e3336dfb2755dd1b9dc29c5320a155013b.tar.bz2
advtrains-b075d8e3336dfb2755dd1b9dc29c5320a155013b.zip
Implement staticdata for trains
This patch exposes train.staticdata that can be used by other modders to save data in trains across restarts. It additionally exposes two new APIs for modders where this is relevant: * advtrains.te_register_on_couple(function(init_train, stat_train)): registers a callback for train coupling, where stat_train is couple into init_train and is subsequently removed. This callback is run before the actual coupling takes place; in particular, it is run before stat_train is removed. * advtrains.te_register_on_decouple(function(train, newtrain, index)): registers a callback for train decoupling, where newtrain is created by splitting the train at the given index (the wagon at the index is part of the new train). This callback is run after decoupling takes place. advtrains.te_register_on_decouple(function
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua6
1 files changed, 6 insertions, 0 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 3b006d2..ed49a4c 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -263,6 +263,10 @@ function advtrains.train_ensure_init(id, train)
atwarn(debug.traceback())
return nil
end
+
+ if not train.staticdata then
+ train.staticdata = {}
+ end
train.dirty = true
if train.no_step then
@@ -1190,6 +1194,8 @@ function advtrains.split_train_at_index(train, index)
newtrain.points_split = advtrains.merge_tables(train.points_split)
newtrain.autocouple = train.autocouple
+ advtrains.te_run_callbacks_on_decouple(train, newtrain, index)
+
return newtrain_id -- return new train ID, so new train can be manipulated
end