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

Reload all guns and magazines #28245

Merged

Conversation

kevingranade
Copy link
Member

Summary

SUMMARY: Features "Reload all guns and magazines in inventory if reload command is repeatedly triggered."

Purpose of change

Streamlines reloading guns and magazines by automatically select guns and magazines to reload instead of requiring the player to go through the inventory for each one.

Describe the solution

Enumerates all reloadable weapons in the player inventory, sorts them into an advantageous order, and then reloads the first valid option.
Reload wielded gun.
First reload a magazine if necessary.
Then load said magazine into gun.
Reload magazines that are compatible with the current gun.
Reload other guns in inventory.
Reload misc magazines in inventory.

src/character.cpp Outdated Show resolved Hide resolved
@ZhilkinSerg ZhilkinSerg added <Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc. [C++] Changes (can be) made in C++. Previously named `Code` Controls / Input Keyboard, mouse, keybindings, input UI, etc. Ranged Ranged (firearms, bows, crossbows, throwing), balance, tactics labels Feb 18, 2019
src/character.cpp Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
src/game.cpp Outdated Show resolved Hide resolved
src/game.cpp Outdated Show resolved Hide resolved
@Firestorm01X2
Copy link
Contributor

Firestorm01X2 commented Feb 18, 2019

@kevingranade
Could you look at autofire algorithm?

I am still insisting that it has multiple problems. Probably it is not for 0.D. But it is still problem.

@Mecares
Copy link
Contributor

Mecares commented Feb 18, 2019

Could we make it so that if all guns and magazines in the inventory are reloaded but there are still empty ones on the ground in the tile you are standing on that it asks if the reload should continue with those?

@kevingranade kevingranade force-pushed the reload-all-guns-and-magazines branch from 56dcff4 to f852f36 Compare February 25, 2019 01:13
@ZhilkinSerg ZhilkinSerg self-assigned this Feb 28, 2019
@ifreund ifreund removed the 0.D Freeze label Mar 8, 2019
@ZhilkinSerg ZhilkinSerg changed the base branch from 0.D-branch to master March 10, 2019 06:58
@ZhilkinSerg ZhilkinSerg removed their assignment Mar 10, 2019
@ZhilkinSerg ZhilkinSerg self-assigned this Mar 20, 2019
{
std::vector<item_location> reloadables;

visit_items( [this, &reloadables]( item *node ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
visit_items( [this, &reloadables]( item *node ) {
visit_items( [this, &reloadables]( item * node ) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, these files got astyled while the PR was pending, hopefully this will be the last time I have to deal with that...

bool reloadable = false;
if( node->is_gun() && !node->magazine_compatible().empty() ) {
reloadable = node->magazine_current() == nullptr ||
node->ammo_remaining() < node->ammo_capacity();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node->ammo_remaining() < node->ammo_capacity();
node->ammo_remaining() < node->ammo_capacity();

} else {
reloadable = ( node->is_magazine() || node->is_bandolier() ||
( node->is_gun() && node->magazine_integral() ) ) &&
node->ammo_remaining() < node->ammo_capacity();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node->ammo_remaining() < node->ammo_capacity();
node->ammo_remaining() < node->ammo_capacity();

@kevingranade kevingranade force-pushed the reload-all-guns-and-magazines branch from 29f25b1 to 331f3b4 Compare March 22, 2019 06:01
@kevingranade kevingranade force-pushed the reload-all-guns-and-magazines branch from 331f3b4 to b2ff110 Compare March 22, 2019 06:01
@ZhilkinSerg ZhilkinSerg merged commit 63d1990 into CleverRaven:master Mar 22, 2019
}
GIVEN( "the player also has another gun with ammo" ) {
item &mag2 = dummy.i_add( item( "glockbigmag", 0, 0 ) );
const cata::optional<islot_magazine> &magazine_type2 = mag2.type->magazine;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Un)surprisingly breaks tests in osxcross-builds:

https://ci.narc.ro/job/Cataclysm-Matrix/Graphics=Curses,Platform=OSX/8648/console

13:04:20 CCACHE_CPP2=1 ccache /usr/local/osxcross/osxcross/target/bin/x86_64-apple-darwin15-clang++ -DRELEASE -DMACOSX -DGIT_VERSION -DBACKTRACE -DLOCALIZE -DUSE_HOME_DIR -ffast-math -O0  -Wall -Wextra    -fsigned-char -stdlib=libc++ -Werror -std=c++11 -MMD -MP -mmacosx-version-min=10.7 -I/usr/local/osxcross/libs/gettext/include -I/usr/local/osxcross/libs/ncurses/include -I../src -Wno-unused-variable -Wno-sign-compare -Wno-unknown-pragmas -Wno-parentheses -MMD -MP -Wall -Wextra -c savegame_test.cpp -o obj/savegame_test.o
13:04:21 reloading_test.cpp:263:55: error: unused variable 'magazine_type2' [-Werror,-Wunused-variable]
13:04:21                 const cata::optional<islot_magazine> &magazine_type2 = mag2.type->magazine;
13:04:21                                                       ^
13:04:21 1 error generated.

@adamkad1
Copy link
Contributor

adamkad1 commented Mar 23, 2019

someone said it breaks reload/unload

@ZhilkinSerg ZhilkinSerg removed their assignment Mar 23, 2019
@kevingranade kevingranade deleted the reload-all-guns-and-magazines branch June 12, 2019 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Controls / Input Keyboard, mouse, keybindings, input UI, etc. <Enhancement / Feature> New features, or enhancements on existing Info / User Interface Game - player communication, menus, etc. Ranged Ranged (firearms, bows, crossbows, throwing), balance, tactics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants