Workaround to handle split points (dt. aufgefahrene Weichen), fixing H#77
parent
d61c2145a0
commit
b13c725976
|
@ -291,8 +291,9 @@ function advtrains.conn_matches_to(conn, other_conns)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Going from the rail at pos (does not need to be rounded) along connection with id conn_idx, if there is a matching rail, return it and the matching connid
|
||||||
-- returns: <adjacent pos>, <conn index of adjacent>, <my conn index>, <railheight of adjacent>
|
-- returns: <adjacent pos>, <conn index of adjacent>, <my conn index>, <railheight of adjacent>
|
||||||
|
-- parameter this_conns_p is connection table of this rail and is optional, is determined by get_rail_info_at if not provided.
|
||||||
function advtrains.get_adjacent_rail(this_posnr, this_conns_p, conn_idx, drives_on)
|
function advtrains.get_adjacent_rail(this_posnr, this_conns_p, conn_idx, drives_on)
|
||||||
local this_pos = advtrains.round_vector_floor_y(this_posnr)
|
local this_pos = advtrains.round_vector_floor_y(this_posnr)
|
||||||
local this_conns = this_conns_p
|
local this_conns = this_conns_p
|
||||||
|
@ -332,6 +333,9 @@ function advtrains.get_adjacent_rail(this_posnr, this_conns_p, conn_idx, drives_
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- when a train enters a rail on connid 'conn', which connid will it go out?
|
||||||
|
-- nconns: number of connections in connection table
|
||||||
|
-- returns: connid_out
|
||||||
local connlku={[2]={2,1}, [3]={2,1,1}, [4]={2,1,4,3}}
|
local connlku={[2]={2,1}, [3]={2,1,1}, [4]={2,1,4,3}}
|
||||||
function advtrains.get_matching_conn(conn, nconns)
|
function advtrains.get_matching_conn(conn, nconns)
|
||||||
return connlku[nconns][conn]
|
return connlku[nconns][conn]
|
||||||
|
|
|
@ -392,7 +392,7 @@ advtrains.avt_save = function(remove_players_from_wagons)
|
||||||
"trainparts", "recently_collided_with_env",
|
"trainparts", "recently_collided_with_env",
|
||||||
"atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open",
|
"atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open",
|
||||||
"text_outside", "text_inside", "line", "routingcode",
|
"text_outside", "text_inside", "line", "routingcode",
|
||||||
"il_sections", "speed_restriction", "is_shunt",
|
"il_sections", "speed_restriction", "is_shunt", "points_split",
|
||||||
})
|
})
|
||||||
--then save it
|
--then save it
|
||||||
tmp_trains[id]=v
|
tmp_trains[id]=v
|
||||||
|
|
|
@ -178,9 +178,15 @@ function advtrains.path_get(train, index)
|
||||||
if adj_pos then
|
if adj_pos then
|
||||||
advtrains.occ.set_item(train.id, adj_pos, pef)
|
advtrains.occ.set_item(train.id, adj_pos, pef)
|
||||||
|
|
||||||
|
-- If we have split points, notify accordingly
|
||||||
|
local mconnid = advtrains.get_matching_conn(adj_connid, #next_conns)
|
||||||
|
if #next_conns==3 and adj_connid==1 and train.points_split and train.points_split[advtrains.encode_pos(adj_pos)] then
|
||||||
|
--atdebug(id,"has split points restored at",adj_pos)
|
||||||
|
mconnid = 3
|
||||||
|
end
|
||||||
|
|
||||||
adj_pos.y = adj_pos.y + nextrail_y
|
adj_pos.y = adj_pos.y + nextrail_y
|
||||||
train.path_cp[pef] = adj_connid
|
train.path_cp[pef] = adj_connid
|
||||||
local mconnid = advtrains.get_matching_conn(adj_connid, #next_conns)
|
|
||||||
train.path_cn[pef] = mconnid
|
train.path_cn[pef] = mconnid
|
||||||
train.path_dir[pef] = advtrains.conn_angle_median(next_conns[adj_connid].c, next_conns[mconnid].c)
|
train.path_dir[pef] = advtrains.conn_angle_median(next_conns[adj_connid].c, next_conns[mconnid].c)
|
||||||
train.path_trk_f = pef
|
train.path_trk_f = pef
|
||||||
|
@ -211,9 +217,15 @@ function advtrains.path_get(train, index)
|
||||||
if adj_pos then
|
if adj_pos then
|
||||||
advtrains.occ.set_item(train.id, adj_pos, peb)
|
advtrains.occ.set_item(train.id, adj_pos, peb)
|
||||||
|
|
||||||
|
-- If we have split points, notify accordingly
|
||||||
|
local mconnid = advtrains.get_matching_conn(adj_connid, #next_conns)
|
||||||
|
if #next_conns==3 and adj_connid==1 and train.points_split and train.points_split[advtrains.encode_pos(adj_pos)] then
|
||||||
|
atdebug(id,"has split points restored at",adj_pos)
|
||||||
|
mconnid = 3
|
||||||
|
end
|
||||||
|
|
||||||
adj_pos.y = adj_pos.y + nextrail_y
|
adj_pos.y = adj_pos.y + nextrail_y
|
||||||
train.path_cn[peb] = adj_connid
|
train.path_cn[peb] = adj_connid
|
||||||
local mconnid = advtrains.get_matching_conn(adj_connid, #next_conns)
|
|
||||||
train.path_cp[peb] = mconnid
|
train.path_cp[peb] = mconnid
|
||||||
train.path_dir[peb] = advtrains.conn_angle_median(next_conns[mconnid].c, next_conns[adj_connid].c)
|
train.path_dir[peb] = advtrains.conn_angle_median(next_conns[mconnid].c, next_conns[adj_connid].c)
|
||||||
train.path_trk_b = peb
|
train.path_trk_b = peb
|
||||||
|
|
|
@ -627,6 +627,16 @@ local function tnc_call_enter_callback(pos, train_id, train, index)
|
||||||
|
|
||||||
-- call other registered callbacks
|
-- call other registered callbacks
|
||||||
run_callbacks_enter_node(pos, train_id, train, index)
|
run_callbacks_enter_node(pos, train_id, train, index)
|
||||||
|
|
||||||
|
-- check for split points
|
||||||
|
if mregnode and mregnode.at_conns and #mregnode.at_conns == 3 and train.path_cp[index] == 3 then
|
||||||
|
-- train came from connection 3 of a switch, so it split points.
|
||||||
|
if not train.points_split then
|
||||||
|
train.points_split = {}
|
||||||
|
end
|
||||||
|
train.points_split[advtrains.encode_pos(pos)] = true
|
||||||
|
--atdebug(train_id,"split points at",pos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local function tnc_call_leave_callback(pos, train_id, train, index)
|
local function tnc_call_leave_callback(pos, train_id, train, index)
|
||||||
--atdebug("tnc leave",pos,train_id)
|
--atdebug("tnc leave",pos,train_id)
|
||||||
|
@ -638,6 +648,20 @@ local function tnc_call_leave_callback(pos, train_id, train, index)
|
||||||
|
|
||||||
-- call other registered callbacks
|
-- call other registered callbacks
|
||||||
run_callbacks_leave_node(pos, train_id, train, index)
|
run_callbacks_leave_node(pos, train_id, train, index)
|
||||||
|
|
||||||
|
-- split points do not matter anymore. clear them
|
||||||
|
if train.points_split then
|
||||||
|
if train.points_split[advtrains.encode_pos(pos)] then
|
||||||
|
train.points_split[advtrains.encode_pos(pos)] = nil
|
||||||
|
--atdebug(train_id,"has passed split points at",pos)
|
||||||
|
end
|
||||||
|
-- any entries left?
|
||||||
|
for _,_ in pairs(train.points_split) do
|
||||||
|
return
|
||||||
|
end
|
||||||
|
train.points_split = nil
|
||||||
|
end
|
||||||
|
-- WARNING possibly unreachable place!
|
||||||
end
|
end
|
||||||
|
|
||||||
function advtrains.tnc_call_approach_callback(pos, train_id, train, index, lzbdata)
|
function advtrains.tnc_call_approach_callback(pos, train_id, train, index, lzbdata)
|
||||||
|
|
Loading…
Reference in New Issue