diff options
author | orwell <orwell@bleipb.de> | 2024-12-03 00:56:17 +0100 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2024-12-03 00:56:17 +0100 |
commit | b2889e33ba389c936b9d6b1ca5be27ef8f147280 (patch) | |
tree | d27093b8d071aa7371883b4f1632a554165e7522 | |
parent | fc13e732224f935bc558902e878e81a40afe4713 (diff) | |
download | advtrains-b2889e33ba389c936b9d6b1ca5be27ef8f147280.tar.gz advtrains-b2889e33ba389c936b9d6b1ca5be27ef8f147280.tar.bz2 advtrains-b2889e33ba389c936b9d6b1ca5be27ef8f147280.zip |
Feature to add passive components to a section as fixed locks (for level crossings)
-rw-r--r-- | advtrains/p_mesecon_iface.lua | 2 | ||||
-rw-r--r-- | advtrains/signals.lua | 2 | ||||
-rw-r--r-- | advtrains_interlocking/database.lua | 7 | ||||
-rwxr-xr-x | advtrains_interlocking/tcb_ts_ui.lua | 59 |
4 files changed, 63 insertions, 7 deletions
diff --git a/advtrains/p_mesecon_iface.lua b/advtrains/p_mesecon_iface.lua index 0b99891..0426e2b 100644 --- a/advtrains/p_mesecon_iface.lua +++ b/advtrains/p_mesecon_iface.lua @@ -46,7 +46,7 @@ minetest.override_item("mesecons_switch:mesecon_switch_on", { mesecon.receptor_off(pos) end end, - fallback_state = "off", + node_fallback_state = "off", on_updated_from_nodedb = function(pos, node) mesecon.receptor_on(pos) end, diff --git a/advtrains/signals.lua b/advtrains/signals.lua index 8bdd877..e3d75c3 100644 --- a/advtrains/signals.lua +++ b/advtrains/signals.lua @@ -310,7 +310,7 @@ minetest.register_node("advtrains:across_on", { advtrains = { node_state = "on", node_state_map = { on = "advtrains:across_on", off = "advtrains:across_off" }, - fallback_state = "off", + node_fallback_state = "off", }, on_rightclick=function(pos, node, player) if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index c05e69a..09b1c72 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -758,6 +758,7 @@ function ildb.update_rs_cache(ts_id) --atdebug("Starting for ",start_tcbi, start_tcbs) local locks_found = {} local result_table = {} + recursively_find_routes(start_tcbs.p, start_tcbs.s, locks_found, result_table, TS_MAX_SCAN) -- now result_table contains found route locks. Match them with the other TCBs we have in this section for end_tcbi, end_tcbs in ipairs(ts.tc_breaks) do @@ -765,7 +766,11 @@ function ildb.update_rs_cache(ts_id) end_pkey = advtrains.encode_pos(end_tcbs.p) if result_table[end_pkey] then --atdebug("Set RSCache entry",end_pkey.."-"..end_pkey,"=",result_table[end_pkey]) - rscache[start_pkey][end_pkey] = result_table[end_pkey] + local lockstab = result_table[end_pkey] + if ts.fixed_locks then -- include the sections fixedlocks if present + for pts, st in pairs(ts.fixed_locks) do lockstab[pts] = st end + end + rscache[start_pkey][end_pkey] = lockstab result_table[end_pkey] = nil end end diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 87e56ca..bc52339 100755 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -4,6 +4,7 @@ local players_assign_tcb = {} local players_assign_signal = {} local players_assign_xlink = {} local players_link_ts = {} +local players_assign_fixedlocks = {} local ildb = advtrains.interlocking.db local ilrs = advtrains.interlocking.route @@ -206,6 +207,28 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing) end players_assign_signal[pname] = nil end + + -- FixedLocks assignment + local ts_id = players_assign_fixedlocks[pname] + if ts_id then + if advtrains.is_passive(pos) then + local pts = advtrains.encode_pos(pos) + local state = advtrains.getstate(pos) + local ts = ildb.get_ts(ts_id) + if ts and ts.fixed_locks then + minetest.chat_send_player(pname, minetest.pos_to_string(pos).." locks in state "..state) + ts.fixed_locks[pts] = state + else + minetest.chat_send_player(pname, "Error: TS modified, abort!") + players_assign_fixedlocks[pname] = nil + end + else + minetest.chat_send_player(pname, "Setting fixed locks finished!") + players_assign_fixedlocks[pname] = nil + ildb.update_rs_cache(ts_id) + advtrains.interlocking.show_ts_form(ts_id, pname) + end + end end) -- "Self-contained TCB" @@ -492,7 +515,7 @@ function advtrains.interlocking.show_ts_form(ts_id, pname) local ts = ildb.get_ts(ts_id) if not ts_id then return end - local form = "size[10,10]label[0.5,0.5;Track Section Detail - "..ts_id.."]" + local form = "size[10.5,10]label[0.5,0.5;Track Section Detail - "..ts_id.."]" form = form.."field[0.8,2;5.2,1;name;Section name;"..minetest.formspec_escape(ts.name or "").."]" form = form.."button[5.5,1.7;1,1;setname;Set]" local hint @@ -503,11 +526,27 @@ function advtrains.interlocking.show_ts_form(ts_id, pname) advtrains.interlocking.show_tcb_marker(sigd.p) end - form = form.."textlist[0.5,3;5,3;tcblist;"..table.concat(strtab, ",").."]" + form = form.."label[0.5,2.5;Boundary TCBs:]" + form = form.."textlist[0.5,3;4,3;tcblist;"..table.concat(strtab, ",").."]" + + -- additional route locks (e.g. for level crossings) + + strtab = {} + if ts.fixed_locks then + for pts, state in pairs(ts.fixed_locks) do + strtab[#strtab+1] = minetest.formspec_escape( + minetest.pos_to_string(advtrains.decode_pos(pts)).." = "..state) + end + end + form = form.."label[5.5,2.5;Fixed route locks (e.g. level crossings):]" + form = form.."textlist[5.5,3;4,3;fixedlocks;"..table.concat(strtab, ",").."]" if ildb.may_modify_ts(ts) then - form = form.."button[5.5,4;4,1;remove;Remove Section]" - form = form.."tooltip[dissolve;This will remove the track section and set all its end points to End Of Interlocking]" + form = form.."button[5.5,6;2,1;flk_add;Add locks]" + form = form.."button[7.5,6;2,1;flk_clear;Clear locks]" + + form = form.."button[5.5,8;4,1;remove;Remove Section]" + form = form.."tooltip[remove;This will remove the track section and set all its end points to End Of Interlocking]" else hint=3 end @@ -564,6 +603,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end + if fields.flk_add then + if not ts.fixed_locks then + ts.fixed_locks = {} + end + players_assign_fixedlocks[pname] = ts_id + minetest.chat_send_player(pname, "Punch components to add fixed locks. (punch anything else = end)") + minetest.close_formspec(pname, formname) + return + elseif fields.flk_clear then + ts.fixed_locks = nil + end + if fields.reset then -- User requested resetting the section -- Show him what this means... |