From 5ab75f45e9058fafd462f059b914603beab088d9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 29 Sep 2022 13:17:27 +0200 Subject: [PATCH] - floatified and consolidated throwPower handling. --- source/games/blood/src/player.h | 2 +- source/games/blood/src/weapon.cpp | 33 ++++++++++++++----- .../static/zscript/games/blood/bloodgame.zs | 2 +- wadsrc/static/zscript/games/blood/ui/sbar.zs | 8 ++--- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/source/games/blood/src/player.h b/source/games/blood/src/player.h index 84b55a792..2c4958a7b 100644 --- a/source/games/blood/src/player.h +++ b/source/games/blood/src/player.h @@ -135,7 +135,7 @@ struct PLAYER int qavTimer; int fuseTime; int throwTime; - int throwPower; + double throwPower; DVector3 aim; // world DVector3 relAim; // relative DVector3 flt_aim() const { return aim; } diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index fa925bd12..4879487dd 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -139,6 +139,23 @@ enum nClientAltFireNapalm, }; + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +double getThrowPower(PLAYER* pPlayer) +{ + return pPlayer->throwPower * 23.46666 + 6.4; +} + +void setThrowPower(PLAYER* pPlayer) +{ + pPlayer->throwPower = min((PlayClock - pPlayer->throwTime) / 240., 1.); +} + //--------------------------------------------------------------------------- // // @@ -1179,7 +1196,7 @@ void FireSpray(int, PLAYER* pPlayer) void ThrowCan(int, PLAYER* pPlayer) { sfxKill3DSound(pPlayer->actor, -1, 441); - double nSpeed = FixedToFloat(MulScale(pPlayer->throwPower, 0x177777, 16) + 0x66666); // deal with this later. + double nSpeed = getThrowPower(pPlayer); sfxPlay3DSound(pPlayer->actor, 455, 1, 0); auto spawned = playerFireThing(pPlayer, 0, -9460 / 65536., kThingArmedSpray, nSpeed); if (spawned) @@ -1239,7 +1256,7 @@ void ExplodeCan(int, PLAYER* pPlayer) void ThrowBundle(int, PLAYER* pPlayer) { sfxKill3DSound(pPlayer->actor, 16, -1); - double nSpeed = FixedToFloat(MulScale(pPlayer->throwPower, 0x177777, 16) + 0x66666); // deal with this later. + double nSpeed = getThrowPower(pPlayer); sfxPlay3DSound(pPlayer->actor, 455, 1, 0); auto spawned = playerFireThing(pPlayer, 0, -9460 / 65536., kThingArmedTNTBundle, nSpeed); if (spawned) @@ -1298,7 +1315,7 @@ void ExplodeBundle(int, PLAYER* pPlayer) void ThrowProx(int, PLAYER* pPlayer) { - double nSpeed = FixedToFloat(MulScale(pPlayer->throwPower, 0x177777, 16) + 0x66666); // deal with this later. + double nSpeed = getThrowPower(pPlayer); sfxPlay3DSound(pPlayer->actor, 455, 1, 0); auto spawned = playerFireThing(pPlayer, 0, -9460 / 65536., kThingArmedProxBomb, nSpeed); if (spawned) @@ -1333,7 +1350,7 @@ void DropProx(int, PLAYER* pPlayer) void ThrowRemote(int, PLAYER* pPlayer) { - double nSpeed = FixedToFloat(MulScale(pPlayer->throwPower, 0x177777, 16) + 0x66666); // deal with this later. + double nSpeed = getThrowPower(pPlayer); sfxPlay3DSound(pPlayer->actor, 455, 1, 0); auto spawned = playerFireThing(pPlayer, 0, -9460 / 65536., kThingArmedRemoteBomb, nSpeed); if (spawned) @@ -2170,7 +2187,7 @@ int processSprayCan(PLAYER* pPlayer) return 1; case 7: { - pPlayer->throwPower = ClipHigh(DivScale(PlayClock - pPlayer->throwTime, 240, 16), 65536); + setThrowPower(pPlayer); if (!(pPlayer->input.actions & SB_FIRE)) { if (!pPlayer->fuseTime) @@ -2214,7 +2231,7 @@ static bool processTNT(PLAYER* pPlayer) return 1; case 6: { - pPlayer->throwPower = ClipHigh(DivScale(PlayClock - pPlayer->throwTime, 240, 16), 65536); + setThrowPower(pPlayer); if (!(pPlayer->input.actions & SB_FIRE)) { if (!pPlayer->fuseTime) @@ -2239,7 +2256,7 @@ static bool processProxy(PLAYER* pPlayer) switch (pPlayer->weaponState) { case 9: - pPlayer->throwPower = ClipHigh(DivScale(PlayClock - pPlayer->throwTime, 240, 16), 65536); + setThrowPower(pPlayer); pPlayer->weaponTimer = 0; pPlayer->qavTimer = 0; if (!(pPlayer->input.actions & SB_FIRE)) @@ -2263,7 +2280,7 @@ static bool processRemote(PLAYER* pPlayer) switch (pPlayer->weaponState) { case 13: - pPlayer->throwPower = ClipHigh(DivScale(PlayClock - pPlayer->throwTime, 240, 16), 65536); + setThrowPower(pPlayer); if (!(pPlayer->input.actions & SB_FIRE)) { pPlayer->weaponState = 11; diff --git a/wadsrc/static/zscript/games/blood/bloodgame.zs b/wadsrc/static/zscript/games/blood/bloodgame.zs index 7331fd43a..ab4e7630a 100644 --- a/wadsrc/static/zscript/games/blood/bloodgame.zs +++ b/wadsrc/static/zscript/games/blood/bloodgame.zs @@ -94,7 +94,7 @@ struct BloodPlayer native native bool qavLoop; native int fuseTime; native int throwTime; - native int throwPower; + native double throwPower; //native Aim aim; // world //native int aimTarget; // aim target sprite native int aimTargetsCount; diff --git a/wadsrc/static/zscript/games/blood/ui/sbar.zs b/wadsrc/static/zscript/games/blood/ui/sbar.zs index 13244a890..085f2a0ff 100644 --- a/wadsrc/static/zscript/games/blood/ui/sbar.zs +++ b/wadsrc/static/zscript/games/blood/ui/sbar.zs @@ -117,7 +117,7 @@ class BloodStatusBar : RazeStatusBar // //--------------------------------------------------------------------------- - void TileHGauge(String nTile, double x, double y, int nMult, int nDiv, double sc = 1) + void TileHGauge(String nTile, double x, double y, double nMult, double nDiv, double sc = 1) { int w = texWidth(nTile); double bx = w * sc * nMult / nDiv + x; @@ -555,7 +555,7 @@ class BloodStatusBar : RazeStatusBar DrawImage("BlinkIcon", (201.5, 185.5), DI_ITEM_RELCENTER, col:Raze.shadeToLight(pPlayer.isRunning || cl_bloodvanillarun ? 16 : 40)); if (pPlayer.throwPower) { - TileHGauge("ThrowGauge", 124, 175.5, pPlayer.throwPower, 65536); + TileHGauge("ThrowGauge", 124, 175.5, pPlayer.throwPower, 1); } drawInventory(pPlayer, 166, 200 - th); // Depending on the scale we can lower the stats display. This needs some tweaking but this catches the important default case already. @@ -695,7 +695,7 @@ class BloodStatusBar : RazeStatusBar BeginStatusBar(false, 320, 200, 28); if (pPlayer.throwPower) - TileHGauge("ThrowGauge", 124, 175, pPlayer.throwPower, 65536); + TileHGauge("ThrowGauge", 124, 175, pPlayer.throwPower, 1); else drawInventory(pPlayer, 166, 200 - texHeight("FULLHUD") / 2 - 30); return 28; @@ -732,7 +732,7 @@ class BloodStatusBar : RazeStatusBar { BeginStatusBar(false, 320, 200, 28); if (pPlayer.throwPower) - TileHGauge("ThrowGauge", 124, 175, pPlayer.throwPower, 65536); + TileHGauge("ThrowGauge", 124, 175, pPlayer.throwPower, 1); else if (hud_size > Hud_StbarOverlay) drawInventory(pPlayer, 166, 200 - texHeight("FullHUD") / 2); }