Skip to content

Commit

Permalink
Prevent wielding items under certain conditions while driving (#75955)
Browse files Browse the repository at this point in the history
* Prevent wielding items under certain conditions while driving

* Formatting

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* More formatting

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* More formatting

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: strategictraveler <>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
strategictraveler and github-actions[bot] authored Aug 27, 2024
1 parent 8d2ad4c commit 5e19877
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7777,6 +7777,16 @@ 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 5e19877

Please sign in to comment.