diff options
Diffstat (limited to 'm4')
-rw-r--r-- | m4/init_code.lua | 127 | ||||
-rw-r--r-- | m4/nodes/(-1524,-11,-4611).lua | 3 | ||||
-rw-r--r-- | m4/nodes/(-1921,13,-4576).lua | 5 | ||||
-rw-r--r-- | m4/nodes/(-1967,-11,-4415).lua | 3 | ||||
-rw-r--r-- | m4/nodes/(1345,3,-5637).lua | 5 | ||||
-rw-r--r-- | m4/nodes/(4045,24,5650).lua | 19 | ||||
-rw-r--r-- | m4/nodes/(5397,13,6916).lua | 3 |
7 files changed, 165 insertions, 0 deletions
diff --git a/m4/init_code.lua b/m4/init_code.lua index 8133311..d32be9f 100644 --- a/m4/init_code.lua +++ b/m4/init_code.lua @@ -94,3 +94,130 @@ 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.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 diff --git a/m4/nodes/(-1524,-11,-4611).lua b/m4/nodes/(-1524,-11,-4611).lua new file mode 100644 index 0000000..6272a7b --- /dev/null +++ b/m4/nodes/(-1524,-11,-4611).lua @@ -0,0 +1,3 @@ +if get_line()=="52" then + atc_set_text_outside("Line 52 - Olo Beach") +end
\ No newline at end of file diff --git a/m4/nodes/(-1921,13,-4576).lua b/m4/nodes/(-1921,13,-4576).lua new file mode 100644 index 0000000..eb9b943 --- /dev/null +++ b/m4/nodes/(-1921,13,-4576).lua @@ -0,0 +1,5 @@ +if event.train then + if get_line()=="E36" then + atc_set_text_outside("[E36] Souford\nSouthbound Express (SBX)") + end +end
\ No newline at end of file diff --git a/m4/nodes/(-1967,-11,-4415).lua b/m4/nodes/(-1967,-11,-4415).lua new file mode 100644 index 0000000..afb0335 --- /dev/null +++ b/m4/nodes/(-1967,-11,-4415).lua @@ -0,0 +1,3 @@ +if get_line()=="52" then + atc_set_text_outside("Line 52 - Merliansas Ruins") +end
\ No newline at end of file diff --git a/m4/nodes/(1345,3,-5637).lua b/m4/nodes/(1345,3,-5637).lua new file mode 100644 index 0000000..b34a162 --- /dev/null +++ b/m4/nodes/(1345,3,-5637).lua @@ -0,0 +1,5 @@ +if event.train then + if get_line()=="E36" then + atc_set_text_outside("[E36] Melinka\nSouthbound Express (SBX)") + end +end
\ No newline at end of file diff --git a/m4/nodes/(4045,24,5650).lua b/m4/nodes/(4045,24,5650).lua new file mode 100644 index 0000000..037b135 --- /dev/null +++ b/m4/nodes/(4045,24,5650).lua @@ -0,0 +1,19 @@ +do return end +-- delete above line to re-enable reversing into Factory +if event.schedule then + if atc_id and atc_id == event.msg then + schedule_in("0;04",atc_id) + print("ping") + return + end + atc_send_to_train(event.msg, "B0WRS3") + setstate(POS(4051,24,5653),"cr") + print("end: "..event.msg) + return +end +if event.train and atc_arrow and get_line() == "E8" then + atc_send("B2") + schedule_in("0;04",atc_id) + print("Start "..atc_id) + return +end
\ No newline at end of file diff --git a/m4/nodes/(5397,13,6916).lua b/m4/nodes/(5397,13,6916).lua new file mode 100644 index 0000000..e9f1e05 --- /dev/null +++ b/m4/nodes/(5397,13,6916).lua @@ -0,0 +1,3 @@ +if event.train and get_line()=="E16" then +atc_set_text_outside("[E16] Personhood\nvia Grub Valley\nC&C Rail") +end
\ No newline at end of file |