Skip to content

Commit

Permalink
Merge pull request #23975 from Vasyan2006/asthma
Browse files Browse the repository at this point in the history
Reduce occurrences of asthma attacks during sleep.
  • Loading branch information
Rivet-the-Zombie authored Jun 19, 2018
2 parents 9844ca2 + 31e9c7e commit 8bf0d6b
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ int player::blood_loss( body_part bp ) const
{
int hp_cur_sum = 1;
int hp_max_sum = 1;

if( bp == bp_leg_l || bp == bp_leg_r ) {
hp_cur_sum = hp_cur[hp_leg_l] + hp_cur[hp_leg_r];
hp_max_sum = hp_max[hp_leg_l] + hp_max[hp_leg_r];
Expand All @@ -1680,7 +1680,7 @@ int player::blood_loss( body_part bp ) const
hp_cur_sum = hp_cur[hp_head];
hp_max_sum = hp_max[hp_head];
}

hp_cur_sum = std::min( hp_max_sum, std::max( 0, hp_cur_sum ) );
return 100 - ( 100 * hp_cur_sum ) / hp_max_sum;
}
Expand Down Expand Up @@ -5156,24 +5156,35 @@ void player::suffer()
}
} // Done with while-awake-only effects

if( has_trait( trait_ASTHMA ) && one_in(3600 - stim * 50) &&
if( has_trait( trait_ASTHMA ) && one_in( ( 3600 - stim * 50 ) * ( has_effect( effect_sleep ) ? 10 : 1 ) ) &&
!has_effect( effect_adrenaline ) & !has_effect( effect_datura ) ) {
bool auto_use = has_charges("inhaler", 1);
if (underwater) {
bool auto_use = has_charges( "inhaler", 1 );
if ( underwater ) {
oxygen = oxygen / 2;
auto_use = false;
}

if( has_effect( effect_sleep ) ) {
add_msg_if_player(_("You have an asthma attack!"));
wake_up();
auto_use = false;
} else {
add_msg_if_player( m_bad, _( "You have an asthma attack!" ) );
}

if (auto_use) {
use_charges("inhaler", 1);
inventory map_inv;
map_inv.form_from_map( g->u.pos(), 2 );
// check if character has an inhaler
if ( auto_use ) {
add_msg_if_player( m_bad, _( "You have an asthma attack!" ) );
use_charges( "inhaler", 1 );
add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
// check if an inhaler is somewhere near
} else if ( map_inv.has_charges( "inhaler", 1 ) ) {
add_msg_if_player( m_bad, _( "You have an asthma attack!" ) );
// create new variable to resolve a reference issue
long amount = 1;
g->m.use_charges( g->u.pos(), 2, "inhaler", amount );
add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
} else {
add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
wake_up();
}
} else if ( auto_use ) {
use_charges( "inhaler", 1 );
moves -= 40;
const auto charges = charges_of( "inhaler" );
if( charges == 0 ) {
Expand All @@ -5185,7 +5196,7 @@ void player::suffer()
}
} else {
add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
if (!is_npc()) {
if ( !is_npc() ) {
g->cancel_activity_query( _( "You have an asthma attack!" ) );
}
}
Expand Down

0 comments on commit 8bf0d6b

Please sign in to comment.