Implement energy and power classes to allow appropriate units to be used everywhere, separate batteries from magazines #32067
Description
Is your feature request related to a problem? Please describe.
Working with integer kJ values for power draw under 1kW requires using RNG to decide if a charge will be consumed in a given turn, which becomes more inconsistent the lower the power draw is. See #30656.
See also the original PR #31079 which is being split up as it was going to get far too big.
Describe the solution you'd like
Energy and power should have supporting code for quantity classes that allow much higher precision.
- Implement energy quantity using
units::quantity
- Add energy units class #31988 - Rework
read_from_json_string
to load any quantity string - Template read_from_json_string #32015 - Support saving and loading
units::quantity
data - Implement battery item type #32141 - Implement new item type
BATTERY
with energy quantity - Implement battery item type #32141 - Allow reloading items with
BATTERY
items - Fully support use of BATTERY items by tools #32193 - Rework ammo consumption to work with
BATTERY
items - Fully support use of BATTERY items by tools #32193 - Require voltmeter and electronics skill to know state of charge
- Implement power using
units::quantity
- Use power quantity for items with
power_draw
- Use power quantity for vehicle power
- Add unit tests covering new code
- Charging works correctly
- Update
Item_factory::check_definitions
for new items- Check battery definitions
- Check electric tool definitions
Describe alternatives you've considered
Making battery charges millijoules would be the easiest solution but then we'd have to use that precision everywhere and some cases are more appropriately handled with larger units. Separating batteries from magazines will also allow easier modification in the future if there is interest in making batteries more detailed eg modeling maximum voltage and current.