ReGameDLL_CS/regamedll/dlls/wpn_shared/wpn_ak47.cpp

190 lines
4.3 KiB
C++
Raw Normal View History

2015-06-30 12:46:07 +03:00
#include "precompiled.h"
LINK_ENTITY_TO_CLASS(weapon_ak47, CAK47, CCSAK47);
2015-06-30 12:46:07 +03:00
void CAK47::__MAKE_VHOOK(Spawn)()
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
Precache();
2015-12-06 22:57:51 +03:00
m_iId = WEAPON_AK47;
SET_MODEL(edict(), "models/w_ak47.mdl");
m_iDefaultAmmo = AK47_DEFAULT_GIVE;
m_flAccuracy = 0.2f;
2015-12-06 22:57:51 +03:00
m_iShotsFired = 0;
2015-11-24 00:01:09 +03:00
FallInit();
2015-06-30 12:46:07 +03:00
}
void CAK47::__MAKE_VHOOK(Precache)()
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
PRECACHE_MODEL("models/v_ak47.mdl");
PRECACHE_MODEL("models/w_ak47.mdl");
PRECACHE_SOUND("weapons/ak47-1.wav");
PRECACHE_SOUND("weapons/ak47-2.wav");
PRECACHE_SOUND("weapons/ak47_clipout.wav");
PRECACHE_SOUND("weapons/ak47_clipin.wav");
PRECACHE_SOUND("weapons/ak47_boltpull.wav");
m_iShell = PRECACHE_MODEL("models/rshell.mdl");
2015-11-24 00:01:09 +03:00
m_usFireAK47 = PRECACHE_EVENT(1, "events/ak47.sc");
2015-06-30 12:46:07 +03:00
}
2015-11-24 00:01:09 +03:00
int CAK47::__MAKE_VHOOK(GetItemInfo)(ItemInfo *p)
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "762Nato";
p->iMaxAmmo1 = MAX_AMMO_762NATO;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = AK47_MAX_CLIP;
p->iSlot = 0;
p->iPosition = 1;
p->iId = m_iId = WEAPON_AK47;
p->iFlags = 0;
p->iWeight = AK47_WEIGHT;
2015-11-24 00:01:09 +03:00
return 1;
2015-06-30 12:46:07 +03:00
}
BOOL CAK47::__MAKE_VHOOK(Deploy)()
2015-06-30 12:46:07 +03:00
{
m_flAccuracy = 0.2f;
2015-12-06 22:57:51 +03:00
m_iShotsFired = 0;
iShellOn = 1;
2015-11-24 00:01:09 +03:00
return DefaultDeploy("models/v_ak47.mdl", "models/p_ak47.mdl", AK47_DRAW, "ak47", UseDecrement() != FALSE);
2015-06-30 12:46:07 +03:00
}
void CAK47::__MAKE_VHOOK(SecondaryAttack)()
2015-06-30 12:46:07 +03:00
{
2015-11-24 00:01:09 +03:00
;
2015-06-30 12:46:07 +03:00
}
void CAK47::__MAKE_VHOOK(PrimaryAttack)()
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
if (!(m_pPlayer->pev->flags & FL_ONGROUND))
{
AK47Fire(0.04 + (0.4 * m_flAccuracy), 0.0955, FALSE);
}
else if (m_pPlayer->pev->velocity.Length2D() > 140)
{
AK47Fire(0.04 + (0.07 * m_flAccuracy), 0.0955, FALSE);
}
else
{
AK47Fire(0.0275 * m_flAccuracy, 0.0955, FALSE);
2015-11-24 00:01:09 +03:00
}
2015-06-30 12:46:07 +03:00
}
2015-11-24 00:01:09 +03:00
void CAK47::AK47Fire(float flSpread, float flCycleTime, BOOL fUseAutoAim)
{
2015-12-06 22:57:51 +03:00
Vector vecAiming, vecSrc, vecDir;
int flag;
m_bDelayFire = true;
++m_iShotsFired;
2015-12-06 22:57:51 +03:00
m_flAccuracy = ((m_iShotsFired * m_iShotsFired * m_iShotsFired) / 200) + 0.35f;
2015-12-06 22:57:51 +03:00
if (m_flAccuracy > 1.25f)
m_flAccuracy = 1.25f;
2015-12-06 22:57:51 +03:00
if (m_iClip <= 0)
{
if (m_fFireOnEmpty)
{
PlayEmptySound();
m_flNextPrimaryAttack = GetNextAttackDelay(0.2);
}
if (TheBots != NULL)
{
TheBots->OnEvent(EVENT_WEAPON_FIRED_ON_EMPTY, m_pPlayer);
}
return;
2015-11-24 00:01:09 +03:00
}
--m_iClip;
2015-12-06 22:57:51 +03:00
m_pPlayer->pev->effects |= EF_MUZZLEFLASH;
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
vecSrc = m_pPlayer->GetGunPosition();
vecAiming = gpGlobals->v_forward;
vecDir = m_pPlayer->FireBullets3(vecSrc, vecAiming, flSpread, 8192, 2, BULLET_PLAYER_762MM,
AK47_DAMAGE, AK47_RANGE_MODIFER, m_pPlayer->pev, false, m_pPlayer->random_seed);
#ifdef CLIENT_WEAPONS
flag = FEV_NOTHOST;
#else
flag = 0;
#endif
2015-12-06 22:57:51 +03:00
PLAYBACK_EVENT_FULL(flag, m_pPlayer->edict(), m_usFireAK47, 0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y,
int(m_pPlayer->pev->punchangle.x * 100), int(m_pPlayer->pev->punchangle.y * 100), FALSE, FALSE);
2015-12-06 22:57:51 +03:00
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_flNextPrimaryAttack = m_flNextSecondaryAttack = GetNextAttackDelay(flCycleTime);
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
{
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.9f;
2015-11-24 00:01:09 +03:00
if (m_pPlayer->pev->velocity.Length2D() > 0)
2015-12-06 22:57:51 +03:00
{
2015-11-24 00:01:09 +03:00
KickBack(1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7);
2015-12-06 22:57:51 +03:00
}
2015-11-24 00:01:09 +03:00
else if (!(m_pPlayer->pev->flags & FL_ONGROUND))
2015-12-06 22:57:51 +03:00
{
2015-11-24 00:01:09 +03:00
KickBack(2.0, 1.0, 0.5, 0.35, 9.0, 6.0, 5);
2015-12-06 22:57:51 +03:00
}
2015-11-24 00:01:09 +03:00
else if (m_pPlayer->pev->flags & FL_DUCKING)
2015-12-06 22:57:51 +03:00
{
2015-11-24 00:01:09 +03:00
KickBack(0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9);
2015-12-06 22:57:51 +03:00
}
2015-11-24 00:01:09 +03:00
else
2015-12-06 22:57:51 +03:00
{
2015-11-24 00:01:09 +03:00
KickBack(1.0, 0.375, 0.175, 0.0375, 5.75, 1.75, 8);
}
2015-06-30 12:46:07 +03:00
}
void CAK47::__MAKE_VHOOK(Reload)()
2015-06-30 12:46:07 +03:00
{
2015-11-24 00:01:09 +03:00
#ifdef REGAMEDLL_FIXES
// to prevent reload if not enough ammo
2015-12-06 22:57:51 +03:00
if (m_pPlayer->ammo_762nato <= 0)
return;
#endif
2015-12-06 22:57:51 +03:00
if (DefaultReload(AK47_MAX_CLIP, AK47_RELOAD, AK47_RELOAD_TIME))
{
m_pPlayer->SetAnimation(PLAYER_RELOAD);
m_flAccuracy = 0.2f;
2015-12-06 22:57:51 +03:00
m_iShotsFired = 0;
m_bDelayFire = false;
2015-11-24 00:01:09 +03:00
}
2015-06-30 12:46:07 +03:00
}
void CAK47::__MAKE_VHOOK(WeaponIdle)()
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
ResetEmptySound();
m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);
if (m_flTimeWeaponIdle <= UTIL_WeaponTimeBase())
{
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 20.0f;
2015-12-06 22:57:51 +03:00
SendWeaponAnim(AK47_IDLE1, UseDecrement() != FALSE);
2015-11-24 00:01:09 +03:00
}
2015-06-30 12:46:07 +03:00
}