diff options
Diffstat (limited to 'durt/init_code.lua')
-rw-r--r-- | durt/init_code.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/durt/init_code.lua b/durt/init_code.lua index 2cd41c9..85776a4 100644 --- a/durt/init_code.lua +++ b/durt/init_code.lua @@ -23,6 +23,39 @@ if event.init then S.yards = S.yards or list_of_yards end +F.remove_rc = function(rc_list,arrow_mode) + -- rc_list MUST be a table of rc codes to remove + -- eg: {"rc1","rc2"} + -- Arrow Modes: + -- true: with arrow direction + -- false: against arrow direction + -- nil: ignores arrow direction + + if not event.train then return end + if (arrow_mode == nil) or (atc_arrow == arrow_mode) then + local rc = get_rc() or "" + rc_list = rc_list or {} + + -- ensure rc-remove table can be read + local rc_remove = {} + for _,v in pairs(rc_list) do + rc_remove[v] = true + end + + -- remove codes from train's rc + local reinsert = {} + for token in rc:gmatch("[^%s]+") do + if not rc_remove[token] then + table.insert(reinsert,token) + end + end + + -- insert new string to train's rc + rc = table.concat(reinsert," ") + set_rc(rc) + end +end + F.yard_road_count = function(yard,section_id,monitoring_light)
if not S.yards[yard][section_id] then S.yards[yard][section_id] = {['car_count'] = 0} end
local car_count = S.yards[yard][section_id].car_count
if event.train then
if atc_arrow then --arrow points into section, add to length
car_count = car_count + train_length()
else -- subtract from
car_count = car_count - train_length()
end
if car_count > 0 then -- light = on
setstate(monitoring_light,"on")
else
car_count = 0
setstate(monitoring_light,"off")
end
S.yards[yard][section_id].car_count = car_count
end
end |