aboutsummaryrefslogtreecommitdiff
path: root/assets/manual_img
ModeNameSize
-rw-r--r--Bildschirmfoto_2016-09-17_09-43-29.png9345logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-45-38.png16695logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-46-21.png18834logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-48-54.png14032logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-50-27.png4246logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-51-02.png3704logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-52-17.png13788logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-52-40.png13889logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-53-01.png15473logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-56-34.png2789logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-58-20.png10375logplain
-rw-r--r--Bildschirmfoto_2016-09-17_09-58-39.png6880logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-04-12.png72813logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-04-57.png105448logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-05-51.png93538logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-07-13.png83521logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-08-02.png107762logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-09-01.png112579logplain
-rw-r--r--Bildschirmfoto_2016-09-17_10-10-15.png114075logplain
-rw-r--r--Bildschirmfoto_2016-12-13_19-25-26.png15044logplain
-rw-r--r--Bildschirmfoto_2017-03-09_11-33-09.png3496logplain
-rw-r--r--Bildschirmfoto_2017-03-09_11-42-49.png25657logplain
-rw-r--r--screenshot_20161203_223055.png824772logplain
-rw-r--r--screenshot_20161203_223328.png526640logplain
-rw-r--r--screenshot_20161203_230644.png610738logplain
-rw-r--r--screenshot_20161203_230648.png555494logplain
-rw-r--r--screenshot_20161203_231622.png108256logplain
-rw-r--r--screenshot_20161203_232335.png1607786logplain
-rw-r--r--screenshot_20161203_232545.png1527310logplain
f='#n534'>534 535 536
-- Signal API implementation


--[[
Signal aspect table:
asp = {
	main = {
		free = <boolean>,
		speed = <int km/h>,
	},
	shunt = {
		free = <boolean>,
		-- Whether train may proceed as shunt move, on sight
		-- main aspect takes precedence over this
		proceed_as_main = <boolean>,
		-- If an approaching train is a shunt move and "main.free" is set,
		-- the train may proceed as a train move under the "main" aspect
		-- If this is not set, shunt moves are NOT allowed to switch to
		-- a train move, and must stop even if "main.free" is set.
		-- This is intended to be used for "Halt for shunt moves" signs.
	}
	dst = {
		free = <boolean>,
		speed = <int km/h>,
	}
	info = {
		call_on = <boolean>, -- Call-on route, expect train in track ahead (not implemented yet)
		dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper) (not implemented yet)
		w_speed = <integer>,
		-- "Warning speed restriction". Supposed for short-term speed
		-- restrictions which always override any other restrictions
		-- imposed by "speed" fields, until lifted by a value of -1
		-- (Example: german Langsamfahrstellen-Signale)
	}
}
-- For "speed" and "w_speed" fields, a value of -1 means that the
-- restriction is lifted. If they are omitted, the value imposed at
-- the last aspect received remains valid.
-- The "dst" subtable can be completely omitted when no explicit dst
-- aspect should be signalled to the train. In this case, the last
-- signalled dst aspect remains valid.

== How signals actually work in here ==
Each signal (in the advtrains universe) is some node that has at least the
following things:
- An "influence point" that is set somewhere on a rail
- An aspect which trains that pass the "influence point" have to obey

There can be static and dynamic signals. Static signals are, roughly
spoken, signs, while dynamic signals are "real" signals which can display
different things.

The node definition of a signal node should contain those fields:
groups = {
  	advtrains_signal = 2,
	save_in_at_nodedb = 1,
}
advtrains = {
	set_aspect = function(pos, node, asp)
		-- This function gets called whenever the signal should display
		-- a new or changed signal aspect. It is not required that
		-- the signal actually displays the exact same aspect, since
		-- some signals can not do this by design.
		-- Example: pure shunt signals can not display a "main" aspect
		-- and have no effect on train moves, so they will only ever
		-- honor the shunt.free field for their aspect.
		-- In turn, it is not guaranteed that the aspect will fulfill the
		-- criteria put down in supported_aspects.
		-- If set_aspect is present, supported_aspects should also be declared.
		
		-- The aspect passed in here can always be queried using the
		-- advtrains.interlocking.signal_get_supposed_aspect(pos) function.
		-- It is always DANGER when the signal is not used as route signal.
		
		-- For static signals, this function should be completely omitted
		-- If this function is omitted, it won't be possible to use
		-- route setting on this signal.
	end,
	supported_aspects = {
		-- A table which tells which different types of aspects this signal
		--  is able to display. It is used to construct the "aspect editing"
		--  formspec for route programming (and others) It should always be
		--  present alongside with set_aspect. If this is not specified but
		--  set_aspect is, the user will be allowed to select any aspect.
		-- Any of the fields marked with <boolean/nil> support 3 types of values:
				nil: if this signal can switch between free/blocked
				false: always shows "blocked", unchangable
				true: always shows "free", unchangable
		-- Any of the "speed" fields should contain a list of possible values
		--  to be set as restriction. If omitted, this signal should never
		--  set the corresponding "speed" field in the aspect, which means
		--  that the previous speed limit stays valid
		-- If your signal can only display a single speed (may it be -1),
		--  always enclose that single value into a list. (such as {-1})
		main = {
			free = <boolean/nil>,
			speed = {<speed1>, ..., <speedn>} or nil,
		},
		dst = {
			free = <boolean/nil>,
			speed = {<speed1>, ..., <speedn>} or nil,
		},
		shunt = {
			free = <boolean/nil>,
		},
		info = {
			call_on = <boolean/nil>,
			dead_end = <boolean/nil>,
			w_speed = {<speed1>, ..., <speedn>} or nil,
		}
		
	},
	get_aspect = function(pos, node)
		-- This function gets called by the train safety system. It
		should return the aspect that this signal actually displays,
		not preferably the input of set_aspect.
		-- For regular, full-featured light signals, they will probably
		honor all entries in the original aspect, however, e.g.
		simple shunt signals always return main.free=true regardless of
		the set_aspect input because they can not signal "Halt" to
		train moves.
		-- advtrains.interlocking.DANGER contains a default "all-danger" aspect.
		-- If your signal does not cover certain sub-tables of the aspect,
		the following reasonable defaults are automatically assumed:
		main = {
			free = true,
		}
		dst = {
			free = true,
		}
		shunt = {
			free = false,
			proceed_as_main = false,
		}
	end,
}
on_rightclick = advtrains.interlocking.signal_rc_handler
can_dig =  advtrains.interlocking.signal_can_dig
after_dig_node = advtrains.interlocking.signal_after_dig

(If you need to specify custom can_dig or after_dig_node callbacks,
please call those functions anyway!)

Important note: If your signal should support external ways to set its
aspect (e.g. via mesecons), there are some things that need to be considered:
- advtrains.interlocking.signal_get_supposed_aspect(pos) won't respect this
- Whenever you change the signal aspect, and that aspect change
did not happen through a call to
advtrains.interlocking.signal_set_aspect(pos, asp), you are
*required* to call this function:
advtrains.interlocking.signal_on_aspect_changed(pos)
in order to notify trains about the aspect change.
This function will query get_aspect to retrieve the new aspect.

]]--

