From aeea70df13db7d77ce2ce1075cbd14dc1c3797fc Mon Sep 17 00:00:00 2001 From: autocommitter Date: Mon, 22 Apr 2024 14:56:58 +0200 Subject: State at 2022-04-19 --- Tyard/init_code.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) (limited to 'Tyard/init_code.lua') diff --git a/Tyard/init_code.lua b/Tyard/init_code.lua index 99b63e4..a90efdf 100644 --- a/Tyard/init_code.lua +++ b/Tyard/init_code.lua @@ -1,5 +1,67 @@ --- flag to hard enable RTS: -S.single_dir = true +--Environment Code +F.yard_active = function(set) --if set == true then yard = active + local yard_indicator = POS(-4025,14,-2659) + if set ~= nil then + setstate(yard_indicator,(set and "on") or "off") + end + return (getstate(yard_indicator) == "on") or false +end +F.dir = function(set) -- if set == true then dir = pointing north + local dir_indicator = POS(-4025,13,-2665) + if set ~= nil then + setstate(dir_indicator,(set and "on") or "off") + end + return (getstate(dir_indicator) == "on") or false +end -F.EOL = function(direction,lane) if S.yard_active then if S.dir == direction then if atc_arrow then if not S.exiting then --return to PICKUP via headshunt split_off_locomotive("B0WR") set_rc("PICKUP") set_route("TY"..direction.."_"..lane, "HEADSHUNT") else --if S.exiting then loco has already sorted to correct lane for departure --S.exiting set by the pickup track set_rc(S.rc) set_route("TY"..direction.."_"..lane, "EXIT") S.exiting = nil end end else -- preparing for bi-directional. also EOL Bounce atc_send("B0WD1RS4") end end end \ No newline at end of file +F.get_rc_safe = function() + return get_rc() or "" +end + +F.has_rc = function(query,rc_list) + 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 + return false +end + +F.remove_rc = function(rc_list,arrow_mode) -- rc_list eg: {"rc1","rc2"} + -- 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 atc_id then return false end + if (arrow_mode == nil) or (atc_arrow == arrow_mode) then + local rc = F.get_rc_safe() + rc_list = rc_list or {} + 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 + set_rc(table.concat(reinsert," ")) + end + return reinsert +end + +F.add_rc = function(rc_list) -- rc_list 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) + return true +end \ No newline at end of file -- cgit v1.2.3