#LyX 2.2 created this file. For more info see http://www.lyx.org/ \lyxformat 508 \begin_document \begin_header \save_transient_properties true \origin unavailable \textclass paper \use_default_options true \maintain_unincluded_children false \language english \language_package default \inputencoding auto \fontencoding global \font_roman "default" "default" \font_sans "default" "default" \font_typewriter "default" "default" \font_math "auto" "auto" \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 100 \font_tt_scale 100 100 \graphics default \default_output_format default \output_sync 0 \bibtex_command default \index_command default \paperfontsize default \spacing single \use_hyperref false \papersize default \use_geometry true \use_package amsmath 1 \use_package amssymb 1 \use_package cancel 1 \use_package esint 1 \use_package mathdots 1 \use_package mathtools 1 \use_package mhchem 1 \use_package stackrel 1 \use_package stmaryrd 1 \use_package undertilde 1 \cite_engine basic \cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false \justification true \use_refstyle 1 \index Index \shortcut idx \color #008000 \end_index \leftmargin 1cm \topmargin 1cm \rightmargin 1cm \bottommargin 1cm \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \paragraph_indentation 0bp \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false \end_header \begin_body \begin_layout Title Minetest Mod - Advanced Trains [advtrains] \end_layout \begin_layout Title Interlocking System Guide \end_layout \begin_layout Section Introduction \end_layout \begin_layout Standard In real-world railways, a so-called interlocking system is a set of railway signals and trackside equipment. Its purpose is to prevent conflicting train movements which otherwise could result in derailing or colliding trains. If you want more information, just search for \begin_inset Quotes eld \end_inset railway interlocking \begin_inset Quotes erd \end_inset on the internet. \end_layout \begin_layout Standard Real-world interlocking systems perform this task by setting routes. A route is a path along a track that a train can safely pass. To set a route for a train, the signalman (the operator of a signal box) has to set switches (turnouts) to the correct position and lock them in order to make a signal for a train show \begin_inset Quotes eld \end_inset Proceed \begin_inset Quotes erd \end_inset . In newer systems, this is done automatically by the interlocking system. A route can not be set if switches are locked to a wrong position by another route or if any portion of the route is occupied by a train. \end_layout \begin_layout Standard The interlocking system in this Minetest mod tries to follow real-world interlocking systems as far as applicable. It divides tracks into track sections and implements a route setting mechanism following the same principle. \end_layout \begin_layout Standard However, for the sake of simplicity of implementation and usage, not all concepts of real-world interlocking have been taken over. Especially, there is no mechanism for overlap. \end_layout \begin_layout Standard If you are looking for a place to learn how real-world interlocking systems work, have a look at \begin_inset Quotes eld \end_inset SimSig \begin_inset Quotes erd \end_inset . By looking at their simulations, you can obtain experience on how to set up your own interlocking systems in AdvTrains. The SimSig glossary is a good place to look up unknown terms in this document. \end_layout \begin_layout Section Setting up track sections \end_layout \begin_layout Standard In the real world, a line of track is divided into so-called track sections, or track circuits. Those systems often can not tell where exactly a train is, but only which track sections it occupies. A route can never be set through an occupied track section. \end_layout \begin_layout Standard A track section often covers: \end_layout \begin_layout Itemize A section on a main running line, between two signals \end_layout \begin_layout Itemize A single turnout \end_layout \begin_layout Itemize A rail crossing, or a set of turnouts acting as a double/single slip switch \end_layout \begin_layout Itemize A siding \end_layout \begin_layout Standard You will find some examples on how to interlock certain patterns later. \end_layout \begin_layout Subsection Track Circuit Breaks \end_layout \begin_layout Standard In this mod, you will not directly configure the locations of track sections. Instead, you designate the borders of each track section using a special node, the Track Circuit Break, abbreviated TCB. \end_layout \begin_layout Standard For example, if you want to create a track section for a piece of a main running line, you set up two TCBs at the ends of this track circuit. \end_layout \begin_layout Standard Setting up a TCB works as follows: \end_layout \begin_layout Enumerate Place a TCB node somewhere near the place where the circuit break is going to be located. \end_layout \begin_layout Enumerate Right-click the TCB node \end_layout \begin_layout Enumerate Punch the rail which should act as TCB \end_layout \begin_layout Standard The result should look like this: \end_layout \begin_layout Standard \begin_inset Graphics filename lyx_img/screenshot_20180830_142551.png width 10cm \end_inset \end_layout \begin_layout Standard Now you have assigned the TCB node to a rail. Right-click the TCB node once again. This will bring up a form which looks as follows: \end_layout \begin_layout Standard \begin_inset Graphics filename lyx_img/Bildschirmfoto_2018-08-30_14-26-35.png width 10cm \end_inset \end_layout \begin_layout Standard You see that the form is divided in side A and side B. To designate where each side is, a marker is displayed on the rail. You can always make this marker show up by punching the TCB node, and remove it by punching the marker. Both sides are shown as \begin_inset Quotes eld \end_inset End of interlocking \begin_inset Quotes erd \end_inset . This means that there is no track section set up at this place. \end_layout \begin_layout Standard You should repeat this procedure once again a few meters away from the first TCB to create a second TCB on the same track. \end_layout \begin_layout Standard \begin_inset Graphics filename lyx_img/Bildschirmfoto_2018-08-30_14-32-48.png width 10cm \end_inset \end_layout \begin_layout Standard Once you have both bordering TCBs set up, you can now create the actual track section. To do this: \end_layout \begin_layout Enumerate Right-click one of the TCBs \end_layout \begin_layout Enumerate Locate the correct side (A or B) to create the track section \end_layout \begin_layout Enumerate Click \begin_inset Quotes eld \end_inset Create interlocked Track Section \begin_inset Quotes erd \end_inset in the formspec on the chosen side. \end_layout \begin_layout Standard Now, the text on the formspec has changed. It shows something like this: \end_layout \begin_layout Standard \begin_inset Graphics filename lyx_img/Bildschirmfoto_2018-08-30_14-27-25.png width 5cm \end_inset \end_layout \begin_layout Standard Clicking \begin_inset Quotes eld \end_inset Show Track Section \begin_inset Quotes erd \end_inset brings up another formspec: \end_layout \begin_layout Standard \begin_inset Graphics filename lyx_img/Bildschirmfoto_2018-08-30_14-28-32.png width 5cm \end_inset \end_layout \begin_layout Standard On the top, you see a list of all TCBs that border this track section. In your case, there should be two TCBs listed. If there's only one, head over to \begin_inset CommandInset ref LatexCommand ref reference "subsec:Long-track-sections," \end_inset . You should now select a name for the track section, to identify it later. \end_layout \begin_layout Standard The same procedure is applicable when you create a turnout track section, except that you have to set up three or more TCBs. \end_layout \begin_layout Standard The AdvTrains interlocking system allows you to add more TCBs after you have created a track section. This works without problems in most cases. For example, you can easily insert a turnout into an already set-up track section and create another TCB behind it, and AdvTrains will automatically detect the existing track section. Problems arise only if you try to insert a TCB in-between a section, in which case both sides of the TCB will end up assigned to the same section. The code currently does not handle this case properly, so try to avoid this situation by all means. As a last resort, you can always dissolve a faulty track section, as described in the next chapter. \end_layout \begin_layout Subsection Long track sections, crossings and other edge cases \begin_inset CommandInset label LatexCommand label name "subsec:Long-track-sections," \end_inset \end_layout \begin_layout Subsubsection Very long track sections \end_layout \begin_layout Standard If you try to set up a track section that is longer than 1000 nodes, advtrains won't recognize the TCB at the other end because of a safety limit in the traverser function, which is supposed to prevent deadlocks. This case has happened when the Track Section overview screen only shows one TCB in the list. The procedure for this is as follows: \end_layout \begin_layout Enumerate Go to the second TCB (the one that wasn't recognized). It should show \begin_inset Quotes eld \end_inset End of Interlocking \begin_inset Quotes erd \end_inset on the relevant side. \end_layout \begin_layout Enumerate Click \begin_inset Quotes eld \end_inset Create interlocked track section \begin_inset Quotes erd \end_inset . The section created will be different from the one that is already present. \end_layout \begin_layout Enumerate In the track section overview, click \begin_inset Quotes eld \end_inset Join into other section \begin_inset Quotes erd \end_inset \end_layout \begin_layout Enumerate Go back to the first TCB, bring up the Track Section overview screen of the first track section and click \begin_inset Quotes eld \end_inset Join with ??? \begin_inset Quotes erd \end_inset \end_layout \begin_layout Standard The other, missing TCB should now appear in the list. If you accidentally started such a joining procedure, click the \begin_inset Quotes eld \end_inset X \begin_inset Quotes erd \end_inset button on the right. \end_layout \begin_layout Subsubsection Rail crosses \end_layout \begin_layout Standard Since rail crosses are created by laying tracks across each other without logical connection, there's no way for advtrains to know whether rails cross each other. \end_layout \begin_layout Standard Rail crossings in interlocking systems are always one single track section, which in most cases has 4 TCBs adjacent. \end_layout \begin_layout Standard \begin_inset Graphics filename lyx_img/Bildschirmfoto_2018-08-30_14-51-25.png width 5cm \end_inset \end_layout \begin_layout Standard The procedure is quite similar to the one for long sections: First, create two track sections for the branches, and then use the \begin_inset Quotes eld \end_inset Join \begin_inset Quotes erd \end_inset function to merge both sections into one. \end_layout \begin_layout Subsubsection Deleting and re-adding single TCBs to a section \end_layout \begin_layout Standard In some occasions, for example when you remove a siding or a crossover, it can be necessary to unassign a TCB from a track section. There are multiple ways to do this: \end_layout \begin_layout Itemize In the TCB form, click the \begin_inset Quotes eld \end_inset Remove from section \begin_inset Quotes erd \end_inset button \end_layout \begin_layout Itemize In the track section form, first select the TCB in the list and then click \begin_inset Quotes eld \end_inset Unlink selected TCB \begin_inset Quotes erd \end_inset \end_layout \begin_layout Standard The result is that the TCB shows \begin_inset Quotes eld \end_inset End of Interlocking \begin_inset Quotes erd \end_inset and the section does not list the TCB as an endpoint anymore. \end_layout \begin_layout Standard The other case is adding a siding or a crossover, in which case one or more TCBs still show \begin_inset Quotes eld \end_inset End of Interlocking \begin_inset Quotes erd \end_inset alt-- tracks.lua -- rewritten with advtrains 2.5 according to new track registration system --[[ Tracks in advtrains are defined by the node definition. They must have at least 2 connections, but can have any number. Switchable nodes (turnouts, single/double-slip switches) are implemented by having a separate node (node name) for each of the possible states. minetest.register_node(nodename, { ... usual node definition ... groups = { advtrains_track = 1, advtrains_track_<tracktype>=1 ^- these groups tell that the node is a track not_blocking_trains=1, ^- this group tells that the node should not block trains although it's walkable. }, at_rail_y = 0, ^- Height of this rail node (the y position of a wagon that stands centered on this rail) at_conns = { [1] = { c=0..15, y=0..1 }, [2] = { c=0..15, y=0..1 }, ( [3] = { c=0..15, y=0..1 }, ) ( [4] = { c=0..15, y=0..1 }, ) ( ... ) } ^- Connections of this rail. There are two general cases: a) SIMPLE TRACK - the track has exactly 2 connections, and does not feature a turnout, crossing or other contraption For simple tracks, except for the at_conns table no further setup needs to be specified. A train entering on conn 1 will go out at conn 2 and vice versa. A track with only one connection defined is not permitted. b) COMPOUND TRACK - the track has more than 2 connections This will be used for turnouts and crossings. Tracks with more than 2 conns MUST define 'at_conn_map'. Switchable nodes, whose state can be changed (e.g. turnouts) MUST define a 'state_map' within the advtrains table as well. This differs from the behavior up until 2.4.2, where the conn mapping was fixed. ^- Connection definition: - c is the direction of the connection (0-16). For the mapping to world directions see helpers.lua. - Connections will be auto-rotated with param2 of the node (horizontal, param2 values 0-3 only) - y is the height of the connection (rail will only connect when this matches) ^- The index of a connection inside the conns table (1, 2, 3, ...) is referred throughout advtrains code as 'connid' ^- IMPORTANT: For switchable nodes (any kind of turnout), it is crucial that for all of the node's variants the at_conns table stays the same. See below. at_conn_map = { [1] = 2, [2] = 1, [3] = 1, } ^- Connection map of this rail. It specifies when a train enters the track on connid X, on which connid it will leave This field MUST be specified when the number of connections in at_conns is greater than 2 This field may, and obviously will, vary between nodes for switchable nodes. can_dig = advtrains.track_can_dig_callback after_dig_node = advtrains.track_update_callback after_place_node = advtrains.track_update_callback ^- the code in these 3 default minetest API functions is required for advtrains to work, however you can add your own code on_rightclick = advtrains.state_node_on_rightclick_callback ^- Must be added if the node is a turnout and if it should be switched by right-click. It will cause the turnout to be switched to next_state. advtrains = { on_train_enter=function(pos, train_id, train, index) end ^- called when a train enters the rail on_train_leave=function(pos, train_id, train, index) end ^- called when a train leaves the rail -- The following function is only in effect when interlocking is enabled: on_train_approach = function(pos, train_id, train, index, has_entered, lzbdata) ^- called when a train is approaching this position, called exactly once for every path recalculation (which can happen at any time) ^- This is called so that if the train would start braking now, it would come to halt about(wide approx) 5 nodes before the rail. ^- has_entered: when true, the train is already standing on this node with its front tip, and the enter callback has already been called. Possibly, some actions need not to be taken in this case. Only set if it's the very first node the train is standing on. ^- lzbdata should be ignored and nothing should be assigned to it -- The following information is required if the node is a turnout (e.g. can be switched into different positions) node_state = "st" ^- The name of the state this node represents ^- Conventions for this field are as follows: - Two-way straight/turn switches: 'st'=straight branch, 'cr'=diverting/turn branch - 3-way turnouts, Y-turnouts: 'l'=left branch, 's'=straight branch, 'r'=right branch node_next_state = "cr" ^- The name of the state that the turnout should be switched to when it is right-clicked node_fallback_state = "st" ^- The name of the state that the turnout should "fall back" to when it is released Only used by the interlocking system, when a route on the node is released it is switched back to this state. node_state_map = { ["st"] = "<node name of the st variant>", ["cr"] = "<node name of the cr variant>", ... etc ... } ^- Map of state name to the appropriate node name that should be set by advtrains when a switch is requested Note that for all of those nodes, the at_conns table must be identical (however the conn_map will vary) node_on_switch_state = function(pos, node, oldstate, newstate) ^- Called when the node state is switched by advtrains, after the node replacement has commenced. Turnout switching can happen programmatically via advtrains.setstate(pos, state), via user right_click or via the interlocking system. In no other situation is it permissible to exchange track nodes in-place, unless both at_conns and at_conn_map stay identical. Note that the fields node_state, node_next_state and node_state_map completely replace the getstate/setstate functions. There must be a one-to-one mapping between states and node names and no function can be defined for state switching. This principle enables the seamless working of the interlocking autorouter and reduces failure points. The node_state_* system can also be used as drop-in replacement for the passive-API-enabled nodes (andrews-cross, mesecon_switch etc.) The advtrains API functions advtrains.getstate() and advtrains.setstate() remain the programmatic access points, but will now utilize the new state system. trackworker_next_rot = <nodename of next rotation step>, ^- if set, right-click with trackworker will set this node trackworker_rot_incr_param2 = true ^- if set, trackworker will increase node param2 on rightclick trackworker_next_var = <nodename of next variant> ^- if set, left-click with trackworker will set this node } }) ]]-- -- This file provides some utilities to register tracks, but tries to not get into the way too much function advtrains.track_can_dig_callback(pos, player) local ok, reason = advtrains.can_dig_or_modify_track(pos) if not ok and player then minetest.chat_send_player(player:get_player_name(), attrans("This track can not be removed!") .. " " .. reason) end return ok end function advtrains.track_update_callback(pos) advtrains.ndb.update(pos) end function advtrains.state_node_on_rightclick_callback(pos, node, player) if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then local ndef = minetest.registered_nodes[node.name] if ndef and ndef.advtrains and ndef.advtrains.node_next_state then advtrains.setstate(pos, ndef.advtrains.node_next_state, node) advtrains.log("Switch", player:get_player_name(), pos) end end end -- advtrains.register_node_4rot(name, nodedef) -- Registers four rotations for the node defined by nodedef (0°, 30°, 45° and 60°; the 4 90°-steps are already handled by the param2, resulting in 16 directions total). -- You must provide the definition for the base node, and certain fields are altered automatically for the 3 additional rotations: -- name: appends the suffix "_30", "_45" or "_60" -- description: appends the rotation (human-readable) in parenthesis -- tiles_prefix: if defined, "tiles" field will be set as prefix..rotationExtension..".png" -- mesh_prefix, mesh_suffix: if defined, "mesh" field will be set as prefix..rotationExtension..suffix -- at_conns: are rotated according to the node rotation -- node_state_map, trackworker_next_var: appends the suffix appropriately. -- groups: applies save_in_at_nodedb and not_blocking_trains groups if not already present -- The nodes are registered in the trackworker to be rotated with right-click. -- definition_mangling_function is an optional parameter. For each of the 4 rotations, it gets passed the modified node definition and may perform final modifications to it. -- signature: function definition_mangling_function(name, nodedef, rotationIndex, rotationSuffix) -- Example usage: define the setstate function of turnouts (if that is not done via the "automatic" way of state_node_map) local rotations = { {i = 0, s = "", h = " (0)", n = "_30"}, {i = 1, s = "_30", h = " (30)", n = "_45"}, {i = 2, s = "_45", h = " (45)", n = "_60"}, {i = 3, s = "_60", h = " (60)", n = ""}, } function advtrains.register_node_4rot(ori_name, ori_ndef, definition_mangling_function) for _, rot in ipairs(rotations) do local ndef = table.copy(ori_ndef) if ori_ndef.advtrains then -- make sure advtrains table is deep-copied because we may need to replace node_state_map ndef.advtrains = table.copy(ori_ndef.advtrains) else ndef.advtrains = {} -- we need the table later for trackworker end -- Perform the name mangling local suffix = rot.s local name = ori_name..suffix ndef.description = ori_ndef.description .. rot.h if ori_ndef.tiles_prefix then ndef.tiles = { ori_ndef.tiles_prefix .. suffix .. ".png" } end if ori_ndef.mesh_prefix then ndef.mesh = ori_ndef.mesh_prefix .. suffix .. ori_ndef.mesh_suffix end -- rotate connections if ori_ndef.at_conns then ndef.at_conns = advtrains.rotate_conn_by(ori_ndef.at_conns, rot.i) end -- update node state map if present if ori_ndef.advtrains then if ori_ndef.advtrains.node_state_map then local new_nsm = {} for state, nname in pairs(ori_ndef.advtrains.node_state_map) do new_nsm[state] = nname .. suffix end ndef.advtrains.node_state_map = new_nsm end if ori_ndef.advtrains.trackworker_next_var then ndef.advtrains.trackworker_next_var = ori_ndef.advtrains.trackworker_next_var .. suffix end -- apply trackworker rot field ndef.advtrains.trackworker_next_rot = ori_name .. rot.n ndef.advtrains.trackworker_rot_incr_param2 = (rot.n=="") end -- apply groups ndef.groups.save_in_at_nodedb = 1 ndef.groups.not_blocking_trains = 1 -- give the definition mangling function an option to do some adjustments if definition_mangling_function then definition_mangling_function(name, ndef, rot.i, suffix) end -- register node minetest.register_node(":"..name, ndef) -- if this has the track_place_group set, register as a candidate for the track_place_group if ndef.advtrains.track_place_group then advtrains.trackplacer.register_candidate(ndef.advtrains.track_place_group, name, ndef, ndef.advtrains.track_place_single, true) end end end -- Registers an item to place and automatically connect nearby tracks function advtrains.register_track_placer(...) end -- Registers an item to place and adjust slope tracks function advtrains.register_slope_placer(...) end -- track-related helper functions function advtrains.is_track(nodename) if not minetest.registered_nodes[nodename] then return false end local nodedef=minetest.registered_nodes[nodename] if nodedef and nodedef.groups.advtrains_track then return true end return false end function advtrains.get_track_connections(name, param2) local nodedef=minetest.registered_nodes[name] if not nodedef then atprint(" get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return nil end local noderot=param2 if not param2 then noderot=0 end if noderot > 3 then atprint(" get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end local tracktype for k,_ in pairs(nodedef.groups) do local tt=string.match(k, "^advtrains_track_(.+)$") if tt then tracktype=tt end end return advtrains.rotate_conn_by(nodedef.at_conns, noderot*AT_CMAX/4), (nodedef.at_rail_y or 0), tracktype end -- Function called when a track is about to be dug or modified by the trackworker -- Returns either true (ok) or false,"translated string describing reason why it isn't allowed" function advtrains.can_dig_or_modify_track(pos) if advtrains.get_train_at_pos(pos) then return false, attrans("Position is occupied by a train.") end -- interlocking: tcb, signal IP a.s.o. if advtrains.interlocking then -- TCB? if advtrains.interlocking.db.get_tcb(pos) then return false, attrans("There's a Track Circuit Break here.") end -- signal ip? if advtrains.interlocking.db.is_ip_at(pos, true) then -- is_ip_at with purge parameter return false, attrans("There's a Signal Influence Point here.") end end return true end