-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing error thrown when unloading gun when there is no inventory ava…
…ilable (#48999) * Adding unloaded gun to avoid * Added unit test * Unload partial ammo of wielded item without duplication Signed-off-by: Lance Finfrock <lancewf@gmail.com> Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com> Co-authored-by: RoyBerube <royberube1965@gmail.com>
- Loading branch information
1 parent
9e12cf5
commit ce412c8
Showing
4 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <list> | ||
#include <memory> | ||
|
||
#include "avatar.h" | ||
#include "calendar.h" | ||
#include "catch/catch.hpp" | ||
#include "item.h" | ||
#include "map.h" | ||
#include "map_helpers.h" | ||
#include "optional.h" | ||
#include "player_helpers.h" | ||
#include "type_id.h" | ||
|
||
/** | ||
* When a player has no open inventory to place unloaded bullets, but there is room in the gun being | ||
* unloaded the bullets are dropped. | ||
* issue# 29839 | ||
*/ | ||
|
||
TEST_CASE( "unload_revolver_naked_one_bullet", "[unload][nonmagzine]" ) | ||
{ | ||
clear_avatar(); | ||
clear_map(); | ||
|
||
Character &dummy = get_player_character(); | ||
avatar &player_character = get_avatar(); | ||
|
||
// revolver with only one of six bullets | ||
item revolver( "ruger_redhawk" ); | ||
revolver.ammo_set( revolver.ammo_default(), 1 ); | ||
|
||
// wield the revolver | ||
REQUIRE( !player_character.is_armed( ) ); | ||
REQUIRE( player_character.wield( revolver ) ); | ||
REQUIRE( player_character.is_armed( ) ); | ||
|
||
CHECK( player_character.weapon.ammo_remaining() == 1 ); | ||
|
||
// Unload weapon | ||
item_location revo_loc( dummy, &player_character.weapon ); | ||
player_character.moves = 100; | ||
REQUIRE( player_character.unload( revo_loc ) ); | ||
player_character.activity.do_turn( player_character ); | ||
|
||
// No bullets in wielded gun | ||
CHECK( player_character.weapon.ammo_remaining() == 0 ); | ||
|
||
// No bullets in inventory | ||
const std::vector<item *> bullets = dummy.items_with( []( const item & item ) { | ||
return item.is_ammo(); | ||
} ); | ||
CHECK( bullets.empty() ); | ||
} | ||
|
||
TEST_CASE( "unload_revolver_naked_fully_loaded", "[unload][nonmagzine]" ) | ||
{ | ||
clear_avatar(); | ||
clear_map(); | ||
|
||
Character &dummy = get_player_character(); | ||
avatar &player_character = get_avatar(); | ||
|
||
// revolver fully loaded | ||
item revolver( "ruger_redhawk" ); | ||
revolver.ammo_set( revolver.ammo_default(), revolver.remaining_ammo_capacity() ); | ||
|
||
// wield the revolver | ||
REQUIRE( !player_character.is_armed( ) ); | ||
REQUIRE( player_character.wield( revolver ) ); | ||
REQUIRE( player_character.is_armed( ) ); | ||
|
||
CHECK( player_character.weapon.remaining_ammo_capacity() == 0 ); | ||
|
||
// Unload weapon | ||
item_location revo_loc( dummy, &player_character.weapon ); | ||
player_character.moves = 100; | ||
REQUIRE( player_character.unload( revo_loc ) ); | ||
player_character.activity.do_turn( player_character ); | ||
|
||
// No bullets in wielded gun | ||
CHECK( player_character.weapon.ammo_remaining() == 0 ); | ||
|
||
// No bullets in inventory | ||
const std::vector<item *> bullets = dummy.items_with( []( const item & item ) { | ||
return item.is_ammo(); | ||
} ); | ||
CHECK( bullets.empty() ); | ||
} |