From 559dab153c2e78d1ab8f8f8621d92b9f747f6698 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Thu, 21 Nov 2019 17:22:03 +0100 Subject: [PATCH] passive power generation --- src/bionics.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/character.h | 1 + 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/bionics.cpp b/src/bionics.cpp index 3086fbd8357cd..43e80c0540a2b 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -893,7 +893,6 @@ bool Character::burn_fuel( int b, bool start ) } else if( tmp_fuel.has_flag( "PERPETUAL" ) ) { if( fuel == itype_id( "sunlight" ) ) { const double modifier = g->natural_light_level( pos().z ) / default_daylight_level(); - add_msg( std::to_string( fuel_energy * modifier * fuel_efficiency ) ); mod_power_level( units::from_kilojoule( fuel_energy ) * modifier * fuel_efficiency ); } } else { @@ -939,6 +938,43 @@ bool Character::burn_fuel( int b, bool start ) return true; } +void Character::passive_power_gen( int b ) +{ + 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 ) { + } + const std::vector &fuel_available = get_fuel_available( bio.id ); + + for( const itype_id &fuel : fuel_available ) { + const item &tmp_fuel = item( fuel ); + 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(); + 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 ); + } + } + g->m.emit_field( pos(), bio.info().power_gen_emission ); + } +} + /** * @param p the player * @param bio the bionic that is meant to be recharged. @@ -983,6 +1019,7 @@ void Character::process_bionic( int b ) bionic &bio = ( *my_bionics )[b]; // Only powered bionics should be processed if( !bio.powered ) { + passive_power_gen( b ); return; } diff --git a/src/character.h b/src/character.h index 413c76773f8aa..8b50c6aa5c8d0 100644 --- a/src/character.h +++ b/src/character.h @@ -787,6 +787,7 @@ class Character : public Creature, public visitable virtual bool deactivate_bionic( int b, bool eff_only = false ); /**Convert fuel to bionic power*/ bool burn_fuel( int b, bool start = false ); + void passive_power_gen( int b ); units::energy get_power_level() const; units::energy get_max_power_level() const;