Skip to content

Commit

Permalink
More accurate weapon firing interval control
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Jan 26, 2017
1 parent 1a4db49 commit 27d9320
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/Client/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace spades {
owner(p),
time(0),
shooting(false),
shootingPreviously(false),
reloading(false),
nextShotTime(0.f),
reloadEndTime(-100.f),
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions Sources/Client/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace spades {
Player *owner;
float time;
bool shooting;
bool shootingPreviously;
bool reloading;
float nextShotTime;
float reloadStartTime;
Expand Down

0 comments on commit 27d9320

Please sign in to comment.