diff options
-rw-r--r-- | durt/nodes/(-2132,8,914).lua | 29 | ||||
-rw-r--r-- | durt/nodes/(-2135,21,920).lua | 25 | ||||
-rw-r--r-- | durt/nodes/(-2213,7,887).lua (renamed from durt/nodes/(-2213,8,898).lua) | 4 | ||||
-rw-r--r-- | durt/nodes/(1718,17,4636).lua | 1 | ||||
-rw-r--r-- | durt/nodes/(1740,17,4636).lua | 1 | ||||
-rw-r--r-- | durt/nodes/(1751,17,4655).lua | 1 | ||||
-rw-r--r-- | durt/nodes/(1759,17,4623).lua | 1 | ||||
-rw-r--r-- | durt/nodes/(1780,18,4595).lua | 1 | ||||
-rw-r--r-- | m4/init_code.lua | 130 |
9 files changed, 154 insertions, 39 deletions
diff --git a/durt/nodes/(-2132,8,914).lua b/durt/nodes/(-2132,8,914).lua index ec8cd4a..5229dce 100644 --- a/durt/nodes/(-2132,8,914).lua +++ b/durt/nodes/(-2132,8,914).lua @@ -1,17 +1,22 @@ -local trigger = POS(-2130,21,925) -if event.train then - if getstate(trigger)=="off" then return end - digiline_send("ars_set_query",true) - return -end +local ch = { + get = "ars_set_query", + input = "ars_set", + indicator = "ars_indicator", +} -if event.digiline and event.channel=="ars_set" and atc_id then - set_rc(event.msg) - setstate(trigger,"off") +if event.train then + digiline_send(ch.get, "GET") return end -if event.digiline and event.channel=="ars_indicator" then - setstate(trigger,event.msg) - return +if event.digiline then + if event.channel==ch.input then + if not atc_id then + digiline_send(ch.indicator, true) + return + end + set_rc(tostring(event.msg)) + digiline_send(ch.indicator, false) + return + end end
\ No newline at end of file diff --git a/durt/nodes/(-2135,21,920).lua b/durt/nodes/(-2135,21,920).lua deleted file mode 100644 index 74dac88..0000000 --- a/durt/nodes/(-2135,21,920).lua +++ /dev/null @@ -1,25 +0,0 @@ -local ch = { - output = "ars_manual_input", - get = "ars_set_query", - input = "ars_set", - indicator = "ars_indicator", - lcd = "lcd", - debug = "debug" -} - -if event.train then - digiline_send(ch.get, "GET") - return -end - -if event.digiline then - if event.channel==ch.input then - if not atc_id then - digiline_send(ch.indicator, true) - return - end - set_rc(tostring(event.msg)) - digiline_send(ch.indicator, false) - return - end -end
\ No newline at end of file diff --git a/durt/nodes/(-2213,8,898).lua b/durt/nodes/(-2213,7,887).lua index 0be631f..2a67431 100644 --- a/durt/nodes/(-2213,8,898).lua +++ b/durt/nodes/(-2213,7,887).lua @@ -1,13 +1,13 @@ if event.type=="digiline" then if event.channel ~= "trainctl" then return end if not atc_id then return end - local cmd = "I+S0WR;S4" + local cmd = "I+S0WR;S3" if event.msg == "send" then atc_send(cmd) return end if event.msg == "send_cpl" then - atc_send(cmd.."CplWS0WRS4") + atc_send(cmd.."CplS0WRS3") return end end
\ No newline at end of file diff --git a/durt/nodes/(1718,17,4636).lua b/durt/nodes/(1718,17,4636).lua new file mode 100644 index 0000000..7489acc --- /dev/null +++ b/durt/nodes/(1718,17,4636).lua @@ -0,0 +1 @@ +--
\ No newline at end of file diff --git a/durt/nodes/(1740,17,4636).lua b/durt/nodes/(1740,17,4636).lua new file mode 100644 index 0000000..7489acc --- /dev/null +++ b/durt/nodes/(1740,17,4636).lua @@ -0,0 +1 @@ +--
\ No newline at end of file diff --git a/durt/nodes/(1751,17,4655).lua b/durt/nodes/(1751,17,4655).lua new file mode 100644 index 0000000..7489acc --- /dev/null +++ b/durt/nodes/(1751,17,4655).lua @@ -0,0 +1 @@ +--
\ No newline at end of file diff --git a/durt/nodes/(1759,17,4623).lua b/durt/nodes/(1759,17,4623).lua new file mode 100644 index 0000000..7489acc --- /dev/null +++ b/durt/nodes/(1759,17,4623).lua @@ -0,0 +1 @@ +--
\ No newline at end of file diff --git a/durt/nodes/(1780,18,4595).lua b/durt/nodes/(1780,18,4595).lua new file mode 100644 index 0000000..7489acc --- /dev/null +++ b/durt/nodes/(1780,18,4595).lua @@ -0,0 +1 @@ +--
\ No newline at end of file diff --git a/m4/init_code.lua b/m4/init_code.lua index 8133311..5d055f0 100644 --- a/m4/init_code.lua +++ b/m4/init_code.lua @@ -94,3 +94,133 @@ function F.cpl_looparound(ln) end --end of new cpl functions + + +--[[ Utility Functions +]]-- +F.indicator = function(indicator,set) + if set ~= nil then + if type(set) == string then + setstate(indicator,set) + else + setstate(indicator,(set and "on") or "off") + end + end + return (getstate(indicator) == "on") or false +end + +F.dir = F.indicator -- legacy alias, to be updated to F.indicator + +F.get_rc_safe = function() + return get_rc() or "" +end + +F.has_rc = function(query,rc_list) -- query = string, single entry + if not atc_id then return false end + if rc_list == "" or query == nil or query=="" then return false end + if not rc_list then rc_list = F.get_rc_safe() end + for word in rc_list:gmatch("[^%s]+") do + if word == query then return true end + end + -- print(F.get_rc_safe()) + return false +end + +F.has_rc_match = function(query,rc_list) -- query = pattern string, single entry + if not atc_id then return false end + if rc_list == "" or query == nil or query=="" then return false end + if not rc_list then rc_list = F.get_rc_safe() end + + local rc = {} + for v in rc_list:gmatch("("..query..")") do + table.insert(rc,v) + end + + if rc[1] == true then + return true, rc + else + return nil + end +end + +F.add_rc = function(rc_list) -- rc_list = string or table, eg: {"rc1","rc2"} OR "rc1 rc2" + if not atc_id then return false end + if type(rc_list) == "table" then + rc_list = table.concat(rc_list," ") + end + set_rc(F.get_rc_safe().." "..rc_list) + -- print(F.get_rc_safe()) + return true +end + +F.remove_rc = function(rc_list,arrow_mode) -- rc_list = string eg: "rc1 rc2 rc3" OR table eg: {"rc1","rc2","rc3"} + -- Arrow Modes: + -- true: with arrow direction + -- false: against arrow direction + -- nil: ignores arrow direction + + if not atc_id then return false end + if not rc_list then return false end + + if (arrow_mode == nil) or (atc_arrow == arrow_mode) then + -- prep rc_list to useable format + local rc_remove = {} + if type(rc_list) == "string" then + for word in rc_list:gmatch("[^%s]+") do + rc_remove[word] = true + end + elseif type(rc_list) == "table" then + for _,word in pairs(rc_list) do + rc_remove[word] = true + end + end + + -- remove codes from train's rc + local rc = F.get_rc_safe() + 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 + set_rc(table.concat(reinsert," ")) + end + -- print(F.get_rc_safe()) + return reinsert +end + +F.remove_rc_match = function(rc_list) -- rc_list = pattern string, single entry, eg: "rc_%d+" + if not atc_id then return false end + if not rc_list then return false end + local rm = {} + for v in F.get_rc_safe():gmatch("("..rc_list..")") do + table.insert(rm,v) + end + F.remove_rc(rm) + -- print(F.get_rc_safe()) + return rm +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
\ No newline at end of file |