From 5bfd4069ef6b4fd44ff270f1d63b2955f5e66d41 Mon Sep 17 00:00:00 2001
From: Mitchell Richters <mjr4077au@gmail.com>
Date: Wed, 26 Aug 2020 20:55:46 +1000
Subject: [PATCH] - Blood: Cleanup some timing variables following timing
 uplift.

* Remove cast of int on `gFrameClock` since gFrameClock is now just an int.
* Remove unused `gFrameTicks`.
* Remove unused `gFrameRate`.
* Rename `gFrame` to `gFrameCount` so it's easier to search and distinguish from `gFrameClock` without relying on regex.
---
 source/blood/src/actor.cpp         | 24 ++++++++++++------------
 source/blood/src/ai.cpp            | 20 ++++++++++----------
 source/blood/src/aiunicult.cpp     |  2 +-
 source/blood/src/animatesprite.cpp |  2 +-
 source/blood/src/blood.cpp         |  9 ++++-----
 source/blood/src/eventq.cpp        |  4 ++--
 source/blood/src/gameutil.cpp      | 12 ------------
 source/blood/src/gameutil.h        |  1 -
 source/blood/src/globals.cpp       |  4 +---
 source/blood/src/globals.h         |  4 +---
 source/blood/src/loadsave.cpp      | 11 +++--------
 source/blood/src/network.cpp       |  3 +--
 source/blood/src/network.h         |  1 -
 source/blood/src/nnexts.cpp        |  8 ++++----
 source/blood/src/replace.cpp       |  2 +-
 source/blood/src/view.cpp          |  3 +--
 source/blood/src/weapon.cpp        | 18 +++++++++---------
 17 files changed, 51 insertions(+), 77 deletions(-)

diff --git a/source/blood/src/actor.cpp b/source/blood/src/actor.cpp
index 500492dea..cd0d9e8e6 100644
--- a/source/blood/src/actor.cpp
+++ b/source/blood/src/actor.cpp
@@ -2935,7 +2935,7 @@ void actKillDude(int nKillerSprite, spritetype *pSprite, DAMAGE_TYPE damageType,
                         aiGenDudeNewState(pSprite, &genDudeBurnGoto);
                         actHealDude(pXSprite, dudeInfo[55].startHealth, dudeInfo[55].startHealth);
                         if (pXSprite->burnTime <= 0) pXSprite->burnTime = 1200;
-                        gDudeExtra[pSprite->extra].at0 = (int)gFrameClock + 360;
+                        gDudeExtra[pSprite->extra].at0 = gFrameClock + 360;
                         return;
                     }
 
