aboutsummaryrefslogtreecommitdiff
path: root/advtrains_train_track/textures/advtrains_dtrack_xing4590_placer.png
blob: 7c5633bb4fbcbdf197ca4ece493a4aadcde073c3 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 38 00 00 00 38 04 03 00 00 00 5a a8 26 .PNG........IHDR...8...8.....Z.&
0020 2d 00 00 00 1b 50 4c 54 45 3e 47 c6 4c 07 01 39 16 05 50 21 01 66 4a 42 81 78 75 9a 94 92 b0 ac -....PLTE>G.L..9..P!.fJB.xu.....
0040 aa c8 c9 c6 4d aa af be 00 00 00 01 74 52 4e 53 00 40 e6 d8 66 00 00 00 09 70 48 59 73 00 00 0b ....M.......tRNS.@..f....pHYs...
0060 13 00 00 0b 13 01 00 9a 9c 18 00 00 01 52 49 44 41 54 38 cb ed d4 b1 4e c3 30 10 06 e0 50 07 b5 .............RIDAT8....N.0...P..
0080 63 95 28 e0 11 9c 16 18 9b 18 1e a1 85 b1 20 4c 67 50 91 18 a9 d4 c1 63 0c 55 ef 1e 9b 3b 17 d1 c.(............LgP.....c.U...;..
00a0 38 a1 88 81 81 a1 1e 92 c8 9f 7e c7 b9 b3 12 45 fb b1 1f 7f 36 30 b8 fd 16 79 06 fb fc 14 43 0b 8.........~....E....60...y....C.
00c0 af f1 07 2c 48 ed eb 0e 14 c5 4d 35 c1 1d 18 09 e9 c0 60 0b 6d e5 6f 5d 87 f0 80 4d cc 36 da 7b ...,H.....M5......`.m.o]...M.6.{
00e0 b3 33 ce c6 d0 ab b6 a8 37 da 75 36 99 51 56 80 ac a1 57 a1 8f 09 53 ce 82 74 7a 14 e8 4a 49 87 .3......7.u6.QV...W...S..tz..JI.
0100 c9 a9 a6 2c c8 45 3e 0a b3 4b 4e 96 ba 98 a1 91 2e a9 23 ab 75 98 e6 5a 53 36 c3 a7 00 a3 d2 58 ...,.E>..KN.......#.u..ZS6.....X
0120 4a 2a a5 0a 0d d2 e0 34 c0 43 34 0b 54 14 d4 97 20 c1 84 78 30 c4 bb 97 39 25 55 0e 72 0d d3 46 J*.....4.C4.T......x0...9%U.r..F
0140 6d a5 33 76 55 fa e4 e2 3c ec a9 c8 69 b7 cf 76 99 97 1a a5 2b 26 81 76 d4 85 43 24 55 03 fe ce m.3vU...<...i..v....+&.v..C$U...
0160 50 7d 85 86 ac 29 c8 77 ad 03 ed 70 85 d2 8c 95 92 ea 44 70 f7 b7 c9 ab 47 9b 6a 52 44 5f 5b 51 P}...).w...p......Dp....G.jRD_[Q
0180 cb 76 d4 e0 16 13 c5 ea 93 bc ff 71 70 02 fb 34 93 e1 fc b3 65 e2 ac 81 b4 fc 11 d5 b6 6a 1f 23 .v.........qp..4....e........j.#
01a0 db f7 2f a7 7d d9 b6 7e 9d 5b ea d1 6e 24 fd 7e d9 28 5e d3 65 d4 c2 b1 9f 12 f7 ff f8 47 f0 01 ../.}..~.[..n$.~.(^.e........G..
01c0 d8 76 70 34 8f 70 70 d0 00 00 00 00 49 45 4e 44 ae 42 60 82 .vp4.pp.....IEND.B`.
23'>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
-- Setting and clearing routes

-- TODO duplicate
local lntrans = { "A", "B" }
local function sigd_to_string(sigd)
	return minetest.pos_to_string(sigd.p).." / "..lntrans[sigd.s]
end

local asp_generic_free = {
	main = {
		free = true,
		speed = -1,
	},
	shunt = {
		free = false,
	},
	dst = {
		free = true,
		speed = -1,
	},
	info = {}
}

local ildb = advtrains.interlocking.db
local ilrs = {}

local sigd_equal = advtrains.interlocking.sigd_equal

-- table containing locked points
-- also manual locks (maintenance a.s.o.) are recorded here
-- [pts] = { 
--		[n] = { [by = <ts_id>], rsn = <human-readable text>, [origin = <sigd>] }
--	}
ilrs.rte_locks = {}
ilrs.rte_callbacks = {
	ts = {},
	lck = {}
}


-- main route setting. First checks if everything can be set as designated,
-- then (if "try" is not set) actually sets it
-- returns:
-- true - route can be/was successfully set
-- false, message, cbts, cblk - something went wrong, what is contained in the message.
-- cbts: the ts id of the conflicting ts, cblk: the pts of the conflicting component
function ilrs.set_route(signal, route, try)
	if not try then
		local tsuc, trsn, cbts, cblk = ilrs.set_route(signal, route, true)
		if not tsuc then
			return false, trsn, cbts, cblk
		end
	end

	
	-- we start at the tc designated by signal
	local c_sigd = signal
	local first = true
	local i = 1
	local rtename = route.name
	local signalname = ildb.get_tcbs(signal).signal_name
	local c_tcbs, c_ts_id, c_ts, c_rseg, c_lckp
	while c_sigd and i<=#route do
		c_tcbs = ildb.get_tcbs(c_sigd)
		if not c_tcbs then
			if not try then atwarn("Did not find TCBS",c_sigd,"while setting route",rtename,"of",signal) end
			return false, "No TCB found at "..sigd_to_string(c_sigd)..". Please reconfigure route!"
		end
		c_ts_id = c_tcbs.ts_id
		if not c_ts_id then
			if not try then atwarn("Encountered End-Of-Interlocking while setting route",rtename,"of",signal) end
			return false, "No track section adjacent to "..sigd_to_string(c_sigd)..". Please reconfigure route!"
		end
		c_ts = ildb.get_ts(c_ts_id)
		c_rseg = route[i]
		c_lckp = {}
		
		if c_ts.route then
			if not try then atwarn("Encountered ts lock during a real run of routesetting routine, at ts=",c_ts_id,"while setting route",rtename,"of",signal) end
			return false, "Section '"..c_ts.name.."' already has route set from "..sigd_to_string(c_ts.route.origin)..":\n"..c_ts.route.rsn, c_ts_id, nil
		end
		if c_ts.trains and #c_ts.trains>0 then
			if not try then atwarn("Encountered ts occupied during a real run of routesetting routine, at ts=",c_ts_id,"while setting route",rtename,"of",signal) end
			return false, "Section '"..c_ts.name.."' is occupied!", c_ts_id, nil
		end
		
		for pts, state in pairs(c_rseg.locks) do
			local confl = ilrs.has_route_lock(pts, state)
			
			local pos = minetest.string_to_pos(pts)
			if advtrains.is_passive(pos) then
				local cstate = advtrains.getstate(pos)
				if cstate ~= state then
					local confl = ilrs.has_route_lock(pts)
					if confl then
						if not try then atwarn("Encountered route lock while a real run of routesetting routine, at position",pts,"while setting route",rtename,"of",signal) end
						return false, "Lock conflict at "..pts..", Held locked by:\n"..confl, nil, pts
					elseif not try then
						advtrains.setstate(pos, state)
					end
				end
				if not try then
					ilrs.add_route_lock(pts, c_ts_id, "Route '"..rtename.."' from signal '"..signalname.."'", signal)
					c_lckp[#c_lckp+1] = pts
				end
			else
				if not try then atwarn("Encountered route lock misconfiguration (no passive component) while a real run of routesetting routine, at position",pts,"while setting route",rtename,"of",signal) end
				return false, "No passive component at "..pts..". Please reconfigure route!"
			end
		end
		-- reserve ts and write locks
		if not try then
			local nvar = c_rseg.next
			if not route[i+1] then
				-- We shouldn't use the "next" value of the final route segment, because this can lead to accidental route-cancelling of already set routes from another signal.
				nvar = nil
			end
			c_ts.route = {
				origin = signal,
				entry = c_sigd,
				rsn = "Route '"..rtename.."' from signal '"..signalname.."', segment #"..i,
				first = first,
			}
			c_ts.route_post = {
				locks = c_lckp,
				next = nvar,
			}
			if c_tcbs.signal then
				c_tcbs.route_committed = true
				c_tcbs.aspect = route.aspect or asp_generic_free
				c_tcbs.route_origin = signal