17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-07 02:38:08 +01:00

refactor(sonar): merge collapsible nested if statements (cpp:S1066)

Comments that preceded the inner if are kept above the merged statement.
This commit is contained in:
jerrrrycho
2026-10-10 15:39:11 +02:00
parent 8042953b95
commit 0d886e65ec
17 changed files with 616 additions and 882 deletions

View File

@@ -446,17 +446,13 @@ double TMoverParameters::Current(double n, double U)
if (MotorCurrent > 0)
{
if (FuzzyLogic(abs(n), nmax * 1.1, p_elengproblem))
if (MainSwitch(false))
EventFlag = true; /*zbyt duze obroty - wywalanie wskutek ognia okreznego*/
if (TestFlag(DamageFlag, dtrain_engine))
if (FuzzyLogic(MotorCurrent, (double)ImaxLo / 10.0, p_elengproblem))
if (MainSwitch(false))
EventFlag = true; /*uszkodzony silnik (uplywy)*/
if (FuzzyLogic(abs(Im), Imax * 2, p_elengproblem) || FuzzyLogic(abs(n), nmax * 1.11, p_elengproblem))
/* or FuzzyLogic(Abs(U/Mn),2*NominalVoltage,1)) then */ /*poprawic potem*/
if (SetFlag(DamageFlag, dtrain_engine))
EventFlag = true;
if (FuzzyLogic(abs(n), nmax * 1.1, p_elengproblem) && MainSwitch(false))
EventFlag = true; /*zbyt duze obroty - wywalanie wskutek ognia okreznego*/
if (TestFlag(DamageFlag, dtrain_engine) && FuzzyLogic(MotorCurrent, (double)ImaxLo / 10.0, p_elengproblem) && MainSwitch(false))
EventFlag = true; /*uszkodzony silnik (uplywy)*/
/* or FuzzyLogic(Abs(U/Mn),2*NominalVoltage,1)) then */ /*poprawic potem*/
if ((FuzzyLogic(abs(Im), Imax * 2, p_elengproblem) || FuzzyLogic(abs(n), nmax * 1.11, p_elengproblem)) && SetFlag(DamageFlag, dtrain_engine))
EventFlag = true;
/*! dorobic grzanie oporow rozruchowych i silnika*/
}
@@ -1010,9 +1006,8 @@ void TMoverParameters::UpdateBatteryVoltage(double dt)
sn5 = dt * 0.000001; // bardzo powolny spadek przy wyłączonych bateriach
}
BatteryVoltage -= sn1 + sn2 + sn3 + sn4 + sn5;
if (NominalBatteryVoltage / BatteryVoltage > 1.57)
if (MainSwitch(false) && EngineType != TEngineType::DieselEngine && EngineType != TEngineType::WheelsDriven)
EventFlag = true; // wywalanie szybkiego z powodu zbyt niskiego napiecia
if (NominalBatteryVoltage / BatteryVoltage > 1.57 && MainSwitch(false) && EngineType != TEngineType::DieselEngine && EngineType != TEngineType::WheelsDriven)
EventFlag = true; // wywalanie szybkiego z powodu zbyt niskiego napiecia
if (BatteryVoltage > NominalBatteryVoltage)
BatteryVoltage = NominalBatteryVoltage; // wstrzymanie ładowania pow. 110V
if (BatteryVoltage < 0.01)
@@ -1383,12 +1378,11 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap
if (CategoryFlag == 4)
OffsetTrackV = TotalMass / (Dim.L * Dim.W * 1000.0);
else if (TestFlag(CategoryFlag, 1) && TestFlag(RunningTrack.CategoryFlag, 1))
if (TestFlag(DamageFlag, dtrain_out))
{
OffsetTrackV = -0.2;
OffsetTrackH = Sign(RunningShape.R) * 0.2;
}
else if (TestFlag(CategoryFlag, 1) && TestFlag(RunningTrack.CategoryFlag, 1) && TestFlag(DamageFlag, dtrain_out))
{
OffsetTrackV = -0.2;
OffsetTrackH = Sign(RunningShape.R) * 0.2;
}
// TODO: investigate, seems supplied NewRot is always 0 although the code here suggests some actual values are expected
Loc = NewLoc;
@@ -1554,24 +1548,21 @@ void TMoverParameters::compute_movement_(double const Deltatime)
RunInternalCommand();
// relay settings
if (EngineType == TEngineType::ElectricSeriesMotor)
// adjust motor overload relay threshold
if (EngineType == TEngineType::ElectricSeriesMotor && ImaxHi > ImaxLo)
{
// adjust motor overload relay threshold
if (ImaxHi > ImaxLo)
{
if (MotorOverloadRelayHighThreshold)
{ // set high threshold
if (TrainType != dt_ET42 ? RList[MainCtrlPos].Bn < 2 : MainCtrlPos == 0)
{
Imax = ImaxHi;
}
if (MotorOverloadRelayHighThreshold)
{ // set high threshold
if (TrainType != dt_ET42 ? RList[MainCtrlPos].Bn < 2 : MainCtrlPos == 0)
{
Imax = ImaxHi;
}
else
{ // set low threshold
if (TrainType != dt_ET42 || MainCtrlPos == 0)
{
Imax = ImaxLo;
}
}
else
{ // set low threshold
if (TrainType != dt_ET42 || MainCtrlPos == 0)
{
Imax = ImaxLo;
}
}
}
@@ -1595,20 +1586,14 @@ void TMoverParameters::compute_movement_(double const Deltatime)
}
// automatyczny rozruch
if (EngineType == TEngineType::ElectricSeriesMotor)
if (EngineType == TEngineType::ElectricSeriesMotor && AutoRelayCheck())
{
if (AutoRelayCheck())
{
SetFlag(SoundFlag, sound::relay);
}
SetFlag(SoundFlag, sound::relay);
}
if (EngineType == TEngineType::DieselEngine || EngineType == TEngineType::DieselElectric)
if ((EngineType == TEngineType::DieselEngine || EngineType == TEngineType::DieselElectric) && dizel_Update(Deltatime))
{
if (dizel_Update(Deltatime))
{
SetFlag(SoundFlag, sound::relay);
}
SetFlag(SoundFlag, sound::relay);
}
// TODO: gather and move current calculations to dedicated method
@@ -2009,17 +1994,13 @@ double TMoverParameters::ShowEngineRotation(int VehN) const
return std::abs(enrot);
case 2:
for (b = 0; b <= 1; ++b)
if (TestFlag(Couplers[b].CouplingFlag, coupling::control))
if (Couplers[b].Connected->Power > 0.01)
return fabs(Couplers[b].Connected->enrot);
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01)
return fabs(Couplers[b].Connected->enrot);
break;
case 3: // to nie uwzględnia ewentualnego odwrócenia pojazdu w środku
for (b = 0; b <= 1; ++b)
if (TestFlag(Couplers[b].CouplingFlag, coupling::control))
if (Couplers[b].Connected->Power > 0.01)
if (TestFlag(Couplers[b].Connected->Couplers[b].CouplingFlag, coupling::control))
if (Couplers[b].Connected->Couplers[b].Connected->Power > 0.01)
return fabs(Couplers[b].Connected->Couplers[b].Connected->enrot);
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01 && TestFlag(Couplers[b].Connected->Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Couplers[b].Connected->Power > 0.01)
return fabs(Couplers[b].Connected->Couplers[b].Connected->enrot);
break;
}
return 0.0;
@@ -2454,21 +2435,18 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
{ // CtrlSpeed == 1
++MainCtrlPos;
OK = true;
if (Imax == ImaxHi)
if (Imax == ImaxHi && RList[MainCtrlPos].Bn > 1)
{
if (RList[MainCtrlPos].Bn > 1)
/* NOTE: disabled, relay configuration was moved to compute_movement_
if( true == MaxCurrentSwitch( false )) {
// wylaczanie wysokiego rozruchu
SetFlag( SoundFlag, sound::relay );
}
*/
if (TrainType == dt_ET42)
{
/* NOTE: disabled, relay configuration was moved to compute_movement_
if( true == MaxCurrentSwitch( false )) {
// wylaczanie wysokiego rozruchu
SetFlag( SoundFlag, sound::relay );
}
*/
if (TrainType == dt_ET42)
{
--MainCtrlPos;
OK = false;
}
--MainCtrlPos;
OK = false;
}
}
//
@@ -2481,13 +2459,10 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
//}
}
if (TrainType == dt_ET42 && true == DynamicBrakeFlag)
if (TrainType == dt_ET42 && true == DynamicBrakeFlag && MainCtrlPos > 20)
{
if (MainCtrlPos > 20)
{
MainCtrlPos = 20;
OK = false;
}
MainCtrlPos = 20;
OK = false;
}
break;
}
@@ -2781,9 +2756,8 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
OK = false;
// if OK then LastRelayTime:=0;
// hunter-101012: poprawka
if (OK)
if (LastRelayTime > CtrlDelay)
LastRelayTime = 0;
if (OK && LastRelayTime > CtrlDelay)
LastRelayTime = 0;
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1 && MainCtrlPos > 0)
{
@@ -2844,9 +2818,8 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
OK = false;
// if OK then LastRelayTime:=0;
// hunter-101012: poprawka
if (OK)
if (LastRelayTime > CtrlDownDelay)
LastRelayTime = 0;
if (OK && LastRelayTime > CtrlDownDelay)
LastRelayTime = 0;
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1)
{
@@ -2873,11 +2846,8 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
int TMoverParameters::GetVirtualScndPos() const
{
if (TrainType == dt_ET42)
{
if (DynamicBrakeFlag && !ScndCtrlPos)
return -1;
}
if (TrainType == dt_ET42 && DynamicBrakeFlag && !ScndCtrlPos)
return -1;
return ScndCtrlPos;
}
@@ -3255,11 +3225,10 @@ bool TMoverParameters::DirectionBackward(void)
return false;
}
if (DirActive == 1 && MainCtrlPos == 0 && TrainType == dt_EZT && EngineType != TEngineType::ElectricInductionMotor)
if (MinCurrentSwitch(false))
{
return true;
}
if (DirActive == 1 && MainCtrlPos == 0 && TrainType == dt_EZT && EngineType != TEngineType::ElectricInductionMotor && MinCurrentSwitch(false))
{
return true;
}
if (MainCtrlPosNo > 0 && DirActive > -1 && (CabActive != 0 || (InactiveCabFlag & activation::neutraldirection) == 0))
{
if (EngineType == TEngineType::WheelsDriven)
@@ -4646,10 +4615,10 @@ void TMoverParameters::UpdatePipePressure(double dt)
LocBrakePress = LocHandle->GetCP();
for (int b = 0; b < 2; b++)
if ((TrainType & (dt_ET41 | dt_ET42)) != 0 && Couplers[b].Connected != nullptr) // nie podoba mi się to rozwiązanie, chyba trzeba
// dodać jakiś wpis do fizyki na to
if ((Couplers[b].Connected->TrainType & (dt_ET41 | dt_ET42)) != 0 && (Couplers[b].CouplingFlag & 36) == 36)
LocBrakePress = std::max(Couplers[b].Connected->LocHandle->GetCP(), LocBrakePress);
// nie podoba mi się to rozwiązanie, chyba trzeba
// dodać jakiś wpis do fizyki na to
if ((TrainType & (dt_ET41 | dt_ET42)) != 0 && Couplers[b].Connected != nullptr && (Couplers[b].Connected->TrainType & (dt_ET41 | dt_ET42)) != 0 && (Couplers[b].CouplingFlag & 36) == 36)
LocBrakePress = std::max(Couplers[b].Connected->LocHandle->GetCP(), LocBrakePress);
// if ((DynamicBrakeFlag) && (EngineType == ElectricInductionMotor))
//{
@@ -4797,32 +4766,29 @@ void TMoverParameters::UpdateScndPipePressure(double dt)
dv2 = 0;
// sprzeg 1
if (Couplers[0].Connected != nullptr)
if (TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic))
{
c = Couplers[0].Connected; // skrot
dv1 = 0.5 * dt * PF(ScndPipePress, c->ScndPipePress, Spz * 0.75);
if (dv1 * dv1 > 0.00000000000001)
c->switch_physics(true);
c->Pipe2->Flow(-dv1);
}
if (Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic))
{
c = Couplers[0].Connected; // skrot
dv1 = 0.5 * dt * PF(ScndPipePress, c->ScndPipePress, Spz * 0.75);
if (dv1 * dv1 > 0.00000000000001)
c->switch_physics(true);
c->Pipe2->Flow(-dv1);
}
// sprzeg 2
if (Couplers[1].Connected != nullptr)
if (TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic))
{
c = Couplers[1].Connected; // skrot
dv2 = 0.5 * dt * PF(ScndPipePress, c->ScndPipePress, Spz * 0.75);
if (dv2 * dv2 > 0.00000000000001)
c->switch_physics(true);
c->Pipe2->Flow(-dv2);
}
if (Couplers[1].Connected != nullptr && Couplers[0].Connected != nullptr)
if (TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic) && TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic))
{
dV = 0.00025 * dt * PF(Couplers[0].Connected->ScndPipePress, Couplers[1].Connected->ScndPipePress, Spz * 0.25);
Couplers[0].Connected->Pipe2->Flow(+dV);
Couplers[1].Connected->Pipe2->Flow(-dV);
}
if (Couplers[1].Connected != nullptr && TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic))
{
c = Couplers[1].Connected; // skrot
dv2 = 0.5 * dt * PF(ScndPipePress, c->ScndPipePress, Spz * 0.75);
if (dv2 * dv2 > 0.00000000000001)
c->switch_physics(true);
c->Pipe2->Flow(-dv2);
}
if (Couplers[1].Connected != nullptr && Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic) && TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic))
{
dV = 0.00025 * dt * PF(Couplers[0].Connected->ScndPipePress, Couplers[1].Connected->ScndPipePress, Spz * 0.25);
Couplers[0].Connected->Pipe2->Flow(+dV);
Couplers[1].Connected->Pipe2->Flow(-dV);
}
Pipe2->Flow(Hamulec->GetHPFlow(ScndPipePress, dt));
// NOTE: condition disabled to allow the air flow from the main hose to the main tank as well
@@ -4888,25 +4854,23 @@ double TMoverParameters::GetDVc(double dt)
dv1 = 0;
dv2 = 0;
// sprzeg 1
if (Couplers[0].Connected != nullptr)
if (TestFlag(Couplers[0].CouplingFlag, ctrain_pneumatic))
{ //*0.85
c = Couplers[0].Connected; // skrot //0.08 //e/D * L/D = e/D^2 * L
dv1 = 0.5 * dt * PF(PipePress, c->PipePress, Spg / (1.0 + 0.015 / Spg * Dim.L));
if (dv1 * dv1 > 0.00000000000001)
c->switch_physics(true);
c->Pipe->Flow(-dv1);
}
if (Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_pneumatic))
{ //*0.85
c = Couplers[0].Connected; // skrot //0.08 //e/D * L/D = e/D^2 * L
dv1 = 0.5 * dt * PF(PipePress, c->PipePress, Spg / (1.0 + 0.015 / Spg * Dim.L));
if (dv1 * dv1 > 0.00000000000001)
c->switch_physics(true);
c->Pipe->Flow(-dv1);
}
// sprzeg 2
if (Couplers[1].Connected != nullptr)
if (TestFlag(Couplers[1].CouplingFlag, ctrain_pneumatic))
{
c = Couplers[1].Connected; // skrot
dv2 = 0.5 * dt * PF(PipePress, c->PipePress, Spg / (1.0 + 0.015 / Spg * Dim.L));
if (dv2 * dv2 > 0.00000000000001)
c->switch_physics(true);
c->Pipe->Flow(-dv2);
}
if (Couplers[1].Connected != nullptr && TestFlag(Couplers[1].CouplingFlag, ctrain_pneumatic))
{
c = Couplers[1].Connected; // skrot
dv2 = 0.5 * dt * PF(PipePress, c->PipePress, Spg / (1.0 + 0.015 / Spg * Dim.L));
if (dv2 * dv2 > 0.00000000000001)
c->switch_physics(true);
c->Pipe->Flow(-dv2);
}
// if ((Couplers[1].Connected != NULL) && (Couplers[0].Connected != NULL))
// if ((TestFlag(Couplers[0].CouplingFlag, ctrain_pneumatic)) &&
// (TestFlag(Couplers[1].CouplingFlag, ctrain_pneumatic)))
@@ -5458,32 +5422,29 @@ double TMoverParameters::CouplerForce(int const End, double dt)
// zderzenie
coupler.CheckCollision = true;
}
if (-newdistance >= std::min(collisiondistance, dEpsilon))
{
if (coupler.type() == TCouplerType::Automatic && coupler.type() == othercoupler.type() && coupler.CouplingFlag == coupling::faux &&
if (-newdistance >= std::min(collisiondistance, dEpsilon) && coupler.type() == TCouplerType::Automatic && coupler.type() == othercoupler.type() && coupler.CouplingFlag == coupling::faux &&
coupler.AutomaticCouplingAllowed &&
othercoupler.AutomaticCouplingAllowed)
{
// sprzeganie wagonow z samoczynnymi sprzegami
auto couplingtype{coupler.AutomaticCouplingFlag & othercoupler.AutomaticCouplingFlag};
// potentially exclude incompatible control coupling
if (coupler.control_type != othercoupler.control_type)
{
// sprzeganie wagonow z samoczynnymi sprzegami
auto couplingtype{coupler.AutomaticCouplingFlag & othercoupler.AutomaticCouplingFlag};
// potentially exclude incompatible control coupling
if (coupler.control_type != othercoupler.control_type)
{
couplingtype &= ~coupling::control;
}
if (Attach(End, otherend, othervehicle, couplingtype))
{
// HACK: we're reusing sound enum to mark whether vehicle was connected to another
SetFlag(AIFlag, sound::attachcoupler);
coupler.AutomaticCouplingAllowed = false;
othercoupler.AutomaticCouplingAllowed = false;
}
/*
coupler.CouplingFlag = ( coupler.AutomaticCouplingFlag & othercoupler.AutomaticCouplingFlag );
SetFlag( coupler.sounds, sound::attachcoupler );
*/
couplingtype &= ~coupling::control;
}
if (Attach(End, otherend, othervehicle, couplingtype))
{
// HACK: we're reusing sound enum to mark whether vehicle was connected to another
SetFlag(AIFlag, sound::attachcoupler);
coupler.AutomaticCouplingAllowed = false;
othercoupler.AutomaticCouplingAllowed = false;
}
/*
coupler.CouplingFlag = ( coupler.AutomaticCouplingFlag & othercoupler.AutomaticCouplingFlag );
SetFlag( coupler.sounds, sound::attachcoupler );
*/
}
}
}
@@ -5726,14 +5687,11 @@ double TMoverParameters::TractionForce(double dt)
case TEngineType::ElectricInductionMotor:
{
// TODO: check if we can use instead the code for electricseriesmotor
if (Mains)
// nie wchodzić w funkcję bez potrzeby
if (Mains && (std::max(GetTrainsetHighVoltage(), PantographVoltage) < EnginePowerSource.CollectorParameters.MinV ||
std::max(GetTrainsetHighVoltage(), PantographVoltage) > EnginePowerSource.CollectorParameters.MaxV + 200))
{
// nie wchodzić w funkcję bez potrzeby
if (std::max(GetTrainsetHighVoltage(), PantographVoltage) < EnginePowerSource.CollectorParameters.MinV ||
std::max(GetTrainsetHighVoltage(), PantographVoltage) > EnginePowerSource.CollectorParameters.MaxV + 200)
{
MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide
}
MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide
}
break;
}
@@ -5780,9 +5738,8 @@ double TMoverParameters::TractionForce(double dt)
case TEngineType::WheelsDriven:
{
if (EnginePowerSource.SourceType == TPowerSource::InternalSource)
if (EnginePowerSource.PowerType == TPowerType::BioPower)
Ft = Sign(sin(eAngle)) * PulseForce * Transmision.Ratio;
if (EnginePowerSource.SourceType == TPowerSource::InternalSource && EnginePowerSource.PowerType == TPowerType::BioPower)
Ft = Sign(sin(eAngle)) * PulseForce * Transmision.Ratio;
PulseForceTimer = PulseForceTimer + dt;
if (PulseForceTimer > CtrlDelay)
{
@@ -6208,24 +6165,21 @@ double TMoverParameters::TractionForce(double dt)
}
}
// malenie
if (MainCtrlPos < 12 && ScndCtrlPos > 0)
if (MainCtrlPos < 12 && ScndCtrlPos > 0 && Vel < 50.0)
{
if (Vel < 50.0)
// above 50 km/h already active shunt field can be maintained until lower controller setting
if (ScndCtrlPos % 2 == 0)
{
// above 50 km/h already active shunt field can be maintained until lower controller setting
if (ScndCtrlPos % 2 == 0)
if (MPTRelay[ScndCtrlPos].Idown < Im)
{
if (MPTRelay[ScndCtrlPos].Idown < Im)
{
--ScndCtrlPos;
}
--ScndCtrlPos;
}
else
}
else
{
if (MPTRelay[ScndCtrlPos + 1].Idown < Im && MPTRelay[ScndCtrlPos].Idown > Vel)
{
if (MPTRelay[ScndCtrlPos + 1].Idown < Im && MPTRelay[ScndCtrlPos].Idown > Vel)
{
--ScndCtrlPos;
}
--ScndCtrlPos;
}
}
}
@@ -6621,9 +6575,8 @@ bool TMoverParameters::FuseFlagCheck(void) const
FFC = FuseFlag;
else // pobor pradu jezeli niema mocy
for (int b = 0; b < 2; b++)
if (TestFlag(Couplers[b].CouplingFlag, coupling::control))
if (Couplers[b].Connected->Power > 0.01)
FFC = Couplers[b].Connected->FuseFlagCheck();
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01)
FFC = Couplers[b].Connected->FuseFlagCheck();
return FFC;
}
@@ -6681,43 +6634,34 @@ bool TMoverParameters::RelayReset(int const Relays, range_t const Notify)
auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable};
bool reset{false};
if (TestFlag(Relays, relay_t::maincircuitground))
{
if ((EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) &&
if (TestFlag(Relays, relay_t::maincircuitground) && (EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) &&
(GroundRelayStart == start_t::manual || GroundRelayStart == start_t::manualwithautofallback) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 &&
!TestFlag(EngDmgFlag, 1))
{
// NOTE: true means the relay is operational
reset |= !GroundRelay && lowvoltagepower;
GroundRelay |= lowvoltagepower;
}
{
// NOTE: true means the relay is operational
reset |= !GroundRelay && lowvoltagepower;
GroundRelay |= lowvoltagepower;
}
if (TestFlag(Relays, relay_t::tractionnmotoroverload))
{
if ((EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 &&
if (TestFlag(Relays, relay_t::tractionnmotoroverload) && (EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 &&
!TestFlag(EngDmgFlag, 1))
{
// NOTE: false means the relay is operational
// TODO: cleanup, flip the FuseFlag code to match other relays
// TODO: check whether the power is required, TBD, TODO: make it configurable?
reset |= FuseFlag && lowvoltagepower;
FuseFlag &= !lowvoltagepower;
}
{
// NOTE: false means the relay is operational
// TODO: cleanup, flip the FuseFlag code to match other relays
// TODO: check whether the power is required, TBD, TODO: make it configurable?
reset |= FuseFlag && lowvoltagepower;
FuseFlag &= !lowvoltagepower;
}
if (TestFlag(Relays, relay_t::primaryconverteroverload))
{
if (ConverterOverloadRelayStart == start_t::manual
if (TestFlag(Relays, relay_t::primaryconverteroverload) && ConverterOverloadRelayStart == start_t::manual
// && ( false == Mains )
&& false == ConverterAllow)
{
// NOTE: false means the relay is operational
// TODO: cleanup, flip the FuseFlag code to match other relays
// TODO: check whether the power is required, TBD, TODO: make it configurable?
reset |= ConvOvldFlag && lowvoltagepower;
ConvOvldFlag &= !lowvoltagepower;
}
{
// NOTE: false means the relay is operational
// TODO: cleanup, flip the FuseFlag code to match other relays
// TODO: check whether the power is required, TBD, TODO: make it configurable?
reset |= ConvOvldFlag && lowvoltagepower;
ConvOvldFlag &= !lowvoltagepower;
}
if (reset)
@@ -6751,14 +6695,10 @@ double TMoverParameters::v2n(void)
SlippingWheels = false; // wygaszenie poslizgu */ //poslizg jest w innym miejscu wygaszany też
if (SlippingWheels) // nie ma zwiazku z predkoscia liniowa V
{ // McZapkie-221103: uszkodzenia kol podczas poslizgu
if (deltan > dmgn)
if (FuzzyLogic(deltan, dmgn, p_slippdmg))
if (SetFlag(DamageFlag, dtrain_wheelwear)) // podkucie
EventFlag = true;
if (deltan < -dmgn)
if (FuzzyLogic(-deltan, dmgn, p_slippdmg))
if (SetFlag(DamageFlag, dtrain_thinwheel)) // wycieranie sie obreczy
EventFlag = true;
if (deltan > dmgn && FuzzyLogic(deltan, dmgn, p_slippdmg) && SetFlag(DamageFlag, dtrain_wheelwear)) // podkucie
EventFlag = true;
if (deltan < -dmgn && FuzzyLogic(-deltan, dmgn, p_slippdmg) && SetFlag(DamageFlag, dtrain_thinwheel)) // wycieranie sie obreczy
EventFlag = true;
n = nrot; // predkosc obrotowa nie zalezy od predkosci liniowej
}
return n;
@@ -6774,9 +6714,8 @@ double TMoverParameters::Momentum(double I) const
int SP;
SP = ScndCtrlActualPos;
if (ScndInMain)
if (!(RList[MainCtrlActualPos].ScndAct == 255))
SP = RList[MainCtrlActualPos].ScndAct;
if (ScndInMain && !(RList[MainCtrlActualPos].ScndAct == 255))
SP = RList[MainCtrlActualPos].ScndAct;
// Momentum:=mfi*I*(1-1.0/(Abs(I)/mIsat+1));
return motor_param(SP).mfi * I * (abs(I) / (abs(I) + motor_param(SP).mIsat) - motor_param(SP).mfi0);
@@ -6800,13 +6739,10 @@ double TMoverParameters::MomentumF(double I, double Iw, int SCP) const
bool TMoverParameters::CutOffEngine(void)
{
bool COE = false; // Ra: wartość domyślna, sprawdzić to trzeba
if (NPoweredAxles > 0 && CabActive == 0 && EngineType == TEngineType::ElectricSeriesMotor)
if (NPoweredAxles > 0 && CabActive == 0 && EngineType == TEngineType::ElectricSeriesMotor && SetFlag(DamageFlag, -dtrain_engine))
{
if (SetFlag(DamageFlag, -dtrain_engine))
{
NPoweredAxles = NPoweredAxles / 2; // bylo div czyli mod?
COE = true;
}
NPoweredAxles = NPoweredAxles / 2; // bylo div czyli mod?
COE = true;
}
return COE;
}
@@ -6870,9 +6806,8 @@ bool TMoverParameters::ResistorsFlagCheck(void) const
else // pobor pradu jezeli niema mocy
{
for (int b = 0; b < 2; b++)
if (TestFlag(Couplers[b].CouplingFlag, coupling::control))
if (Couplers[b].Connected->Power > 0.01)
RFC = Couplers[b].Connected->ResistorsFlagCheck();
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01)
RFC = Couplers[b].Connected->ResistorsFlagCheck();
}
return RFC;
}
@@ -6961,13 +6896,10 @@ bool TMoverParameters::AutoRelayCheck(void)
}
else
{ // zmieniaj mainctrlactualpos
if (DirActive < 0 && TrainType != dt_PseudoDiesel)
if (DirActive < 0 && TrainType != dt_PseudoDiesel && RList[MainCtrlActualPos + 1].Bn > BackwardsBranchesAllowed)
{
if (RList[MainCtrlActualPos + 1].Bn > BackwardsBranchesAllowed)
{
return false; // nie poprawiamy przy konwersji
// return ARC;// bbylo exit; //Ra: to powoduje, że EN57 nie wyłącza się przy IminLo
}
return false; // nie poprawiamy przy konwersji
// return ARC;// bbylo exit; //Ra: to powoduje, że EN57 nie wyłącza się przy IminLo
}
// main bez samoczynnego rozruchu
if (MainCtrlActualPos < sizeof(RList) / sizeof(TScheme) - 1 // crude guard against running out of current fixed table
@@ -7065,12 +6997,12 @@ bool TMoverParameters::AutoRelayCheck(void)
--MainCtrlActualPos;
OK = true;
}
if (MainCtrlActualPos > 0) // hunter-111211: poprawki
if (RList[MainCtrlActualPos].R == 0)
{
// dzwieki schodzenia z bezoporowej}
SetFlag(SoundFlag, sound::parallel);
}
// hunter-111211: poprawki
if (MainCtrlActualPos > 0 && RList[MainCtrlActualPos].R == 0)
{
// dzwieki schodzenia z bezoporowej}
SetFlag(SoundFlag, sound::parallel);
}
}
}
else if (RList[MainCtrlActualPos].R > 0 && ScndCtrlActualPos > 0)
@@ -7554,11 +7486,8 @@ void TMoverParameters::CheckSpeedCtrl(double dt)
{
SpeedCtrlUnit.Standby = false;
}
if (!SpeedCtrlUnit.BrakeIntervention)
{
if (Hamulec->GetEDBCP() > 0.4 || PipePress < HighPipePress - 0.2)
SpeedCtrlUnit.Standby = true;
}
if (!SpeedCtrlUnit.BrakeIntervention && (Hamulec->GetEDBCP() > 0.4 || PipePress < HighPipePress - 0.2))
SpeedCtrlUnit.Standby = true;
if (EIMCtrlType >= 3 && UniCtrlList[MainCtrlPos].SpeedUp <= 0)
{
accfactor = 0.0;
@@ -7571,11 +7500,8 @@ void TMoverParameters::CheckSpeedCtrl(double dt)
{
if (!SpeedCtrlUnit.Standby)
{
if (SpeedCtrlUnit.ManualStateOverride)
{
if (eimic > 0.0009)
eimic = 1.0;
}
if (SpeedCtrlUnit.ManualStateOverride && eimic > 0.0009)
eimic = 1.0;
double error = std::max(SpeedCtrlValue + SpeedCtrlUnit.Offset, 0.0) - Vel;
double factorP = error > 0 ? SpeedCtrlUnit.FactorPpos : SpeedCtrlUnit.FactorPneg;
double eSCP = std::clamp(factorP * error, -1.2, 1.0); // P module
@@ -11814,9 +11740,8 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/)
// WriteLogSS("aa ok", BoolToYN(OK));
}
if (BrakeSystem == TBrakeSystem::Individual)
if (BrakeSubsystem != TBrakeSubSystem::ss_None)
OK = false; //!
if (BrakeSystem == TBrakeSystem::Individual && BrakeSubsystem != TBrakeSubSystem::ss_None)
OK = false; //!
if (BrakeVVolume == 0 && MaxBrakePress[3] > 0 && BrakeSystem != TBrakeSystem::Individual)
{
@@ -12228,24 +12153,21 @@ bool TMoverParameters::SendCtrlToNext(std::string const CtrlCommand, double cons
// Ra: problem jest również, jeśli AI będzie na końcu składu
OK = true; // ( dir != 0 ); // experimentally disabled
d = (1 + static_cast<int>(Sign(dir))) / 2; // dir=-1=>d=0, dir=1=>d=1 - wysyłanie tylko w tył
if (OK)
// musi być wybrana niezerowa kabina
if (OK && Couplers[d].Connected != nullptr && TestFlag(Couplers[d].CouplingFlag, Couplertype))
{
// musi być wybrana niezerowa kabina
if (Couplers[d].Connected != nullptr && TestFlag(Couplers[d].CouplingFlag, Couplertype))
{
if (Couplers[d].ConnectedNr != d)
{
// jeśli ten nastpęny jest zgodny z aktualnym
if (Couplers[d].Connected->SetInternalCommand(CtrlCommand, ctrlvalue, dir, Couplertype))
OK = Couplers[d].Connected->RunInternalCommand() && OK; // tu jest rekurencja
}
else
{
// jeśli następny jest ustawiony przeciwnie, zmieniamy kierunek
if (Couplers[d].Connected->SetInternalCommand(CtrlCommand, ctrlvalue, -dir, Couplertype))
OK = Couplers[d].Connected->RunInternalCommand() && OK; // tu jest rekurencja
}
if (Couplers[d].ConnectedNr != d)
{
// jeśli ten nastpęny jest zgodny z aktualnym
if (Couplers[d].Connected->SetInternalCommand(CtrlCommand, ctrlvalue, dir, Couplertype))
OK = Couplers[d].Connected->RunInternalCommand() && OK; // tu jest rekurencja
}
else
{
// jeśli następny jest ustawiony przeciwnie, zmieniamy kierunek
if (Couplers[d].Connected->SetInternalCommand(CtrlCommand, ctrlvalue, -dir, Couplertype))
OK = Couplers[d].Connected->RunInternalCommand() && OK; // tu jest rekurencja
}
}
return OK;
@@ -12589,50 +12511,44 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV
}
else if (Command == "DoorOpen") /*NBMX*/
{ // Ra: uwzględnić trzeba jeszcze zgodność sprzęgów
if (Doors.open_control == control_t::conductor || Doors.open_control == control_t::driver || Doors.open_control == control_t::mixed)
// ignore remote command if the door is only operated locally
if ((Doors.open_control == control_t::conductor || Doors.open_control == control_t::driver || Doors.open_control == control_t::mixed) && (Power24vIsAvailable || Power110vIsAvailable))
{
// ignore remote command if the door is only operated locally
if (Power24vIsAvailable || Power110vIsAvailable)
auto const left{CValue2 > 0 ? 1 : 2};
auto const right{3 - left};
if (static_cast<int>(CValue1) & right)
{
auto const left{CValue2 > 0 ? 1 : 2};
auto const right{3 - left};
if (static_cast<int>(CValue1) & right)
{
Doors.instances[side::right].remote_open = true;
Doors.instances[side::right].remote_close = false;
}
if (static_cast<int>(CValue1) & left)
{
Doors.instances[side::left].remote_open = true;
Doors.instances[side::left].remote_close = false;
}
Doors.instances[side::right].remote_open = true;
Doors.instances[side::right].remote_close = false;
}
if (static_cast<int>(CValue1) & left)
{
Doors.instances[side::left].remote_open = true;
Doors.instances[side::left].remote_close = false;
}
}
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
}
else if (Command == "DoorClose") /*NBMX*/
{ // Ra: uwzględnić trzeba jeszcze zgodność sprzęgów
if (Doors.close_control == control_t::conductor || Doors.close_control == control_t::driver || Doors.close_control == control_t::mixed)
// ignore remote command if the door is only operated locally
if ((Doors.close_control == control_t::conductor || Doors.close_control == control_t::driver || Doors.close_control == control_t::mixed) && (Power24vIsAvailable || Power110vIsAvailable))
{
// ignore remote command if the door is only operated locally
if (Power24vIsAvailable || Power110vIsAvailable)
auto const left{CValue2 > 0 ? 1 : 2};
auto const right{3 - left};
if (static_cast<int>(CValue1) & right)
{
auto const left{CValue2 > 0 ? 1 : 2};
auto const right{3 - left};
if (static_cast<int>(CValue1) & right)
{
Doors.instances[side::right].remote_close = true;
Doors.instances[side::right].remote_open = false;
}
if (static_cast<int>(CValue1) & left)
{
Doors.instances[side::left].remote_close = true;
Doors.instances[side::left].remote_open = false;
}
Doors.instances[side::right].remote_close = true;
Doors.instances[side::right].remote_open = false;
}
if (static_cast<int>(CValue1) & left)
{
Doors.instances[side::left].remote_close = true;
Doors.instances[side::left].remote_open = false;
}
}
OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype);
@@ -12857,9 +12773,8 @@ double TMoverParameters::ShowCurrentP(int AmpN) const
int current = 0;
for (b = 0; b < 2; b++)
// with Couplers[b] do
if (TestFlag(Couplers[b].CouplingFlag, coupling::control))
if (Couplers[b].Connected->Power > 0.01)
current = static_cast<int>(Couplers[b].Connected->ShowCurrent(AmpN));
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01)
current = static_cast<int>(Couplers[b].Connected->ShowCurrent(AmpN));
return current;
}
}

View File

@@ -355,14 +355,14 @@ void TNESt3::CheckState(double const BCP, double & /*dV1*/) // glowny przyrzad r
if( ( BrakeStatus & b_hld ) == 0 )
SoundFlag |= sf_CylU;
if (VVP + 0.10 < CVP && BCP < 0.25) // poczatek hamowania
if (false == Przys_blok)
{
ValveRes->CreatePress(0.1 * VVP);
SoundFlag |= sf_Acc;
ValveRes->Act();
Przys_blok = true;
}
// poczatek hamowania
if (VVP + 0.10 < CVP && BCP < 0.25 && false == Przys_blok)
{
ValveRes->CreatePress(0.1 * VVP);
SoundFlag |= sf_Acc;
ValveRes->Act();
Przys_blok = true;
}
if (BCP > 0.5)
Zamykajacy = true;

View File

@@ -786,15 +786,12 @@ void TWest::SetEPS(double const nEPS)
BCP = BrakeCyl->P();
if (nEPS > 0)
DCV = true;
else if (nEPS == 0)
else if (nEPS == 0 && EPS != 0)
{
if (EPS != 0)
{
if (LBP > 0.4)
LBP = BrakeCyl->P();
if (LBP < 0.15)
LBP = 0;
}
if (LBP > 0.4)
LBP = BrakeCyl->P();
if (LBP < 0.15)
LBP = 0;
}
EPS = nEPS;
}
@@ -1934,14 +1931,14 @@ double TEStED::GetPF(double const PP, double const dt, double const Vel)
else if (VVP + (BCP - 0.1) / BVM < CVP - 0.05 && BCP > 0.25) // zatrzymanie luzowania
BrakeStatus |= b_hld;
if (VVP + 0.10 < CVP && BCP < 0.25) // poczatek hamowania
if (!Przys_blok)
{
ValveRes->CreatePress(0.75 * VVP);
SoundFlag |= sf_Acc;
ValveRes->Act();
Przys_blok = true;
}
// poczatek hamowania
if (VVP + 0.10 < CVP && BCP < 0.25 && !Przys_blok)
{
ValveRes->CreatePress(0.75 * VVP);
SoundFlag |= sf_Acc;
ValveRes->Act();
Przys_blok = true;
}
if (BCP > 0.5)
Zamykajacy = true;
@@ -2969,9 +2966,8 @@ double TFV4a::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
if (lround(i_bcp) == -1)
{
CP = CP + 5 * std::min(std::abs(LimPP - CP), 0.2) * PR(CP, LimPP) * dt / 2;
if (CP < RP + 0.03)
if (TP < 5)
TP = TP + dt;
if (CP < RP + 0.03 && TP < 5)
TP = TP + dt;
// if(cp+0.03<5.4)then
if (RP + 0.03 < 5.4 || CP + 0.03 < 5.4) // fala
dpMainValve = PF(std::min(HP, 17.1), PP, ActFlowSpeed / LBDelay) * dt;
@@ -3134,13 +3130,9 @@ double TFV4aM::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
}
}
if (EQ(i_bcp, 0))
if (EQ(i_bcp, 0) && TP > 2)
{
if (TP > 2)
{
dpMainValve *= 1.5;
}
dpMainValve *= 1.5;
}
ep = dpPipe;

View File

@@ -501,16 +501,14 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
break;
}
case driver_hint::mastercontrollersetseriesmode: {
if( AIControllFlag ) {
if( mvControlling->RList[ mvControlling->MainCtrlPos ].Bn > 1 ) {
// limit yourself to series mode
if( mvControlling->ScndCtrlPos ) {
mvControlling->DecScndCtrl( 2 );
}
while( mvControlling->RList[mvControlling->MainCtrlPos].Bn > 1
&& mvControlling->DecMainCtrl(1) ) {
// all work is performed in the header
}
if (AIControllFlag && mvControlling->RList[ mvControlling->MainCtrlPos ].Bn > 1) {
// limit yourself to series mode
if( mvControlling->ScndCtrlPos ) {
mvControlling->DecScndCtrl( 2 );
}
while( mvControlling->RList[mvControlling->MainCtrlPos].Bn > 1
&& mvControlling->DecMainCtrl(1) ) {
// all work is performed in the header
}
}
remove_master_controller_hints();
@@ -581,10 +579,8 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
break;
}
case driver_hint::bufferscompress: {
if( AIControllFlag ) {
if( std::abs( mvControlling->Ft ) < 50000.0 ) {
IncSpeed();
}
if (AIControllFlag && std::abs( mvControlling->Ft ) < 50000.0) {
IncSpeed();
}
remove_master_controller_hints();
hint(
@@ -773,12 +769,10 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
// driver_hint_brakingforcesetzero
// driver_hint_brakingforcelap
case driver_hint::trainbrakesetpipeunlock: {
if( AIControllFlag ) {
if( mvOccupied->HandleUnlock != -3 ) {
while( BrakeCtrlPosition >= mvOccupied->HandleUnlock
&& BrakeLevelAdd(-1) ) {
// all work is done in the header
}
if (AIControllFlag && mvOccupied->HandleUnlock != -3) {
while( BrakeCtrlPosition >= mvOccupied->HandleUnlock
&& BrakeLevelAdd(-1) ) {
// all work is done in the header
}
}
remove_train_brake_hints();
@@ -878,13 +872,11 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
}
// independent brake
case driver_hint::independentbrakeapply: {
if( AIControllFlag ) {
if( mvOccupied->LocalBrakePosA < 1.0 ) {
mvOccupied->IncLocalBrakeLevel( LocalBrakePosNo );
if (mvOccupied->EIMCtrlEmergency) {
mvOccupied->DecLocalBrakeLevel(1);
if (AIControllFlag && mvOccupied->LocalBrakePosA < 1.0) {
mvOccupied->IncLocalBrakeLevel( LocalBrakePosNo );
if (mvOccupied->EIMCtrlEmergency) {
mvOccupied->DecLocalBrakeLevel(1);
}
}
}
remove_hint( driver_hint::independentbrakerelease );
hint(
@@ -1192,10 +1184,8 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
}
case driver_hint::securitysystemreset: {
if( AIControllFlag ) {
if (mvOccupied->SecuritySystem.is_blinking())
mvOccupied->SecuritySystemReset();
}
if (AIControllFlag && mvOccupied->SecuritySystem.is_blinking())
mvOccupied->SecuritySystemReset();
hint(
Action,
[this](float const /*Parameter*/) {
@@ -1203,10 +1193,8 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
break;
}
case driver_hint::shpsystemreset: {
if( AIControllFlag ) {
if (mvOccupied->SecuritySystem.is_cabsignal_blinking())
mvOccupied->SecuritySystem.cabsignal_reset();
}
if (AIControllFlag && mvOccupied->SecuritySystem.is_cabsignal_blinking())
mvOccupied->SecuritySystem.cabsignal_reset();
hint(
Action,
[this](float const /*Parameter*/) {

View File

@@ -277,18 +277,16 @@ scenario_panel::render() {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() );
}
// hints
if( owner != nullptr ) {
if( true == ImGui::CollapsingHeader( STR_C("Hints"), ImGuiTreeNodeFlags_DefaultOpen ) ) {
for( auto const &hint : owner->m_hints ) {
auto const isdone { std::get<TController::hintpredicate>( hint )( std::get<float>( hint ) ) };
auto const hintcolor{ (
isdone ?
colors::uitextgreen :
Global.UITextColor ) };
ImGui::PushStyleColor( ImGuiCol_Text, { hintcolor.r, hintcolor.g, hintcolor.b, hintcolor.a } );
ImGui::TextWrapped( Translations.lookup_c(driver_hints_texts[(size_t)std::get<driver_hint>( hint )], true), std::get<float>( hint ) );
ImGui::PopStyleColor();
}
if (owner != nullptr && true == ImGui::CollapsingHeader( STR_C("Hints"), ImGuiTreeNodeFlags_DefaultOpen )) {
for( auto const &hint : owner->m_hints ) {
auto const isdone { std::get<TController::hintpredicate>( hint )( std::get<float>( hint ) ) };
auto const hintcolor{ (
isdone ?
colors::uitextgreen :
Global.UITextColor ) };
ImGui::PushStyleColor( ImGuiCol_Text, { hintcolor.r, hintcolor.g, hintcolor.b, hintcolor.a } );
ImGui::TextWrapped( Translations.lookup_c(driver_hints_texts[(size_t)std::get<driver_hint>( hint )], true), std::get<float>( hint ) );
ImGui::PopStyleColor();
}
}
}
@@ -588,13 +586,9 @@ debug_panel::render() {
}
// sections
ImGui::Separator();
if( true == render_section( "Vehicle", m_vehiclelines ) ) {
if( DebugModeFlag && m_input.mover && m_input.mover->DamageFlag != 0 ) {
if( true == ImGui::Button( "Stop and repair consist" ) ) {
command_relay relay;
relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_input.vehicle->name());
}
}
if (true == render_section( "Vehicle", m_vehiclelines ) && DebugModeFlag && m_input.mover && m_input.mover->DamageFlag != 0 && true == ImGui::Button( "Stop and repair consist" )) {
command_relay relay;
relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_input.vehicle->name());
}
render_section( "Vehicle Engine", m_enginelines );
render_section( "Vehicle AI", m_ailines );
@@ -695,10 +689,8 @@ debug_panel::render_section_scenario() {
}
// dynamic material update checkbox
ImGui::Checkbox( "Update Item Materials", &Global.UpdateMaterials );
if( DebugModeFlag ) {
if( ImGui::Checkbox( "Force Daylight", &Global.FakeLight ) ) {
simulation::Environment.on_daylight_change();
}
if (DebugModeFlag && ImGui::Checkbox( "Force Daylight", &Global.FakeLight )) {
simulation::Environment.on_daylight_change();
}
// advanced options, only visible in debug mode
if( DebugModeFlag ) {

View File

@@ -117,24 +117,18 @@ sound_source::deserialize( cParser &Input, sound_type const Legacytype, int cons
}
}
if( Legacyparameters & sound_parameters::range ) {
if( Input.getTokens( 1, false ) ) {
Input >> m_range;
}
if (Legacyparameters & sound_parameters::range && Input.getTokens( 1, false )) {
Input >> m_range;
}
if( Legacyparameters & sound_parameters::amplitude ) {
if( Input.getTokens( 2, false ) ) {
Input
>> m_amplitudefactor
>> m_amplitudeoffset;
}
if (Legacyparameters & sound_parameters::amplitude && Input.getTokens( 2, false )) {
Input
>> m_amplitudefactor
>> m_amplitudeoffset;
}
if( Legacyparameters & sound_parameters::frequency ) {
if( Input.getTokens( 2, false ) ) {
Input
>> m_frequencyfactor
>> m_frequencyoffset;
}
if (Legacyparameters & sound_parameters::frequency && Input.getTokens( 2, false )) {
Input
>> m_frequencyfactor
>> m_frequencyoffset;
}
}
// restore parser behaviour

View File

@@ -314,15 +314,13 @@ drivermouse_input::button( int const Button, int const Action ) {
if( true == FreeFlyModeFlag ) {
// freefly mode
// left mouse button launches on_click event associated with to the node
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
if( Action == GLFW_PRESS ) {
GfxRenderer->Pick_Node_Callback(
[this](scene::basic_node *node) {
if( node == nullptr
|| typeid(*node) != typeid(TAnimModel) )
return;
simulation::Region->on_click( static_cast<TAnimModel const *>( node ) ); } );
}
if (Button == GLFW_MOUSE_BUTTON_LEFT && Action == GLFW_PRESS) {
GfxRenderer->Pick_Node_Callback(
[this](scene::basic_node *node) {
if( node == nullptr
|| typeid(*node) != typeid(TAnimModel) )
return;
simulation::Region->on_click( static_cast<TAnimModel const *>( node ) ); } );
}
// right button controls panning
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
@@ -343,11 +341,9 @@ drivermouse_input::button( int const Button, int const Action ) {
}
else {
m_pickwaiting = false;
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
if( m_slider.command() != user_command::none ) {
m_relay.post( m_slider.command(), 0, 0, Action, 0 );
m_slider.release();
}
if (Button == GLFW_MOUSE_BUTTON_LEFT && m_slider.command() != user_command::none) {
m_relay.post( m_slider.command(), 0, 0, Action, 0 );
m_slider.release();
}
// if it's the right mouse button that got released and we had no command active, we were potentially in view panning mode; stop it
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {

View File

@@ -370,16 +370,14 @@ gamepad_input::process_axes() {
auto const deltatime { Timer::GetDeltaTime() * 15.0 };
if( axis.state >= 0.0f ) {
// first bound command selected
if( axis.accumulator < 0.0f ) {
// we were issuing the other command, post notification that's no longer the case
if( boundcommand2 != user_command::none ) {
m_relay.post(
boundcommand2,
0, 0,
GLFW_RELEASE,
0 );
axis.accumulator = 0.0f;
}
// we were issuing the other command, post notification that's no longer the case
if (axis.accumulator < 0.0f && boundcommand2 != user_command::none) {
m_relay.post(
boundcommand2,
0, 0,
GLFW_RELEASE,
0 );
axis.accumulator = 0.0f;
}
if( boundcommand1 != user_command::none ) {
if( axis.state > m_deadzone ) {
@@ -410,16 +408,14 @@ gamepad_input::process_axes() {
}
else {
// second bound command selected
if( axis.accumulator > 0.0f ) {
// we were issuing the other command, post notification that's no longer the case
if( boundcommand1 != user_command::none ) {
m_relay.post(
boundcommand1,
0, 0,
GLFW_RELEASE,
0 );
axis.accumulator = 0.0f;
}
// we were issuing the other command, post notification that's no longer the case
if (axis.accumulator > 0.0f && boundcommand1 != user_command::none) {
m_relay.post(
boundcommand1,
0, 0,
GLFW_RELEASE,
0 );
axis.accumulator = 0.0f;
}
if( boundcommand1 != user_command::none ) {
if( axis.state < -m_deadzone ) {
@@ -465,10 +461,8 @@ gamepad_input::process_axes() {
else {
param = param > 0.0 ? (param - m_deadzone) / (1.0 - m_deadzone) : (param + m_deadzone) / (1.0 - m_deadzone);
}
if( param != 0.0 ) {
if( inputtype == input_type::value_invert ) {
param *= -1.0;
}
if (param != 0.0 && inputtype == input_type::value_invert) {
param *= -1.0;
}
// scale passed value according to command type
switch( boundcommand1 ) {

View File

@@ -63,14 +63,12 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
if( Global.iMultiplayer ) {
auto *event = simulation::Events.FindEvent( std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) );
if( event != nullptr ) {
if( typeid(*event) == typeid(multi_event)
if (event != nullptr && (typeid(*event) == typeid(multi_event)
|| typeid(*event) == typeid(lights_event)
|| event->m_sibling != nullptr ) {
// tylko jawne albo niejawne Multiple
|| event->m_sibling != nullptr)) {
// tylko jawne albo niejawne Multiple
command_relay relay;
relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &event->name());
}
}
}
break;
@@ -111,17 +109,17 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
case 5: // ustawienie parametrów
{
CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " params " + std::to_string(*pRozkaz->iPar) + " rcvd");
if (*pRozkaz->iPar == 0) // sprawdzenie czasu
if (*pRozkaz->iPar & 1) // ustawienie czasu
{
auto t = pRozkaz->fPar[1];
simulation::Time.data().wDay = static_cast<uint16_t>(std::floor(t)); // niby nie powinno być dnia, ale...
if (Global.fMoveLight >= 0)
Global.fMoveLight = t; // trzeba by deklinację Słońca przeliczyć
simulation::Time.data().wHour = static_cast<uint16_t>(std::floor(24 * t) - 24.0 * simulation::Time.data().wDay);
simulation::Time.data().wMinute = static_cast<uint16_t>(std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour));
simulation::Time.data().wSecond = static_cast<uint16_t>(std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute ));
}
// sprawdzenie czasu
if (*pRozkaz->iPar == 0 && *pRozkaz->iPar & 1) // ustawienie czasu
{
auto t = pRozkaz->fPar[1];
simulation::Time.data().wDay = static_cast<uint16_t>(std::floor(t)); // niby nie powinno być dnia, ale...
if (Global.fMoveLight >= 0)
Global.fMoveLight = t; // trzeba by deklinację Słońca przeliczyć
simulation::Time.data().wHour = static_cast<uint16_t>(std::floor(24 * t) - 24.0 * simulation::Time.data().wDay);
simulation::Time.data().wMinute = static_cast<uint16_t>(std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour));
simulation::Time.data().wSecond = static_cast<uint16_t>(std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute ));
}
if (*pRozkaz->iPar & 2)
{ // ustawienie flag zapauzowania
Global.iPause = static_cast<int>(pRozkaz->fPar[2]); // zakładamy, że wysyłający wie, co robi

View File

@@ -47,12 +47,10 @@ void opengl33_skydome::update() {
m_vao->unbind();
}
// ship the current dynamic data to the gpu
if( true == skydome.is_dirty() ) {
if( m_coloursbuffer ) {
// the colour buffer was already initialized, so on this run we update its content
m_coloursbuffer->upload( gl::buffer::ARRAY_BUFFER, skydome.colors().data(), 0, skydome.colors().size() * sizeof( glm::vec3 ) );
skydome.is_dirty() = false;
}
if (true == skydome.is_dirty() && m_coloursbuffer) {
// the colour buffer was already initialized, so on this run we update its content
m_coloursbuffer->upload( gl::buffer::ARRAY_BUFFER, skydome.colors().data(), 0, skydome.colors().size() * sizeof( glm::vec3 ) );
skydome.is_dirty() = false;
}
}

View File

@@ -54,20 +54,18 @@ void opengl_skydome::update() {
}
// ship the current dynamic data to the gpu
// TODO: ship the data if it changed since the last update
if( true == skydome.is_dirty() ) {
if( ( m_coloursbuffer > 0 ) && ( m_coloursbuffer != (GLuint)-1 ) ) {
::glBindBuffer( GL_ARRAY_BUFFER, m_coloursbuffer );
auto &colors{ skydome.colors() };
/*
float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f;
auto gamma = std::lerp( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
for( auto & color : colors ) {
color = glm::pow( color, gamma );
}
*/
::glBufferSubData( GL_ARRAY_BUFFER, 0, colors.size() * sizeof( glm::vec3 ), colors.data() );
skydome.is_dirty() = false;
if (true == skydome.is_dirty() && ( m_coloursbuffer > 0 ) && ( m_coloursbuffer != (GLuint)-1 )) {
::glBindBuffer( GL_ARRAY_BUFFER, m_coloursbuffer );
auto &colors{ skydome.colors() };
/*
float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f;
auto gamma = std::lerp( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
for( auto & color : colors ) {
color = glm::pow( color, gamma );
}
*/
::glBufferSubData( GL_ARRAY_BUFFER, 0, colors.size() * sizeof( glm::vec3 ), colors.data() );
skydome.is_dirty() = false;
}
// cleanup
::glPopClientAttrib();

View File

@@ -290,11 +290,9 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) {
bool
TGauge::UpdateValue( float fNewDesired, std::optional<sound_source> &Fallbacksound ) {
if( false == UpdateValue( fNewDesired ) ) {
if( Fallbacksound ) {
Fallbacksound->play( m_soundtype );
return true;
}
if (false == UpdateValue( fNewDesired ) && Fallbacksound) {
Fallbacksound->play( m_soundtype );
return true;
}
return false;
}

View File

@@ -1007,13 +1007,10 @@ void TTrain::set_train_brake(double const Position)
return;
}
if (true == is_eztoer() && false == ((originalbrakeposition / 100 == 0 || originalbrakeposition / 100 >= 5) && (mvOccupied->BrakeCtrlPos == 0 || mvOccupied->BrakeCtrlPos >= 5)))
// sound feedback if the lever movement activates one of the switches
if (true == is_eztoer() && false == ((originalbrakeposition / 100 == 0 || originalbrakeposition / 100 >= 5) && (mvOccupied->BrakeCtrlPos == 0 || mvOccupied->BrakeCtrlPos >= 5)) && dsbPneumaticSwitch)
{
// sound feedback if the lever movement activates one of the switches
if (dsbPneumaticSwitch)
{
dsbPneumaticSwitch->play();
}
dsbPneumaticSwitch->play();
}
}
@@ -1031,24 +1028,21 @@ void TTrain::zero_charging_train_brake()
void TTrain::set_train_brake_speed(TDynamicObject *Vehicle, int const Speed)
{
if (true == Vehicle->MoverParameters->BrakeDelaySwitch(Speed))
// visual feedback
// TODO: add setting indicator to vehicle class, for external lever/indicator
if (true == Vehicle->MoverParameters->BrakeDelaySwitch(Speed) && Vehicle == DynamicObject)
{
// visual feedback
// TODO: add setting indicator to vehicle class, for external lever/indicator
if (Vehicle == DynamicObject)
if (ggBrakeProfileCtrl.SubModel != nullptr)
{
if (ggBrakeProfileCtrl.SubModel != nullptr)
{
ggBrakeProfileCtrl.UpdateValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 2.0 : static_cast<float>(mvOccupied->BrakeDelayFlag - 1), dsbSwitch);
}
if (ggBrakeProfileG.SubModel != nullptr)
{
ggBrakeProfileG.UpdateValue(mvOccupied->BrakeDelayFlag == bdelay_G ? 1.0 : 0.0, dsbSwitch);
}
if (ggBrakeProfileR.SubModel != nullptr)
{
ggBrakeProfileR.UpdateValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 1.0 : 0.0, dsbSwitch);
}
ggBrakeProfileCtrl.UpdateValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 2.0 : static_cast<float>(mvOccupied->BrakeDelayFlag - 1), dsbSwitch);
}
if (ggBrakeProfileG.SubModel != nullptr)
{
ggBrakeProfileG.UpdateValue(mvOccupied->BrakeDelayFlag == bdelay_G ? 1.0 : 0.0, dsbSwitch);
}
if (ggBrakeProfileR.SubModel != nullptr)
{
ggBrakeProfileR.UpdateValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 1.0 : 0.0, dsbSwitch);
}
}
}
@@ -1109,13 +1103,9 @@ void TTrain::OnCommand_aidriverenable(TTrain *Train, command_data const &Command
void TTrain::OnCommand_aidriverdisable(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
{
// on press
if (Train->DynamicObject->Mechanik)
Train->DynamicObject->Mechanik->TakeControl(false);
}
// on press
if (Command.action == GLFW_PRESS && Train->DynamicObject->Mechanik)
Train->DynamicObject->Mechanik->TakeControl(false);
}
auto const EU07_CONTROLLER_BASERETURNDELAY{0.5f};
@@ -1624,13 +1614,10 @@ void TTrain::OnCommand_secondcontrollerdecrease(TTrain *Train, command_data cons
if (Train->ggScndCtrl.is_push())
{
// basic push control can't decrease state, but pushtoggle can
if (true == Train->ggScndCtrl.is_toggle())
if (true == Train->ggScndCtrl.is_toggle() && Command.action == GLFW_PRESS)
{
if (Command.action == GLFW_PRESS)
{
// activate on press
Train->mvControlled->DecScndCtrl(1);
}
// activate on press
Train->mvControlled->DecScndCtrl(1);
}
}
// toggle control type
@@ -2348,20 +2335,17 @@ void TTrain::OnCommand_autosandboxdeactivate(TTrain *Train, command_data const &
void TTrain::OnCommand_epbrakecontrolenable(TTrain *Train, command_data const &Command)
{
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
if (Command.action == GLFW_PRESS)
// command only works for bistable switch
if (Command.action == GLFW_PRESS && istoggle)
{
// command only works for bistable switch
if (istoggle)
if (Train->mvOccupied->EpFuseSwitch(true))
{
if (Train->mvOccupied->EpFuseSwitch(true))
// audio feedback
if (Train->dsbPneumaticSwitch)
{
// audio feedback
if (Train->dsbPneumaticSwitch)
{
Train->dsbPneumaticSwitch->play();
}
Train->ggEPFuseButton.UpdateValue(1.0f, Train->dsbSwitch);
Train->dsbPneumaticSwitch->play();
}
Train->ggEPFuseButton.UpdateValue(1.0f, Train->dsbSwitch);
}
}
}
@@ -2369,15 +2353,12 @@ void TTrain::OnCommand_epbrakecontrolenable(TTrain *Train, command_data const &C
void TTrain::OnCommand_epbrakecontroldisable(TTrain *Train, command_data const &Command)
{
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
if (Command.action == GLFW_PRESS)
// command only works for bistable switch
if (Command.action == GLFW_PRESS && istoggle)
{
// command only works for bistable switch
if (istoggle)
if (Train->mvOccupied->EpFuseSwitch(false))
{
if (Train->mvOccupied->EpFuseSwitch(false))
{
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
}
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
}
}
}
@@ -2401,13 +2382,10 @@ void TTrain::OnCommand_epbrakecontroltoggle(TTrain *Train, command_data const &C
if (false == Train->mvOccupied->EpFuse)
{
// turn on
if (Train->mvOccupied->EpFuseSwitch(true))
// audio feedback
if (Train->mvOccupied->EpFuseSwitch(true) && Train->dsbPneumaticSwitch)
{
// audio feedback
if (Train->dsbPneumaticSwitch)
{
Train->dsbPneumaticSwitch->play();
}
Train->dsbPneumaticSwitch->play();
}
}
else
@@ -2419,13 +2397,10 @@ void TTrain::OnCommand_epbrakecontroltoggle(TTrain *Train, command_data const &C
else if (ispush)
{
// potentially turn on
if (Train->mvOccupied->EpFuseSwitch(true))
// audio feedback
if (Train->mvOccupied->EpFuseSwitch(true) && Train->dsbPneumaticSwitch)
{
// audio feedback
if (Train->dsbPneumaticSwitch)
{
Train->dsbPneumaticSwitch->play();
}
Train->dsbPneumaticSwitch->play();
}
}
// visual feedback
@@ -2434,45 +2409,36 @@ void TTrain::OnCommand_epbrakecontroltoggle(TTrain *Train, command_data const &C
0.0f, // toggle
Train->dsbSwitch);
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && ispush)
{
if (ispush)
{
// return the switch to neutral position
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
}
// return the switch to neutral position
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
}
}
void TTrain::OnCommand_trainbrakeoperationmodeincrease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if (Command.action == GLFW_PRESS && (Train->mvOccupied->BrakeOpModeFlag << 1 & Train->mvOccupied->BrakeOpModes) != 0)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if ((Train->mvOccupied->BrakeOpModeFlag << 1 & Train->mvOccupied->BrakeOpModes) != 0)
{
// next mode
Train->mvOccupied->BrakeOpModeFlag <<= 1;
// visual feedback
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(Train->mvOccupied->BrakeOpModeFlag)) : 0); // audio fallback
}
// next mode
Train->mvOccupied->BrakeOpModeFlag <<= 1;
// visual feedback
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(Train->mvOccupied->BrakeOpModeFlag)) : 0); // audio fallback
}
}
void TTrain::OnCommand_trainbrakeoperationmodedecrease(TTrain *Train, command_data const &Command)
{
if (Command.action == GLFW_PRESS)
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if (Command.action == GLFW_PRESS && (Train->mvOccupied->BrakeOpModeFlag >> 1 & Train->mvOccupied->BrakeOpModes) != 0)
{
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if ((Train->mvOccupied->BrakeOpModeFlag >> 1 & Train->mvOccupied->BrakeOpModes) != 0)
{
// previous mode
Train->mvOccupied->BrakeOpModeFlag >>= 1;
// visual feedback
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(Train->mvOccupied->BrakeOpModeFlag)) : 0);
}
// previous mode
Train->mvOccupied->BrakeOpModeFlag >>= 1;
// visual feedback
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(Train->mvOccupied->BrakeOpModeFlag)) : 0);
}
}
@@ -2671,14 +2637,11 @@ void TTrain::OnCommand_reverserincrease(TTrain *Train, command_data const &Comma
return;
}
if (Train->mvOccupied->DirectionForward())
// aktualizacja skrajnych pojazdów w składzie
if (Train->mvOccupied->DirectionForward() && Train->mvOccupied->DirActive && Train->DynamicObject->Mechanik)
{
// aktualizacja skrajnych pojazdów w składzie
if (Train->mvOccupied->DirActive && Train->DynamicObject->Mechanik)
{
Train->DynamicObject->Mechanik->DirectionChange();
}
Train->DynamicObject->Mechanik->DirectionChange();
}
}
}
@@ -2696,14 +2659,11 @@ void TTrain::OnCommand_reverserdecrease(TTrain *Train, command_data const &Comma
return;
}
if (Train->mvOccupied->DirectionBackward())
// aktualizacja skrajnych pojazdów w składzie
if (Train->mvOccupied->DirectionBackward() && Train->mvOccupied->DirActive && Train->DynamicObject->Mechanik)
{
// aktualizacja skrajnych pojazdów w składzie
if (Train->mvOccupied->DirActive && Train->DynamicObject->Mechanik)
{
Train->DynamicObject->Mechanik->DirectionChange();
}
Train->DynamicObject->Mechanik->DirectionChange();
}
}
}
@@ -3109,13 +3069,10 @@ void TTrain::OnCommand_cabactivationenable(TTrain *Train, command_data const &Co
Train->Dynamic()->SetLights();
}
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && Train->ggCabActivationButton.type() == TGaugeType::push)
{
if (Train->ggCabActivationButton.type() == TGaugeType::push)
{
// return the switch to neutral position
Train->ggCabActivationButton.UpdateValue(0.5f);
}
// return the switch to neutral position
Train->ggCabActivationButton.UpdateValue(0.5f);
}
}
@@ -3136,13 +3093,10 @@ void TTrain::OnCommand_cabactivationdisable(TTrain *Train, command_data const &C
Train->Dynamic()->SetLights();
}
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && Train->ggCabActivationButton.type() == TGaugeType::push)
{
if (Train->ggCabActivationButton.type() == TGaugeType::push)
{
// return the switch to neutral position
Train->ggCabActivationButton.UpdateValue(0.5f);
}
// return the switch to neutral position
Train->ggCabActivationButton.UpdateValue(0.5f);
}
}
@@ -3838,12 +3792,9 @@ void TTrain::OnCommand_linebreakerclose(TTrain *Train, command_data const &Comma
// setup with two separate switches
Train->ggMainOnButton.UpdateValue(0.0, Train->dsbSwitch);
}
else if (Train->ggMainButton.SubModel != nullptr)
else if (Train->ggMainButton.SubModel != nullptr && Train->ggMainButton.type() != TGaugeType::toggle)
{
if (Train->ggMainButton.type() != TGaugeType::toggle)
{
Train->ggMainButton.UpdateValue(0.5, Train->dsbSwitch);
}
Train->ggMainButton.UpdateValue(0.5, Train->dsbSwitch);
}
if (Train->m_linebreakerstate == 1)
@@ -3851,16 +3802,13 @@ void TTrain::OnCommand_linebreakerclose(TTrain *Train, command_data const &Comma
return;
} // already in the desired state
if (Train->m_linebreakerstate == 2)
// we don't need to start the diesel twice, but the other types (with impulse switch setup) still need to be launched
// NOTE: this behaviour should depend on MainOnButton presence and type_delayed
// TODO: change it when/if vehicle definition files get their proper switch types
if (Train->m_linebreakerstate == 2 && Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor)
{
// we don't need to start the diesel twice, but the other types (with impulse switch setup) still need to be launched
// NOTE: this behaviour should depend on MainOnButton presence and type_delayed
// TODO: change it when/if vehicle definition files get their proper switch types
if (Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor)
{
// try to finalize state change of the line breaker, set the state based on the outcome
Train->m_linebreakerstate = Train->mvControlled->MainSwitch(true) ? 1 : 0;
}
// try to finalize state change of the line breaker, set the state based on the outcome
Train->m_linebreakerstate = Train->mvControlled->MainSwitch(true) ? 1 : 0;
}
// on button release reset the closing timer
Train->fMainRelayTimer = 0.0f;
@@ -6402,15 +6350,12 @@ void TTrain::OnCommand_compartmentlightsenable(TTrain *Train, command_data const
}
else if (Command.action == GLFW_RELEASE)
{
if (Train->m_controlmapper.contains("compartmentlights_sw:"))
if (Train->m_controlmapper.contains("compartmentlights_sw:") && Train->ggCompartmentLightsButton.type() == TGaugeType::push)
{
if (Train->ggCompartmentLightsButton.type() == TGaugeType::push)
{
// return the switch to neutral position
Train->mvOccupied->CompartmentLightsSwitch(false);
Train->mvOccupied->CompartmentLightsSwitchOff(false);
Train->ggCompartmentLightsButton.UpdateValue(0.5f);
}
// return the switch to neutral position
Train->mvOccupied->CompartmentLightsSwitch(false);
Train->mvOccupied->CompartmentLightsSwitchOff(false);
Train->ggCompartmentLightsButton.UpdateValue(0.5f);
}
if (Train->m_controlmapper.contains("compartmentlightson_sw:"))
{
@@ -6446,15 +6391,12 @@ void TTrain::OnCommand_compartmentlightsdisable(TTrain *Train, command_data cons
}
else if (Command.action == GLFW_RELEASE)
{
if (Train->m_controlmapper.contains("compartmentlights_sw:"))
if (Train->m_controlmapper.contains("compartmentlights_sw:") && Train->ggCompartmentLightsButton.type() == TGaugeType::push)
{
if (Train->ggCompartmentLightsButton.type() == TGaugeType::push)
{
// return the switch to neutral position
Train->mvOccupied->CompartmentLightsSwitch(false);
Train->mvOccupied->CompartmentLightsSwitchOff(false);
Train->ggCompartmentLightsButton.UpdateValue(0.5f);
}
// return the switch to neutral position
Train->mvOccupied->CompartmentLightsSwitch(false);
Train->mvOccupied->CompartmentLightsSwitchOff(false);
Train->ggCompartmentLightsButton.UpdateValue(0.5f);
}
if (Train->m_controlmapper.contains("compartmentlightsoff_sw:"))
{
@@ -6682,15 +6624,11 @@ void TTrain::OnCommand_heatingtoggle(TTrain *Train, command_data const &Command)
OnCommand_heatingdisable(Train, Command);
}
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && Train->ggTrainHeatingButton.type() == TGaugeType::push)
{
if (Train->ggTrainHeatingButton.type() == TGaugeType::push)
{
// impulse switch
// visual feedback
Train->ggTrainHeatingButton.UpdateValue(0.0, Train->dsbSwitch);
}
// impulse switch
// visual feedback
Train->ggTrainHeatingButton.UpdateValue(0.0, Train->dsbSwitch);
}
}
@@ -6759,16 +6697,12 @@ void TTrain::OnCommand_generictoggle(TTrain *Train, command_data const &Command)
}
}
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && item.type() == TGaugeType::push)
{
if (item.type() == TGaugeType::push)
{
// impulse switch
// turn off
// visual feedback
item.UpdateValue(0.0);
}
// impulse switch
// turn off
// visual feedback
item.UpdateValue(0.0);
}
}
@@ -7230,17 +7164,13 @@ void TTrain::OnCommand_doorpermitleft(TTrain *Train, command_data const &Command
Train->ggDoorLeftPermitButton.UpdateValue(newstate ? 1.0 : 0.0, Train->dsbSwitch);
}
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && Train->ggDoorLeftPermitButton.is_push())
{
if (Train->ggDoorLeftPermitButton.is_push())
{
// impulse switch
// visual feedback
Train->ggDoorLeftPermitButton.UpdateValue(0.0, Train->dsbSwitch);
// reset potential remote door control timer
Train->m_doorpermittimers[side] = -1.f;
}
// impulse switch
// visual feedback
Train->ggDoorLeftPermitButton.UpdateValue(0.0, Train->dsbSwitch);
// reset potential remote door control timer
Train->m_doorpermittimers[side] = -1.f;
}
}
@@ -7280,17 +7210,13 @@ void TTrain::OnCommand_doorpermitright(TTrain *Train, command_data const &Comman
Train->ggDoorRightPermitButton.UpdateValue(newstate ? 1.0 : 0.0, Train->dsbSwitch);
}
}
else if (Command.action == GLFW_RELEASE)
else if (Command.action == GLFW_RELEASE && Train->ggDoorRightPermitButton.type() == TGaugeType::push)
{
if (Train->ggDoorRightPermitButton.type() == TGaugeType::push)
{
// impulse switch
// visual feedback
Train->ggDoorRightPermitButton.UpdateValue(0.0, Train->dsbSwitch);
// reset potential remote door control timer
Train->m_doorpermittimers[side] = -1.f;
}
// impulse switch
// visual feedback
Train->ggDoorRightPermitButton.UpdateValue(0.0, Train->dsbSwitch);
// reset potential remote door control timer
Train->m_doorpermittimers[side] = -1.f;
}
}
@@ -8398,15 +8324,11 @@ void TTrain::UpdateCab()
// Ra: przesiadka, jeśli AI zmieniło kabinę (a człon?)...
if (DynamicObject->Mechanik // może nie być?
&& DynamicObject->Mechanik->AIControllFlag)
&& DynamicObject->Mechanik->AIControllFlag && iCabn != ( // numer kabiny (-1: kabina B)
mvOccupied->CabOccupied == -1 ? 2 : mvOccupied->CabOccupied))
{
if (iCabn != ( // numer kabiny (-1: kabina B)
mvOccupied->CabOccupied == -1 ? 2 : mvOccupied->CabOccupied))
{
InitializeCab(mvOccupied->CabOccupied, mvOccupied->TypeName + ".mmd");
}
InitializeCab(mvOccupied->CabOccupied, mvOccupied->TypeName + ".mmd");
}
iCabn = mvOccupied->CabOccupied == -1 ? 2 : mvOccupied->CabOccupied;
}
@@ -8415,22 +8337,16 @@ bool TTrain::Update(double const Deltatime)
{
// train state update
// line breaker:
if (m_linebreakerstate == 0)
if (m_linebreakerstate == 0 && true == mvControlled->Mains)
{
if (true == mvControlled->Mains)
{
// crude way to sync state of the linebreaker with ai-issued commands
m_linebreakerstate = 1;
}
// crude way to sync state of the linebreaker with ai-issued commands
m_linebreakerstate = 1;
}
if (m_linebreakerstate == 1)
if (m_linebreakerstate == 1 && false == (mvControlled->Mains || mvControlled->dizel_startup))
{
if (false == (mvControlled->Mains || mvControlled->dizel_startup))
{
// 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 = 0;
}
// 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 = 0;
}
if ((ggMainButton.SubModel != nullptr && ggMainButton.GetDesiredValue() > 0.95) ||
@@ -8453,24 +8369,18 @@ bool TTrain::Update(double const Deltatime)
// if the button disconnecting the line breaker is down prevent the timer from accumulating
fMainRelayTimer = 0.0f;
}
if (m_linebreakerstate == 0)
if (m_linebreakerstate == 0 && fMainRelayTimer > mvControlled->InitialCtrlDelay)
{
if (fMainRelayTimer > mvControlled->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 = 2;
}
// 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 = 2;
}
if (m_linebreakerstate == 2)
// 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 == 2 && (ggMainOnButton.SubModel == nullptr || mvControlled->EngineType != TEngineType::ElectricSeriesMotor))
{
// 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 (ggMainOnButton.SubModel == nullptr || mvControlled->EngineType != TEngineType::ElectricSeriesMotor)
{
// try to finalize state change of the line breaker, set the state based on the outcome
m_linebreakerstate = mvControlled->MainSwitch(true) ? 1 : 0;
}
// try to finalize state change of the line breaker, set the state based on the outcome
m_linebreakerstate = mvControlled->MainSwitch(true) ? 1 : 0;
}
// door permits
for (auto idx = 0; idx < 2; ++idx)
@@ -8544,34 +8454,31 @@ bool TTrain::Update(double const Deltatime)
UpdateCab();
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag)
// nie blokujemy AI
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag && (mvOccupied->TrainType == dt_ET40 || mvOccupied->TrainType == dt_EP05 || mvOccupied->HasCamshaft))
{
// nie blokujemy AI
if (mvOccupied->TrainType == dt_ET40 || mvOccupied->TrainType == dt_EP05 || mvOccupied->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))
{
// 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 -= static_cast<float>(Deltatime);
if (m_mastercontrollerreturndelay < 0.f)
m_mastercontrollerreturndelay = EU07_CONTROLLER_BASERETURNDELAY;
if (mvOccupied->MainCtrlPos > mvOccupied->MainCtrlActualPos)
{
m_mastercontrollerreturndelay = EU07_CONTROLLER_BASERETURNDELAY;
if (mvOccupied->MainCtrlPos > mvOccupied->MainCtrlActualPos)
{
mvOccupied->DecMainCtrl(1);
}
else if (mvOccupied->MainCtrlPos < mvOccupied->MainCtrlActualPos)
{
// Ra 15-01: a to nie miało być tylko cofanie?
mvOccupied->IncMainCtrl(1);
}
mvOccupied->DecMainCtrl(1);
}
else if (mvOccupied->MainCtrlPos < mvOccupied->MainCtrlActualPos)
{
// Ra 15-01: a to nie miało być tylko cofanie?
mvOccupied->IncMainCtrl(1);
}
}
}
@@ -8842,46 +8749,41 @@ bool TTrain::Update(double const Deltatime)
// youBy - prad w drugim czlonie: galaz lub calosc
{
TDynamicObject *tmp{nullptr};
if (DynamicObject->NextConnected())
if (TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == 1)
tmp = DynamicObject->NextConnected();
if (DynamicObject->PrevConnected())
if (TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == -1)
tmp = DynamicObject->PrevConnected();
if (tmp)
if (DynamicObject->NextConnected() && TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == 1)
tmp = DynamicObject->NextConnected();
if (DynamicObject->PrevConnected() && TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == -1)
tmp = DynamicObject->PrevConnected();
if (tmp && tmp->MoverParameters->Power > 0)
{
if (tmp->MoverParameters->Power > 0)
if (ggI1B.SubModel)
{
if (ggI1B.SubModel)
{
ggI1B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(1)));
ggI1B.Update();
}
if (ggI2B.SubModel)
{
ggI2B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(2)));
ggI2B.Update();
}
if (ggI3B.SubModel)
{
ggI3B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(3)));
ggI3B.Update();
}
if (ggItotalB.SubModel)
{
ggItotalB.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(0)));
ggItotalB.Update();
}
if (ggWater1TempB.SubModel)
{
ggWater1TempB.UpdateValue(tmp->MoverParameters->dizel_heat.temperatura1);
ggWater1TempB.Update();
}
if (ggOilPressB.SubModel)
{
ggOilPressB.UpdateValue(tmp->MoverParameters->OilPump.pressure);
ggOilPressB.Update();
}
ggI1B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(1)));
ggI1B.Update();
}
if (ggI2B.SubModel)
{
ggI2B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(2)));
ggI2B.Update();
}
if (ggI3B.SubModel)
{
ggI3B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(3)));
ggI3B.Update();
}
if (ggItotalB.SubModel)
{
ggItotalB.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(0)));
ggItotalB.Update();
}
if (ggWater1TempB.SubModel)
{
ggWater1TempB.UpdateValue(tmp->MoverParameters->dizel_heat.temperatura1);
ggWater1TempB.Update();
}
if (ggOilPressB.SubModel)
{
ggOilPressB.UpdateValue(tmp->MoverParameters->OilPump.pressure);
ggOilPressB.Update();
}
}
}
@@ -8975,13 +8877,10 @@ bool TTrain::Update(double const Deltatime)
{
// Ra 2014-12: lokomotywy 181/182 dostają SlippingWheels po zahamowaniu powyżej 2.85 bara i buczały
double veldiff = (DynamicObject->GetVelocity() - fTachoVelocity) / mvControlled->Vmax;
if (veldiff < -0.01)
// 1% Vmax rezerwy, żeby 181/182 nie buczały po zahamowaniu, ale to proteza
if (veldiff < -0.01 && std::abs(mvControlled->Im) > 10.0)
{
// 1% Vmax rezerwy, żeby 181/182 nie buczały po zahamowaniu, ale to proteza
if (std::abs(mvControlled->Im) > 10.0)
{
btLampkaPoslizg.Turn(true);
}
btLampkaPoslizg.Turn(true);
}
}
else
@@ -9734,12 +9633,9 @@ bool TTrain::Update(double const Deltatime)
}
// anti slip system activation, maintained while the control button is down
if (mvOccupied->BrakeSystem != TBrakeSystem::ElectroPneumatic)
if (mvOccupied->BrakeSystem != TBrakeSystem::ElectroPneumatic && ggAntiSlipButton.GetDesiredValue() > 0.95)
{
if (ggAntiSlipButton.GetDesiredValue() > 0.95)
{
mvControlled->AntiSlippingBrake();
}
mvControlled->AntiSlippingBrake();
}
// screens
@@ -10140,15 +10036,12 @@ void TTrain::update_sounds(double const Deltatime)
else
{
// stop power-reliant sounds if power is cut
if (dsbBuzzer)
if (dsbBuzzer && true == dsbBuzzer->is_playing())
{
if (true == dsbBuzzer->is_playing())
{
dsbBuzzer->stop();
dsbBuzzer->stop();
#ifdef _WIN32
Console::BitsClear(1 << 14); // ustawienie bitu 16 na PoKeys
Console::BitsClear(1 << 14); // ustawienie bitu 16 na PoKeys
#endif
}
}
if (dsbBuzzerShp && dsbBuzzerShp->is_playing())
@@ -10307,15 +10200,12 @@ bool TTrain::CabChange(int iDirection)
else
{ // jeśli pojazd prowadzony ręcznie albo wcale (wagon)
mvOccupied->CabDeactivisationAuto();
if (mvOccupied->ChangeCab(iDirection))
if (mvOccupied->ChangeCab(iDirection) && InitializeCab(mvOccupied->CabOccupied, mvOccupied->TypeName + ".mmd"))
{
if (InitializeCab(mvOccupied->CabOccupied, mvOccupied->TypeName + ".mmd"))
{
// zmiana kabiny w ramach tego samego pojazdu
mvOccupied->CabActivisationAuto(); // załączenie rozrządu (wirtualne kabiny)
DynamicObject->Mechanik->DirectionChange();
return true; // udało się zmienić kabinę
}
// zmiana kabiny w ramach tego samego pojazdu
mvOccupied->CabActivisationAuto(); // załączenie rozrządu (wirtualne kabiny)
DynamicObject->Mechanik->DirectionChange();
return true; // udało się zmienić kabinę
}
// aktywizacja poprzedniej, bo jeszcze nie wiadomo, czy jakiś pojazd jest
mvOccupied->CabActivisationAuto();
@@ -12280,15 +12170,12 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
else if (Label == "clock:")
{
// zegar analogowy
if (Parser.getToken<std::string>() == "analog")
if (Parser.getToken<std::string>() == "analog" && DynamicObject->mdKabina)
{
if (DynamicObject->mdKabina)
{
// McZapkie-300302: zegarek
ggClockSInd.Init(DynamicObject->mdKabina->GetFromName("ClockShand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 60.0));
ggClockMInd.Init(DynamicObject->mdKabina->GetFromName("ClockMhand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 60.0));
ggClockHInd.Init(DynamicObject->mdKabina->GetFromName("ClockHhand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 12.0));
}
// McZapkie-300302: zegarek
ggClockSInd.Init(DynamicObject->mdKabina->GetFromName("ClockShand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 60.0));
ggClockMInd.Init(DynamicObject->mdKabina->GetFromName("ClockMhand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 60.0));
ggClockHInd.Init(DynamicObject->mdKabina->GetFromName("ClockHhand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 12.0));
}
}
else if (Label == "clock_seconds:")

View File

@@ -195,12 +195,10 @@ bool TEventLauncher::check_activation() {
else {
// jeśli nie cykliczny, to sprawdzić czas
if( simulation::Time.data().wHour == iHour ) {
if( simulation::Time.data().wMinute == iMinute ) {
// zgodność czasu uruchomienia
if( UpdatedTime < 10 ) {
UpdatedTime = 20; // czas do kolejnego wyzwolenia?
bCond = true;
}
// zgodność czasu uruchomienia
if (simulation::Time.data().wMinute == iMinute && UpdatedTime < 10) {
UpdatedTime = 20; // czas do kolejnego wyzwolenia?
bCond = true;
}
}
else {

View File

@@ -502,13 +502,12 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
glm::normalize( norm ),
glm::vec2 { ( jmm1 * ShapePoints[ j ].texture.x + m1 * ShapePoints[ j + iNumShapePoints ].texture.x ) / texturescale, tv1 } );
}
if( p ) // jeśli jest wskaźnik do tablicy
if( *p )
if( !j ) // to dla pierwszego punktu
{
**p = pt;
( *p )++;
} // zapamiętanie brzegu jezdni
// jeśli jest wskaźnik do tablicy
if (p && *p && !j) // to dla pierwszego punktu
{
**p = pt;
( *p )++;
} // zapamiętanie brzegu jezdni
// dla trapezu drugi koniec ma inne współrzędne
pt = parallel2 * ( jmm2 * ( ShapePoints[ j ].position.x - fOffsetX.first ) + m2 * ( ShapePoints[ j + iNumShapePoints ].position.x - fOffsetX.second ) ) + pos2;
pt.y += jmm2 * ShapePoints[ j ].position.y + m2 * ShapePoints[ j + iNumShapePoints ].position.y;
@@ -521,13 +520,12 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
glm::normalize( norm ),
glm::vec2 { ( jmm2 * ShapePoints[ j ].texture.x + m2 * ShapePoints[ j + iNumShapePoints ].texture.x ) / texturescale, tv2 } );
}
if( p ) // jeśli jest wskaźnik do tablicy
if( *p )
if( !j ) // to dla pierwszego punktu
if( i == iSegCount ) {
**p = pt;
( *p )++;
} // zapamiętanie brzegu jezdni
// jeśli jest wskaźnik do tablicy
// to dla pierwszego punktu
if (p && *p && !j && i == iSegCount) {
**p = pt;
( *p )++;
} // zapamiętanie brzegu jezdni
}
}
else {

View File

@@ -472,9 +472,8 @@ void TTraction::PowerSet(TTractionPowerSource *ps)
double TTraction::VoltageGet(double u, double i)
{ // pobranie napięcia na przęśle po podłączeniu do niego rezystancji (res) - na razie jest to prąd
if (!psSection)
if (!psPowered)
return NominalVoltage; // jak nie ma zasilacza, to napięcie podane w przęśle
if (!psSection && !psPowered)
return NominalVoltage; // jak nie ma zasilacza, to napięcie podane w przęśle
// na początek można założyć, że wszystkie podstacje mają to samo napięcie i nie płynie prąd
// pomiędzy nimi
// dla danego przęsła mamy 3 źródła zasilania
@@ -740,29 +739,25 @@ traction_table::InitTraction() {
break;
}
}
if( traction->hvNext[ 0 ] ) {
// jeśli został podłączony
if( traction->psSection != nullptr
&& matchingtraction->psSection != nullptr ) {
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if( traction->psSection != matchingtraction->psSection ) {
// połączone odcinki mają różne zasilacze
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint1 ) );
}
}
// jeśli został podłączony
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if (traction->hvNext[ 0 ] && traction->psSection != nullptr
&& matchingtraction->psSection != nullptr && traction->psSection != matchingtraction->psSection) {
// połączone odcinki mają różne zasilacze
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint1 ) );
}
}
}
@@ -779,28 +774,24 @@ traction_table::InitTraction() {
break;
}
}
if( traction->hvNext[ 1 ] ) {
// jeśli został podłączony
if( traction->psSection != nullptr
&& matchingtraction->psSection != nullptr ) {
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if( traction->psSection != matchingtraction->psSection ) {
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint2 ) );
}
}
// jeśli został podłączony
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if (traction->hvNext[ 1 ] && traction->psSection != nullptr
&& matchingtraction->psSection != nullptr && traction->psSection != matchingtraction->psSection) {
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint2 ) );
}
}
}

View File

@@ -565,14 +565,11 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin.close();
}
}
if (ConversionError == 0)
{
if (TimeTable[1].StationName == Relation1) // jeśli nazwa pierwszego zgodna z relacją
if (TimeTable[1].Ah < 0) // a nie podany czas przyjazdu
{ // to mamy zatrzymanie na pierwszym, a nie przelot
TimeTable[1].Ah = TimeTable[1].Dh;
TimeTable[1].Am = TimeTable[1].Dm;
}
// jeśli nazwa pierwszego zgodna z relacją
if (ConversionError == 0 && TimeTable[1].StationName == Relation1 && TimeTable[1].Ah < 0) // a nie podany czas przyjazdu
{ // to mamy zatrzymanie na pierwszym, a nie przelot
TimeTable[1].Ah = TimeTable[1].Dh;
TimeTable[1].Am = TimeTable[1].Dm;
}
//
load_sounds();
@@ -632,9 +629,9 @@ TTrainParameters::load_sounds() {
bool TTrainParameters::DirectionChange() const
// sprawdzenie, czy po zatrzymaniu wykonać kolejne komendy
{
if (StationIndex > 0 && StationIndex < StationCount) // dla ostatniej stacji nie
if (contains( TimeTable[StationIndex].StationWare, '@') )
return true;
// dla ostatniej stacji nie
if (StationIndex > 0 && StationIndex < StationCount && contains( TimeTable[StationIndex].StationWare, '@'))
return true;
return false;
}