From 407b18768808b825896544f42d0fa4f7fb2ee125 Mon Sep 17 00:00:00 2001 From: jakubg1 <24206305+jakubg1@users.noreply.github.com> Date: Sat, 4 Apr 2026 00:13:26 +0200 Subject: [PATCH] Tweak the door closing and warning signal delays - The warning signal is no longer going to be played for an obnoxiously long amount of time by AI drivers when driving vehicles with a manual warning signal switch, most notably EN57. - A new `moveDepartureWarned` driving flag has been created to accomodate this behavior. - Added the action time counter and the missing driving flags to the Vehicle AI section. --- application/driveruipanels.cpp | 12 +++-- vehicle/Driver.cpp | 91 +++++++++++++++++----------------- vehicle/Driver.h | 3 +- 3 files changed, 55 insertions(+), 51 deletions(-) diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 16465d50..05e20b84 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -1138,9 +1138,12 @@ debug_panel::update_section_ai( std::vector &Output ) { "Current order: [" + std::to_string( mechanik.OrderPos ) + "] " + mechanik.Order2Str( mechanik.OrderCurrentGet() ); - if( mechanik.fStopTime < 0.0 ) { - textline += "\n stop time: " + to_string( std::abs( mechanik.fStopTime ), 1 ); - } + if( mechanik.fStopTime < 0.0 ) { + textline += "\n stop time: " + to_string( std::abs( mechanik.fStopTime ), 1 ); + } + if( mechanik.fActionTime < 0.0 ) { + textline += "\n action time: " + to_string( std::abs( mechanik.fActionTime ), 1 ); + } Output.emplace_back( textline, Global.UITextColor ); @@ -1231,7 +1234,8 @@ debug_panel::update_section_ai( std::vector &Output ) { std::vector const drivingflagnames { "StopCloser", "StopPoint", "Active", "Press", "Connect", "Primary", "Late", "StopHere", "StartHorn", "StartHornNow", "StartHornDone", "Oerlikons", "IncSpeed", "TrackEnd", "SwitchFound", "GuardSignal", - "Visibility", "DoorOpened", "PushPull", "SignalFound", "StopPointFound" /*"SemaphorWasElapsed", "TrainInsideStation", "SpeedLimitFound"*/ }; + "Visibility", "DoorOpened", "PushPull", "SignalFound", "StopPointFound", "GuardOpenDoor", "DepartureWarned" + /*"SemaphorWasElapsed", "TrainInsideStation", "SpeedLimitFound"*/ }; textline = "Driving flags:"; for( int idx = 0, flagbit = 1; idx < drivingflagnames.size(); ++idx, flagbit <<= 1 ) { diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 33a7a43d..9a1f5d84 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -4359,62 +4359,61 @@ void TController::Doors( bool const Open, int const Side ) { if( ( false == doors_permit_active() ) && ( false == doors_open() ) ) { iDrivigFlags &= ~moveDoorOpened; + iDrivigFlags &= ~moveDepartureWarned; return; } + if (mvOccupied->Doors.has_warning && !TestFlag(iDrivigFlags, moveDepartureWarned)) + { + if (!mvOccupied->DepartureSignal) + { + // Not warned yet, not warning yet - start the warning signal. + cue_action( driver_hint::departuresignalon ); // załącenie bzyczka + fActionTime = Random( -0.3, -0.8 ); // 0.3-0.8 second buzzer + return; + } + // Not warned yet, warning now - stop the warning signal and mark it as done. + cue_action( driver_hint::departuresignaloff ); + fActionTime = Random( 0.0, -0.2 ); // Wait just a bit more before departing + iDrivigFlags |= moveDepartureWarned; + return; + } + if( true == doors_open() ) { - if( ( true == mvOccupied->Doors.has_warning ) - && ( false == mvOccupied->DepartureSignal ) - && ( true == TestFlag( iDrivigFlags, moveDoorOpened ) ) ) { - cue_action( driver_hint::departuresignalon ); // załącenie bzyczka - fActionTime = -1.5 - 0.1 * Random( 10 ); // 1.5-2.5 second wait + // consist-wide remote signals to close doors + if( ( pVehicle->MoverParameters->Doors.close_control == control_t::conductor ) + || ( pVehicle->MoverParameters->Doors.close_control == control_t::driver ) + || ( pVehicle->MoverParameters->Doors.close_control == control_t::mixed ) ) { + cue_action( driver_hint::doorrightclose ); + cue_action( driver_hint::doorleftclose ); } } + if( true == doors_permit_active() ) { + cue_action( driver_hint::doorrightpermitoff ); + cue_action( driver_hint::doorleftpermitoff ); + } + // if applicable close manually-operated doors in vehicles which may ignore remote signals + { + const auto *vehicle = pVehicles[ end::front ]; // pojazd na czole składu + while( vehicle != nullptr ) { + // zamykanie drzwi w pojazdach - flaga zezwolenia była by lepsza + auto const ismanualdoor { + ( vehicle->MoverParameters->Doors.auto_velocity == -1.f ) + && ( ( vehicle->MoverParameters->Doors.close_control == control_t::passenger ) + || ( vehicle->MoverParameters->Doors.close_control == control_t::mixed ) ) }; - if( ( false == AIControllFlag ) || ( fActionTime > -0.5 ) ) { - // ai doesn't close the door until it's free to depart, but human driver has free reign to do stupid things - if( true == doors_open() ) { - // consist-wide remote signals to close doors - if( ( pVehicle->MoverParameters->Doors.close_control == control_t::conductor ) - || ( pVehicle->MoverParameters->Doors.close_control == control_t::driver ) - || ( pVehicle->MoverParameters->Doors.close_control == control_t::mixed ) ) { - cue_action( driver_hint::doorrightclose ); - cue_action( driver_hint::doorleftclose ); + if( ( true == ismanualdoor ) + && ( ( vehicle->LoadExchangeTime() == 0.f ) + || ( vehicle->MoverParameters->Vel > EU07_AI_MOVEMENT ) ) ) { + vehicle->MoverParameters->OperateDoors( side::right, false, range_t::local ); + vehicle->MoverParameters->OperateDoors( side::left, false, range_t::local ); } - } - if( true == doors_permit_active() ) { - cue_action( driver_hint::doorrightpermitoff ); - cue_action( driver_hint::doorleftpermitoff ); - } - // if applicable close manually-operated doors in vehicles which may ignore remote signals - { - auto *vehicle = pVehicles[ end::front ]; // pojazd na czole składu - while( vehicle != nullptr ) { - // zamykanie drzwi w pojazdach - flaga zezwolenia była by lepsza - auto const ismanualdoor { - ( vehicle->MoverParameters->Doors.auto_velocity == -1.f ) - && ( ( vehicle->MoverParameters->Doors.close_control == control_t::passenger ) - || ( vehicle->MoverParameters->Doors.close_control == control_t::mixed ) ) }; - - if( ( true == ismanualdoor ) - && ( ( vehicle->LoadExchangeTime() == 0.f ) - || ( vehicle->MoverParameters->Vel > EU07_AI_MOVEMENT ) ) ) { - vehicle->MoverParameters->OperateDoors( side::right, false, range_t::local ); - vehicle->MoverParameters->OperateDoors( side::left, false, range_t::local ); - } - vehicle = vehicle->Next(); // pojazd podłączony z tyłu (patrząc od czoła) - } - } - fActionTime = -2.0 - 0.1 * Random( 15 ); // 2.0-3.5 sec wait, +potentially 0.5 remaining - iDrivigFlags &= ~moveDoorOpened; // zostały zamknięte - nie wykonywać drugi raz - - if( ( true == mvOccupied->DepartureSignal ) - && ( Random( 100 ) < Random( 100 ) ) ) { - // potentially turn off the warning before actual departure - // TBD, TODO: dedicated buzzer duration counter? - cue_action( driver_hint::departuresignaloff ); + vehicle = vehicle->Next(); // pojazd podłączony z tyłu (patrząc od czoła) } } + fActionTime = Random( -1.0, -3.5 ); // 1.0-3.5 sec wait + iDrivigFlags &= ~moveDoorOpened; // zostały zamknięte - nie wykonywać drugi raz + iDrivigFlags &= ~moveDepartureWarned; } } diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 554ffc87..e897ba91 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -75,7 +75,8 @@ enum TMovementStatus movePushPull = 0x40000, // zmiana czoła przez zmianę kabiny - nie odczepiać przy zmianie kierunku moveSignalFound = 0x80000, // na drodze skanowania został znaleziony semafor moveStopPointFound = 0x100000, // stop point detected ahead - moveGuardOpenDoor = 0x200000 // time for opening a door before departure + moveGuardOpenDoor = 0x200000, // time for opening a door before departure + moveDepartureWarned = 0x400000 // driver has already warned about the doors being closed (only for manual warning - i.e. EN57-ish) /* moveSemaphorWasElapsed = 0x100000, // minięty został semafor moveTrainInsideStation = 0x200000, // pociąg między semaforem a rozjazdami lub następnym semaforem