@@ -3572,7 +3572,7 @@ int actDamageSprite(int nSource, spritetype *pSprite, DAMAGE_TYPE damageType, in
                 case kThingZombieHead:
                     if (damageType == 3 && pSourcePlayer && gFrameClock > pSourcePlayer->laughCount && Chance(0x4000)) {
                         sfxPlay3DSound(pSourcePlayer->pSprite, gPlayerGibThingComments[Random(10)], 0, 2);
-                        pSourcePlayer->laughCount = (int)gFrameClock+3600;
+                        pSourcePlayer->laughCount = gFrameClock+3600;
                     }
                     break;
                 case kTrapMachinegun:
@@ -4211,7 +4211,7 @@ void ProcessTouchObjects(spritetype *pSprite, int nXSprite)
             case kThingKickablePail:
                 if (pPlayer) {
                     if (pPlayer->kickPower > gFrameClock) return;
-                    pPlayer->kickPower = (int)gFrameClock+60;
+                    pPlayer->kickPower = gFrameClock+60;
                 }
                 actKickObject(pSprite, pSprite2);
                 sfxPlay3DSound(pSprite->x, pSprite->y, pSprite->z, 357, pSprite->sectnum);
@@ -4220,7 +4220,7 @@ void ProcessTouchObjects(spritetype *pSprite, int nXSprite)
             case kThingZombieHead:
                 if (pPlayer) {
                     if (pPlayer->kickPower > gFrameClock) return;
-                    pPlayer->kickPower = (int)gFrameClock+60;
+                    pPlayer->kickPower = gFrameClock+60;
                 }
                 actKickObject(pSprite, pSprite2);
                 sfxPlay3DSound(pSprite->x, pSprite->y, pSprite->z, 357, pSprite->sectnum);
@@ -4400,9 +4400,9 @@ int MoveThing(spritetype *pSprite)
             spritetype *pFX = gFX.fxSpawn(FX_27, pSprite->sectnum, pSprite->x, pSprite->y, pSprite->z, 0);
             if (pFX)
             {
-                int v34 = ((int)gFrameClock*3)&2047;
-                int v30 = ((int)gFrameClock*5)&2047;
-                int vbx = ((int)gFrameClock*11)&2047;
+                int v34 = (gFrameClock*3)&2047;
+                int v30 = (gFrameClock*5)&2047;
+                int vbx = (gFrameClock*11)&2047;
                 int v2c = 0x44444;
                 int v28 = 0;
                 int v24 = 0;
@@ -5571,7 +5571,7 @@ void actProcessSprites(void)
             }
             actAirDrag(pSprite, 128);
 
-            if (((pSprite->index>>8)&15) == (gFrame&15) && (pSprite->flags&2))
+            if (((pSprite->index>>8)&15) == (gFrameCount&15) && (pSprite->flags&2))
                 pSprite->flags |= 4;
             if ((pSprite->flags&4) || xvel[nSprite] || yvel[nSprite] || zvel[nSprite] ||
                 velFloor[pSprite->sectnum] || velCeil[pSprite->sectnum])
@@ -6221,7 +6221,7 @@ spritetype * actSpawnThing(int nSector, int x, int y, int z, int nThingType)
         pXThing->data2 = 0;
         pXThing->data3 = 0;
         pXThing->data4 = 318;
-        pXThing->targetX = (int)gFrameClock+180.0;
+        pXThing->targetX = gFrameClock+180.0;
         pXThing->locked = 1;
         pXThing->state = 1;
         pXThing->triggerOnce = 0;
@@ -6233,7 +6233,7 @@ spritetype * actSpawnThing(int nSector, int x, int y, int z, int nThingType)
         pXThing->data2 = 0;
         pXThing->data3 = 0;
         pXThing->data4 = 318;
-        pXThing->targetX = (int)gFrameClock+180.0;
+        pXThing->targetX = gFrameClock+180.0;
         pXThing->locked = 1;
         pXThing->state = 1;
         pXThing->triggerOnce = 0;
@@ -6830,7 +6830,7 @@ void DudeToGibCallback1(int, int nXSprite)
     pXSprite->triggerOnce = 0;
     pXSprite->isTriggered = 0;
     pXSprite->locked = 0;
-    pXSprite->targetX = (int)gFrameClock;
+    pXSprite->targetX = gFrameClock;
     pXSprite->state = 1;
 }
 
@@ -6848,7 +6848,7 @@ void DudeToGibCallback2(int, int nXSprite)
     pXSprite->triggerOnce = 0;
     pXSprite->isTriggered = 0;
     pXSprite->locked = 0;
-    pXSprite->targetX = (int)gFrameClock;
+    pXSprite->targetX = gFrameClock;
     pXSprite->state = 1;
 }
 
diff --git a/source/blood/src/ai.cpp b/source/blood/src/ai.cpp
index 3404ba1ee..34f6c419d 100644
--- a/source/blood/src/ai.cpp
+++ b/source/blood/src/ai.cpp
@@ -75,12 +75,12 @@ void aiPlay3DSound(spritetype *pSprite, int a2, AI_SFX_PRIORITY a3, int a4)
     DUDEEXTRA *pDudeExtra = &gDudeExtra[pSprite->extra];
     if (a3 == AI_SFX_PRIORITY_0)
         sfxPlay3DSound(pSprite, a2, a4, 2);
