Skip to content

Commit

Permalink
passive power generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed Nov 21, 2019
1 parent 4549400 commit 559dab1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<itype_id> &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.
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ class Character : public Creature, public visitable<Character>
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;
Expand Down

0 comments on commit 559dab1

Please sign in to comment.