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

feat: add an action for toggling on/off UPS charging for mundane electronics #4775

Merged
merged 4 commits into from
Jun 16, 2024

Conversation

chaosvolt
Copy link
Member

@chaosvolt chaosvolt commented Jun 10, 2024

Purpose of change

This adds the ability to toggle whether a UPS-compatible item will charge from a UPS or not via a use action, to finally fix the issue of items only implied to be compatible with UPS because it's a portable power bank you could plug it into uncontrollably draining your power as soon as you pick them up.

Fixes #3900

Closes #1605

Describe the solution

C++ changes:

  1. In itemfactory.cpp, added iuse TOGGLE_UPS_CHARGING to Item_factory::init.
  2. In iuse.cpp and iuse.h, defined iuse::toggle_ups_charging which, similar to iuse::toggle_heats_food, toggles whether an item will have the USE_UPS flag or not.

JSON changes:

  1. Added item_action JSON for TOGGLE_UPS_CHARGING action.
  2. Updated the following items to use TOGGLE_UPS_CHARGING in their use actions instead of starting with the USE_UPS flag, replaced with RECHARGE where absent, and updated item descriptions accordingly: professional camera, control laptop, e-ink tablet PC, laptop computers, mp3 players, handheld game system, smartphones, electric jackhammer, and game watch.
  3. Updated the following items in mods accordingly: C.R.I.T. gasmask, C.R.I.T. EM vest, and C.R.I.T. helmet, being a rare example of military UPS-fed armor that has internal charges instead of mandatory UPS usage, so they can afford to be set to recharge via normal means.

Documentation changes:

  1. Wrote an explanation of the TOGGLE_HEATS_FOOD and TOGGLE_UPS_CHARGING use actions in json_flags.md.

Describe alternatives you've considered

  1. Adding it as some sort of use action on the UPS itself. Less JSON work but would make code more complicated to ensure that a given UPS either tracks which items it's assigned to charge or else remotely swaps around flags, and likely requiring new item flags too.
  2. Letting mundane electronics keep the UPS charging flag as their default behavior so they can continue to be power vampires every single time you pick a new one up off the floor.

Testing

  1. Checked affected JSON files for syntax and lint errors.
  2. Compiled and load-tested.
  3. Spawned in and activated a pro camera, confirmed I can take pictures or turn UPS mode on, it gains and loses the tagtext as expected.
  4. Spawned in an mp3 player, toggled UPS charging on it then turned it on. UPS flag remained present on the item even after switching it on and off.
  5. Disabled UPS charging on said MP3 player, then confirmed that likewise turning it on and off doesn't cause the UPS tagtext to appear without being requested.
  6. Played around with using both items with a UPS in inventory, no error messages and only drew from UPS when set to.
  7. Saved and loaded with phone set to draw from UPS, no error messages on load and it remembered the flag.
  8. Checked affected C++ files for astyle.

Additional context

Checklist

@github-actions github-actions bot added src changes related to source code. JSON related to game datas in JSON format. mods PR changes related to mods. labels Jun 10, 2024
@github-actions github-actions bot added the docs PRs releated to docs page label Jun 10, 2024
@Lamandus
Copy link
Contributor

what happens to items that got a UPS module installed? They don't have an internal charge, so they will always get energy, right?

@chaosvolt
Copy link
Member Author

what happens to items that got a UPS module installed? They don't have an internal charge, so they will always get energy, right?

They should be unaffected by this since any item you'd UPS-mod would lack the use action that toggles the flag (and code doesn't yet support toolmods slapping entire use actions on items either), and conversely none of the items that were already set to use UPS should be able to install the UPS mod (if they can then that'd be a bug we need to fix).

Copy link
Member

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

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

image

@scarf005 scarf005 merged commit 95cb1e5 into cataclysmbnteam:main Jun 16, 2024
13 checks passed
@chaosvolt chaosvolt deleted the unlimited-toggling-of-power branch June 16, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs releated to docs page JSON related to game datas in JSON format. mods PR changes related to mods. src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UPS devices preference external sources of power
3 participants