-    else if (a3 > pDudeExtra->at5 || pDudeExtra->at0 <= (int)gFrameClock)
+    else if (a3 > pDudeExtra->at5 || pDudeExtra->at0 <= gFrameClock)
     {
         sfxKill3DSound(pSprite, -1, -1);
         sfxPlay3DSound(pSprite, a2, a4, 0);
         pDudeExtra->at5 = a3;
-        pDudeExtra->at0 = (int)gFrameClock+120;
+        pDudeExtra->at0 = gFrameClock+120;
     }
 }
 
@@ -935,7 +935,7 @@ int aiDamageSprite(spritetype *pSprite, XSPRITE *pXSprite, int nSource, DAMAGE_T
                 aiNewState(pSprite, pXSprite, &cultistBurnGoto);
                 aiPlay3DSound(pSprite, 361, AI_SFX_PRIORITY_0, -1);
                 aiPlay3DSound(pSprite, 1031+Random(2), AI_SFX_PRIORITY_2, -1);
-                gDudeExtra[pSprite->extra].at0 = (int)gFrameClock+360;
+                gDudeExtra[pSprite->extra].at0 = gFrameClock+360;
                 actHealDude(pXSprite, dudeInfo[40].startHealth, dudeInfo[40].startHealth);
                 evKill(nSprite, 3, kCallbackFXFlameLick);
             }
@@ -946,7 +946,7 @@ int aiDamageSprite(spritetype *pSprite, XSPRITE *pXSprite, int nSource, DAMAGE_T
                 pSprite->type = kDudeBurningInnocent;
                 aiNewState(pSprite, pXSprite, &cultistBurnGoto);
                 aiPlay3DSound(pSprite, 361, AI_SFX_PRIORITY_0, -1);
-                gDudeExtra[pSprite->extra].at0 = (int)gFrameClock+360;
+                gDudeExtra[pSprite->extra].at0 = gFrameClock+360;
                 actHealDude(pXSprite, dudeInfo[39].startHealth, dudeInfo[39].startHealth);
                 evKill(nSprite, 3, kCallbackFXFlameLick);
             }
