aboutsummaryrefslogtreecommitdiff
path: root/data/skybox1_dawn.png
blob: 9711c47819be9d823169536679c8c1dbc5e6cf56 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 20 00 00 00 18 08 02 00 00 00 14 31 68 .PNG........IHDR..............1h
0020 63 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 00 c....sRGB.........pHYs..........
0040 9a 9c 18 00 00 00 07 74 49 4d 45 07 db 04 1d 0e 21 17 e6 0c d2 e0 00 00 00 1d 69 54 58 74 43 6f .......tIME.....!.........iTXtCo
0060 6d 6d 65 6e 74 00 00 00 00 00 43 72 65 61 74 65 64 20 77 69 74 68 20 47 49 4d 50 64 2e 65 07 00 mment.....Created.with.GIMPd.e..
0080 00 01 bf 49 44 41 54 48 c7 ed 95 4b 6e d5 50 10 44 4f f5 35 91 90 22 46 8c 18 b3 16 76 c1 52 d8 ...IDATH...Kn.P.DO.5.."F....v.R.
00a0 15 fb 60 23 8c 10 0a 51 92 d7 87 c1 b5 8d 79 79 09 42 08 46 f4 c0 ba 76 bb 3f ee aa 2e e7 dd fb ..`#...Q......yy.B.F...v.?......
00c0 0f fc 4d 2b fe b2 fd 2f f0 4b 5b 82 00 84 f5 70 76 5e ef 1f db 0c 74 73 fa d8 8f c0 f2 c2 d3 53 ..M+.../.K[....pv^....ts.......S
00e0 c5 b7 bc e6 52 76 c9 bc 1e b2 5f 28 b6 bc f4 8e 27 e2 6b 7d 53 a0 b6 5c 7b ef 5b ae 04 9b 02 67 ....Rv...._(....'.k}S..\{.[....g
0100 81 3e 14 06 96 6b 6f 8f 01 7b 6b 7b 3f d1 b3 a4 c7 a1 09 12 f3 e3 f1 d6 d4 3c 67 b9 f6 36 ee 43 .>...ko..{k{?............<g..6.C
0120 f0 80 be 4d 6a 9d cf 05 78 0e 35 82 fb ac e6 07 ad bd 75 b2 bc 7d 75 87 a2 b5 b9 01 31 07 68 c5 ...Mj...x.5.......u..}u.....1.h.
0140 3a f4 05 1d 32 cf 41 f1 c8 c6 3d b6 09 c9 f2 e6 f5 97 c4 ea 0e 9c a8 40 a5 d7 69 9a c0 a8 6e 13 :...2.A...=............@..i...n.
0160 3d 59 86 2a d3 06 3a 05 8c b4 42 62 27 90 6a 89 da d6 89 8c 72 f9 dc 37 57 e9 91 ae 98 14 64 8c =Y.*..:...Bb'.j.....r..7W.....d.
0180 a6 f7 3e 92 72 76 29 69 52 65 61 61 25 a9 74 3a ce 89 25 03 a4 9b fb 13 df ee c7 bd f5 f0 c0 f2 ..>.rv)iReaa%.t:..%.............
01a0 f1 d3 d5 18 71 07 c7 d4 86 d9 1c 56 95 31 0d 0d 9a 51 22 3d e1 35 05 60 9b 26 3b a1 dd 30 aa b8 ....q......V.1...Q"=.5.`.&;..0..
01c0 7c bd 19 a9 08 ae 34 0b 0a 34 64 63 45 26 55 a6 83 04 fa c0 d7 6c e0 07 03 23 1e 28 90 e5 64 79 |.....4..4dcE&U......l...#.(..dy
01e0 42 5c e1 cf 3a 9c de 17 29 b4 2b 68 9e 2f 76 b6 15 71 44 65 84 d6 c0 69 e5 43 96 1b c6 91 c0 51 B\..:...).+h./v..qDe...i.C.....Q
0200 49 b4 49 4d f2 49 af ac 38 d7 81 79 9d 3b 36 e6 ba a8 2c c7 0d 5f 6e 1d cf 48 d5 81 b8 79 5e d4 I.IM.I..8..y.;6...,.._n..H...y^.
0220 8e bb f9 93 54 3c 50 67 9b 99 4b 9a e4 2f b2 5f 90 44 ff 91 5c 3f d6 3f 7f 3f 8b ff 7f 99 7f 60 ....T<Pg..K../._.D..\?.?.?.....`
0240 df 01 61 9a 0b 0c 74 64 28 8f 00 00 00 00 49 45 4e 44 ae 42 60 82 ..a...td(.....IEND.B`.
f='#n116'>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 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
-- Route programming system

