18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-22 16:09:52 +01:00

refactor(sonar): replace single-case switch statements with if (cpp:S1301)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 17:39:27 +02:00
parent 71d4796649
commit 9fec0e925c
3 changed files with 22 additions and 94 deletions

View File

@@ -1715,9 +1715,7 @@ void TMoverParameters::LowVoltagePowerCheck(double const /*Deltatime*/)
auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable};
switch (EngineType) if (EngineType == TEngineType::ElectricSeriesMotor)
{
case TEngineType::ElectricSeriesMotor:
{ {
GroundRelay &= lowvoltagepower; GroundRelay &= lowvoltagepower;
if (GroundRelayStart != start_t::manual) if (GroundRelayStart != start_t::manual)
@@ -1726,12 +1724,6 @@ void TMoverParameters::LowVoltagePowerCheck(double const /*Deltatime*/)
// TODO: generic check method which takes these into account // TODO: generic check method which takes these into account
GroundRelay |= lowvoltagepower; GroundRelay |= lowvoltagepower;
} }
break;
}
default:
{
break;
}
} }
} }
@@ -1780,17 +1772,9 @@ void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, coupling c
} }
} }
// high voltage power sources // high voltage power sources
switch (EnginePowerSource.SourceType) if (EnginePowerSource.SourceType == TPowerSource::CurrentCollector)
{
case TPowerSource::CurrentCollector:
{ {
localvoltage = std::max(localvoltage, PantographVoltage); localvoltage = std::max(localvoltage, PantographVoltage);
break;
}
default:
{
break;
}
} }
break; break;
} }
@@ -2066,9 +2050,7 @@ void TMoverParameters::HeatingCheck(double const /*Timestep*/)
// update heating devices // update heating devices
// TBD, TODO: move this to a separate method? // TBD, TODO: move this to a separate method?
switch (HeatingPowerSource.SourceType) if (HeatingPowerSource.SourceType == TPowerSource::Generator)
{
case TPowerSource::Generator:
{ {
if (HeatingPowerSource.EngineGenerator.engine_revolutions != nullptr && HeatingPowerSource.EngineGenerator.revolutions_max > 0) if (HeatingPowerSource.EngineGenerator.engine_revolutions != nullptr && HeatingPowerSource.EngineGenerator.revolutions_max > 0)
{ {
@@ -2087,12 +2069,6 @@ void TMoverParameters::HeatingCheck(double const /*Timestep*/)
std::clamp((absrevolutions - generator.revolutions_min) / (generator.revolutions_max - generator.revolutions_min), 0.0, 1.0))) * std::clamp((absrevolutions - generator.revolutions_min) / (generator.revolutions_max - generator.revolutions_min), 0.0, 1.0))) *
sign(generator.revolutions); sign(generator.revolutions);
} }
break;
}
default:
{
break;
}
} }
// quick check first to avoid unnecessary calls... // quick check first to avoid unnecessary calls...
@@ -4392,21 +4368,16 @@ void TMoverParameters::CompressorCheck(double dt)
} }
// working compressor adds air to the air reservoir // working compressor adds air to the air reservoir
switch (CompressorPower) if (CompressorPower == 3)
{
case 3:
{ {
// the compressor is coupled with the diesel engine, engine revolutions affect the output // the compressor is coupled with the diesel engine, engine revolutions affect the output
CompressedVolume += CompressedVolume +=
CompressorSpeedF * (2.0 * MaxCompressorF - Compressor) / MaxCompressorF * EngineRPMRatio() * dt * (CompressorGovernorLock ? 0.0 : 1.0); // with the lock active air is vented out CompressorSpeedF * (2.0 * MaxCompressorF - Compressor) / MaxCompressorF * EngineRPMRatio() * dt * (CompressorGovernorLock ? 0.0 : 1.0); // with the lock active air is vented out
break;
} }
default: else
{ {
// the compressor is a stand-alone device, working at steady pace // the compressor is a stand-alone device, working at steady pace
CompressedVolume += CompressorSpeedF * (2.0 * MaxCompressorF - Compressor) / MaxCompressorF * dt; CompressedVolume += CompressorSpeedF * (2.0 * MaxCompressorF - Compressor) / MaxCompressorF * dt;
break;
}
} }
if (pressureistoohigh && (false == governorlockispresent || CompressorPower == 3)) if (pressureistoohigh && (false == governorlockispresent || CompressorPower == 3))
@@ -4424,14 +4395,11 @@ void TMoverParameters::CompressorCheck(double dt)
// tymczasowo tylko obciążenie sprężarki, tak z 5A na sprężarkę // tymczasowo tylko obciążenie sprężarki, tak z 5A na sprężarkę
// TODO: draw power from proper high- or low voltage circuit // TODO: draw power from proper high- or low voltage circuit
switch (CompressorPower) if (CompressorPower == 3)
{
case 3:
{ {
// diesel-powered compressor doesn't draw power // diesel-powered compressor doesn't draw power
break;
} }
default: else
{ {
// TODO: drain power from 110v circuit // TODO: drain power from 110v circuit
/* /*
@@ -4439,8 +4407,6 @@ void TMoverParameters::CompressorCheck(double dt)
compressorowner->TotalCurrent += 0.0015 * compressorowner->PantographVoltage; compressorowner->TotalCurrent += 0.0015 * compressorowner->PantographVoltage;
} }
*/ */
break;
}
} }
} }
@@ -6523,18 +6489,10 @@ double TMoverParameters::TractionForce(double dt)
} }
} // case EngineType } // case EngineType
switch (EngineType) if (EngineType == TEngineType::DieselElectric)
{
case TEngineType::DieselElectric:
{ {
// rough approximation of extra effort to overcome friction etc // rough approximation of extra effort to overcome friction etc
EnginePower += EngineRPMRatio() * 0.15 * DElist[MainCtrlPosNo].GenPower; EnginePower += EngineRPMRatio() * 0.15 * DElist[MainCtrlPosNo].GenPower;
break;
}
default:
{
break;
}
} }
return Ft; return Ft;
@@ -8864,9 +8822,7 @@ bool TMoverParameters::ChangeOffsetH(double DeltaOffset)
std::string TMoverParameters::EngineDescription(int what) const std::string TMoverParameters::EngineDescription(int what) const
{ {
std::string outstr{"OK"}; std::string outstr{"OK"};
switch (what) if (what == 0)
{
case 0:
{ {
if (DamageFlag == 255) if (DamageFlag == 255)
{ {
@@ -8916,13 +8872,10 @@ std::string TMoverParameters::EngineDescription(int what) const
outstr = "DERAILED"; outstr = "DERAILED";
} }
} }
break;
} }
default: else
{ {
outstr = "Invalid qualifier"; outstr = "Invalid qualifier";
break;
}
} }
return outstr; return outstr;
} }
@@ -9066,18 +9019,13 @@ bool TMoverParameters::readMPT0(std::string const &line)
{ {
return false; return false;
} }
switch (EngineType) if (EngineType == TEngineType::DieselEngine)
{
case TEngineType::DieselEngine:
{ {
parser >> MotorParam[idx].mIsat >> MotorParam[idx].fi0 >> MotorParam[idx].fi >> MotorParam[idx].mfi0 >> MotorParam[idx].mfi >> MotorParam[idx].Isat; parser >> MotorParam[idx].mIsat >> MotorParam[idx].fi0 >> MotorParam[idx].fi >> MotorParam[idx].mfi0 >> MotorParam[idx].mfi >> MotorParam[idx].Isat;
break;
} }
default: else
{ {
parser >> MotorParam[idx].mfi >> MotorParam[idx].mIsat >> MotorParam[idx].mfi0 >> MotorParam[idx].fi >> MotorParam[idx].Isat >> MotorParam[idx].fi0; parser >> MotorParam[idx].mfi >> MotorParam[idx].mIsat >> MotorParam[idx].mfi0 >> MotorParam[idx].fi >> MotorParam[idx].Isat >> MotorParam[idx].fi0;
break;
}
} }
if (true == parser.getTokens(1, false)) if (true == parser.getTokens(1, false))
{ {

View File

@@ -330,8 +330,8 @@ smoke_source::initialize( smoke_particle &Particle ) {
if( m_ownertype == owner_type::vehicle ) { if( m_ownertype == owner_type::vehicle ) {
Particle.opacity *= static_cast<float>(m_owner.vehicle->MoverParameters->dizel_fill); Particle.opacity *= static_cast<float>(m_owner.vehicle->MoverParameters->dizel_fill);
switch( m_owner.vehicle->MoverParameters->EngineType ) { if (m_owner.vehicle->MoverParameters->EngineType == TEngineType::DieselElectric)
case TEngineType::DieselElectric: { {
if (m_owner.vehicle->MoverParameters->dizel_spinup == true) if (m_owner.vehicle->MoverParameters->dizel_spinup == true)
{ {
Particle.velocity *= 0.38*(((m_owner.vehicle->MoverParameters->enrot)/2)*0.5); // / m_owner.vehicle->MoverParameters->dizel_fill *0.01)) ; Particle.velocity *= 0.38*(((m_owner.vehicle->MoverParameters->enrot)/2)*0.5); // / m_owner.vehicle->MoverParameters->dizel_fill *0.01)) ;
@@ -344,11 +344,6 @@ smoke_source::initialize( smoke_particle &Particle ) {
//Particle.velocity *= m_owner.vehicle->GetVelocity(); // / m_owner.vehicle->MoverParameters->dizel_fill *0.01)) ; //Particle.velocity *= m_owner.vehicle->GetVelocity(); // / m_owner.vehicle->MoverParameters->dizel_fill *0.01)) ;
} }
break;
}
default: {
break;
}
} }
} }
} }
@@ -365,22 +360,17 @@ smoke_source::update( smoke_particle &Particle, bounding_box &Boundingbox, doubl
// crude smoke dispersion simulation // crude smoke dispersion simulation
// http://www.auburn.edu/academic/forestry_wildlife/fire/smoke_guide/smoke_dispersion.htm // http://www.auburn.edu/academic/forestry_wildlife/fire/smoke_guide/smoke_dispersion.htm
switch (m_ownertype) if (m_ownertype == owner_type::vehicle)
{
case owner_type::vehicle:
{ {
Particle.velocity.y += static_cast<float>(( 0.025 * Particle.velocity.y ) * std::min( 0.f, Global.AirTemperature - 90 ) * Timedelta); // decelerate faster in cold weather Particle.velocity.y += static_cast<float>(( 0.025 * Particle.velocity.y ) * std::min( 0.f, Global.AirTemperature - 90 ) * Timedelta); // decelerate faster in cold weather
Particle.velocity.y -= static_cast<float>(( (0.05 * (pow(m_owner.vehicle->GetVelocity()*1,0.4))) * Particle.velocity.y ) * Global.Overcast * Timedelta); // decelerate faster with high air humidity and/or precipitation Particle.velocity.y -= static_cast<float>(( (0.05 * (pow(m_owner.vehicle->GetVelocity()*1,0.4))) * Particle.velocity.y ) * Global.Overcast * Timedelta); // decelerate faster with high air humidity and/or precipitation
break; }
} else
default:
{ {
Particle.velocity.y += static_cast<float>(( 0.005 * Particle.velocity.y ) * std::min( 0.f, Global.AirTemperature - 10 ) * Timedelta); // decelerate faster in cold weather Particle.velocity.y += static_cast<float>(( 0.005 * Particle.velocity.y ) * std::min( 0.f, Global.AirTemperature - 10 ) * Timedelta); // decelerate faster in cold weather
Particle.velocity.y -= static_cast<float>(( 0.050 * Particle.velocity.y ) * Global.Overcast * Timedelta); // decelerate faster with high air humidity and/or precipitation Particle.velocity.y -= static_cast<float>(( 0.050 * Particle.velocity.y ) * Global.Overcast * Timedelta); // decelerate faster with high air humidity and/or precipitation
Particle.velocity.y = std::max<float>( static_cast<float>(0.25 * ( 2.f - Global.Overcast )), Particle.velocity.y ); // put a cap on deceleration Particle.velocity.y = std::max<float>( static_cast<float>(0.25 * ( 2.f - Global.Overcast )), Particle.velocity.y ); // put a cap on deceleration
break; }
}
}
Particle.position += Particle.velocity * static_cast<float>( Timedelta ); Particle.position += Particle.velocity * static_cast<float>( Timedelta );
Particle.position += 0.1f * Particle.age * simulation::Environment.wind() * static_cast<float>( Timedelta ); Particle.position += 0.1f * Particle.age * simulation::Environment.wind() * static_cast<float>( Timedelta );

View File

@@ -2062,18 +2062,13 @@ void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_dat
} }
} }
void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_data const &Command) void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_data const &Command)
{
{ {
if (Command.action != GLFW_RELEASE) if (Command.action != GLFW_RELEASE)
{ {
if (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a) if (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 - 0.01, -1.5, 2.0);
break;
{ {
Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 - 0.01, -1.5, 2.0); Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 - 0.01, -1.5, 2.0);
} }
@@ -2084,18 +2079,13 @@ void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_dat
} }
} }
void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_data const &Command) void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_data const &Command)
{
{ {
if (Command.action != GLFW_RELEASE) if (Command.action != GLFW_RELEASE)
{ {
if (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a) if (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 + 0.01, -1.5, 2.0);
break;
{ {
Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 + 0.01, -1.5, 2.0); Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 + 0.01, -1.5, 2.0);
} }