18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 04:47:06 +01:00
Files
maszyna/application/driverhints.cpp
T
Hirek 84f1aa2515 refactor(physics): the controllers and the switches of the cab are private to the vehicle
The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.

The .fiz keys are untouched.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
2026-11-29 12:26:21 +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( AIControllFlag ) {
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( AIControllFlag ) {
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 (AIControllFlag && 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 (AIControllFlag) {
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( AIControllFlag ) {
occupied->SetRadio(true);
}
remove_hint( driver_hint::radiooff );
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->Radio() == true; } );
break;
}
case driver_hint::radiofuseon: {
if( AIControllFlag ) {
occupied->SetRadioFuse(true);
}
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->RadioFuse() == true; } );
break;
}
case driver_hint::radiochannel: {
if( AIControllFlag ) {
iRadioChannel = static_cast<int>( Actionparameter );
}
hint(
Action,
[this](float const Parameter) {
return iRadioChannel == static_cast<int>(Parameter); },
Actionparameter );
break;
}
case driver_hint::radiooff: {
if( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
occupied->ConverterSwitch( false );
}
remove_hint( driver_hint::converteron );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyConverterExplicitlyEnabled == false; } );
break;
}
// relays
case driver_hint::primaryconverteroverloadreset: {
if( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
occupied->RelayReset( relay_t::tractionnmotoroverload );
}
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->FuseFlag == false; } );
break;
}
// line breaker
case driver_hint::linebreakerclose: {
if( AIControllFlag ) {
occupied->MainSwitch( true );
}
remove_hint( driver_hint::linebreakeropen );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyLineBreakerOpen == false; } );
break;
}
case driver_hint::linebreakeropen: {
if( AIControllFlag ) {
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( AIControllFlag ) {
occupied->CompressorSwitch( true );
}
remove_hint( driver_hint::compressoroff );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyCompressorEnabled == true; } );
break;
}
case driver_hint::compressoroff: {
if( AIControllFlag ) {
occupied->CompressorSwitch( false );
}
remove_hint( driver_hint::compressoron );
hint(
Action,
[this](float const /*Parameter*/) {
return IsAnyCompressorExplicitlyEnabled == false; } );
break;
}
case driver_hint::frontmotorblowerson: {
if( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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 (AIControllFlag && 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( AIControllFlag ) {
ZeroSpeed();
}
remove_master_controller_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->IsMainCtrlNoPowerPos() && mvControlling->IsScndCtrlNoPowerPos(); } );
break;
}
case driver_hint::mastercontrollersetreverserunlock: {
if( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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->eimic_real >= 1.0 : mvControlling->IsScndCtrlMaxPowerPos() && mvControlling->IsMainCtrlMaxPowerPos()); } );
break;
}
case driver_hint::bufferscompress: {
if (AIControllFlag && 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( AIControllFlag ) {
mvControlling->DecScndCtrl( 2 );
}
remove_master_controller_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return mvControlling->IsScndCtrlNoPowerPos(); } );
break;
}
case driver_hint::waterpumpon: {
if( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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 (AIControllFlag && 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( AIControllFlag ) {
// 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( AIControllFlag ) {
// 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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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 (AIControllFlag && 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( AIControllFlag ) {
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( AIControllFlag ) {
OrderDirectionChange( 1, occupied );
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->DirActive * occupied->CabActive > 0; } );
break;
}
case driver_hint::directionbackward: {
if( AIControllFlag ) {
OrderDirectionChange( -1, occupied );
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->DirActive * occupied->CabActive < 0; } );
break;
}
case driver_hint::directionother: {
if( AIControllFlag ) {
// 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( AIControllFlag ) {
ZeroDirection();
}
remove_reverser_hints();
hint(
Action,
[this](float const /*Parameter*/) {
return occupied->DirActive == 0; } );
break;
}
// anti-slip systems
case driver_hint::sandingon: {
if( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag
|| 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( AIControllFlag
|| 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( AIControllFlag
|| 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( AIControllFlag
|| 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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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 (AIControllFlag && occupied->SecuritySystem.is_blinking())
occupied->SecuritySystemReset();
hint(
Action,
[this](float const /*Parameter*/) {
return !occupied->SecuritySystem.is_vigilance_blinking(); } );
break;
}
case driver_hint::shpsystemreset: {
if (AIControllFlag && 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( AIControllFlag ) {
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( AIControllFlag || 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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag
|| ( 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( AIControllFlag ) {
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( AIControllFlag ) {
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( AIControllFlag ) {
occupied->BrakeReleaser( 0 );
}
remove_hint( driver_hint::releaseron );
hint(
Action,
[this](float const /*Parameter*/) {
return false == occupied->brakes.distributor->Releaser(); } );
break;
}
default: {
break;
}
}
}