aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/testtools/README.md
blob: a1eb95ed72f3d8eacceeea05ed808a2b508bcfa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
# Test Tools readme

Test Tools is a mod for developers that adds a bunch of tools to directly manipulate nodes and entities. This is great for quickly testing out stuff.

Here's the list of tools:

## Remover
Removes nodes and non-player entities that you punch.

## Node Setter
Replace a node with another one.

First, punch a node you want to remember.
Then rightclick any other node to replace it with the node you remembered.

If you rightclick while pointing nothing, you can manually enter the node and param2.

## Param2 Tool
Change the value param2 of nodes.

* Punch: Add 1 to param2
* Sneak+Punch: Add 8 to param2
* Place: Subtract 1 from param2
* Sneak+Place: Subtract 8 from param2

Note: Use the debug screen (F5) to see the param2 of the pointed node.

## Falling Node Tool
Turns nodes into falling nodes.

Usage:

* Punch node: Make it fall
* Place: Try to teleport up to 2 units upwards, then make it fall

## Node Meta Editor
Edit and view metadata of nodes.

Usage:

* Punch: Open node metadata editor

## Entity Rotator
Changes the entity rotation (with `set_rotation`).

Usage:

* Punch entity: Rotate yaw
* Punch entity while holding down “Sneak” key: Rotate pitch
* Punch entity while holding down “Special” key (aka “Aux”): Rotate roll

Each usage rotates the entity by 22.5°.

## Entity Spawner
Spawns entities.

Usage:

* Punch to select entity or spawn one directly
* Place to place selected entity

## Object Property Editor
Edits properties of objects.

Usage:

* Punch object to open a formspec that allows you to view and edit properties
* Punch air to edit properties of your own player object

To edit a property, select it in the list, enter a new value (in Lua syntax)
and hit “Submit”.

## Object Attacher
Allows you to attach an object to another one.

Basic usage:
* First select the parent object, then the child object that should be attached
* Selecting an object is done by punching it
* Sneak+punch to detach selected object
* If you punch air, you select yourself

Configuration:
* Place: Increase attachment Y position
* Sneak+place: decrease attachment Y position
* Aux+place: Increase attachment X rotation
* Aux+Sneak+Rightclick: Decrease attachment X rotation

Hint: To detach all objects nearby you (including on yourself), use the
`/detach` server command.

## Object Mover
Move an object by a given distance.

Usage:
* Punch object into the direction you want to move it
* Sneak+punch: Move object towards you
* Place: Increase move distance
* Sneak+place: Decrease move distance

## Children Getter
Shows list of objects that are attached to an object (aka "children") in chat.

Usage:
* Punch object: Show children of punched object
* Punch air: Show your own children

## Entity Visual Scaler
Change visual size of entities

Usage:

* Punch entity to increase visual size
* Sneak+punch entity to decrease visual size

## Light Tool
Show light level of node.

Usage:
* Punch: Show light info of node in front of the punched node's side
* Place: Show light info of the node that you touched
'>264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
-- Signal API implementation


--[[
Signal aspect table:
Note: All speeds are measured in m/s, aka the number of + signs in the HUD.
asp = {
	main = <int speed>,
		-- Main signal aspect, tells state and permitted speed of next section
		-- 0 = section is blocked
		-- >0 = section is free, speed limit is this value
		-- -1 = section is free, maximum speed permitted
		-- false/nil = Signal doesn't provide main signal information, retain current speed limit.
	shunt = <boolean>,
		-- Whether train may proceed as shunt move, on sight
		-- main aspect takes precedence over this
		-- When main==0, train switches to shunt move and is restricted to speed 6
	proceed_as_main = <boolean>,
		-- If an approaching train is a shunt move and 'shunt' is false,
		-- the train may proceed as a train move under the "main" aspect
		-- if the main aspect permits it (i.e. main!=0)
		-- If this is not set, shunt moves are NOT allowed to switch to
		-- a train move, and must stop even if "main" would permit passing.
		-- This is intended to be used for "Halt for shunt moves" signs.
	
	dst = <int speed>,
		-- Distant signal aspect, tells state and permitted speed of the section after next section
		-- The character of these information is purely informational
		-- At this time, this field is not actively used
		-- 0 = section is blocked
		-- >0 = section is free, speed limit is this value
		-- -1 = section is free, maximum speed permitted
		-- false/nil = Signal doesn't provide distant signal information.
	
	-- the character of call_on and dead_end is purely informative
	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)
	}
}

== 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. However, it must
		-- display an aspect that is at least as restrictive as the passed
		-- aspect as far as it is capable of doing so.
		-- Examples:
		-- - 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.
		-- - the german Hl system can only signal speeds of 40, 60
		--   and 100 km/h, a speed of 80km/h should then be signalled
		--   as 60 km/h instead.
		-- 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, the value of the described
		--  field is always assumed to be false (no information)
		-- A speed of 0 means that the signal can show a "blocked" aspect
		--  (which is probably the case for most signals)
		-- If the signal can signal "no information" on one of the fields
		--  (thus false is an acceptable value), include false in the list
		-- 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 = {<speed1>, ..., <speedn>} or nil,
		dst = {<speed1>, ..., <speedn>} or nil,
		shunt = <boolean/nil>,
		
		call_on = <boolean/nil>,
		dead_end = <boolean/nil>,
		w_speed = {<speed1>, ..., <speedn>} or nil,
		
	},
	Example for supported_aspects:
	supported_aspects = {
		main = {0, 6, -1}, -- can show either "Section blocked", "Proceed at speed 6" or "Proceed at maximum speed"
		dst = {0, false}, -- can show only if next signal shows "blocked", no other information.
		shunt = false, -- shunting by this signal is never allowed.
		
		call_on = false,
		dead_end = false,
		w_speed = nil,
		-- none of the information can be shown by the signal
		
	},
	
	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=false 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 = false (unchanged)
		dst = false (unchanged)
		shunt = false (shunting not allowed)
		info = {} (no further information)
	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 = 0,
	dst = false,
	shunt = false,
}
advtrains.interlocking.DANGER = DANGER

advtrains.interlocking.GENERIC_FREE = {
	main = -1,
	shunt = false,
	dst = false,
}

local function convert_aspect_if_necessary(asp)