derhass reported that using demo content allows the user to select
non-demo weapons, which then render incorrectly. derhass observed the
problem when the game automatically changed weapons, but affected users
can also select the missing weapon by hand. Demo data sets non-demo
weapons to have zero ammo_usage, so a player has "enough" rounds even
when he has none. Past releases blocked this through the dedicated
secondary_weapon_flags field. Add an explicit check for non-zero ammo.
Reported-by: derhass <https://github.com/dxx-rebirth/dxx-rebirth/issues/165>
Commit 7da64d3 added the ability to select a weapon when firing stops.
However, it did not take into account that
select_primary_weapon/select_secondary_weapon do not check whether the
selected weapon is available. The caller must perform that check. The
draft version proposed by Mako88 in the original feature request mostly
avoided the problem by clearing the delayed auto-select when it was
first applied. That version would only manifest the problem if the
player had a delayed auto-select and lost the weapon before resolving
it, whether due to death, a thief bot, or, in the case of mines,
direct-dropping the last mine by the "Drop Bomb" key.
The version that went in switched to using delayed==active to indicate
that no change was required. Under that design, the incorrect
auto-select appears if the player loses the active weapon even if no
delayed selection was pending.
Add a check that the player has the weapon before switching to it and
reset delayed=current if the delayed weapon is not available. This
fixes all known cases under which a spurious delayed selection could
activate a missing weapon and prevents repeated checks for weapon
availability.
Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/158>
Fixes: 7da64d3782 ("Add new autoselect-while-firing mode: "when firing stops"")
Mako88 reports that some users want not to autoselect while firing, but
do not notice when a new weapon is added to the HUD, and end up never
activating a preferred weapon. Add a new autoselect mode that remembers
what would be selected and switches to it once the player ceases firing.
Changes since Mako88's proposed version:
- Use `enum class` for autoselection mode and a radio button to
represent the decision of Immediate/Never/Delayed.
- Handle delayed autoselect for vulcan ammo.
- Set Delayed_primary == Primary_weapon to indicate no change is needed,
rather than Delayed_primary==-1. This lets some paths use
Delayed_primary without checking for a magic value.
- Likewise Delayed_secondary / Secondary_weapon.
- Update Delayed_primary/Delayed_secondary when changing active
primary/secondary weapon, so that a player who changes weapons while
firing will automatically clear any deferred change.
Requested-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/97>
Based-on-patch-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/pull/147>
Autoselect from pick_up_vulcan_ammo only ever armed the Vulcan cannon,
even if the user has and prefers a Gauss cannon. This is probably an
oversight from when D2 weapons were added. Rework the pickup logic in
D2 so that the more desirable of Vulcan or Gauss is picked.
Autoselect events are gated on the player having none of the item prior
to this pickup, so making the mini-autoselect more aggressive should not
cause unwanted switches.
Since the main autoselect is complicated, requiring the mini-autoselect
to happen only when the main autoselect is skipped makes it complicated
for players to reason about whether the mini-autoselect will happen.
Modifying a by-value temporary does not affect the underlying container,
so modifying it is almost always a bug. Require use of a by-reference
capture when modification is desired.
sed -i -e 's/range_for\s*(\s*\(const\s\+\)\?auto\s\+\([[:alpha:]_]\)/range_for (const auto \2/g'
Fix potential for initializing .children to wrong value with old data
files. Currently, this cannot be hit because no caller uses the right
combination of arguments to cause it.
Rely on partial_range to report invalid custom files.