18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 21:15:20 +01:00

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.
This commit is contained in:
2026-11-29 12:26:21 +01:00
parent 7387e36df5
commit 84f1aa2515
87 changed files with 798 additions and 769 deletions
+92 -92
View File
@@ -48,7 +48,7 @@ bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
// nie ma sterowania
return false;
}
if (TrainType == train_type::et22 && ScndCtrlPos != 0)
if (TrainType == train_type::et22 && scndCtrlPos != 0)
{
// w ET22 nie da się kręcić nastawnikiem przy włączonym boczniku
return false;
@@ -60,18 +60,18 @@ bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
}
bool OK = false;
if (MainCtrlPos < MainCtrlPosNo)
if (mainCtrlPos < MainCtrlPosNo)
{
OK = IncMainCtrlByEngine(CtrlSpeed);
}
else
{ // MainCtrlPos>=MainCtrlPosNo
{ // mainCtrlPos>=MainCtrlPosNo
if (true == CoupledCtrl)
{
// wspólny wał nastawnika jazdy i bocznikowania
if (ScndCtrlPos < ScndCtrlPosNo)
if (scndCtrlPos < ScndCtrlPosNo)
{ // 3<3 -> false
++ScndCtrlPos;
++scndCtrlPos;
OK = true;
}
else
@@ -85,7 +85,7 @@ bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
{
ScndCtrlResistiveLockCheck(); // e.g. from the last series position on to the resistive parallel ones
SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); //???
SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
SendCtrlToNext(VehicleCommand::secondaryController, scndCtrlPos, CabActive);
}
// hunter-101012: poprawka
@@ -97,7 +97,7 @@ bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
{
if (DelayCtrlFlag)
{
if (lineContactors.TimeSinceSwitch() >= InitialCtrlDelay && MainCtrlPos == 1)
if (lineContactors.TimeSinceSwitch() >= InitialCtrlDelay && mainCtrlPos == 1)
lineContactors.RestartSwitchTimer();
}
else if (lineContactors.TimeSinceSwitch() > CtrlDelay)
@@ -129,21 +129,21 @@ bool physics::Vehicle::IncMainCtrlSeriesMotor(int const CtrlSpeed)
{
return false; // this means ET40 won't react at all to fast acceleration command. should it issue just IncMainCtrl(1) instead?
}
while (RList[MainCtrlPos].R > 0.0 && IncMainCtrl(1))
while (RList[mainCtrlPos].R > 0.0 && IncMainCtrl(1))
{
// all work is done in the loop header
}
OK = false; // shouldn't this be part of the loop above?
// if (TrainType=train_type::et40) then
// while Abs (Im)>IminHi do
// dec(MainCtrlPos);
// dec(mainCtrlPos);
// OK:=false ;
}
else
{ // CtrlSpeed == 1
++MainCtrlPos;
++mainCtrlPos;
OK = true;
if (Imax == ImaxHi && RList[MainCtrlPos].Bn > 1)
if (Imax == ImaxHi && RList[mainCtrlPos].Bn > 1)
{
/* NOTE: disabled, relay configuration was moved to compute_movement_
if( true == MaxCurrentSwitch( false )) {
@@ -153,7 +153,7 @@ bool physics::Vehicle::IncMainCtrlSeriesMotor(int const CtrlSpeed)
*/
if (TrainType == train_type::et42)
{
--MainCtrlPos;
--mainCtrlPos;
OK = false;
}
}
@@ -161,15 +161,15 @@ bool physics::Vehicle::IncMainCtrlSeriesMotor(int const CtrlSpeed)
// if (TrainType == "et40")
// if (Abs(Im) > IminHi)
// {
// MainCtrlPos--; //Blokada nastawnika po przekroczeniu minimalnego pradu
// mainCtrlPos--; //Blokada nastawnika po przekroczeniu minimalnego pradu
// OK = false;
// }
//}
}
if (TrainType == train_type::et42 && true == brakes.electrodynamic.on && MainCtrlPos > 20)
if (TrainType == train_type::et42 && true == brakes.electrodynamic.on && mainCtrlPos > 20)
{
MainCtrlPos = 20;
mainCtrlPos = 20;
OK = false;
}
return OK;
@@ -195,13 +195,13 @@ bool physics::Vehicle::DecMainCtrl(int CtrlSpeed)
else
{
// TBD, TODO: replace with mainctrlpowerpos() check?
if (MainCtrlPos > 0)
if (mainCtrlPos > 0)
{
if (TrainType != train_type::et22 || ScndCtrlPos == 0) // Ra: ET22 blokuje nastawnik przy boczniku
if (TrainType != train_type::et22 || scndCtrlPos == 0) // Ra: ET22 blokuje nastawnik przy boczniku
{
if (CoupledCtrl && ScndCtrlPos > 0)
if (CoupledCtrl && scndCtrlPos > 0)
{
ScndCtrlPos--; // wspolny wal
scndCtrlPos--; // wspolny wal
OK = true;
}
else
@@ -217,7 +217,7 @@ bool physics::Vehicle::DecMainCtrl(int CtrlSpeed)
{
ScndCtrlResistiveLockCheck(); // the shunt drops when the master controller leaves a resistance-free position
/*OK:=*/SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); // hmmmm...???!!!
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, scndCtrlPos, CabActive);
}
}
// if OK then LastRelayTime:=0;
@@ -245,23 +245,23 @@ bool physics::Vehicle::DecMainCtrlByEngine(int const CtrlSpeed)
bool physics::Vehicle::DecMainCtrlSeriesMotor(int const CtrlSpeed)
{
bool OK = false;
if (CtrlSpeed == 1) /*and (ScndCtrlPos=0)*/
if (CtrlSpeed == 1) /*and (scndCtrlPos=0)*/
{
MainCtrlPos--;
// if (MainCtrlPos=0) and (ScndCtrlPos=0) and
mainCtrlPos--;
// if (mainCtrlPos=0) and (scndCtrlPos=0) and
// (TrainType<>train_type::et40)and(TrainType<>train_type::ep05) then
// StLinFlag:=false;
// if (MainCtrlPos=0) and (TrainType<>train_type::et40) and
// if (mainCtrlPos=0) and (TrainType<>train_type::et40) and
// (TrainType<>train_type::ep05) then
// MainCtrlActualPos:=0; //yBARC: co to tutaj robi? ;)
OK = true;
}
else if (CtrlSpeed > 1) /*and (ScndCtrlPos=0)*/
else if (CtrlSpeed > 1) /*and (scndCtrlPos=0)*/
{
OK = true;
if (RList[MainCtrlPos].R == 0) // Q: tu zrobilem = ;]
if (RList[mainCtrlPos].R == 0) // Q: tu zrobilem = ;]
DecMainCtrl(1);
while (RList[MainCtrlPos].R > 0 && DecMainCtrl(1))
while (RList[mainCtrlPos].R > 0 && DecMainCtrl(1))
; // takie chamskie, potem poprawie}
}
return OK;
@@ -276,13 +276,13 @@ bool physics::Vehicle::IsMainCtrlActualNoPowerPos() const
bool physics::Vehicle::IsMainCtrlNoPowerPos() const
{
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
return MainCtrlPos <= MainCtrlNoPowerPos();
return mainCtrlPos <= MainCtrlNoPowerPos();
}
bool physics::Vehicle::IsMainCtrlMaxPowerPos() const
{
// TODO: wrap controller pieces into a class for potential specializations, similar to brake subsystems
return MainCtrlPos == MainCtrlPosNo;
return mainCtrlPos == MainCtrlPosNo;
}
int physics::Vehicle::MainCtrlNoPowerPos() const
@@ -318,7 +318,7 @@ int physics::Vehicle::MainCtrlActualPowerPos() const
int physics::Vehicle::MainCtrlPowerPos() const
{
return MainCtrlPos - MainCtrlNoPowerPos();
return mainCtrlPos - MainCtrlNoPowerPos();
}
int physics::Vehicle::EIMCtrlEmergencyPositions() const
@@ -328,13 +328,13 @@ int physics::Vehicle::EIMCtrlEmergencyPositions() const
bool physics::Vehicle::IsMainCtrlEmergencyPos() const
{
return MainCtrlPos < EIMCtrlEmergencyPositions();
return mainCtrlPos < EIMCtrlEmergencyPositions();
}
int physics::Vehicle::MainCtrlPosForCoupled() const
{
// the emergency brake itself reaches the train through the brake pipe, vented by the vehicle driven from
return std::max(0, MainCtrlPos - EIMCtrlEmergencyPositions());
return std::max(0, mainCtrlPos - EIMCtrlEmergencyPositions());
}
int physics::Vehicle::MainCtrlPosFromCoupled(int const Position) const
@@ -350,15 +350,15 @@ bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
{
bool OK = false;
if (brakes.electrodynamic.on && TrainType == train_type::et42 && CabActive != 0 && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0)
if (brakes.electrodynamic.on && TrainType == train_type::et42 && CabActive != 0 && IsMainCtrlNoPowerPos() && scndCtrlPos == 0)
{
OK = DynamicBrakeSwitch(false);
}
else if (ScndCtrlPosNo > 0 && CabActive != 0 && !(TrainType == train_type::et42 && (Imax == ImaxHi || (brakes.electrodynamic.on && MainCtrlPowerPos() > 0))))
{
// if (RList[MainCtrlPos].R=0) and (MainCtrlPos>0) and (ScndCtrlPos<ScndCtrlPosNo) and
// if (RList[mainCtrlPos].R=0) and (mainCtrlPos>0) and (scndCtrlPos<ScndCtrlPosNo) and
// (not CoupledCtrl) then
if (ScndCtrlPos < ScndCtrlPosNo && !CoupledCtrl && !IsScndCtrlLockedByMainCtrl())
if (scndCtrlPos < ScndCtrlPosNo && !CoupledCtrl && !IsScndCtrlLockedByMainCtrl())
{
// TBD, TODO: refactor this validation as part of relay check routine (currently in tractionforce()
// TBD, TODO: diesel electric engine utilize scndctrlactualpos like the other types?
@@ -371,11 +371,11 @@ bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
{
if (CtrlSpeed == 1)
{
ScndCtrlPos++;
scndCtrlPos++;
}
else if (CtrlSpeed > 1)
{
ScndCtrlPos = ScndCtrlPosNo; // takie chamskie, potem poprawie
scndCtrlPos = ScndCtrlPosNo; // takie chamskie, potem poprawie
}
OK = true;
}
@@ -385,7 +385,7 @@ bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
if (OK)
{
/*OK:=*/SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); //???
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, scndCtrlPos, CabActive);
}
}
else // nie ma sterowania
@@ -395,17 +395,17 @@ bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
if (OK && lineContactors.TimeSinceSwitch() > CtrlDelay)
lineContactors.RestartSwitchTimer();
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1 && MainCtrlPos > 0)
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1 && mainCtrlPos > 0)
{
SpeedCtrlValue = Vel;
if (EIMCtrlType == 0 && (SpeedCtrlAutoTurnOffFlag & 1) == 1)
{
MainCtrlActualPos = MainCtrlPos;
MainCtrlActualPos = mainCtrlPos;
}
SpeedCtrlUnit.IsActive = true;
}
if (OK && SpeedCtrl && ScndCtrlPos == 1 && EngineType == TEngineType::DieselEngine)
if (OK && SpeedCtrl && scndCtrlPos == 1 && EngineType == TEngineType::DieselEngine)
{
// NOTE: round() already adds 0.5, are the ones added here as well correct?
SpeedCtrlValue = static_cast<double>(Round(Vel));
@@ -423,22 +423,22 @@ bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
{
bool OK = false;
if (IsMainCtrlNoPowerPos() && CabActive != 0 && TrainType == train_type::et42 && ScndCtrlPos == 0 && !brakes.electrodynamic.on && CtrlSpeed == 1)
if (IsMainCtrlNoPowerPos() && CabActive != 0 && TrainType == train_type::et42 && scndCtrlPos == 0 && !brakes.electrodynamic.on && CtrlSpeed == 1)
{
// Ra: AI wywołuje z CtrlSpeed=2 albo gdy ScndCtrlPos>0
// Ra: AI wywołuje z CtrlSpeed=2 albo gdy scndCtrlPos>0
OK = DynamicBrakeSwitch(true);
}
else if (ScndCtrlPosNo > 0 && CabActive != 0)
{
if (ScndCtrlPos > 0 && !CoupledCtrl && (EngineType != TEngineType::DieselElectric || !AutoRelayFlag) && !IsScndCtrlLockedByMainCtrl())
if (scndCtrlPos > 0 && !CoupledCtrl && (EngineType != TEngineType::DieselElectric || !AutoRelayFlag) && !IsScndCtrlLockedByMainCtrl())
{
if (CtrlSpeed == 1)
{
ScndCtrlPos--;
scndCtrlPos--;
}
else if (CtrlSpeed > 1)
{
ScndCtrlPos = 0; // takie chamskie, potem poprawie
scndCtrlPos = 0; // takie chamskie, potem poprawie
}
OK = true;
}
@@ -447,7 +447,7 @@ bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
if (OK)
{
/*OK:=*/SendCtrlToNext(VehicleCommand::mainController, MainCtrlPosForCoupled(), CabActive); //???
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, ScndCtrlPos, CabActive);
/*OK:=*/SendCtrlToNext(VehicleCommand::secondaryController, scndCtrlPos, CabActive);
}
}
else
@@ -467,7 +467,7 @@ bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
}
}
if (OK && SpeedCtrl && ScndCtrlPos == 0 && EngineType == TEngineType::DieselEngine)
if (OK && SpeedCtrl && scndCtrlPos == 0 && EngineType == TEngineType::DieselEngine)
{
SpeedCtrlValue = 0;
SpeedCtrlUnit.IsActive = false;
@@ -483,36 +483,36 @@ bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
bool physics::Vehicle::IsScndCtrlLockedByMainCtrl() const
{
// ET21, ET22, EP09: the field shunting engages only on the resistance-free positions of the master controller (eu07/maszyna#402)
return ScndCtrlResistiveLock && (IsMainCtrlNoPowerPos() || RList[MainCtrlPos].R >= 0.01);
return ScndCtrlResistiveLock && (IsMainCtrlNoPowerPos() || RList[mainCtrlPos].R >= 0.01);
}
void physics::Vehicle::ScndCtrlResistiveLockCheck()
{
// the shunt controller, locked in both directions on zero and the resistive positions, would otherwise stay engaged there once the
// master controller is taken back (or set from elsewhere, e.g. by the AI or another vehicle of the consist) with the shunt on
if (ScndCtrlPos > 0 && !CoupledCtrl && IsScndCtrlLockedByMainCtrl())
if (scndCtrlPos > 0 && !CoupledCtrl && IsScndCtrlLockedByMainCtrl())
{
ScndCtrlPos = 0;
scndCtrlPos = 0;
}
}
int physics::Vehicle::GetVirtualScndPos() const
{
if (TrainType == train_type::et42 && brakes.electrodynamic.on && !ScndCtrlPos)
if (TrainType == train_type::et42 && brakes.electrodynamic.on && !scndCtrlPos)
return -1;
return ScndCtrlPos;
return scndCtrlPos;
}
bool physics::Vehicle::IsScndCtrlNoPowerPos() const
{
// TODO: refine the check on account of potential electric series vehicles with speed control
return ScndCtrlPos == 0 || true == SpeedCtrl;
return scndCtrlPos == 0 || true == SpeedCtrl;
}
bool physics::Vehicle::IsScndCtrlMaxPowerPos() const
{
// TODO: refine the check on account of potential electric series vehicles with speed control
return ScndCtrlPos == ScndCtrlPosNo || true == SpeedCtrl;
return scndCtrlPos == ScndCtrlPosNo || true == SpeedCtrl;
}
// *************************************************************************************************
@@ -561,7 +561,7 @@ bool physics::Vehicle::AutoRelayCheck(void)
// sprawdzenie wszystkich warunkow (AutoRelayFlag, AutoSwitch, Im<Imin)
auto const ARFASI2{(false == AutoRelayFlag || (motor_param(ScndCtrlActualPos).AutoSwitch && abs(Im) < Imin))};
auto const ARFASI{
(false == AutoRelayFlag || (RList[MainCtrlActualPos].AutoSwitch && abs(Im) < Imin) || (!RList[MainCtrlActualPos].AutoSwitch && RList[MainCtrlActualPos].Relay < MainCtrlPos))};
(false == AutoRelayFlag || (RList[MainCtrlActualPos].AutoSwitch && abs(Im) < Imin) || (!RList[MainCtrlActualPos].AutoSwitch && RList[MainCtrlActualPos].Relay < mainCtrlPos))};
// brak PSR na tej pozycji działa PSR i prąd poniżej progu
// na tej pozycji nie działa PSR i pozycja walu ponizej
// chodzi w tym wszystkim o to, żeby można było zatrzymać rozruch na
@@ -571,7 +571,7 @@ bool physics::Vehicle::AutoRelayCheck(void)
{
if (lineContactors.IsClosed())
{
if (RList[MainCtrlActualPos].R == 0 && (ScndCtrlActualPos > 0 || ScndCtrlPos > 0) && (!CoupledCtrl || RList[MainCtrlActualPos].Relay == MainCtrlPos))
if (RList[MainCtrlActualPos].R == 0 && (ScndCtrlActualPos > 0 || scndCtrlPos > 0) && (!CoupledCtrl || RList[MainCtrlActualPos].Relay == mainCtrlPos))
{ // zmieniaj scndctrlactualpos
OK = AutoRelayShuntStep(ARFASI2);
}
@@ -596,7 +596,7 @@ bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2)
{
bool OK = false;
// scnd bez samoczynnego rozruchu
if (ScndCtrlActualPos < ScndCtrlPos)
if (ScndCtrlActualPos < scndCtrlPos)
{
if (lineContactors.TimeSinceSwitch() > CtrlDelay && ARFASI2)
{
@@ -605,7 +605,7 @@ bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2)
OK = true;
}
}
else if (ScndCtrlActualPos > ScndCtrlPos)
else if (ScndCtrlActualPos > scndCtrlPos)
{
if (lineContactors.TimeSinceSwitch() > CtrlDownDelay && TrainType != train_type::emu)
{
@@ -629,12 +629,12 @@ bool physics::Vehicle::AutoRelayMainStep(bool const ARFASI)
auto const backwardslimit{DirActive < 0 && TrainType != train_type::pseudodiesel && RList[MainCtrlActualPos + 1].Bn > BackwardsBranchesAllowed};
// main bez samoczynnego rozruchu
if (false == backwardslimit && MainCtrlActualPos < std::size(RList) - 1 // crude guard against running out of current fixed table
&& (RList[MainCtrlActualPos].Relay < MainCtrlPos || (RList[MainCtrlActualPos + 1].Relay == MainCtrlPos && MainCtrlActualPos < RlistSize) ||
&& (RList[MainCtrlActualPos].Relay < mainCtrlPos || (RList[MainCtrlActualPos + 1].Relay == mainCtrlPos && MainCtrlActualPos < RlistSize) ||
(TrainType == train_type::et22 && DelayCtrlFlag)))
{
OK = AutoRelayMainUp(ARFASI);
}
else if (RList[MainCtrlActualPos].Relay > MainCtrlPos)
else if (RList[MainCtrlActualPos].Relay > mainCtrlPos)
{
OK = AutoRelayMainDown();
}
@@ -663,12 +663,12 @@ bool physics::Vehicle::AutoRelayMainUp(bool const ARFASI)
return false;
}
if (RList[MainCtrlPos].R == 0 && MainCtrlPos > 0 && MainCtrlPos != MainCtrlPosNo && FastSerialCircuit == 1)
if (RList[mainCtrlPos].R == 0 && mainCtrlPos > 0 && mainCtrlPos != MainCtrlPosNo && FastSerialCircuit == 1)
{
// szybkie wchodzenie na bezoporowa (303E)
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// MainCtrlActualPos:=mainCtrlPos; //hunter-111012:
++MainCtrlActualPos;
if (MainCtrlPos - MainCtrlActualPos == 1)
if (mainCtrlPos - MainCtrlActualPos == 1)
{
// HACK: ensure we play only single sound of basic relays for entire trasition; return false
// for all but last step despite configuration change, to prevent playback of the basic relay sound
@@ -695,7 +695,7 @@ bool physics::Vehicle::AutoRelayMainNotchUp()
bool OK = false;
// WriteLog("LRT = " + FloatToStr(LastRelayTime) + ", " +
// FloatToStr(CtrlDelay));
if (TrainType == train_type::et22 && MainCtrlPos > 1 && (RList[MainCtrlActualPos].Bn < RList[MainCtrlActualPos + 1].Bn || DelayCtrlFlag))
if (TrainType == train_type::et22 && mainCtrlPos > 1 && (RList[MainCtrlActualPos].Bn < RList[MainCtrlActualPos + 1].Bn || DelayCtrlFlag))
{
// et22 z walem grupowym
if (!DelayCtrlFlag) // najpierw przejscie
@@ -742,10 +742,10 @@ bool physics::Vehicle::AutoRelayMainNotchUp()
bool physics::Vehicle::AutoRelayMainDown()
{
bool OK = false;
if (RList[MainCtrlPos].R == 0 && MainCtrlPos > 0 && !(MainCtrlPos == MainCtrlPosNo) && FastSerialCircuit == 1)
if (RList[mainCtrlPos].R == 0 && mainCtrlPos > 0 && !(mainCtrlPos == MainCtrlPosNo) && FastSerialCircuit == 1)
{
// szybkie wchodzenie na bezoporowa (303E)
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// MainCtrlActualPos:=mainCtrlPos; //hunter-111012:
--MainCtrlActualPos;
OK = true;
if (RList[MainCtrlActualPos].R == 0)
@@ -1036,7 +1036,7 @@ void physics::Vehicle::CheckEIMIC(double dt)
// the controller (EIMCtrlType 0): the position of the main controller, or the analog one, or the brake asked
void physics::Vehicle::EIMICFromController(double const brakeDemand, double const offset, double const multiplier)
{
eimic = brakeDemand > 0.01 ? -brakeDemand : eimic_analog > 0.01 ? eimic_analog : (double)MainCtrlPos / (double)MainCtrlPosNo;
eimic = brakeDemand > 0.01 ? -brakeDemand : eimic_analog > 0.01 ? eimic_analog : (double)mainCtrlPos / (double)MainCtrlPosNo;
if (EIMCtrlAdditionalZeros || EIMCtrlEmergency)
{
if (eimic > 0.001)
@@ -1051,7 +1051,7 @@ void physics::Vehicle::EIMICFromController(double const brakeDemand, double cons
// EIMCtrlType 1: the positions B+ to TMax move the value at a steady pace
void physics::Vehicle::EIMICFromSteps(double dt)
{
switch (MainCtrlPos)
switch (mainCtrlPos)
{
case 0: // B+
eimic -= std::clamp(1.0 + eimic, 0.0, dt * 0.14); // odejmuj do -1
@@ -1077,9 +1077,9 @@ void physics::Vehicle::EIMICFromSteps(double dt)
default:
break;
}
if (MainCtrlPos >= 3 && eimic < 0)
if (mainCtrlPos >= 3 && eimic < 0)
eimic = 0;
if (MainCtrlPos <= 3 && eimic > 0)
if (mainCtrlPos <= 3 && eimic > 0)
eimic = 0;
}
@@ -1092,11 +1092,11 @@ void physics::Vehicle::EIMICFromFourPositions(double dt)
// hamowanie nagle: pelne hamowanie od razu, przewod glowny oproznia UpdatePipePressure()
eimic = -1.0;
}
else if (MainCtrlActualPos != MainCtrlPos || lineContactors.TimeSinceSwitch() > InitialCtrlDelay)
else if (MainCtrlActualPos != mainCtrlPos || lineContactors.TimeSinceSwitch() > InitialCtrlDelay)
{
double delta = MainCtrlActualPos == MainCtrlPos ? dt * CtrlDelay : 0.01;
double delta = MainCtrlActualPos == mainCtrlPos ? dt * CtrlDelay : 0.01;
// the positions below are those of the controller without the emergency brake position
switch (MainCtrlPos - EIMCtrlEmergencyPositions())
switch (mainCtrlPos - EIMCtrlEmergencyPositions())
{
case 0:
case 1:
@@ -1119,12 +1119,12 @@ void physics::Vehicle::EIMICFromFourPositions(double dt)
break;
}
}
if (MainCtrlActualPos == MainCtrlPos)
if (MainCtrlActualPos == mainCtrlPos)
lineContactors.AdvanceSwitchTimer(dt);
else
{
lineContactors.RestartSwitchTimer();
MainCtrlActualPos = MainCtrlPos;
MainCtrlActualPos = mainCtrlPos;
}
}
@@ -1136,23 +1136,23 @@ void physics::Vehicle::EIMICFromUniversalController(double dt, double const brak
UniversalControllerTrainBrake();
}
if (MainCtrlActualPos != MainCtrlPos || lineContactors.TimeSinceSwitch() > InitialCtrlDelay)
if (MainCtrlActualPos != mainCtrlPos || lineContactors.TimeSinceSwitch() > InitialCtrlDelay)
{
auto const &position{UniCtrlList[MainCtrlPos]};
auto const &position{UniCtrlList[mainCtrlPos]};
double ramped{eimic};
ramped -= safe_clamp(-position.SetCtrlVal + ramped, 0.0,
MainCtrlActualPos == MainCtrlPos ? dt * position.SpeedDown : sign(position.SpeedDown) * 0.01); // odejmuj do X
MainCtrlActualPos == mainCtrlPos ? dt * position.SpeedDown : sign(position.SpeedDown) * 0.01); // odejmuj do X
ramped += safe_clamp(position.SetCtrlVal - ramped, 0.0,
MainCtrlActualPos == MainCtrlPos ? dt * position.SpeedUp : sign(position.SpeedUp) * 0.01); // dodawaj do X
MainCtrlActualPos == mainCtrlPos ? dt * position.SpeedUp : sign(position.SpeedUp) * 0.01); // dodawaj do X
ramped = safe_clamp(ramped, position.MinCtrlVal, position.MaxCtrlVal);
eimic = UniCtrlValStep > 0.0 ? stepped_uc_value(eimic, ramped, position, UniCtrlValStep, MainCtrlActualPos != MainCtrlPos, eimic_step_progress) : ramped;
eimic = UniCtrlValStep > 0.0 ? stepped_uc_value(eimic, ramped, position, UniCtrlValStep, MainCtrlActualPos != mainCtrlPos, eimic_step_progress) : ramped;
}
if (MainCtrlActualPos == MainCtrlPos)
if (MainCtrlActualPos == mainCtrlPos)
lineContactors.AdvanceSwitchTimer(dt);
else
{
lineContactors.RestartSwitchTimer();
MainCtrlActualPos = MainCtrlPos;
MainCtrlActualPos = mainCtrlPos;
}
if (brakes.distributor->GetEDBCP() > 0.3 && eimic < 0 && !UniCtrlIntegratedLocalBrakeCtrl) // when braking with pneumatic brake
eimic = 0; // shut off retarder
@@ -1168,7 +1168,7 @@ void physics::Vehicle::EIMICFromUniversalController(double dt, double const brak
// controller, at a brake handle moved alone, to the nearest position of the handle's
void physics::Vehicle::UniversalControllerTrainBrake()
{
if (UniCtrlList[MainCtrlPos].mode != brakes.handlePosition && MainCtrlActualPos == MainCtrlPos) // there was no move of controller, but brake only
if (UniCtrlList[mainCtrlPos].mode != brakes.handlePosition && MainCtrlActualPos == mainCtrlPos) // there was no move of controller, but brake only
{
if (brakes.handlePosition < UniCtrlList[MainCtrlPosNo].mode)
BrakeLevelSet(UniCtrlList[MainCtrlPosNo].mode); // bottom clamping
@@ -1176,14 +1176,14 @@ void physics::Vehicle::UniversalControllerTrainBrake()
BrakeLevelSet(UniCtrlList[0].mode); // top clamping
if (IsCabMaster())
{
while (brakes.handlePosition > UniCtrlList[MainCtrlPos].mode)
while (brakes.handlePosition > UniCtrlList[mainCtrlPos].mode)
DecMainCtrl(1); // find nearest position
while (brakes.handlePosition < UniCtrlList[MainCtrlPos].mode)
while (brakes.handlePosition < UniCtrlList[mainCtrlPos].mode)
IncMainCtrl(1); // find nearest position
}
}
else // controller was moved
BrakeLevelSet(UniCtrlList[MainCtrlPos].mode);
BrakeLevelSet(UniCtrlList[mainCtrlPos].mode);
}
// the local brake of the TRAXX locomotives, by time: released, held or applied, which cuts the drive off
@@ -1245,17 +1245,17 @@ void physics::Vehicle::CheckSpeedCtrl(double dt)
double accfactor = SpeedCtrlUnit.DesiredPower;
if (EIMCtrlType >= 2)
{
if (MainCtrlPos < MainCtrlPosNo - 2)
if (mainCtrlPos < MainCtrlPosNo - 2)
{
SpeedCtrlUnit.Standby = true;
}
if (MainCtrlPos > MainCtrlPosNo - 1)
if (mainCtrlPos > MainCtrlPosNo - 1)
{
SpeedCtrlUnit.Standby = false;
}
if (!SpeedCtrlUnit.BrakeIntervention && (brakes.distributor->GetEDBCP() > 0.4 || brakePipe.Pressure() < brakes.config.pipeHighPressure - 0.2))
SpeedCtrlUnit.Standby = true;
if (EIMCtrlType >= 3 && UniCtrlList[MainCtrlPos].SpeedUp <= 0)
if (EIMCtrlType >= 3 && UniCtrlList[mainCtrlPos].SpeedUp <= 0)
{
accfactor = 0.0;
eimicSpeedCtrl = 0;
@@ -1332,7 +1332,7 @@ void physics::Vehicle::SpeedCtrlRegulator(double dt, double const accfactor)
{
eimicSpeedCtrl = std::min(eimicSpeedCtrl, SpeedCtrlUnit.InitialPower);
}
if (Vel < SpeedCtrlUnit.StartVelocity && MainCtrlPos < MainCtrlPosNo)
if (Vel < SpeedCtrlUnit.StartVelocity && mainCtrlPos < MainCtrlPosNo)
{
eimicSpeedCtrl = 0;
eimic = 0;
@@ -1347,7 +1347,7 @@ bool physics::Vehicle::IsSpeedCtrlSeparate() const
bool physics::Vehicle::IsSpeedCtrlEngaged() const
{
return IsSpeedCtrlSeparate() ? SpeedCtrlUnit.IsActive : ScndCtrlPos > 0;
return IsSpeedCtrlSeparate() ? SpeedCtrlUnit.IsActive : scndCtrlPos > 0;
}
bool physics::Vehicle::SpeedCtrlSwitch(bool const State)