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

Fix playing generic game not spending battery charges #46693

Conversation

MilosRasic
Copy link
Contributor

Summary

SUMMARY: Bugfixes "Fix playing generic game not spending battery charges"

Purpose of change

Handheld game system is not spending battery charges when a generic game is played. Looking at the code in activity_handlers.cpp, activity_handlers::game_do_turn() has battery code but it's completely lacking in activity_handlers::generic_game_do_turn().

Thought I'd fix it because I'm playing games to pass time while listening to music to boost my focus while learning from books 😃

Describe the solution

Generic game handling code is extracted as

void generic_game_turn_handler( player_activity *act, player *p, int morale_bonus,
                                int morale_max_bonus );

then both activity_handlers::generic_game_do_turn() and activity_handlers::game_do_turn() call it with different morale arguments. Values remain the same as before the fix.

Also had to add activity target in iuse::portable_game() because it was skipped by an early return when playing a generic game.

Describe alternatives you've considered

At first I thought I'd have activity_handlers::generic_game_do_turn() take additional parameters morale_bonus and morale_max_bonus with default values, then call it from activity_handlers::game_do_turn(), but it turns out real activity handlers called directly to handle an activity must have a specific signature, so I opted to extract the common logic as a separate function instead.

Testing

Loading my save with a handheld game system at the ready and tested following scenarios:

  • play a specific minigame a bit, then press q to quit
  • play a generic game
  • repeat both of the above when running out of battery in the middle of the activity

Ran unit tests. Looks like activity handlers are not covered. There's a spelling failure unrelated to my changes.

@BrettDong BrettDong added <Bugfix> This is a fix for a bug (or closes open issue) Items / Item Actions / Item Qualities Items and how they work and interact [C++] Changes (can be) made in C++. Previously named `Code` labels Jan 12, 2021
@kevingranade kevingranade merged commit 4ab911e into CleverRaven:master Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Items / Item Actions / Item Qualities Items and how they work and interact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants