-- Track Circuit Breaks and Track Sections - Player interaction
local players_assign_tcb = {}
local players_assign_signal = {}
local players_link_ts = {}
local ildb = advtrains.interlocking.db
local ilrs = advtrains.interlocking.route
local sigd_equal = advtrains.interlocking.sigd_equal
local lntrans = { "A", "B" }
local function sigd_to_string(sigd)
return minetest.pos_to_string(sigd.p).." / "..lntrans[sigd.s]
end
minetest.register_node("advtrains_interlocking:tcb_node", {
drawtype = "mesh",
paramtype="light",
paramtype2="facedir",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/6, -1/2, -1/6, 1/6, 1/4, 1/6},
},
mesh = "at_il_tcb_node.obj",
tiles = {"at_il_tcb_node.png"},
description="Track Circuit Break",
sunlight_propagates=true,
groups = {
cracky=3,
not_blocking_trains=1,
--save_in_at_nodedb=2,
at_il_track_circuit_break = 1,
},
after_place_node = function(pos, node, player)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Unconfigured Track Circuit Break, right-click to assign.")
end,
on_rightclick = function(pos, node, player)
local pname = player:get_player_name()
if not minetest.check_player_privs(pname, "interlocking") then
minetest.chat_send_player(pname, "Insufficient privileges to use this!")
return
end
local meta = minetest.get_meta(pos)
local tcbpts = meta:get_string("tcb_pos")
if tcbpts ~= "" then
local tcbpos = minetest.string_to_pos(tcbpts)
local tcb = ildb.get_tcb(tcbpos)
if tcb then
advtrains.interlocking.show_tcb_form(tcbpos, pname)
else
minetest.chat_send_player(pname, "This TCB has been removed. Please dig marker.")
end
else
--unconfigured
minetest.chat_send_player(pname, "Configuring TCB: Please punch the rail you want to assign this TCB to.")
players_assign_tcb[pname] = pos
end
end,
--on_punch = function(pos, node, player)
-- local meta = minetest.get_meta(pos)
-- local tcbpts = meta:get_string("tcb_pos")
-- if tcbpts ~= "" then
-- local tcbpos = minetest.string_to_pos(tcbpts)
-- advtrains.interlocking.show_tcb_marker(tcbpos)
-- end
--end,
can_dig = function(pos, player)
if player == nil then return false end
local pname = player:get_player_name()
-- Those markers can only be dug when all adjacent TS's are set
-- as EOI.
local meta = minetest.get_meta(pos)
local tcbpts = meta:get_string("tcb_pos")
if tcbpts ~= "" then
if not minetest.check_player_privs(pname, "interlocking") then
minetest.chat_send_player(pname, "Insufficient privileges to use this!")
return
end
local tcbpos = minetest.string_to_pos(tcbpts)
local tcb = ildb.get_tcb(tcbpos)
if not tcb then return true end
for connid=1,2 do
if tcb[connid].ts_id or tcb[connid].signal then
minetest.chat_send_player(pname, "Can't remove TCB: Both sides must have no track section and no signal assigned!")
return false
end
|