From 06bd7805bc8983918bd1c3d4f59e1eef8b7fc732 Mon Sep 17 00:00:00 2001 From: tankefugl Date: Mon, 26 Sep 2005 19:18:19 +0000 Subject: [PATCH] Mantis 1104: - Added an optimistic latency-based prediction for alien energy usage for weapons, making missing attacks much less frequent. The prediction takes into account the player's latency and adrenaline upgrade, and adds that to the test performed by AvHMUHasEnoughAlienEnergy so that the client may predict how much energy the player has on the server when the +attack reaches it. git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@335 67975925-1194-0748-b3d5-c16f83f1a3a1 --- releases/3.1/source/mod/AvHAlienWeapon.cpp | 17 +++++++++++++++-- releases/3.1/source/mod/AvHMovementUtil.cpp | 12 ++++++++++-- releases/3.1/source/mod/AvHMovementUtil.h | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/releases/3.1/source/mod/AvHAlienWeapon.cpp b/releases/3.1/source/mod/AvHAlienWeapon.cpp index 4fa9e5b9..5e9a043d 100644 --- a/releases/3.1/source/mod/AvHAlienWeapon.cpp +++ b/releases/3.1/source/mod/AvHAlienWeapon.cpp @@ -53,6 +53,8 @@ extern int g_runfuncs; #include "cl_dll/com_weapons.h" +#include "common/net_api.h" + #include "pm_shared/pm_defs.h" #include "pm_shared/pm_shared.h" #include "pm_shared/pm_movevars.h" @@ -266,8 +268,19 @@ BOOL AvHAlienWeapon::IsUseable(void) // Make sure we have enough energy for this attack float theEnergyCost = this->GetEnergyForAttack(); float& theFuser = this->GetEnergyLevel(); - - if(AvHMUHasEnoughAlienEnergy(theFuser, theEnergyCost) && this->GetEnabledState()) + float theLatency = 0.0f; +#ifdef AVH_CLIENT + // tankefugl: 991 -- added latency-based prediction for the ammount of energy available to the alien + net_status_s current_status; + gEngfuncs.pNetAPI->Status(¤t_status); + theLatency = max(0.0f, current_status.latency); + + int theNumLevels = AvHGetAlienUpgradeLevel(this->m_pPlayer->pev->iuser4, MASK_UPGRADE_5); + if(theNumLevels > 0) + theLatency *= (1.0 + theNumLevels * BALANCE_VAR(kAdrenalineEnergyPercentPerLevel)); +#endif + + if(AvHMUHasEnoughAlienEnergy(theFuser, theEnergyCost, theLatency) && this->GetEnabledState()) { theIsUseable = TRUE; } diff --git a/releases/3.1/source/mod/AvHMovementUtil.cpp b/releases/3.1/source/mod/AvHMovementUtil.cpp index 0aa48768..a2fa4800 100644 --- a/releases/3.1/source/mod/AvHMovementUtil.cpp +++ b/releases/3.1/source/mod/AvHMovementUtil.cpp @@ -285,12 +285,20 @@ float AvHMUGetWalkSpeedFactor(AvHUser3 inUser3) return theMoveSpeed; } -bool AvHMUHasEnoughAlienEnergy(float& ioFuser, float inNormAmount) +// tankefugl: 991 -- added latency-based prediction for the ammount of energy available to the alien +bool AvHMUHasEnoughAlienEnergy(float& ioFuser, float inNormAmount, float latency) { bool theSuccess = false; float theCurrentEnergy = ioFuser/kNormalizationNetworkFactor; - if(theCurrentEnergy >= inNormAmount) + float thePredictedByLatency = 0.0f; + +#ifdef AVH_CLIENT + float theAlienEnergyRate = (float)BALANCE_VAR(kAlienEnergyRate); + float theUpgradeFactor = 1.0f; + thePredictedByLatency = (latency / 1000) * theAlienEnergyRate * theUpgradeFactor; +#endif + if((theCurrentEnergy + thePredictedByLatency) >= inNormAmount) { theSuccess = true; } diff --git a/releases/3.1/source/mod/AvHMovementUtil.h b/releases/3.1/source/mod/AvHMovementUtil.h index ea5199f6..49e9665a 100644 --- a/releases/3.1/source/mod/AvHMovementUtil.h +++ b/releases/3.1/source/mod/AvHMovementUtil.h @@ -35,7 +35,7 @@ bool AvHMUGiveAlienEnergy(float& ioFuser, float inNormAmount); bool AvHMUGetEnergyCost(AvHWeaponID inWeaponID, float& outEnergyCost); float AvHMUGetWalkSpeedFactor(AvHUser3 inUser3); -bool AvHMUHasEnoughAlienEnergy(float& ioFuser, float inNormAmount); +bool AvHMUHasEnoughAlienEnergy(float& ioFuser, float inNormAmount, float latency = 0.0f); void AvHMUUpdateAlienEnergy(float inTimePassed, int inUser3, int inUser4, float& ioFuser); void AvHMUUpdateJetpackEnergy(bool inIsJetpacking, float theTimePassed, float& ioJetpackEnergy);