halflife-photomode/dlls/glock.cpp

239 lines
5.4 KiB
C++
Raw Normal View History

/***
2013-08-30 13:34:05 -07:00
*
* Copyright (c) 1996-2001, 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 "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "player.h"
LINK_ENTITY_TO_CLASS(weapon_glock, CGlock);
LINK_ENTITY_TO_CLASS(weapon_9mmhandgun, CGlock);
2013-08-30 13:34:05 -07:00
void CGlock::Spawn()
2013-08-30 13:34:05 -07:00
{
pev->classname = MAKE_STRING("weapon_9mmhandgun"); // hack to allow for old names
Precache();
2013-08-30 13:34:05 -07:00
m_iId = WEAPON_GLOCK;
SET_MODEL(ENT(pev), "models/w_9mmhandgun.mdl");
m_iDefaultAmmo = GLOCK_DEFAULT_GIVE;
FallInit(); // get ready to fall down.
2013-08-30 13:34:05 -07:00
}
void CGlock::Precache()
2013-08-30 13:34:05 -07:00
{
PRECACHE_MODEL("models/v_9mmhandgun.mdl");
PRECACHE_MODEL("models/w_9mmhandgun.mdl");
PRECACHE_MODEL("models/p_9mmhandgun.mdl");
m_iShell = PRECACHE_MODEL("models/shell.mdl"); // brass shell
2013-08-30 13:34:05 -07:00
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND("items/9mmclip2.wav");
PRECACHE_SOUND("weapons/pl_gun1.wav"); //silenced handgun
PRECACHE_SOUND("weapons/pl_gun2.wav"); //silenced handgun
PRECACHE_SOUND("weapons/pl_gun3.wav"); //handgun
2013-08-30 13:34:05 -07:00
m_usFireGlock1 = PRECACHE_EVENT(1, "events/glock1.sc");
m_usFireGlock2 = PRECACHE_EVENT(1, "events/glock2.sc");
2013-08-30 13:34:05 -07:00
}
bool CGlock::GetItemInfo(ItemInfo* p)
2013-08-30 13:34:05 -07:00
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "9mm";
p->iMaxAmmo1 = _9MM_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = GLOCK_MAX_CLIP;
p->iSlot = 1;
p->iPosition = 0;
p->iFlags = 0;
p->iId = m_iId = WEAPON_GLOCK;
p->iWeight = GLOCK_WEIGHT;
return true;
2013-08-30 13:34:05 -07:00
}
bool CGlock::Deploy()
2013-08-30 13:34:05 -07:00
{
// pev->body = 1;
return DefaultDeploy("models/v_9mmhandgun.mdl", "models/p_9mmhandgun.mdl", GLOCK_DRAW, "onehanded");
2013-08-30 13:34:05 -07:00
}
void CGlock::SecondaryAttack()
2013-08-30 13:34:05 -07:00
{
GlockFire(0.1, 0.2, false);
2013-08-30 13:34:05 -07:00
}
void CGlock::PrimaryAttack()
2013-08-30 13:34:05 -07:00
{
GlockFire(0.01, 0.3, true);
2013-08-30 13:34:05 -07:00
}
void CGlock::GlockFire(float flSpread, float flCycleTime, bool fUseAutoAim)
2013-08-30 13:34:05 -07:00
{
if (m_iClip <= 0)
{
//if (m_fFireOnEmpty)
2013-08-30 13:34:05 -07:00
{
PlayEmptySound();
m_flNextPrimaryAttack = m_flNextSecondaryAttack = GetNextAttackDelay(0.2);
2013-08-30 13:34:05 -07:00
}
return;
}
m_iClip--;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
int flags;
#if defined(CLIENT_WEAPONS)
2013-08-30 13:34:05 -07:00
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
2013-08-30 13:34:05 -07:00
// silenced
if (pev->body == 1)
{
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
}
else
{
// non-silenced
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
}
Vector vecSrc = m_pPlayer->GetGunPosition();
2013-08-30 13:34:05 -07:00
Vector vecAiming;
if (fUseAutoAim)
2013-08-30 13:34:05 -07:00
{
vecAiming = m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);
2013-08-30 13:34:05 -07:00
}
else
{
vecAiming = gpGlobals->v_forward;
}
Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer(1, vecSrc, vecAiming, Vector(flSpread, flSpread, flSpread), 8192, BULLET_PLAYER_9MM, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed);
2013-08-30 13:34:05 -07:00
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), fUseAutoAim ? m_usFireGlock1 : m_usFireGlock2, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, (m_iClip == 0) ? 1 : 0, 0);
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = m_flNextSecondaryAttack = GetNextAttackDelay(flCycleTime);
if (0 == m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
2013-08-30 13:34:05 -07:00
// HEV suit - indicate out of ammo condition
2021-11-19 13:43:33 +01:00
m_pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
2013-08-30 13:34:05 -07:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
2013-08-30 13:34:05 -07:00
}
void CGlock::Reload()
2013-08-30 13:34:05 -07:00
{
if (m_pPlayer->ammo_9mm <= 0)
return;
2013-08-30 13:34:05 -07:00
bool iResult = DefaultReload(17, m_iClip > 0 ? GLOCK_RELOAD_NOT_EMPTY : GLOCK_RELOAD, 1.5);
2013-08-30 13:34:05 -07:00
if (iResult)
{
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
2013-08-30 13:34:05 -07:00
}
}
void CGlock::WeaponIdle()
2013-08-30 13:34:05 -07:00
{
ResetEmptySound();
2013-08-30 13:34:05 -07:00
m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);
2013-08-30 13:34:05 -07:00
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
2013-08-30 13:34:05 -07:00
return;
// only idle if the slid isn't back
if (m_iClip != 0)
{
int iAnim;
float flRand = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 0.0, 1.0);
2013-08-30 13:34:05 -07:00
if (flRand <= 0.3 + 0 * 0.75)
{
iAnim = GLOCK_IDLE3;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 49.0 / 16;
}
else if (flRand <= 0.6 + 0 * 0.875)
{
iAnim = GLOCK_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 60.0 / 16.0;
}
else
{
iAnim = GLOCK_IDLE2;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 40.0 / 16.0;
}
SendWeaponAnim(iAnim);
2013-08-30 13:34:05 -07:00
}
}
class CGlockAmmo : public CBasePlayerAmmo
{
void Spawn() override
{
Precache();
2013-08-30 13:34:05 -07:00
SET_MODEL(ENT(pev), "models/w_9mmclip.mdl");
CBasePlayerAmmo::Spawn();
2013-08-30 13:34:05 -07:00
}
void Precache() override
2013-08-30 13:34:05 -07:00
{
PRECACHE_MODEL("models/w_9mmclip.mdl");
2013-08-30 13:34:05 -07:00
PRECACHE_SOUND("items/9mmclip1.wav");
}
bool AddAmmo(CBaseEntity* pOther) override
{
if (pOther->GiveAmmo(AMMO_GLOCKCLIP_GIVE, "9mm", _9MM_MAX_CARRY) != -1)
2013-08-30 13:34:05 -07:00
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
2021-11-19 13:45:16 +01:00
return true;
2013-08-30 13:34:05 -07:00
}
2021-11-19 13:43:33 +01:00
return false;
2013-08-30 13:34:05 -07:00
}
};
LINK_ENTITY_TO_CLASS(ammo_glockclip, CGlockAmmo);
LINK_ENTITY_TO_CLASS(ammo_9mmclip, CGlockAmmo);