local DANGER = {
	main = {
		free = false,
		speed = 0,
	},
	shunt = {
		free = false,
	},
	dst = {
		free = false,
		speed = 0,
	},
	info = {}
}
advtrains.interlocking.DANGER = DANGER

local function fillout_aspect(asp)
	if not asp.main then
		asp.main = {
			free = true,
		}
	end
	if not asp.dst then
		asp.dst = {
			free = true,
		}
	end 
	if not asp.shunt then
		asp.shunt = {
			free = false,
			proceed_as_main = false,
		}
	end
	if not asp.info then
		asp.info = {}
	end
end

function advtrains.interlocking.update_signal_aspect(tcbs)
	if tcbs.signal then
		local asp = tcbs.aspect or DANGER
		advtrains.interlocking.signal_set_aspect(tcbs.signal, asp)
	end
end

function advtrains.interlocking.signal_can_dig(pos)
	return not advtrains.interlocking.db.get_sigd_for_signal(pos)
end

function advtrains.interlocking.signal_after_dig(pos)
	-- clear influence point
	advtrains.interlocking.db.clear_ip_by_signalpos(pos)
end

function advtrains.interlocking.signal_set_aspect(pos, asp)
	fillout_aspect(asp)
	local node=advtrains.ndb.get_node(pos)
	local ndef=minetest.registered_nodes[node.name]
	if ndef and ndef.advtrains and ndef.advtrains.set_aspect then
		ndef.advtrains.set_aspect(pos, node, asp)
		advtrains.interlocking.signal_on_aspect_changed(pos)
	end
end

-- should be called when aspect has changed on this signal.
function advtrains.interlocking.signal_on_aspect_changed(pos)
	local ipts, iconn = advtrains.interlocking.db.get_ip_by_signalpos(pos)
	if not ipts then return end
	local ipos = minetest.string_to_pos(ipts)
	
	local tns = advtrains.occ.get_trains_over(ipos)
	for id, sidx in pairs(tns) do
--		local train = advtrains.trains[id]
		--if train.index <= sidx then
		minetest.after(0, advtrains.invalidate_path, id)
		--end
	end
end

function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing)
	local pname = player:get_player_name()
	local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
	if sigd then
		advtrains.interlocking.show_signalling_form(sigd, pname)
	else
		local ndef = minetest.registered_nodes[node.name]
		if ndef.advtrains and ndef.advtrains.set_aspect then