aboutsummaryrefslogtreecommitdiff
path: root/util/master
diff options
context:
space:
mode:
authorNovatux <nathanael.courant@laposte.net>2013-05-06 18:53:15 +0200
committerproller <proller@github.com>2013-10-16 21:58:29 +0400
commit34e0a0ca0fbb6826ea0c583295f79307b1a754c6 (patch)
tree25397c2e2d93d5438f35e5cfea83adf446f3cc78 /util/master
parent4e5760a5416cbca6945b1b4484cbd96bea7b250c (diff)
Add tool callback
Diffstat (limited to 'util/master')
0 files changed, 0 insertions, 0 deletions
ef='#n87'>87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
-- 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.