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

refactor: Energy Rework #5259

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

KheirFerrum
Copy link
Collaborator

Checklist

Required

Optional

  • This is a C++ PR that modifies JSON loading or behavior.
    • I have documented the changes in the appropriate location in the doc/ folder.
    • If documentation for this feature does not exist, please write it or at least note its lack in PR description.
    • New localizable fields need to be added to the lang/bn_extract_json_strings.sh script if it does not support them yet.
    • If applicable, add checks on game load that would validate the loaded data.
    • If it modifies format of save files, please add migration from the old format.

Purpose of change

Basically, make batteries use discrete charges in the form of units::energy instead of charges, which will allow us to make power_draw behaviour less cursed and in general make code that handles power more reliable.

Describe the solution

This PR isn't functional at the moment, I'm partway through a lot of infrastructure reworking but I can at least confirm that most of the sections I've changed thus far work the way I expect them to.

Right now it's mainly visual, with batteries being able to store charges as units::energy, display them when loaded, etc. The ammo_consume() function written for it is placeholder and will be converted to energy_consume() in the near future.

Describe alternatives you've considered

  • Keeping our shitty power_draw code
    • Tempting, and if I am not able to complete this within the next 2 weeks, likely.

Testing

Additional context

Procrastinated long enough. This commit is mainly proof of concept, it makes batteries type: BATTERY instead of type magazine and has them store energy as units::energy instead of charges.

`ammo_consume` is a hack for me to play with, which confirms that power is being drawn correctly when it is called.

The bionic scanner is sort of necessary at the moment for testing purposes.

Next step is to convert energy using functions over from charge usage.
@github-actions github-actions bot added src changes related to source code. tests changes related to tests data labels Aug 27, 2024
@@ -576,7 +576,6 @@
"target": "bionic_scanner_on",
"msg": "You start scanning for bionics.",
"active": true,
"need_charges": 1,
Copy link
Member

Choose a reason for hiding this comment

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

Removing this will if I recall let you turn it on even when it has zero power? Unless 1 is a default in the code already.

Copy link
Collaborator Author

@KheirFerrum KheirFerrum Aug 28, 2024

Choose a reason for hiding this comment

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

Necessary while I'm testing, since batteries don't have charges in the rework. There's not a whole lot of point in reviewing my work at this stage, it's very preliminary.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, aight. Hope it goes well then. :D

@scarf005 scarf005 added JSON related to game datas in JSON format. and removed data labels Aug 28, 2024
Add and convert most of the power handling code.

Need to update `has_energy()` and `use_energy()` pending an understanding of `visitable.cpp` code.
Finishes all the power draw code, so items that consume power via power draw will now consume power properly.

Next up is the ability to load batteries, unload batteries, and use magazines alongside batteries.
Copy link
Contributor

autofix-ci bot commented Aug 29, 2024

Autofix has formatted code style violation in this PR.

I edit commits locally (e.g: git, github desktop) and want to keep autofix
  1. Run git pull. this will merge the automated commit into your local copy of the PR branch.
  2. Continue working.
I do not want the automated commit
  1. Format your code locally, then commit it.
  2. Run git push --force to force push your branch. This will overwrite the automated commit on remote with your local one.
  3. Continue working.

If you don't do this, your following commits will be based on the old commit, and cause MERGE CONFLICT.

KheirFerrum and others added 2 commits August 30, 2024 00:43
Allow you to reload batteries into an item, add migration of batteries to new system. Lay down early framework for gun power draw system.

Energy Rework Part 3

Allow you to reload batteries into an item, add migration of batteries to new system. Lay down early framework for gun power draw system.
autofix-ci bot and others added 5 commits August 29, 2024 23:45
set and mod energy should be able to modify non-battery items
`iuse_actor.cpp` use functions now return charges to be used and energy to be used as appropriate.

Updates partially some of the jsons that use batteries as ammo
autofix-ci bot and others added 6 commits October 2, 2024 19:56
Partially updates the iuse.cpp action. Fixes up the things the merge fucks in the code.
Continue work on iuse.cpp

Note, check up on pet food, it used to consume charges from via code instead of the return function. Must confirm if that will still work.
Starting with some macros, it's working alright. Updated the firework iuse actions to use the new transforms, removed the `taser2` iuse.

Remind myself to update the hand crank to actually recharge batteries after I'm done here.
No need to bother calculating energy/units remaining if the value to compare against is 0, should save on processing time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON related to game datas in JSON format. src changes related to source code. tests changes related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants