fix(prototype): count driving lanes from laneConfigs, require moving leader
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2a08067a6d
commit
69b94552c2
1 file changed
+8
-4
@@ -47,10 +47,13 @@ local function rebuildable(seg : integer) : boolean, string
|
|||||||
local be = api.engine.getComponent(seg, api.type.ComponentType.BASE_EDGE) as Engine.Component.BaseEdge
|
local be = api.engine.getComponent(seg, api.type.ComponentType.BASE_EDGE) as Engine.Component.BaseEdge
|
||||||
if be == nil then return false, "no BaseEdge" end
|
if be == nil then return false, "no BaseEdge" end
|
||||||
if #be.objects > 0 then return false, "has edge objects" end
|
if #be.objects > 0 then return false, "has edge objects" end
|
||||||
local tn = api.engine.getComponent(seg, api.type.ComponentType.TRANSPORT_NETWORK) as Engine.Component.TransportNetwork
|
-- count BaseEdge lanes, not TransportNetwork edges (town roads split each lane into several edges).
|
||||||
|
-- Sidewalks carry modes 0/1 only; driving lanes carry 2+ (observed: [2,3,4]).
|
||||||
local driving = 0
|
local driving = 0
|
||||||
for _, e in ipairs(tn.edges) do
|
for _, lc in ipairs(be.laneConfigs) do
|
||||||
if e.speedLimit > 0 then driving = driving + 1 end
|
for k, on in pairs(lc.transportModes) do
|
||||||
|
if on and (tonumber(tostring(k)) or 0) >= 2 then driving = driving + 1 break end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if driving ~= 2 then return false, "driving lanes=" .. driving end
|
if driving ~= 2 then return false, "driving lanes=" .. driving end
|
||||||
return true, string.format("template=%s length=%.1f", tostring(be.roadTemplate), be.distance)
|
return true, string.format("template=%s length=%.1f", tostring(be.roadTemplate), be.distance)
|
||||||
@@ -116,7 +119,8 @@ local function dump(dt : number, state : GameScriptState<ProbeState>)
|
|||||||
local a, b = cars[i], cars[j]
|
local a, b = cars[i], cars[j]
|
||||||
-- ponytail: assumes pos grows in driving direction when dir=true (held so far in the logs)
|
-- ponytail: assumes pos grows in driving direction when dir=true (held so far in the logs)
|
||||||
local ahead = (a.dir and b.pos > a.pos) or (not a.dir and b.pos < a.pos)
|
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
|
-- leader must be moving, otherwise it's a queue at a stop or junction, not a slow vehicle
|
||||||
|
if i ~= j and ahead and math.abs(b.pos - a.pos) < MAX_GAP and b.speed > 1.0 then
|
||||||
local seg = laneSeg[key]
|
local seg = laneSeg[key]
|
||||||
local ok, why = rebuildable(seg)
|
local ok, why = rebuildable(seg)
|
||||||
p(string.format("REBUILD_TEST candidate seg=%d follower=%d (pos=%.1f v=%.2f) leader=%d (pos=%.1f v=%.2f) ok=%s %s",
|
p(string.format("REBUILD_TEST candidate seg=%d follower=%d (pos=%.1f v=%.2f) leader=%d (pos=%.1f v=%.2f) ok=%s %s",
|
||||||
|
|||||||
Reference in new issue
Block a user