From 3a6b1ca8500cad74f95b925b191582c0aa739116 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Thu, 17 Nov 2022 23:19:57 +0800 Subject: 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 --- advtrains_luaautomation/atc_rail.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) mode change 100644 => 100755 advtrains_luaautomation/atc_rail.lua (limited to 'advtrains_luaautomation/atc_rail.lua') diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua old mode 100644 new mode 100755 index 5dde99c..aac11f0 --- 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 -- cgit v1.2.3