18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 02:27:06 +01:00
Files
maszyna/application/driverhints.cpp
Hirek 23b695752a refactor(physics): the demand of the integrated controller is private to the vehicle
eimic_real, the demand of the integrated controller the vehicle goes by with
the speed control counted, which TDynamicObject and the consist braking set
for the vehicle that leads, is private: EimicReal() and SetEimicReal(). The
field of the same name of drivingaid::input stays as it is.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
2026-11-29 13:39:07 +01:00

1381 lines
55 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "vehicle/Driver.h"
#include "utilities/Globals.h"
#include "utilities/utilities.h"
#include "physics/vehicle.h"
void
TController::hint( driver_hint const Value, hintpredicate const Predicate, float const Predicateparameter ) {
if( Predicate( Predicateparameter ) ) { return; }
// check already recorded hints, if there's a match update it instead of adding a new one
for( auto &hint : m_hints ) {
if( std::get<driver_hint>( hint ) == Value ) {
std::get<float>( hint ) = Predicateparameter;
return; // done, can bail out early
}
}
m_hints.emplace_back( Value, Predicate, Predicateparameter );
}
void
TController::update_hints() {
m_hints.remove_if(
[]( auto const &Hint ) {
return std::get<hintpredicate>(Hint)(std::get<float>(Hint)); } );
}
void
TController::remove_hint( driver_hint const Value ) {
m_hints.remove_if(
[Value]( auto const &Hint ) {
return std::get<driver_hint>(Hint) == Value; } );
}
void
TController::remove_train_brake_hints() {
remove_hint( driver_hint::trainbrakesetpipeunlock );
remove_hint( driver_hint::trainbrakerelease );
remove_hint( driver_hint::trainbrakeapply );
remove_hint( driver_hint::brakingforcedecrease );
remove_hint( driver_hint::brakingforceincrease );
remove_hint( driver_hint::brakingforcesetzero );
remove_hint( driver_hint::brakingforcelap );
}
void
TController::remove_master_controller_hints() {
remove_hint( driver_hint::mastercontrollersetidle );
remove_hint( driver_hint::mastercontrollersetseriesmode );
remove_hint( driver_hint::mastercontrollersetzerospeed );
remove_hint( driver_hint::mastercontrollersetreverserunlock );
remove_hint( driver_hint::tractiveforcedecrease );
remove_hint( driver_hint::tractiveforceincrease );
remove_hint( driver_hint::bufferscompress );
}
void
TController::remove_reverser_hints() {
remove_hint( driver_hint::directionforward );
remove_hint( driver_hint::directionbackward );
remove_hint( driver_hint::directionother );
remove_hint( driver_hint::directionnone );
}
void
TController::cue_action( driver_hint const Action, float const Actionparameter ) {
switch( Action ) {
// battery
case driver_hint::batteryon: {
if( aiControlled ) {
occupied->BatterySwitch( true );
}
remove_hint( driver_hint::batteryoff );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->lowVoltage.config.batteryStart != start_t::manual || occupied->lowVoltage.Is24vAvailable() == true; } );
break;
}
case driver_hint::batteryoff: {
if( aiControlled ) {
occupied->BatterySwitch( false );
}
remove_hint( driver_hint::batteryon );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->lowVoltage.config.batteryStart != start_t::manual || occupied->lowVoltage.Is24vAvailable() == false; } );
break;
}
// battery
case driver_hint::cabactivation: {
if (aiControlled && occupied->lowVoltage.Is24vAvailable()) {
occupied->CabActivisation();
CheckVehicles();
}
remove_hint( driver_hint::cabdeactivation );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->AutomaticCabActivation || occupied->IsCabMaster(); } );
break;
}
case driver_hint::cabdeactivation: {
if (aiControlled) {
occupied->CabDeactivisation();
}
remove_hint( driver_hint::cabactivation );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->AutomaticCabActivation || (occupied->CabMaster() == false && occupied->CabActive == 0); } );
break;
}
// radio
case driver_hint::radioon: {
if( aiControlled ) {
occupied->SetRadio(true);
}
remove_hint( driver_hint::radiooff );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Radio() == true; } );
break;
}
case driver_hint::radiofuseon: {
if( aiControlled ) {
occupied->SetRadioFuse(true);
}
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->RadioFuse() == true; } );
break;
}
case driver_hint::radiochannel: {
if( aiControlled ) {
iRadioChannel = static_cast<int>( Actionparameter );
}
hint(
Action,
[this](float const Parameter) {
return iRadioChannel == static_cast<int>(Parameter); },
Actionparameter );
break;
}
case driver_hint::radiooff: {
if( aiControlled ) {
occupied->SetRadio(false);
}
remove_hint( driver_hint::radioon );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Radio() == false; } );
break;
}
// oil pump
case driver_hint::oilpumpon: {
if( aiControlled ) {
occupied->OilPumpSwitch( true );
}
remove_hint( driver_hint::oilpumpoff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { occupied->OilPump };
return device.start_type != start_t::manual || device.is_enabled == true || device.is_active == true || occupied->lineBreaker.IsClosed(); } );
break;
}
case driver_hint::oilpumpoff: {
if( aiControlled ) {
occupied->OilPumpSwitch( false );
}
remove_hint( driver_hint::oilpumpon );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { occupied->OilPump };
return device.start_type != start_t::manual || (device.is_enabled == false && device.is_active == false); } );
break;
}
// fuel pump
case driver_hint::fuelpumpon: {
if( aiControlled ) {
occupied->FuelPumpSwitch( true );
}
remove_hint( driver_hint::fuelpumpoff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { occupied->FuelPump };
return device.start_type != start_t::manual || device.is_enabled == true || device.is_active == true; } );
break;
}
case driver_hint::fuelpumpoff: {
if( aiControlled ) {
occupied->FuelPumpSwitch( false );
}
remove_hint( driver_hint::fuelpumpon );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { occupied->FuelPump };
return device.start_type != start_t::manual || (device.is_enabled == false && device.is_active == false); } );
break;
}
// pantographs
case driver_hint::pantographairsourcesetmain: {
if( aiControlled ) {
pantographUnit->pantographAir.ConnectToMainReservoir(true);
}
remove_hint( driver_hint::pantographairsourcesetauxiliary );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographAir.IsConnectedToMainReservoir() == true; } );
break;
}
case driver_hint::pantographairsourcesetauxiliary: {
if( aiControlled ) {
pantographUnit->pantographAir.ConnectToMainReservoir(false);
}
remove_hint( driver_hint::pantographcompressoron );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographAir.IsConnectedToMainReservoir() == false; } );
break;
}
case driver_hint::pantographcompressoron: {
if( aiControlled ) {
pantographUnit->pantographAir.SwitchCompressor(true);
}
remove_hint( driver_hint::pantographcompressoroff );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographAir.IsCompressorRunning() == true; } );
break;
}
case driver_hint::pantographcompressoroff: {
if( aiControlled ) {
pantographUnit->pantographAir.SwitchCompressor(false);
}
remove_hint( driver_hint::pantographcompressoron );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographAir.IsCompressorRunning() == false; } );
break;
}
case driver_hint::pantographsvalveon: {
if( aiControlled ) {
occupied->OperatePantographsValve( operation_t::enable );
}
remove_hint( driver_hint::pantographsvalveoff );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographAir.valve.is_active == true; } );
break;
}
case driver_hint::frontpantographvalveon: {
if( aiControlled ) {
occupied->OperatePantographValve( VehicleEnd::front, operation_t::enable );
}
remove_hint( driver_hint::frontpantographvalveoff );
hint(
Action,
[ this ]( float const Parameter ) {
return pantographUnit->pantographs[VehicleEnd::front].valve.is_active == true || (Parameter > 0 && occupied->Vel > Parameter); },
Actionparameter );
break;
}
case driver_hint::frontpantographvalveoff: {
if( aiControlled ) {
occupied->OperatePantographValve( VehicleEnd::front, operation_t::disable );
}
remove_hint( driver_hint::frontpantographvalveon );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographs[VehicleEnd::front].valve.is_active == false; } );
break;
}
case driver_hint::rearpantographvalveon: {
if( aiControlled ) {
occupied->OperatePantographValve( VehicleEnd::rear, operation_t::enable );
}
remove_hint( driver_hint::rearpantographvalveoff );
hint(
Action,
[ this ]( float const Parameter ) {
return pantographUnit->pantographs[VehicleEnd::rear].valve.is_active == true || (Parameter > 0 && occupied->Vel > Parameter); },
Actionparameter );
break;
}
case driver_hint::rearpantographvalveoff: {
if( aiControlled ) {
occupied->OperatePantographValve( VehicleEnd::rear, operation_t::disable );
}
remove_hint( driver_hint::rearpantographvalveon );
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographs[VehicleEnd::rear].valve.is_active == false; } );
break;
}
// converter
case driver_hint::converteron: {
if( aiControlled ) {
occupied->ConverterSwitch( true );
// the local switch of the converter too, where the line contactors wait for the vehicle's own converter
// (LineContactorsInterlock): left off by the human driver, that vehicle would never take power
pVehicle->for_each(
Coupling::control,
[]( TDynamicObject * Vehicle ) {
auto *vehicle { Vehicle->physics };
if( vehicle->LineContactorsHeldByLocalConverterSwitch() ) {
vehicle->converter.SetLocalSwitch(true); } } );
}
remove_hint( driver_hint::converteroff );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyConverterEnabled == true; } );
break;
}
case driver_hint::converteroff: {
if( aiControlled ) {
occupied->ConverterSwitch( false );
}
remove_hint( driver_hint::converteron );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyConverterExplicitlyEnabled == false; } );
break;
}
// relays
case driver_hint::primaryconverteroverloadreset: {
if( aiControlled ) {
occupied->RelayReset( relay_t::primaryconverteroverload );
}
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->converter.config.overloadRelayStart != start_t::manual || occupied->converter.IsOverloaded() == false; } );
break;
}
case driver_hint::maincircuitgroundreset: {
if( aiControlled ) {
occupied->RelayReset( relay_t::maincircuitground );
}
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->protection.config.groundStart != start_t::manual || occupied->protection.GroundHolds() == true; } );
break;
}
case driver_hint::tractionnmotoroverloadreset: {
if( aiControlled ) {
occupied->RelayReset( relay_t::tractionnmotoroverload );
}
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->FuseFlag == false; } );
break;
}
// line breaker
case driver_hint::linebreakerclose: {
if( aiControlled ) {
occupied->MainSwitch( true );
}
remove_hint( driver_hint::linebreakeropen );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyLineBreakerOpen == false; } );
break;
}
case driver_hint::linebreakeropen: {
if( aiControlled ) {
occupied->MainSwitch( false );
}
remove_hint( driver_hint::linebreakerclose );
hint(
Action,
[this](float const /*Parameter*/) {
// TBD, TODO: replace with consist-wide flag set true if any line breaker is closed?
return mvControlling->lineBreaker.IsClosed() == false; } );
break;
}
// compressor
case driver_hint::compressoron: {
if( aiControlled ) {
occupied->CompressorSwitch( true );
}
remove_hint( driver_hint::compressoroff );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyCompressorEnabled == true; } );
break;
}
case driver_hint::compressoroff: {
if( aiControlled ) {
occupied->CompressorSwitch( false );
}
remove_hint( driver_hint::compressoron );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyCompressorExplicitlyEnabled == false; } );
break;
}
case driver_hint::frontmotorblowerson: {
if( aiControlled ) {
occupied->MotorBlowersSwitchOff( false, VehicleEnd::front );
occupied->MotorBlowersSwitch( true, VehicleEnd::front );
}
remove_hint( driver_hint::frontmotorblowersoff );
hint(
Action,
[this]( float const /*Parameter*/ ) {
auto const &device { occupied->MotorBlowers[ VehicleEnd::front ] };
return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false); } );
break;
}
case driver_hint::rearmotorblowerson: {
if( aiControlled ) {
occupied->MotorBlowersSwitchOff( false, VehicleEnd::rear );
occupied->MotorBlowersSwitch( true, VehicleEnd::rear );
}
remove_hint( driver_hint::rearmotorblowersoff );
hint(
Action,
[this]( float const /*Parameter*/ ) {
auto const &device { occupied->MotorBlowers[ VehicleEnd::rear ] };
return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false); } );
break;
}
// spring brake
case driver_hint::springbrakeon: {
if( aiControlled ) {
occupied->SpringBrakeActivate( true );
}
remove_hint( driver_hint::springbrakeoff );
hint(
Action,
[this]( float const /*Parameter*/ ) {
return occupied->brakes.spring.activate == true; } );
break;
}
case driver_hint::springbrakeoff: {
if( aiControlled ) {
occupied->SpringBrakeActivate( false );
}
remove_hint( driver_hint::springbrakeon );
hint(
Action,
[this]( float const /*Parameter*/ ) {
return occupied->brakes.spring.activate == false; } );
break;
}
// manual brake
case driver_hint::manualbrakon: {
if( aiControlled ) {
occupied->IncManualBrakeLevel( ManualBrakePosNo );
}
remove_hint( driver_hint::manualbrakoff );
hint(
Action,
[this]( float const /*Parameter*/ ) {
return occupied->brakes.config.localKind != TLocalBrake::ManualBrake || occupied->brakes.config.hasHandBrake == false || occupied->brakes.HandBrakePosition() == ManualBrakePosNo; } );
break;
}
case driver_hint::manualbrakoff: {
if( aiControlled ) {
occupied->DecManualBrakeLevel( ManualBrakePosNo );
}
remove_hint( driver_hint::manualbrakon );
hint(
Action,
[this]( float const /*Parameter*/ ) {
return occupied->brakes.config.localKind != TLocalBrake::ManualBrake || occupied->brakes.config.hasHandBrake == false || occupied->brakes.HandBrakePosition() == 0; } );
break;
}
// master controller
case driver_hint::mastercontrollersetidle: {
if( aiControlled ) {
while( mvControlling->RList[mvControlling->MainCtrlPos()].Mn == 0
&& mvControlling->IncMainCtrl(1) ) {
// all work is done in the loop header
}
}
remove_master_controller_hints();
hint(
Action,
[this]( float const /*Parameter*/ ) {
return mvControlling->RList[mvControlling->MainCtrlPos()].Mn > 0; } );
break;
}
case driver_hint::mastercontrollersetseriesmode: {
if (aiControlled && mvControlling->RList[ mvControlling->MainCtrlPos() ].Bn > 1) {
// limit yourself to series mode
if( mvControlling->ScndCtrlPos() ) {
mvControlling->DecScndCtrl( 2 );
}
while( mvControlling->RList[mvControlling->MainCtrlPos()].Bn > 1
&& mvControlling->DecMainCtrl(1) ) {
// all work is performed in the header
}
}
remove_master_controller_hints();
hint(
Action,
[this]( float const /*Parameter*/ ) {
return mvControlling->RList[mvControlling->MainCtrlPos()].Bn < 2; } );
break;
}
case driver_hint::mastercontrollersetzerospeed: {
if( aiControlled ) {
ZeroSpeed();
}
remove_master_controller_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->IsMainCtrlNoPowerPos() && mvControlling->IsScndCtrlNoPowerPos(); } );
break;
}
case driver_hint::mastercontrollersetreverserunlock: {
if( aiControlled ) {
while( false == mvControlling->EIMDirectionChangeAllow()
&& mvControlling->DecMainCtrl(1) ) {
// all work is done in the loop header
}
}
remove_master_controller_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->EIMDirectionChangeAllow(); },
static_cast<float>(mvControlling->MainCtrlMaxDirChangePos()) );
break;
}
case driver_hint::tractiveforcedecrease: {
if( aiControlled ) {
DecSpeed();
}
remove_master_controller_hints();
hint(
Action,
[this](float const Parameter) {
return std::abs(mvControlling->Ft()) <= Parameter; },
static_cast<float>(std::min(
0.0,
std::max(
std::abs( mvControlling->Ft() ) * 0.95,
std::abs( mvControlling->Ft() ) - 5.0 ) )) );
break;
}
case driver_hint::tractiveforceincrease: {
if( aiControlled ) {
IncSpeed();
}
remove_master_controller_hints();
// clear potentially remaining braking hints
// TODO: add other brake application hints, refactor into a method
{
remove_hint( driver_hint::brakingforceincrease );
remove_hint( driver_hint::independentbrakeapply );
}
hint(
Action,
[this](float const /*Parameter*/) {
return AccDesired <= EU07_AI_NOACCELERATION || (false == Ready && false == occupied->ShuntMode) || AccDesired - AbsAccS <= 0.05 ||
(occupied->EIMCtrlType > 0 ? mvControlling->EimicReal() >= 1.0 : mvControlling->IsScndCtrlMaxPowerPos() && mvControlling->IsMainCtrlMaxPowerPos()); } );
break;
}
case driver_hint::bufferscompress: {
if (aiControlled && std::abs( mvControlling->Ft() ) < 50000.0) {
IncSpeed();
}
remove_master_controller_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return std::abs(mvControlling->Ft()) > 30.0 || false == OrderCurrentGet().HasAny(DriverOrder::disconnect); } );
break;
}
case driver_hint::secondcontrollersetzero: {
if( aiControlled ) {
mvControlling->DecScndCtrl( 2 );
}
remove_master_controller_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->IsScndCtrlNoPowerPos(); } );
break;
}
case driver_hint::waterpumpon: {
if( aiControlled ) {
mvControlling->WaterPumpSwitch( true );
}
remove_hint( driver_hint::waterpumpoff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterPump };
return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false) || device.is_active == true; } );
break;
}
case driver_hint::waterpumpoff: {
if( aiControlled ) {
mvControlling->WaterPumpSwitch( false );
}
remove_hint( driver_hint::waterpumpon );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterPump };
return device.start_type != start_t::manual || (device.is_enabled == false && device.is_active == false); } );
break;
}
case driver_hint::waterpumpbreakeron: {
if( aiControlled ) {
mvControlling->WaterPumpBreakerSwitch( true );
}
remove_hint( driver_hint::waterpumpbreakeroff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterPump };
return device.breaker == true; } );
break;
}
case driver_hint::waterpumpbreakeroff: {
if( aiControlled ) {
mvControlling->WaterPumpBreakerSwitch( false );
}
remove_hint( driver_hint::waterpumpbreakeron );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterPump };
return device.breaker == false; } );
break;
}
case driver_hint::waterheateron: {
if( aiControlled ) {
mvControlling->WaterHeaterSwitch( true );
}
remove_hint( driver_hint::waterheateroff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterHeater };
return device.is_enabled == true; } );
break;
}
case driver_hint::waterheateroff: {
if( aiControlled ) {
mvControlling->WaterHeaterSwitch( false );
}
remove_hint( driver_hint::waterheateron );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterHeater };
return device.is_enabled == false; } );
break;
}
case driver_hint::waterheaterbreakeron: {
if( aiControlled ) {
mvControlling->WaterHeaterBreakerSwitch( true );
}
remove_hint( driver_hint::waterheaterbreakeroff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterHeater };
return device.breaker == true; } );
break;
}
case driver_hint::waterheaterbreakeroff: {
if( aiControlled ) {
mvControlling->WaterHeaterBreakerSwitch( false );
}
remove_hint( driver_hint::waterheaterbreakeron );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { mvControlling->WaterHeater };
return device.breaker == false; } );
break;
}
case driver_hint::watercircuitslinkon: {
if( aiControlled ) {
mvControlling->WaterCircuitsLinkSwitch( true );
}
remove_hint( driver_hint::watercircuitslinkoff );
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->diesel.heat.auxiliary_water_circuit == false || mvControlling->WaterCircuitsLink() == true; } );
break;
}
case driver_hint::watercircuitslinkoff: {
if( aiControlled ) {
mvControlling->WaterCircuitsLinkSwitch( false );
}
remove_hint( driver_hint::watercircuitslinkon );
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->diesel.heat.auxiliary_water_circuit == false || mvControlling->WaterCircuitsLink() == false; } );
break;
}
case driver_hint::waittemperaturetoolow: {
// NOTE: this action doesn't have AI component
hint(
Action,
[this](float const /*Parameter*/) {
return false == IsHeatingTemperatureTooLow; } );
break;
}
case driver_hint::waitpressuretoolow: {
// NOTE: this action doesn't have AI component
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->mainPipe.Pressure() > 4.5 || mvControlling->air.config.mainReservoirVolume == 0.0; } );
break;
}
case driver_hint::waitpantographpressuretoolow: {
// NOTE: this action doesn't have AI component
hint(
Action,
[this](float const /*Parameter*/) {
return pantographUnit->pantographAir.Pressure() >= (is_emu() ? (pantographUnit->pantographAir.IsPressureLockActive() ? 4.6 : 2.6) : 4.2); } );
break;
}
case driver_hint::waitbrakecharge: {
// NOTE: this action doesn't have AI component: the ai waits through Ready and DecBrake()
hint(
Action,
[this](float const /*Parameter*/) {
return IsConsistCharged; } );
break;
}
case driver_hint::waitloadexchange: {
// NOTE: this action doesn't have AI component
hint(
Action,
[this](float const /*Parameter*/) {
return ExchangeTime <= 0; } );
break;
}
case driver_hint::waitdeparturetime: {
// NOTE: this action doesn't have AI component
hint(
Action,
[this](float const /*Parameter*/) {
return IsAtPassengerStop == false; } );
break;
}
// train brake and braking force. mutually exclusive:
// driver_hint_trainbrakesetpipeunlock
// driver_hint_trainbrakerelease
// driver_hint_brakingforcedecrease
// driver_hint_brakingforceincrease
// driver_hint_brakingforcesetzero
// driver_hint_brakingforcelap
case driver_hint::trainbrakesetpipeunlock: {
if (aiControlled && occupied->brakes.pipeLock.unlockHandlePosition != -3) {
while( BrakeCtrlPosition >= occupied->brakes.pipeLock.unlockHandlePosition
&& BrakeLevelAdd(-1) ) {
// all work is done in the header
}
}
remove_train_brake_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->brakes.pipeLock.unlockHandlePosition == -3 || BrakeCtrlPosition == occupied->brakes.pipeLock.unlockHandlePosition; } );
break;
}
case driver_hint::trainbrakerelease: {
if( aiControlled ) {
// occupied->BrakeLevelSet( occupied->Handle->GetPos( bh_RP ) );
BrakeLevelSet( gbh_RP );
}
remove_train_brake_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_RP), 0.2) || (occupied->brakes.driverValve->Time && occupied->brakes.driverValve->GetCP() > occupied->brakes.config.pipeHighPressure - 0.05); } );
// return ( BrakeCtrlPosition == gbh_RP ); } );
break;
}
case driver_hint::trainbrakeapply: {
if( aiControlled ) {
// za radą yB ustawiamy pozycję 3 kranu (ruszanie kranem w innych miejscach powino zostać wyłączone)
if( BrakeSystem == TBrakeSystem::ElectroPneumatic && false == ForcePNBrake ) {
occupied->BrakeLevelSet( occupied->brakes.driverValve->GetPos( bh_EPB ) );
}
else {
BrakeCtrlPosition = 3;
}
}
remove_train_brake_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return IsConsistBraked /*|| ( false == OrderCurrentGet().HasAny(DriverOrder::disconnect) ) */; } );
break;
}
case driver_hint::brakingforcedecrease: {
if( aiControlled ) {
auto const brakingcontrolschange { DecBrake() };
// set optional delay between brake adjustments
if( brakingcontrolschange && Actionparameter > 0 ) {
fBrakeTime = Actionparameter;
}
}
remove_train_brake_hints();
hint(
Action,
[this](float const Parameter) {
return std::abs(mvControlling->Fb()) <= Parameter; },
static_cast<float>(std::min( 0.0, 0.95 * std::abs( mvControlling->Fb() ) )) ); // keep hint until 5% decrease
break;
}
case driver_hint::brakingforceincrease: {
if( aiControlled ) {
auto const brakingcontrolschange { IncBrake() };
// set optional delay between brake adjustments
if( brakingcontrolschange && Actionparameter > 0 ) {
fBrakeTime = Actionparameter;
}
}
remove_train_brake_hints();
hint(
Action,
[this](float const Parameter) {
return std::abs(mvControlling->Fb()) > Parameter || is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_EB), 0.2); },
static_cast<float>(std::max(
0.0,
std::max(
std::abs( mvControlling->Fb() ) * 1.05,
std::abs( mvControlling->Fb() ) + 5.0 ) )) );
break;
}
case driver_hint::brakingforcesetzero: { // releases both train and independent brake
if( aiControlled ) {
while( true == DecBrake() ) {
// all work is done in the loop condition
}
}
remove_train_brake_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return Ready && fReady < 0.4 && is_equal(occupied->brakes.HandlePositionSmooth(), occupied->brakes.driverValve->GetPos(bh_RP), 0.2); } );
break;
}
case driver_hint::brakingforcelap: {
if( aiControlled ) {
LapBrake();
}
remove_train_brake_hints();
// NOTE: this action doesn't have human component
// TBD, TODO: provide one?
break;
}
// independent brake
case driver_hint::independentbrakeapply: {
if (aiControlled && occupied->brakes.IndependentPosition() < 1.0) {
occupied->IncLocalBrakeLevel( LocalBrakePosNo );
if (occupied->EIMCtrlEmergency()) {
occupied->DecLocalBrakeLevel(1);
}
}
remove_hint( driver_hint::independentbrakerelease );
hint(
Action,
[this](float const Parameter) {
return occupied->brakes.IndependentPosition() >= Parameter; },
( LocalBrakePosNo - ( occupied->EIMCtrlEmergency() ? 1 : 0 ) ) / LocalBrakePosNo );
break;
}
case driver_hint::independentbrakerelease: {
if( aiControlled ) {
ZeroLocalBrake();
}
remove_hint( driver_hint::independentbrakeapply );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->brakes.IndependentPosition() < 0.05; } );
break;
}
// reverser
case driver_hint::directionforward: {
if( aiControlled ) {
OrderDirectionChange( 1, occupied );
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->DirActive * occupied->CabActive > 0; } );
break;
}
case driver_hint::directionbackward: {
if( aiControlled ) {
OrderDirectionChange( -1, occupied );
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->DirActive * occupied->CabActive < 0; } );
break;
}
case driver_hint::directionother: {
if( aiControlled ) {
// DirectionForward( occupied->DirAbsolute < 0 );
OrderDirectionChange( iDirectionOrder, occupied );
DirectionChange();
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return iDirection == iDirectionOrder; } );
break;
}
case driver_hint::directionnone: {
if( aiControlled ) {
ZeroDirection();
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->DirActive == 0; } );
break;
}
// anti-slip systems
case driver_hint::sandingon: {
if( aiControlled ) {
mvControlling->Sandbox( true );
}
remove_hint( driver_hint::sandingoff );
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->Sand == 0 || mvControlling->SandDose() == true || mvControlling->SlippingWheels() == false; } );
break;
}
case driver_hint::sandingoff: {
if( aiControlled ) {
mvControlling->Sandbox( false );
}
remove_hint( driver_hint::sandingon );
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->Sand == 0 || mvControlling->SandDose() == false; } );
break;
}
case driver_hint::antislip: {
if( aiControlled ) {
mvControlling->AntiSlippingButton();
}
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->brakes.config.antiSlipType != 1 || (mvControlling->brakes.distributor->GetBrakeStatus() & b_asb) != 0 || mvControlling->SlippingWheels() == false; } );
break;
}
// horns
case driver_hint::hornon: {
if( aiControlled ) {
occupied->SetWarningSignal(static_cast<int>( Actionparameter ));
}
remove_hint( driver_hint::hornoff );
hint(
Action,
[this](float const /*Parameter*/) {
// NOTE: we provide slightly larger horn activation window for human driver
return fWarningDuration + 5.0 < 0.05 || occupied->WarningSignal() != 0; } );
break;
}
case driver_hint::hornoff: {
if( aiControlled ) {
occupied->SetWarningSignal(0);
}
/*
// NOTE: for human driver the hint to switch horn on will disappear automatically
remove_hint( driver_hint::hornon );
hint(
Action,
[this](float const Parameter) -> bool {
return ( occupied->WarningSignal() == 0 ); } );
*/
break;
}
// door locks
case driver_hint::consistdoorlockson: {
if( aiControlled ) {
occupied->LockDoors( true );
}
// TODO: remove other door lock hints
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Doors.has_lock == false || occupied->Doors.lock_enabled == true; } );
break;
}
// departure signal
case driver_hint::departuresignalon: {
if( aiControlled ) {
occupied->signal_departure( true );
}
remove_hint( driver_hint::departuresignaloff );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Doors.has_warning == false || occupied->Doors.has_autowarning == true || occupied->DepartureSignal() == true || occupied->Vel > 5.0; } );
break;
}
case driver_hint::departuresignaloff: {
if( aiControlled ) {
occupied->signal_departure( false );
}
remove_hint( driver_hint::departuresignalon );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Doors.has_warning == false || occupied->Doors.has_autowarning == true || occupied->DepartureSignal() == false; } );
break;
}
// consist doors
case driver_hint::doorrightopen: {
if( aiControlled
|| pVehicle->physics->Doors.open_control == control_t::conductor ) {
pVehicle->physics->OperateDoors( VehicleSide::right, true );
}
remove_hint( driver_hint::doorrightclose );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorOpen[VehicleSide::right] == true; } );
break;
}
case driver_hint::doorrightclose: {
if( aiControlled
|| pVehicle->physics->Doors.open_control == control_t::conductor ) {
pVehicle->physics->OperateDoors( VehicleSide::right, false );
}
remove_hint( driver_hint::doorrightopen );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorOpen[VehicleSide::right] == false; } );
break;
}
case driver_hint::doorleftopen: {
if( aiControlled
|| pVehicle->physics->Doors.open_control == control_t::conductor ) {
pVehicle->physics->OperateDoors( VehicleSide::left, true );
}
remove_hint( driver_hint::doorleftclose );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorOpen[VehicleSide::left] == true; } );
break;
}
case driver_hint::doorleftclose: {
if( aiControlled
|| pVehicle->physics->Doors.open_control == control_t::conductor ) {
pVehicle->physics->OperateDoors( VehicleSide::left, false );
}
remove_hint( driver_hint::doorleftopen );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorOpen[VehicleSide::left] == false; } );
break;
}
case driver_hint::doorrightpermiton: {
if( aiControlled ) {
pVehicle->physics->PermitDoors( VehicleSide::right, true );
}
remove_hint( driver_hint::doorrightpermitoff );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorPermitActive[VehicleSide::right] == true; } );
break;
}
case driver_hint::doorrightpermitoff: {
if( aiControlled ) {
pVehicle->physics->PermitDoors( VehicleSide::right, false );
}
remove_hint( driver_hint::doorrightpermiton );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorPermitActive[VehicleSide::right] == false; } );
break;
}
case driver_hint::doorleftpermiton: {
if( aiControlled ) {
pVehicle->physics->PermitDoors( VehicleSide::left, true );
}
remove_hint( driver_hint::doorleftpermitoff );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorPermitActive[VehicleSide::left] == true; } );
break;
}
case driver_hint::doorleftpermitoff: {
if( aiControlled ) {
pVehicle->physics->PermitDoors( VehicleSide::left, false );
}
remove_hint( driver_hint::doorleftpermiton );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyDoorPermitActive[VehicleSide::left] == false; } );
break;
}
// doorsteps, as the timetable asks (eu07/maszyna#95)
case driver_hint::doorstepon: {
if( aiControlled ) {
occupied->PermitDoorStep( true );
}
remove_hint( driver_hint::doorstepoff );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Doors.step_enabled == true; } );
break;
}
case driver_hint::doorstepoff: {
if( aiControlled ) {
occupied->PermitDoorStep( false );
}
remove_hint( driver_hint::doorstepon );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Doors.step_enabled == false; } );
break;
}
// consist lights
case driver_hint::consistlightson: {
if( aiControlled ) {
occupied->CompartmentLightsSwitch( true );
occupied->CompartmentLightsSwitchOff( false );
}
remove_hint( driver_hint::consistlightsoff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { occupied->CompartmentLights };
return Global.fLuminance * ConsistShade > 0.40 || device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false) || device.is_active == true; } );
break;
}
case driver_hint::consistlightsoff: {
if( aiControlled ) {
occupied->CompartmentLightsSwitch( false );
occupied->CompartmentLightsSwitchOff( true );
}
remove_hint( driver_hint::consistlightson );
hint(
Action,
[this](float const /*Parameter*/) {
auto const &device { occupied->CompartmentLights };
return Global.fLuminance * ConsistShade < 0.35 || device.start_type != start_t::manual || (device.is_enabled == false && device.is_active == false); } );
break;
}
// consist heating
case driver_hint::consistheatingon: {
if( aiControlled ) {
occupied->HeatingSwitch( true );
}
remove_hint( driver_hint::consistheatingoff );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->trainHeating.IsAllowed() == true; } );
break;
}
case driver_hint::consistheatingoff: {
if( aiControlled ) {
occupied->HeatingSwitch( false );
}
remove_hint( driver_hint::consistheatingon );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->trainHeating.IsAllowed() == false; } );
break;
}
case driver_hint::securitysystemreset: {
if (aiControlled && occupied->SecuritySystem.is_blinking())
occupied->SecuritySystemReset();
hint(
Action,
[this](float const /*Parameter*/) {
return !occupied->SecuritySystem.is_vigilance_blinking(); } );
break;
}
case driver_hint::shpsystemreset: {
if (aiControlled && occupied->SecuritySystem.is_cabsignal_blinking())
occupied->SecuritySystem.cabsignal_reset();
hint(
Action,
[this](float const /*Parameter*/) {
return !occupied->SecuritySystem.is_cabsignal_blinking(); } );
break;
}
case driver_hint::couplingadapterattach: {
// TODO: run also for potential settings-based virtual assistant
if( aiControlled ) {
pVehicles[ VehicleEnd::front ]->attach_coupler_adapter( EndOf( static_cast<int>(Actionparameter) ) );
}
hint(
Action,
[this](float const Parameter) {
auto const &device { pVehicles[ VehicleEnd::front ]->physics->Couplers[ static_cast<int>( Parameter ) ] };
return device.type() == TCouplerType::Automatic; } );
break;
}
case driver_hint::couplingadapterremove: {
if( aiControlled || Global.AITrainman ) {
pVehicles[ VehicleEnd::front ]->remove_coupler_adapter( EndOf( static_cast<int>(Actionparameter) ) );
}
hint(
Action,
[this](float const Parameter) {
auto const &device { pVehicles[ VehicleEnd::front ]->physics->Couplers[ static_cast<int>( Parameter ) ] };
return false == device.has_adapter(); } );
break;
}
// lights
case driver_hint::headcodepc1: {
if( aiControlled ) {
pVehicles[ VehicleEnd::front ]->RaLightsSet( light::headlight_left | light::headlight_right | light::headlight_upper, -1 );
}
remove_hint( driver_hint::headcodepc2 );
remove_hint( driver_hint::headcodetb1 );
remove_hint( driver_hint::lightsoff );
hint(
Action,
[this](float const /*Parameter*/) {
return pVehicles[VehicleEnd::front]->has_signal_pc1_on(); } );
break;
}
case driver_hint::headcodepc2: {
if( aiControlled ) {
pVehicles[ VehicleEnd::front ]->RaLightsSet( light::redmarker_left | light::headlight_right | light::headlight_upper, -1 );
}
remove_hint( driver_hint::headcodepc1 );
remove_hint( driver_hint::headcodetb1 );
remove_hint( driver_hint::lightsoff );
hint(
Action,
[this](float const /*Parameter*/) {
return pVehicles[VehicleEnd::front]->has_signal_pc2_on(); } );
break;
}
case driver_hint::headcodetb1: {
// HACK: the 'front' and 'rear' of the consist is determined by current consist direction
// since direction shouldn't affect Tb1 light configuration, we 'counter' this behaviour by virtually swapping end vehicles
if( aiControlled ) {
if( occupied->DirActive >= 0 ) { Lights( light::headlight_right, light::headlight_left ); }
else { Lights( light::headlight_left, light::headlight_right ); }
}
remove_hint( driver_hint::headcodepc1 );
remove_hint( driver_hint::headcodepc2 );
remove_hint( driver_hint::headcodepc5 );
remove_hint( driver_hint::lightsoff );
hint(
Action,
[this](float const /*Parameter*/) {
auto const activeend { occupied->CabActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
auto const consistfront { occupied->DirActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
return pVehicles[consistfront]->has_signal_on(activeend, light::headlight_right) && pVehicles[Opposite(consistfront)]->has_signal_on(Opposite(activeend), light::headlight_left); } );
break;
}
case driver_hint::headcodepc5: {
if( aiControlled
|| ( Global.AITrainman && false == pVehicles[VehicleEnd::rear]->is_connected(pVehicle, Coupling::control) ) ) {
pVehicles[ VehicleEnd::rear ]->RaLightsSet( -1, light::redmarker_left | light::redmarker_right | light::rearendsignals );
}
remove_hint( driver_hint::headcodetb1 );
remove_hint( driver_hint::lightsoff );
hint(
Action,
[this](float const /*Parameter*/) {
return pVehicles[VehicleEnd::rear]->has_signal_pc5_on(); } );
break;
}
case driver_hint::lightsoff: {
if( aiControlled ) {
Lights( 0, 0 );
}
remove_hint( driver_hint::headcodepc1 );
remove_hint( driver_hint::headcodepc2 );
remove_hint( driver_hint::headcodepc5 );
remove_hint( driver_hint::headcodetb1 );
hint(
Action,
[this](float const /*Parameter*/) {
auto const activeend { occupied->CabActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
auto const consistfront { occupied->DirActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
return pVehicles[consistfront]->has_signal_on(activeend, 0) && pVehicles[Opposite(consistfront)]->has_signal_on(Opposite(activeend), 0); } );
break;
}
// releaser
case driver_hint::releaseron: {
if( aiControlled ) {
occupied->BrakeReleaser( 1 );
}
remove_hint( driver_hint::releaseroff );
hint(
Action,
[this](float const /*Parameter*/) {
return true == occupied->brakes.distributor->Releaser(); } );
break;
}
case driver_hint::releaseroff: {
if( aiControlled ) {
occupied->BrakeReleaser( 0 );
}
remove_hint( driver_hint::releaseron );
hint(
Action,
[this](float const /*Parameter*/) {
return false == occupied->brakes.distributor->Releaser(); } );
break;
}
default: {
break;
}
}
}