Skip to content

Commit

Permalink
Prevent wielding items under certain conditions while driving
Browse files Browse the repository at this point in the history
  • Loading branch information
strategictraveler committed Aug 25, 2024
1 parent 9bacf01 commit e82c9ad
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7777,6 +7777,15 @@ ret_val<void> Character::can_wield( const item &it ) const
mount->type->mech_weapon && it.typeId() != mount->type->mech_weapon ) {
return ret_val<void>::make_failure( _( "You cannot wield anything while piloting a mech." ) );
}
if( controlling_vehicle ) {
if( worn_with_flag( flag_RESTRICT_HANDS ) ) {
return ret_val<void>::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<void>::make_failure( _( "You can't wield your %s while driving." ),
it.tname() );
}
}

return ret_val<void>::make_success();
}
Expand Down
29 changes: 29 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit e82c9ad

Please sign in to comment.