aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation/atc_rail.lua
diff options
context:
space:
mode:
authorMaverick2797 <git.maverick2797@gmail.com>2022-11-17 23:19:57 +0800
committerorwell96 <orwell@bleipb.de>2023-03-17 20:03:12 +0100
commit3a6b1ca8500cad74f95b925b191582c0aa739116 (patch)
treec37c4d34832c9af3e3ff2f569e996154c7dc94a1 /advtrains_luaautomation/atc_rail.lua
parent82987b1a4f74074088a414d90898ad19ec8c4b20 (diff)
downloadadvtrains-3a6b1ca8500cad74f95b925b191582c0aa739116.tar.gz
advtrains-3a6b1ca8500cad74f95b925b191582c0aa739116.tar.bz2
advtrains-3a6b1ca8500cad74f95b925b191582c0aa739116.zip
Add get_fc() and set_fc() commands
get_fc: returns a table of each wagon's FC codes set_fc: set a table to overwrite the FC codes of a train's wagons
Diffstat (limited to 'advtrains_luaautomation/atc_rail.lua')
-rwxr-xr-x[-rw-r--r--]advtrains_luaautomation/atc_rail.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua
index 5dde99c..aac11f0 100644..100755
--- a/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains_luaautomation/atc_rail.lua
@@ -91,6 +91,38 @@ function r.fire_event(pos, evtdata, appr_internal)
if not train_id then return false end
advtrains.train_step_fc(train)
end,
+ get_fc = function()
+ if not train_id then return end
+ local fc_list = {}
+ for index,wagon_id in ipairs(train.trainparts) do
+ fc_list[index] = table.concat(advtrains.wagons[wagon_id].fc,"!") or ""
+ end
+ return fc_list
+ end,
+ set_fc = function(fc_list)
+ assertt(fc_list, "table")
+ if not train_id then return false end
+ -- safety type-check for entered values
+ for _,v in ipairs(fc_list) do
+ if v and type(v) ~= "string" then
+ error("FC entries must be a string")
+ return
+ end
+ end
+ for index,wagon_id in ipairs(train.trainparts) do
+ if fc_list[index] then -- has FC to enter to this wagon
+ local data = advtrains.wagons[wagon_id]
+ if data then -- wagon actually exists
+ for _,wagon in pairs(minetest.luaentities) do -- find wagon entity
+ if wagon.is_wagon and wagon.initialized and wagon.id==wagon_id then
+ wagon.set_fc(data,fc_list[index]) -- overwrite to new FC
+ break -- no point cycling through every other entity. we found our wagon
+ end
+ end
+ end
+ end
+ end
+ end,
set_shunt = function()
-- enable shunting mode
if not train_id then return false end