--[[
Progamming routes:
1. Select "program new route" in the signalling dialog
-> route_start marker will appear to designate route-program mode
2. Do those actions in any order:
A. punch a TCB marker node to proceed route along this TCB. This will only work if
	this is actually a TCB bordering the current TS, and will place a
	route_set marker and shift to the next TS
B. right-click a turnout to switch it (no impact to route programming
C. punch a turnout (or some other passive component) to fix its state (toggle)
	for the route. A sprite telling "Route Fix" will show that fact.
3. To complete route setting, use the chat command '/at_program_route <route name>'.
	The last punched TCB will get a 'route end' marker
	The end of a route should be at another signal facing the same direction as the entrance signal,
	however this is not enforced and left up to the signal engineer (the programmer)
	
The route visualization will also be used to visualize routes after they have been programmed.
]]--


-- table with objectRefs
local markerent = {}

minetest.register_entity("advtrains_interlocking:routemarker", {
	visual = "mesh",
	mesh = "trackplane.b3d",
	textures = {"at_il_route_set.png"},
	collisionbox = {-1,-0.5,-1, 1,-0.4,1},
	visual_size = {x=10, y=10},
	on_punch = function(self)
		self.object:remove()
	end,
	get_staticdata = function() return "STATIC" end,
	on_activate = function(self, sdata) if sdata=="STATIC" then self.object:remove() end end,
	static_save = false,
})


-- Spawn or update a route marker entity
-- pos: position where this is going to be
-- key: something unique to determine which entity to remove if this was set before
-- img: texture
local function routemarker(context, pos, key, img, yaw, itex)
	if not markerent[context] then
		markerent[context] = {}
	end
	if markerent[context][key] then
		markerent[context][key]:remove()
	end
	
	local obj = minetest.add_entity(vector.add(pos, {x=0, y=0.3, z=0}), "advtrains_interlocking:routemarker")
	if not obj then return end
	obj:set_yaw(yaw)
	obj:set_properties({
		infotext = itex,
		textures = {img},
	})
	
	markerent[context][key] = obj
end

minetest.register_entity("advtrains_interlocking:routesprite", {
	visual = "sprite",
	textures = {"at_il_turnout_free.png"},
	collisionbox = {-0.2,-0.2,-0.2, 0.2,0.2,0.2},
	visual_size = {x=1, y=1},
	on_punch = function(self)
		if self.callback then
			self.callback()
		end
		self.object:remove()
	end,
	get_staticdata = function() return "STATIC" end,
	on_activate = function(self, sdata) if sdata=="STATIC" then self.object:remove() end end,
	static_save = false,
})


-- Spawn or update a route sprite entity
-- pos: position where this is going to be
-- key: something unique to determine which entity to remove if this was set before
-- img: texture
local function routesprite(context, pos, key, img, itex, callback)
	if not markerent[context] then
		markerent[context] = {}
	end
	if markerent[context][key] then
		markerent[context][key]:remove()
	end
	
	local obj = minetest.add_entity(vector.add(pos, {x=0, y=0, z=0}), "advtrains_interlocking:routesprite")
	if not obj then return end
	obj:set_properties({
		infotext = itex,
		textures = {img},
	})
	
	if callback then
		obj:get_luaentity().callback = callback
	end
	
	markerent[context][key] = obj
end

--[[
Route definition:
route = {
	name = <string>
	[n] = {
		next = <sigd>, -- of the next (note: next) TCB on the route
		locks = {<pts> = "state"} -- route locks of this route segment
	}
	terminal = 
}
The first item in the TCB path (namely i=0) is always the start signal of this route,
so this is left out.
All subsequent entries, starting from 1, contain:
- all route locks of the segment on TS between the (i-1). and the i. TCB
- the next TCB signal describer in proceeding direction of the route.
'Terminal' once again repeats the "next" entry of the last route segment.
It is needed for distant signal aspect determination. If it is not set,
the distant signal aspect is determined as DANGER.
]]--

local function chat(pname, message)
	minetest.chat_send_player(pname, "[Route programming] "..message)
end
local function clear_lock(locks, pname, pts)
	locks[pts] = nil
	chat(pname, pts.." is no longer affected when this route is set.")
end

local function otherside(s)
	if s==1 then return 2 else return 1 end
end

function advtrains.interlocking.clear_visu_context(context)
	if not markerent[context] then return end
	for key, obj in pairs(markerent[context]) do
		obj:remove()
	end
	markerent[context] = nil
end

-- visualize route. 'context' is a string that identifies the context of this visualization
-- e.g. prog_<player> or vis_<pts> for later visualizations
-- last 2 parameters are only to be used in the context of route programming!
function advtrains.interlocking.visualize_route(origin, route, context, tmp_lcks, pname)
	advtrains.interlocking.clear_visu_context(context)
	
	local oyaw = 0
	local onode_ok, oconns, orhe = advtrains.get_rail_info_at(origin.p, advtrains.all_tracktypes)
	if onode_ok then
		oyaw = advtrains.dir_to_angle(oconns[origin.s].c)
	end
	routemarker(context, origin.p, "rte_origin", "at_il_route_start.png", oyaw, route.name)
	
	local c_sigd = origin
	for k,v in ipairs(route) do
		c_sigd = v.next
		-- display route path
		-- Final "next" marker can be EOI, thus undefined. This is legitimate.
		if c_sigd then
			local yaw = 0
			local node_ok, conns, rhe = advtrains.get_rail_info_at(c_sigd.p, advtrains.all_tracktypes)
			if node_ok then
				yaw = advtrains.dir_to_angle(conns[c_sigd.s].c)
			end
			local img = "at_il_route_set.png"
			if k==#route and not tmp_lcks then
				img = "at_il_route_end.png"
			end
			routemarker(context, c_sigd.p, "rte"..k, img, yaw, route.name.." #"..k)
		end
		-- display locks
		for pts, state in pairs(v.locks) do
			local pos = minetest.string_to_pos(pts)
			routesprite(context, pos, "fix"..k..pts, "at_il_route_lock.png", "Fixed in state '"..state.."' by route "..route.name.." until segment #"..k.." is freed.")
		end
	end
	
	-- The presence of tmp_lcks tells us that we are displaying during route programming.
	if tmp_lcks then
		-- display route end markers at appropriate places (check next TS, if it exists)
		local terminal = c_sigd
		if terminal then
			local term_tcbs = advtrains.interlocking.db.get_tcbs(terminal)
			if term_tcbs.ts_id then
				local over_ts = advtrains.interlocking.db.get_ts(term_tcbs.ts_id)
				for i, sigd in ipairs(over_ts.tc_breaks) do
					if not vector.equals(sigd.p, terminal.p) then
						local yaw = 0
						local node_ok, conns, rhe = advtrains.get_rail_info_at(sigd.p, advtrains.all_tracktypes)
						if node_ok then
							yaw = advtrains.dir_to_angle(conns[otherside(sigd.s)].c)
						end
						routemarker(context, sigd.p, "rteterm"..i, "at_il_route_end.png", yaw, route.name.." Terminal "..i)
					end
				end
			end
		end
	-- display locks set by player		
		for pts, state in pairs(tmp_lcks) do
			local pos = minetest.string_to_pos(pts)
			routesprite(context, pos, "fixp"..pts, "at_il_route_lock_edit.png", "Fixed in state '"..state.."' by route "..route.name.." (punch to unfix)",
				function() clear_lock(tmp_lcks, pname, pts) end)
		end
	end
end


local player_rte_prog = {}

function advtrains.interlocking.init_route_prog(pname, sigd)
	if not minetest.check_player_privs(pname, "interlocking") then
		minetest.chat_send_player(pname, "Insufficient privileges to use this!")
		return
	end
	player_rte_prog[pname] = {
		origin = sigd,
		route = {
			name = "PROG["..pname.."]",
		},
		tmp_lcks = {},
	}
	advtrains.interlocking.visualize_route(sigd, player_rte_prog[pname].route, "prog_"..pname, player_rte_prog[pname].tmp_lcks, pname)
	minetest.chat_send_player(pname, "Route programming mode active. Punch TCBs to add route segments, punch turnouts to lock them.")
end

local function get_last_route_item(origin, route)
	if #route == 0 then
		return origin
	end
	return route[#route].next
end

local function do_advance_route(pname, rp, sigd, tsname)
	table.insert(rp.route, {next = sigd, locks = rp.tmp_lcks})
	rp.tmp_lcks = {}
	chat(pname, "Added track section '"..tsname.."' to the route.")
end

local function finishrpform(pname)
	local rp = player_rte_prog[pname]
	if not rp then return end
	
	local form = "size[7,6]label[0.5,0.5;Finish programming route]"
	local terminal = get_last_route_item(rp.origin, rp.route)
	if terminal then
		local term_tcbs = advtrains.interlocking.db.get_tcbs(terminal)
		
		if term_tcbs.signal then
			form = form .. "label[0.5,1.5;Route ends at signal:]"
			form = form .. "label[0.5,2  ;"..term_tcbs.signal_name.."]"
		else
			form = form .. "label[0.5,1.5;WARNING: Route does not end at a signal.]"
			form = form .. "label[0.5,2  ;Routes should in most cases end at signals.]"
			form = form .. "label[0.5,2.5;Cancel if you are unsure!]"
		end
	else
		form = form .. "label[0.5,1.5;Route leads into]"
		form = form .. "label[0.5,2  ;non-interlocked area]"
	end
	form = form.."field[0.8,3.5;5.2,1;name;Enter Route Name;]"
	form = form.."button_exit[0.5,4.5;  5,1;save;Save Route]"
	
	
	minetest.show_formspec(pname, "at_il_routepf", form)
end


local function check_advance_valid(tcbpos, rp)
	-- track circuit break, try to advance route over it
	local lri = get_last_route_item(rp.origin, rp.route)
	if not lri then
		return false, false
	end
	
	local is_endpoint = false
	
	local this_sigd, this_ts, adv_side
	
	if vector.equals(lri.p, tcbpos) then
		-- If the player just punched the last TCB again, it's of course possible to
		-- finish the route here (although it can't be advanced by here.
		-- Fun fact: you can now program routes that end exactly where they begin :)
		is_endpoint = true
		this_sigd = lri
	else
		-- else, we need to check whether this TS actually borders
		local start_tcbs = advtrains.interlocking.db.get_tcbs(lri)
		if not start_tcbs.ts_id then
			return false, false
		end
		
		this_ts = advtrains.interlocking.db.get_ts(start_tcbs.ts_id)
		for _,sigd in ipairs(this_ts.tc_breaks) do
			if vector.equals(sigd.p, tcbpos) then
				adv_side = otherside(sigd.s)
			end
		end
		if not adv_side then
			-- this TCB is not bordering to the section
			return false, false
		end
		this_sigd = {p=tcbpos, s=adv_side}
	end
	
	-- check whether the ts at the other end is capable of "end over"
	local adv_tcbs = advtrains.interlocking.db.get_tcbs(this_sigd)
	local next_tsid = adv_tcbs.ts_id
	local can_over, over_ts, next_tc_bs = false, nil, nil
	local cannotover_rsn = "Next section is diverging (>2 TCBs)"
	if next_tsid then
		-- you may not advance over EOI. While this is technically possible,
		-- in practise this just enters an unnecessary extra empty route item.
		over_ts = advtrains.interlocking.db.get_ts(adv_tcbs.ts_id)
		next_tc_bs = over_ts.tc_breaks
		can_over = #next_tc_bs <= 2
	else
		cannotover_rsn = "End of interlocking"
	end
	
	local over_sigd = nil
	if can_over then
		if next_tc_bs and #next_tc_bs == 2 then
			local sdt
			if vector.equals(next_tc_bs[1].p, tcbpos) then
				sdt = next_tc_bs[2]
			end
			if vector.equals(next_tc_bs[2].p, tcbpos) then
				sdt = next_tc_bs[1]
			end
			if not sdt then
				error("Inconsistency: "..dump(next_ts))
			end
			-- swap TCB direction
			over_sigd = {p = sdt.p, s = otherside(sdt.s) }
		end
	end
	
	return is_endpoint, true, this_sigd, this_ts, can_over, over_ts, over_sigd, cannotover_rsn
end

local function show_routing_form(pname, tcbpos, message)

	local rp = player_rte_prog[pname]
	
	if not rp then return end
	
	local is_endpoint, advance_valid, this_sigd, this_ts, can_over, over_ts, over_sigd, cannotover_rsn = check_advance_valid(tcbpos, rp)
	
	-- at this place, advance_valid shows whether the current route can be advanced
	-- over this TCB.
	-- If it can: 
	--  Advance over (continue programming)
	--  End here
	--  Advance and end (only <=2 TCBs, terminal signal needs to be known)
	-- if not:
	--  show nothing at all
	-- In all cases, Discard and Backtrack buttons needed.
	
	local form = "size[7,9.5]label[0.5,0.5;Advance/Complete Route]"
	if message then
		form = form .. "label[0.5,1;"..message.."]"
	end
	
	if advance_valid and not is_endpoint then
		form = form.. "label[0.5,1.8;Advance to next route section]"
		form = form.."image_button[0.5,2.2;  5,1;at_il_routep_advance.png;advance;]"
		
		form = form.. "label[0.5,3.5;-------------------------]"
	else
		form = form.. "label[0.5,2.3;This TCB is not suitable as]"
		form = form.. "label[0.5,2.8;route continuation.]"
	end
	if advance_valid or is_endpoint then
		form = form.. "label[0.5,3.8;Finish route HERE]"
		form = form.."image_button[0.5,  4.2;  5,1;at_il_routep_end_here.png;endhere;]"
		if can_over then
			form = form.. "label[0.5,5.3;Finish route at end of NEXT section]"
			form = form.."image_button[0.5,5.7;  5,1;at_il_routep_end_over.png;endover;]"
		else
			form = form.. "label[0.5,5.3;Advancing over next section is]"
			form = form.. "label[0.5,5.8;impossible at this place.]"
			if cannotover_rsn then
				form = form.. "label[0.5,6.3;"..cannotover_rsn.."]"
			end
		end
	end
	
	form = form.. "label[0.5,7;-------------------------]"
	if #rp.route > 0 then
		form = form.."button[0.5,7.4;  5,1;retract;Step back one section]"
	end
	form = form.."button[0.5,8.4;  5,1;cancel;Cancel route programming]"
	
	minetest.show_formspec(pname, "at_il_rprog_"..minetest.pos_to_string(tcbpos), form)
end

minetest.register_on_player_receive_fields(function(player, formname, fields)
	local pname = player:get_player_name()
	
	local tcbpts = string.match(formname, "^at_il_rprog_([^_]+)$")
	local tcbpos
	if tcbpts then
		tcbpos = minetest.string_to_pos(tcbpts)
	end
	if tcbpos then
		-- RPROG form
		local rp = player_rte_prog[pname]
		if not rp then
			minetest.close_formspec(pname, formname)
			return
		end
		
		local is_endpoint, advance_valid, this_sigd, this_ts, can_over, over_ts, over_sigd = check_advance_valid(tcbpos, rp)
		
		if advance_valid then
			if fields.advance then
				-- advance route
				if not is_endpoint then
					do_advance_route(pname, rp, this_sigd, this_ts.name)
				end
			end
			if fields.endhere then
				if not is_endpoint then