From f4f8c75e4994088a732fb7cd75a18dfb4e133940 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Thu, 22 Oct 2026 17:16:33 +0200 Subject: [PATCH] fix(ai): orders of road junctions and level crossings measured along the lane they lie on, so they aren't misplaced on short lanes --- vehicle/Driver.cpp | 9 ++++++++- world/RoadPoint.cpp | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 5bbaa80e..f37a591a 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -24,6 +24,7 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/DynObj.h" #include "world/Event.h" #include "world/MemCell.h" +#include "world/RoadOrder.h" #include "simulation/simulation.h" #include "simulation/simulationtime.h" #include "world/Track.h" @@ -602,7 +603,13 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) fCurrentDistance + ProjectEventOnTrack( pEvent, pTrack, fLastDir ), OrderCurrentGet() ) ) { */ - if (newspeedpoint.Set(pEvent, GetDistanceToEvent(pTrack, pEvent, fLastDir, fCurrentDistance), fLength, OrderCurrentGet())) + // an order of a road junction or a level crossing lies on the lane it's on. it's measured along that lane: the search + // for the events beside the track goes in steps of about a metre, and misplaces the ones on lanes shorter than a few metres + auto const eventdistance{ + typeid( *pEvent ) == typeid( road_order ) ? + fCurrentDistance + ProjectEventOnTrack( pEvent, pTrack, fLastDir ) : + GetDistanceToEvent( pTrack, pEvent, fLastDir, fCurrentDistance ) }; + if (newspeedpoint.Set(pEvent, eventdistance, fLength, OrderCurrentGet())) { fDistance = newspeedpoint.fDist; // jeśli sygnał stop, to nie ma potrzeby dalej skanować diff --git a/world/RoadPoint.cpp b/world/RoadPoint.cpp index 0c44d731..2a6347fa 100644 --- a/world/RoadPoint.cpp +++ b/world/RoadPoint.cpp @@ -947,6 +947,8 @@ void roadpoint_node::update_crossing(double const Deltatime) auto const closed{control > 0.0 || (control == 0.0 && m_hold > 0.0)}; if (closed != m_closed) { + WriteLog("Level crossing \"" + m_name + "\" " + (closed ? "closed" : "opened") + (control != 0.0 ? " by memory cell \"" + m_memcell->name() + "\"" : " by the trains") + ", stops: " + + std::to_string(m_stops.size())); close(closed); } }