Chaingun makes two sounds firing single bullet


The chaingun in the Doom games, like its predecessor in Wolfenstein 3D, normally fires an even number of bullets each time the firing key or button is pressed. When only one bullet remains in the player's supply, that bullet is deducted and a single shot is fired, as expected — but as the engine does not check whether the ammunition has run out when producing the necessary pair of firing noises (which are DSPISTOL), the sound is still played twice as if two shots had been fired.

Some source ports have fixed this bug. However, some DM players pointed out that this changes the gameplay, because you can tell if your opponent has run out of ammo if their chaingun emits an odd number of shot sounds.

The cause of the bug can be found in A_FireCGun. The function starts the chaingun sound and immediately after, checks if the player has no ammo. It can simply be fixed by moving the S_StartSound line under the return, so the sound is started only after this check.

   void A_FireCGun ( player_t* player, pspdef_t* psp ) 
       S_StartSound (player->mo, sfx_pistol);
       if (!player->ammo[weaponinfo[player->readyweapon].ammo])
       P_SetMobjState (player->mo, S_PLAY_ATK2);
       P_SetPsprite (player,
                     + psp->state
                     - &states[S_CHAIN1] );
       P_BulletSlope (player->mo);
       P_GunShot (player->mo, !player->refire);

Demo files[edit]