aboutsummaryrefslogtreecommitdiff
path: root/advtrains/tracks.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-10-07 17:20:47 +0200
committerorwell96 <orwell@bleipb.de>2020-10-07 17:20:47 +0200
commit3256c2778d626548541bcdfabf3026f781a2287c (patch)
tree8fac88986a2cd4f00ed6b1855dd1dafa08c09662 /advtrains/tracks.lua
parenta73236d7eb6ff79476d0187ff46e83872fc798be (diff)
downloadadvtrains-3256c2778d626548541bcdfabf3026f781a2287c.tar.gz
advtrains-3256c2778d626548541bcdfabf3026f781a2287c.tar.bz2
advtrains-3256c2778d626548541bcdfabf3026f781a2287c.zip
Forbid track modification when train, IP or TCB is on it, better handle removing of TCBs (H#149)
Diffstat (limited to 'advtrains/tracks.lua')
-rw-r--r--advtrains/tracks.lua24
1 files changed, 21 insertions, 3 deletions
diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua
index 45d45ff..6799c40 100644
--- a/advtrains/tracks.lua
+++ b/advtrains/tracks.lua
@@ -478,9 +478,7 @@ function advtrains.register_tracks(tracktype, def, preset)
not_blocking_trains=1,
},
- can_dig=function(pos)
- return not advtrains.get_train_at_pos(pos)
- end,
+ can_dig = advtrains.can_dig_or_modify_track,
after_dig_node=function(pos)
advtrains.ndb.update(pos)
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
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.
--crafted with rail and gravel
local sl={}