Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make copy of item to be thrown - fix throwing bugs #36296

Merged
merged 4 commits into from Dec 22, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,17 @@ void avatar_action::plthrow( avatar &you, item_location loc,
add_msg( _( "Never mind." ) );
return;
}

item &thrown = *loc;
// make a copy and get the original.
// the copy is thrown and has its and the originals charges set appropiately
// or deleted from inventory if its charges(1) or not stackable.
item *orig = loc.get_item();
item thrown;
if( orig ) {
This conversation was marked as resolved.
Show resolved Hide resolved
thrown = *orig;
} else {
debugmsg( "item location not valid for thrown item" );
return;
}
int range = you.throw_range( thrown );
if( range < 0 ) {
add_msg( m_info, _( "You don't have that item." ) );
Expand All @@ -990,7 +999,7 @@ void avatar_action::plthrow( avatar &you, item_location loc,
return;
}

if( you.is_wielding( thrown ) && thrown.has_flag( "NO_UNWIELD" ) ) {
if( you.is_wielding( *orig ) && orig->has_flag( "NO_UNWIELD" ) ) {
// pos == -1 is the weapon, NO_UNWIELD is used for bio_claws_weapon
add_msg( m_info, _( "That's part of your body, you can't throw that!" ) );
return;
Expand All @@ -1006,16 +1015,16 @@ void avatar_action::plthrow( avatar &you, item_location loc,
}
}
// if you're wearing the item you need to be able to take it off
if( you.is_wearing( thrown.typeId() ) ) {
ret_val<bool> ret = you.can_takeoff( thrown );
if( you.is_wearing( orig->typeId() ) ) {
ret_val<bool> ret = you.can_takeoff( *orig );
if( !ret.success() ) {
add_msg( m_info, "%s", ret.c_str() );
return;
}
}
// you must wield the item to throw it
if( !you.is_wielding( thrown ) ) {
you.wield( thrown );
if( !you.is_wielding( *orig ) ) {
you.wield( *orig );
This conversation was marked as resolved.
Show resolved Hide resolved
}

// Shift our position to our "peeking" position, so that the UI
Expand All @@ -1033,7 +1042,7 @@ void avatar_action::plthrow( avatar &you, item_location loc,
const target_mode throwing_target_mode = blind_throw_from_pos ? TARGET_MODE_THROW_BLIND :
TARGET_MODE_THROW;
// target_ui() sets x and y, or returns empty vector if we canceled (by pressing Esc)
std::vector<tripoint> trajectory = target_handler().target_ui( you, throwing_target_mode, &thrown,
std::vector<tripoint> trajectory = target_handler().target_ui( you, throwing_target_mode, orig,
range );

// If we previously shifted our position, put ourselves back now that we've picked our target.
Expand All @@ -1045,7 +1054,7 @@ void avatar_action::plthrow( avatar &you, item_location loc,
return;
}

if( thrown.count_by_charges() && thrown.charges > 1 ) {
if( orig->count_by_charges() && orig->charges > 1 ) {
you.weapon.mod_charges( -1 );
thrown.charges = 1;
} else {
Expand Down