diff options
author | orwell96 <orwell@bleipb.de> | 2019-01-22 12:07:53 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2019-01-22 12:07:53 +0100 |
commit | 64e59b54f880fde044332e23b80aff3e8ce14b15 (patch) | |
tree | 96d570a86aa516a9e24ea9470bab4894be88fc18 /advtrains_interlocking/database.lua | |
parent | adc8db22fb35e7d18dd20b73478c241b6fed7de0 (diff) | |
download | advtrains-64e59b54f880fde044332e23b80aff3e8ce14b15.tar.gz advtrains-64e59b54f880fde044332e23b80aff3e8ce14b15.tar.bz2 advtrains-64e59b54f880fde044332e23b80aff3e8ce14b15.zip |
Prohibit removing/changing of TCBs and sections while routes or signals are set
Diffstat (limited to 'advtrains_interlocking/database.lua')
-rw-r--r-- | advtrains_interlocking/database.lua | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index 12853c0..af20bea 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -304,6 +304,9 @@ local function merge_ts(root_id, merge_id) if not mts then return end -- This may be the case when sync_tcb_neighbors -- inserts the same id twice. do nothing. + if not ildb.may_modify_ts(rts) then return false end + if not ildb.may_modify_ts(mts) then return false end + -- cobble together the list of TCBs for _, msigd in ipairs(mts.tc_breaks) do local tcbs = ildb.get_tcbs(msigd) @@ -384,12 +387,14 @@ end function ildb.remove_from_interlocking(sigd) local tcbs = ildb.get_tcbs(sigd) + if not ildb.may_modify_tcbs(tcbs) then return false end + if tcbs.ts_id then local tsid = tcbs.ts_id local ts = ildb.get_ts(tsid) if not ts then tcbs.ts_id = nil - return + return true end -- remove entry from the list @@ -411,24 +416,54 @@ function ildb.remove_from_interlocking(sigd) end end advtrains.interlocking.show_tcb_marker(sigd.p) + return true end function ildb.remove_tcb(pos) local pts = advtrains.roundfloorpts(pos) if not track_circuit_breaks[pts] then return end for connid=1,2 do - ildb.remove_from_interlocking({p=pos, s=connid}) + if not ildb.remove_from_interlocking({p=pos, s=connid}) then + return false + end end track_circuit_breaks[pts] = nil + return true end function ildb.dissolve_ts(ts_id) local ts = ildb.get_ts(ts_id) + if not ildb.may_modify_ts(ts) then return false end local tcbr = advtrains.merge_tables(ts.tc_breaks) for _,sigd in ipairs(tcbr) do ildb.remove_from_interlocking(sigd) end -- Note: ts gets removed in the moment of the removal of the last TCB. + return true +end + +-- Returns true if it is allowed to modify any property of a track section, such as +-- - removing TCBs +-- - merging and dissolving sections +-- As of now the action will be denied if a route is set or if a train is in the section. +function ildb.may_modify_ts(ts) + if ts.route or ts.route_post or #ts.trains>0 then + return false + end + return true +end + + +function ildb.may_modify_tcbs(tcbs) + if tcbs.signal then + return false + elseif tcbs.ts_id then + local ts = ildb.get_ts(tcbs.ts_id) + if ts and not ildb.may_modify_ts(ts) then + return false + end + end + return true end -- Utilize the traverser to find the track section at the specified position |