]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reloadable shotgun: fix primary fire triggering melee attack too if clip has some... 1061/head
authorterencehill <piuntn@gmail.com>
Tue, 9 Aug 2022 13:33:11 +0000 (15:33 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 9 Aug 2022 13:33:11 +0000 (15:33 +0200)
Implementation notes:
- the first return was added to fix only the case where clip has exactly 1 bullet but player has none
- the second return was added for consistency's sake and avoids wasting a couple checks because if(WEP_CVAR(shotgun, secondary) == 1) will always return false

qcsrc/common/weapons/weapon/shotgun.qc

index 403299caabd2af51229b3551c6083a30b37fb3bf..45431597e529f9caa731c49c252a73a89e8da3a6 100644 (file)
@@ -231,6 +231,7 @@ METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentit
                                                EFFECT_BULLET_WEAK);
                     actor.(weaponentity).shotgun_primarytime = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor(actor);
                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready);
+                    return;
                 }
             }
         }
@@ -250,15 +251,18 @@ METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentit
                                                EFFECT_BULLET_WEAK);
                     actor.(weaponentity).shotgun_primarytime = time + WEP_CVAR_SEC(shotgun, alt_refire) * W_WeaponRateFactor(actor);
                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame1);
+                    return;
                 }
             }
         }
     }
+
     if(actor.(weaponentity).clip_load >= 0) // we are not currently reloading
     if(WEP_CVAR(shotgun, secondary) == 1)
-    if(((fire & 1) && !IS_BOT_CLIENT(actor) && GetResource(actor, thiswep.ammo_type) <= 0 && !(actor.items & IT_UNLIMITED_AMMO)) || (fire & 2))
+    if(((fire & 1) && !IS_BOT_CLIENT(actor) && GetResource(actor, thiswep.ammo_type) <= 0 && actor.(weaponentity).clip_load == 0 && !(actor.items & IT_UNLIMITED_AMMO)) || (fire & 2))
     if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(shotgun, refire)))
     {
+        // melee attack
         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shotgun_Attack2);
     }