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
This commit is contained in:
tankefugl 2005-09-26 19:18:19 +00:00
parent 162e23928f
commit 06bd7805bc
3 changed files with 26 additions and 5 deletions

View File

@ -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(&current_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;
}

View File

@ -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;
}

View File

@ -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);