aboutsummaryrefslogtreecommitdiff
path: root/textures/base/pack/debug_btn.png
blob: 66bd41f7abc7e16fa061b881747ba2920177ee4d (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 40 00 00 00 40 08 06 00 00 00 aa 69 71 .PNG........IHDR...@...@......iq
0020 de 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0d d7 00 .....bKGD..............pHYs.....
0040 00 0d d7 01 42 28 9b 78 00 00 00 07 74 49 4d 45 07 de 0c 0c 01 17 29 2d 35 f3 8b 00 00 03 4d 49 ....B(.x....tIME......)-5.....MI
0060 44 41 54 78 da ed 98 5d 68 8e 61 18 80 ef 77 46 23 6b 11 63 24 61 b1 a5 76 a0 a4 14 85 22 22 29 DATx...]h.a...wF#k.c$a..v...."")
0080 c9 81 31 72 e0 a7 fc ad 70 40 24 39 a1 fc 1d 60 0e fc 44 38 14 72 64 96 bf 34 56 22 7f 4b 68 22 ..1r....p@$9...`..D8.rd..4V".Kh"
00a0 da b2 2d b4 c6 b6 cb c9 fd e6 e9 e9 7b bf 7d d8 fa 5e af fb 3a f9 be ef fe 79 be f7 be df e7 b9 ..-.........{.}..^..:....y......
00c0 9f e7 7e 44 0c c3 30 0c c3 30 0c c3 30 0c c3 30 fe 33 82 de 18 14 18 2a 22 cd 41 10 74 38 b2 1a ..~D..0..0..0..0.3.....*".A.t8..
00e0 11 f9 2c 22 77 44 e4 5e 10 04 f7 13 97 4d a0 0f b0 11 68 05 b6 39 f2 42 a0 8b 5f d4 c7 e5 99 73 ..,"wD.^.....M....h..9.B.._....s
0100 7b 30 f8 42 11 b9 28 22 33 54 b4 03 40 44 26 8a 48 89 37 db ee 25 f1 ed f7 03 9e 92 19 af 81 b9 {0.B..("3T..@D&.H.7..%..........
0120 ea 37 00 58 94 94 24 2c 20 73 ba 80 a3 9a 8c 4e 60 ea bf 1e 7c 2e 70 9b 3f e7 31 d0 b7 9b ff 28 .7.X..$,.s.....N`...|.p.?.1....(
0140 01 f2 e2 16 f8 61 60 05 b0 27 45 50 d5 c0 6c 60 38 30 06 58 07 7c 4a 93 84 65 de d8 63 81 4b 40 .....a`..'EP..l`80.X.|J..e..c.K@
0160 81 fe 7e 03 b4 01 83 e3 12 7c 71 9a 60 8e 44 f8 8c 06 1a 3c db 26 60 39 10 78 b6 17 55 ff 14 78 ..~......|q.`.D....<.&`9.x..U..x
0180 a7 df bf 01 13 74 c6 0d cb 76 02 2a 22 82 7f 01 e4 a4 f1 9b e3 d9 d7 46 d8 ad 8e 18 ff 0b f0 0c .....t...v.*"..........F........
01a0 a8 05 fa 64 33 01 27 23 1e 70 7b 37 7e 01 f0 d1 b1 ff ee be 7d a0 1c d8 0f 34 03 1d c0 26 dd 2d ...d3.'#.p{7~.......}....4...&.-
01c0 06 01 07 1d bf 3a a0 28 9b 09 18 06 2c 06 6a bc 04 2c c9 c0 b7 d6 f3 59 0f 94 a8 ee aa 23 af 4a .....:.(....,.j..,.....Y.....#.J
01e0 e1 7b 4b 75 d3 e3 52 0b 36 7b c1 6c e9 c6 3e 07 78 1f 31 7b ca 80 29 c0 65 fd bd 36 85 ff 7e d5 .{Ku..R.6{.l..>.x.1{..).e..6..~.
0200 9d 00 8a e3 90 80 99 fe 9a f6 0b 9a 67 3f 3f 22 f8 e6 b0 76 38 f5 e5 4c 0a ff 6a c7 e7 58 b6 83 ............g??"...v8..L..j..X..
0220 2f 00 8e a7 08 66 67 84 fd 48 a7 a2 fb 5c 53 9b 52 e0 89 73 60 aa 04 fa 02 f9 c0 5e 95 bf 01 0e /....fg..H...\S.R..s`......^....
0240 85 27 ca 6c 26 e0 41 9a ad f0 12 30 59 8b 57 29 b0 01 f8 e0 d9 b4 00 4b 81 03 40 b9 8e 99 af 4b .'.l&.A....0Y.W).......K..@....K
0260 e4 b1 16 c8 54 cc 8a cb fa 5f cc df b1 32 62 dc 71 5a 2b a6 a9 5d a7 ce 9c b0 76 ec 8b d3 69 f0 ....T...._...2b.qZ+..]....v...i.
0280 9a 3e d4 d5 df 68 88 00 9e a7 ab 15 3a 76 19 f0 03 b8 e9 1c be 2e 00 a3 e2 94 80 31 61 47 a7 d3 .>...h......:v.............1aG..
02a0 f7 84 d7 ff a7 63 79 06 e3 e7 03 e3 fe a5 c6 68 b0 4e d9 90 af da 28 55 01 e7 1d 79 3b b0 d5 f1 .....cy........h.N....(U...y;...
02c0 9b 01 14 01 8b 80 73 c0 9a 58 bd e9 df 48 80 bf cd 9d 73 74 fd 81 57 ba 95 95 aa 6c 08 70 5a 67 ......s..X...H....st..W....l.pZg
02e0 4d bd f6 06 21 15 b1 eb 00 33 48 40 11 b0 0a 38 05 bc f4 0f 33 aa 77 8f be e3 bd 19 e3 d2 a8 5b M...!....3H@...8....3.w........[
0300 5e 32 2e 4d 52 24 6b 21 70 26 83 5a d1 00 0c 4c 62 02 ae 7b 81 ee d6 65 52 0c 3c 74 e4 6f c3 5e ^2.MR$k!p&.Z...Lb..{...eR.<t.o.^
0320 21 69 b7 c8 2d ee b6 e8 e9 a7 3b ba 1b c0 90 9e 7e 86 9c 2c e7 20 47 44 dc c6 e9 9b a7 6f 73 be !i..-.....;.....~..,..GD.....os.
0340 cf 14 91 5d 89 4a 40 10 04 3f 44 a4 c9 11 4d 02 56 84 3d 86 88 ec f5 5c ee 26 b1 06 54 a6 28 78 ...].J@..?D...M.V.=....\.&..T.(x
0360 ad 7a 46 08 69 d3 eb b1 11 49 4c 40 ae de ec 34 a6 d9 01 ae f4 e6 1a 94 2c 2f 83 0e 11 99 27 22 .zF.i....IL@...4........,/....'"
0380 23 44 e4 91 a3 6a 17 91 2e fd ac eb ae 67 48 ca 6c 28 07 ce ea a5 6a 9e 5e 8a 96 88 61 18 86 61 #D...j.......gH.l(....j.^...a..a
03a0 18 86 61 18 86 61 18 86 d1 73 fc 04 b1 3e cf 06 d0 e7 5d d4 00 00 00 00 49 45 4e 44 ae 42 60 82 ..a..a...s...>....].....IEND.B`.
='n197' href='#n197'>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 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 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
-- Track Circuit Breaks and Track Sections - Player interaction

local players_assign_tcb = {}
local players_assign_signal = {}
local players_link_ts = {}

local ildb = advtrains.interlocking.db
local ilrs = advtrains.interlocking.route

local sigd_equal = advtrains.interlocking.sigd_equal

local lntrans = { "A", "B" }

local function sigd_to_string(sigd)
	return minetest.pos_to_string(sigd.p).." / "..lntrans[sigd.s]
end

minetest.register_node("advtrains_interlocking:tcb_node", {
	drawtype = "mesh",
	paramtype="light",
	paramtype2="facedir",
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-1/6, -1/2, -1/6, 1/6, 1/4, 1/6},
	},
	mesh = "at_il_tcb_node.obj",
	tiles = {"at_il_tcb_node.png"},
	description="Track Circuit Break",
	sunlight_propagates=true,
	groups = {
		cracky=3,
		not_blocking_trains=1,
		--save_in_at_nodedb=2,
		at_il_track_circuit_break = 1,
	},
	after_place_node = function(pos, node, player)
		local meta = minetest.get_meta(pos)
		meta:set_string("infotext", "Unconfigured Track Circuit Break, right-click to assign.")
	end,
	on_rightclick = function(pos, node, player)
		local pname = player:get_player_name()
		if not minetest.check_player_privs(pname, "interlocking") then
			minetest.chat_send_player(pname, "Insufficient privileges to use this!")
			return
		end
		
		local meta = minetest.get_meta(pos)
		local tcbpts = meta:get_string("tcb_pos")
		if tcbpts ~= "" then
			local tcbpos = minetest.string_to_pos(tcbpts)
			advtrains.interlocking.show_tcb_form(tcbpos, pname)
		else
			if not minetest.check_player_privs(pname, "interlocking") then
				minetest.chat_send_player(pname, "Insufficient privileges to use this!")
				return
			end
			--unconfigured
			minetest.chat_send_player(pname, "Configuring TCB: Please punch the rail you want to assign this TCB to.")
			
			players_assign_tcb[pname] = pos
		end	
	end,
	--on_punch = function(pos, node, player)
	--	local meta = minetest.get_meta(pos)
	--	local tcbpts = meta:get_string("tcb_pos")
	--	if tcbpts ~= "" then
	--		local tcbpos = minetest.string_to_pos(tcbpts)
	--		advtrains.interlocking.show_tcb_marker(tcbpos)
	--	end	
	--end,
	can_dig = function(pos, player)
		local pname = player:get_player_name()

		-- Those markers can only be dug when all adjacent TS's are set
		-- as EOI.
		local meta = minetest.get_meta(pos)
		local tcbpts = meta:get_string("tcb_pos")
		if tcbpts ~= "" then
			if not minetest.check_player_privs(pname, "interlocking") then
				minetest.chat_send_player(pname, "Insufficient privileges to use this!")
				return
			end			
			local tcbpos = minetest.string_to_pos(tcbpts)
			local tcb = ildb.get_tcb(tcbpos)
			if not tcb then return true end
			for connid=1,2 do
				if tcb[connid].ts_id then
					return false
				end
			end
		end	
		return true
	end,
	after_dig_node = function(pos, oldnode, oldmetadata, player)
		if not oldmetadata or not oldmetadata.fields then return end
		local tcbpts = oldmetadata.fields.tcb_pos
		if tcbpts and tcbpts ~= "" then
			local tcbpos = minetest.string_to_pos(tcbpts)
			ildb.remove_tcb(tcbpos)
		end
	end,
})

minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
	local pname = player:get_player_name()
	if not minetest.check_player_privs(pname, "interlocking") then
		return
	end
	-- TCB assignment
	local tcbnpos = players_assign_tcb[pname]
	if tcbnpos then
		if vector.distance(pos, tcbnpos)<=20 then
			local node_ok, conns, rhe = advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
			if node_ok and #conns == 2 then
				local ok = ildb.create_tcb(pos)
				
				if not ok then
					minetest.chat_send_player(pname, "Configuring TCB: TCB already exists at this position. Aborted.")
				end
				
				ildb.sync_tcb_neighbors(pos, 1)
				ildb.sync_tcb_neighbors(pos, 2)
				
				local meta = minetest.get_meta(tcbnpos)
				meta:set_string("tcb_pos", minetest.pos_to_string(pos))
				meta:set_string("infotext", "TCB assigned to "..minetest.pos_to_string(pos))
				minetest.chat_send_player(pname, "Configuring TCB: Successfully configured TCB")
			else
				minetest.chat_send_player(pname, "Configuring TCB: This is not a normal two-connection rail! Aborted.")
			end
		else
			minetest.chat_send_player(pname, "Configuring TCB: Node is too far away. Aborted.")
		end
		players_assign_tcb[pname] = nil
	end
	
	-- Signal assignment
	local sigd = players_assign_signal[pname]
	if sigd then
		if vector.distance(pos, sigd.p)<=50 then
			local is_signal = minetest.get_item_group(node.name, "advtrains_signal") >= 2
			if is_signal then
				local ndef = minetest.registered_nodes[node.name]
				if ndef and ndef.advtrains and ndef.advtrains.set_aspect then
					local tcbs = ildb.get_tcbs(sigd)
					if tcbs then
						tcbs.signal = pos
						if not tcbs.signal_name then
							tcbs.signal_name = "Signal at "..minetest.pos_to_string(sigd.p)
						end
						if not tcbs.routes then
							tcbs.routes = {}
						end
						ildb.set_sigd_for_signal(pos, sigd)
						minetest.chat_send_player(pname, "Configuring TCB: Successfully assigned signal.")
						advtrains.interlocking.show_ip_form(pos, pname, true)
					else
						minetest.chat_send_player(pname, "Configuring TCB: Internal error, TCBS doesn't exist. Aborted.")
					end
				else
					minetest.chat_send_player(pname, "Configuring TCB: Cannot use static signals for routesetting. Aborted.")
				end
			else
				minetest.chat_send_player(pname, "Configuring TCB: Not a compatible signal. Aborted.")
			end
		else
			minetest.chat_send_player(pname, "Configuring TCB: Node is too far away. Aborted.")
		end
		players_assign_signal[pname] = nil
	end
end)

-- TCB Form

local function mktcbformspec(tcbs, btnpref, offset, pname)
	local form = ""
	local ts
	if tcbs.ts_id then
		ts = ildb.get_ts(tcbs.ts_id)
	end
	if ts then
		form = form.."label[0.5,"..offset..";Side "..btnpref..": "..ts.name.."]"
		form = form.."button[0.5,"..(offset+0.5)..";5,1;"..btnpref.."_gotots;Show track section]"
		if ildb.may_modify_tcbs(tcbs) then
			-- Note: the security check to prohibit those actions is located in database.lua in the corresponding functions.
			form = form.."button[0.5,"..(offset+1.5)..";2.5,1;"..btnpref.."_update;Update near TCBs]"
			form = form.."button[3  ,"..(offset+1.5)..";2.5,1;"..btnpref.."_remove;Remove from section]"
		end
	else
		tcbs.ts_id = nil
		form = form.."label[0.5,"..offset..";Side "..btnpref..": ".."End of interlocking]"
		form = form.."button[0.5,"..(offset+0.5)..";5,1;"..btnpref.."_makeil;Create Interlocked Track Section]"
		--if tcbs.section_free then
			--form = form.."button[0.5,"..(offset+1.5)..";5,1;"..btnpref.."_setlocked;Section is free]"
		--else
			--form = form.."button[0.5,"..(offset+1.5)..";5,1;"..btnpref.."_setfree;Section is blocked]"		
		--end
	end
	if tcbs.signal then
		form = form.."button[0.5,"..(offset+2.5)..";5,1;"..btnpref.."_sigdia;Signalling]"	
	else
		form = form.."button[0.5,"..(offset+2.5)..";5,1;"..btnpref.."_asnsig;Assign a signal]"
	end
	return form
end


function advtrains.interlocking.show_tcb_form(pos, pname)
	if not minetest.check_player_privs(pname, "interlocking") then
		minetest.chat_send_player(pname, "Insufficient privileges to use this!")
		return
	end
	local tcb = ildb.get_tcb(pos)
	if not tcb then return end
	
	local form = "size[6,9] label[0.5,0.5;Track Circuit Break Configuration]"
	form = form .. mktcbformspec(tcb[1], "A", 1, pname)
	form = form .. mktcbformspec(tcb[2], "B", 5, pname)
	
	minetest.show_formspec(pname, "at_il_tcbconfig_"..minetest.pos_to_string(pos), form)
	advtrains.interlocking.show_tcb_marker(pos)
end

--helper: length of nil table is 0
local function nlen(t)
	if not t then return 0 end
	return #t
end


minetest.register_on_player_receive_fields(function(player, formname, fields)
	local pname = player:get_player_name()
	if not minetest.check_player_privs(pname, "interlocking") then
		return
	end
	local pts = string.match(formname, "^at_il_tcbconfig_(.+)$")
	local pos
	if pts then
		pos = minetest.string_to_pos(pts)
	end
	if pos and not fields.quit then
		local tcb = ildb.get_tcb(pos)
		if not tcb then return end
		local f_gotots = {fields.A_gotots, fields.B_gotots}
		local f_update = {fields.A_update, fields.B_update}
		local f_remove = {fields.A_remove, fields.B_remove}
		local f_makeil = {fields.A_makeil, fields.B_makeil}
		local f_setlocked = {fields.A_setlocked, fields.B_setlocked}
		local f_setfree = {fields.A_setfree, fields.B_setfree}
		local f_asnsig = {fields.A_asnsig, fields.B_asnsig}
		local f_sigdia = {fields.A_sigdia, fields.B_sigdia}
		
		for connid=1,2 do
			local tcbs = tcb[connid]
			if tcbs.ts_id then
				if f_gotots[connid] then
					advtrains.interlocking.show_ts_form(tcbs.ts_id, pname)
					return
				end
				if f_update[connid] then
					ildb.sync_tcb_neighbors(pos, connid)
				end
				if f_remove[connid] then
					ildb.remove_from_interlocking({p=pos, s=connid})
				end
			else
				if f_makeil[connid] then
					-- try sinc_tcb_neighbors first
					ildb.sync_tcb_neighbors(pos, connid)
					-- if that didn't work, create new section
					if not tcbs.ts_id then
						ildb.create_ts({p=pos, s=connid})
						ildb.sync_tcb_neighbors(pos, connid)
					end
				end
				-- non-interlocked
				if f_setfree[connid] then
					tcbs.section_free = true
				end
				if f_setlocked[connid] then
					tcbs.section_free = nil
				end
			end
			if f_asnsig[connid] and not tcbs.signal then
				minetest.chat_send_player(pname, "Configuring TCB: Please punch the signal to assign.")