P3: The ballistic ammo gauge shows weapon energy as empty unless it is completely full
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The Energy bar width is computed in hudtarget.cpp around line 6043, where fl2i truncates the ratio before the multiplication; the label lookup near line 6030 uses a bank number where a weapon class is needed. Reproduce with -ballistic_gauge and a ballistic primary, checking the bar at partial energy. Done when the bar scales with energy, the label uses the correct weapon class, and empty banks (-1) are skipped.
Written by the indexing model from the issue text.
Description
Problem
When the ballistic ammo gauge is on (-ballistic_gauge, on a ship with a ballistic primary), its Energy bar is either completely full or completely empty. Any weapon energy below 100% draws as an empty bar, so the gauge tells the player they have no energy when they may have almost all of it.
The bar's width is max_w * fl2i(energy / max_reserve) (hudtarget.cpp:6043 on master). fl2i truncates the ratio first, so it is 1 only at full energy and 0 otherwise. Multiplying before truncating (fl2i(max_w * energy / max_reserve)) gives the right width.
Steps to reproduce
- Current master (I used 8afa31842, Debug build), MediaVPs 5.0.2, launched with
-ballistic_gauge. - Use a mod that gives the player's ship a ballistic primary. I made a small test mod: a
weapons.tbmthat adds the"ballistic"flag and$Rearm Rate: 100to the Subach HL-7, and aships.tbmthat gives the GTF Ulysses$PBank Capacity: ( 1000, 1000 ). - Start SM1-01 and drain some weapon energy.
I set the energy from Lua and paused before each screenshot: at 150/150 the Energy bar is full; at 148.5/150 and at 75/150 it is empty.
Expected vs. actual behavior
Expected: the bar is drawn in proportion to the weapon energy left.
Actual: it's full at 100% and empty at anything less.
Two more problems in the same gauge, found by reading the code and not run:
hudtarget.cpp:6030looks upWeapon_infowithcurrent_primary_bank, a bank number rather than a weapon class, so the Energy label's brightness comes from the wrong weapon.hudtarget.cpp:5997and:6060readWeapon_info[primary_bank_weapons[bx]]without checking for -1, which other HUD code guards against for an empty bank. I haven't confirmed an empty primary bank can reach this gauge.
Proposed fixes
- Do the multiplication before the truncation in the bar width, as above. One line.
- Fix the other two lookups in the same pass: use the weapon class in the current bank for the label, and skip banks set to -1.
- Compute the ratio as a float clamped to 0..1, then scale it to the bar width, so energy above the reserve can't overdraw either.
- Dominant language
- C++
- Stars
- 488
- Forks
- 184
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 33
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scp-fs2open/fs2open.github.com
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
scp-fs2open/fs2open.github.com#7956 ·
Maintainers usually reply within 1 day
-
bug controls LLM-suggested
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
scp-fs2open/fs2open.github.com#7946 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 66/100
scp-fs2open/fs2open.github.com#7932 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
scp-fs2open/fs2open.github.com#7924 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
scp-fs2open/fs2open.github.com#7918 ·
Maintainers usually reply within 1 day
All issues in scp-fs2open/fs2open.github.com
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
godotengine/godot#125004 ·
Maintainers usually reply within 1 day
-
44-x-y bug :beetle:
Difficulty 1/5 Under an hour Newbie friendliness 82/100
electron/electron#55528 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
gabime/spdlog#3698 · 1 comment ·
Maintainers usually reply within 5 days
-
ai_p2 bug comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
ClickHouse/ClickHouse#128306 · 1 comment ·
Maintainers usually reply within 1 day
-
70 Instance - Raid - Outland
Difficulty 1/5 Under an hour Newbie friendliness 85/100
azerothcore/azerothcore-wotlk#28328 ·
Maintainers usually reply within 1 day