Skip to content

Commit

Permalink
Fix for Unloaded ammo belt doesn't disappear (CleverRaven#58)
Browse files Browse the repository at this point in the history
* Fix for Unloaded ammo belt doesn't disappear

Fix for Unloaded ammo belt doesn't disappear

* remove commented lines

remove commented lines

* astyling iuse.cpp

astyling iuse.cpp

* Pre inline

Pre inline

* inline and astyle

inline and astyle

* Revert "inline and astyle"

This reverts commit 8b53d62.

* Done

Done

* to value

to value

* correcting

correcting

Co-authored-by: firestorm01x2 <firestorm01x2gmail.com>
  • Loading branch information
Firestorm01X2 authored Sep 16, 2020
1 parent f18cd63 commit ce5603c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,8 @@ void avatar_action::aim_do_turn( avatar &you, map &m )
bool not_aiming = you.activity.id() != ACT_AIM;
if( not_aiming && gun->has_flag( flag_RELOAD_AND_SHOOT ) ) {
const auto previous_moves = you.moves;
g->unload( *gun );
item_location loc = item_location( you, gun.target );
g->unload( loc );
// Give back time for unloading as essentially nothing has been done.
// Note that reload_time has not been applied either.
you.moves = previous_moves;
Expand Down Expand Up @@ -1284,9 +1285,5 @@ void avatar_action::unload( avatar &you )
return;
}

if( you.unload( *loc ) ) {
if( loc->has_flag( "MAG_DESTROY" ) && loc->ammo_remaining() == 0 ) {
loc.remove_item();
}
}
you.unload( loc );
}
6 changes: 3 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
u.drop( locThisItem, u.pos() );
break;
case 'U':
unload( oThisItem );
unload( locThisItem );
break;
case 'r':
reload( locThisItem );
Expand Down Expand Up @@ -8652,9 +8652,9 @@ void game::reload_weapon( bool try_everything )
reload_item();
}

bool game::unload( item &it )
bool game::unload( item_location loc )
{
return u.unload( it );
return u.unload( loc );
}

void game::wield( item_location &loc )
Expand Down
2 changes: 1 addition & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ class game
point place_player( const tripoint &dest );
void place_player_overmap( const tripoint &om_dest );

bool unload( item &it ); // Unload a gun/tool 'U'
bool unload( item_location loc ); // Unload a gun/tool 'U'

unsigned int get_seed() const;

Expand Down
4 changes: 2 additions & 2 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ int iuse::remove_all_mods( player *p, item *, bool, const tripoint & )
return 0;
}

if( !loc->ammo_remaining() || g->unload( *loc ) ) {
if( !loc->ammo_remaining() || g->unload( loc ) ) {
item *mod = loc->contents.get_item_with(
[]( const item & e ) {
return e.is_toolmod() && !e.is_irremovable();
Expand Down Expand Up @@ -5917,7 +5917,7 @@ int iuse::toolmod_attach( player *p, item *it, bool, const tripoint & )
}

if( loc->ammo_remaining() ) {
if( !g->unload( *loc ) ) {
if( !g->unload( loc ) ) {
p->add_msg_if_player( m_info, _( "You cancel unloading the tool." ) );
return 0;
}
Expand Down
13 changes: 10 additions & 3 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3095,8 +3095,9 @@ bool player::add_or_drop_with_msg( item &it, const bool unloading )
return true;
}

bool player::unload( item &it )
bool player::unload( item_location loc )
{
item &it = *loc.get_item();
// Unload a container consuming moves per item successfully removed
if( it.is_container() || it.is_bandolier() ) {
if( it.contents.empty() ) {
Expand Down Expand Up @@ -3208,7 +3209,9 @@ bool player::unload( item &it )
}

mod_moves( -std::min( 200, mv ) );

if( loc->has_flag( "MAG_DESTROY" ) && loc->ammo_remaining() == 0 ) {
loc.remove_item();
}
return true;

} else if( target->magazine_current() ) {
Expand Down Expand Up @@ -3270,8 +3273,10 @@ bool player::unload( item &it )

add_msg( _( "You unload your %s." ), target->tname() );
return true;

}


void player::use_wielded()
{
use( -1 );
Expand Down Expand Up @@ -3483,7 +3488,9 @@ bool player::gunmod_remove( item &gun, item &mod )
debugmsg( "Cannot remove non-existent gunmod" );
return false;
}
if( mod.ammo_remaining() && !g->unload( mod ) ) {

item_location loc = item_location( *this, &mod );
if( mod.ammo_remaining() && !g->unload( loc ) ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class player : public Character
/** So far only called by unload() from game.cpp */
bool add_or_drop_with_msg( item &it, bool unloading = false );

bool unload( item &it );
bool unload( item_location loc );

/**
* Try to wield a contained item consuming moves proportional to weapon skill and volume.
Expand Down
3 changes: 2 additions & 1 deletion src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,8 @@ void vehicle::interact_with( const tripoint &pos, int interact_part )
return;
}
case UNLOAD_TURRET: {
g->unload( *turret.base() );
item_location loc = turret.base();
g->unload( loc );
return;
}
case RELOAD_TURRET: {
Expand Down
3 changes: 2 additions & 1 deletion tests/reloading_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ TEST_CASE( "reload_gun_with_swappable_magazine", "[reload],[gun]" )
REQUIRE( gun_pos != INT_MIN );
item &glock = dummy.i_at( gun_pos );
// We're expecting the magazine to end up in the inventory.
g->unload( glock );
item_location glock_loc( dummy, &glock );
REQUIRE( g->unload( glock_loc ) );
int magazine_pos = dummy.inv.position_by_type( "glockmag" );
REQUIRE( magazine_pos != INT_MIN );
item &magazine = dummy.inv.find_item( magazine_pos );
Expand Down

0 comments on commit ce5603c

Please sign in to comment.