diff --git a/mod/content/overtake_probe.script.tl b/mod/content/overtake_probe.script.tl index a2b02d0..9356a2a 100644 --- a/mod/content/overtake_probe.script.tl +++ b/mod/content/overtake_probe.script.tl @@ -25,32 +25,27 @@ local function turnaround(edge : EdgeId) : integer return tn.turnaroundEdges[edge.index + 1] end -local function modes(m : {TransportMode : boolean}) : string - local out : {string} = {} - for k, v in pairs(m or {}) do - if v then table.insert(out, tostring(k)) end - end - return table.concat(out, ",") +-- EXPERIMENT: does api.cmd.debug.makeComponentExchangeCmd accept a MovePath, and does a positive +-- dyn.timeToIgnore make the follower ignore the vehicle ahead? Hypothesis only; nothing documents either. +local IGNORE_SECONDS = 10.0 +local MAX_GAP = 40.0 + +local record Car + v : integer + pos : number + speed : number + dir : boolean + mp : Engine.Component.MovePath end --- per street segment: BaseEdge lane layout + TransportNetwork lanes (modes, speed, opposite lane) -local function segmentInfo(seg : integer) : string - local be = api.engine.getComponent(seg, api.type.ComponentType.BASE_EDGE) as Engine.Component.BaseEdge - local tn = api.engine.getComponent(seg, api.type.ComponentType.TRANSPORT_NETWORK) as Engine.Component.TransportNetwork - local parts : {string} = {} - if be ~= nil then - table.insert(parts, string.format("roadType=%s template=%s laneConfigs=%d", tostring(be.roadType), tostring(be.roadTemplate), #be.laneConfigs)) - for i, lc in ipairs(be.laneConfigs) do - table.insert(parts, string.format(" lc%d fwd=%s off=%.1f w=%.1f modes=[%s]", i, tostring(lc.forward), lc.offset, lc.width, modes(lc.transportModes))) - end - end - if tn ~= nil then - table.insert(parts, string.format("tnEdges=%d", #tn.edges)) - for i, e in ipairs(tn.edges) do - table.insert(parts, string.format(" tn%d modes=[%s] speedLimit=%.1f curSpeed=%.1f turnaround=%s", i - 1, modes(e.transportModes), e.speedLimit, e.curSpeed, tostring(tn.turnaroundEdges[i]))) - end - end - return table.concat(parts, "\n" .. TAG .. " ") +local function tryIgnore(follower : Car, leader : Car) + local mp = follower.mp + mp.dyn.timeToIgnore = IGNORE_SECONDS + p(string.format("IGNORE_TEST send veh=%d leader=%d gap=%.1f v=%.2f leaderV=%.2f", follower.v, leader.v, math.abs(leader.pos - follower.pos), follower.speed, leader.speed)) + local cmd = api.cmd.debug.makeComponentExchangeCmd(follower.v, mp as Engine.Component) + api.cmd.sendCommand(cmd, function(_data : any, success : boolean) + p(string.format("IGNORE_TEST result veh=%d success=%s", follower.v, tostring(success))) + end) end local function dump(dt : number) @@ -59,6 +54,7 @@ local function dump(dt : number) p(string.format("tick=%d dt=%s playerVehicles=%d", ticks, tostring(dt), #vehicles)) local bySegment : {integer : {string}} = {} + local byLane : {string : {Car}} = {} for _, v in ipairs(vehicles) do local lv = api.engine.getComponent(v, api.type.ComponentType.LAND_VEHICLE) as Engine.Component.LandVehicle local mp = api.engine.getComponent(v, api.type.ComponentType.MOVE_PATH) as Engine.Component.MovePath @@ -74,6 +70,11 @@ local function dump(dt : number) tostring(mp.occupiedBackIndex), tostring(mp.occupiedFrontIndex), lv.dyn.brakingTimer, tostring(info and info.availPower), tostring(info and info.traction)) p(line) + if edge ~= nil then + local key = seg .. ":" .. edge.index + byLane[key] = byLane[key] or {} + table.insert(byLane[key], { v = v, pos = mp.dyn.pathPos.pos, speed = mp.dyn.speed, dir = dir, mp = mp }) + end bySegment[seg] = bySegment[seg] or {} table.insert(bySegment[seg], string.format("%d(lane=%s,dir=%s,v=%.1f,blk=%s)", v, tostring(edge and edge.index), tostring(dir), mp.dyn.speed, tostring(mp.blocked))) end @@ -81,7 +82,18 @@ local function dump(dt : number) for seg, list in pairs(bySegment) do if #list > 1 then p(string.format("SHARED seg=%d: %s", seg, table.concat(list, " "))) - p(" SEGMENT " .. seg .. " " .. segmentInfo(seg)) + end + end + for _, cars in pairs(byLane) do + for i = 1, #cars do + for j = 1, #cars do + local a, b = cars[i], cars[j] + -- ponytail: assumes pos grows in driving direction when dir=true; the log shows whether that holds + local ahead = (a.dir and b.pos > a.pos) or (not a.dir and b.pos < a.pos) + if i ~= j and ahead and math.abs(b.pos - a.pos) < MAX_GAP then + tryIgnore(a, b) + end + end end end end