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

change parameter of plthrow from int to item_location #36106

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 13 additions & 21 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,15 +935,15 @@ void avatar_action::eat( avatar &you, item_location loc )
}
}

void avatar_action::plthrow( avatar &you, int pos,
void avatar_action::plthrow( avatar &you, item_location loc,
const cata::optional<tripoint> &blind_throw_from_pos )
{
if( you.has_active_mutation( trait_SHELL2 ) ) {
add_msg( m_info, _( "You can't effectively throw while you're in your shell." ) );
return;
}
if( you.is_mounted() ) {
auto mons = g->u.mounted_creature.get();
monster *mons = g->u.mounted_creature.get();
if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
if( !mons->check_mech_powered() ) {
add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
Expand All @@ -953,18 +953,18 @@ void avatar_action::plthrow( avatar &you, int pos,
}
}

if( pos == INT_MIN ) {
pos = you.get_item_position( game_menus::inv::titled_menu( you, _( "Throw item" ),
_( "You don't have any items to throw." ) ).get_item() );
if( !loc ) {
loc = game_menus::inv::titled_menu( you, _( "Throw item" ),
_( "You don't have any items to throw." ) );
g->refresh_all();
}

if( pos == INT_MIN ) {
if( !loc ) {
add_msg( _( "Never mind." ) );
return;
}

item thrown = you.i_at( pos );
item &thrown = *loc;
int range = you.throw_range( thrown );
if( range < 0 ) {
add_msg( m_info, _( "You don't have that item." ) );
Expand All @@ -974,7 +974,7 @@ void avatar_action::plthrow( avatar &you, int pos,
return;
}

if( pos == -1 && thrown.has_flag( "NO_UNWIELD" ) ) {
if( you.is_wielding( thrown ) && thrown.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 @@ -990,24 +990,16 @@ void avatar_action::plthrow( avatar &you, int pos,
}
}
// if you're wearing the item you need to be able to take it off
if( pos < -1 ) {
auto ret = you.can_takeoff( you.i_at( pos ) );
if( you.is_wearing( thrown.typeId() ) ) {
ret_val<bool> ret = you.can_takeoff( thrown );
if( !ret.success() ) {
add_msg( m_info, "%s", ret.c_str() );
return;
}
}
// you must wield the item to throw it
if( pos != -1 ) {
you.i_rem( pos );
if( !you.wield( thrown ) ) {
// We have to remove the item before checking for wield because it
// can invalidate our pos index. Which means we have to add it
// back if the player changed their mind about unwielding their
// current item
you.i_add( thrown );
return;
}
if( !you.is_wielding( thrown ) ) {
you.wield( thrown );
}

// Shift our position to our "peeking" position, so that the UI
Expand Down Expand Up @@ -1038,7 +1030,7 @@ void avatar_action::plthrow( avatar &you, int pos,
}

if( thrown.count_by_charges() && thrown.charges > 1 ) {
you.i_at( -1 ).charges--;
you.weapon.mod_charges( -1 );
thrown.charges = 1;
} else {
you.i_rem( -1 );
Expand Down
2 changes: 1 addition & 1 deletion src/avatar_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool fire( avatar &you, map &m );
*/
bool fire( avatar &you, map &m, item &weapon, int bp_cost = 0 );
// Throw an item 't'
void plthrow( avatar &you, int pos = INT_MIN,
void plthrow( avatar &you, item_location loc,
const cata::optional<tripoint> &blind_throw_from_pos = cata::nullopt );

void unload( avatar &you );
Expand Down
5 changes: 3 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ int game::inventory_item_menu( int pos, int iStartX, int iWidth,
wield( locThisItem );
break;
case 't':
avatar_action::plthrow( u, pos );
avatar_action::plthrow( u, locThisItem );
break;
case 'c':
change_side( pos );
Expand Down Expand Up @@ -5671,7 +5671,8 @@ void game::peek( const tripoint &p )
u.setpos( prev );

if( result.peek_action && *result.peek_action == PA_BLIND_THROW ) {
avatar_action::plthrow( u, INT_MIN, p );
item_location loc;
avatar_action::plthrow( u, loc, p );
}
m.invalidate_map_cache( p.z );

Expand Down
6 changes: 4 additions & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1929,9 +1929,11 @@ bool game::handle_action()
mend();
break;

case ACTION_THROW:
avatar_action::plthrow( g->u );
case ACTION_THROW: {
item_location loc;
avatar_action::plthrow( g->u, loc );
break;
}

case ACTION_FIRE:
fire();
Expand Down