From 1ceb0581f466b9f34cfe9ca601853f4fa199507b Mon Sep 17 00:00:00 2001 From: BevapDin Date: Fri, 20 Dec 2019 21:21:15 +0100 Subject: [PATCH] Reduce scope of variable. Mostly just make new variables within the blocks. This avoids the need to clear the variable each time. And sometimes just use the string directly. --- src/construction.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/construction.cpp b/src/construction.cpp index f9fe16ce43fb1..35c7a5809b253 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -423,7 +423,6 @@ int construction_menu( bool blueprint ) current_con->requirements->can_make_with_inventory( total_inv, is_crafting_component ); std::vector current_buffer; - std::string current_line; const auto add_folded = [&]( const std::vector &folded ) { current_buffer.insert( current_buffer.end(), folded.begin(), folded.end() ); @@ -437,7 +436,7 @@ int construction_menu( bool blueprint ) // in their title what their result is. if( !current_con->post_terrain.empty() && options.size() > 1 ) { //also print out stage number when multiple stages are available - current_line += string_format( _( "Stage/Variant #%d: " ), stage_counter ); + std::string current_line = string_format( _( "Stage/Variant #%d: " ), stage_counter ); // print name of the result of each stage std::string result_string; @@ -466,7 +465,7 @@ int construction_menu( bool blueprint ) // display description of the result for single stages } else if( !current_con->post_terrain.empty() ) { - current_line = _( "Result: " ); + std::string current_line = _( "Result: " ); if( current_con->post_is_furniture ) { current_line += colorize( furn_str_id( current_con->post_terrain ).obj().description, @@ -481,14 +480,12 @@ int construction_menu( bool blueprint ) add_line( current_line ); } - current_line.clear(); // display required skill and difficulty if( current_con->required_skills.empty() ) { - current_line += _( "N/A" ); + add_line( _( "N/A" ) ); } else { - current_line += _( "Required skills: " ) + - enumerate_as_string( current_con->required_skills.begin(), - current_con->required_skills.end(), + std::string current_line = _( "Required skills: " ) + enumerate_as_string( + current_con->required_skills.begin(), current_con->required_skills.end(), []( const std::pair &skill ) { nc_color col; int s_lvl = g->u.get_skill_level( skill.first ); @@ -502,9 +499,9 @@ int construction_menu( bool blueprint ) return colorize( string_format( "%s (%d)", skill.first.obj().name(), skill.second ), col ); }, enumeration_conjunction::none ); + add_line( current_line ); } - add_line( current_line ); // TODO: Textify pre_flags to provide a bit more information. // Example: First step of dig pit could say something about // requiring diggable ground. @@ -516,12 +513,10 @@ int construction_menu( bool blueprint ) require_string = ter_str_id( current_con->pre_terrain )->name(); } nc_color pre_color = has_pre_terrain( *current_con ) ? c_green : c_red; - current_line = _( "Requires: " ) + colorize( require_string, pre_color ); - add_line( current_line ); + add_line( _( "Requires: " ) + colorize( require_string, pre_color ) ); } if( !current_con->pre_note.empty() ) { - current_line = _( "Annotation: " ) + colorize( _( current_con->pre_note ), color_data ); - add_line( current_line ); + add_line( _( "Annotation: " ) + colorize( _( current_con->pre_note ), color_data ) ); } // get pre-folded versions of the rest of the construction project to be displayed later