mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 03:37:09 +01:00
12c5bb35e7
The split of Driver.cpp, DynObj.cpp and Train.cpp took five helpers out of their anonymous namespaces. outside() is used in offtrack.cpp alone and goes back into its anonymous namespace. The four shared by the parts of a class go into a namespace of its module: vehicle_ai (brake_response_horizon, uphill_stopping_distance), vehicle_dynamic (seconds_since) and vehicle_cab (is_hold_coil_lever). The rename of mover to physics also hit comments where the word meant something else: "prime mover" and "move the master controller" are back.
1616 lines
62 KiB
C++
1616 lines
62 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 update of the cab in a step of the simulation
|
|
|
|
#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"
|
|
|
|
|
|
bool TTrain::Update(double const Deltatime)
|
|
{
|
|
// train state update
|
|
updateLineBreakerState(Deltatime);
|
|
// the switches of the other vehicles in multiple
|
|
update_remote_linebreakers(Deltatime);
|
|
updateTimers(Deltatime);
|
|
updateDoorAndDirectionStates();
|
|
processReceivedCommands();
|
|
|
|
UpdateCab();
|
|
|
|
returnMasterController(Deltatime);
|
|
updateTachometer(Deltatime);
|
|
updateVoltagesAndCurrents();
|
|
updateUnitStates();
|
|
updateFeedbackGauges();
|
|
updateConverterOverload(Deltatime);
|
|
auto const lowvoltagepower{occupied->lowVoltage.power24vAvailable || occupied->lowVoltage.power110vAvailable};
|
|
|
|
updateSecondUnitGauges();
|
|
updateClock();
|
|
|
|
Cabine[iCabn].Update(lowvoltagepower); // nowy sposób ustawienia animacji
|
|
/*
|
|
if (ggZbS.SubModel)
|
|
{
|
|
ggZbS.UpdateValue(occupied->Handle->GetCP());
|
|
ggZbS.Update();
|
|
}
|
|
*/
|
|
// replacement for the above. TODO: move it to a more suitable place
|
|
m_brakehandlecp = occupied->brakes.driverValve->GetCP();
|
|
|
|
updateEngineGauges();
|
|
updateBasicLamps();
|
|
|
|
if (true == lowvoltagepower)
|
|
{
|
|
updateCircuitLamps(Deltatime);
|
|
updateTrainLamps();
|
|
}
|
|
else
|
|
{
|
|
turnOffLamps();
|
|
}
|
|
|
|
updateSecondUnitLamps(lowvoltagepower);
|
|
updateMasterControllers(lowvoltagepower);
|
|
updateBrakeControllers();
|
|
updateCabSwitches(lowvoltagepower);
|
|
updateHeatingAndInstrumentLights();
|
|
updateButtons();
|
|
updateAuxiliaryButtons(lowvoltagepower);
|
|
|
|
// wyprowadzenie sygnałów dla haslera na PoKeys (zaznaczanie na taśmie)
|
|
btHaslerBrakes.Turn(occupied->brakes.cylinderPressure > 0.4); // ciśnienie w cylindrach
|
|
btHaslerCurrent.Turn(occupied->Im != 0.0); // prąd na silnikach
|
|
|
|
updateCabLightLevels();
|
|
|
|
// anti slip system activation, maintained while the control button is down
|
|
if (occupied->brakes.kind != TBrakeSystem::ElectroPneumatic && ggAntiSlipButton.GetDesiredValue() > 0.95)
|
|
{
|
|
controlled->AntiSlippingBrake();
|
|
}
|
|
// screens
|
|
|
|
if (!FreeFlyModeFlag && simulation::Train == this) // don't bother if we're outside
|
|
{
|
|
update_screens(Deltatime);
|
|
update_script_screens();
|
|
}
|
|
|
|
// update direction relay
|
|
if (prevBatState != occupied->lowVoltage.power24vAvailable)
|
|
SetupDirectionRelays();
|
|
if (prevDirection != occupied->DirActive)
|
|
UpdateDirectionRelays();
|
|
|
|
prevBatState = occupied->lowVoltage.power24vAvailable;
|
|
prevDirection = occupied->DirActive;
|
|
|
|
// sounds
|
|
update_sounds(Deltatime);
|
|
|
|
return true; //(DynamicObject->Update(dt));
|
|
} // koniec update
|
|
|
|
// keeps the state of the line breaker in step with the vehicle and with the buttons that close and open it
|
|
void TTrain::updateLineBreakerState(double const Deltatime)
|
|
{
|
|
// line breaker:
|
|
if (m_linebreakerstate == linebreaker::state::open && true == controlled->lineBreaker.closed)
|
|
{
|
|
// crude way to sync state of the linebreaker with ai-issued commands
|
|
m_linebreakerstate = linebreaker::state::closed;
|
|
}
|
|
if (m_linebreakerstate == linebreaker::state::closed && false == (controlled->lineBreaker.closed || controlled->diesel.startupRequested))
|
|
{
|
|
// crude way to catch cases where the main was knocked out
|
|
// because the state of the line breaker isn't changed to match, we need to do it here manually
|
|
m_linebreakerstate = linebreaker::state::open;
|
|
}
|
|
if (vehicle_cab::is_hold_coil_lever(ggMainOffButton) && hold_coil_lever::cuts_off(ggMainOffButton.GetDesiredValue()))
|
|
{
|
|
if (true == controlled->lineBreaker.closed)
|
|
{
|
|
// the line breaker was closed with the hold coil lever off, by the AI or through the control cable:
|
|
// put the lever back on to match, like the line breaker state above
|
|
ggMainOffButton.UpdateValue(0.0);
|
|
}
|
|
else if (m_linebreakerstate == linebreaker::state::closing)
|
|
{
|
|
// the hold coil was cut off while the closing button was held, the line breaker won't close on its release
|
|
m_linebreakerstate = linebreaker::state::open;
|
|
}
|
|
}
|
|
|
|
if ((ggMainButton.SubModel != nullptr && ggMainButton.GetDesiredValue() > 0.95) ||
|
|
ggMainOnButton.SubModel != nullptr && ggMainOnButton.GetDesiredValue() > 0.95 ||
|
|
ggIgnitionKey.GetDesiredValue() > 0.95)
|
|
{ // HACK: fallback
|
|
// keep track of period the line breaker button is held down, to determine when/if circuit closes
|
|
if (controlled->MainSwitchCheck())
|
|
{
|
|
fMainRelayTimer += static_cast<float>(Deltatime);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// button isn't down, reset the timer
|
|
fMainRelayTimer = 0.0f;
|
|
}
|
|
if (ggMainOffButton.GetDesiredValue() > 0.95)
|
|
{
|
|
// if the button disconnecting the line breaker is down prevent the timer from accumulating
|
|
fMainRelayTimer = 0.0f;
|
|
}
|
|
if (m_linebreakerstate == linebreaker::state::open && fMainRelayTimer > controlled->InitialCtrlDelay)
|
|
{
|
|
// wlaczanie WSa z opoznieniem
|
|
// mark the line breaker as ready to close; for electric series vehicles with impulse switch the setup is completed on button release
|
|
m_linebreakerstate = linebreaker::state::closing;
|
|
}
|
|
// for diesels and/or vehicles with toggle switch setup we complete the engine start here
|
|
// TODO: make it a test for main_on_bt of type push_delayed instead
|
|
if (m_linebreakerstate == linebreaker::state::closing && (ggMainOnButton.SubModel == nullptr || controlled->EngineType != TEngineType::ElectricSeriesMotor))
|
|
{
|
|
// try to finalize state change of the line breaker, set the state based on the outcome
|
|
m_linebreakerstate = controlled->MainSwitch(true, controlled->MainSwitchRange()) ? linebreaker::state::closed : linebreaker::state::open;
|
|
}
|
|
}
|
|
|
|
// counts down the door permit, the train length measurement and the battery timers
|
|
void TTrain::updateTimers(double const Deltatime)
|
|
{
|
|
// door permits
|
|
for (auto idx = 0; idx < 2; ++idx)
|
|
{
|
|
auto &doorpermittimer{m_doorpermittimers[idx]};
|
|
if (doorpermittimer < 0.f)
|
|
{
|
|
continue;
|
|
}
|
|
doorpermittimer -= static_cast<float>(Deltatime);
|
|
if (doorpermittimer < 0.f)
|
|
{
|
|
occupied->OperateDoors(static_cast<VehicleSide>(idx), true);
|
|
}
|
|
}
|
|
|
|
// train measurement timer
|
|
if (trainLenghtMeasureTimer >= 0.f)
|
|
{
|
|
trainLenghtMeasureTimer -= static_cast<float>(Deltatime);
|
|
if (trainLenghtMeasureTimer < 0.f)
|
|
trainLenghtMeasureTimer = -1.f;
|
|
}
|
|
|
|
// battery timer
|
|
if (fBatteryTimer >= 0.f)
|
|
{
|
|
fBatteryTimer -= static_cast<float>(Deltatime);
|
|
if (fBatteryTimer < 0.f)
|
|
fBatteryTimer = -1.f;
|
|
}
|
|
}
|
|
|
|
// sets the helper flags of the open doors, the door permits and the direction of travel
|
|
void TTrain::updateDoorAndDirectionStates()
|
|
{
|
|
// helper variables
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
m_doors = DynamicObject->Mechanik->IsAnyDoorOpen[VehicleSide::right] || DynamicObject->Mechanik->IsAnyDoorOpen[VehicleSide::left];
|
|
m_doorpermits = DynamicObject->Mechanik->IsAnyDoorPermitActive[VehicleSide::right] || DynamicObject->Mechanik->IsAnyDoorPermitActive[VehicleSide::left];
|
|
m_doorspermitleft = occupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right].open_permit &&
|
|
(simulation::Time.data().wSecond % 2 < 1 || occupied->DoorsPermitLightBlinking < 1 ||
|
|
occupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right] ||
|
|
(occupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right]));
|
|
m_doorspermitright = occupied->Doors.instances[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left].open_permit &&
|
|
(simulation::Time.data().wSecond % 2 < 1 || occupied->DoorsPermitLightBlinking < 1 ||
|
|
occupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left] ||
|
|
(occupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left]));
|
|
}
|
|
m_dirforward = controlled->DirActive > 0;
|
|
m_dirneutral = controlled->DirActive == 0;
|
|
m_dirbackward = controlled->DirActive < 0;
|
|
}
|
|
|
|
// passes the user commands received by the vehicle to their handlers
|
|
void TTrain::processReceivedCommands()
|
|
{
|
|
// check for received user commands
|
|
// NOTE: this is a temporary arrangement, for the transition period from old command setup to the new one
|
|
// eventually commands are going to be retrieved directly by the vehicle, filtered through active control stand
|
|
// and ultimately executed, provided the stand allows it.
|
|
command_data commanddata;
|
|
while (simulation::Commands.pop(commanddata, static_cast<std::size_t>(command_target::vehicle) | id()))
|
|
{
|
|
simulation::Blackbox.command(DynamicObject, commanddata.command, commanddata.action, commanddata.param1, commanddata.param2);
|
|
|
|
auto lookup = m_commandhandlers.find(commanddata.command);
|
|
if (lookup != m_commandhandlers.end())
|
|
{
|
|
// debug data
|
|
if (commanddata.action == GLFW_PRESS)
|
|
{
|
|
WriteLog(occupied->Name + " received command: [" + simulation::Commands_descriptions[static_cast<std::size_t>(commanddata.command)].name + "]");
|
|
}
|
|
// pass the command to the assigned handler
|
|
lookup->second(this, commanddata);
|
|
}
|
|
}
|
|
}
|
|
|
|
// moves the master controller a step towards the actual position of the switch group when the driver leaves it (ET40, EP05, camshaft)
|
|
void TTrain::returnMasterController(double const Deltatime)
|
|
{
|
|
// nie blokujemy AI
|
|
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag && (occupied->TrainType == train_type::et40 || occupied->TrainType == train_type::ep05 || occupied->HasCamshaft))
|
|
{
|
|
// dla ET40 i EU05 automatyczne cofanie nastawnika - i tak nie będzie to działać dobrze...
|
|
// TODO: use deltatime to stabilize speed
|
|
/*
|
|
if( false == (
|
|
( input::command == user_command::mastercontrollerset )
|
|
|| ( input::command == user_command::mastercontrollerincrease )
|
|
|| ( input::command == user_command::mastercontrollerdecrease ) ) ) {
|
|
*/
|
|
if (false == (m_mastercontrollerinuse || Global.ctrlState))
|
|
{
|
|
m_mastercontrollerreturndelay -= static_cast<float>(Deltatime);
|
|
if (m_mastercontrollerreturndelay < 0.f)
|
|
{
|
|
m_mastercontrollerreturndelay = EU07_CONTROLLER_BASERETURNDELAY;
|
|
if (occupied->MainCtrlPos > occupied->MainCtrlActualPos)
|
|
{
|
|
occupied->DecMainCtrl(1);
|
|
}
|
|
else if (occupied->MainCtrlPos < occupied->MainCtrlActualPos)
|
|
{
|
|
// Ra 15-01: a to nie miało być tylko cofanie?
|
|
occupied->IncMainCtrl(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// sets the speed shown by the tachometer, its jumps and the ticking of the speed recorder
|
|
void TTrain::updateTachometer(double const Deltatime)
|
|
{
|
|
// McZapkie: predkosc wyswietlana na tachometrze brana jest z obrotow kol
|
|
auto const maxtacho{3.0};
|
|
|
|
double maxSpeed = controlled->Vmax * 1.05; // zachowanie starej logiki jak nie ma definicji max tarczki
|
|
if (occupied->maxTachoSpeed != 0)
|
|
{
|
|
maxSpeed = occupied->maxTachoSpeed;
|
|
}
|
|
fTachoVelocity = static_cast<float>(std::min(std::abs(11.31 * controlled->WheelDiameter * controlled->nrot), maxSpeed));
|
|
{ // skacze osobna zmienna
|
|
float ff = simulation::Time.data().wSecond; // skacze co sekunde - pol sekundy
|
|
// pomiar, pol sekundy ustawienie
|
|
if (ff != fTachoTimer) // jesli w tej sekundzie nie zmienial
|
|
{
|
|
if (fTachoVelocity >= 5) // jedzie
|
|
fTachoVelocityJump = static_cast<float>(fTachoVelocity + (2.0 - LocalRandom(3) + LocalRandom(3)) * 0.5);
|
|
else if (fTachoVelocity < 5 && fTachoVelocity > 1)
|
|
fTachoVelocityJump = static_cast<float>(Random(0, 4)); // tu ma sie bujac jak wariat i zatrzymac na jakiejs predkosci
|
|
// fTachoVelocityJump = 0; // stoi
|
|
fTachoTimer = ff; // juz zmienil
|
|
}
|
|
}
|
|
if (fTachoVelocity > 1) // McZapkie-270503: podkrecanie tachometru
|
|
{
|
|
// szybciej zacznij stukac
|
|
fTachoCount = static_cast<float>(std::min(maxtacho, fTachoCount + Deltatime * 3));
|
|
}
|
|
else if (fTachoCount > 0)
|
|
{
|
|
// schodz powoli - niektore haslery to ze 4 sekundy potrafia stukac
|
|
fTachoCount = static_cast<float>(std::max(0.0, fTachoCount - Deltatime * 0.66));
|
|
}
|
|
}
|
|
|
|
// sets the high voltage and the currents shown in the cab, of the controlled vehicle or of the second unit
|
|
void TTrain::updateVoltagesAndCurrents()
|
|
{
|
|
// Ra 2014-09: napięcia i prądy muszą być ustalone najpierw, bo wysyłane są ewentualnie na PoKeys
|
|
if (controlled->EngineType != TEngineType::DieselElectric && controlled->EngineType != TEngineType::ElectricInductionMotor)
|
|
{ // Ra 2014-09: czy taki rozdzia? ma sens?
|
|
fHVoltage = static_cast<float>(std::max(controlled->pantographCircuit.supplyVoltage,
|
|
controlled->GetTrainsetHighVoltage())); // Winger czy to nie jest zle?
|
|
}
|
|
// *controlled->Mains);
|
|
else
|
|
{
|
|
fHVoltage = static_cast<float>(controlled->EngineVoltage);
|
|
}
|
|
if (ShowNextCurrent)
|
|
{ // jeśli pokazywać drugi człon
|
|
if (secondUnit)
|
|
{ // o ile jest ten drugi
|
|
fHCurrent[0] = static_cast<float>(secondUnit->ShowCurrent(0) * 1.05);
|
|
fHCurrent[1] = static_cast<float>(secondUnit->ShowCurrent(1) * 1.05);
|
|
fHCurrent[2] = static_cast<float>(secondUnit->ShowCurrent(2) * 1.05);
|
|
fHCurrent[3] = static_cast<float>(secondUnit->ShowCurrent(3) * 1.05);
|
|
}
|
|
else
|
|
{
|
|
fHCurrent[0] = 0.0; // gdy nie ma człona
|
|
fHCurrent[1] = 0.0;
|
|
fHCurrent[2] = 0.0;
|
|
fHCurrent[3] = 0.0;
|
|
}
|
|
}
|
|
else
|
|
{ // normalne pokazywanie
|
|
fHCurrent[0] = static_cast<float>(controlled->ShowCurrent(0));
|
|
fHCurrent[1] = static_cast<float>(controlled->ShowCurrent(1));
|
|
fHCurrent[2] = static_cast<float>(controlled->ShowCurrent(2));
|
|
fHCurrent[3] = static_cast<float>(controlled->ShowCurrent(3));
|
|
}
|
|
}
|
|
|
|
// clears the states of the units in multiple before they are read again
|
|
void TTrain::resetUnitStates()
|
|
{
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
bMains[i] = false;
|
|
fCntVol[i] = 0.0f;
|
|
bPants[i][0] = false;
|
|
bPants[i][1] = false;
|
|
bFuse[i] = false;
|
|
bBatt[i] = false;
|
|
bConv[i] = false;
|
|
bComp[i][0] = false;
|
|
bComp[i][1] = false;
|
|
// bComp[i][2] = false;
|
|
// bComp[i][3] = false;
|
|
bHeat[i] = false;
|
|
}
|
|
bCompressors.clear();
|
|
}
|
|
|
|
// reads the states of the vehicles and the units in multiple, from the cab along the control coupling
|
|
void TTrain::updateUnitStates()
|
|
{
|
|
bool kier = DynamicObject->DirectionGet() * occupied->CabOccupied > 0;
|
|
TDynamicObject *p = DynamicObject->GetFirstDynamic(occupied->CabOccupied < 0 ? VehicleEnd::rear : VehicleEnd::front, Coupling::control);
|
|
int in = 0;
|
|
fEIMParams[0][6] = 0;
|
|
iCarNo = 0;
|
|
iPowerNo = 0;
|
|
iUnitNo = 1;
|
|
|
|
resetUnitStates();
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
if (p)
|
|
{
|
|
fPress[i][0] = static_cast<float>(p->physics->brakes.cylinderPressure);
|
|
fPress[i][1] = static_cast<float>(p->physics->brakePipe.pressure);
|
|
fPress[i][2] = static_cast<float>(p->physics->mainPipe.pressure);
|
|
fPress[i][3] = static_cast<float>(p->physics->brakes.controlReservoirPressure);
|
|
fPress[i][4] = static_cast<float>(p->physics->brakes.distributor->GetBRP());
|
|
fPress[i][5] = static_cast<float>((p->physics->TotalMass - p->physics->Mred) * 0.001);
|
|
fPress[i][6] = static_cast<float>(p->physics->brakes.spring.pressure);
|
|
bBrakes[i][0] = p->physics->brakes.spring.isActive;
|
|
bBrakes[i][1] = p->physics->brakes.spring.shutOff;
|
|
bDoors[i][1] = p->physics->Doors.instances[VehicleSide::left].position > 0.f;
|
|
bDoors[i][2] = p->physics->Doors.instances[VehicleSide::right].position > 0.f;
|
|
bDoors[i][3] = p->physics->Doors.instances[VehicleSide::left].step_position > 0.f;
|
|
bDoors[i][4] = p->physics->Doors.instances[VehicleSide::right].step_position > 0.f;
|
|
bDoors[i][0] = bDoors[i][1] || bDoors[i][2];
|
|
iDoorNo[i] = p->iAnimType[ANIM_DOORS];
|
|
iUnits[i] = iUnitNo;
|
|
cCode[i] = p->physics->TypeName[p->physics->TypeName.length() - 1];
|
|
asCarName[i] = p->name();
|
|
if (p->physics->EnginePowerSource.SourceType == TPowerSource::CurrentCollector && iUnitNo <= 8)
|
|
{
|
|
bPants[iUnitNo - 1][VehicleEnd::front] = bPants[iUnitNo - 1][VehicleEnd::front] || p->physics->pantographs[VehicleEnd::front].is_active;
|
|
bPants[iUnitNo - 1][VehicleEnd::rear] = bPants[iUnitNo - 1][VehicleEnd::rear] || p->physics->pantographs[VehicleEnd::rear].is_active;
|
|
}
|
|
// TBD, TODO: clean up compressor data arrangement?
|
|
if (iUnitNo <= 8)
|
|
{
|
|
bComp[iUnitNo - 1][0] = bComp[iUnitNo - 1][0] || p->physics->air.compressor.allow || p->physics->air.compressor.start == start_t::automatic;
|
|
}
|
|
if (p->physics->air.compressor.speed > 0.00001)
|
|
{
|
|
if (iUnitNo <= 8)
|
|
{
|
|
bComp[iUnitNo - 1][1] = bComp[iUnitNo - 1][1] || p->physics->air.compressor.running;
|
|
}
|
|
bCompressors.emplace_back(p->physics->air.compressor.allow || p->physics->air.compressor.start == start_t::automatic, p->physics->air.compressor.running, i);
|
|
}
|
|
bSlip[i] = p->physics->SlippingWheels;
|
|
if (in < 8 && p->physics->inductionMotor.traction.maxPower > 1)
|
|
{
|
|
fEIMParams[1 + in][0] = static_cast<float>(p->physics->inductionMotor.state.maxForce);
|
|
fEIMParams[1 + in][1] = std::max(fEIMParams[1 + in][0], 0.f);
|
|
fEIMParams[1 + in][2] = -std::min(fEIMParams[1 + in][0], 0.f);
|
|
fEIMParams[1 + in][3] = static_cast<float>(p->physics->inductionMotor.state.maxForce / std::max(p->physics->inductionMotor.state.fullForce, 1.));
|
|
fEIMParams[1 + in][4] = std::max(fEIMParams[1 + in][3], 0.f);
|
|
fEIMParams[1 + in][5] = -std::min(fEIMParams[1 + in][3], 0.f);
|
|
fEIMParams[1 + in][6] = static_cast<float>(p->physics->inductionMotor.state.fieldCurrent);
|
|
fEIMParams[1 + in][7] = static_cast<float>(p->physics->inductionMotor.state.voltage);
|
|
fEIMParams[1 + in][8] = static_cast<float>(p->physics->Itot); // p->physics->inductionMotor.state.lineCurrent;
|
|
fEIMParams[1 + in][9] = static_cast<float>(p->physics->EngineVoltage);
|
|
fEIMParams[0][6] += fEIMParams[1 + in][8];
|
|
bMains[in] = p->physics->lineBreaker.closed;
|
|
fCntVol[in] = static_cast<float>(p->physics->lowVoltage.batteryVoltage);
|
|
bFuse[in] = p->physics->FuseFlag;
|
|
bBatt[in] = p->physics->lowVoltage.batteryOn;
|
|
bConv[in] = p->physics->converter.running;
|
|
bHeat[in] = p->physics->trainHeating.on;
|
|
// bComp[in][2] = (p->physics->CompressorAllow || (p->physics->CompressorStart == start_t::automatic));
|
|
// bComp[in][3] = (p->physics->CompressorFlag);
|
|
in++;
|
|
iPowerNo = in;
|
|
}
|
|
if (in < 8 && (p->physics->EngineType == TEngineType::DieselEngine || p->physics->EngineType == TEngineType::DieselElectric))
|
|
{
|
|
fDieselParams[1 + in][0] = static_cast<float>(p->physics->enrot * 60);
|
|
fDieselParams[1 + in][1] = static_cast<float>(p->physics->nrot);
|
|
fDieselParams[1 + in][2] = static_cast<float>(p->physics->RList[p->physics->MainCtrlPos].R);
|
|
fDieselParams[1 + in][3] = static_cast<float>(p->physics->diesel.fill);
|
|
fDieselParams[1 + in][4] = static_cast<float>(p->physics->RList[p->physics->MainCtrlPos].Mn);
|
|
fDieselParams[1 + in][5] = static_cast<float>(p->physics->diesel.clutchPressure);
|
|
fDieselParams[1 + in][6] = p->physics->diesel.heat.Twy;
|
|
fDieselParams[1 + in][7] = p->physics->OilPump.pressure;
|
|
fDieselParams[1 + in][8] = p->physics->diesel.heat.Ts;
|
|
fDieselParams[1 + in][9] = static_cast<float>(p->physics->retarder.fill);
|
|
bMains[in] = p->physics->lineBreaker.closed;
|
|
fCntVol[in] = static_cast<float>(p->physics->lowVoltage.batteryVoltage);
|
|
bFuse[in] = p->physics->FuseFlag;
|
|
bBatt[in] = p->physics->lowVoltage.batteryOn;
|
|
bConv[in] = p->physics->converter.running;
|
|
bHeat[in] = p->physics->trainHeating.on;
|
|
in++;
|
|
iPowerNo = in;
|
|
}
|
|
if ((kier ? p->Next(Coupling::permanent) : p->Prev(Coupling::permanent)) != (kier ? p->Next(Coupling::control) : p->Prev(Coupling::control)))
|
|
iUnitNo++;
|
|
p = kier ? p->Next(Coupling::control) : p->Prev(Coupling::control);
|
|
iCarNo = i + 1;
|
|
}
|
|
else
|
|
{
|
|
fPress[i][0] = 0;
|
|
fPress[i][1] = 0;
|
|
fPress[i][2] = 0;
|
|
fPress[i][3] = 0;
|
|
fPress[i][4] = 0;
|
|
fPress[i][5] = 0;
|
|
fPress[i][6] = 0;
|
|
bDoors[i][0] = false;
|
|
bDoors[i][1] = false;
|
|
bDoors[i][2] = false;
|
|
bDoors[i][3] = false;
|
|
bDoors[i][4] = false;
|
|
bBrakes[i][0] = false;
|
|
bBrakes[i][1] = false;
|
|
bSlip[i] = false;
|
|
iUnits[i] = 0;
|
|
cCode[i] = 0; //'0';
|
|
asCarName[i] = "";
|
|
}
|
|
}
|
|
|
|
completeUnitStates(in);
|
|
}
|
|
|
|
// sets the induction motor values of the whole train and clears the slots of the units after the first in ones
|
|
void TTrain::completeUnitStates(int const in)
|
|
{
|
|
// if (controlled == occupied)
|
|
// fEIMParams[0][3] = controlled->inductionMotor.state.forceDemand; // procent zadany
|
|
// else
|
|
// fEIMParams[0][3] =
|
|
// controlled->inductionMotor.state.forceDemand - occupied->LocalBrakeRatio(); // procent zadany
|
|
fEIMParams[0][3] = static_cast<float>(occupied->eimic_real);
|
|
fEIMParams[0][4] = std::max(fEIMParams[0][3], 0.f);
|
|
fEIMParams[0][5] = -std::min(fEIMParams[0][3], 0.f);
|
|
fEIMParams[0][1] = static_cast<float>(fEIMParams[0][4] * controlled->inductionMotor.state.fullForce);
|
|
fEIMParams[0][2] = static_cast<float>(fEIMParams[0][5] * controlled->inductionMotor.state.fullForce);
|
|
fEIMParams[0][0] = fEIMParams[0][1] - fEIMParams[0][2];
|
|
fEIMParams[0][7] = 0;
|
|
fEIMParams[0][8] = 0;
|
|
fEIMParams[0][9] = 0;
|
|
|
|
for (int i = in; i < 8; i++)
|
|
{
|
|
for (int j = 0; j <= 9; j++)
|
|
{
|
|
fEIMParams[1 + i][j] = 0;
|
|
fDieselParams[1 + i][j] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// sets the gauges of the PoKeys desk from the state of the cab
|
|
void TTrain::updateFeedbackGauges() const
|
|
{
|
|
#ifdef _WIN32
|
|
if (Global.iFeedbackMode == 4)
|
|
{
|
|
// wykonywać tylko gdy wyprowadzone na pulpit
|
|
// Ra: sterowanie miernikiem: zbiornik główny
|
|
Console::ValueSet(0, occupied->air.mainReservoirPressure);
|
|
// Ra: sterowanie miernikiem: przewód główny
|
|
Console::ValueSet(1, occupied->brakePipe.pressure);
|
|
// Ra: sterowanie miernikiem: cylinder hamulcowy
|
|
Console::ValueSet(2, occupied->brakes.cylinderPressure);
|
|
// woltomierz wysokiego napięcia
|
|
Console::ValueSet(3, fHVoltage);
|
|
// Ra: sterowanie miernikiem: drugi amperomierz
|
|
Console::ValueSet(4, fHCurrent[2]);
|
|
// pierwszy amperomierz; dla EZT prąd całkowity
|
|
Console::ValueSet(5, fHCurrent[controlled->TrainType == train_type::emu ? 0 : 1]);
|
|
// Ra: prędkość na pin 43 - wyjście analogowe (to nie jest PWM); skakanie zapewnia mechanika napędu
|
|
Console::ValueSet(6, fTachoVelocity);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// trips the converter overload relay when the compressor starts too soon after the converter, in the vehicles driven by hand
|
|
void TTrain::updateConverterOverload(double const Deltatime)
|
|
{
|
|
//------------------
|
|
// hunter-261211: nadmiarowy przetwornicy i ogrzewania
|
|
// Ra 15-01: to musi stąd wylecieć - zależności nie mogą być w kabinie
|
|
if (controlled->converter.running == true)
|
|
{
|
|
fConverterTimer += static_cast<float>(Deltatime);
|
|
if (controlled->air.compressor.running == true && controlled->air.compressor.supply == physics::CompressorSupply::converterManual && (controlled->EngineType == TEngineType::ElectricSeriesMotor || controlled->TrainType == train_type::emu) &&
|
|
DynamicObject->Controller == Humandriver // hunter-110212: poprawka dla EZT
|
|
&& DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag)
|
|
{ // hunter-091012: poprawka (zmiana warunku z CompressorPower /rozne od 0/ na /rowne 1/)
|
|
if (fConverterTimer < fConverterPrzekaznik)
|
|
{
|
|
controlled->converter.overloaded = true;
|
|
if (controlled->TrainType != train_type::emu)
|
|
controlled->MainSwitch(false, controlled->TrainType == train_type::emu ? range_t::unit : range_t::local);
|
|
}
|
|
else if (fConverterTimer >= fConverterPrzekaznik)
|
|
{
|
|
// changed switch from always true to take into account state of the compressor switch
|
|
controlled->CompressorSwitch(controlled->air.compressor.allow);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
fConverterTimer = 0;
|
|
//------------------
|
|
}
|
|
|
|
// sets the current, the water temperature and the oil pressure gauges of the second unit
|
|
void TTrain::updateSecondUnitGauges()
|
|
{
|
|
// youBy - prad w drugim czlonie: galaz lub calosc
|
|
{
|
|
TDynamicObject const *tmp{nullptr};
|
|
if (DynamicObject->NextConnected() && controlled->Couplers[VehicleEnd::rear].CouplingFlag.HasAll(Coupling::control) && occupied->CabOccupied == 1)
|
|
tmp = DynamicObject->NextConnected();
|
|
if (DynamicObject->PrevConnected() && controlled->Couplers[VehicleEnd::front].CouplingFlag.HasAll(Coupling::control) && occupied->CabOccupied == -1)
|
|
tmp = DynamicObject->PrevConnected();
|
|
if (tmp && tmp->physics->Power > 0)
|
|
{
|
|
if (ggI1B.SubModel)
|
|
{
|
|
ggI1B.UpdateValue(static_cast<float>(tmp->physics->ShowCurrent(1)));
|
|
ggI1B.Update();
|
|
}
|
|
if (ggI2B.SubModel)
|
|
{
|
|
ggI2B.UpdateValue(static_cast<float>(tmp->physics->ShowCurrent(2)));
|
|
ggI2B.Update();
|
|
}
|
|
if (ggI3B.SubModel)
|
|
{
|
|
ggI3B.UpdateValue(static_cast<float>(tmp->physics->ShowCurrent(3)));
|
|
ggI3B.Update();
|
|
}
|
|
if (ggItotalB.SubModel)
|
|
{
|
|
ggItotalB.UpdateValue(static_cast<float>(tmp->physics->ShowCurrent(0)));
|
|
ggItotalB.Update();
|
|
}
|
|
if (ggWater1TempB.SubModel)
|
|
{
|
|
ggWater1TempB.UpdateValue(tmp->physics->diesel.heat.temperatura1);
|
|
ggWater1TempB.Update();
|
|
}
|
|
if (ggOilPressB.SubModel)
|
|
{
|
|
ggOilPressB.UpdateValue(tmp->physics->OilPump.pressure);
|
|
ggOilPressB.Update();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// sets the hands of the cab clock
|
|
void TTrain::updateClock()
|
|
{
|
|
// McZapkie-300302: zegarek
|
|
if (ggClockMInd.SubModel)
|
|
{
|
|
ggClockSInd.UpdateValue(simulation::Time.data().wSecond);
|
|
ggClockSInd.Update();
|
|
ggClockMInd.UpdateValue(simulation::Time.data().wMinute);
|
|
ggClockMInd.Update();
|
|
ggClockHInd.UpdateValue(static_cast<float>(simulation::Time.data().wHour + simulation::Time.data().wMinute / 60.0));
|
|
ggClockHInd.Update();
|
|
}
|
|
}
|
|
|
|
// sets the gauges of the motor and the low voltage, and the gauges and the ignition key of a diesel engine
|
|
void TTrain::updateEngineGauges()
|
|
{
|
|
// youBy - napiecie na silnikach
|
|
if (ggEngineVoltage.SubModel)
|
|
{
|
|
if (controlled->brakes.electrodynamic.on)
|
|
{
|
|
ggEngineVoltage.UpdateValue(static_cast<float>(std::abs(controlled->Im * 5)));
|
|
}
|
|
else
|
|
{
|
|
int x;
|
|
if (controlled->TrainType == train_type::et42 && controlled->Imax == controlled->ImaxHi)
|
|
x = 1;
|
|
else
|
|
x = 2;
|
|
if (controlled->RList[controlled->MainCtrlActualPos].Mn > 0 && std::abs(controlled->Im) > 0)
|
|
{
|
|
ggEngineVoltage.UpdateValue(static_cast<float>(x * (std::abs(controlled->EngineVoltage) - controlled->RList[controlled->MainCtrlActualPos].R * std::abs(controlled->Im)) /
|
|
controlled->RList[controlled->MainCtrlActualPos].Mn));
|
|
}
|
|
else
|
|
{
|
|
ggEngineVoltage.UpdateValue(0);
|
|
}
|
|
}
|
|
ggEngineVoltage.Update();
|
|
}
|
|
|
|
// Winger 140404 - woltomierz NN
|
|
if (ggLVoltage.SubModel)
|
|
{
|
|
// NOTE: since we don't have functional converter object, we're faking it here by simple check whether converter is on
|
|
// TODO: implement object-based circuits and power systems model so we can have this working more properly
|
|
ggLVoltage.UpdateValue(static_cast<float>(std::max(occupied->lowVoltage.power110vAvailable ? occupied->lowVoltage.nominalBatteryVoltage : 0.0, occupied->lowVoltage.power24vAvailable ? occupied->lowVoltage.batteryVoltage : 0.0)));
|
|
ggLVoltage.Update();
|
|
}
|
|
|
|
if (controlled->EngineType == TEngineType::DieselElectric)
|
|
{ // ustawienie zmiennych dla silnika spalinowego
|
|
fEngine[1] = static_cast<float>(controlled->ShowEngineRotation(1));
|
|
fEngine[2] = static_cast<float>(controlled->ShowEngineRotation(2));
|
|
}
|
|
|
|
else if (controlled->EngineType == TEngineType::DieselEngine)
|
|
{ // albo dla innego spalinowego
|
|
fEngine[1] = static_cast<float>(controlled->ShowEngineRotation(1));
|
|
fEngine[2] = static_cast<float>(controlled->ShowEngineRotation(2));
|
|
fEngine[3] = static_cast<float>(controlled->ShowEngineRotation(3));
|
|
if (ggMainGearStatus.SubModel)
|
|
{
|
|
if (controlled->lineBreaker.closed)
|
|
ggMainGearStatus.UpdateValue(static_cast<float>(1.1 - std::abs(controlled->diesel.automaticGearShift)));
|
|
else
|
|
ggMainGearStatus.UpdateValue(0.0);
|
|
ggMainGearStatus.Update();
|
|
}
|
|
if (ggIgnitionKey.SubModel && ggIgnitionKey.GetDesiredValue() == 0.0)
|
|
{
|
|
ggIgnitionKey.UpdateValue(controlled->lineBreaker.closed || controlled->diesel.startupRequested || fMainRelayTimer > 0.f ||
|
|
(ggMainButton.SubModel != nullptr && ggMainButton.GetDesiredValue() > 0.95) ||
|
|
(ggMainOnButton.SubModel != nullptr && ggMainOnButton.GetDesiredValue() > 0.95));
|
|
}
|
|
ggIgnitionKey.Update();
|
|
}
|
|
}
|
|
|
|
// sets the lamps of the wheel slip, the compressors, the dynamic brake permit and the active cab
|
|
void TTrain::updateBasicLamps()
|
|
{
|
|
if (controlled->SlippingWheels)
|
|
{
|
|
// Ra 2014-12: lokomotywy 181/182 dostają SlippingWheels po zahamowaniu powyżej 2.85 bara i buczały
|
|
double veldiff = (DynamicObject->GetVelocity() - fTachoVelocity) / controlled->Vmax;
|
|
// 1% Vmax rezerwy, żeby 181/182 nie buczały po zahamowaniu, ale to proteza
|
|
if (veldiff < -0.01 && std::abs(controlled->Im) > 10.0)
|
|
{
|
|
btLampkaPoslizg.Turn(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btLampkaPoslizg.Turn(false);
|
|
}
|
|
|
|
// Lampka pracujacej sprezacki
|
|
if (controlled->air.compressor.running || occupied->air.compressor.running)
|
|
btCompressors.Turn(true);
|
|
else
|
|
btCompressors.Turn(false);
|
|
|
|
// Lampka zezwolenia na hamowanie ED
|
|
if (controlled->EpFuse)
|
|
btEDenabled.Turn(true);
|
|
else
|
|
btEDenabled.Turn(false);
|
|
|
|
// Lampka aktywowanej kabiny
|
|
if (controlled->CabActive != 0)
|
|
{
|
|
btCabActived.Turn(true);
|
|
}
|
|
else
|
|
{
|
|
btCabActived.Turn(false);
|
|
}
|
|
|
|
if (controlled->lowVoltage.batteryOn && controlled->CabActive != 0)
|
|
btAKLVents.Turn(true);
|
|
else
|
|
btAKLVents.Turn(false);
|
|
}
|
|
|
|
// sets the lamps of the vigilance, the line breaker, the converter, the circuits and the controllers, with the low voltage on
|
|
void TTrain::updateCircuitLamps(double const Deltatime)
|
|
{
|
|
// McZapkie-141102: SHP i czuwak, TODO: sygnalizacja kabinowa
|
|
if (occupied->SecuritySystem.is_vigilance_blinking())
|
|
{
|
|
if (fBlinkTimer > fCzuwakBlink)
|
|
fBlinkTimer = -fCzuwakBlink;
|
|
else
|
|
fBlinkTimer += Deltatime;
|
|
|
|
btLampkaCzuwaka.Turn(fBlinkTimer > 0);
|
|
}
|
|
else
|
|
{
|
|
fBlinkTimer = 0.0;
|
|
btLampkaCzuwaka.Turn(false);
|
|
}
|
|
|
|
btLampkaSHP.Turn(occupied->SecuritySystem.is_cabsignal_blinking());
|
|
btLampkaCzuwakaSHP.Turn(btLampkaSHP.GetValue() || btLampkaCzuwaka.GetValue());
|
|
|
|
btLampkaWylSzybki.Turn(m_linebreakerstate == linebreaker::state::closing || controlled->lineBreaker.closed);
|
|
btLampkaWylSzybkiOff.Turn(m_linebreakerstate != linebreaker::state::closing && !controlled->lineBreaker.closed);
|
|
btLampkaMainBreakerReady.Turn(controlled->lineBreaker.initCountdown <= 0.0 && m_linebreakerstate != linebreaker::state::closing && !controlled->lineBreaker.closed);
|
|
btLampkaMainBreakerBlinkingIfReady.Turn(m_linebreakerstate == linebreaker::state::closing || controlled->lineBreaker.closed || controlled->lineBreaker.initCountdown < 0.0 && simulation::Time.data().wMilliseconds > 500);
|
|
|
|
btLampkaPrzetw.Turn(occupied->lowVoltage.power110vAvailable);
|
|
btLampkaPrzetwOff.Turn(!occupied->lowVoltage.power110vAvailable);
|
|
btLampkaPrzetwAOff.Turn(!controlled->converter.running);
|
|
btLampkaNadmPrzetw.Turn(Dynamic()->Mechanik ? Dynamic()->Mechanik->IsAnyConverterOverloadRelayOpen : controlled->converter.overloaded);
|
|
|
|
btLampkaOpory.Turn(controlled->lineContactors.closed && controlled->ResistorsFlagCheck());
|
|
btLampkaBezoporowa.Turn(controlled->ResistorsFlagCheck() || controlled->MainCtrlActualPos == 0); // do EU04
|
|
btLampkaStyczn.Turn(controlled->LineContactorsLampLit()); // mozna prowadzic rozruch
|
|
btLampkaPrzekRozn.Turn(!controlled->protection.ground && controlled->MainCircuitLampsEnabled()); // relay is off and needs a reset
|
|
btLampkaNadmSil.Turn(controlled->FuseFlagCheck() && controlled->MainCircuitLampsEnabled()); // relay is off and needs a reset
|
|
btLampkaUkrotnienie.Turn(controlled->Couplers[controlled->CabOccupied == 1 ? VehicleEnd::rear : VehicleEnd::front].CouplingFlag.HasAll(Coupling::control));
|
|
btLampkaHamPosp.Turn(TestFlag(occupied->brakes.distributor->GetBrakeStatus(), 1)); // lampka drugiego stopnia hamowania
|
|
// TODO: youBy wyciągnąć flagę wysokiego stopnia
|
|
btLampkaNadmWent.Turn(controlled->RventRot < 5.0 && controlled->ResistorsFlagCheck()); // hunter-121211: lampka zanikowo-pradowego wentylatorow
|
|
btLampkaWysRozr.Turn(controlled->Imax >= controlled->ImaxHi);
|
|
|
|
btLampkaNapNastHam.Turn(controlled->DirActive != 0); // napiecie na nastawniku hamulcowym
|
|
btLampkaSprezarka.Turn(controlled->air.compressor.running); // mutopsitka dziala
|
|
btLampkaSprezarkaOff.Turn(!controlled->air.compressor.running);
|
|
btLampkaFuelPumpOff.Turn(!controlled->FuelPump.is_active);
|
|
btLampkaOilPump.Turn(controlled->OilPump.is_active); // pre-lubrication pump, goes off once the engine is started
|
|
|
|
// boczniki
|
|
// Ra: w SU45 boczniki wchodzą na ScndCtrlPos, a nie na ScndCtrlActualPos
|
|
// - pokićkał ktoś?
|
|
int scp = controlled->RList[controlled->MainCtrlPos].ScndAct;
|
|
scp = scp == 255 ? 0 : scp; // Ra: whatta hella is this?
|
|
btLampkaBoczniki.Turn(!controlled->DelayCtrlFlag && controlled->ScndCtrlActualPos > 0 || scp > 0);
|
|
btLampkaBocznik1.Turn(!controlled->DelayCtrlFlag && controlled->ScndCtrlPos > 0 || controlled->ScndCtrlActualPos > 0 || scp > 0);
|
|
btLampkaBocznik2.Turn(!controlled->DelayCtrlFlag && controlled->ScndCtrlPos > 1 || controlled->ScndCtrlActualPos > 1 || scp > 1);
|
|
btLampkaBocznik3.Turn(!controlled->DelayCtrlFlag && controlled->ScndCtrlPos > 2 || controlled->ScndCtrlActualPos > 2 || scp > 2);
|
|
btLampkaBocznik4.Turn(!controlled->DelayCtrlFlag && controlled->ScndCtrlPos > 3 || controlled->ScndCtrlActualPos > 3 || scp > 3);
|
|
|
|
// biegi dla motoraka
|
|
btLampkaGear1.Turn(controlled->ScndCtrlActualPos == 1 && controlled->diesel.clutchState > 0); // bieg 1
|
|
btLampkaGear2.Turn(controlled->ScndCtrlActualPos == 2 && controlled->diesel.clutchState > 0); // bieg 2
|
|
btLampkaHydroLockup.Turn(controlled->torqueConverter.lockedUp); // zblokowanie skrzyni z silnikiem
|
|
|
|
if (controlled->Signalling == true)
|
|
{
|
|
if (occupied->brakes.cylinderPressure >= 1.45f)
|
|
{
|
|
btLampkaHamowanie1zes.Turn(true);
|
|
}
|
|
if (controlled->brakes.cylinderPressure < 0.75f)
|
|
{
|
|
btLampkaHamowanie1zes.Turn(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btLampkaHamowanie1zes.Turn(false);
|
|
}
|
|
}
|
|
|
|
// sets the lamps of the braking, the radio, the doors, the direction, the lights and the overheating, with the low voltage on
|
|
void TTrain::updateTrainLamps()
|
|
{
|
|
switch (controlled->TrainType)
|
|
{
|
|
// zależnie od typu lokomotywy
|
|
case train_type::emu:
|
|
{
|
|
btLampkaHamienie.Turn(controlled->brakes.cylinderPressure >= 0.2 && controlled->Signalling);
|
|
break;
|
|
}
|
|
case train_type::et41:
|
|
{
|
|
// odhamowanie drugiego członu
|
|
if (secondUnit)
|
|
{
|
|
// bo może komuś przyjść do głowy jeżdżenie jednym członem
|
|
btLampkaHamienie.Turn(secondUnit->brakes.cylinderPressure < 0.4);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
btLampkaHamienie.Turn(occupied->brakes.cylinderPressure >= 0.1 || controlled->brakes.electrodynamic.on);
|
|
btLampkaBrakingOff.Turn(occupied->brakes.cylinderPressure < 0.1 && !controlled->brakes.electrodynamic.on);
|
|
break;
|
|
}
|
|
}
|
|
// KURS90
|
|
btLampkaMaxSila.Turn(abs(controlled->Im) >= 350);
|
|
btLampkaPrzekrMaxSila.Turn(abs(controlled->Im) >= 450);
|
|
btLampkaRadio.Turn(occupied->Radio && occupied->RadioFuse);
|
|
btLampkaRadioMessage.Turn(radio_message_played);
|
|
btLampkaRadioStop.Turn(occupied->Radio && occupied->RadioFuse && occupied->RadioStopFlag);
|
|
btLampkaHamulecReczny.Turn(occupied->brakes.handBrakePosition > 0);
|
|
// NBMX wrzesien 2003 - drzwi oraz sygnał odjazdu
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
btLampkaDoorLeft.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::left : VehicleSide::right]);
|
|
btLampkaDoorRight.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == VehicleEnd::front ? VehicleSide::right : VehicleSide::left]);
|
|
}
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
// with DoorClosureSignal in the definition of the cab's vehicle, the door closure signalling (SOD) of the whole
|
|
// consist: lit with all doors closed and locked, blinking with them closed but released, dark with a door open.
|
|
// without it, the lock of the vehicle's own doors, as before
|
|
btLampkaBlokadaDrzwi.Turn(occupied->door_closure_lamp_lit(DynamicObject->Mechanik->DoorClosure, simulation::Time.data().wSecond % 2 < 1));
|
|
}
|
|
else
|
|
{
|
|
btLampkaBlokadaDrzwi.Turn(occupied->Doors.is_locked);
|
|
}
|
|
btLampkaDoorLockOff.Turn(false == occupied->Doors.lock_enabled);
|
|
btLampkaDepartureSignal.Turn(controlled->DepartureSignal);
|
|
btLampkaNapNastHam.Turn(controlled->DirActive != 0 && occupied->EpFuse); // napiecie na nastawniku hamulcowym
|
|
|
|
// Wylaczanie lampek kierunku gdy jedziemy
|
|
// Feature uruchamiany z fiz z sekcji Ctrl. wpisem HideDirStatusWhenMoving=Yes (domyslnie No)
|
|
if (occupied->HideDirStatusWhenMoving && // Czy ta funkcja jest w ogole wlaczona
|
|
occupied->Vel > occupied->HideDirStatusSpeed) // Uzaleznienie od predkosci
|
|
{
|
|
btLampkaForward.Turn(false);
|
|
btLampkaBackward.Turn(false);
|
|
btLampkaNeutral.Turn(false);
|
|
}
|
|
else
|
|
{
|
|
btLampkaForward.Turn(controlled->DirActive > 0); // jazda do przodu
|
|
btLampkaBackward.Turn(controlled->DirActive < 0); // jazda do tyłu
|
|
btLampkaNeutral.Turn(controlled->DirActive == 0); // kierunek neutral
|
|
}
|
|
|
|
btLampkaED.Turn(controlled->brakes.electrodynamic.on); // hamulec ED
|
|
btLampkaBrakeProfileG.Turn(TestFlag(occupied->brakes.delaySetting, bdelay_G));
|
|
btLampkaBrakeProfileP.Turn(TestFlag(occupied->brakes.delaySetting, bdelay_P));
|
|
btLampkaBrakeProfileR.Turn(TestFlag(occupied->brakes.delaySetting, bdelay_R));
|
|
btLampkaSpringBrakeActive.Turn(occupied->brakes.spring.isActive);
|
|
btLampkaSpringBrakeInactive.Turn(!occupied->brakes.spring.isActive);
|
|
// light indicators
|
|
// NOTE: sides are hardcoded to deal with setups where single cab is equipped with all indicators
|
|
btLampkaUpperLight.Turn((occupied->iLights[VehicleEnd::front] & light::headlight_upper) != 0);
|
|
btLampkaLeftLight.Turn((occupied->iLights[VehicleEnd::front] & light::headlight_left) != 0);
|
|
btLampkaRightLight.Turn((occupied->iLights[VehicleEnd::front] & light::headlight_right) != 0);
|
|
btLampkaLeftEndLight.Turn((occupied->iLights[VehicleEnd::front] & light::redmarker_left) != 0);
|
|
btLampkaRightEndLight.Turn((occupied->iLights[VehicleEnd::front] & light::redmarker_right) != 0);
|
|
btLampkaRearUpperLight.Turn((occupied->iLights[VehicleEnd::rear] & light::headlight_upper) != 0);
|
|
btLampkaRearLeftLight.Turn((occupied->iLights[VehicleEnd::rear] & light::headlight_left) != 0);
|
|
btLampkaRearRightLight.Turn((occupied->iLights[VehicleEnd::rear] & light::headlight_right) != 0);
|
|
btLampkaRearLeftEndLight.Turn((occupied->iLights[VehicleEnd::rear] & light::redmarker_left) != 0);
|
|
btLampkaRearRightEndLight.Turn((occupied->iLights[VehicleEnd::rear] & light::redmarker_right) != 0);
|
|
// others
|
|
btLampkaMalfunction.Turn(controlled->diesel.heat.PA);
|
|
// overheat indicator lamps
|
|
btLampkaOilOverheat.Turn(controlled->diesel.heat.oil.is_hot);
|
|
btLampkaWaterOverheat.Turn(controlled->diesel.heat.water.is_hot);
|
|
btLampkaWaterAuxOverheat.Turn(controlled->diesel.heat.water_aux.is_hot);
|
|
btLampkaEngineOverheat.Turn(controlled->diesel.heat.engine_is_hot);
|
|
btLampkaMotorBlowers.Turn(controlled->MotorBlowers[VehicleEnd::front].is_active && controlled->MotorBlowers[VehicleEnd::rear].is_active);
|
|
btLampkaCoolingFans.Turn(controlled->RventRot > 1.0);
|
|
btLampkaLouvresClosed.Turn(controlled->LouvresClosed());
|
|
btLampkaTempomat.Turn(occupied->SpeedCtrlUnit.IsActive);
|
|
btLampkaDistanceCounter.Turn(m_distancecounter >= 0.f);
|
|
// universal devices state indicators
|
|
for (auto idx = 0; idx < btUniversals.size(); ++idx)
|
|
{
|
|
btUniversals[idx].Turn(ggUniversals[idx].GetValue() > 0.5);
|
|
}
|
|
}
|
|
|
|
// turns off the lamps of the cab when there's no low voltage
|
|
void TTrain::turnOffLamps()
|
|
{
|
|
// wylaczone
|
|
btLampkaCzuwaka.Turn(false);
|
|
btLampkaSHP.Turn(false);
|
|
btLampkaCzuwakaSHP.Turn(false);
|
|
btLampkaWylSzybki.Turn(false);
|
|
btLampkaWylSzybkiOff.Turn(false);
|
|
btLampkaMainBreakerReady.Turn(false);
|
|
btLampkaMainBreakerBlinkingIfReady.Turn(false);
|
|
btLampkaWysRozr.Turn(false);
|
|
btLampkaOpory.Turn(false);
|
|
btLampkaStyczn.Turn(false);
|
|
btLampkaPrzekRozn.Turn(false);
|
|
btLampkaNadmSil.Turn(false);
|
|
btLampkaUkrotnienie.Turn(false);
|
|
btLampkaHamPosp.Turn(false);
|
|
btLampkaBoczniki.Turn(false);
|
|
btLampkaBocznik1.Turn(false);
|
|
btLampkaBocznik2.Turn(false);
|
|
btLampkaBocznik3.Turn(false);
|
|
btLampkaBocznik4.Turn(false);
|
|
btLampkaGear1.Turn(false);
|
|
btLampkaGear2.Turn(false);
|
|
btLampkaHydroLockup.Turn(false);
|
|
btLampkaNapNastHam.Turn(false);
|
|
btLampkaPrzetw.Turn(false);
|
|
btLampkaPrzetwOff.Turn(false);
|
|
btLampkaPrzetwAOff.Turn(false);
|
|
btLampkaNadmPrzetw.Turn(false);
|
|
btLampkaSprezarka.Turn(false);
|
|
btLampkaSprezarkaOff.Turn(false);
|
|
btLampkaFuelPumpOff.Turn(false);
|
|
btLampkaOilPump.Turn(false);
|
|
btLampkaBezoporowa.Turn(false);
|
|
btLampkaHamowanie1zes.Turn(false);
|
|
btLampkaHamienie.Turn(false);
|
|
btLampkaBrakingOff.Turn(false);
|
|
btLampkaBrakeProfileG.Turn(false);
|
|
btLampkaBrakeProfileP.Turn(false);
|
|
btLampkaBrakeProfileR.Turn(false);
|
|
btLampkaSpringBrakeActive.Turn(false);
|
|
btLampkaSpringBrakeInactive.Turn(false);
|
|
// overheat indicator lamps off
|
|
btLampkaOilOverheat.Turn(false);
|
|
btLampkaWaterOverheat.Turn(false);
|
|
btLampkaWaterAuxOverheat.Turn(false);
|
|
btLampkaEngineOverheat.Turn(false);
|
|
btLampkaMaxSila.Turn(false);
|
|
btLampkaPrzekrMaxSila.Turn(false);
|
|
btLampkaRadio.Turn(false);
|
|
btLampkaRadioMessage.Turn(false);
|
|
btLampkaRadioStop.Turn(false);
|
|
btLampkaHamulecReczny.Turn(false);
|
|
btLampkaDoorLeft.Turn(false);
|
|
btLampkaDoorRight.Turn(false);
|
|
btLampkaBlokadaDrzwi.Turn(false);
|
|
btLampkaDoorLockOff.Turn(false);
|
|
btLampkaDepartureSignal.Turn(false);
|
|
btLampkaNapNastHam.Turn(false);
|
|
btLampkaForward.Turn(false);
|
|
btLampkaBackward.Turn(false);
|
|
btLampkaNeutral.Turn(false);
|
|
btLampkaED.Turn(false);
|
|
// light indicators
|
|
btLampkaUpperLight.Turn(false);
|
|
btLampkaLeftLight.Turn(false);
|
|
btLampkaRightLight.Turn(false);
|
|
btLampkaLeftEndLight.Turn(false);
|
|
btLampkaRightEndLight.Turn(false);
|
|
btLampkaRearUpperLight.Turn(false);
|
|
btLampkaRearLeftLight.Turn(false);
|
|
btLampkaRearRightLight.Turn(false);
|
|
btLampkaRearLeftEndLight.Turn(false);
|
|
btLampkaRearRightEndLight.Turn(false);
|
|
// others
|
|
btLampkaMalfunction.Turn(false);
|
|
btLampkaMotorBlowers.Turn(false);
|
|
btLampkaCoolingFans.Turn(false);
|
|
btLampkaLouvresClosed.Turn(false);
|
|
btLampkaTempomat.Turn(false);
|
|
btLampkaDistanceCounter.Turn(false);
|
|
// universal devices state indicators
|
|
for (auto &universal : btUniversals)
|
|
{
|
|
universal.Turn(false);
|
|
}
|
|
}
|
|
|
|
// sets the lamps of the second unit, from the vehicle coupled behind the cab with the control coupling
|
|
void TTrain::updateSecondUnitLamps(bool const lowvoltagepower)
|
|
{
|
|
{ // yB - wskazniki drugiego czlonu
|
|
TDynamicObject const *tmp{nullptr}; //=controlled->secondUnit; //Ra 2014-07: trzeba to jeszcze wyjąć z kabiny...
|
|
// Ra 2014-07: no nie ma potrzeby szukać tego w każdej klatce
|
|
if (controlled->Couplers[1].CouplingFlag.HasAll(Coupling::control) && occupied->CabOccupied > 0)
|
|
tmp = DynamicObject->NextConnected();
|
|
if (controlled->Couplers[0].CouplingFlag.HasAll(Coupling::control) && occupied->CabOccupied < 0)
|
|
tmp = DynamicObject->PrevConnected();
|
|
|
|
if (tmp)
|
|
{
|
|
if (lowvoltagepower)
|
|
{
|
|
|
|
auto const *physics{tmp->physics};
|
|
|
|
btLampkaWylSzybkiB.Turn(physics->lineBreaker.closed);
|
|
btLampkaWylSzybkiBOff.Turn(false == physics->lineBreaker.closed
|
|
/*&& ( physics->MainsInitTimeCountdown <= 0.0 )*/
|
|
/*&& ( fHVoltage != 0.0 )*/);
|
|
|
|
btLampkaOporyB.Turn(physics->ResistorsFlagCheck());
|
|
btLampkaBezoporowaB.Turn(true == physics->ResistorsFlagCheck() || physics->MainCtrlActualPos == 0); // do EU04
|
|
|
|
btLampkaStycznB.Turn(physics->LineContactorsLampLit()); // mozna prowadzic rozruch
|
|
// hunter-271211: sygnalizacja poslizgu w pierwszym pojezdzie, gdy wystapi w drugim
|
|
if (physics->SlippingWheels)
|
|
{
|
|
// Ra 2014-12: lokomotywy 181/182 dostają SlippingWheels po zahamowaniu powyżej 2.85 bara i buczały
|
|
auto const veldiff{(DynamicObject->GetVelocity() - fTachoVelocity) / controlled->Vmax};
|
|
if (veldiff < -0.01)
|
|
{
|
|
// 1% Vmax rezerwy, żeby 181/182 nie buczały po zahamowaniu, ale to proteza
|
|
auto const lightstate{std::abs(physics->Im) > 10.0};
|
|
btLampkaPoslizg.Turn(btLampkaPoslizg.GetValue() || lightstate);
|
|
}
|
|
}
|
|
|
|
btLampkaSprezarkaB.Turn(physics->air.compressor.running); // mutopsitka dziala
|
|
btLampkaSprezarkaBOff.Turn(false == physics->air.compressor.running);
|
|
if (controlled->Signalling == true)
|
|
{
|
|
if (physics->brakes.cylinderPressure >= 1.45f)
|
|
{
|
|
btLampkaHamowanie2zes.Turn(true);
|
|
}
|
|
if (physics->brakes.cylinderPressure < 0.75f)
|
|
{
|
|
btLampkaHamowanie2zes.Turn(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btLampkaHamowanie2zes.Turn(false);
|
|
}
|
|
btLampkaNadmPrzetwB.Turn(physics->converter.overloaded); // nadmiarowy przetwornicy?
|
|
btLampkaPrzetwB.Turn(physics->converter.running); // zalaczenie przetwornicy
|
|
btLampkaPrzetwBOff.Turn(false == physics->converter.running);
|
|
btLampkaHVoltageB.Turn(physics->protection.noVoltage && physics->protection.overvoltage);
|
|
btLampkaMalfunctionB.Turn(physics->diesel.heat.PA);
|
|
// motor fuse indicator turns on if the fuse was blown in any unit under control
|
|
if (physics->lineBreaker.closed)
|
|
{
|
|
btLampkaNadmSil.Turn(btLampkaNadmSil.GetValue() || physics->FuseFlagCheck());
|
|
}
|
|
}
|
|
else // wylaczone
|
|
{
|
|
btLampkaWylSzybkiB.Turn(false);
|
|
btLampkaWylSzybkiBOff.Turn(false);
|
|
btLampkaOporyB.Turn(false);
|
|
btLampkaStycznB.Turn(false);
|
|
btLampkaSprezarkaB.Turn(false);
|
|
btLampkaSprezarkaBOff.Turn(false);
|
|
btLampkaBezoporowaB.Turn(false);
|
|
btLampkaHamowanie2zes.Turn(false);
|
|
btLampkaNadmPrzetwB.Turn(false);
|
|
btLampkaPrzetwB.Turn(false);
|
|
btLampkaPrzetwBOff.Turn(false);
|
|
btLampkaHVoltageB.Turn(false);
|
|
btLampkaMalfunctionB.Turn(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// sets the master and the secondary controllers, the speed control buttons and the reverser
|
|
void TTrain::updateMasterControllers(bool const lowvoltagepower)
|
|
{
|
|
// McZapkie-080602: obroty (albo translacje) regulatorow
|
|
if (ggJointCtrl.SubModel != nullptr)
|
|
{
|
|
// joint master controller moves forward to adjust power and backward to adjust brakes
|
|
auto const brakerangemultiplier{/* NOTE: scaling disabled as it was conflicting with associating sounds with control positions
|
|
( controlled->CoupledCtrl ?
|
|
controlled->MainCtrlPosNo + controlled->ScndCtrlPosNo :
|
|
controlled->MainCtrlPosNo )
|
|
/ static_cast<double>(LocalBrakePosNo)
|
|
*/
|
|
1};
|
|
// when SplitEDPneumaticBrake is active the negative range of the joint controller
|
|
// represents the dedicated dynamic-brake lever (DBPN steps), not the pneumatic local brake
|
|
auto const negativePart{controlled->brakes.electrodynamic.splitFromPneumatic ?
|
|
(controlled->brakes.electrodynamic.controllerPosition > 0.0 ? controlled->brakes.electrodynamic.controllerPosition * controlled->brakes.electrodynamic.controllerPositions * -1 * brakerangemultiplier : 0.0) :
|
|
occupied->brakes.independentPosition > 0.0 ? occupied->brakes.independentPosition * LocalBrakePosNo * -1 * brakerangemultiplier :
|
|
0.0};
|
|
ggJointCtrl.UpdateValue(negativePart < 0.0 ? static_cast<float>(negativePart) :
|
|
controlled->CoupledCtrl ? static_cast<float>(double(controlled->MainCtrlPos + controlled->ScndCtrlPos)) :
|
|
static_cast<float>(double(controlled->MainCtrlPos)),
|
|
dsbNastawnikJazdy);
|
|
ggJointCtrl.Update();
|
|
}
|
|
if (ggMainCtrl.SubModel != nullptr)
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag // nie blokujemy AI
|
|
&& Global.iFeedbackMode == 4 && Global.fCalibrateIn[2][1] != 0.0)
|
|
{
|
|
|
|
set_master_controller(Console::AnalogCalibrateGet(2) * occupied->MainCtrlPosNo);
|
|
occupied->eimic_analog = Console::AnalogCalibrateGet(2);
|
|
}
|
|
#endif
|
|
|
|
if (controlled->CoupledCtrl)
|
|
{
|
|
ggMainCtrl.UpdateValue(static_cast<float>(double(controlled->MainCtrlPos + controlled->ScndCtrlPos)), dsbNastawnikJazdy);
|
|
}
|
|
else
|
|
{
|
|
ggMainCtrl.UpdateValue(static_cast<float>(double(controlled->MainCtrlPos)), dsbNastawnikJazdy);
|
|
}
|
|
ggMainCtrl.Update();
|
|
}
|
|
if (ggMainCtrlAct.SubModel != nullptr)
|
|
{
|
|
ggMainCtrlAct.UpdateValue(main_ctrl_act::position(*controlled, ggMainCtrlAct.has_scaletable()));
|
|
ggMainCtrlAct.Update();
|
|
}
|
|
if (ggScndCtrl.SubModel != nullptr)
|
|
{
|
|
// Ra: od byte odejmowane boolean i konwertowane potem na double?
|
|
if (false == ggScndCtrl.is_push())
|
|
{
|
|
ggScndCtrl.UpdateValue(static_cast<float>(double(controlled->ScndCtrlPos - (controlled->TrainType == train_type::et42 && controlled->brakes.electrodynamic.on))), dsbNastawnikBocz);
|
|
}
|
|
ggScndCtrl.Update();
|
|
}
|
|
if (ggScndCtrlButton.SubModel != nullptr)
|
|
{
|
|
if (ggScndCtrlButton.is_toggle())
|
|
{
|
|
ggScndCtrlButton.UpdateValue(controlled->IsSpeedCtrlEngaged() ? 1.f : 0.f, dsbSwitch);
|
|
}
|
|
ggScndCtrlButton.Update(lowvoltagepower);
|
|
}
|
|
if (ggScndCtrlOffButton.SubModel != nullptr)
|
|
{
|
|
ggScndCtrlOffButton.Update(lowvoltagepower);
|
|
}
|
|
if (ggDistanceCounterButton.SubModel != nullptr)
|
|
{
|
|
ggDistanceCounterButton.Update();
|
|
}
|
|
if (ggDirKey.SubModel != nullptr)
|
|
{
|
|
if (controlled->TrainType != train_type::emu)
|
|
{
|
|
ggDirKey.UpdateValue(static_cast<float>(double(controlled->DirActive)), dsbReverserKey);
|
|
}
|
|
else
|
|
{
|
|
ggDirKey.UpdateValue(static_cast<float>(double(controlled->DirActive) + double(controlled->Imin == controlled->IminHi)), dsbReverserKey);
|
|
}
|
|
ggDirKey.Update();
|
|
}
|
|
}
|
|
|
|
// sets the train brake and the local brake handles, from the PoKeys desk when it drives them
|
|
void TTrain::updateBrakeControllers()
|
|
{
|
|
if (ggBrakeCtrl.SubModel != nullptr)
|
|
{
|
|
#ifdef _WIN32
|
|
if (DynamicObject->Mechanik ? (DynamicObject->Mechanik->AIControllFlag ? false : Global.iFeedbackMode == 4 /*|| (Global.bMWDmasterEnable && Global.bMWDBreakEnable)*/) :
|
|
false && Global.fCalibrateIn[0][1] != 0.0) // nie blokujemy AI
|
|
{ // Ra: nie najlepsze miejsce, ale na początek gdzieś to dać trzeba
|
|
// Firleju: dlatego kasujemy i zastepujemy funkcją w Console
|
|
if (occupied->brakes.driverValveType == TBrakeHandle::FV4a)
|
|
{
|
|
double b = Console::AnalogCalibrateGet(0);
|
|
b = b * 8.0 - 2.0;
|
|
b = safe_clamp(b, -2.0, (double)occupied->brakes.handlePositions); // przycięcie zmiennej do granic
|
|
ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia
|
|
occupied->BrakeLevelSet(b);
|
|
}
|
|
else if (occupied->brakes.driverValveType == TBrakeHandle::FVel6) // może można usunąć ograniczenie do FV4a i FVel6?
|
|
{
|
|
double b = Console::AnalogCalibrateGet(0);
|
|
b = b * 7.0 - 1.0;
|
|
b = safe_clamp(b, -1.0, (double)occupied->brakes.handlePositions); // przycięcie zmiennej do granic
|
|
ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia
|
|
occupied->BrakeLevelSet(b);
|
|
}
|
|
else
|
|
{
|
|
double b = Console::AnalogCalibrateGet(0);
|
|
b = b * (occupied->brakes.driverValve->GetPos(bh_MAX) - occupied->brakes.driverValve->GetPos(bh_MIN)) + occupied->brakes.driverValve->GetPos(bh_MIN);
|
|
b = safe_clamp(b, occupied->brakes.driverValve->GetPos(bh_MIN), occupied->brakes.driverValve->GetPos(bh_MAX)); // przycięcie zmiennej do granic
|
|
ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia
|
|
occupied->BrakeLevelSet(b);
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
// else //standardowa prodedura z kranem powiązanym z klawiaturą
|
|
// ggBrakeCtrl.UpdateValue(double(occupied->BrakeCtrlPos));
|
|
ggBrakeCtrl.UpdateValue(static_cast<float>(occupied->brakes.handlePositionSmooth));
|
|
ggBrakeCtrl.Update();
|
|
}
|
|
}
|
|
|
|
if (ggLocalBrake.SubModel != nullptr)
|
|
{
|
|
#ifdef _WIN32
|
|
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag // nie blokujemy AI
|
|
&& occupied->brakes.independentValveType == TBrakeHandle::FD1 && Global.iFeedbackMode == 4 && Global.fCalibrateIn[0][1] != 0.0)
|
|
{
|
|
// Ra: nie najlepsze miejsce, ale na początek gdzieś to dać trzeba
|
|
// Firleju: dlatego kasujemy i zastepujemy funkcją w Console
|
|
auto const b = std::clamp(Console::AnalogCalibrateGet(1), 0.f, 1.f);
|
|
occupied->brakes.independentPosition = b;
|
|
ggLocalBrake.UpdateValue(b * LocalBrakePosNo);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
// standardowa prodedura z kranem powiązanym z klawiaturą
|
|
ggLocalBrake.UpdateValue(static_cast<float>(occupied->brakes.independentPosition * LocalBrakePosNo));
|
|
}
|
|
ggLocalBrake.Update();
|
|
}
|
|
}
|
|
|
|
// updates the direction, the brake setting, the door and the compressor switches and buttons
|
|
void TTrain::updateCabSwitches(bool const lowvoltagepower)
|
|
{
|
|
ggDirForwardButton.Update(lowvoltagepower);
|
|
ggDirNeutralButton.Update(lowvoltagepower);
|
|
ggDirBackwardButton.Update(lowvoltagepower);
|
|
ggAlarmChain.Update();
|
|
ggBrakeProfileCtrl.Update();
|
|
ggBrakeProfileG.Update();
|
|
ggBrakeProfileR.Update();
|
|
ggBrakeOperationModeCtrl.Update();
|
|
ggWiperSw.Update();
|
|
ggMaxCurrentCtrl.UpdateValue(true == controlled->ShuntModeAllow ? (true == controlled->ShuntMode ? 1.f : 0.f) : controlled->MotorOverloadRelayHighThreshold ? 1.f : 0.f);
|
|
ggMaxCurrentCtrl.Update();
|
|
ggAutoRelayButton.UpdateValue(occupied->AutoRelayFlag ? 1.f : 0.f);
|
|
ggAutoRelayButton.Update();
|
|
// NBMX wrzesien 2003 - drzwi
|
|
ggDoorLeftPermitButton.Update(lowvoltagepower);
|
|
ggDoorRightPermitButton.Update(lowvoltagepower);
|
|
ggDoorPermitPresetButton.Update(lowvoltagepower);
|
|
ggDoorLeftButton.Update(lowvoltagepower);
|
|
ggDoorRightButton.Update(lowvoltagepower);
|
|
ggDoorLeftOnButton.Update(lowvoltagepower);
|
|
ggDoorRightOnButton.Update(lowvoltagepower);
|
|
ggDoorLeftOffButton.Update(lowvoltagepower);
|
|
ggDoorRightOffButton.Update(lowvoltagepower);
|
|
ggDoorAllOnButton.Update(lowvoltagepower);
|
|
ggDoorAllOffButton.Update(lowvoltagepower);
|
|
ggDoorSignallingButton.Update(lowvoltagepower);
|
|
ggDoorStepButton.Update(lowvoltagepower);
|
|
// NBMX dzwignia sprezarki
|
|
ggCompressorButton.Update();
|
|
ggCompressorLocalButton.Update();
|
|
ggCompressorListButton.Update();
|
|
}
|
|
|
|
// sets the train heating lamp and the instrument, the dashboard and the timetable lights
|
|
void TTrain::updateHeatingAndInstrumentLights()
|
|
{
|
|
//---------
|
|
// hunter-080812: poprawka na ogrzewanie w elektrykach - usuniete uzaleznienie od przetwornicy
|
|
if (controlled->trainHeating.on == true && controlled->converter.overloaded == false)
|
|
btLampkaOgrzewanieSkladu.Turn(true);
|
|
else
|
|
btLampkaOgrzewanieSkladu.Turn(false);
|
|
|
|
//----------
|
|
|
|
// lights
|
|
auto const lightpower{(InstrumentLightType == 0 ? occupied->lowVoltage.power24vAvailable || occupied->lowVoltage.power110vAvailable :
|
|
InstrumentLightType == 1 ? controlled->lineBreaker.closed :
|
|
InstrumentLightType == 2 ? occupied->lowVoltage.power110vAvailable :
|
|
InstrumentLightType == 3 ? occupied->lowVoltage.power24vAvailable || occupied->lowVoltage.power110vAvailable :
|
|
InstrumentLightType == 4 ? occupied->lowVoltage.power24vAvailable || occupied->lowVoltage.power110vAvailable :
|
|
false)};
|
|
InstrumentLightActive = InstrumentLightType == 3 ? true : // TODO: link the light state with the state of the master key
|
|
InstrumentLightType == 4 ? occupied->iLights[VehicleEnd::front] != 0 || occupied->iLights[VehicleEnd::rear] != 0 :
|
|
InstrumentLightActive;
|
|
btInstrumentLight.Turn(InstrumentLightActive && lightpower);
|
|
btDashboardLight.Turn(DashboardLightActive && lightpower);
|
|
btTimetableLight.Turn(TimetableLightActive && lightpower);
|
|
}
|
|
|
|
// updates the buttons of the line breaker, the brakes, the radio, the pantographs and the lights
|
|
void TTrain::updateButtons()
|
|
{
|
|
// guziki:
|
|
ggMainOffButton.Update();
|
|
ggMainOnButton.Update();
|
|
ggMainButton.Update();
|
|
for (auto &remotelinebreaker : m_remotelinebreakers)
|
|
{
|
|
remotelinebreaker.main_switch.Update();
|
|
remotelinebreaker.on_button.Update();
|
|
remotelinebreaker.off_button.Update();
|
|
}
|
|
ggSecurityResetButton.Update();
|
|
ggSHPResetButton.Update();
|
|
ggReleaserButton.Update();
|
|
ggSpringBrakeOnButton.Update();
|
|
ggSpringBrakeOffButton.Update();
|
|
ggUniveralBrakeButton1.Update();
|
|
ggUniveralBrakeButton2.Update();
|
|
ggUniveralBrakeButton3.Update();
|
|
ggEPFuseButton.Update();
|
|
ggAntiSlipButton.Update();
|
|
ggSandButton.Update();
|
|
ggAutoSandButton.Update();
|
|
ggFuseButton.Update();
|
|
ggConverterFuseButton.Update();
|
|
ggStLinOffButton.Update();
|
|
ggRadioChannelSelector.Update();
|
|
ggRadioChannelPrevious.Update();
|
|
ggRadioChannelNext.Update();
|
|
ggRadioStop.Update();
|
|
ggRadioTest.Update();
|
|
ggRadioCall1.Update();
|
|
ggRadioCall3.Update();
|
|
ggRadioVolumeSelector.Update();
|
|
ggRadioVolumePrevious.Update();
|
|
ggRadioVolumeNext.Update();
|
|
ggRadioOnButton.Update();
|
|
ggRadioOffButton.Update();
|
|
ggRadioFuseOnButton.Update();
|
|
ggRadioFuseOffButton.Update();
|
|
ggDepartureSignalButton.Update();
|
|
/*
|
|
ggPantFrontButton.Update();
|
|
ggPantRearButton.Update();
|
|
ggPantFrontButtonOff.Update();
|
|
ggPantRearButtonOff.Update();
|
|
*/
|
|
ggPantAllDownButton.Update();
|
|
ggPantSelectedDownButton.Update();
|
|
ggPantSelectedButton.Update();
|
|
ggPantValvesButton.Update();
|
|
ggPantCompressorButton.Update();
|
|
ggPantCompressorValve.Update();
|
|
|
|
ggPantValvesOff.Update();
|
|
ggPantValvesUpdate.Update();
|
|
|
|
ggLightsButton.Update();
|
|
ggUpperLightButton.Update();
|
|
ggLeftLightButton.Update();
|
|
ggRightLightButton.Update();
|
|
ggLeftEndLightButton.Update();
|
|
ggRightEndLightButton.Update();
|
|
ggModernLightDimSw.Update();
|
|
// hunter-230112
|
|
ggRearUpperLightButton.Update();
|
|
ggRearLeftLightButton.Update();
|
|
ggRearRightLightButton.Update();
|
|
ggRearLeftEndLightButton.Update();
|
|
ggRearRightEndLightButton.Update();
|
|
ggDimHeadlightsButton.Update();
|
|
ggDimHeadlightsButton.Update();
|
|
}
|
|
|
|
// updates the buttons of the converter, the horns, the speed control, the universal devices, the cab and the engine auxiliaries
|
|
void TTrain::updateAuxiliaryButtons(bool const lowvoltagepower)
|
|
{
|
|
//------------
|
|
// the converter switches follow the vehicle when something else flips them (the AI driver, the other cab,
|
|
// the pressure switch of an EMU), not only when the cab is entered (set_cab_controls())
|
|
if (ggConverterButton.SubModel != nullptr && occupied->converter.switchType != "impulse" && occupied->converter.start == start_t::manual)
|
|
{
|
|
ggConverterButton.UpdateValue(occupied->converter.allow ? 1.f : 0.f, dsbSwitch);
|
|
}
|
|
ggConverterButton.Update();
|
|
if (ggConverterLocalButton.SubModel != nullptr)
|
|
{
|
|
ggConverterLocalButton.UpdateValue(occupied->converter.allowLocal ? 1.f : 0.f, dsbSwitch);
|
|
}
|
|
ggConverterLocalButton.Update();
|
|
ggConverterOffButton.Update();
|
|
ggTrainHeatingButton.Update();
|
|
ggSignallingButton.Update();
|
|
ggNextCurrentButton.Update();
|
|
ggHornButton.Update();
|
|
ggHornLowButton.Update();
|
|
ggHornHighButton.Update();
|
|
ggWhistleButton.Update();
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
ggHelperButton.UpdateValue(static_cast<float>(DynamicObject->Mechanik->HelperState));
|
|
}
|
|
ggHelperButton.Update();
|
|
|
|
ggSpeedControlIncreaseButton.Update(lowvoltagepower);
|
|
ggSpeedControlDecreaseButton.Update(lowvoltagepower);
|
|
ggSpeedControlPowerIncreaseButton.Update(lowvoltagepower);
|
|
ggSpeedControlPowerDecreaseButton.Update(lowvoltagepower);
|
|
for (auto &speedctrlbutton : ggSpeedCtrlButtons)
|
|
{
|
|
speedctrlbutton.Update(lowvoltagepower);
|
|
}
|
|
for (auto &universal : ggUniversals)
|
|
{
|
|
universal.Update();
|
|
}
|
|
for (auto &item : ggInverterEnableButtons)
|
|
{
|
|
item.Update();
|
|
}
|
|
for (auto &item : ggInverterDisableButtons)
|
|
{
|
|
item.Update();
|
|
}
|
|
for (auto &item : ggInverterToggleButtons)
|
|
{
|
|
item.Update();
|
|
}
|
|
for (auto &relayresetbutton : ggRelayResetButtons)
|
|
{
|
|
relayresetbutton.Update();
|
|
}
|
|
// hunter-091012
|
|
ggInstrumentLightButton.Update();
|
|
ggDashboardLightButton.Update();
|
|
ggTimetableLightButton.Update();
|
|
ggCabLightDimButton.Update();
|
|
ggCompartmentLightsButton.Update();
|
|
ggCompartmentLightsOnButton.Update();
|
|
ggCompartmentLightsOffButton.Update();
|
|
ggBatteryButton.Update();
|
|
ggBatteryOnButton.Update();
|
|
ggBatteryOffButton.Update();
|
|
if (ggCabActivationButton.SubModel != nullptr && ggCabActivationButton.type() != TGaugeType::push)
|
|
{
|
|
ggCabActivationButton.UpdateValue(occupied->IsCabMaster() ? 1.0 : 0.0);
|
|
}
|
|
ggCabActivationButton.Update();
|
|
|
|
ggWaterPumpBreakerButton.Update();
|
|
ggWaterPumpButton.Update();
|
|
ggWaterHeaterBreakerButton.Update();
|
|
ggWaterHeaterButton.Update();
|
|
ggWaterCircuitsLinkButton.Update();
|
|
ggFuelPumpButton.Update();
|
|
ggOilPumpButton.Update();
|
|
ggOilFuelPumpButton.Update();
|
|
ggTractionModeSwitch.Update();
|
|
ggGensetButton.Update();
|
|
ggMotorBlowersFrontButton.Update();
|
|
ggMotorBlowersRearButton.Update();
|
|
ggMotorBlowersAllOffButton.Update();
|
|
}
|
|
|
|
// sets the light level of each cab and of the interior of the vehicle
|
|
void TTrain::updateCabLightLevels()
|
|
{
|
|
// calculate current level of interior illumination
|
|
{
|
|
// TODO: organize it along with rest of train update in a more sensible arrangement
|
|
// Ra: uzeleżnic od napięcia w obwodzie sterowania
|
|
// hunter-091012: uzaleznienie jasnosci od przetwornicy
|
|
int cabidx{0};
|
|
for (auto &cab : Cabine)
|
|
{
|
|
|
|
auto const cablightlevel = (cab.bLight == false ? 0.f : cab.bLightDim == true ? 0.4f : 1.f) * (occupied->lowVoltage.power110vAvailable ? 1.f : 0.5f);
|
|
|
|
if (cab.LightLevel != cablightlevel)
|
|
{
|
|
cab.LightLevel = cablightlevel;
|
|
DynamicObject->set_cab_lights(cabidx, cab.LightLevel);
|
|
}
|
|
if (cabidx == iCabn)
|
|
{
|
|
DynamicObject->InteriorLightLevel = cablightlevel;
|
|
}
|
|
|
|
++cabidx;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::UpdateDirectionRelays()
|
|
{
|
|
if (occupied->DirActive < 0 && occupied->lowVoltage.power24vAvailable) // wstecz
|
|
Dynamic()->sDirectionRelayR.play();
|
|
if (occupied->DirActive == 0 && occupied->lowVoltage.power24vAvailable) // neutral
|
|
Dynamic()->sDirectionRelayN.play();
|
|
if (occupied->DirActive > 0 && occupied->lowVoltage.power24vAvailable) // przod
|
|
Dynamic()->sDirectionRelayD.play();
|
|
}
|
|
|
|
void TTrain::SetupDirectionRelays()
|
|
{
|
|
if (occupied->lowVoltage.power24vAvailable)
|
|
{
|
|
if (occupied->DirActive < 0 && occupied->lowVoltage.power24vAvailable) // wstecz
|
|
Dynamic()->sDirectionRelayR.play();
|
|
if (occupied->DirActive > 0 && occupied->lowVoltage.power24vAvailable) // przod
|
|
Dynamic()->sDirectionRelayD.play();
|
|
}
|
|
else if (occupied->DirActive != 0) // neutral
|
|
Dynamic()->sDirectionRelayN.play();
|
|
}
|