Skip to content

Fix ammo pack spawning and weapon bitmask check in FinishSpawningItem - #461

Open
pdewilde wants to merge 1 commit into
Razish:masterfrom
pdewilde:fix/ammo-spawn-check
Open

pdewilde wants to merge 1 commit into
Razish:masterfrom
pdewilde:fix/ammo-spawn-check

Conversation

@pdewilde

Copy link
Copy Markdown

Problem

In FinishSpawningItem (game/g_items.cpp), the IT_AMMO check has two bugs that prevent ammo packs from spawning properly:

if (ent->item->giType == IT_AMMO) {
    ammo_e ammo_type = (ammo_e)ent->item->giTag;
    for (int i = WP_BRYAR_PISTOL; i < WP_NUM_WEAPONS; i++) {
        if (G_AmmoForWeapon((weapon_e)i) == ammo_type) {
            if (g_weaponDisable.bits & i) {
                continue; // disabled
            } else {
                return; // at least one weapon is enabled - spawn it
            }
        }
    }
    G_FreeEntity(ent);
    return;
}
  1. Wrong bitmask test (g_weaponDisable.bits & i):
    g_weaponDisable.bits is a bitmask where weapon i (WP_BRYAR_PISTOL = 4, WP_BLASTER = 5, WP_DISRUPTOR = 6, ..., WP_ROCKET_LAUNCHER = 11) is represented by bit (1 << i), not the raw integer i. Testing g_weaponDisable.bits & i compares against the wrong bits (for example, WP_BLASTER = 5 (0b101) checks bits 0 and 2 instead of bit 5).
  2. Early return; skips item initialization:
    When an enabled weapon is found, the else branch returns immediately out of FinishSpawningItem(). That skips the entire second half of the function — setting ent->s.eType = ET_ITEM, ent->s.modelindex, ent->r.contents = CONTENTS_TRIGGER, ent->touch = Touch_Item, tracing to the floor, and calling trap->LinkEntity(ent). As a result, ammo pickups whose weapons are enabled never appear or become pickable in the world.

Fix

  • Check !(g_weaponDisable.bits & (1 << i)) against the weapon's actual bit in g_weaponDisable.bits.
  • Record weaponEnabled = qtrue; break; instead of returning early, so execution continues through the rest of FinishSpawningItem() to spawn and link the item.
  • Only call G_FreeEntity(ent); return; when !weaponEnabled.

Verification

Tested on mp/ffa1 with g_weaponDisable 0: previously 0 ammo_* entities spawned/linked; with this fix, all 14 ammo_* pickups spawn, render, and can be collected normally, and disabling a weapon's bit properly suppresses its ammo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant