From e82c9ad0a90938dc95752ce019f568070b9e6361 Mon Sep 17 00:00:00 2001 From: strategictraveler <> Date: Sun, 25 Aug 2024 23:08:51 +0000 Subject: [PATCH] Prevent wielding items under certain conditions while driving --- src/character.cpp | 9 +++++++++ src/game.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/character.cpp b/src/character.cpp index 6fcc136ba73f9..161ffcdbeeba4 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -7777,6 +7777,15 @@ ret_val Character::can_wield( const item &it ) const mount->type->mech_weapon && it.typeId() != mount->type->mech_weapon ) { return ret_val::make_failure( _( "You cannot wield anything while piloting a mech." ) ); } + if( controlling_vehicle ) { + if( worn_with_flag( flag_RESTRICT_HANDS ) ) { + return ret_val::make_failure( _( "Something you are wearing hinders the use of both hands." ) ); + } + if( !has_two_arms_lifting() || it.has_flag( flag_ALWAYS_TWOHAND ) ) { + return ret_val::make_failure( _( "You can't wield your %s while driving." ), + it.tname() ); + } + } return ret_val::make_success(); } diff --git a/src/game.cpp b/src/game.cpp index 68fa7d4af6e5d..fd50a33c71651 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5537,6 +5537,35 @@ void game::control_vehicle() if( !veh->handle_potential_theft( u ) ) { return; // player not owner and refused to steal } + const item_location weapon = u.get_wielded_item(); + if(weapon) { + if( u.worn_with_flag( flag_RESTRICT_HANDS ) ) { + add_msg( m_info, _( "Something you are wearing hinders the use of both hands." ) ); + return; + } + if( !u.has_two_arms_lifting() ) { + if( query_yn( + _( "You can't drive because you have to wield a %s.\n\nPut it away?" ), + weapon->tname() ) ) { + if( !u.unwield() ) { + return; + } + } else { + return; + } + } + if(weapon->is_two_handed( u ) ) { + if( query_yn( + _( "You can't drive because you have to wield a %s with both hands.\n\nPut it away?" ), + weapon->tname() ) ) { + if( !u.unwield() ) { + return; + } + } else { + return; + } + } + } if( veh->engine_on ) { u.controlling_vehicle = true; add_msg( _( "You take control of the %s." ), veh->name );