aboutsummaryrefslogtreecommitdiff
path: root/advtrains_train_industrial/models
diff options
context:
space:
mode:
authorBlockhead <jbis1337@hotmail.com>2020-10-11 12:02:16 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-10-11 12:28:41 +0200
commit2ecd474ed74bcf63eb7e8081ce1caf4422fd9a56 (patch)
tree98c5c6c6c60ff4161a76ad27f84231958efc26ec /advtrains_train_industrial/models
parent3256c2778d626548541bcdfabf3026f781a2287c (diff)
downloadadvtrains-2ecd474ed74bcf63eb7e8081ce1caf4422fd9a56.tar.gz
advtrains-2ecd474ed74bcf63eb7e8081ce1caf4422fd9a56.tar.bz2
advtrains-2ecd474ed74bcf63eb7e8081ce1caf4422fd9a56.zip
Fix 3-way conns table so traverser doesn't complain
The remaining patch to make advtrains master stable: we can't have any conns entries without a 'c' member, so make all ["3"] entries into just ["c"] entries.
Diffstat (limited to 'advtrains_train_industrial/models')
0 files changed, 0 insertions, 0 deletions
26'>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
-- train_related.lua
-- Occupation of track sections - mainly implementation of train callbacks

--[[
Track section occupation is saved as follows

In train:
train.il_sections = {
	[n] = {ts_id = <...> (origin = <sigd>)}
}
-- "origin" is the TCB (signal describer) the train initially entered this section

In track section
ts.trains = {
	[n] = <train_id>
}

When any inconsistency is detected, we will assume the most restrictive setup.
It will be possible to indicate a section "free" via the GUI.
]]

local ildb = advtrains.interlocking.db

local sigd_equal = advtrains.interlocking.sigd_equal

local function itexist(tbl, com)
	for _,item in ipairs(tbl) do
		if (item==com) then
			return true
		end
	end
	return false
end
local function itkexist(tbl, ikey, com)
	for _,item in ipairs(tbl) do
		if item[ikey] == com then
			return true
		end
	end
	return false
end

local function itremove(tbl, com)
	local i=1
	while i <= #tbl do
		if tbl[i] == com then
			table.remove(tbl, i)
		else
			i = i + 1
		end
	end
end
local function itkremove(tbl, ikey, com)
	local i=1
	while i <= #tbl do
		if tbl[i][ikey] == com then
			table.remove(tbl, i)
		else
			i = i + 1
		end
	end
end

local function setsection(tid, train, ts_id, ts, sigd)
	-- train
	if not train.il_sections then train.il_sections = {} end
	if not itkexist(train.il_sections, "ts_id", ts_id) then
		table.insert(train.il_sections, {ts_id = ts_id, origin = sigd})
	end
	
	-- ts
	if not ts.trains then ts.trains = {} end
	if not itexist(ts.trains, tid) then
		table.insert(ts.trains, tid)
	end
	
	-- routes
	local tcbs
	if sigd then
		tcbs = advtrains.interlocking.db.get_tcbs(sigd)
	end
	
	-- route setting - clear route state
	if ts.route then
		--atdebug(tid,"enters",ts_id,"examining Routestate",ts.route)
		if not sigd_equal(ts.route.entry, sigd) then
			-- Train entered not from the route. Locate origin and cancel route!
			atwarn("Train",tid,"hit route",ts.route.rsn,"!")
			advtrains.interlocking.route.cancel_route_from(ts.route.origin)
			atwarn("Route was cancelled.")
		else
			-- train entered route regularily.
		end