17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 09:09:19 +02: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

@@ -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 ) {