Forbid track modification when train, IP or TCB is on it, better handle removing of TCBs (H#149)
This commit is contained in:
parent
a73236d7eb
commit
3256c2778d
|
@ -64,3 +64,8 @@ Passenger Wagon=Passagierwaggon
|
||||||
Box wagon=Güterwaggon
|
Box wagon=Güterwaggon
|
||||||
Subway Passenger Wagon=U-Bahn-Waggon
|
Subway Passenger Wagon=U-Bahn-Waggon
|
||||||
The wagon's inventory is not empty!=Das Inventar dieses Waggons ist nicht leer!
|
The wagon's inventory is not empty!=Das Inventar dieses Waggons ist nicht leer!
|
||||||
|
This track can not be changed!=Diese Schiene kann nicht geändert werden!
|
||||||
|
This track can not be rotated!=Diese Schiene kann nicht gedreht werden!
|
||||||
|
Position is occupied by a train.=Ein Zug steht an dieser Position.
|
||||||
|
There's a Track Circuit Break here.=Hier ist eine Gleisabschnittsgrenze (TCB).
|
||||||
|
There's a Signal Influence Point here.=Hier ist ein Signal-Beeinflussungspunkt.
|
||||||
|
|
|
@ -120,6 +120,11 @@ function tp.rail_and_can_be_bent(originpos, conn)
|
||||||
return advtrains.conn_matches_to(conn, cconns)
|
return advtrains.conn_matches_to(conn, cconns)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- If the rail is not allowed to be modified, also only use if already in desired direction
|
||||||
|
if not advtrains.can_dig_or_modify_track(pos) then
|
||||||
|
local cconns=advtrains.get_track_connections(node.name, node.param2)
|
||||||
|
return advtrains.conn_matches_to(conn, cconns)
|
||||||
|
end
|
||||||
--rail at other end?
|
--rail at other end?
|
||||||
local adj1, adj2=tp.find_already_connected(pos)
|
local adj1, adj2=tp.find_already_connected(pos)
|
||||||
if adj1 and adj2 then
|
if adj1 and adj2 then
|
||||||
|
@ -326,15 +331,7 @@ minetest.register_craftitem("advtrains:trackworker",{
|
||||||
local node=minetest.get_node(pos)
|
local node=minetest.get_node(pos)
|
||||||
|
|
||||||
--if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end
|
--if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end
|
||||||
if advtrains.get_train_at_pos(pos) then return end
|
|
||||||
|
|
||||||
if has_aux1_down then
|
|
||||||
--feature: flip the node by 180°
|
|
||||||
--i've always wanted this!
|
|
||||||
advtrains.ndb.swap_node(pos, {name=node.name, param2=(node.param2+2)%4})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local nnprefix, suffix, rotation=string.match(node.name, "^(.+)_([^_]+)(_[^_]+)$")
|
local nnprefix, suffix, rotation=string.match(node.name, "^(.+)_([^_]+)(_[^_]+)$")
|
||||||
--atdebug(node.name.."\npattern recognizes:"..nnprefix.." / "..suffix.." / "..rotation)
|
--atdebug(node.name.."\npattern recognizes:"..nnprefix.." / "..suffix.." / "..rotation)
|
||||||
--atdebug("nntab: ",tp.tracks[nnprefix])
|
--atdebug("nntab: ",tp.tracks[nnprefix])
|
||||||
|
@ -346,6 +343,28 @@ minetest.register_craftitem("advtrains:trackworker",{
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if the node is modify-protected
|
||||||
|
if advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then
|
||||||
|
-- is a track, we can query
|
||||||
|
local can_modify, reason = advtrains.can_dig_or_modify_track(pos)
|
||||||
|
if not can_modify then
|
||||||
|
local str = attrans("This track can not be rotated!")
|
||||||
|
if reason then
|
||||||
|
str = str .. " " .. reason
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(placer:get_player_name(), str)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if has_aux1_down then
|
||||||
|
--feature: flip the node by 180°
|
||||||
|
--i've always wanted this!
|
||||||
|
advtrains.ndb.swap_node(pos, {name=node.name, param2=(node.param2+2)%4})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local modext=tp.tracks[nnprefix].twrotate[suffix]
|
local modext=tp.tracks[nnprefix].twrotate[suffix]
|
||||||
|
|
||||||
if rotation==modext[#modext] then --increase param2
|
if rotation==modext[#modext] then --increase param2
|
||||||
|
@ -390,6 +409,21 @@ minetest.register_craftitem("advtrains:trackworker",{
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if the node is modify-protected
|
||||||
|
if advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then
|
||||||
|
-- is a track, we can query
|
||||||
|
local can_modify, reason = advtrains.can_dig_or_modify_track(pos)
|
||||||
|
if not can_modify then
|
||||||
|
local str = attrans("This track can not be changed!")
|
||||||
|
if reason then
|
||||||
|
str = str .. " " .. reason
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(user:get_player_name(), str)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local nextsuffix=tp.tracks[nnprefix].twcycle[suffix]
|
local nextsuffix=tp.tracks[nnprefix].twcycle[suffix]
|
||||||
advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..nextsuffix..rotation, param2=node.param2})
|
advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..nextsuffix..rotation, param2=node.param2})
|
||||||
|
|
||||||
|
|
|
@ -478,9 +478,7 @@ function advtrains.register_tracks(tracktype, def, preset)
|
||||||
not_blocking_trains=1,
|
not_blocking_trains=1,
|
||||||
},
|
},
|
||||||
|
|
||||||
can_dig=function(pos)
|
can_dig = advtrains.can_dig_or_modify_track,
|
||||||
return not advtrains.get_train_at_pos(pos)
|
|
||||||
end,
|
|
||||||
after_dig_node=function(pos)
|
after_dig_node=function(pos)
|
||||||
advtrains.ndb.update(pos)
|
advtrains.ndb.update(pos)
|
||||||
end,
|
end,
|
||||||
|
@ -602,6 +600,26 @@ function advtrains.get_track_connections(name, param2)
|
||||||
return advtrains.rotate_conn_by(nodedef.at_conns, noderot*AT_CMAX/4), (nodedef.at_rail_y or 0), tracktype
|
return advtrains.rotate_conn_by(nodedef.at_conns, noderot*AT_CMAX/4), (nodedef.at_rail_y or 0), tracktype
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Function called when a track is about to be dug or modified by the trackworker
|
||||||
|
-- Returns either true (ok) or false,"translated string describing reason why it isn't allowed"
|
||||||
|
function advtrains.can_dig_or_modify_track(pos)
|
||||||
|
if advtrains.get_train_at_pos(pos) then
|
||||||
|
return false, attrans("Position is occupied by a train.")
|
||||||
|
end
|
||||||
|
-- interlocking: tcb, signal IP a.s.o.
|
||||||
|
if advtrains.interlocking then
|
||||||
|
-- TCB?
|
||||||
|
if advtrains.interlocking.db.get_tcb(pos) then
|
||||||
|
return false, attrans("There's a Track Circuit Break here.")
|
||||||
|
end
|
||||||
|
-- signal ip?
|
||||||
|
if advtrains.interlocking.db.is_ip_at(pos) then
|
||||||
|
return false, attrans("There's a Signal Influence Point here.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
-- slope placer. Defined in register_tracks.
|
-- slope placer. Defined in register_tracks.
|
||||||
--crafted with rail and gravel
|
--crafted with rail and gravel
|
||||||
local sl={}
|
local sl={}
|
||||||
|
|
|
@ -526,6 +526,14 @@ function ildb.set_sigd_for_signal(pos, sigd)
|
||||||
signal_assignments[pts] = sigd
|
signal_assignments[pts] = sigd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- checks if there's any influence point set to this position
|
||||||
|
function ildb.is_ip_at(pos)
|
||||||
|
local pts = advtrains.roundfloorpts(pos)
|
||||||
|
if influence_points[pts] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
-- checks if a signal is influencing here
|
-- checks if a signal is influencing here
|
||||||
function ildb.get_ip_signal(pts, connid)
|
function ildb.get_ip_signal(pts, connid)
|
||||||
|
|
|
@ -49,12 +49,13 @@ minetest.register_node("advtrains_interlocking:tcb_node", {
|
||||||
local tcbpts = meta:get_string("tcb_pos")
|
local tcbpts = meta:get_string("tcb_pos")
|
||||||
if tcbpts ~= "" then
|
if tcbpts ~= "" then
|
||||||
local tcbpos = minetest.string_to_pos(tcbpts)
|
local tcbpos = minetest.string_to_pos(tcbpts)
|
||||||
advtrains.interlocking.show_tcb_form(tcbpos, pname)
|
local tcb = ildb.get_tcb(tcbpos)
|
||||||
else
|
if tcb then
|
||||||
if not minetest.check_player_privs(pname, "interlocking") then
|
advtrains.interlocking.show_tcb_form(tcbpos, pname)
|
||||||
minetest.chat_send_player(pname, "Insufficient privileges to use this!")
|
else
|
||||||
return
|
minetest.chat_send_player(pname, "This TCB has been removed. Please dig marker.")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
--unconfigured
|
--unconfigured
|
||||||
minetest.chat_send_player(pname, "Configuring TCB: Please punch the rail you want to assign this TCB to.")
|
minetest.chat_send_player(pname, "Configuring TCB: Please punch the rail you want to assign this TCB to.")
|
||||||
|
|
||||||
|
@ -88,6 +89,11 @@ minetest.register_node("advtrains_interlocking:tcb_node", {
|
||||||
if not tcb then return true end
|
if not tcb then return true end
|
||||||
for connid=1,2 do
|
for connid=1,2 do
|
||||||
if tcb[connid].ts_id or tcb[connid].signal then
|
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
|
||||||
|
if not ildb.may_modify_tcbs(tcb[connid]) then
|
||||||
|
minetest.chat_send_player(pname, "Can't remove TCB: Side "..connid.." forbids modification (shouldn't happen).")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,7 +105,15 @@ minetest.register_node("advtrains_interlocking:tcb_node", {
|
||||||
local tcbpts = oldmetadata.fields.tcb_pos
|
local tcbpts = oldmetadata.fields.tcb_pos
|
||||||
if tcbpts and tcbpts ~= "" then
|
if tcbpts and tcbpts ~= "" then
|
||||||
local tcbpos = minetest.string_to_pos(tcbpts)
|
local tcbpos = minetest.string_to_pos(tcbpts)
|
||||||
ildb.remove_tcb(tcbpos)
|
local success = ildb.remove_tcb(tcbpos)
|
||||||
|
if success and player then
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "TCB has been removed.")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "Failed to remove TCB!")
|
||||||
|
minetest.set_node(pos, oldnode)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("tcb_pos", minetest.pos_to_string(tcbpos))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -118,7 +132,7 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
|
||||||
local ok = ildb.create_tcb(pos)
|
local ok = ildb.create_tcb(pos)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
minetest.chat_send_player(pname, "Configuring TCB: TCB already exists at this position. Aborted.")
|
minetest.chat_send_player(pname, "Configuring TCB: TCB already exists at this position! It has now been re-assigned.")
|
||||||
end
|
end
|
||||||
|
|
||||||
ildb.sync_tcb_neighbors(pos, 1)
|
ildb.sync_tcb_neighbors(pos, 1)
|
||||||
|
|
Loading…
Reference in New Issue