2015-06-30 12:46:07 +03:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2016-03-17 20:44:52 +03:00
|
|
|
LINK_ENTITY_TO_CLASS(weapon_hegrenade, CHEGrenade, CCSHEGrenade);
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::__MAKE_VHOOK(Spawn)()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-12-06 22:57:51 +03:00
|
|
|
Precache();
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-12-06 22:57:51 +03:00
|
|
|
m_iId = WEAPON_HEGRENADE;
|
|
|
|
SET_MODEL(edict(), "models/w_hegrenade.mdl");
|
|
|
|
|
|
|
|
pev->dmg = 4;
|
2016-07-20 19:44:00 +03:00
|
|
|
|
2015-12-06 22:57:51 +03:00
|
|
|
m_iDefaultAmmo = HEGRENADE_DEFAULT_GIVE;
|
|
|
|
m_flStartThrow = 0;
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flReleaseThrow = -1.0f;
|
2015-12-06 22:57:51 +03:00
|
|
|
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
|
|
|
|
|
|
|
|
// get ready to fall down.
|
2015-11-24 00:01:09 +03:00
|
|
|
FallInit();
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::__MAKE_VHOOK(Precache)()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-12-06 22:57:51 +03:00
|
|
|
PRECACHE_MODEL("models/v_hegrenade.mdl");
|
|
|
|
PRECACHE_MODEL("models/shield/v_shield_hegrenade.mdl");
|
|
|
|
|
|
|
|
PRECACHE_SOUND("weapons/hegrenade-1.wav");
|
|
|
|
PRECACHE_SOUND("weapons/hegrenade-2.wav");
|
|
|
|
PRECACHE_SOUND("weapons/he_bounce-1.wav");
|
|
|
|
PRECACHE_SOUND("weapons/pinpull.wav");
|
|
|
|
|
2015-11-24 00:01:09 +03:00
|
|
|
m_usCreateExplosion = PRECACHE_EVENT(1, "events/createexplo.sc");
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:01:09 +03:00
|
|
|
int CHEGrenade::__MAKE_VHOOK(GetItemInfo)(ItemInfo *p)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2016-07-15 16:52:38 +03:00
|
|
|
auto info = GetWeaponInfo(WEAPON_HEGRENADE);
|
|
|
|
|
2015-12-06 22:57:51 +03:00
|
|
|
p->pszName = STRING(pev->classname);
|
|
|
|
p->pszAmmo1 = "HEGrenade";
|
2016-07-15 16:52:38 +03:00
|
|
|
|
|
|
|
p->iMaxAmmo1 = info ? info->maxRounds : MAX_AMMO_HEGRENADE;
|
|
|
|
p->iMaxClip = info ? info->gunClipSize : WEAPON_NOCLIP;
|
|
|
|
|
2015-12-06 22:57:51 +03:00
|
|
|
p->pszAmmo2 = NULL;
|
|
|
|
p->iMaxAmmo2 = -1;
|
|
|
|
p->iSlot = 3;
|
|
|
|
p->iPosition = 1;
|
|
|
|
p->iId = m_iId = WEAPON_HEGRENADE;
|
|
|
|
p->iWeight = HEGRENADE_WEIGHT;
|
|
|
|
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
|
|
|
|
|
2015-11-24 00:01:09 +03:00
|
|
|
return 1;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
BOOL CHEGrenade::__MAKE_VHOOK(Deploy)()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flReleaseThrow = -1.0f;
|
2015-12-06 22:57:51 +03:00
|
|
|
m_fMaxSpeed = HEGRENADE_MAX_SPEED;
|
|
|
|
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
|
|
|
|
|
|
|
|
m_pPlayer->m_bShieldDrawn = false;
|
|
|
|
|
|
|
|
if (m_pPlayer->HasShield())
|
|
|
|
return DefaultDeploy("models/shield/v_shield_hegrenade.mdl", "models/shield/p_shield_hegrenade.mdl", HEGRENADE_DRAW, "shieldgren", UseDecrement() != FALSE);
|
|
|
|
else
|
2015-11-24 00:01:09 +03:00
|
|
|
return DefaultDeploy("models/v_hegrenade.mdl", "models/p_hegrenade.mdl", HEGRENADE_DRAW, "grenade", UseDecrement() != FALSE);
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:01:09 +03:00
|
|
|
void CHEGrenade::__MAKE_VHOOK(Holster)(int skiplocal)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2016-02-04 03:18:26 +03:00
|
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
|
2015-12-06 22:57:51 +03:00
|
|
|
|
|
|
|
if (!m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
|
|
|
{
|
|
|
|
m_pPlayer->pev->weapons &= ~(1 << WEAPON_HEGRENADE);
|
|
|
|
DestroyItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flStartThrow = 0;
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flReleaseThrow = -1.0f;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::__MAKE_VHOOK(PrimaryAttack)()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-12-06 22:57:51 +03:00
|
|
|
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_flStartThrow && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0)
|
|
|
|
{
|
|
|
|
m_flReleaseThrow = 0;
|
|
|
|
m_flStartThrow = gpGlobals->time;
|
|
|
|
|
|
|
|
SendWeaponAnim(HEGRENADE_PULLPIN, UseDecrement() != FALSE);
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5f;
|
2015-11-24 00:01:09 +03:00
|
|
|
}
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:01:09 +03:00
|
|
|
bool CHEGrenade::ShieldSecondaryFire(int iUpAnim, int iDownAnim)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-12-06 22:57:51 +03:00
|
|
|
if (!m_pPlayer->HasShield() || m_flStartThrow > 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
|
|
|
|
{
|
|
|
|
m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN;
|
|
|
|
SendWeaponAnim(iDownAnim, UseDecrement() != FALSE);
|
|
|
|
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
|
|
|
|
|
|
|
|
m_fMaxSpeed = HEGRENADE_MAX_SPEED;
|
|
|
|
m_pPlayer->m_bShieldDrawn = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_iWeaponState |= WPNSTATE_SHIELD_DRAWN;
|
|
|
|
SendWeaponAnim(iUpAnim, UseDecrement() != FALSE);
|
|
|
|
Q_strcpy(m_pPlayer->m_szAnimExtention, "shielded");
|
|
|
|
|
|
|
|
m_fMaxSpeed = HEGRENADE_MAX_SPEED_SHIELD;
|
|
|
|
m_pPlayer->m_bShieldDrawn = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pPlayer->UpdateShieldCrosshair((m_iWeaponState & WPNSTATE_SHIELD_DRAWN) != WPNSTATE_SHIELD_DRAWN);
|
|
|
|
m_pPlayer->ResetMaxSpeed();
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.4f;
|
2015-12-06 22:57:51 +03:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(0.4);
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.6f;
|
2015-12-06 22:57:51 +03:00
|
|
|
|
2015-11-24 00:01:09 +03:00
|
|
|
return true;
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::__MAKE_VHOOK(SecondaryAttack)()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-11-24 00:01:09 +03:00
|
|
|
ShieldSecondaryFire(SHIELDGUN_DRAW, SHIELDGUN_DRAWN_IDLE);
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::SetPlayerShieldAnim()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-11-24 00:01:09 +03:00
|
|
|
if (!m_pPlayer->HasShield())
|
|
|
|
return;
|
2015-12-06 22:57:51 +03:00
|
|
|
|
|
|
|
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
|
|
|
|
Q_strcpy(m_pPlayer->m_szAnimExtention, "shield");
|
|
|
|
else
|
2015-11-24 00:01:09 +03:00
|
|
|
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::ResetPlayerShieldAnim()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2015-12-06 22:57:51 +03:00
|
|
|
if (!m_pPlayer->HasShield())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
|
|
|
|
{
|
|
|
|
Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldgren");
|
2015-11-24 00:01:09 +03:00
|
|
|
}
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void CHEGrenade::__MAKE_VHOOK(WeaponIdle)()
|
2015-12-06 22:57:51 +03:00
|
|
|
{
|
|
|
|
if (m_flReleaseThrow == 0 && m_flStartThrow != 0.0f)
|
|
|
|
m_flReleaseThrow = gpGlobals->time;
|
|
|
|
|
|
|
|
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_flStartThrow)
|
|
|
|
{
|
|
|
|
m_pPlayer->Radio("%!MRAD_FIREINHOLE", "#Fire_in_the_hole");
|
|
|
|
|
|
|
|
Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
|
|
|
|
|
|
|
|
if (angThrow.x < 0)
|
|
|
|
angThrow.x = -10 + angThrow.x * ((90 - 10) / 90.0);
|
|
|
|
else
|
|
|
|
angThrow.x = -10 + angThrow.x * ((90 + 10) / 90.0);
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
float flVel = (90.0f - angThrow.x) * 6.0f;
|
2015-12-06 22:57:51 +03:00
|
|
|
|
|
|
|
if (flVel > 750.0f)
|
|
|
|
flVel = 750.0f;
|
|
|
|
|
|
|
|
UTIL_MakeVectors(angThrow);
|
|
|
|
|
|
|
|
Vector vecSrc = m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16;
|
|
|
|
Vector vecThrow = gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity;
|
|
|
|
|
|
|
|
CGrenade::ShootTimed2(m_pPlayer->pev, vecSrc, vecThrow, 1.5, m_pPlayer->m_iTeam, m_usCreateExplosion);
|
|
|
|
|
|
|
|
SendWeaponAnim(HEGRENADE_THROW, UseDecrement() != FALSE);
|
|
|
|
SetPlayerShieldAnim();
|
|
|
|
|
|
|
|
// player "shoot" animation
|
|
|
|
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
|
|
|
|
m_flStartThrow = 0;
|
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(0.5);
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.75f;
|
2015-12-06 22:57:51 +03:00
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
if (--m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
2015-12-06 22:57:51 +03:00
|
|
|
{
|
|
|
|
// just threw last grenade
|
|
|
|
// set attack times in the future, and weapon idle in the future so we can see the whole throw
|
|
|
|
// animation, weapon idle will automatically retire the weapon for us.
|
|
|
|
// ensure that the animation can finish playing
|
|
|
|
m_flTimeWeaponIdle = m_flNextSecondaryAttack = m_flNextPrimaryAttack = GetNextAttackDelay(0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResetPlayerShieldAnim();
|
2015-11-24 00:01:09 +03:00
|
|
|
}
|
2015-12-06 22:57:51 +03:00
|
|
|
else if (m_flReleaseThrow > 0)
|
|
|
|
{
|
|
|
|
// we've finished the throw, restart.
|
|
|
|
m_flStartThrow = 0;
|
|
|
|
|
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
|
|
|
{
|
|
|
|
SendWeaponAnim(HEGRENADE_DRAW, UseDecrement() != FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RetireWeapon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + RANDOM_FLOAT(10, 15);
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flReleaseThrow = -1.0f;
|
2015-11-24 00:01:09 +03:00
|
|
|
}
|
|
|
|
else if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
2015-12-06 22:57:51 +03:00
|
|
|
{
|
|
|
|
if (m_pPlayer->HasShield())
|
|
|
|
{
|
2016-02-04 03:18:26 +03:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 20.0f;
|
2015-12-06 22:57:51 +03:00
|
|
|
|
|
|
|
if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN)
|
|
|
|
{
|
|
|
|
SendWeaponAnim(SHIELDREN_IDLE, UseDecrement() != FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SendWeaponAnim(HEGRENADE_IDLE, UseDecrement() != FALSE);
|
|
|
|
|
|
|
|
// how long till we do this again.
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + RANDOM_FLOAT(10, 15);
|
2015-11-24 00:01:09 +03:00
|
|
|
}
|
|
|
|
}
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
BOOL CHEGrenade::__MAKE_VHOOK(CanDeploy)()
|
2015-11-24 00:01:09 +03:00
|
|
|
{
|
|
|
|
return m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] != 0;
|
|
|
|
}
|