ReGameDLL_CS/regamedll/dlls/wpn_shared/wpn_xm1014.cpp

262 lines
6.0 KiB
C++
Raw Normal View History

2015-06-30 12:46:07 +03:00
#include "precompiled.h"
LINK_ENTITY_TO_CLASS(weapon_xm1014, CXM1014, CCSXM1014)
2015-06-30 12:46:07 +03:00
void CXM1014::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_XM1014;
SET_MODEL(edict(), "models/w_xm1014.mdl");
m_iDefaultAmmo = XM1014_DEFAULT_GIVE;
#ifdef REGAMEDLL_API
CSPlayerWeapon()->m_flBaseDamage = XM1014_DAMAGE;
#endif
// Get ready to fall down
2015-11-24 00:01:09 +03:00
FallInit();
// extend
CBasePlayerWeapon::Spawn();
2015-06-30 12:46:07 +03:00
}
void CXM1014::Precache()
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
PRECACHE_MODEL("models/v_xm1014.mdl");
PRECACHE_MODEL("models/w_xm1014.mdl");
m_iShellId = m_iShell = PRECACHE_MODEL("models/shotgunshell.mdl");
PRECACHE_SOUND("weapons/xm1014-1.wav");
PRECACHE_SOUND("weapons/reload1.wav");
PRECACHE_SOUND("weapons/reload3.wav");
2015-11-24 00:01:09 +03:00
m_usFireXM1014 = PRECACHE_EVENT(1, "events/xm1014.sc");
2015-06-30 12:46:07 +03:00
}
int CXM1014::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 = "buckshot";
p->iMaxAmmo1 = MAX_AMMO_BUCKSHOT;
2017-11-22 20:27:55 +03:00
p->pszAmmo2 = nullptr;
2015-12-06 22:57:51 +03:00
p->iMaxAmmo2 = -1;
p->iMaxClip = XM1014_MAX_CLIP;
p->iSlot = 0;
p->iPosition = 12;
p->iId = m_iId = WEAPON_XM1014;
p->iFlags = 0;
p->iWeight = XM1014_WEIGHT;
2015-11-24 00:01:09 +03:00
return 1;
2015-06-30 12:46:07 +03:00
}
BOOL CXM1014::Deploy()
2015-06-30 12:46:07 +03:00
{
2015-11-24 00:01:09 +03:00
return DefaultDeploy("models/v_xm1014.mdl", "models/p_xm1014.mdl", XM1014_DRAW, "m249", UseDecrement() != FALSE);
2015-06-30 12:46:07 +03:00
}
void CXM1014::PrimaryAttack()
2015-06-30 12:46:07 +03:00
{
2015-11-24 00:01:09 +03:00
Vector vecAiming, vecSrc, vecDir;
int flag;
// don't fire underwater
2015-12-06 22:57:51 +03:00
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound();
m_flNextPrimaryAttack = GetNextAttackDelay(0.15);
return;
2015-11-24 00:01:09 +03:00
}
2015-12-06 22:57:51 +03:00
if (m_iClip <= 0)
{
#ifdef BUILD_LATEST_FIXES
if (!m_fInSpecialReload)
{
PlayEmptySound();
if (TheBots)
{
TheBots->OnEvent(EVENT_WEAPON_FIRED_ON_EMPTY, m_pPlayer);
}
}
Reload();
#else
2015-12-06 22:57:51 +03:00
Reload();
2015-12-06 22:57:51 +03:00
if (!m_iClip)
{
PlayEmptySound();
}
2017-11-22 20:27:55 +03:00
if (TheBots)
2015-12-06 22:57:51 +03:00
{
TheBots->OnEvent(EVENT_WEAPON_FIRED_ON_EMPTY, m_pPlayer);
}
m_flNextPrimaryAttack = GetNextAttackDelay(1);
#endif // #ifdef BUILD_LATEST_FIXES
2015-12-06 22:57:51 +03:00
return;
2015-11-24 00:01:09 +03:00
}
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_iClip--;
m_pPlayer->pev->effects |= EF_MUZZLEFLASH;
// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
2015-12-06 22:57:51 +03:00
vecSrc = m_pPlayer->GetGunPosition();
vecAiming = gpGlobals->v_forward;
#ifdef REGAMEDLL_API
float flBaseDamage = CSPlayerWeapon()->m_flBaseDamage;
#else
float flBaseDamage = XM1014_DAMAGE;
#endif
#ifdef REGAMEDLL_FIXES
m_pPlayer->FireBuckshots(6, vecSrc, vecAiming, XM1014_CONE_VECTOR, 3048, 0, flBaseDamage);
#else
2015-11-24 00:01:09 +03:00
m_pPlayer->FireBullets(6, vecSrc, vecAiming, XM1014_CONE_VECTOR, 3048, BULLET_PLAYER_BUCKSHOT, 0);
#endif
2015-11-24 00:01:09 +03:00
2015-12-06 22:57:51 +03:00
#ifdef CLIENT_WEAPONS
flag = FEV_NOTHOST;
#else
flag = 0;
#endif
2015-12-06 22:57:51 +03:00
2015-11-24 00:01:09 +03:00
PLAYBACK_EVENT_FULL(flag, m_pPlayer->edict(), m_usFireXM1014, 0, (float *)&g_vecZero, (float *)&g_vecZero, m_vVecAiming.x, m_vVecAiming.y, 7,
int(m_vVecAiming.x * 100), m_iClip == 0, FALSE);
2015-11-24 00:01:09 +03:00
2015-12-06 22:57:51 +03:00
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
{
// HEV suit - indicate out of ammo condition
2017-10-12 17:50:56 +03:00
m_pPlayer->SetSuitUpdate("!HEV_AMO0", SUIT_SENTENCE, SUIT_REPEAT_OK);
2015-11-24 00:01:09 +03:00
}
2017-10-12 17:50:56 +03:00
#ifndef REGAMEDLL_FIXES
2015-11-24 00:01:09 +03:00
if (m_iClip != 0)
m_flPumpTime = UTIL_WeaponTimeBase() + 0.125f;
2017-10-12 17:50:56 +03:00
#endif
2015-11-24 00:01:09 +03:00
2015-12-06 22:57:51 +03:00
m_flNextPrimaryAttack = GetNextAttackDelay(0.25);
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.25f;
2015-11-24 00:01:09 +03:00
2015-12-06 22:57:51 +03:00
if (m_iClip != 0)
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.25f;
2015-12-06 22:57:51 +03:00
else
m_flTimeWeaponIdle = 0.75f;
2015-11-24 00:01:09 +03:00
m_fInSpecialReload = 0;
if (m_pPlayer->pev->flags & FL_ONGROUND)
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 3, 5);
else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 7, 10);
2015-06-30 12:46:07 +03:00
}
void CXM1014::Reload()
2015-06-30 12:46:07 +03:00
{
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == iMaxClip())
2015-12-06 22:57:51 +03:00
return;
// don't reload until recoil is done
if (m_flNextPrimaryAttack > UTIL_WeaponTimeBase())
return;
// check to see if we're ready to reload
if (m_fInSpecialReload == 0)
{
m_pPlayer->SetAnimation(PLAYER_RELOAD);
SendWeaponAnim(XM1014_START_RELOAD, UseDecrement() != FALSE);
m_fInSpecialReload = 1;
m_flNextSecondaryAttack = m_flTimeWeaponIdle = m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.55f;
2015-12-06 22:57:51 +03:00
m_flNextPrimaryAttack = GetNextAttackDelay(0.55);
}
else if (m_fInSpecialReload == 1)
{
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
return;
// was waiting for gun to move to side
m_fInSpecialReload = 2;
if (RANDOM_LONG(0, 1))
EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_ITEM, "weapons/reload1.wav", VOL_NORM, ATTN_NORM, 0, 85 + RANDOM_LONG(0, 31));
else
EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_ITEM, "weapons/reload3.wav", VOL_NORM, ATTN_NORM, 0, 85 + RANDOM_LONG(0, 31));
SendWeaponAnim(XM1014_RELOAD, UseDecrement());
m_flTimeWeaponIdle = m_flNextReload = UTIL_WeaponTimeBase() + 0.3f;
2015-12-06 22:57:51 +03:00
}
else
#ifdef BUILD_LATEST_FIXES
if (m_flTimeWeaponIdle <= UTIL_WeaponTimeBase())
#endif
2015-12-06 22:57:51 +03:00
{
2017-10-12 17:50:56 +03:00
m_iClip++;
#ifdef REGAMEDLL_ADD
if (refill_bpammo_weapons.value < 3.0f)
#endif
{
2017-10-12 17:50:56 +03:00
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->ammo_buckshot--;
}
2015-12-06 22:57:51 +03:00
m_fInSpecialReload = 1;
2015-11-24 00:01:09 +03:00
}
2015-06-30 12:46:07 +03:00
}
void CXM1014::WeaponIdle()
2015-06-30 12:46:07 +03:00
{
2015-12-06 22:57:51 +03:00
ResetEmptySound();
m_pPlayer->GetAutoaimVector(AUTOAIM_5DEGREES);
2017-10-12 17:50:56 +03:00
#ifndef REGAMEDLL_FIXES
2015-12-06 22:57:51 +03:00
if (m_flPumpTime && m_flPumpTime < UTIL_WeaponTimeBase())
{
m_flPumpTime = 0;
}
2017-10-12 17:50:56 +03:00
#endif
2015-12-06 22:57:51 +03:00
if (m_flTimeWeaponIdle < UTIL_WeaponTimeBase())
{
if (m_iClip == 0 && m_fInSpecialReload == 0 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
{
Reload();
}
else if (m_fInSpecialReload != 0)
{
if (m_iClip != iMaxClip() && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
2015-12-06 22:57:51 +03:00
{
Reload();
}
else
{
// reload debounce has timed out
SendWeaponAnim(XM1014_PUMP, UseDecrement() != FALSE);
m_fInSpecialReload = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5f;
2015-12-06 22:57:51 +03:00
}
}
else
{
SendWeaponAnim(XM1014_IDLE, UseDecrement() != FALSE);
}
2015-11-24 00:01:09 +03:00
}
2015-06-30 12:46:07 +03:00
}