18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 14:16:48 +01:00
Files
maszyna/vehicle/cab/brakecommands.cpp
T
Hirek 5879c228dc refactor(physics): what the rest of the simulator only reads of a vehicle is private to it
53 fields of physics::Vehicle that only the vehicle itself writes, and the rest
of the simulator reads, are private, with a query each, named as the field was
(Vmax(), TotalMass(), Ft(), nrot(), NAxles(), PhysicActivation(), ...): the
compiler now keeps the cab, the AI, the scenery, the renderer and the tests from
changing what the definition gives or the physics works out. The fields were
picked by what is never written outside the class, of plain types, with no
other member of the same name to confuse; inside the class they keep their
meaning under camelCase names. The one place outside that cleared a flag of
the AI through a reference does it through ClearAIFlag().

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

944 lines
25 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/.
*/
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
*/
// the commands of the brakes: the independent, the train, the manual and the spring brake handles, the sand
#include "stdafx.h"
#include "vehicle/Train.h"
#include "vehicle/horn.h"
#include "vehicle/linebreaker.h"
#include "vehicle/holdcoillever.h"
#include "vehicle/compartmentlightsswitch.h"
#include "vehicle/odometer.h"
#include "vehicle/mainctrlact.h"
#include "utilities/Globals.h"
#include "simulation/simulation.h"
#include "simulation/blackboxrecorder.h"
#include "world/Event.h"
#include "simulation/simulationtime.h"
#include "vehicle/Camera.h"
#include "utilities/Logs.h"
#include "model/MdlMngr.h"
#include "model/Model3d.h"
#include "utilities/Timer.h"
#include "vehicle/Driver.h"
#include "vehicle/DynObj.h"
#include "world/mtable.h"
#include "Console.h"
#include "application/application.h"
#include "rendering/renderer.h"
#include "physics/vehicle.h"
#include <future>
#include <thread>
#include <cmath>
#include <algorithm>
#include <format>
#include "vehicle/cab/internal.h"
void TTrain::OnCommand_independentbrakeincrease(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
// when SplitEDPneumaticBrake is active the local brake key always operates
// the pneumatic local brake directly, never piggy-backing on the joint controller
auto const splitMode{Train->controlled->brakes.electrodynamic.splitFromPneumatic};
auto const useStepped{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
if (Train->occupied->brakes.config.localKind != TLocalBrake::ManualBrake)
{
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->MainCtrlPos() > 0)
{
OnCommand_mastercontrollerdecrease(Train, Command);
}
else
{
Train->occupied->IncLocalBrakeLevel(useStepped ? 1 : static_cast<float>(Global.brake_speed * Command.time_delta * LocalBrakePosNo));
if (useStepped)
{
Train->m_mastercontrollerinuse = true;
}
}
}
}
}
void TTrain::OnCommand_independentbrakeincreasefast(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
auto const splitMode{Train->controlled->brakes.electrodynamic.splitFromPneumatic};
auto const useJointAnim{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
if (Train->occupied->brakes.config.localKind != TLocalBrake::ManualBrake)
{
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->MainCtrlPos() > 0)
{
OnCommand_mastercontrollerdecreasefast(Train, Command);
}
else
{
Train->occupied->IncLocalBrakeLevel(LocalBrakePosNo);
if (useJointAnim)
{
Train->m_mastercontrollerinuse = true;
}
}
}
}
}
void TTrain::OnCommand_independentbrakedecrease(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
auto const splitMode{Train->controlled->brakes.electrodynamic.splitFromPneumatic};
auto const useStepped{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
if (Train->occupied->brakes.config.localKind != TLocalBrake::ManualBrake
// Ra 1014-06: AI potrafi zahamować pomocniczym mimo jego braku - odhamować jakoś trzeba
// TODO: sort AI out so it doesn't do things it doesn't have equipment for
|| Train->occupied->brakes.IndependentPosition() > 0)
{
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->brakes.IndependentPosition() == 0.0)
{
OnCommand_mastercontrollerincrease(Train, Command);
}
else
{
Train->occupied->DecLocalBrakeLevel(useStepped ? 1 : static_cast<float>(Global.brake_speed * Command.time_delta * LocalBrakePosNo));
if (useStepped)
{
Train->m_mastercontrollerinuse = true;
}
}
}
}
}
void TTrain::OnCommand_independentbrakedecreasefast(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
auto const splitMode{Train->controlled->brakes.electrodynamic.splitFromPneumatic};
auto const useJointAnim{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
if (Train->occupied->brakes.config.localKind != TLocalBrake::ManualBrake
// Ra 1014-06: AI potrafi zahamować pomocniczym mimo jego braku - odhamować jakoś trzeba
// TODO: sort AI out so it doesn't do things it doesn't have equipment for
|| Train->occupied->brakes.IndependentPosition() > 0)
{
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->occupied->brakes.IndependentPosition() == 0.0)
{
OnCommand_mastercontrollerincreasefast(Train, Command);
}
else
{
Train->occupied->DecLocalBrakeLevel(LocalBrakePosNo);
if (useJointAnim)
{
Train->m_mastercontrollerinuse = true;
}
}
}
}
}
void TTrain::OnCommand_independentbrakeset(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
Train->occupied->brakes.SetIndependentPosition(std::clamp(Command.param1, 0.0, 1.0));
}
/*
Train->controlled->LocalBrakePos = (
std::round(
interpolate<double>(
0.0,
LocalBrakePosNo,
clamp(
Command.param1,
0.0, 1.0 ) ) ) );
*/
}
void TTrain::OnCommand_independentbrakebailoff(TTrain *Train, command_data const &Command)
{
if (false == Command.freefly)
{
// TODO: check if this set of conditions can be simplified.
// it'd be more flexible to have an attribute indicating whether bail off position is supported
if (Train->controlled->TrainType() != train_type::emu &&
(Train->controlled->EngineType == TEngineType::ElectricSeriesMotor || Train->controlled->EngineType == TEngineType::DieselElectric ||
Train->controlled->EngineType == TEngineType::ElectricInductionMotor) &&
Train->occupied->brakes.config.handlePositions > 0)
{
if (Command.action == GLFW_PRESS)
{
// press or hold
// visual feedback
Train->ggReleaserButton.UpdateValue(1.0, Train->dsbSwitch);
Train->occupied->BrakeReleaser(1);
}
else if (Command.action == GLFW_RELEASE)
{
// release
// visual feedback
Train->ggReleaserButton.UpdateValue(0.0, Train->dsbSwitch);
Train->occupied->BrakeReleaser(0);
}
}
}
else
{
// car brake handling, while in walk mode
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle != nullptr)
{
if (Command.action == GLFW_PRESS)
{
// press or hold
vehicle->physics->BrakeReleaser(1);
}
else if (Command.action == GLFW_RELEASE)
{
// release
vehicle->physics->BrakeReleaser(0);
}
}
}
}
void TTrain::OnCommand_universalbrakebutton1(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// press or hold
// visual feedback
Train->ggUniveralBrakeButton1.UpdateValue(1.0, Train->dsbSwitch);
Train->occupied->UniversalBrakeButton(0, 1);
}
else if (Command.action == GLFW_RELEASE)
{
// release
// visual feedback
Train->ggUniveralBrakeButton1.UpdateValue(0.0, Train->dsbSwitch);
Train->occupied->UniversalBrakeButton(0, 0);
}
}
void TTrain::OnCommand_universalbrakebutton2(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// press or hold
// visual feedback
Train->ggUniveralBrakeButton2.UpdateValue(1.0, Train->dsbSwitch);
Train->occupied->UniversalBrakeButton(1, 1);
}
else if (Command.action == GLFW_RELEASE)
{
// release
// visual feedback
Train->ggUniveralBrakeButton2.UpdateValue(0.0, Train->dsbSwitch);
Train->occupied->UniversalBrakeButton(1, 0);
}
}
void TTrain::OnCommand_universalbrakebutton3(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// press or hold
// visual feedback
Train->ggUniveralBrakeButton3.UpdateValue(1.0, Train->dsbSwitch);
Train->occupied->UniversalBrakeButton(2, 1);
}
else if (Command.action == GLFW_RELEASE)
{
// release
// visual feedback
Train->ggUniveralBrakeButton3.UpdateValue(0.0, Train->dsbSwitch);
Train->occupied->UniversalBrakeButton(2, 0);
}
}
void TTrain::OnCommand_trainbrakeincrease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_REPEAT && Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a)
Train->occupied->BrakeLevelAdd(Global.brake_speed * Command.time_delta * Train->occupied->brakes.config.handlePositions);
else if (Command.action == GLFW_PRESS && Train->occupied->brakes.config.driverValveType != TBrakeHandle::FV4a)
Train->set_train_brake(Train->occupied->brakes.HandlePositionSmooth() + Global.fBrakeStep);
}
void TTrain::OnCommand_trainbrakedecrease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_REPEAT && Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a)
Train->occupied->BrakeLevelAdd(-Global.brake_speed * Command.time_delta * Train->occupied->brakes.config.handlePositions);
else if (Command.action == GLFW_PRESS && Train->occupied->brakes.config.driverValveType != TBrakeHandle::FV4a)
Train->set_train_brake(Train->occupied->brakes.HandlePositionSmooth() - Global.fBrakeStep);
else if (Command.action == GLFW_RELEASE)
{
// release
Train->zero_charging_train_brake();
}
}
void TTrain::OnCommand_trainbrakeset(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
// press or hold
Train->occupied->BrakeLevelSet(std::lerp(Train->occupied->brakes.driverValve->GetPos(bh_MIN), Train->occupied->brakes.driverValve->GetPos(bh_MAX), std::clamp(Command.param1, 0.0, 1.0)));
}
else
{
// release
Train->zero_charging_train_brake();
}
}
void TTrain::OnCommand_trainbrakecharging(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
// press or hold
Train->set_train_brake(-1);
}
else
{
// release
Train->zero_charging_train_brake();
}
}
void TTrain::OnCommand_trainbrakerelease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->set_train_brake(0);
}
}
void TTrain::OnCommand_trainbrakefirstservice(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->set_train_brake(1);
}
}
void TTrain::OnCommand_trainbrakeservice(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->set_train_brake(Train->occupied->brakes.config.handlePositions / 2 + (Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a ? 1 : 0));
}
}
void TTrain::OnCommand_trainbrakefullservice(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->set_train_brake(Train->occupied->brakes.config.handlePositions - 1);
}
}
void TTrain::OnCommand_trainbrakehandleoff(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->set_train_brake(Train->occupied->brakes.driverValve->GetPos(bh_NP));
}
}
void TTrain::OnCommand_trainbrakeemergency(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->set_train_brake(Train->occupied->brakes.driverValve->GetPos(bh_EB));
/*
if( Train->occupied->BrakeCtrlPosNo <= 0.1 ) {
// hamulec bezpieczeństwa dla wagonów
Train->occupied->SetRadioStopFlag(true);
}
*/
}
}
void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
if (Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a)
{
Train->occupied->brakes.SetHandleCapPosition(std::clamp(Train->occupied->brakes.HandleCapPosition() - 0.01, -1.5, 2.0));
}
else
{
Train->occupied->BrakeLevelAdd(0.01);
}
}
}
void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
if (Train->occupied->brakes.config.driverValveType == TBrakeHandle::FV4a)
{
Train->occupied->brakes.SetHandleCapPosition(std::clamp(Train->occupied->brakes.HandleCapPosition() + 0.01, -1.5, 2.0));
}
else
{
Train->occupied->BrakeLevelAdd(-0.01);
}
}
}
void TTrain::OnCommand_trainbrakebasepressurereset(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
Train->occupied->brakes.SetHandleCapPosition(0);
}
}
void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
auto const *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
vehicle->physics->brakes.distributor->SetBrakeStatus(vehicle->physics->brakes.distributor->GetBrakeStatus() ^ b_dmg);
// the brake is the player's now, the wagon inspector won't put it back on its own
vehicle->physics->ClaimBrakeCutOut();
}
}
void TTrain::OnCommand_manualbrakeincrease(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
if (vehicle->physics->brakes.config.localKind == TLocalBrake::ManualBrake || vehicle->physics->brakes.config.hasHandBrake == true)
{
vehicle->physics->IncManualBrakeLevel(1);
}
}
}
void TTrain::OnCommand_manualbrakedecrease(TTrain *Train, command_data const &Command)
{
if (Command.action != GLFW_RELEASE)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
if (vehicle->physics->brakes.config.localKind == TLocalBrake::ManualBrake || vehicle->physics->brakes.config.hasHandBrake == true)
{
vehicle->physics->DecManualBrakeLevel(1);
}
}
}
void TTrain::OnCommand_alarmchaintoggle(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
if (false == Train->occupied->brakes.alarmChain)
{
OnCommand_alarmchainenable(Train, Command);
}
else
{
OnCommand_alarmchaindisable(Train, Command);
}
}
}
void TTrain::OnCommand_alarmchainenable(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// pull
Train->occupied->AlarmChainSwitch(true);
// visual feedback
Train->ggAlarmChain.UpdateValue(1.0);
}
}
void TTrain::OnCommand_alarmchaindisable(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// release
Train->occupied->AlarmChainSwitch(false);
// visual feedback
Train->ggAlarmChain.UpdateValue(0.0);
}
}
void TTrain::OnCommand_wheelspinbrakeactivate(TTrain *Train, command_data const &Command)
{
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
if (Train->ggAntiSlipButton.SubModel == nullptr)
{
if (Command.action == GLFW_PRESS)
{
WriteLog("Wheelspin Brake button is missing, or wasn't defined");
}
return;
}
if (Train->occupied->brakes.config.kind != TBrakeSystem::ElectroPneumatic)
{
// standard behaviour
if (Command.action == GLFW_PRESS)
{
// visual feedback
Train->ggAntiSlipButton.UpdateValue(1.0, Train->dsbSwitch);
// NOTE: system activation is (repeatedly) done in the train update routine
}
else if (Command.action == GLFW_RELEASE)
{
// visual feedback
Train->ggAntiSlipButton.UpdateValue(0.0);
}
}
else
{
// electro-pneumatic, custom case
if (Command.action == GLFW_PRESS)
{
// visual feedback
Train->ggAntiSlipButton.UpdateValue(1.0, Train->dsbPneumaticSwitch);
// the EP fuse is the cab car's (Ctrl+Z switches occupied's), checked by SwitchEPBrake with the rest of
// the control's supply
if (Train->occupied->brakes.config.driverValveType == TBrakeHandle::St113)
{
Train->occupied->SwitchEPBrake(1);
}
}
else if (Command.action == GLFW_RELEASE)
{
// visual feedback
Train->ggAntiSlipButton.UpdateValue(0.0);
Train->occupied->SwitchEPBrake(0);
}
}
}
void TTrain::OnCommand_sandboxactivate(TTrain *Train, command_data const &Command)
{
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
if (Train->ggSandButton.SubModel == nullptr)
{
if (Command.action == GLFW_PRESS)
{
WriteLog("Sandbox activation button is missing, or wasn't defined");
}
return;
}
if (Command.action == GLFW_PRESS)
{
// visual feedback
Train->ggSandButton.UpdateValue(1.0, Train->dsbSwitch);
Train->controlled->SandboxManual(true);
}
else if (Command.action == GLFW_RELEASE)
{
// visual feedback
Train->ggSandButton.UpdateValue(0.0);
Train->controlled->SandboxManual(false);
}
}
void TTrain::OnCommand_autosandboxtoggle(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if (false == Train->occupied->SandDoseAutoAllow)
{
// turn on
OnCommand_autosandboxactivate(Train, Command);
}
else
{
// turn off
OnCommand_autosandboxdeactivate(Train, Command);
}
}
};
void TTrain::OnCommand_autosandboxactivate(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
Train->occupied->SandboxAutoAllow(true);
Train->ggAutoSandButton.UpdateValue(1.0, Train->dsbSwitch);
}
};
void TTrain::OnCommand_autosandboxdeactivate(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
Train->occupied->SandboxAutoAllow(false);
Train->ggAutoSandButton.UpdateValue(0.0, Train->dsbSwitch);
}
};
void TTrain::OnCommand_epbrakecontrolenable(TTrain *Train, command_data const &Command)
{
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
// command only works for bistable switch
if (Command.action == GLFW_PRESS && istoggle)
{
if (Train->occupied->EpFuseSwitch(true))
{
// audio feedback
if (Train->dsbPneumaticSwitch)
{
Train->dsbPneumaticSwitch->play();
}
Train->ggEPFuseButton.UpdateValue(1.0f, Train->dsbSwitch);
}
}
}
void TTrain::OnCommand_epbrakecontroldisable(TTrain *Train, command_data const &Command)
{
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
// command only works for bistable switch
if (Command.action == GLFW_PRESS && istoggle)
{
if (Train->occupied->EpFuseSwitch(false))
{
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
}
}
}
void TTrain::OnCommand_epbrakecontroltoggle(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_REPEAT)
{
return;
}
auto const ispush{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::push)) != 0};
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
if (Command.action == GLFW_PRESS)
{
if (istoggle)
{
// switch state
if (false == Train->occupied->EpFuse())
{
// turn on
// audio feedback
if (Train->occupied->EpFuseSwitch(true) && Train->dsbPneumaticSwitch)
{
Train->dsbPneumaticSwitch->play();
}
}
else
{
// turn off
Train->occupied->EpFuseSwitch(false);
}
}
else if (ispush)
{
// potentially turn on
// audio feedback
if (Train->occupied->EpFuseSwitch(true) && Train->dsbPneumaticSwitch)
{
Train->dsbPneumaticSwitch->play();
}
}
// visual feedback
Train->ggEPFuseButton.UpdateValue(ispush ? 1.0f : // push or pushtoggle
Train->occupied->EpFuse() ? 1.0f :
0.0f, // toggle
Train->dsbSwitch);
}
else if (Command.action == GLFW_RELEASE && ispush)
{
// return the switch to neutral position
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
}
}
void TTrain::OnCommand_trainbrakeoperationmodeincrease(TTrain *Train, command_data const &Command)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if (Command.action == GLFW_PRESS && (Train->occupied->brakes.operatingMode << 1 & Train->occupied->brakes.config.availableOperatingModes) != 0)
{
// next mode
Train->occupied->brakes.operatingMode <<= 1;
// visual feedback
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->occupied->brakes.operatingMode > 0 ? static_cast<float>(std::log2(Train->occupied->brakes.operatingMode)) : 0); // audio fallback
}
}
void TTrain::OnCommand_trainbrakeoperationmodedecrease(TTrain *Train, command_data const &Command)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if (Command.action == GLFW_PRESS && (Train->occupied->brakes.operatingMode >> 1 & Train->occupied->brakes.config.availableOperatingModes) != 0)
{
// previous mode
Train->occupied->brakes.operatingMode >>= 1;
// visual feedback
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->occupied->brakes.operatingMode > 0 ? static_cast<float>(std::log2(Train->occupied->brakes.operatingMode)) : 0);
}
}
void TTrain::OnCommand_brakeactingspeedincrease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
if ((vehicle->physics->brakes.delaySetting & bdelay_M) != 0)
{
// can't speed it up any more than this
return;
}
auto const fasterbrakesetting = vehicle->physics->brakes.delaySetting < bdelay_R ? vehicle->physics->brakes.delaySetting << 1 : vehicle->physics->brakes.delaySetting | bdelay_M;
Train->set_train_brake_speed(vehicle, fasterbrakesetting);
}
}
void TTrain::OnCommand_brakeactingspeeddecrease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
if (vehicle->physics->brakes.delaySetting == bdelay_G)
{
// can't slow it down any more than this
return;
}
auto const slowerbrakesetting = vehicle->physics->brakes.delaySetting < bdelay_M ? vehicle->physics->brakes.delaySetting >> 1 : vehicle->physics->brakes.delaySetting ^ bdelay_M;
Train->set_train_brake_speed(vehicle, slowerbrakesetting);
}
}
void TTrain::OnCommand_brakeactingspeedsetcargo(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
Train->set_train_brake_speed(vehicle, bdelay_G);
}
}
void TTrain::OnCommand_brakeactingspeedsetpassenger(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
Train->set_train_brake_speed(vehicle, bdelay_P);
}
}
void TTrain::OnCommand_brakeactingspeedsetrapid(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle == nullptr)
{
return;
}
Train->set_train_brake_speed(vehicle, bdelay_R);
}
}
void TTrain::OnCommand_brakeloadcompensationincrease(TTrain *Train, command_data const &Command)
{
if (true == Command.freefly && Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle != nullptr)
{
vehicle->physics->IncBrakeMult();
}
}
}
void TTrain::OnCommand_brakeloadcompensationdecrease(TTrain *Train, command_data const &Command)
{
if (true == Command.freefly && Command.action == GLFW_PRESS)
{
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
if (vehicle != nullptr)
{
vehicle->physics->DecBrakeMult();
}
}
}
void TTrain::OnCommand_mubrakingindicatortoggle(TTrain *Train, command_data const &Command)
{
if (Train->ggSignallingButton.SubModel == nullptr)
{
if (Command.action == GLFW_PRESS)
{
WriteLog("Braking Indicator switch is missing, or wasn't defined");
}
return;
}
if (Train->controlled->TrainType() != train_type::emu)
{
//
return;
}
if (Command.action == GLFW_PRESS)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if (false == Train->controlled->Signalling())
{
// turn on
Train->controlled->SetSignalling(true);
// visual feedback
Train->ggSignallingButton.UpdateValue(1.0, Train->dsbSwitch);
}
else
{
// turn off
Train->controlled->SetSignalling(false);
// visual feedback
Train->ggSignallingButton.UpdateValue(0.0, Train->dsbSwitch);
}
}
}