@@ -955,7 +955,7 @@ int aiDamageSprite(spritetype *pSprite, XSPRITE *pXSprite, int nSource, DAMAGE_T
             if (Chance(0x4000) && gDudeExtra[pSprite->extra].at0 < gFrameClock)
             {
                 aiPlay3DSound(pSprite, 1031+Random(2), AI_SFX_PRIORITY_2, -1);
-                gDudeExtra[pSprite->extra].at0 = (int)gFrameClock+360;
+                gDudeExtra[pSprite->extra].at0 = gFrameClock+360;
             }
             if (Chance(0x600) && (pXSprite->medium == kMediumWater || pXSprite->medium == kMediumGoo))
             {
@@ -989,16 +989,16 @@ int aiDamageSprite(spritetype *pSprite, XSPRITE *pXSprite, int nSource, DAMAGE_T
                 pSprite->type = kDudeBurningInnocent;
                 aiNewState(pSprite, pXSprite, &cultistBurnGoto);
                 aiPlay3DSound(pSprite, 361, AI_SFX_PRIORITY_0, -1);
-                gDudeExtra[pSprite->extra].at0 = (int)gFrameClock+360;
+                gDudeExtra[pSprite->extra].at0 = gFrameClock+360;
                 actHealDude(pXSprite, dudeInfo[39].startHealth, dudeInfo[39].startHealth);
                 evKill(nSprite, 3, kCallbackFXFlameLick);
             }
             break;
 #ifdef NOONE_EXTENSIONS
         case kDudeModernCustomBurning:
-            if (Chance(0x2000) && gDudeExtra[pSprite->extra].at0 < (int)gFrameClock) {
+            if (Chance(0x2000) && gDudeExtra[pSprite->extra].at0 < gFrameClock) {
                 playGenDudeSound(pSprite, kGenDudeSndBurning);
-                gDudeExtra[pSprite->extra].at0 = (int)gFrameClock + 360;
+                gDudeExtra[pSprite->extra].at0 = gFrameClock + 360;
             }
             if (pXSprite->burnTime == 0) pXSprite->burnTime = 2400;
             if (spriteIsUnderwater(pSprite, false)) {
@@ -1038,7 +1038,7 @@ int aiDamageSprite(spritetype *pSprite, XSPRITE *pXSprite, int nSource, DAMAGE_T
 
                         aiGenDudeNewState(pSprite, &genDudeBurnGoto);
                         actHealDude(pXSprite, dudeInfo[55].startHealth, dudeInfo[55].startHealth);
-                        gDudeExtra[pSprite->extra].at0 = (int)gFrameClock + 360;
+                        gDudeExtra[pSprite->extra].at0 = gFrameClock + 360;
                         evKill(nSprite, 3, kCallbackFXFlameLick);
 
                     }
@@ -1453,7 +1453,7 @@ void aiProcessDudes(void) {
         if (pXSprite->aiState->moveFunc)
             pXSprite->aiState->moveFunc(pSprite, pXSprite);
 
-        if (pXSprite->aiState->thinkFunc && (gFrame & 3) == (nSprite & 3))
+        if (pXSprite->aiState->thinkFunc && (gFrameCount & 3) == (nSprite & 3))
             pXSprite->aiState->thinkFunc(pSprite, pXSprite);
 
         switch (pSprite->type) {
diff --git a/source/blood/src/aiunicult.cpp b/source/blood/src/aiunicult.cpp
index 4c7c27796..30fe8e272 100644
--- a/source/blood/src/aiunicult.cpp
+++ b/source/blood/src/aiunicult.cpp
@@ -497,7 +497,7 @@ static void thinkChase( spritetype* pSprite, XSPRITE* pXSprite ) {
     // is the target visible?
     if (dist < pDudeInfo->seeDist && klabs(losAngle) <= pDudeInfo->periphery) {
 
-        if (((int)gFrameClock & 64) == 0 && Chance(0x3000) && !spriteIsUnderwater(pSprite, false))
+        if ((gFrameClock & 64) == 0 && Chance(0x3000) && !spriteIsUnderwater(pSprite, false))
             playGenDudeSound(pSprite, kGenDudeSndChasing);
 
         gDudeSlope[pSprite->extra] = divscale(pTarget->z - pSprite->z, dist, 10);
diff --git a/source/blood/src/animatesprite.cpp b/source/blood/src/animatesprite.cpp
index 656b32319..640ac71c9 100644
--- a/source/blood/src/animatesprite.cpp
+++ b/source/blood/src/animatesprite.cpp
@@ -143,7 +143,7 @@ static tspritetype *viewAddEffect(int nTSprite, VIEW_EFFECT nViewEffect)
         for (int i = 0; i < 16; i++)
         {
             auto pNSprite = viewInsertTSprite(pTSprite->sectnum, 32767, pTSprite);
-            int ang = ((int)gFrameClock*2048)/120;
+            int ang = (gFrameClock*2048)/120;
             int nRand1 = dword_172CE0[i][0];
             int nRand2 = dword_172CE0[i][1];
             int nRand3 = dword_172CE0[i][2];
diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp
index b3bbc453d..6c73577e4 100644
--- a/source/blood/src/blood.cpp
+++ b/source/blood/src/blood.cpp
@@ -504,7 +504,7 @@ void StartLevel(MapRecord *level)
         sfxSetReverb(0);
     ambInit();
     netReset();
-    gFrame = 0;
+    gFrameCount = 0;
     gChokeCounter = 0;
 	M_ClearMenus();
     // viewSetMessage("");
@@ -580,7 +580,7 @@ void ProcessFrame(void)
         playerProcess(&gPlayer[i]);
     }
     trProcessBusy();
-    evProcess((int)gFrameClock);
+    evProcess(gFrameClock);
     seqProcess(4);
     DoSectorPanning();
     actProcessSprites();
@@ -605,7 +605,7 @@ void ProcessFrame(void)
         }
     }
     gLevelTime++;
-    gFrame++;
+    gFrameCount++;
     gFrameClock += 4;
     if ((gGameOptions.uGameFlags&1) != 0 && !gStartNewGame)
     {
@@ -800,7 +800,6 @@ static void gameTicker()
         gInput = {};
         netGetInput();
         lastTic = currentTic;
-        gNetFifoClock = gameclock;
         while (gNetFifoHead[myconnectindex] - gNetFifoTail > gBufferJitter && !gStartNewGame && !gQuitGame)
         {
             int i;
@@ -853,7 +852,7 @@ static void commonTicker()
         auto completion = [=](bool = false)
         {
             StartLevel(sng);
-            gNetFifoClock = gFrameClock = gameclock;
+            gFrameClock = gameclock;
             gamestate = GS_LEVEL;
         };
 
diff --git a/source/blood/src/eventq.cpp b/source/blood/src/eventq.cpp
index 853a5efb2..81c509635 100644
--- a/source/blood/src/eventq.cpp
+++ b/source/blood/src/eventq.cpp
@@ -493,7 +493,7 @@ void evPost(int nIndex, int nType, unsigned int nDelta, COMMAND_ID command) {
     evn.index = nIndex;
     evn.type = nType;
     evn.cmd = command;
-    eventQ.PQueue->Insert((int)gFrameClock+nDelta, evn);
+    eventQ.PQueue->Insert(gFrameClock+nDelta, evn);
 }
 
 void evPost(int nIndex, int nType, unsigned int nDelta, CALLBACK_ID callback) {
@@ -502,7 +502,7 @@ void evPost(int nIndex, int nType, unsigned int nDelta, CALLBACK_ID callback) {
     evn.type = nType;
     evn.cmd = kCmdCallback;
     evn.funcID = callback;
-    eventQ.PQueue->Insert((int)gFrameClock+nDelta, evn);
+    eventQ.PQueue->Insert(gFrameClock+nDelta, evn);
 }
 
 void evProcess(unsigned int nTime)
diff --git a/source/blood/src/gameutil.cpp b/source/blood/src/gameutil.cpp
index 6944d7582..9d125fbfa 100644
--- a/source/blood/src/gameutil.cpp
+++ b/source/blood/src/gameutil.cpp
@@ -143,18 +143,6 @@ bool FindSector(int nX, int nY, int *nSector)
     return 0;
 }
 
-void CalcFrameRate(void)
-{
-    static int ticks[64];
-    static int index;
-    if (ticks[index] != gFrameClock)
-    {
-        gFrameRate = (120*64)/((int)gFrameClock-ticks[index]);
-        ticks[index] = (int)gFrameClock;
-    }
-    index = (index+1) & 63;
-}
-
 bool CheckProximity(spritetype *pSprite, int nX, int nY, int nZ, int nSector, int nDist)
 {
     dassert(pSprite != NULL);
diff --git a/source/blood/src/gameutil.h b/source/blood/src/gameutil.h
index c7e8f5f3f..a1073d91d 100644
--- a/source/blood/src/gameutil.h
+++ b/source/blood/src/gameutil.h
@@ -68,7 +68,6 @@ inline bool wallRangeIsFine(int nIndex) {
 bool AreSectorsNeighbors(int sect1, int sect2);
 bool FindSector(int nX, int nY, int nZ, int *nSector);
 bool FindSector(int nX, int nY, int *nSector);
-void CalcFrameRate(void);
 bool CheckProximity(spritetype *pSprite, int nX, int nY, int nZ, int nSector, int nDist);
 bool CheckProximityPoint(int nX1, int nY1, int nZ1, int nX2, int nY2, int nZ2, int nDist);
 bool CheckProximityWall(int nWall, int x, int y, int nDist);
diff --git a/source/blood/src/globals.cpp b/source/blood/src/globals.cpp
index d22c611ab..886456409 100644
--- a/source/blood/src/globals.cpp
+++ b/source/blood/src/globals.cpp
@@ -34,10 +34,8 @@ BEGIN_BLD_NS
 
 bool bVanilla = false;
 int gFrameClock;
-int gFrameTicks;
-int gFrame;
+int gFrameCount;
 //int volatile gGameClock;
-int gFrameRate;
 
 static const char *_module;
 static int _line;
diff --git a/source/blood/src/globals.h b/source/blood/src/globals.h
index 8da9549db..4dce8e78d 100644
--- a/source/blood/src/globals.h
+++ b/source/blood/src/globals.h
@@ -31,10 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 BEGIN_BLD_NS
 
 extern int gFrameClock;
-extern int gFrameTicks;
-extern int gFrame;
+extern int gFrameCount;
 //extern int gGameClock;
-extern int gFrameRate;
 extern bool bVanilla;
 
 #define MAXPLAYERNAME 16
diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp
index aaabf3d0d..adb4f8d3c 100644
--- a/source/blood/src/loadsave.cpp
+++ b/source/blood/src/loadsave.cpp
@@ -504,7 +504,6 @@ bool GameInterface::LoadGame(FSaveGameNode* node)
     memset(myMinLag, 0, sizeof(myMinLag));
     otherMinLag = 0;
     myMaxLag = 0;
-    gNetFifoClock = 0;
     gNetFifoTail = 0;
     memset(gNetFifoHead, 0, sizeof(gNetFifoHead));
     gPredictTail = 0;
@@ -522,9 +521,7 @@ bool GameInterface::LoadGame(FSaveGameNode* node)
         netWaitForEveryone(0);
         memset(gPlayerReady, 0, sizeof(gPlayerReady));
     }
-    gFrameTicks = 0;
-    gFrame = 0;
-    gFrameRate = 0;
+    gFrameCount = 0;
     gameclock = 0;
     lastTic = -1;
     paused = 0;
@@ -617,8 +614,7 @@ void MyLoadSave::Load(void)
     Read(gotpic, sizeof(gotpic));
     Read(gotsector, sizeof(gotsector));
     Read(&gFrameClock, sizeof(gFrameClock));
-    Read(&gFrameTicks, sizeof(gFrameTicks));
-    Read(&gFrame, sizeof(gFrame));
+    Read(&gFrameCount, sizeof(gFrameCount));
     Read(&gameclock, sizeof(gameclock));
     Read(&gLevelTime, sizeof(gLevelTime));
     Read(&paused, sizeof(paused));
@@ -708,8 +704,7 @@ void MyLoadSave::Save(void)
     Write(gotpic, sizeof(gotpic));
     Write(gotsector, sizeof(gotsector));
     Write(&gFrameClock, sizeof(gFrameClock));
-    Write(&gFrameTicks, sizeof(gFrameTicks));
-    Write(&gFrame, sizeof(gFrame));
+    Write(&gFrameCount, sizeof(gFrameCount));
     int nGameClock = gameclock;
     Write(&nGameClock, sizeof(nGameClock));
     Write(&gLevelTime, sizeof(gLevelTime));
diff --git a/source/blood/src/network.cpp b/source/blood/src/network.cpp
index 861baac9c..bcb2a7d7d 100644
--- a/source/blood/src/network.cpp
+++ b/source/blood/src/network.cpp
@@ -40,7 +40,6 @@ BEGIN_BLD_NS
 
 MapRecord *gStartNewGame = 0;
 PACKETMODE gPacketMode = PACKETMODE_1;
-int gNetFifoClock = 0;
 int gNetFifoTail = 0;
 int gNetFifoHead[8];
 int gPredictTail = 0;
@@ -78,7 +77,7 @@ void netResetToSinglePlayer(void)
 
 void netReset(void)
 {
-    gNetFifoClock = gFrameClock = gameclock = 0;
+    gFrameClock = gameclock = 0;
     lastTic = -1;
     gNetFifoMasterTail = 0;
     gPredictTail = 0;
diff --git a/source/blood/src/network.h b/source/blood/src/network.h
index 7ab120036..0ea414a45 100644
--- a/source/blood/src/network.h
+++ b/source/blood/src/network.h
@@ -45,7 +45,6 @@ enum NETWORKMODE {
 
 extern MapRecord *gStartNewGame;
 extern PACKETMODE gPacketMode;
-extern int gNetFifoClock;
 extern int gNetFifoTail;
 extern int gNetFifoHead[8];
 extern int gPredictTail;
diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp
index 2fc612d8c..a87899cec 100644
--- a/source/blood/src/nnexts.cpp
+++ b/source/blood/src/nnexts.cpp
@@ -885,7 +885,7 @@ void nnExtProcessSuperSprites() {
 
             actAirDrag(pDebris, airVel);
 
-            if (((pDebris->index >> 8) & 15) == (gFrame & 15) && (pXDebris->physAttr & kPhysGravity))
+            if (((pDebris->index >> 8) & 15) == (gFrameCount & 15) && (pXDebris->physAttr & kPhysGravity))
                 pXDebris->physAttr |= kPhysFalling;
 
             if ((pXDebris->physAttr & 4) == 0 && xvel[pDebris->index] == 0 && yvel[pDebris->index] == 0 &&
@@ -4588,7 +4588,7 @@ void useTargetChanger(XSPRITE* pXSource, spritetype* pSprite) {
             return;
         }
         // lets try to look for target that fits better by distance
-        else if (((int)gFrameClock & 256) != 0 && (pXSprite->target < 0 || aiFightGetTargetDist(pSprite, pDudeInfo, pTarget) >= mDist)) {
+        else if ((gFrameClock & 256) != 0 && (pXSprite->target < 0 || aiFightGetTargetDist(pSprite, pDudeInfo, pTarget) >= mDist)) {
             pTarget = aiFightGetTargetInRange(pSprite, 0, mDist, pXSource->data1, pXSource->data2);
             if (pTarget != NULL) {
                 pXTarget = &xsprite[pTarget->extra];
@@ -4618,7 +4618,7 @@ void useTargetChanger(XSPRITE* pXSource, spritetype* pSprite) {
         }
     }
     
-    if ((pXSprite->target < 0 || pPlayer != NULL) && ((int)gFrameClock & 32) != 0) {
+    if ((pXSprite->target < 0 || pPlayer != NULL) && (gFrameClock & 32) != 0) {
         // try find first target that dude can see
         for (int nSprite = headspritestat[kStatDude]; nSprite >= 0; nSprite = nextspritestat[nSprite]) {
             
@@ -4664,7 +4664,7 @@ void useTargetChanger(XSPRITE* pXSource, spritetype* pSprite) {
     }
 
     // got no target - let's ask mates if they have targets
-    if ((pXSprite->target < 0 || pPlayer != NULL) && pXSource->data2 == 1 && ((int)gFrameClock & 64) != 0) {
+    if ((pXSprite->target < 0 || pPlayer != NULL) && pXSource->data2 == 1 && (gFrameClock & 64) != 0) {
         spritetype* pMateTarget = NULL;
         if ((pMateTarget = aiFightGetMateTargets(pXSprite)) != NULL && pMateTarget->extra > 0) {
             XSPRITE* pXMateTarget = &xsprite[pMateTarget->extra];
diff --git a/source/blood/src/replace.cpp b/source/blood/src/replace.cpp
index 03ac20538..19bea6069 100644
--- a/source/blood/src/replace.cpp
+++ b/source/blood/src/replace.cpp
@@ -38,7 +38,7 @@ int qanimateoffs(int a1, int a2)
         int frames = picanm[a1].num;
         if (frames > 0)
         {
-            int const frameClock = (int)gFrameClock;
+            int const frameClock = gFrameClock;
             int vd;
             if ((a2&0xc000) == 0x8000)
                 vd = (Bcrc32(&a2, 2, 0)+frameClock)>>(picanm[a1].sf&PICANM_ANIMSPEED_MASK);
diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp
index c3a717a8a..fdd9012cb 100644
--- a/source/blood/src/view.cpp
+++ b/source/blood/src/view.cpp
@@ -572,7 +572,7 @@ void viewUpdateDelirium(void)
 	if ((powerCount = powerupCheck(gView, kPwUpDeliriumShroom)) != 0)
 	{
 		int tilt1 = 170, tilt2 = 170, pitch = 20;
-        int timer = (int)gFrameClock*4;
+        int timer = gFrameClock*4;
 		if (powerCount < 512)
 		{
 			int powerScale = (powerCount<<16) / 512;
@@ -1057,7 +1057,6 @@ void viewDrawScreen(bool sceneonly)
         DrawStatSprite(2048, xdim-15, 20);
     }
 #endif
-    CalcFrameRate();
 
     viewDrawMapTitle();
     viewDrawAimedPlayerName();
diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp
index 33a2001c7..ee5748c8a 100644
--- a/source/blood/src/weapon.cpp
+++ b/source/blood/src/weapon.cpp
@@ -1781,12 +1781,12 @@ char sub_4F0E0(PLAYER *pPlayer)
         {
             pPlayer->weaponState = 7;
             pPlayer->fuseTime = 0;
-            pPlayer->throwTime = (int)gFrameClock;
+            pPlayer->throwTime = gFrameClock;
         }
         return 1;
     case 7:
     {
-        pPlayer->throwPower = ClipHigh(divscale16((int)gFrameClock-pPlayer->throwTime,240), 65536);
+        pPlayer->throwPower = ClipHigh(divscale16(gFrameClock-pPlayer->throwTime,240), 65536);
         if (!pPlayer->input.buttonFlags.shoot)
         {
             if (!pPlayer->fuseTime)
@@ -1819,12 +1819,12 @@ char sub_4F200(PLAYER *pPlayer)
         {
             pPlayer->weaponState = 6;
             pPlayer->fuseTime = 0;
-            pPlayer->throwTime = (int)gFrameClock;
+            pPlayer->throwTime = gFrameClock;
         }
         return 1;
     case 6:
     {
-        pPlayer->throwPower = ClipHigh(divscale16((int)gFrameClock-pPlayer->throwTime,240), 65536);
+        pPlayer->throwPower = ClipHigh(divscale16(gFrameClock-pPlayer->throwTime,240), 65536);
         if (!pPlayer->input.buttonFlags.shoot)
         {
             if (!pPlayer->fuseTime)
@@ -1843,7 +1843,7 @@ char sub_4F320(PLAYER *pPlayer)
     switch (pPlayer->weaponState)
     {
     case 9:
-        pPlayer->throwPower = ClipHigh(divscale16((int)gFrameClock-pPlayer->throwTime,240), 65536);
+        pPlayer->throwPower = ClipHigh(divscale16(gFrameClock-pPlayer->throwTime,240), 65536);
         pPlayer->weaponTimer = 0;
         if (!pPlayer->input.buttonFlags.shoot)
         {
@@ -1860,7 +1860,7 @@ char sub_4F3A0(PLAYER *pPlayer)
     switch (pPlayer->weaponState)
     {
     case 13:
-        pPlayer->throwPower = ClipHigh(divscale16((int)gFrameClock-pPlayer->throwTime,240), 65536);
+        pPlayer->throwPower = ClipHigh(divscale16(gFrameClock-pPlayer->throwTime,240), 65536);
         if (!pPlayer->input.buttonFlags.shoot)
         {
             pPlayer->weaponState = 11;
@@ -2197,7 +2197,7 @@ void WeaponProcess(PLAYER *pPlayer) {
             case 3:
                 pPlayer->weaponState = 6;
                 pPlayer->fuseTime = -1;
-                pPlayer->throwTime = (int)gFrameClock;
+                pPlayer->throwTime = gFrameClock;
                 StartQAV(pPlayer, 21, nClientExplodeBundle, 0);
                 return;
             }
@@ -2208,7 +2208,7 @@ void WeaponProcess(PLAYER *pPlayer) {
             case 7:
                 pPlayer->weaponQav = 27;
                 pPlayer->weaponState = 9;
-                pPlayer->throwTime = (int)gFrameClock;
+                pPlayer->throwTime = gFrameClock;
                 return;
             }
             break;
@@ -2218,7 +2218,7 @@ void WeaponProcess(PLAYER *pPlayer) {
             case 10:
                 pPlayer->weaponQav = 36;
                 pPlayer->weaponState = 13;
-                pPlayer->throwTime = (int)gFrameClock;
+                pPlayer->throwTime = gFrameClock;
                 return;
             case 11:
                 pPlayer->weaponState = 12;