Skip to content

Commit

Permalink
const and & stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed Nov 21, 2019
1 parent 559dab1 commit e094038
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<itype_id> fuel_available = get_fuel_available( bio.id );
const float fuel_efficiency = bio.info().fuel_efficiency;
const std::vector<itype_id> &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." ),
Expand All @@ -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 ) {
Expand All @@ -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 {
Expand All @@ -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 {

Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );
}
}

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

0 comments on commit e094038

Please sign in to comment.