mirror of
https://github.com/ENSL/NS.git
synced 2025-02-21 11:21:55 +00:00
GL staged reload and SG reload update
This commit is contained in:
parent
12a122af14
commit
30c66a434b
3 changed files with 222 additions and 29 deletions
|
@ -60,10 +60,17 @@
|
|||
LINK_ENTITY_TO_CLASS(kwGrenadeGun, AvHGrenadeGun);
|
||||
void V_PunchAxis( int axis, float punch );
|
||||
|
||||
const int kSpecialReloadNone = 0;
|
||||
const int kSpecialReloadGotoReload = 1;
|
||||
const int kSpecialReloadAddGren = 2;
|
||||
const int kSpecialReloadCloseGG = 3;
|
||||
const float kEndReloadAnimationTime = 2.43f;
|
||||
|
||||
void AvHGrenadeGun::Init()
|
||||
{
|
||||
this->mRange = kGGRange;
|
||||
this->mDamage = BALANCE_VAR(kGrenadeDamage);
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
}
|
||||
|
||||
int AvHGrenadeGun::GetBarrelLength() const
|
||||
|
@ -182,28 +189,32 @@ char* AvHGrenadeGun::GetPlayerModel() const
|
|||
int AvHGrenadeGun::GetReloadAnimation() const
|
||||
{
|
||||
int theAnimation = -1;
|
||||
|
||||
int ShotsEmpty = this->GetClipSize() - this->GetShotsInClip();
|
||||
|
||||
int Shotsleft = this->m_pPlayer->m_rgAmmo[this->m_iPrimaryAmmoType];
|
||||
|
||||
int ShotsToReload = min(ShotsEmpty, Shotsleft);
|
||||
|
||||
int theShotsInClip = this->GetShotsInClip();
|
||||
|
||||
switch(theShotsInClip)
|
||||
switch(ShotsToReload)
|
||||
{
|
||||
case 0:
|
||||
case 4:
|
||||
theAnimation = 7;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
case 3:
|
||||
theAnimation = 6;
|
||||
break;
|
||||
|
||||
|
||||
case 2:
|
||||
theAnimation = 5;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
case 1:
|
||||
theAnimation = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return theAnimation;
|
||||
}
|
||||
|
||||
|
@ -240,6 +251,27 @@ int AvHGrenadeGun::GetShootAnimation() const
|
|||
return theAnimation;
|
||||
}
|
||||
|
||||
int AvHGrenadeGun::GetEndAnimation() const
|
||||
{
|
||||
int theAnimation = -1;
|
||||
|
||||
int theShotsInClip = this->GetShotsInClip();
|
||||
|
||||
switch (theShotsInClip)
|
||||
{
|
||||
case 1:
|
||||
theAnimation = 17;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
theAnimation = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
return theAnimation;
|
||||
}
|
||||
|
||||
char* AvHGrenadeGun::GetViewModel() const
|
||||
{
|
||||
return kGGVModel;
|
||||
|
@ -287,6 +319,150 @@ void AvHGrenadeGun::Precache()
|
|||
this->mEvent = PRECACHE_EVENT(1, kGGEventName);
|
||||
}
|
||||
|
||||
void AvHGrenadeGun::DeductCostForShot(void)
|
||||
{
|
||||
AvHMarineWeapon::DeductCostForShot();
|
||||
|
||||
// Stop reload if we were in the middle of one
|
||||
if (this->m_fInSpecialReload != kSpecialReloadNone)
|
||||
{
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
}
|
||||
}
|
||||
|
||||
int AvHGrenadeGun::DefaultReload(int iClipSize, int iAnim, float fDelay)
|
||||
{
|
||||
// Needed to prevet super fast default reload
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void AvHGrenadeGun::Holster(int skiplocal)
|
||||
{
|
||||
AvHMarineWeapon::Holster(skiplocal);
|
||||
|
||||
// Cancel any reload in progress.
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
}
|
||||
|
||||
void AvHGrenadeGun::Reload(void)
|
||||
{
|
||||
int theClipSize = this->GetClipSize();
|
||||
|
||||
if ((this->m_pPlayer->m_rgAmmo[this->m_iPrimaryAmmoType] > 0) && (m_iClip < theClipSize))
|
||||
{
|
||||
if (this->m_fInSpecialReload == kSpecialReloadCloseGG)
|
||||
{
|
||||
this->SendWeaponAnim(this->GetEndAnimation());
|
||||
//Timings here made to match animations as well as reload length of the previous reload version. Numbers are seconds*2 because they get decremented twice in NS.
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
//this->m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
}
|
||||
else if (this->m_fInSpecialReload == kSpecialReloadAddGren)
|
||||
{
|
||||
// Add to grenade count at specified time in the middle of reload to sync with animation and sound.
|
||||
if (m_flTimeWeaponIdle <= UTIL_WeaponTimeBase())
|
||||
{
|
||||
// Add them to the clip
|
||||
this->m_iClip += 1;
|
||||
this->m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
|
||||
|
||||
if (this->m_iClip < theClipSize && (this->m_pPlayer->m_rgAmmo[this->m_iPrimaryAmmoType] != 0))
|
||||
{
|
||||
this->m_fInSpecialReload = kSpecialReloadGotoReload;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
|
||||
}
|
||||
}
|
||||
}
|
||||
// don't reload until recoil is done
|
||||
else if (this->m_flNextPrimaryAttack <= UTIL_WeaponTimeBase())
|
||||
{
|
||||
if (this->m_fInSpecialReload == kSpecialReloadNone)
|
||||
{
|
||||
// Start reload
|
||||
this->m_fInSpecialReload = kSpecialReloadGotoReload;
|
||||
|
||||
this->SendWeaponAnim(this->GetReloadAnimation());
|
||||
|
||||
const float theGotoReloadAnimationTime = 1.1f;
|
||||
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theGotoReloadAnimationTime;
|
||||
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theGotoReloadAnimationTime;
|
||||
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theGotoReloadAnimationTime;
|
||||
|
||||
//this->m_pPlayer->SetAnimation(PLAYER_RELOAD);
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_START);
|
||||
}
|
||||
else if (this->m_fInSpecialReload == kSpecialReloadGotoReload)
|
||||
{
|
||||
if (m_flTimeWeaponIdle <= UTIL_WeaponTimeBase())
|
||||
{
|
||||
this->m_fInSpecialReload = kSpecialReloadAddGren;
|
||||
|
||||
const float theGrenReloadTime = 2.4f;
|
||||
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theGrenReloadTime;
|
||||
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theGrenReloadTime;
|
||||
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theGrenReloadTime;
|
||||
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_INSERT);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AvHGrenadeGun::WeaponIdle(void)
|
||||
{
|
||||
// : 0000484 - ensures that all idle weapons can fire the empty sound
|
||||
ResetEmptySound();
|
||||
if (this->m_flTimeWeaponIdle < UTIL_WeaponTimeBase())
|
||||
{
|
||||
if ((this->m_iClip == 0) && (this->m_fInSpecialReload == kSpecialReloadNone) && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
||||
{
|
||||
this->Reload();
|
||||
}
|
||||
else if (this->m_fInSpecialReload != kSpecialReloadNone)
|
||||
{
|
||||
if ((m_iClip != this->GetClipSize()) && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
||||
{
|
||||
this->Reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reload debounce has timed out
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
//ALERT(at_console, "specreset time:%g idle:%g primary:%g specrel:%d\n", gpGlobals->time, this->m_flTimeWeaponIdle, this->m_flNextPrimaryAttack, m_fInSpecialReload);
|
||||
this->SendWeaponAnim(this->GetEndAnimation());
|
||||
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + kEndReloadAnimationTime;
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// Hack to prevent idle animation from playing mid-reload. Not sure how to fix this right, but all this special reloading is happening server-side, client doesn't know about it
|
||||
//if (m_iClip == this->GetClipSize())
|
||||
//{
|
||||
// AvHMarineWeapon::WeaponIdle();
|
||||
//}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
void AvHGrenadeGun::Spawn()
|
||||
{
|
||||
AvHMarineWeapon::Spawn();
|
||||
|
|
|
@ -159,7 +159,7 @@ void AvHReloadableMarineWeapon::Reload(void)
|
|||
//this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theEndReloadAnimationTime;
|
||||
//this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theEndReloadAnimationTime;
|
||||
|
||||
//+1 second is the average of the gotoreload and shellreload times previously used to limit primary attack and matches the marine putting his hand on the gun.
|
||||
//+1 is the average of the gotoreload and shellreload times previously used to limit primary attack and matches the marine putting his hand on the gun. Actual time is half these values in seconds because timers get decremented twice.
|
||||
//this->m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0f;
|
||||
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.0f;
|
||||
|
@ -168,6 +168,25 @@ void AvHReloadableMarineWeapon::Reload(void)
|
|||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
|
||||
this->m_fInSpecialReload = kSpecialReloadNone;
|
||||
}
|
||||
else if(this->m_fInSpecialReload == kSpecialReloadReloadShell)
|
||||
{
|
||||
// Add to shell count at specified time in the middle of reload to sync with animation and sound.
|
||||
if (m_flTimeWeaponIdle <= UTIL_WeaponTimeBase())
|
||||
{
|
||||
// Don't idle for a bit
|
||||
//this->SetNextIdle();
|
||||
|
||||
// Add them to the clip
|
||||
this->m_iClip += 1;
|
||||
this->m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
|
||||
this->m_fInSpecialReload = kSpecialReloadGotoReload;
|
||||
|
||||
if (this->m_iClip >= theClipSize)
|
||||
{
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
|
||||
}
|
||||
}
|
||||
}
|
||||
// don't reload until recoil is done
|
||||
else if(this->m_flNextPrimaryAttack <= UTIL_WeaponTimeBase())
|
||||
{
|
||||
|
@ -210,32 +229,18 @@ void AvHReloadableMarineWeapon::Reload(void)
|
|||
float theShellReloadTime = this->GetShellReloadAnimationTime();
|
||||
|
||||
//this->mNextReload = UTIL_WeaponTimeBase() + theShellReloadTime;
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theShellReloadTime;
|
||||
|
||||
//Time to call weaponidle and trigger another reload so ammo count addition can by synchronized with animation and sound.
|
||||
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.4f;
|
||||
|
||||
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theShellReloadTime;
|
||||
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theShellReloadTime;
|
||||
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_INSERT);
|
||||
|
||||
}
|
||||
}
|
||||
else if(this->m_fInSpecialReload == kSpecialReloadReloadShell)
|
||||
{
|
||||
//DefaultReload(theClipSize, theReloadAnimation, theReloadTime);
|
||||
|
||||
// Don't idle for a bit
|
||||
//this->SetNextIdle();
|
||||
|
||||
//ALERT(at_console, "reload2clipadd %g\n", gpGlobals->time);
|
||||
|
||||
// Add them to the clip
|
||||
this->m_iClip += 1;
|
||||
this->m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 1;
|
||||
this->m_fInSpecialReload = kSpecialReloadGotoReload;
|
||||
this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -401,6 +401,8 @@ public:
|
|||
|
||||
virtual int GetShootAnimation() const;
|
||||
|
||||
virtual int GetEndAnimation() const;
|
||||
|
||||
virtual char* GetViewModel() const;
|
||||
|
||||
virtual char* GetWorldModel() const;
|
||||
|
@ -409,6 +411,16 @@ public:
|
|||
|
||||
virtual void Precache(void);
|
||||
|
||||
virtual void Reload(void);
|
||||
|
||||
virtual int DefaultReload(int iClipSize, int iAnim, float fDelay);
|
||||
|
||||
virtual void Holster(int skiplocal);
|
||||
|
||||
virtual void WeaponIdle(void);
|
||||
|
||||
virtual void DeductCostForShot(void);
|
||||
|
||||
virtual void Spawn();
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue