From 27d9320476aa17d321399216fd3c9be2cad86c89 Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 26 Jan 2017 15:55:35 +0900 Subject: [PATCH] More accurate weapon firing interval control --- Sources/Client/Weapon.cpp | 12 ++++++++++-- Sources/Client/Weapon.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/Client/Weapon.cpp b/Sources/Client/Weapon.cpp index e2e1db9c4..40c0dca5d 100644 --- a/Sources/Client/Weapon.cpp +++ b/Sources/Client/Weapon.cpp @@ -35,6 +35,7 @@ namespace spades { owner(p), time(0), shooting(false), + shootingPreviously(false), reloading(false), nextShotTime(0.f), reloadEndTime(-100.f), @@ -81,6 +82,10 @@ namespace spades { // abort slow reload reloading = false; + if (!shootingPreviously) { + nextShotTime = std::max(nextShotTime, time); + } + // Automatic operation of weapon. if (time >= nextShotTime && (ammo > 0 || !ownerIsLocalPlayer)) { fired = true; @@ -95,10 +100,13 @@ namespace spades { if (world->GetListener()) { world->GetListener()->PlayerFiredWeapon(owner); } - nextShotTime = time + GetDelay(); + nextShotTime += GetDelay(); } else if (time >= nextShotTime) { dryFire = true; } + shootingPreviously = true; + } else { + shootingPreviously = false; } if (reloading) { if (time >= reloadEndTime) { @@ -211,7 +219,7 @@ namespace spades { public: SMGWeapon3(World *w, Player *p) : Weapon(w, p) {} virtual std::string GetName() { return "SMG"; } - virtual float GetDelay() { return 0.1f; } + virtual float GetDelay() { return 0.11f; } virtual int GetClipSize() { return 30; } virtual int GetMaxStock() { return 120; } virtual float GetReloadTime() { return 2.5f; } diff --git a/Sources/Client/Weapon.h b/Sources/Client/Weapon.h index 505655d3e..b8443753d 100644 --- a/Sources/Client/Weapon.h +++ b/Sources/Client/Weapon.h @@ -34,6 +34,7 @@ namespace spades { Player *owner; float time; bool shooting; + bool shootingPreviously; bool reloading; float nextShotTime; float reloadStartTime;