User Tools

Site Tools


Sidebar



Minetest Forum
Content Database
Git Repository
Bug Tracker
Website

usage:atlatc:examples:tis:digilines

Digilines Train Information System

Introduction

Passengers would like to know information about approaching trains. This system gives information using digilines.

This is useful for stations with different, untimetabled services on platforms. The passangers know the time left until the next service.

Explanation

This code waits for a train to roll over the rail, and then calculates various variables:

Variable Calculation Notes
Time left Distance/speed Assumes a constant speed, which is often not the case when decelerating for a station
Time to minutes time/60 Only used when time left exceeds 59 seconds

After all calculations are completed, the track then sends a digilines message with the information formatted:

Line 
In(very approximately)
x seconds
100 metres away
Of 4 carriages

Code

-- Note: this code assumes a constant speed, which helps avoid complexity. The times will be shorter then the real time.
 
distance = 0 -- Whatever your distance is
stopping_lines = {} -- Give a list of lines that stop  (empty for none)
channel = "1" -- Final channel for the message (defaults to 1)
 
prefix = "seconds"
 
-- DETECTION AND ACTING
if event.type == "train" then    
    -- CALCULATION
    time = distance/atc_speed -- Use our delicate formula to get time, in seconds. Of course, on approach, we will be slowing down.
    if time > 59 then
        time = time/60
        prefix = "minutes"  
    end
 
    -- OUTPUT
    message = get_line() .. "\n" .. "In (very approximately)\n" .. time .. " " .. prefix .. ",\n" .. distance .. " metres away" .. "\nOf " .. train_length() .. " carriages"
    digiline_send(channel, message) 
end
usage/atlatc/examples/tis/digilines.txt · Last modified: 2022-06-28 11:56 by 56independent