diff --git a/src/bionics.cpp b/src/bionics.cpp index 43e80c0540a2b..007e0e819de73 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -845,8 +845,8 @@ bool Character::burn_fuel( int b, bool start ) return true; } const bool is_metabolism_powered = bio.is_this_fuel_powered( "metabolism" ); - const std::vector fuel_available = get_fuel_available( bio.id ); - const float fuel_efficiency = bio.info().fuel_efficiency; + const std::vector &fuel_available = get_fuel_available( bio.id ); + const float &fuel_efficiency = bio.info().fuel_efficiency; if( start && fuel_available.empty() ) { add_msg_player_or_npc( m_bad, _( "Your %s does not have enought fuel to start." ), @@ -860,7 +860,7 @@ bool Character::burn_fuel( int b, bool start ) if( !start ) { for( const itype_id &fuel : fuel_available ) { const item &tmp_fuel = item( fuel ); - const int fuel_energy = tmp_fuel.fuel_energy(); + const int &fuel_energy = tmp_fuel.fuel_energy(); int current_fuel_stock; if( is_metabolism_powered ) { @@ -885,14 +885,14 @@ bool Character::burn_fuel( int b, bool start ) if( current_fuel_stock > 0 ) { if( is_metabolism_powered ) { - const int kcal_consumed = fuel_energy; + const int &kcal_consumed = fuel_energy; // 1kcal = 4187 J - const units::energy power_gain = kcal_consumed * 4184_J * fuel_efficiency; + const units::energy &power_gain = kcal_consumed * 4184_J * fuel_efficiency; mod_stored_kcal( -kcal_consumed ); mod_power_level( power_gain ); } else if( tmp_fuel.has_flag( "PERPETUAL" ) ) { if( fuel == itype_id( "sunlight" ) ) { - const double modifier = g->natural_light_level( pos().z ) / default_daylight_level(); + const double &modifier = g->natural_light_level( pos().z ) / default_daylight_level(); mod_power_level( units::from_kilojoule( fuel_energy ) * modifier * fuel_efficiency ); } } else { @@ -902,16 +902,7 @@ bool Character::burn_fuel( int b, bool start ) mod_power_level( units::from_kilojoule( fuel_energy ) * fuel_efficiency ); } - if( bio.info().exothermic_power_gen ) { - const int heat_prod = fuel_energy * ( 1 - fuel_efficiency ); - const int heat_level = std::min( heat_prod / 10, 4 ); - const int heat_spread = std::max( heat_prod / 10 - heat_level, 1 ); - const emit_id hotness = emit_id( "emit_hot_air" + to_string( heat_level ) + "_cbm" ); - g->m.emit_field( pos(), hotness, heat_spread ); - for( const auto bp : bio.info().occupied_bodyparts ) { - add_effect( efftype_id( "heating_bionic" ), 2_seconds, bp.first, false, heat_prod ); - } - } + heat_emission( b, fuel_energy, fuel_efficiency ); g->m.emit_field( pos(), bio.info().power_gen_emission ); } else { @@ -940,7 +931,7 @@ bool Character::burn_fuel( int b, bool start ) void Character::passive_power_gen( int b ) { - bionic &bio = ( *my_bionics )[b]; + const bionic &bio = ( *my_bionics )[b]; const float &passive_fuel_efficiency = bio.info().passive_fuel_efficiency; if( bio.info().fuel_opts.empty() || bio.is_this_fuel_powered( "muscle" ) || passive_fuel_efficiency == 0.0 ) { @@ -949,29 +940,38 @@ void Character::passive_power_gen( int b ) for( const itype_id &fuel : fuel_available ) { const item &tmp_fuel = item( fuel ); - const int fuel_energy = tmp_fuel.fuel_energy(); + const int &fuel_energy = tmp_fuel.fuel_energy(); if( !tmp_fuel.has_flag( "PERPETUAL" ) ) { continue; } if( fuel == itype_id( "sunlight" ) ) { - const double modifier = g->natural_light_level( pos().z ) / default_daylight_level(); + const double &modifier = g->natural_light_level( pos().z ) / default_daylight_level(); mod_power_level( units::from_kilojoule( fuel_energy ) * modifier * passive_fuel_efficiency ); } else { mod_power_level( units::from_kilojoule( fuel_energy ) * passive_fuel_efficiency ); } - if( bio.info().exothermic_power_gen ) { - const int heat_prod = fuel_energy * ( 1 - passive_fuel_efficiency ); - const int heat_level = std::min( heat_prod / 10, 4 ); - const int heat_spread = std::max( heat_prod / 10 - heat_level, 1 ); - const emit_id hotness = emit_id( "emit_hot_air" + to_string( heat_level ) + "_cbm" ); - g->m.emit_field( pos(), hotness, heat_spread ); - for( const auto bp : bio.info().occupied_bodyparts ) { - add_effect( efftype_id( "heating_bionic" ), 2_seconds, bp.first, false, heat_prod ); - } - } + heat_emission( b, fuel_energy, passive_fuel_efficiency ); g->m.emit_field( pos(), bio.info().power_gen_emission ); + + } +} + +void Character::heat_emission( int b, int fuel_energy, float efficiency ) +{ + const bionic &bio = ( *my_bionics )[b]; + if( !bio.info().exothermic_power_gen ) { + return; + } + + const int &heat_prod = fuel_energy * ( 1 - efficiency ); + const int &heat_level = std::min( heat_prod / 10, 4 ); + const int &heat_spread = std::max( heat_prod / 10 - heat_level, 1 ); + const emit_id hotness = emit_id( "emit_hot_air" + to_string( heat_level ) + "_cbm" ); + g->m.emit_field( pos(), hotness, heat_spread ); + for( const auto bp : bio.info().occupied_bodyparts ) { + add_effect( efftype_id( "heating_bionic" ), 2_seconds, bp.first, false, heat_prod ); } } diff --git a/src/character.h b/src/character.h index 8b50c6aa5c8d0..7fd3690490834 100644 --- a/src/character.h +++ b/src/character.h @@ -788,6 +788,7 @@ class Character : public Creature, public visitable /**Convert fuel to bionic power*/ bool burn_fuel( int b, bool start = false ); void passive_power_gen( int b ); + void heat_emission( int b, int fuel_energy, float efficiency ); units::energy get_power_level() const; units::energy get_max_power_level() const;