diff --git a/src/character.cpp b/src/character.cpp index fe61dfb87017f..547a5f82fda5a 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -4086,8 +4085,8 @@ hp_part Character::body_window( const std::string &menu_header, e.allowed = false; } - std::stringstream msg; - std::stringstream desc; + std::string msg; + std::string desc; bool bleeding = has_effect( effect_bleed, e.bp ); bool bitten = has_effect( effect_bite, e.bp ); bool infected = has_effect( effect_infected, e.bp ); @@ -4106,90 +4105,90 @@ hp_part Character::body_window( const std::string &menu_header, int new_d_power = static_cast( std::floor( disinfectant_power ) ); const auto &aligned_name = std::string( max_bp_name_len - utf8_width( e.name ), ' ' ) + e.name; - msg << colorize( aligned_name, all_state_col ) << " " << hp_str( current_hp, maximal_hp ); + msg += colorize( aligned_name, all_state_col ) + " " + hp_str( current_hp, maximal_hp ); if( limb_is_broken ) { - desc << colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) << "\n"; + desc += colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) + "\n"; } // BLEEDING block if( bleeding ) { - desc << colorize( string_format( "%s: %s", get_effect( effect_bleed, e.bp ).get_speed_name(), - get_effect( effect_bleed, e.bp ).disp_short_desc() ), c_red ) << "\n"; + desc += colorize( string_format( "%s: %s", get_effect( effect_bleed, e.bp ).get_speed_name(), + get_effect( effect_bleed, e.bp ).disp_short_desc() ), c_red ) + "\n"; if( bleed > 0.0f ) { - desc << colorize( string_format( _( "Chance to stop: %d %%" ), - static_cast( bleed * 100 ) ), c_light_green ) << "\n"; + desc += colorize( string_format( _( "Chance to stop: %d %%" ), + static_cast( bleed * 100 ) ), c_light_green ) + "\n"; } else { - desc << colorize( _( "This will not stop the bleeding." ), - c_yellow ) << "\n"; + desc += colorize( _( "This will not stop the bleeding." ), + c_yellow ) + "\n"; } } // BANDAGE block if( bandaged ) { - desc << string_format( _( "Bandaged [%s]" ), texitify_healing_power( b_power ) ) << "\n"; + desc += string_format( _( "Bandaged [%s]" ), texitify_healing_power( b_power ) ) + "\n"; if( new_b_power > b_power ) { - desc << colorize( string_format( _( "Expected quality improvement: %s" ), - texitify_healing_power( new_b_power ) ), c_light_green ) << "\n"; + desc += colorize( string_format( _( "Expected quality improvement: %s" ), + texitify_healing_power( new_b_power ) ), c_light_green ) + "\n"; } else if( new_b_power > 0 ) { - desc << colorize( _( "You don't expect any improvement from using this." ), c_yellow ) << "\n"; + desc += colorize( _( "You don't expect any improvement from using this." ), c_yellow ) + "\n"; } } else if( new_b_power > 0 && e.allowed ) { - desc << colorize( string_format( _( "Expected bandage quality: %s" ), - texitify_healing_power( new_b_power ) ), c_light_green ) << "\n"; + desc += colorize( string_format( _( "Expected bandage quality: %s" ), + texitify_healing_power( new_b_power ) ), c_light_green ) + "\n"; } // BITTEN block if( bitten ) { - desc << colorize( string_format( "%s: ", get_effect( effect_bite, + desc += colorize( string_format( "%s: ", get_effect( effect_bite, e.bp ).get_speed_name() ), c_red ); - desc << colorize( _( "It has a deep bite wound that needs cleaning." ), c_red ) << "\n"; + desc += colorize( _( "It has a deep bite wound that needs cleaning." ), c_red ) + "\n"; if( bite > 0 ) { - desc << colorize( string_format( _( "Chance to clean and disinfect: %d %%" ), - static_cast( bite * 100 ) ), c_light_green ) << "\n"; + desc += colorize( string_format( _( "Chance to clean and disinfect: %d %%" ), + static_cast( bite * 100 ) ), c_light_green ) + "\n"; } else { - desc << colorize( _( "This will not help in cleaning this wound." ), c_yellow ) << "\n"; + desc += colorize( _( "This will not help in cleaning this wound." ), c_yellow ) + "\n"; } } // INFECTED block if( infected ) { - desc << colorize( string_format( "%s: ", get_effect( effect_infected, + desc += colorize( string_format( "%s: ", get_effect( effect_infected, e.bp ).get_speed_name() ), c_red ); - desc << colorize( _( "It has a deep wound that looks infected. Antibiotics might be required." ), - c_red ) << "\n"; + desc += colorize( _( "It has a deep wound that looks infected. Antibiotics might be required." ), + c_red ) + "\n"; if( infect > 0 ) { - desc << colorize( string_format( _( "Chance to heal infection: %d %%" ), - static_cast( infect * 100 ) ), c_light_green ) << "\n"; + desc += colorize( string_format( _( "Chance to heal infection: %d %%" ), + static_cast( infect * 100 ) ), c_light_green ) + "\n"; } else { - desc << colorize( _( "This will not help in healing infection." ), c_yellow ) << "\n"; + desc += colorize( _( "This will not help in healing infection." ), c_yellow ) + "\n"; } } // DISINFECTANT (general) block if( disinfected ) { - desc << string_format( _( "Disinfected [%s]" ), - texitify_healing_power( d_power ) ) << "\n"; + desc += string_format( _( "Disinfected [%s]" ), + texitify_healing_power( d_power ) ) + "\n"; if( new_d_power > d_power ) { - desc << colorize( string_format( _( "Expected quality improvement: %s" ), - texitify_healing_power( new_d_power ) ), c_light_green ) << "\n"; + desc += colorize( string_format( _( "Expected quality improvement: %s" ), + texitify_healing_power( new_d_power ) ), c_light_green ) + "\n"; } else if( new_d_power > 0 ) { - desc << colorize( _( "You don't expect any improvement from using this." ), - c_yellow ) << "\n"; + desc += colorize( _( "You don't expect any improvement from using this." ), + c_yellow ) + "\n"; } } else if( new_d_power > 0 && e.allowed ) { - desc << colorize( string_format( + desc += colorize( string_format( _( "Expected disinfection quality: %s" ), - texitify_healing_power( new_d_power ) ), c_light_green ) << "\n"; + texitify_healing_power( new_d_power ) ), c_light_green ) + "\n"; } // END of blocks if( ( !e.allowed && !limb_is_broken ) || ( show_all && current_hp == maximal_hp && !limb_is_broken && !bitten && !infected && !bleeding ) ) { - desc << colorize( _( "Healthy." ), c_green ) << "\n"; + desc += colorize( _( "Healthy." ), c_green ) + "\n"; } if( !e.allowed ) { - desc << colorize( _( "You don't expect any effect from using this." ), c_yellow ); + desc += colorize( _( "You don't expect any effect from using this." ), c_yellow ); } else { is_valid_choice = true; } - bmenu.addentry_desc( i, e.allowed, MENU_AUTOASSIGN, msg.str(), desc.str() ); + bmenu.addentry_desc( i, e.allowed, MENU_AUTOASSIGN, msg, desc ); } if( !is_valid_choice ) { // no body part can be chosen for this item/effect @@ -4797,15 +4796,15 @@ std::vector Character::get_all_body_parts( bool only_main ) const std::string Character::extended_description() const { - std::ostringstream ss; + std::string ss; if( is_player() ) { // This is me, . - ss << string_format( _( "This is you - %s." ), name ); + ss += string_format( _( "This is you - %s." ), name ); } else { - ss << string_format( _( "This is %s." ), name ); + ss += string_format( _( "This is %s." ), name ); } - ss << std::endl << "--" << std::endl; + ss += "\n--\n"; const auto &bps = get_all_body_parts( true ); // Find length of bp names, to align @@ -4827,29 +4826,29 @@ std::string Character::extended_description() const nc_color name_color = state_col; auto hp_bar = get_hp_bar( current_hp, maximal_hp, false ); - ss << colorize( left_justify( bp_heading, longest ), name_color ); - ss << colorize( hp_bar.first, hp_bar.second ); + ss += colorize( left_justify( bp_heading, longest ), name_color ); + ss += colorize( hp_bar.first, hp_bar.second ); // Trailing bars. UGLY! // TODO: Integrate into get_hp_bar somehow - ss << colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white ); - ss << std::endl; + ss += colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white ); + ss += "\n"; } - ss << "--" << std::endl; - ss << _( "Wielding:" ) << " "; + ss += "--\n"; + ss += _( "Wielding:" ) + std::string( " " ); if( weapon.is_null() ) { - ss << _( "Nothing" ); + ss += _( "Nothing" ); } else { - ss << weapon.tname(); + ss += weapon.tname(); } - ss << std::endl; - ss << _( "Wearing:" ) << " "; - ss << enumerate_as_string( worn.begin(), worn.end(), []( const item & it ) { + ss += "\n"; + ss += _( "Wearing:" ) + std::string( " " ); + ss += enumerate_as_string( worn.begin(), worn.end(), []( const item & it ) { return it.tname(); } ); - return replace_colors( ss.str() ); + return replace_colors( ss ); } social_modifiers Character::get_mutation_social_mods() const diff --git a/src/construction.cpp b/src/construction.cpp index fbbb405a8ba58..35c7a5809b253 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -1,7 +1,6 @@ #include "construction.h" #include -#include #include #include #include @@ -424,14 +423,20 @@ int construction_menu( bool blueprint ) current_con->requirements->can_make_with_inventory( total_inv, is_crafting_component ); std::vector current_buffer; - std::ostringstream current_line; + + const auto add_folded = [&]( const std::vector &folded ) { + current_buffer.insert( current_buffer.end(), folded.begin(), folded.end() ); + }; + const auto add_line = [&]( const std::string & line ) { + add_folded( foldstring( line, available_window_width ) ); + }; // display final product name only if more than one step. // Assume single stage constructions should be clear // 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 << _( "Stage/Variant #" ) << 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; @@ -440,59 +445,47 @@ int construction_menu( bool blueprint ) } else { result_string = ter_str_id( current_con->post_terrain ).obj().name(); } - current_line << colorize( result_string, color_title ); - std::vector folded_result_string = foldstring( current_line.str(), - available_window_width ); - current_buffer.insert( current_buffer.end(), folded_result_string.begin(), - folded_result_string.end() ); + current_line += colorize( result_string, color_title ); + add_line( current_line ); // display description of the result for multi-stages - current_line.str( "" ); - current_line << _( "Result: " ); + current_line = _( "Result: " ); if( current_con->post_is_furniture ) { - current_line << colorize( - furn_str_id( current_con->post_terrain ).obj().description, - color_data - ); + current_line += colorize( + furn_str_id( current_con->post_terrain ).obj().description, + color_data + ); } else { - current_line << colorize( - ter_str_id( current_con->post_terrain ).obj().description, - color_data - ); + current_line += colorize( + ter_str_id( current_con->post_terrain ).obj().description, + color_data + ); } - folded_result_string = foldstring( current_line.str(), available_window_width ); - current_buffer.insert( current_buffer.end(), folded_result_string.begin(), - folded_result_string.end() ); + add_line( current_line ); // display description of the result for single stages } else if( !current_con->post_terrain.empty() ) { - current_line.str( "" ); - 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, - color_data - ); + current_line += colorize( + furn_str_id( current_con->post_terrain ).obj().description, + color_data + ); } else { - current_line << colorize( - ter_str_id( current_con->post_terrain ).obj().description, - color_data - ); + current_line += colorize( + ter_str_id( current_con->post_terrain ).obj().description, + color_data + ); } - std::vector folded_result_string = foldstring( current_line.str(), - available_window_width ); - current_buffer.insert( current_buffer.end(), folded_result_string.begin(), - folded_result_string.end() ); + add_line( current_line ); } - current_line.str( "" ); // 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 ); @@ -506,13 +499,12 @@ 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 ); } - current_buffer.push_back( current_line.str() ); // TODO: Textify pre_flags to provide a bit more information. // Example: First step of dig pit could say something about // requiring diggable ground. - current_line.str( "" ); if( !current_con->pre_terrain.empty() ) { std::string require_string; if( current_con->pre_is_furniture ) { @@ -521,36 +513,21 @@ 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 ); - std::vector folded_result_string = foldstring( current_line.str(), - available_window_width ); - current_buffer.insert( current_buffer.end(), folded_result_string.begin(), - folded_result_string.end() ); + add_line( _( "Requires: " ) + colorize( require_string, pre_color ) ); } if( !current_con->pre_note.empty() ) { - current_line.str( "" ); - current_line << _( "Annotation: " ) - << colorize( _( current_con->pre_note ), color_data ); - std::vector folded_result_string = - foldstring( current_line.str(), available_window_width ); - current_buffer.insert( current_buffer.end(), folded_result_string.begin(), - folded_result_string.end() ); + 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 // get time needed - std::vector folded_time = current_con->get_folded_time_string( - available_window_width ); - current_buffer.insert( current_buffer.end(), folded_time.begin(), folded_time.end() ); + add_folded( current_con->get_folded_time_string( available_window_width ) ); - std::vector folded_tools = current_con->requirements->get_folded_tools_list( - available_window_width, color_stage, total_inv ); - current_buffer.insert( current_buffer.end(), folded_tools.begin(), folded_tools.end() ); + add_folded( current_con->requirements->get_folded_tools_list( available_window_width, color_stage, + total_inv ) ); - std::vector folded_components = current_con->requirements->get_folded_components_list( - available_window_width, color_stage, total_inv, is_crafting_component ); - current_buffer.insert( current_buffer.end(), folded_components.begin(), folded_components.end() ); + add_folded( current_con->requirements->get_folded_components_list( available_window_width, + color_stage, total_inv, is_crafting_component ) ); construct_buffers.push_back( current_buffer ); } diff --git a/src/effect.cpp b/src/effect.cpp index 78a790962e87c..813fb2b8bf96b 100644 --- a/src/effect.cpp +++ b/src/effect.cpp @@ -1,7 +1,6 @@ #include "effect.h" #include -#include #include #include #include @@ -499,32 +498,32 @@ std::string effect::disp_name() const } // End result should look like "name (l. arm)" or "name [intensity] (l. arm)" - std::ostringstream ret; + std::string ret; if( eff_type->use_name_ints() ) { const translation &d_name = eff_type->name[ std::min( intensity, eff_type->name.size() ) - 1 ]; if( d_name.empty() ) { return std::string(); } - ret << d_name; + ret += d_name.translated(); } else { if( eff_type->name[0].empty() ) { return std::string(); } - ret << eff_type->name[0]; + ret += eff_type->name[0].translated(); if( intensity > 1 ) { if( eff_type->id == "bandaged" || eff_type->id == "disinfected" ) { - ret << " [" << texitify_healing_power( intensity ) << "]"; + ret += string_format( " [%s]", texitify_healing_power( intensity ) ); } else { - ret << " [" << intensity << "]"; + ret += string_format( " [%d]", intensity ); } } } if( bp != num_bp ) { - ret << " (" << body_part_name( bp ) << ")"; + ret += string_format( " (%s)", body_part_name( bp ) ); } - return ret.str(); + return ret; } // Used in disp_desc() @@ -540,41 +539,41 @@ struct desc_freq { std::string effect::disp_desc( bool reduced ) const { - std::ostringstream ret; + std::string ret; // First print stat changes, adding + if value is positive int tmp = get_avg_mod( "STR", reduced ); if( tmp > 0 ) { - ret << string_format( _( "Strength +%d; " ), tmp ); + ret += string_format( _( "Strength +%d; " ), tmp ); } else if( tmp < 0 ) { - ret << string_format( _( "Strength %d; " ), tmp ); + ret += string_format( _( "Strength %d; " ), tmp ); } tmp = get_avg_mod( "DEX", reduced ); if( tmp > 0 ) { - ret << string_format( _( "Dexterity +%d; " ), tmp ); + ret += string_format( _( "Dexterity +%d; " ), tmp ); } else if( tmp < 0 ) { - ret << string_format( _( "Dexterity %d; " ), tmp ); + ret += string_format( _( "Dexterity %d; " ), tmp ); } tmp = get_avg_mod( "PER", reduced ); if( tmp > 0 ) { - ret << string_format( _( "Perception +%d; " ), tmp ); + ret += string_format( _( "Perception +%d; " ), tmp ); } else if( tmp < 0 ) { - ret << string_format( _( "Perception %d; " ), tmp ); + ret += string_format( _( "Perception %d; " ), tmp ); } tmp = get_avg_mod( "INT", reduced ); if( tmp > 0 ) { - ret << string_format( _( "Intelligence +%d; " ), tmp ); + ret += string_format( _( "Intelligence +%d; " ), tmp ); } else if( tmp < 0 ) { - ret << string_format( _( "Intelligence %d; " ), tmp ); + ret += string_format( _( "Intelligence %d; " ), tmp ); } tmp = get_avg_mod( "SPEED", reduced ); if( tmp > 0 ) { - ret << string_format( _( "Speed +%d; " ), tmp ); + ret += string_format( _( "Speed +%d; " ), tmp ); } else if( tmp < 0 ) { - ret << string_format( _( "Speed %d; " ), tmp ); + ret += string_format( _( "Speed %d; " ), tmp ); } // Newline if necessary - if( !ret.str().empty() && ret.str().back() != '\n' ) { - ret << "\n"; + if( !ret.empty() && ret.back() != '\n' ) { + ret += "\n"; } // Then print pain/damage/coughing/vomiting, we don't display pkill, health, or radiation @@ -646,21 +645,21 @@ std::string effect::disp_desc( bool reduced ) const } } if( !constant.empty() ) { - ret << _( "Const: " ) << enumerate_as_string( constant ) << " "; + ret += _( "Const: " ) + enumerate_as_string( constant ) + " "; } if( !frequent.empty() ) { - ret << _( "Freq: " ) << enumerate_as_string( frequent ) << " "; + ret += _( "Freq: " ) + enumerate_as_string( frequent ) + " "; } if( !uncommon.empty() ) { - ret << _( "Unfreq: " ) << enumerate_as_string( uncommon ) << " "; + ret += _( "Unfreq: " ) + enumerate_as_string( uncommon ) + " "; } if( !rare.empty() ) { - ret << _( "Rare: " ) << enumerate_as_string( rare ); // No space needed at the end + ret += _( "Rare: " ) + enumerate_as_string( rare ); // No space needed at the end } // Newline if necessary - if( !ret.str().empty() && ret.str().back() != '\n' ) { - ret << "\n"; + if( !ret.empty() && ret.back() != '\n' ) { + ret += "\n"; } std::string tmp_str; @@ -679,14 +678,14 @@ std::string effect::disp_desc( bool reduced ) const } // Then print the effect description if( use_part_descs() ) { - ret << string_format( _( tmp_str ), body_part_name( bp ) ); + ret += string_format( _( tmp_str ), body_part_name( bp ) ); } else { if( !tmp_str.empty() ) { - ret << _( tmp_str ); + ret += _( tmp_str ); } } - return ret.str(); + return ret; } std::string effect::disp_short_desc( bool reduced ) const diff --git a/src/game.cpp b/src/game.cpp index 475dab42018f6..08c833ddd3992 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5396,11 +5396,12 @@ static std::string get_fire_fuel_string( const tripoint &examp ) if( g->m.has_flag( TFLAG_FIRE_CONTAINER, examp ) ) { field_entry *fire = g->m.get_field( examp, fd_fire ); if( fire ) { - std::stringstream ss; - ss << _( "There is a fire here." ) << " "; + std::string ss; + ss += _( "There is a fire here." ); + ss += " "; if( fire->get_field_intensity() > 1 ) { - ss << _( "It's too big and unpredictable to evaluate how long it will last." ); - return ss.str(); + ss += _( "It's too big and unpredictable to evaluate how long it will last." ); + return ss; } time_duration fire_age = fire->get_field_age(); // half-life inclusion @@ -5408,47 +5409,47 @@ static std::string get_fire_fuel_string( const tripoint &examp ) mod = std::max( mod, 0 ); if( fire_age >= 0_turns ) { if( mod >= 4 ) { // = survival level 0-1 - ss << _( "It's going to go out soon without extra fuel." ); - return ss.str(); + ss += _( "It's going to go out soon without extra fuel." ); + return ss; } else { fire_age = 30_minutes - fire_age; if( to_string_approx( fire_age - fire_age * mod / 5 ) == to_string_approx( fire_age + fire_age * mod / 5 ) ) { - ss << string_format( - _( "Without extra fuel it might burn yet for maybe %s, but might also go out sooner." ), - to_string_approx( fire_age - fire_age * mod / 5 ) ); + ss += string_format( + _( "Without extra fuel it might burn yet for maybe %s, but might also go out sooner." ), + to_string_approx( fire_age - fire_age * mod / 5 ) ); } else { - ss << string_format( - _( "Without extra fuel it might burn yet for between %s to %s, but might also go out sooner." ), - to_string_approx( fire_age - fire_age * mod / 5 ), - to_string_approx( fire_age + fire_age * mod / 5 ) ); + ss += string_format( + _( "Without extra fuel it might burn yet for between %s to %s, but might also go out sooner." ), + to_string_approx( fire_age - fire_age * mod / 5 ), + to_string_approx( fire_age + fire_age * mod / 5 ) ); } - return ss.str(); + return ss; } } else { fire_age = fire_age * -1 + 30_minutes; if( mod >= 4 ) { // = survival level 0-1 if( fire_age <= 1_hours ) { - ss << _( "It's quite decent and looks like it'll burn for a bit without extra fuel." ); - return ss.str(); + ss += _( "It's quite decent and looks like it'll burn for a bit without extra fuel." ); + return ss; } else if( fire_age <= 3_hours ) { - ss << _( "It looks solid, and will burn for a few hours without extra fuel." ); - return ss.str(); + ss += _( "It looks solid, and will burn for a few hours without extra fuel." ); + return ss; } else { - ss << _( "It's very well supplied and even without extra fuel might burn for at least a part of a day." ); - return ss.str(); + ss += _( "It's very well supplied and even without extra fuel might burn for at least a part of a day." ); + return ss; } } else { if( to_string_approx( fire_age - fire_age * mod / 5 ) == to_string_approx( fire_age + fire_age * mod / 5 ) ) { - ss << string_format( _( "Without extra fuel it will burn for about %s." ), + ss += string_format( _( "Without extra fuel it will burn for about %s." ), to_string_approx( fire_age - fire_age * mod / 5 ) ); } else { - ss << string_format( _( "Without extra fuel it will burn for between %s to %s." ), + ss += string_format( _( "Without extra fuel it will burn for between %s to %s." ), to_string_approx( fire_age - fire_age * mod / 5 ), to_string_approx( fire_age + fire_age * mod / 5 ) ); } - return ss.str(); + return ss; } } } @@ -7444,13 +7445,13 @@ game::vmenu_ret game::list_items( const std::vector &item_list ) active_pos = iter->vIG[iThisPage].pos; activeItem = &( *iter ); } - std::stringstream sText; + std::string sText; if( iter->vIG.size() > 1 ) { - sText << "[" << iThisPage + 1 << "/" << iter->vIG.size() << "] (" << iter->totalcount << ") "; + sText += string_format( "[%d/%d] (%d) ", iThisPage + 1, iter->vIG.size(), iter->totalcount ); } - sText << iter->example->tname(); + sText += iter->example->tname(); if( iter->vIG[iThisPage].count > 1 ) { - sText << " [" << iter->vIG[iThisPage].count << "]"; + sText += string_format( "[%d]", iter->vIG[iThisPage].count ); } nc_color col = c_light_green; @@ -7463,7 +7464,7 @@ game::vmenu_ret game::list_items( const std::vector &item_list ) col = iter->example->color_in_inventory(); } } - trim_and_print( w_items, point( 1, iNum - iStartPos ), width - 9, col, sText.str() ); + trim_and_print( w_items, point( 1, iNum - iStartPos ), width - 9, col, sText ); const int numw = iItemNum > 9 ? 2 : 1; const int x = iter->vIG[iThisPage].pos.x; const int y = iter->vIG[iThisPage].pos.y; @@ -10749,12 +10750,12 @@ void game::update_stair_monsters() critter.staircount -= 4; // Let the player know zombies are trying to come. if( u.sees( dest ) ) { - std::stringstream dump; + std::string dump; if( critter.staircount > 4 ) { - dump << string_format( _( "You see a %s on the stairs" ), critter.name() ); + dump += string_format( _( "You see a %s on the stairs" ), critter.name() ); } else { if( critter.staircount > 0 ) { - dump << ( from_below ? + dump += ( from_below ? //~ The is almost at the of the ! string_format( _( "The %1$s is almost at the top of the %2$s!" ), critter.name(), @@ -10765,7 +10766,7 @@ void game::update_stair_monsters() } } - add_msg( m_warning, dump.str() ); + add_msg( m_warning, dump ); } else { sounds::sound( dest, 5, sounds::sound_t::movement, _( "a sound nearby from the stairs!" ), true, "misc", "stairs_movement" ); diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 711cbc68561ba..1cfe3eb6450cf 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -5204,7 +5203,6 @@ void iexamine::quern_examine( player &p, const tripoint &examp ) return; } - std::stringstream pop; time_duration time_left = 0_turns; int hours_left = 0; int minutes_left = 0; @@ -5259,39 +5257,37 @@ void iexamine::quern_examine( player &p, const tripoint &examp ) switch( smenu.ret ) { case 0: { //inspect mill + std::string pop; if( active ) { - pop << "" << _( "There's a mill here. It is turning and milling." ) << "" - << "\n"; + pop = colorize( _( "There's a mill here. It is turning and milling." ), c_green ) + "\n"; if( time_left > 0_turns ) { if( minutes_left > 60 ) { - pop << string_format( ngettext( "It will finish milling in about %d hour.", + pop += string_format( ngettext( "It will finish milling in about %d hour.", "It will finish milling in about %d hours.", - hours_left ), hours_left ) << "\n\n "; + hours_left ), hours_left ) + "\n\n"; } else if( minutes_left > 30 ) { - pop << _( "It will finish milling in less than an hour." ); + pop += _( "It will finish milling in less than an hour." ); } else { - pop << string_format( _( "It should take about %d minutes to finish milling." ), minutes_left ); + pop += string_format( _( "It should take about %d minutes to finish milling." ), minutes_left ); } } } else { - pop << "" << _( "There's a mill here." ) << "" << "\n"; + pop += colorize( _( "There's a mill here." ), c_green ) + "\n"; } - pop << "" << _( "You inspect its contents and find: " ) << "" << "\n\n "; + pop += colorize( _( "You inspect its contents and find: " ), c_green ) + "\n\n"; if( items_here.empty() ) { - pop << _( "…that it is empty." ); + pop += _( "…that it is empty." ); } else { for( const item &it : items_here ) { if( it.typeId() == "fake_milling_item" ) { - pop << "\n " << "" << _( "You see some grains that are not yet milled to fine flour." ) - << "" << - "\n "; + pop += "\n" + colorize( _( "You see some grains that are not yet milled to fine flour." ), + c_red ) + "\n"; continue; } - pop << "-> " << item::nname( it.typeId(), it.charges ); - pop << " (" << std::to_string( it.charges ) << ")\n "; + pop += "-> " + item::nname( it.typeId(), it.charges ) + " (" + std::to_string( it.charges ) + ")\n"; } } - popup( pop.str(), PF_NONE ); + popup( pop, PF_NONE ); break; } case 1: @@ -5374,7 +5370,6 @@ void iexamine::smoker_options( player &p, const tripoint &examp ) } bool rem_f_opt = false; - std::stringstream pop; time_duration time_left = 0_turns; int hours_left = 0; int minutes_left = 0; @@ -5466,39 +5461,37 @@ void iexamine::smoker_options( player &p, const tripoint &examp ) switch( smenu.ret ) { case 0: { //inspect smoking rack + std::string pop; if( active ) { - pop << "" << _( "There's a smoking rack here. It is lit and smoking." ) << "" - << "\n"; + pop += colorize( _( "There's a smoking rack here. It is lit and smoking." ), c_green ) + "\n"; if( time_left > 0_turns ) { if( minutes_left > 60 ) { - pop << string_format( ngettext( "It will finish smoking in about %d hour.", + pop += string_format( ngettext( "It will finish smoking in about %d hour.", "It will finish smoking in about %d hours.", - hours_left ), hours_left ) << "\n\n "; + hours_left ), hours_left ) + "\n\n"; } else if( minutes_left > 30 ) { - pop << _( "It will finish smoking in less than an hour." ) << "\n "; + pop += _( "It will finish smoking in less than an hour." ) + std::string( "\n" ); } else { - pop << string_format( _( "It should take about %d minutes to finish smoking." ), - minutes_left ) << "\n "; + pop += string_format( _( "It should take about %d minutes to finish smoking." ), + minutes_left ) + "\n "; } } } else { - pop << "" << _( "There's a smoking rack here." ) << "" << "\n"; + pop += colorize( _( "There's a smoking rack here." ), c_green ) + "\n"; } - pop << "" << _( "You inspect its contents and find: " ) << "" << "\n\n "; + pop += colorize( _( "You inspect its contents and find: " ), c_green ) + "\n"; if( items_here.empty() ) { - pop << _( "…that it is empty." ); + pop += _( "…that it is empty." ); } else { for( const item &it : items_here ) { if( it.typeId() == "fake_smoke_plume" ) { - pop << "\n " << "" << _( "You see some smoldering embers there." ) << "" << - "\n "; + pop += "\n" + colorize( _( "You see some smoldering embers there." ), c_red ) + "\n"; continue; } - pop << "-> " << item::nname( it.typeId(), it.charges ); - pop << " (" << std::to_string( it.charges ) << ")\n "; + pop += "-> " + item::nname( it.typeId(), it.charges ) + " (" + std::to_string( it.charges ) + ")\n"; } } - popup( pop.str(), PF_NONE ); + popup( pop, PF_NONE ); break; } case 1: diff --git a/src/item.cpp b/src/item.cpp index 59d36daa9025b..561f2e1751855 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1241,10 +1241,7 @@ void item::basic_info( std::vector &info, const iteminfo_query *parts, active ) ); info.push_back( iteminfo( "BASE", _( "burn: " ), "", iteminfo::lower_is_better, burnt ) ); - std::ostringstream stream; - std::copy( item_tags.begin(), item_tags.end(), - std::ostream_iterator( stream, "," ) ); - std::string tags_listed = stream.str(); + const std::string tags_listed = enumerate_as_string( item_tags, enumeration_conjunction::none ); info.push_back( iteminfo( "BASE", string_format( _( "tags: %s" ), tags_listed ) ) ); for( auto const &imap : item_vars ) { info.push_back( iteminfo( "BASE", @@ -3661,8 +3658,6 @@ void item::on_damage( int, damage_type ) std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int truncate ) const { - std::stringstream ret; - int dirt_level = get_var( "dirt", 0 ) / 2000; std::string dirt_symbol; // TODO: MATERIALS put this in json @@ -3743,32 +3738,24 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t maintext = type_name( quantity ); } else if( is_gun() || is_tool() || is_magazine() ) { int amt = 0; - ret.str( "" ); - ret << label( quantity ); + maintext = label( quantity ); for( const item *mod : is_gun() ? gunmods() : toolmods() ) { if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) { amt++; } } if( amt ) { - ret << string_format( "+%d", amt ); + maintext += string_format( "+%d", amt ); } - maintext = ret.str(); } else if( is_armor() && has_clothing_mod() ) { - ret.str( "" ); - ret << label( quantity ); - ret << "+1"; - maintext = ret.str(); + maintext = label( quantity ) + "+1"; } else if( is_craft() ) { - ret.str( "" ); - const std::string name = _( "in progress %s" ); - ret << string_format( name, making->result_name() ); + maintext = string_format( _( "in progress %s" ), making->result_name() ); if( charges > 1 ) { - ret << " (" << charges << ")"; + maintext += string_format( " (%d)", charges ); } const int percent_progress = item_counter / 100000; - ret << " (" << percent_progress << "%)"; - maintext = ret.str(); + maintext += string_format( " (%d%%)", percent_progress ); } else if( contents.size() == 1 ) { const item &contents_item = contents.front(); if( contents_item.made_of( LIQUID ) || contents_item.is_food() ) { @@ -3791,114 +3778,112 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t maintext = label( quantity ); } - ret.str( "" ); + std::string tagtext; if( is_food() ) { if( has_flag( "HIDDEN_POISON" ) && g->u.get_skill_level( skill_survival ) >= 3 ) { - ret << _( " (poisonous)" ); + tagtext += _( " (poisonous)" ); } else if( has_flag( "HIDDEN_HALLU" ) && g->u.get_skill_level( skill_survival ) >= 5 ) { - ret << _( " (hallucinogenic)" ); + tagtext += _( " (hallucinogenic)" ); } } if( has_flag( "ETHEREAL_ITEM" ) ) { - ret << string_format( _( " (%s turns)" ), get_var( "ethereal" ) ); + tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) ); } else if( goes_bad() || is_food() ) { if( item_tags.count( "DIRTY" ) ) { - ret << _( " (dirty)" ); + tagtext += _( " (dirty)" ); } else if( rotten() ) { - ret << _( " (rotten)" ); + tagtext += _( " (rotten)" ); } else if( has_flag( "MUSHY" ) ) { - ret << _( " (mushy)" ); + tagtext += _( " (mushy)" ); } else if( is_going_bad() ) { - ret << _( " (old)" ); + tagtext += _( " (old)" ); } else if( is_fresh() ) { - ret << _( " (fresh)" ); + tagtext += _( " (fresh)" ); } } if( has_temperature() ) { if( has_flag( "HOT" ) ) { - ret << _( " (hot)" ); + tagtext += _( " (hot)" ); } if( has_flag( "COLD" ) ) { - ret << _( " (cold)" ); + tagtext += _( " (cold)" ); } if( has_flag( "FROZEN" ) ) { - ret << _( " (frozen)" ); + tagtext += _( " (frozen)" ); } else if( has_flag( "MELTS" ) ) { - ret << _( " (melted)" ); // he melted + tagtext += _( " (melted)" ); // he melted } } const sizing sizing_level = get_sizing( g->u, get_encumber( g->u ) != 0 ); if( sizing_level == sizing::human_sized_small_char ) { - ret << _( " (too big)" ); + tagtext += _( " (too big)" ); } else if( sizing_level == sizing::big_sized_small_char ) { - ret << _( " (huge!)" ); + tagtext += _( " (huge!)" ); } else if( sizing_level == sizing::human_sized_big_char || sizing_level == sizing::small_sized_human_char ) { - ret << _( " (too small)" ); + tagtext += _( " (too small)" ); } else if( sizing_level == sizing::small_sized_big_char ) { - ret << _( " (tiny!)" ); + tagtext += _( " (tiny!)" ); } else if( !has_flag( "FIT" ) && has_flag( "VARSIZE" ) ) { - ret << _( " (poor fit)" ); + tagtext += _( " (poor fit)" ); } if( is_filthy() ) { - ret << _( " (filthy)" ); + tagtext += _( " (filthy)" ); } if( is_bionic() && !has_flag( "NO_PACKED" ) ) { if( !has_flag( "NO_STERILE" ) ) { - ret << _( " (sterile)" ); + tagtext += _( " (sterile)" ); } else { - ret << _( " (packed)" ); + tagtext += _( " (packed)" ); } } if( is_tool() && has_flag( "USE_UPS" ) ) { - ret << _( " (UPS)" ); + tagtext += _( " (UPS)" ); } if( has_var( "NANOFAB_ITEM_ID" ) ) { - ret << string_format( " (%s)", nname( get_var( "NANOFAB_ITEM_ID" ) ) ); + tagtext += string_format( " (%s)", nname( get_var( "NANOFAB_ITEM_ID" ) ) ); } if( has_flag( "RADIO_MOD" ) ) { - ret << _( " (radio:" ); + tagtext += _( " (radio:" ); if( has_flag( "RADIOSIGNAL_1" ) ) { - ret << pgettext( "The radio mod is associated with the [R]ed button.", "R)" ); + tagtext += pgettext( "The radio mod is associated with the [R]ed button.", "R)" ); } else if( has_flag( "RADIOSIGNAL_2" ) ) { - ret << pgettext( "The radio mod is associated with the [B]lue button.", "B)" ); + tagtext += pgettext( "The radio mod is associated with the [B]lue button.", "B)" ); } else if( has_flag( "RADIOSIGNAL_3" ) ) { - ret << pgettext( "The radio mod is associated with the [G]reen button.", "G)" ); + tagtext += pgettext( "The radio mod is associated with the [G]reen button.", "G)" ); } else { debugmsg( "Why is the radio neither red, blue, nor green?" ); - ret << "?)"; + tagtext += "?)"; } } if( has_flag( "WET" ) ) { - ret << _( " (wet)" ); + tagtext += _( " (wet)" ); } if( already_used_by_player( g->u ) ) { - ret << _( " (used)" ); + tagtext += _( " (used)" ); } if( active && ( has_flag( "WATER_EXTINGUISH" ) || has_flag( "LITCIG" ) ) ) { - ret << _( " (lit)" ); + tagtext += _( " (lit)" ); } else if( has_flag( "IS_UPS" ) && get_var( "cable" ) == "plugged_in" ) { - ret << _( " (plugged in)" ); + tagtext += _( " (plugged in)" ); } else if( active && !is_food() && !is_corpse() && ( typeId().length() < 3 || typeId().compare( typeId().length() - 3, 3, "_on" ) != 0 ) ) { // Usually the items whose ids end in "_on" have the "active" or "on" string already contained // in their name, also food is active while it rots. - ret << _( " (active)" ); + tagtext += _( " (active)" ); } if( is_favorite ) { - ret << _( " *" ); // Display asterisk for favorite items + tagtext += _( " *" ); // Display asterisk for favorite items } - const std::string tagtext = ret.str(); - std::string modtext; if( gunmod_find( "barrel_small" ) ) { modtext += _( "sawn-off " ); @@ -3907,21 +3892,19 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t modtext += std::string( pgettext( "Adjective, as in diamond katana", "diamond" ) ) + " "; } - ret.str( "" ); //~ This is a string to construct the item name as it is displayed. This format string has been added for maximum flexibility. The strings are: %1$s: Damage text (e.g. "bruised"). %2$s: burn adjectives (e.g. "burnt"). %3$s: tool modifier text (e.g. "atomic"). %4$s: vehicle part text (e.g. "3.8-Liter"). $5$s: main item text (e.g. "apple"). %6s: tags (e.g. "(wet) (poor fit)"). - ret << string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext, vehtext, - maintext, tagtext ); + std::string ret = string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext, + vehtext, maintext, tagtext ); - std::string r = ret.str(); if( truncate != 0 ) { - r = utf8_truncate( r, truncate + truncate_override ); + ret = utf8_truncate( ret, truncate + truncate_override ); } if( item_vars.find( "item_note" ) != item_vars.end() ) { //~ %s is an item name. This style is used to denote items with notes. - return string_format( _( "*%s*" ), r ); + return string_format( _( "*%s*" ), ret ); } else { - return r; + return ret; } } diff --git a/src/item_action.cpp b/src/item_action.cpp index e8de73ee00d45..a9e7d94fa3e46 100644 --- a/src/item_action.cpp +++ b/src/item_action.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -259,15 +258,13 @@ void game::item_action_menu() // Add mapped actions to the menu vector. std::transform( iactions.begin(), iactions.end(), std::back_inserter( menu_items ), []( const std::pair &elem ) { - std::stringstream ss; - ss << elem.second->display_name(); + std::string ss = elem.second->display_name(); if( elem.second->ammo_required() ) { - ss << " (" << elem.second->ammo_required() << '/' - << elem.second->ammo_remaining() << ')'; + ss += string_format( " (%d/%d)", elem.second->ammo_required(), elem.second->ammo_remaining() ); } const auto method = elem.second->get_use( elem.first ); - return std::make_tuple( method->get_type(), method->get_name(), ss.str() ); + return std::make_tuple( method->get_type(), method->get_name(), ss ); } ); // Sort mapped actions. sort_menu( menu_items.begin(), menu_items.end() ); @@ -289,18 +286,18 @@ void game::item_action_menu() } // Fill the menu. for( const auto &elem : menu_items ) { - std::stringstream ss; - ss << std::get<1>( elem ) - << std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' ) - << std::string( 4, ' ' ); + std::string ss; + ss += std::get<1>( elem ); + ss += std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' ); + ss += std::string( 4, ' ' ); - ss << std::get<2>( elem ) - << std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' ); + ss += std::get<2>( elem ); + ss += std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' ); const char bind = key_bound_to( ctxt, std::get<0>( elem ) ); const bool enabled = assigned_action( std::get<0>( elem ) ); - kmenu.addentry( num, enabled, bind, ss.str() ); + kmenu.addentry( num, enabled, bind, ss ); num++; } diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 8f3c228238ca7..3e84cbead8f18 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -804,14 +803,14 @@ void Item_factory::init() 0 ); } -bool Item_factory::check_ammo_type( std::ostream &msg, const ammotype &ammo ) const +bool Item_factory::check_ammo_type( std::string &msg, const ammotype &ammo ) const { if( ammo.is_null() ) { return false; } if( !ammo.is_valid() ) { - msg << string_format( "ammo type %s is not known", ammo.c_str() ) << "\n"; + msg += string_format( "ammo type %s is not known\n", ammo.c_str() ); return false; } @@ -819,7 +818,7 @@ bool Item_factory::check_ammo_type( std::ostream &msg, const ammotype &ammo ) co m_templates.end(), [&ammo]( const decltype( m_templates )::value_type & e ) { return e.second.ammo && e.second.ammo->type == ammo; } ) ) { - msg << string_format( "there is no actual ammo of type %s defined", ammo.c_str() ) << "\n"; + msg += string_format( "there is no actual ammo of type %s defined\n", ammo.c_str() ); return false; } return true; @@ -828,76 +827,76 @@ bool Item_factory::check_ammo_type( std::ostream &msg, const ammotype &ammo ) co void Item_factory::check_definitions() const { for( const auto &elem : m_templates ) { - std::ostringstream msg; + std::string msg; const itype *type = &elem.second; if( !type->category_force.is_valid() ) { - msg << "undefined category " << type->category_force.c_str() << "\n"; + msg += "undefined category " + type->category_force.str() + "\n"; } if( type->weight < 0_gram ) { - msg << "negative weight" << "\n"; + msg += "negative weight\n"; } if( type->volume < 0_ml ) { - msg << "negative volume" << "\n"; + msg += "negative volume\n"; } if( type->count_by_charges() || type->phase == LIQUID ) { if( type->stack_size <= 0 ) { - msg << "invalid stack_size " << type->stack_size << " on type using charges\n"; + msg += string_format( "invalid stack_size %d on type using charges\n", type->stack_size ); } } if( type->price < 0_cent ) { - msg << "negative price" << "\n"; + msg += "negative price\n"; } if( type->damage_min() > 0 || type->damage_max() < 0 || type->damage_min() > type->damage_max() ) { - msg << "invalid damage range" << "\n"; + msg += "invalid damage range\n"; } if( type->description.empty() ) { - msg << "empty description" << "\n"; + msg += "empty description\n"; } for( const material_id &mat_id : type->materials ) { if( mat_id.str() == "null" || !mat_id.is_valid() ) { - msg << string_format( "invalid material %s", mat_id.c_str() ) << "\n"; + msg += string_format( "invalid material %s\n", mat_id.c_str() ); } } if( type->sym.empty() ) { - msg << "symbol not defined" << "\n"; + msg += "symbol not defined\n"; } else if( utf8_width( type->sym ) != 1 ) { - msg << "symbol must be exactly one console cell width" << "\n"; + msg += "symbol must be exactly one console cell width\n"; } for( const auto &_a : type->techniques ) { if( !_a.is_valid() ) { - msg << string_format( "unknown technique %s", _a.c_str() ) << "\n"; + msg += string_format( "unknown technique %s\n", _a.c_str() ); } } if( !type->snippet_category.empty() ) { if( !SNIPPET.has_category( type->snippet_category ) ) { - msg << string_format( "item %s: snippet category %s without any snippets", type->id.c_str(), - type->snippet_category.c_str() ) << "\n"; + msg += string_format( "item %s: snippet category %s without any snippets\n", type->id.c_str(), + type->snippet_category.c_str() ); } } for( auto &q : type->qualities ) { if( !q.first.is_valid() ) { - msg << string_format( "item %s has unknown quality %s", type->id.c_str(), q.first.c_str() ) << "\n"; + msg += string_format( "item %s has unknown quality %s\n", type->id.c_str(), q.first.c_str() ); } } if( type->default_container && ( !has_template( *type->default_container ) || *type->default_container == "null" ) ) { - msg << string_format( "invalid container property %s", type->default_container->c_str() ) << "\n"; + msg += string_format( "invalid container property %s\n", type->default_container->c_str() ); } for( const auto &e : type->emits ) { if( !e.is_valid() ) { - msg << string_format( "item %s has unknown emit source %s", type->id.c_str(), e.c_str() ) << "\n"; + msg += string_format( "item %s has unknown emit source %s\n", type->id.c_str(), e.c_str() ); } } for( const auto &f : type->faults ) { if( !f.is_valid() ) { - msg << string_format( "invalid item fault %s", f.c_str() ) << "\n"; + msg += string_format( "invalid item fault %s\n", f.c_str() ); } } @@ -905,69 +904,68 @@ void Item_factory::check_definitions() const if( type->comestible->tool != "null" ) { auto req_tool = find_template( type->comestible->tool ); if( !req_tool->tool ) { - msg << string_format( "invalid tool property %s", type->comestible->tool.c_str() ) << "\n"; + msg += string_format( "invalid tool property %s\n", type->comestible->tool.c_str() ); } } } if( type->brewable ) { if( type->brewable->time < 1_turns ) { - msg << "brewable time is less than 1 turn\n"; + msg += "brewable time is less than 1 turn\n"; } if( type->brewable->results.empty() ) { - msg << "empty product list" << "\n"; + msg += "empty product list\n"; } for( auto &b : type->brewable->results ) { if( !has_template( b ) ) { - msg << string_format( "invalid result id %s", b.c_str() ) << "\n"; + msg += string_format( "invalid result id %s\n", b.c_str() ); } } } if( type->seed ) { if( type->seed->grow < 1_turns ) { - msg << "seed growing time is less than 1 turn\n"; + msg += "seed growing time is less than 1 turn\n"; } if( !has_template( type->seed->fruit_id ) ) { - msg << string_format( "invalid fruit id %s", type->seed->fruit_id.c_str() ) << "\n"; + msg += string_format( "invalid fruit id %s\n", type->seed->fruit_id.c_str() ); } for( auto &b : type->seed->byproducts ) { if( !has_template( b ) ) { - msg << string_format( "invalid byproduct id %s", b.c_str() ) << "\n"; + msg += string_format( "invalid byproduct id %s\n", b.c_str() ); } } } if( type->book ) { if( type->book->skill && !type->book->skill.is_valid() ) { - msg << "uses invalid book skill." << "\n"; + msg += "uses invalid book skill.\n"; } if( type->book->martial_art && !type->book->martial_art.is_valid() ) { - msg << string_format( "trains invalid martial art '%s'.", - type->book->martial_art.str() ) << "\n"; + msg += string_format( "trains invalid martial art '%s'.\n", type->book->martial_art.str() ); } if( type->can_use( "MA_MANUAL" ) && !type->book->martial_art ) { - msg << "has use_action MA_MANUAL but does not specify a martial art\n"; + msg += "has use_action MA_MANUAL but does not specify a martial art\n"; } } if( type->can_use( "MA_MANUAL" ) && !type->book ) { - msg << "has use_action MA_MANUAL but is not a book\n"; + msg += "has use_action MA_MANUAL but is not a book\n"; } if( type->ammo ) { if( !type->ammo->type && type->ammo->type != ammotype( "NULL" ) ) { - msg << "must define at least one ammo type" << "\n"; + msg += "must define at least one ammo type\n"; } check_ammo_type( msg, type->ammo->type ); if( type->ammo->casing && ( !has_template( *type->ammo->casing ) || *type->ammo->casing == "null" ) ) { - msg << string_format( "invalid casing property %s", type->ammo->casing->c_str() ) << "\n"; + msg += string_format( "invalid casing property %s\n", type->ammo->casing->c_str() ); } if( type->ammo->drop != "null" && !has_template( type->ammo->drop ) ) { - msg << string_format( "invalid drop item %s", type->ammo->drop.c_str() ) << "\n"; + msg += string_format( "invalid drop item %s\n", type->ammo->drop.c_str() ); } } if( type->battery ) { if( type->battery->max_capacity < 0_mJ ) { - msg << "battery cannot have negative maximum charge\n"; + msg += "battery cannot have negative maximum charge\n"; } } if( type->gun ) { @@ -977,49 +975,49 @@ void Item_factory::check_definitions() const if( type->gun->ammo.empty() ) { // if gun doesn't use ammo forbid both integral or detachable magazines if( static_cast( type->gun->clip ) || !type->magazines.empty() ) { - msg << "cannot specify clip_size or magazine without ammo type" << "\n"; + msg += "cannot specify clip_size or magazine without ammo type\n"; } if( type->item_tags.count( "RELOAD_AND_SHOOT" ) ) { - msg << "RELOAD_AND_SHOOT requires an ammo type to be specified" << "\n"; + msg += "RELOAD_AND_SHOOT requires an ammo type to be specified\n"; } } else { if( type->item_tags.count( "RELOAD_AND_SHOOT" ) && !type->magazines.empty() ) { - msg << "RELOAD_AND_SHOOT cannot be used with magazines" << "\n"; + msg += "RELOAD_AND_SHOOT cannot be used with magazines\n"; } for( const ammotype &at : type->gun->ammo ) { if( !type->gun->clip && !type->magazines.empty() && !type->magazine_default.count( at ) ) { - msg << "specified magazine but none provided for ammo type " << at.str() << "\n"; + msg += string_format( "specified magazine but none provided for ammo type %s\n", at.str() ); } } } if( type->gun->barrel_length < 0_ml ) { - msg << "gun barrel length cannot be negative" << "\n"; + msg += "gun barrel length cannot be negative\n"; } if( !type->gun->skill_used ) { - msg << "uses no skill" << "\n"; + msg += "uses no skill\n"; } else if( !type->gun->skill_used.is_valid() ) { - msg << "uses an invalid skill " << type->gun->skill_used.str() << "\n"; + msg += string_format( "uses an invalid skill %s\n", type->gun->skill_used.str() ); } for( auto &gm : type->gun->default_mods ) { if( !has_template( gm ) ) { - msg << "invalid default mod." << "\n"; + msg += "invalid default mod.\n"; } } for( auto &gm : type->gun->built_in_mods ) { if( !has_template( gm ) ) { - msg << "invalid built-in mod." << "\n"; + msg += "invalid built-in mod.\n"; } } } if( type->gunmod ) { if( type->gunmod->location.str().empty() ) { - msg << "gunmod does not specify location" << "\n"; + msg += "gunmod does not specify location\n"; } if( ( type->gunmod->sight_dispersion < 0 ) != ( type->gunmod->aim_speed < 0 ) ) { - msg << "gunmod must have both sight_dispersion and aim_speed set or neither of them set" << "\n"; + msg += "gunmod must have both sight_dispersion and aim_speed set or neither of them set\n"; } } if( type->mod ) { @@ -1034,12 +1032,12 @@ void Item_factory::check_definitions() const for( const auto &e : type->mod->magazine_adaptor ) { check_ammo_type( msg, e.first ); if( e.second.empty() ) { - msg << "No magazines specified for ammo type " << e.first.str() << "\n"; + msg += string_format( "no magazines specified for ammo type %s\n", e.first.str() ); } for( const itype_id &opt : e.second ) { const itype *mag = find_template( opt ); if( !mag->magazine || !mag->magazine->type.count( e.first ) ) { - msg << "invalid magazine " << opt << " in magazine adapter\n"; + msg += string_format( "invalid magazine %s in magazine adapter\n", opt ); } } } @@ -1049,50 +1047,49 @@ void Item_factory::check_definitions() const check_ammo_type( msg, at ); } if( type->magazine->type.empty() ) { - msg << "magazine did not specify ammo type" << "\n"; + msg += "magazine did not specify ammo type\n"; } if( type->magazine->capacity < 0 ) { - msg << string_format( "invalid capacity %i", type->magazine->capacity ) << "\n"; + msg += string_format( "invalid capacity %i\n", type->magazine->capacity ); } if( type->magazine->count < 0 || type->magazine->count > type->magazine->capacity ) { - msg << string_format( "invalid count %i", type->magazine->count ) << "\n"; + msg += string_format( "invalid count %i\n", type->magazine->count ); } const itype *da = find_template( type->magazine->default_ammo ); if( !( da->ammo && type->magazine->type.count( da->ammo->type ) ) ) { - msg << string_format( "invalid default_ammo %s", type->magazine->default_ammo.c_str() ) << "\n"; + msg += string_format( "invalid default_ammo %s\n", type->magazine->default_ammo.c_str() ); } if( type->magazine->reliability < 0 || type->magazine->reliability > 100 ) { - msg << string_format( "invalid reliability %i", type->magazine->reliability ) << "\n"; + msg += string_format( "invalid reliability %i\n", type->magazine->reliability ); } if( type->magazine->reload_time < 0 ) { - msg << string_format( "invalid reload_time %i", type->magazine->reload_time ) << "\n"; + msg += string_format( "invalid reload_time %i\n", type->magazine->reload_time ); } if( type->magazine->linkage && ( !has_template( *type->magazine->linkage ) || *type->magazine->linkage == "null" ) ) { - msg << string_format( "invalid linkage property %s", type->magazine->linkage->c_str() ) << "\n"; + msg += string_format( "invalid linkage property %s\n", type->magazine->linkage->c_str() ); } } for( const std::pair, std::set> &ammo_variety : type->magazines ) { if( ammo_variety.second.empty() ) { - msg << "No magazine specified for " << ammo_variety.first.str() << "\n"; + msg += string_format( "no magazine specified for %s\n", ammo_variety.first.str() ); } for( const std::string &magazine : ammo_variety.second ) { const itype *mag_ptr = find_template( magazine ); if( mag_ptr == nullptr ) { - msg << "Magazine \"" << magazine << "\" specified for \"" - << ammo_variety.first.str() << "\" does not exist\n"; + msg += string_format( "magazine \"%s\" specified for \"%s\" does not exist\n", magazine, + ammo_variety.first.str() ); } else if( !mag_ptr->magazine ) { - msg << "Magazine \"" << magazine << "\" specified for \"" - << ammo_variety.first.str() << "\" is not a magazine\n"; + msg += string_format( "magazine \"%s\" specified for \"%s\" is not a magazine\n", magazine, + ammo_variety.first.str() ); } else if( !mag_ptr->magazine->type.count( ammo_variety.first ) ) { - msg << "magazine \"" << magazine << "\" does not take compatible ammo\n"; + msg += string_format( "magazine \"%s\" does not take compatible ammo\n", magazine ); } else if( mag_ptr->item_tags.count( "SPEEDLOADER" ) && mag_ptr->magazine->capacity != type->gun->clip ) { - msg << "Speedloader " << magazine << " capacity (" - << mag_ptr->magazine->capacity << ") does not match gun capacity (" - << type->gun->clip << ").\n"; + msg += string_format( "speedloader %s capacity (%d) does not match gun capacity (%d).\n", magazine, + mag_ptr->magazine->capacity, type->gun->clip ); } } } @@ -1103,31 +1100,31 @@ void Item_factory::check_definitions() const } if( type->tool->revert_to && ( !has_template( *type->tool->revert_to ) || *type->tool->revert_to == "null" ) ) { - msg << string_format( "invalid revert_to property %s", type->tool->revert_to->c_str() ) << "\n"; + msg += string_format( "invalid revert_to property %s\n", type->tool->revert_to->c_str() ); } if( !type->tool->revert_msg.empty() && !type->tool->revert_to ) { - msg << _( "cannot specify revert_msg without revert_to" ) << "\n"; + msg += "cannot specify revert_msg without revert_to\n"; } if( !type->tool->subtype.empty() && !has_template( type->tool->subtype ) ) { - msg << _( "Invalid tool subtype" ) << type->tool->subtype << "\n"; + msg += string_format( "invalid tool subtype %s\n", type->tool->subtype ); } } if( type->bionic ) { if( !type->bionic->id.is_valid() ) { - msg << string_format( "there is no bionic with id %s", type->bionic->id.c_str() ) << "\n"; + msg += string_format( "there is no bionic with id %s\n", type->bionic->id.c_str() ); } } if( type->container ) { if( type->container->seals && type->container->unseals_into != "null" ) { - msg << string_format( "Resealable container unseals_into %s", - type->container->unseals_into.c_str() ) << "\n"; + msg += string_format( "resealable container unseals_into %s\n", + type->container->unseals_into.c_str() ); } if( type->container->contains <= 0_ml ) { - msg << string_format( "\"contains\" (%d) must be >0", type->container->contains.value() ) << "\n"; + msg += string_format( "\"contains\" (%d) must be >0\n", type->container->contains.value() ); } if( !has_template( type->container->unseals_into ) ) { - msg << string_format( "unseals_into invalid id %s", type->container->unseals_into.c_str() ) << "\n"; + msg += string_format( "unseals_into invalid id %s\n", type->container->unseals_into.c_str() ); } } @@ -1136,18 +1133,18 @@ void Item_factory::check_definitions() const assert( actor ); if( !actor->is_valid() ) { - msg << string_format( "item action \"%s\" was not described.", actor->type.c_str() ) << "\n"; + msg += string_format( "item action \"%s\" was not described.\n", actor->type.c_str() ); } } if( type->fuel && !type->count_by_charges() ) { - msg << "fuel value set, but item isn't count_by_charges.\n"; + msg += "fuel value set, but item isn't count_by_charges.\n"; } - if( msg.str().empty() ) { + if( msg.empty() ) { continue; } - debugmsg( "warnings for type %s:\n%s", type->id.c_str(), msg.str() ); + debugmsg( "warnings for type %s:\n%s", type->id.c_str(), msg ); } for( const auto &e : migrations ) { if( !m_templates.count( e.second.replace ) ) { @@ -2777,9 +2774,8 @@ void item_group::debug_spawn() uilist menu2; menu2.text = _( "Result of 100 spawns:" ); for( const auto &e : itemnames2 ) { - std::ostringstream buffer; - buffer << e.first << " x " << e.second << "\n"; - menu2.entries.emplace_back( static_cast( menu2.entries.size() ), true, -2, buffer.str() ); + menu2.entries.emplace_back( static_cast( menu2.entries.size() ), true, -2, + string_format( _( "%d x %s" ), e.first, e.second ) ); } menu2.query(); } diff --git a/src/item_factory.h b/src/item_factory.h index e4c1ba2121369..8209532d301e0 100644 --- a/src/item_factory.h +++ b/src/item_factory.h @@ -254,7 +254,7 @@ class Item_factory * @param msg Stream in which all error messages are printed. * @param ammo Ammo type to check. */ - bool check_ammo_type( std::ostream &msg, const ammotype &ammo ) const; + bool check_ammo_type( std::string &msg, const ammotype &ammo ) const; /** * Called before creating a new template and handles inheritance via copy-from diff --git a/src/map_extras.cpp b/src/map_extras.cpp index 600fefc3ff262..bf02a4b81d6e8 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -2836,10 +2836,8 @@ void debug_spawn_test() uilist results_menu; results_menu.text = _( "Result of 32400 selections:" ); for( std::pair &r : sorted_results ) { - std::ostringstream buffer; - buffer << r.first << " x " << r.second << "\n"; results_menu.entries.emplace_back( static_cast( results_menu.entries.size() ), true, -2, - buffer.str() ); + string_format( "%d x %s", r.first, r.second ) ); } results_menu.query(); } diff --git a/src/mapbuffer.cpp b/src/mapbuffer.cpp index 6c32db50189be..40fdb4eefea03 100644 --- a/src/mapbuffer.cpp +++ b/src/mapbuffer.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/src/martialarts.cpp b/src/martialarts.cpp index 7dfc9e283c702..b786d6b362a3b 100644 --- a/src/martialarts.cpp +++ b/src/martialarts.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -487,68 +486,68 @@ bool ma_requirements::is_valid_weapon( const item &i ) const std::string ma_requirements::get_description( bool buff ) const { - std::stringstream dump; + std::string dump; if( std::any_of( min_skill.begin(), min_skill.end(), []( const std::pair &pr ) { return pr.second > 0; } ) ) { - dump << string_format( _( "%s required: " ), + dump += string_format( _( "%s required: " ), ngettext( "Skill", "Skills", min_skill.size() ) ); - dump << enumerate_as_string( min_skill.begin(), + dump += enumerate_as_string( min_skill.begin(), min_skill.end(), []( const std::pair &pr ) { return string_format( "%s: %d", pr.first->name(), pr.second ); - }, enumeration_conjunction::none ) << std::endl; + }, enumeration_conjunction::none ) + "\n"; } if( std::any_of( min_damage.begin(), min_damage.end(), []( const std::pair &pr ) { return pr.second > 0; } ) ) { - dump << ngettext( "Damage type required: ", + dump += ngettext( "Damage type required: ", "Damage types required: ", min_damage.size() ); - dump << enumerate_as_string( min_damage.begin(), + dump += enumerate_as_string( min_damage.begin(), min_damage.end(), []( const std::pair &pr ) { return string_format( _( "%s: %d" ), name_by_dt( pr.first ), pr.second ); - }, enumeration_conjunction::none ) << std::endl; + }, enumeration_conjunction::none ) + "\n"; } if( !req_buffs.empty() ) { - dump << _( "Requires: " ); + dump += _( "Requires: " ); - dump << enumerate_as_string( req_buffs.begin(), req_buffs.end(), []( const mabuff_id & bid ) { + dump += enumerate_as_string( req_buffs.begin(), req_buffs.end(), []( const mabuff_id & bid ) { return _( bid->name ); - }, enumeration_conjunction::none ) << std::endl; + }, enumeration_conjunction::none ) + "\n"; } const std::string type = buff ? _( "activate" ) : _( "be used" ); if( unarmed_allowed && melee_allowed ) { - dump << string_format( _( "* Can %s while armed or unarmed" ), - type ) << std::endl; + dump += string_format( _( "* Can %s while armed or unarmed" ), + type ) + "\n"; if( unarmed_weapons_allowed ) { - dump << string_format( _( "* Can %s while using any unarmed weapon" ), - type ) << std::endl; + dump += string_format( _( "* Can %s while using any unarmed weapon" ), + type ) + "\n"; } } else if( unarmed_allowed ) { - dump << string_format( _( "* Can only %s while unarmed" ), - type ) << std::endl; + dump += string_format( _( "* Can only %s while unarmed" ), + type ) + "\n"; if( unarmed_weapons_allowed ) { - dump << string_format( _( "* Can %s while using any unarmed weapon" ), - type ) << std::endl; + dump += string_format( _( "* Can %s while using any unarmed weapon" ), + type ) + "\n"; } } else if( melee_allowed ) { - dump << string_format( _( "* Can only %s while armed" ), - type ) << std::endl; + dump += string_format( _( "* Can only %s while armed" ), + type ) + "\n"; } if( wall_adjacent ) { - dump << string_format( _( "* Can %s while near to a wall" ), - type ) << std::endl; + dump += string_format( _( "* Can %s while near to a wall" ), + type ) + "\n"; } - return dump.str(); + return dump; } ma_technique::ma_technique() @@ -678,53 +677,53 @@ bool ma_buff::can_melee() const std::string ma_buff::get_description( bool passive ) const { - std::stringstream dump; - dump << string_format( _( "Buff technique: %s" ), _( name ) ) << std::endl; + std::string dump; + dump += string_format( _( "Buff technique: %s" ), _( name ) ) + "\n"; std::string temp = bonuses.get_description(); if( !temp.empty() ) { - dump << string_format( _( "%s: " ), - ngettext( "Bonus", "Bonus/stack", max_stacks ) ) << std::endl << temp; + dump += string_format( _( "%s: " ), + ngettext( "Bonus", "Bonus/stack", max_stacks ) ) + "\n" + temp; } - dump << reqs.get_description( true ); + dump += reqs.get_description( true ); if( max_stacks > 1 ) { - dump << string_format( _( "* Will stack up to %d times" ), - max_stacks ) << std::endl; + dump += string_format( _( "* Will stack up to %d times" ), + max_stacks ) + "\n"; } const int turns = to_turns( buff_duration ); if( !passive && turns ) { - dump << string_format( _( "* Will last for %d %s" ), - turns, ngettext( "turn", "turns", turns ) ) << std::endl; + dump += string_format( _( "* Will last for %d %s" ), + turns, ngettext( "turn", "turns", turns ) ) + "\n"; } if( dodges_bonus > 0 ) { - dump << string_format( _( "* Will give a +%s bonus to dodge%s" ), - dodges_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) << std::endl; + dump += string_format( _( "* Will give a +%s bonus to dodge%s" ), + dodges_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) + "\n"; } else if( dodges_bonus < 0 ) { - dump << string_format( _( "* Will give a %s penalty to dodge%s" ), - dodges_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) << std::endl; + dump += string_format( _( "* Will give a %s penalty to dodge%s" ), + dodges_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) + "\n"; } if( blocks_bonus > 0 ) { - dump << string_format( _( "* Will give a +%s bonus to block%s" ), - blocks_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) << std::endl; + dump += string_format( _( "* Will give a +%s bonus to block%s" ), + blocks_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) + "\n"; } else if( blocks_bonus < 0 ) { - dump << string_format( _( "* Will give a %s penalty to block%s" ), - blocks_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) << std::endl; + dump += string_format( _( "* Will give a %s penalty to block%s" ), + blocks_bonus, ngettext( " for the stack", " per stack", max_stacks ) ) + "\n"; } if( quiet ) { - dump << _( "* Attacks will be completely silent" ) << std::endl; + dump += _( "* Attacks will be completely silent" ) + std::string( "\n" ); } if( stealthy ) { - dump << _( "* Movement will make less noise" ) << std::endl; + dump += _( "* Movement will make less noise" ) + std::string( "\n" ); } - return dump.str(); + return dump; } martialart::martialart() @@ -1240,7 +1239,7 @@ float ma_technique::armor_penetration( const Character &u, damage_type type ) co std::string ma_technique::get_description() const { - std::stringstream dump; + std::string dump; std::string type; if( block_counter ) { @@ -1257,109 +1256,112 @@ std::string ma_technique::get_description() const type = _( "Offensive" ); } - dump << string_format( _( "Type: %s" ), type ) << std::endl; + dump += string_format( _( "Type: %s" ), type ) + "\n"; std::string temp = bonuses.get_description(); if( !temp.empty() ) { - dump << _( "Bonus: " ) << std::endl << temp; + dump += _( "Bonus: " ) + std::string( "\n" ) + temp; } - dump << reqs.get_description(); + dump += reqs.get_description(); if( weighting > 1 ) { - dump << string_format( _( "* Greater chance to activate: +%s%%" ), - ( 100 * ( weighting - 1 ) ) ) << std::endl; + dump += string_format( _( "* Greater chance to activate: +%s%%" ), + ( 100 * ( weighting - 1 ) ) ) + "\n"; } else if( weighting < -1 ) { - dump << string_format( _( "* Lower chance to activate: 1/%s" ), - abs( weighting ) ) << std::endl; + dump += string_format( _( "* Lower chance to activate: 1/%s" ), + abs( weighting ) ) + "\n"; } if( crit_ok ) { - dump << _( "* Can activate on a normal or a crit hit" ) << std::endl; + dump += _( "* Can activate on a normal or a crit hit" ) + + std::string( "\n" ); } else if( crit_tec ) { - dump << _( "* Will only activate on a crit" ) << std::endl; + dump += _( "* Will only activate on a crit" ) + std::string( "\n" ); } if( side_switch ) { - dump << _( "* Moves target behind you" ) << std::endl; + dump += _( "* Moves target behind you" ) + std::string( "\n" ); } if( wall_adjacent ) { - dump << _( "* Will only activate while near to a wall" ) << std::endl; + dump += _( "* Will only activate while near to a wall" ) + + std::string( "\n" ); } if( downed_target ) { - dump << _( "* Only works on a downed target" ) << std::endl; + dump += _( "* Only works on a downed target" ) + std::string( "\n" ); } if( stunned_target ) { - dump << _( "* Only works on a stunned target" ) << std::endl; + dump += _( "* Only works on a stunned target" ) + std::string( "\n" ); } if( human_target ) { - dump << _( "* Only works on a humanoid target" ) << std::endl; + dump += _( "* Only works on a humanoid target" ) + std::string( "\n" ); } if( powerful_knockback ) { - dump << _( "* Causes extra damage on knockback collision." ) << std::endl; + dump += _( "* Causes extra damage on knockback collision." ) + std::string( "\n" ); } if( dodge_counter ) { - dump << _( "* Will counterattack when you dodge" ) << std::endl; + dump += _( "* Will counterattack when you dodge" ) + std::string( "\n" ); } if( block_counter ) { - dump << _( "* Will counterattack when you block" ) << std::endl; + dump += _( "* Will counterattack when you block" ) + std::string( "\n" ); } if( miss_recovery ) { - dump << _( "* Will grant free recovery from a miss" ) << std::endl; + dump += _( "* Will grant free recovery from a miss" ) + + std::string( "\n" ); } if( grab_break ) { - dump << _( "* Will break a grab" ) << std::endl; + dump += _( "* Will break a grab" ) + std::string( "\n" ); } if( aoe == "wide" ) { - dump << _( "* Will attack in a wide arc in front of you" ) << std::endl; + dump += _( "* Will attack in a wide arc in front of you" ) + std::string( "\n" ); } else if( aoe == "spin" ) { - dump << _( "* Will attack adjacent enemies around you" ) << std::endl; + dump += _( "* Will attack adjacent enemies around you" ) + std::string( "\n" ); } else if( aoe == "impale" ) { - dump << _( "* Will attack your target and another one behind it" ) << - std::endl; + dump += _( "* Will attack your target and another one behind it" ) + + std::string( "\n" ); } if( knockback_dist ) { - dump << string_format( _( "* Will knock back enemies %d %s" ), - knockback_dist, ngettext( "tile", "tiles", knockback_dist ) ) << std::endl; + dump += string_format( _( "* Will knock back enemies %d %s" ), + knockback_dist, ngettext( "tile", "tiles", knockback_dist ) ) + "\n"; } if( knockback_follow ) { - dump << _( "* Will follow enemies after knockback." ) << std::endl; + dump += _( "* Will follow enemies after knockback." ) + std::string( "\n" ); } if( down_dur ) { - dump << string_format( _( "* Will down enemies for %d %s" ), - down_dur, ngettext( "turn", "turns", down_dur ) ) << std::endl; + dump += string_format( _( "* Will down enemies for %d %s" ), + down_dur, ngettext( "turn", "turns", down_dur ) ) + "\n"; } if( stun_dur ) { - dump << string_format( _( "* Will stun target for %d %s" ), - stun_dur, ngettext( "turn", "turns", stun_dur ) ) << std::endl; + dump += string_format( _( "* Will stun target for %d %s" ), + stun_dur, ngettext( "turn", "turns", stun_dur ) ) + "\n"; } if( disarms ) { - dump << _( "* Will disarm the target" ) << std::endl; + dump += _( "* Will disarm the target" ) + std::string( "\n" ); } if( take_weapon ) { - dump << _( "* Will disarm the target and take their weapon" ) << - std::endl; + dump += _( "* Will disarm the target and take their weapon" ) + + std::string( "\n" ); } - return dump.str(); + return dump; } bool ma_style_callback::key( const input_context &ctxt, const input_event &event, int entnum, @@ -1377,51 +1379,52 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event if( !style_selected.str().empty() ) { const martialart &ma = style_selected.obj(); - std::ostringstream buffer; + std::string buffer; if( ma.force_unarmed ) { - buffer << _( "This style forces you to use unarmed strikes, even if wielding a weapon." ); - buffer << std::endl; + buffer += _( "This style forces you to use unarmed strikes, even if wielding a weapon." ); + buffer += "\n"; } else if( ma.allow_melee ) { - buffer << _( "This style can be used with all weapons." ); - buffer << std::endl; + buffer += _( "This style can be used with all weapons." ); + buffer += "\n"; } else if( ma.strictly_melee ) { - buffer << _( "This is an armed combat style." ); - buffer << std::endl; + buffer += _( "This is an armed combat style." ); + buffer += "\n"; } - buffer << "--" << std::endl; + buffer += "--\n"; if( ma.arm_block_with_bio_armor_arms || ma.arm_block != 99 || ma.leg_block_with_bio_armor_legs || ma.leg_block != 99 ) { if( ma.arm_block_with_bio_armor_arms ) { - buffer << _( "You can arm block by installing the Arms Alloy Plating CBM" ); - buffer << std::endl; + buffer += _( "You can arm block by installing the Arms Alloy Plating CBM" ); + buffer += "\n"; } else if( ma.arm_block != 99 ) { - buffer << string_format( - _( "You can arm block at unarmed combat: %s" ), - ma.arm_block ) << std::endl; + buffer += string_format( + _( "You can arm block at unarmed combat: %s" ), + ma.arm_block ) + "\n"; } if( ma.leg_block_with_bio_armor_legs ) { - buffer << _( "You can leg block by installing the Legs Alloy Plating CBM" ); - buffer << std::endl; + buffer += _( "You can leg block by installing the Legs Alloy Plating CBM" ); + buffer += "\n"; } else if( ma.leg_block != 99 ) { - buffer << string_format( - _( "You can leg block at unarmed combat: %s" ), - ma.leg_block ) << std::endl; + buffer += string_format( + _( "You can leg block at unarmed combat: %s" ), + ma.leg_block ); + buffer += "\n"; } - buffer << "--" << std::endl; + buffer += "--\n"; } auto buff_desc = [&]( const std::string & title, const std::vector &buffs, bool passive = false ) { if( !buffs.empty() ) { - buffer << string_format( _( "
%s buffs:
" ), title ); + buffer += string_format( _( "
%s buffs:
" ), title ); for( const auto &buff : buffs ) { - buffer << std::endl << buff->get_description( passive ) ; + buffer += "\n" + buff->get_description( passive ); } - buffer << "--" << std::endl; + buffer += "--\n"; } }; @@ -1438,14 +1441,15 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event buff_desc( _( "Get hit" ), ma.ongethit_buffs ); for( const auto &tech : ma.techniques ) { - buffer << string_format( _( "
Technique:
%s " ), - _( tech.obj().name ) ) << std::endl; - buffer << tech.obj().get_description() << "--" << std::endl; + buffer += string_format( _( "
Technique:
%s " ), + _( tech.obj().name ) ) + "\n"; + buffer += tech.obj().get_description() + "--\n"; } if( !ma.weapons.empty() ) { - buffer << ngettext( "Weapon:", "Weapons:", ma.weapons.size() ) << " "; - buffer << enumerate_as_string( ma.weapons.begin(), ma.weapons.end(), []( const std::string & wid ) { + buffer += ngettext( "Weapon:", "Weapons:", + ma.weapons.size() ) + std::string( " " ); + buffer += enumerate_as_string( ma.weapons.begin(), ma.weapons.end(), []( const std::string & wid ) { return item::nname( wid ); } ); } @@ -1454,7 +1458,7 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event point( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ) ); - std::string text = replace_colors( buffer.str() ); + std::string text = replace_colors( buffer ); int width = FULL_SCREEN_WIDTH - 4; int height = FULL_SCREEN_HEIGHT - 2; const auto vFolded = foldstring( text, width ); diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index fe00793e8d913..e5d4d43c5234c 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -1377,73 +1376,72 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef " " ); // Clear the line } - std::ostringstream buffer; + std::string buffer; // Profession addictions const auto prof_addictions = sorted_profs[cur_id]->addictions(); if( !prof_addictions.empty() ) { - buffer << colorize( _( "Addictions:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Addictions:" ), c_light_blue ) + "\n"; for( const auto &a : prof_addictions ) { const auto format = pgettext( "set_profession_addictions", "%1$s (%2$d)" ); - buffer << string_format( format, addiction_name( a ), a.intensity ) << "\n"; + buffer += string_format( format, addiction_name( a ), a.intensity ) + "\n"; } } // Profession traits const auto prof_traits = sorted_profs[cur_id]->get_locked_traits(); - buffer << colorize( _( "Profession traits:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Profession traits:" ), c_light_blue ) + "\n"; if( prof_traits.empty() ) { - buffer << pgettext( "set_profession_trait", "None" ) << "\n"; + buffer += pgettext( "set_profession_trait", "None" ) + std::string( "\n" ); } else { for( const auto &t : prof_traits ) { - buffer << mutation_branch::get_name( t ) << "\n"; + buffer += mutation_branch::get_name( t ) + "\n"; } } // Profession skills const auto prof_skills = sorted_profs[cur_id]->skills(); - buffer << colorize( _( "Profession skills:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Profession skills:" ), c_light_blue ) + "\n"; if( prof_skills.empty() ) { - buffer << pgettext( "set_profession_skill", "None" ) << "\n"; + buffer += pgettext( "set_profession_skill", "None" ) + std::string( "\n" ); } else { for( const auto &sl : prof_skills ) { const auto format = pgettext( "set_profession_skill", "%1$s (%2$d)" ); - buffer << string_format( format, sl.first.obj().name(), sl.second ) << "\n"; + buffer += string_format( format, sl.first.obj().name(), sl.second ) + "\n"; } } // Profession items const auto prof_items = sorted_profs[cur_id]->items( u.male, u.get_mutations() ); - buffer << colorize( _( "Profession items:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Profession items:" ), c_light_blue ) + "\n"; if( prof_items.empty() ) { - buffer << pgettext( "set_profession_item", "None" ) << "\n"; + buffer += pgettext( "set_profession_item", "None" ) + std::string( "\n" ); } else { // TODO: If the item group is randomized *at all*, these will be different each time // and it won't match what you actually start with // TODO: Put like items together like the inventory does, so we don't have to scroll // through a list of a dozen forks. - std::ostringstream buffer_wielded; - std::ostringstream buffer_worn; - std::ostringstream buffer_inventory; + std::string buffer_wielded; + std::string buffer_worn; + std::string buffer_inventory; for( const auto &it : prof_items ) { if( it.has_flag( "no_auto_equip" ) ) { - buffer_inventory << it.display_name() << "\n"; + buffer_inventory += it.display_name() + "\n"; } else if( it.has_flag( "auto_wield" ) ) { - buffer_wielded << it.display_name() << "\n"; + buffer_wielded += it.display_name() + "\n"; } else if( it.is_armor() ) { - buffer_worn << it.display_name() << "\n"; + buffer_worn += it.display_name() + "\n"; } else { - buffer_inventory << it.display_name() << "\n"; + buffer_inventory += it.display_name() + "\n"; } } - buffer << colorize( _( "Wielded:" ), c_cyan ) << "\n"; - buffer << ( !buffer_wielded.str().empty() ? buffer_wielded.str() : - pgettext( "set_profession_item_wielded", "None\n" ) ); - buffer << colorize( _( "Worn:" ), c_cyan ) << "\n"; - buffer << ( !buffer_worn.str().empty() ? buffer_worn.str() : - pgettext( "set_profession_item_worn", "None\n" ) ); - buffer << colorize( _( "Inventory:" ), c_cyan ) << "\n"; - buffer << ( !buffer_inventory.str().empty() ? buffer_inventory.str() : - pgettext( "set_profession_item_inventory", "None\n" ) ); + buffer += colorize( _( "Wielded:" ), c_cyan ) + "\n"; + buffer += !buffer_wielded.empty() ? buffer_wielded : pgettext( "set_profession_item_wielded", + "None\n" ); + buffer += colorize( _( "Worn:" ), c_cyan ) + "\n"; + buffer += !buffer_worn.empty() ? buffer_worn : pgettext( "set_profession_item_worn", "None\n" ); + buffer += colorize( _( "Inventory:" ), c_cyan ) + "\n"; + buffer += !buffer_inventory.empty() ? buffer_inventory : pgettext( "set_profession_item_inventory", + "None\n" ); } // Profession bionics, active bionics shown first @@ -1451,36 +1449,36 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef std::sort( begin( prof_CBMs ), end( prof_CBMs ), []( const bionic_id & a, const bionic_id & b ) { return a->activated && !b->activated; } ); - buffer << colorize( _( "Profession bionics:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Profession bionics:" ), c_light_blue ) + "\n"; if( prof_CBMs.empty() ) { - buffer << pgettext( "set_profession_bionic", "None" ) << "\n"; + buffer += pgettext( "set_profession_bionic", "None" ) + std::string( "\n" ); } else { for( const auto &b : prof_CBMs ) { const auto &cbm = b.obj(); if( cbm.activated && cbm.toggled ) { - buffer << cbm.name << " (" << _( "toggled" ) << ")\n"; + buffer += string_format( _( "%s (toggled)" ), cbm.name ) + "\n"; } else if( cbm.activated ) { - buffer << cbm.name << " (" << _( "activated" ) << ")\n"; + buffer += string_format( _( "%s (activated)" ), cbm.name ) + "\n"; } else { - buffer << cbm.name << "\n"; + buffer += cbm.name + "\n"; } } } // Profession pet cata::optional montype; if( !sorted_profs[cur_id]->pets().empty() ) { - buffer << colorize( _( "Pets:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Pets:" ), c_light_blue ) + "\n"; for( auto elem : sorted_profs[cur_id]->pets() ) { monster mon( elem ); - buffer << mon.get_name() << "\n"; + buffer += mon.get_name() + "\n"; } } // Profession spells if( !sorted_profs[cur_id]->spells().empty() ) { - buffer << colorize( _( "Spells:" ), c_light_blue ) << "\n"; + buffer += colorize( _( "Spells:" ), c_light_blue ) + "\n"; for( const std::pair spell_pair : sorted_profs[cur_id]->spells() ) { - buffer << spell_pair.first->name << _( " level " ) << spell_pair.second << "\n"; + buffer += string_format( _( "%s level %d" ), spell_pair.first->name, spell_pair.second ) + "\n"; } } werase( w_items ); @@ -1488,7 +1486,7 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef _( "Press %1$s or %2$s to scroll." ), ctxt.get_desc( "LEFT" ), ctxt.get_desc( "RIGHT" ) ); - const int iheight = print_scrollable( w_items, desc_offset, buffer.str(), c_light_gray, + const int iheight = print_scrollable( w_items, desc_offset, buffer, c_light_gray, scroll_msg ); werase( w_sorting ); diff --git a/src/npc.cpp b/src/npc.cpp index a547dde81c143..ef2ed3f21c2de 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "auto_pickup.h" #include "avatar.h" @@ -2251,80 +2250,80 @@ int npc::print_info( const catacurses::window &w, int line, int vLines, int colu std::string npc::opinion_text() const { - std::stringstream ret; + std::string ret; if( op_of_u.trust <= -10 ) { - ret << _( "Completely untrusting" ); + ret += _( "Completely untrusting" ); } else if( op_of_u.trust <= -6 ) { - ret << _( "Very untrusting" ); + ret += _( "Very untrusting" ); } else if( op_of_u.trust <= -3 ) { - ret << _( "Untrusting" ); + ret += _( "Untrusting" ); } else if( op_of_u.trust <= 2 ) { - ret << _( "Uneasy" ); + ret += _( "Uneasy" ); } else if( op_of_u.trust <= 4 ) { - ret << _( "Trusting" ); + ret += _( "Trusting" ); } else if( op_of_u.trust < 10 ) { - ret << _( "Very trusting" ); + ret += _( "Very trusting" ); } else { - ret << _( "Completely trusting" ); + ret += _( "Completely trusting" ); } - ret << " (" << _( "Trust: " ) << op_of_u.trust << "); "; + ret += string_format( _( " (Trust: %d); " ), op_of_u.trust ); if( op_of_u.fear <= -10 ) { - ret << _( "Thinks you're laughably harmless" ); + ret += _( "Thinks you're laughably harmless" ); } else if( op_of_u.fear <= -6 ) { - ret << _( "Thinks you're harmless" ); + ret += _( "Thinks you're harmless" ); } else if( op_of_u.fear <= -3 ) { - ret << _( "Unafraid" ); + ret += _( "Unafraid" ); } else if( op_of_u.fear <= 2 ) { - ret << _( "Wary" ); + ret += _( "Wary" ); } else if( op_of_u.fear <= 5 ) { - ret << _( "Afraid" ); + ret += _( "Afraid" ); } else if( op_of_u.fear < 10 ) { - ret << _( "Very afraid" ); + ret += _( "Very afraid" ); } else { - ret << _( "Terrified" ); + ret += _( "Terrified" ); } - ret << " (" << _( "Fear: " ) << op_of_u.fear << "); "; + ret += string_format( _( " (Fear: %d); " ), op_of_u.fear ); if( op_of_u.value <= -10 ) { - ret << _( "Considers you a major liability" ); + ret += _( "Considers you a major liability" ); } else if( op_of_u.value <= -6 ) { - ret << _( "Considers you a burden" ); + ret += _( "Considers you a burden" ); } else if( op_of_u.value <= -3 ) { - ret << _( "Considers you an annoyance" ); + ret += _( "Considers you an annoyance" ); } else if( op_of_u.value <= 2 ) { - ret << _( "Doesn't care about you" ); + ret += _( "Doesn't care about you" ); } else if( op_of_u.value <= 5 ) { - ret << _( "Values your presence" ); + ret += _( "Values your presence" ); } else if( op_of_u.value < 10 ) { - ret << _( "Treasures you" ); + ret += _( "Treasures you" ); } else { - ret << _( "Best Friends Forever!" ); + ret += _( "Best Friends Forever!" ); } - ret << " (" << _( "Value: " ) << op_of_u.value << "); "; + ret += string_format( _( " (Value: %d); " ), op_of_u.value ); if( op_of_u.anger <= -10 ) { - ret << _( "You can do no wrong!" ); + ret += _( "You can do no wrong!" ); } else if( op_of_u.anger <= -6 ) { - ret << _( "You're good people" ); + ret += _( "You're good people" ); } else if( op_of_u.anger <= -3 ) { - ret << _( "Thinks well of you" ); + ret += _( "Thinks well of you" ); } else if( op_of_u.anger <= 2 ) { - ret << _( "Ambivalent" ); + ret += _( "Ambivalent" ); } else if( op_of_u.anger <= 5 ) { - ret << _( "Pissed off" ); + ret += _( "Pissed off" ); } else if( op_of_u.anger < 10 ) { - ret << _( "Angry" ); + ret += _( "Angry" ); } else { - ret << _( "About to kill you" ); + ret += _( "About to kill you" ); } - ret << " (" << _( "Anger: " ) << op_of_u.anger << ")"; + ret += string_format( _( " (Anger: %d)" ), op_of_u.anger ); - return ret.str(); + return ret; } static void maybe_shift( cata::optional &pos, int dx, int dy ) @@ -3047,34 +3046,34 @@ mfaction_id npc::get_monster_faction() const std::string npc::extended_description() const { - std::ostringstream ss; + std::string ss; // For some reason setting it using str or constructor doesn't work - ss << Character::extended_description(); + ss += Character::extended_description(); - ss << std::endl << "--" << std::endl; + ss += "\n--\n"; if( attitude == NPCATT_KILL ) { - ss << _( "Is trying to kill you." ); + ss += _( "Is trying to kill you." ); } else if( attitude == NPCATT_FLEE || attitude == NPCATT_FLEE_TEMP ) { - ss << _( "Is trying to flee from you." ); + ss += _( "Is trying to flee from you." ); } else if( is_player_ally() ) { - ss << _( "Is your friend." ); + ss += _( "Is your friend." ); } else if( is_following() ) { - ss << _( "Is following you." ); + ss += _( "Is following you." ); } else if( is_leader() ) { - ss << _( "Is guiding you." ); + ss += _( "Is guiding you." ); } else if( guaranteed_hostile() ) { - ss << _( "Will try to kill you or flee from you if you reveal yourself." ); + ss += _( "Will try to kill you or flee from you if you reveal yourself." ); } else { - ss << _( "Is neutral." ); + ss += _( "Is neutral." ); } if( hit_by_player ) { - ss << "--" << std::endl; - ss << _( "Is still innocent and killing them will be considered murder." ); + ss += "--\n"; + ss += _( "Is still innocent and killing them will be considered murder." ); // TODO: "But you don't care because you're an edgy psycho" } - return replace_colors( ss.str() ); + return replace_colors( ss ); } void npc::set_companion_mission( npc &p, const std::string &mission_id ) diff --git a/src/output.h b/src/output.h index fe721eef35b14..0003513f2d52b 100644 --- a/src/output.h +++ b/src/output.h @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -665,18 +664,18 @@ std::string enumerate_as_string( const _Container &values, return _( ", " ); } (); - std::ostringstream res; + std::string res; for( auto iter = values.begin(); iter != values.end(); ++iter ) { if( iter != values.begin() ) { if( std::next( iter ) == values.end() ) { - res << final_separator; + res += final_separator; } else { - res << _( ", " ); + res += _( ", " ); } } - res << *iter; + res += *iter; } - return res.str(); + return res; } /** @@ -975,12 +974,12 @@ void refresh_display(); template std::string colorize_symbols( const std::string &str, F color_of ) { - std::ostringstream res; + std::string res; nc_color prev_color = c_unset; const auto closing_tag = [ &res, prev_color ]() { if( prev_color != c_unset ) { - res << ""; + res += ""; } }; @@ -989,16 +988,16 @@ std::string colorize_symbols( const std::string &str, F color_of ) if( prev_color != new_color ) { closing_tag(); - res << ""; + res += ""; prev_color = new_color; } - res << elem; + res += elem; } closing_tag(); - return res.str(); + return res; } #endif diff --git a/src/requirements.cpp b/src/requirements.cpp index d1500ee9fd6b9..e5ec728320727 100644 --- a/src/requirements.cpp +++ b/src/requirements.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -307,65 +306,65 @@ template std::string requirement_data::print_all_objs( const std::string &header, const std::vector< std::vector > &objs ) { - std::ostringstream buffer; + std::string buffer; for( const auto &list : objs ) { - if( !buffer.str().empty() ) { - buffer << "\n" << _( "and " ); + if( !buffer.empty() ) { + buffer += std::string( "\n" ) + _( "and " ); } for( auto it = list.begin(); it != list.end(); ++it ) { if( it != list.begin() ) { - buffer << _( " or " ); + buffer += _( " or " ); } - buffer << it->to_string(); + buffer += it->to_string(); } } - if( buffer.str().empty() ) { + if( buffer.empty() ) { return std::string(); } - return header + "\n" + buffer.str() + "\n"; + return header + "\n" + buffer + "\n"; } std::string requirement_data::list_all() const { - std::ostringstream buffer; - buffer << print_all_objs( _( "These tools are required:" ), tools ); - buffer << print_all_objs( _( "These tools are required:" ), qualities ); - buffer << print_all_objs( _( "These components are required:" ), components ); - return buffer.str(); + std::string buffer; + buffer += print_all_objs( _( "These tools are required:" ), tools ); + buffer += print_all_objs( _( "These tools are required:" ), qualities ); + buffer += print_all_objs( _( "These components are required:" ), components ); + return buffer; } template std::string requirement_data::print_missing_objs( const std::string &header, const std::vector< std::vector > &objs ) { - std::ostringstream buffer; + std::string buffer; for( const auto &list : objs ) { if( any_marked_available( list ) ) { continue; } - if( !buffer.str().empty() ) { - buffer << "\n" << _( "and " ); + if( !buffer.empty() ) { + buffer += std::string( "\n" ) + _( "and " ); } for( auto it = list.begin(); it != list.end(); ++it ) { if( it != list.begin() ) { - buffer << _( " or " ); + buffer += _( " or " ); } - buffer << it->to_string(); + buffer += it->to_string(); } } - if( buffer.str().empty() ) { + if( buffer.empty() ) { return std::string(); } - return header + "\n" + buffer.str() + "\n"; + return header + "\n" + buffer + "\n"; } std::string requirement_data::list_missing() const { - std::ostringstream buffer; - buffer << print_missing_objs( _( "These tools are missing:" ), tools ); - buffer << print_missing_objs( _( "These tools are missing:" ), qualities ); - buffer << print_missing_objs( _( "These components are missing:" ), components ); - return buffer.str(); + std::string buffer; + buffer += print_missing_objs( _( "These tools are missing:" ), tools ); + buffer += print_missing_objs( _( "These tools are missing:" ), qualities ); + buffer += print_missing_objs( _( "These components are missing:" ), components ); + return buffer; } void quality_requirement::check_consistency( const std::string &display_name ) const