221 lines
5.4 KiB
C++
221 lines
5.4 KiB
C++
/***
|
|
*
|
|
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
|
*
|
|
* This product contains software technology licensed from Id
|
|
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
|
* All Rights Reserved.
|
|
*
|
|
* Use, distribution, and modification of this source code and/or resulting
|
|
* object code is restricted to non-commercial enhancements to products from
|
|
* Valve LLC. All other use, distribution, or modification is prohibited
|
|
* without written permission from Valve LLC.
|
|
*
|
|
****/
|
|
|
|
#include "stdafx.h"
|
|
#include "cbase.h"
|
|
#include "player.h"
|
|
#include "weapons.h"
|
|
|
|
enum xm1014_e
|
|
{
|
|
XM1014_IDLE,
|
|
XM1014_FIRE1,
|
|
XM1014_FIRE2,
|
|
XM1014_RELOAD,
|
|
XM1014_PUMP,
|
|
XM1014_START_RELOAD,
|
|
XM1014_DRAW
|
|
};
|
|
|
|
LINK_ENTITY_TO_CLASS(weapon_xm1014, CXM1014);
|
|
|
|
void CXM1014::Spawn(void)
|
|
{
|
|
Precache();
|
|
m_iId = WEAPON_XM1014;
|
|
SET_MODEL(ENT(pev), "models/w_xm1014.mdl");
|
|
|
|
m_iDefaultAmmo = XM1014_DEFAULT_GIVE;
|
|
|
|
FallInit();
|
|
}
|
|
|
|
void CXM1014::Precache(void)
|
|
{
|
|
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");
|
|
|
|
m_usFireXM1014 = PRECACHE_EVENT(1, "events/xm1014.sc");
|
|
}
|
|
|
|
int CXM1014::GetItemInfo(ItemInfo *p)
|
|
{
|
|
p->pszName = STRING(pev->classname);
|
|
p->pszAmmo1 = "buckshot";
|
|
p->iMaxAmmo1 = BUCKSHOT_MAX_CARRY;
|
|
p->pszAmmo2 = NULL;
|
|
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;
|
|
|
|
return 1;
|
|
}
|
|
|
|
BOOL CXM1014::Deploy(void)
|
|
{
|
|
return DefaultDeploy("models/v_xm1014.mdl", "models/p_xm1014.mdl", XM1014_DRAW, "m249", UseDecrement() != FALSE);
|
|
}
|
|
|
|
void CXM1014::PrimaryAttack(void)
|
|
{
|
|
if (m_pPlayer->pev->waterlevel == 3)
|
|
{
|
|
PlayEmptySound();
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15;
|
|
return;
|
|
}
|
|
|
|
if (m_iClip <= 0)
|
|
{
|
|
Reload();
|
|
|
|
if (m_iClip == 0)
|
|
PlayEmptySound();
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.0;
|
|
return;
|
|
}
|
|
|
|
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
|
|
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
|
|
|
|
m_iClip--;
|
|
m_pPlayer->pev->effects |= EF_MUZZLEFLASH;
|
|
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
|
|
m_pPlayer->FireBullets(6, m_pPlayer->GetGunPosition(), gpGlobals->v_forward, Vector(0.0725, 0.0725, 0.0), 3048, BULLET_PLAYER_BUCKSHOT, 0);
|
|
|
|
int flags;
|
|
#ifdef CLIENT_WEAPONS
|
|
flags = FEV_NOTHOST;
|
|
#else
|
|
flags = 0;
|
|
#endif
|
|
|
|
PLAYBACK_EVENT_FULL(flags, ENT(m_pPlayer->pev), m_usFireXM1014, 0, (float *)&g_vecZero, (float *)&g_vecZero, m_vVecAiming.x, m_vVecAiming.y, 7, m_vVecAiming.x * 100, m_iClip != 0, FALSE);
|
|
|
|
if (m_iClip)
|
|
m_flPumpTime = UTIL_WeaponTimeBase() + 0.125;
|
|
|
|
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
|
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
|
|
|
|
if (m_iClip)
|
|
m_flPumpTime = UTIL_WeaponTimeBase() + 0.125;
|
|
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.25;
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.25;
|
|
|
|
if (m_iClip)
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.25;
|
|
else
|
|
m_flTimeWeaponIdle = 0.75;
|
|
|
|
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);
|
|
}
|
|
|
|
void CXM1014::Reload(void)
|
|
{
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == XM1014_MAX_CLIP)
|
|
return;
|
|
|
|
if (m_flNextPrimaryAttack > UTIL_WeaponTimeBase())
|
|
return;
|
|
|
|
if (!m_fInSpecialReload)
|
|
{
|
|
m_pPlayer->SetAnimation(PLAYER_RELOAD);
|
|
SendWeaponAnim(XM1014_START_RELOAD, UseDecrement() != FALSE);
|
|
|
|
m_fInSpecialReload = 1;
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.55;
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.55;
|
|
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.55;
|
|
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.55;
|
|
}
|
|
else if (m_fInSpecialReload == 1)
|
|
{
|
|
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
|
|
return;
|
|
|
|
m_fInSpecialReload = 2;
|
|
|
|
if (RANDOM_LONG(0, 1))
|
|
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/reload1.wav", VOL_NORM, ATTN_NORM, 0, 85 + RANDOM_LONG(0, 31));
|
|
else
|
|
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/reload3.wav", VOL_NORM, ATTN_NORM, 0, 85 + RANDOM_LONG(0, 31));
|
|
|
|
SendWeaponAnim(XM1014_RELOAD, UseDecrement());
|
|
|
|
m_flNextReload = UTIL_WeaponTimeBase() + 0.3;
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.3;
|
|
}
|
|
else
|
|
{
|
|
m_iClip++;
|
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
|
|
m_fInSpecialReload = 1;
|
|
m_pPlayer->ammo_buckshot--;
|
|
}
|
|
}
|
|
|
|
void CXM1014::WeaponIdle(void)
|
|
{
|
|
ResetEmptySound();
|
|
m_pPlayer->GetAutoaimVector(AUTOAIM_5DEGREES);
|
|
|
|
if (m_flPumpTime && m_flPumpTime < UTIL_WeaponTimeBase())
|
|
m_flPumpTime = 0;
|
|
|
|
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 != XM1014_MAX_CLIP && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
|
{
|
|
Reload();
|
|
}
|
|
else
|
|
{
|
|
SendWeaponAnim(XM1014_PUMP, UseDecrement() != FALSE);
|
|
|
|
m_fInSpecialReload = 0;
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5;
|
|
}
|
|
}
|
|
else
|
|
SendWeaponAnim(XM1014_IDLE, UseDecrement() != FALSE);
|
|
}
|
|
} |