diff options
Diffstat (limited to 'advtrains_luaautomation/atc_rail.lua')
-rwxr-xr-x[-rw-r--r--] | advtrains_luaautomation/atc_rail.lua | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua index b862129..aac11f0 100644..100755 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -14,7 +14,7 @@ function r.fire_event(pos, evtdata, appr_internal) local railtbl = atlatc.active.nodes[ph] if not railtbl then - atwarn("LuaAutomation ATC interface rail at",ph,": Data not in memory! Please visit position and click 'Save'!") + atwarn("LuaATC interface rail at",ph,": Data not in memory! Please visit position and click 'Save'!") return end @@ -56,7 +56,7 @@ function r.fire_event(pos, evtdata, appr_internal) split_at_index = function(index, cmd) if not train_id then return false end assertt(cmd, "string") - if type(index) ~= "number" then + if type(index) ~= "number" or index < 2 then return false end local new_id = advtrains.split_train_at_index(train, index) @@ -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 @@ -130,9 +162,8 @@ function r.fire_event(pos, evtdata, appr_internal) get_rc = function() return train.routingcode end, - atc_reset = function(cmd) + atc_reset = function() if not train_id then return false end - assertt(cmd, "string") advtrains.atc.train_reset_command(train) return true end, @@ -188,7 +219,7 @@ advtrains.register_tracks("default", { models_prefix="advtrains_dtrack", models_suffix=".b3d", shared_texture="advtrains_dtrack_shared_atc.png", - description=atltrans("LuaAutomation ATC Rail"), + description=atltrans("LuaATC Rail"), formats={}, get_additional_definiton = function(def, preset, suffix, rotation) return { |