From 4092208a9a11e36fee5d7abfec525c5f5ad2610d Mon Sep 17 00:00:00 2001 From: Eric Pierce Date: Wed, 29 Jan 2020 10:46:42 -0700 Subject: [PATCH 1/3] Prevent safecracking if wearing earphones To increase realism and game consistency regarding partial deafness Partially fixes #36013 Disallows an attempt at safecracking while player has `effect_earphones`. Due to a loophole caused by mp3 player activation being instantaneous, it is still possible to begin safecracking immediately after putting on the mp3 player (but not after 1 turn has passed with the mp3 active). --- src/iexamine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 35dc578b5e460..7f6df3c8946c6 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -106,6 +106,7 @@ static const efftype_id effect_mending( "mending" ); static const efftype_id effect_pkill2( "pkill2" ); static const efftype_id effect_teleglow( "teleglow" ); static const efftype_id effect_sleep( "sleep" ); +static const efftype_id effect_earphones( "earphones" ); static const trait_id trait_DEBUG_HS( "DEBUG_HS" ); static const trait_id trait_AMORPHOUS( "AMORPHOUS" ); @@ -1220,6 +1221,10 @@ void iexamine::safe( player &p, const tripoint &examp ) add_msg( m_info, _( "You can't crack a safe while deaf!" ) ); return; } + if( p.has_effect( effect_earphones ) ) { + add_msg( m_info, _( "You can't crack a safe while wearing headphones!" ) ); + return; + } if( query_yn( _( "Attempt to crack the safe?" ) ) ) { add_msg( m_info, _( "You start cracking the safe." ) ); // 150 minutes +/- 20 minutes per mechanics point away from 3 +/- 10 minutes per From 96ec15eeacc3923e781e9afcd8c483d43c8dc5c2 Mon Sep 17 00:00:00 2001 From: Eric Pierce Date: Wed, 29 Jan 2020 14:23:58 -0700 Subject: [PATCH 2/3] Make toggling mp3 player on/off take 1 second With the logic to prevent safecracking with `effect_earphones`, there was an edge case immediately after activating them mp3 player, still allowing a safecrack attempt to be made. Fixes #36013 Turning an mp3 player on or off now takes 1 second, where before it took 0 time. This allows `effect_earphones` to become active before the next action, preventing a safecracking attempt. Unfortunately, it leaves a second edge case when the mp3 player turns off (which also takes only 1 second); there, for some reason I can't determine, the `effect_earphones` status remains alive for a further second. As a side note, this 1-turn delay on activation, and 2-turn delay on deactivation has been clearly visible in-game in the experimental branch for quite some time, using the DeadPeople tileset. You may have noticed after turning on an mp3 player that it takes 1 further second for the icon to appear above your avatar, and that after turning it off, 2 seconds must elapse before the icon disappears. Now, because of the 1-second (de-)activation time, turning it on gives the icon right away, but turning it off still takes 1 more second. --- src/iexamine.cpp | 8 +++----- src/iuse.cpp | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 7f6df3c8946c6..fc9d0b54791fa 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -1220,12 +1220,10 @@ void iexamine::safe( player &p, const tripoint &examp ) if( p.is_deaf() ) { add_msg( m_info, _( "You can't crack a safe while deaf!" ) ); return; - } - if( p.has_effect( effect_earphones ) ) { - add_msg( m_info, _( "You can't crack a safe while wearing headphones!" ) ); + } else if( p.has_effect( effect_earphones ) ) { + add_msg( m_info, _( "You can't crack a safe with earbuds on!" ) ); return; - } - if( query_yn( _( "Attempt to crack the safe?" ) ) ) { + } else if( query_yn( _( "Attempt to crack the safe?" ) ) ) { add_msg( m_info, _( "You start cracking the safe." ) ); // 150 minutes +/- 20 minutes per mechanics point away from 3 +/- 10 minutes per // perception point away from 8; capped at 30 minutes minimum. *100 to convert to moves diff --git a/src/iuse.cpp b/src/iuse.cpp index 1bbec0c360196..80a1551b75881 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -4106,8 +4106,10 @@ int iuse::mp3( player *p, item *it, bool, const tripoint & ) p->add_msg_if_player( m_info, _( "You put in the earbuds and start listening to music." ) ); if( it->typeId() == "mp3" ) { it->convert( "mp3_on" ).active = true; + p->moves -= to_moves( 1_seconds ); } else if( it->typeId() == "smart_phone" ) { it->convert( "smartphone_music" ).active = true; + p->moves -= to_moves( 1_seconds ); } } return it->type->charges_to_use(); @@ -4185,9 +4187,11 @@ int iuse::mp3_on( player *p, item *it, bool t, const tripoint &pos ) if( it->typeId() == "mp3_on" ) { p->add_msg_if_player( _( "The mp3 player turns off." ) ); it->convert( "mp3" ).active = false; + p->moves -= to_moves( 1_seconds ); } else if( it->typeId() == "smartphone_music" ) { p->add_msg_if_player( _( "The phone turns off." ) ); it->convert( "smart_phone" ).active = false; + p->moves -= to_moves( 1_seconds ); } } return it->type->charges_to_use(); From 732dc8de95d1a8706522acec718361e59a4b4248 Mon Sep 17 00:00:00 2001 From: Eric Pierce Date: Wed, 29 Jan 2020 19:20:12 -0700 Subject: [PATCH 3/3] Use mod_moves; mp3 on/off time to 2 seconds By making the mp3 player take 2 seconds to turn off, the avatar status indicator is correctly updated, and earphone effect is correctly refreshed, allowing a safecrack attempt immediately after turning off the mp3 player. Increasing the mp3 turn-on time to 2 seconds for symmetry. --- src/iuse.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/iuse.cpp b/src/iuse.cpp index 80a1551b75881..ab2209e67e8eb 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -4106,10 +4106,10 @@ int iuse::mp3( player *p, item *it, bool, const tripoint & ) p->add_msg_if_player( m_info, _( "You put in the earbuds and start listening to music." ) ); if( it->typeId() == "mp3" ) { it->convert( "mp3_on" ).active = true; - p->moves -= to_moves( 1_seconds ); + p->mod_moves( -200 ); } else if( it->typeId() == "smart_phone" ) { it->convert( "smartphone_music" ).active = true; - p->moves -= to_moves( 1_seconds ); + p->mod_moves( -200 ); } } return it->type->charges_to_use(); @@ -4187,11 +4187,11 @@ int iuse::mp3_on( player *p, item *it, bool t, const tripoint &pos ) if( it->typeId() == "mp3_on" ) { p->add_msg_if_player( _( "The mp3 player turns off." ) ); it->convert( "mp3" ).active = false; - p->moves -= to_moves( 1_seconds ); + p->mod_moves( -200 ); } else if( it->typeId() == "smartphone_music" ) { p->add_msg_if_player( _( "The phone turns off." ) ); it->convert( "smart_phone" ).active = false; - p->moves -= to_moves( 1_seconds ); + p->mod_moves( -200 ); } } return it->type->charges_to_use();