2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 01:47:45 +01:00
hlsdk-xash3d/dlls/crossbow.cpp

561 lines
13 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* 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.
*
****/
2021-06-07 16:20:38 +02:00
#if !OEM_BUILD && !HLDEMO_BUILD
2016-06-04 15:24:23 +02:00
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"
2021-06-07 02:05:58 +02:00
#if !CLIENT_DLL
2016-06-04 15:24:23 +02:00
#define BOLT_AIR_VELOCITY 2000
#define BOLT_WATER_VELOCITY 1000
// UNDONE: Save/restore this? Don't forget to set classname and LINK_ENTITY_TO_CLASS()
//
// OVERLOADS SOME ENTVARS:
//
// speed - the ideal magnitude of my velocity
class CCrossbowBolt : public CBaseEntity
{
void Spawn( void );
void Precache( void );
2016-07-31 15:48:50 +02:00
int Classify( void );
2016-06-04 15:24:23 +02:00
void EXPORT BubbleThink( void );
void EXPORT BoltTouch( CBaseEntity *pOther );
void EXPORT ExplodeThink( void );
int m_iTrail;
public:
static CCrossbowBolt *BoltCreate( void );
};
2016-06-25 20:21:01 +02:00
LINK_ENTITY_TO_CLASS( crossbow_bolt, CCrossbowBolt )
2016-06-04 15:24:23 +02:00
CCrossbowBolt *CCrossbowBolt::BoltCreate( void )
{
// Create a new entity with CCrossbowBolt private data
CCrossbowBolt *pBolt = GetClassPtr( (CCrossbowBolt *)NULL );
2016-07-31 15:48:50 +02:00
pBolt->pev->classname = MAKE_STRING( "crossbow_bolt" ); // g-cont. enable save\restore
2016-06-04 15:24:23 +02:00
pBolt->Spawn();
return pBolt;
}
2016-07-31 15:48:50 +02:00
void CCrossbowBolt::Spawn()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
2019-10-13 13:49:25 +02:00
pev->gravity = 0.5f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/crossbow_bolt.mdl" );
2016-06-04 15:24:23 +02:00
UTIL_SetOrigin( pev, pev->origin );
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
2016-06-04 15:24:23 +02:00
SetTouch( &CCrossbowBolt::BoltTouch );
SetThink( &CCrossbowBolt::BubbleThink );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.2f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CCrossbowBolt::Precache()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/crossbow_bolt.mdl" );
PRECACHE_SOUND( "weapons/xbow_hitbod1.wav" );
PRECACHE_SOUND( "weapons/xbow_hitbod2.wav" );
PRECACHE_SOUND( "weapons/xbow_fly1.wav" );
PRECACHE_SOUND( "weapons/xbow_hit1.wav" );
PRECACHE_SOUND( "fvox/beep.wav" );
m_iTrail = PRECACHE_MODEL( "sprites/streak.spr" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
int CCrossbowBolt::Classify( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
return CLASS_NONE;
2016-06-04 15:24:23 +02:00
}
void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
{
SetTouch( NULL );
SetThink( NULL );
2016-07-31 15:48:50 +02:00
if( pOther->pev->takedamage )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TraceResult tr = UTIL_GetGlobalTrace();
entvars_t *pevOwner;
2016-06-04 15:24:23 +02:00
pevOwner = VARS( pev->owner );
// UNDONE: this needs to call TraceAttack instead
2016-07-31 15:48:50 +02:00
ClearMultiDamage();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( pOther->IsPlayer() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pOther->TraceAttack( pevOwner, gSkillData.plrDmgCrossbowClient, pev->velocity.Normalize(), &tr, DMG_NEVERGIB );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
pOther->TraceAttack( pevOwner, gSkillData.plrDmgCrossbowMonster, pev->velocity.Normalize(), &tr, DMG_BULLET | DMG_NEVERGIB );
2016-06-04 15:24:23 +02:00
}
ApplyMultiDamage( pev, pevOwner );
pev->velocity = Vector( 0, 0, 0 );
// play body "thwack" sound
2016-07-31 15:48:50 +02:00
switch( RANDOM_LONG( 0, 1 ) )
2016-06-04 15:24:23 +02:00
{
case 0:
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/xbow_hitbod1.wav", 1, ATTN_NORM );
break;
2016-06-04 15:24:23 +02:00
case 1:
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/xbow_hitbod2.wav", 1, ATTN_NORM );
break;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
Killed( pev, GIB_NEVER );
}
}
else
{
2019-10-13 13:49:25 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "weapons/xbow_hit1.wav", RANDOM_FLOAT( 0.95f, 1.0f ), ATTN_NORM, 0, 98 + RANDOM_LONG( 0, 7 ) );
2016-06-04 15:24:23 +02:00
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time;// this will get changed below if the bolt is allowed to stick in what it hit.
2016-07-31 15:48:50 +02:00
if( FClassnameIs( pOther->pev, "worldspawn" ) )
2016-06-04 15:24:23 +02:00
{
// if what we hit is static architecture, can stay around for a while.
2016-07-31 15:48:50 +02:00
Vector vecDir = pev->velocity.Normalize();
2019-10-13 13:49:25 +02:00
UTIL_SetOrigin( pev, pev->origin - vecDir * 12.0f );
2016-06-04 15:24:23 +02:00
pev->angles = UTIL_VecToAngles( vecDir );
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_FLY;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity.z = 0;
2016-07-31 15:48:50 +02:00
pev->angles.z = RANDOM_LONG( 0, 360 );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 10.0f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( pOther->pev->movetype == MOVETYPE_PUSH || pOther->pev->movetype == MOVETYPE_PUSHSTEP )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Vector vecDir = pev->velocity.Normalize();
2019-10-13 13:49:25 +02:00
UTIL_SetOrigin( pev, pev->origin - vecDir * 12.0f );
2016-06-04 15:24:23 +02:00
pev->angles = UTIL_VecToAngles( vecDir );
pev->solid = SOLID_NOT;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity.z = 0;
2016-07-31 15:48:50 +02:00
pev->angles.z = RANDOM_LONG( 0, 360 );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 10.0f;
2016-06-04 15:24:23 +02:00
2020-04-22 10:51:43 +02:00
if( g_fIsXash3D )
{
2017-01-04 20:05:21 +01:00
// g-cont. Setup movewith feature
pev->movetype = MOVETYPE_COMPOUND; // set movewith type
pev->aiment = ENT( pOther->pev ); // set parent
}
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( UTIL_PointContents( pev->origin ) != CONTENTS_WATER )
2016-06-04 15:24:23 +02:00
{
UTIL_Sparks( pev->origin );
}
}
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
SetThink( &CCrossbowBolt::ExplodeThink );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
}
void CCrossbowBolt::BubbleThink( void )
{
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( pev->waterlevel == 0 )
2016-06-04 15:24:23 +02:00
return;
2019-10-13 13:49:25 +02:00
UTIL_BubbleTrail( pev->origin - pev->velocity * 0.1f, pev->origin, 1 );
2016-06-04 15:24:23 +02:00
}
void CCrossbowBolt::ExplodeThink( void )
{
2016-07-31 15:48:50 +02:00
int iContents = UTIL_PointContents( pev->origin );
2016-06-04 15:24:23 +02:00
int iScale;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
pev->dmg = 40;
iScale = 10;
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( TE_EXPLOSION );
2016-06-04 15:24:23 +02:00
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
2016-07-31 15:48:50 +02:00
if( iContents != CONTENTS_WATER )
2016-06-04 15:24:23 +02:00
{
WRITE_SHORT( g_sModelIndexFireball );
}
else
{
WRITE_SHORT( g_sModelIndexWExplosion );
}
2016-07-31 15:48:50 +02:00
WRITE_BYTE( iScale ); // scale * 10
WRITE_BYTE( 15 ); // framerate
2016-06-04 15:24:23 +02:00
WRITE_BYTE( TE_EXPLFLAG_NONE );
MESSAGE_END();
entvars_t *pevOwner;
2016-07-31 15:48:50 +02:00
if( pev->owner )
2016-06-04 15:24:23 +02:00
pevOwner = VARS( pev->owner );
else
pevOwner = NULL;
pev->owner = NULL; // can't traceline attack owner if this is set
::RadiusDamage( pev->origin, pev, pevOwner, pev->dmg, 128, CLASS_NONE, DMG_BLAST | DMG_ALWAYSGIB );
2016-07-31 15:48:50 +02:00
UTIL_Remove( this );
2016-06-04 15:24:23 +02:00
}
#endif
2016-07-31 15:48:50 +02:00
enum crossbow_e
{
2016-06-04 15:24:23 +02:00
CROSSBOW_IDLE1 = 0, // full
CROSSBOW_IDLE2, // empty
CROSSBOW_FIDGET1, // full
CROSSBOW_FIDGET2, // empty
CROSSBOW_FIRE1, // full
CROSSBOW_FIRE2, // reload
CROSSBOW_FIRE3, // empty
CROSSBOW_RELOAD, // from empty
CROSSBOW_DRAW1, // full
CROSSBOW_DRAW2, // empty
CROSSBOW_HOLSTER1, // full
CROSSBOW_HOLSTER2 // empty
2016-06-04 15:24:23 +02:00
};
LINK_ENTITY_TO_CLASS( weapon_crossbow, CCrossbow )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CCrossbow::Spawn()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
m_iId = WEAPON_CROSSBOW;
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/w_crossbow.mdl" );
2016-06-04 15:24:23 +02:00
m_iDefaultAmmo = CROSSBOW_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
int CCrossbow::AddToPlayer( CBasePlayer *pPlayer )
{
2016-07-31 15:48:50 +02:00
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
void CCrossbow::Precache( void )
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/w_crossbow.mdl" );
PRECACHE_MODEL( "models/v_crossbow.mdl" );
PRECACHE_MODEL( "models/p_crossbow.mdl" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_SOUND( "weapons/xbow_fire1.wav" );
PRECACHE_SOUND( "weapons/xbow_reload1.wav" );
2016-06-04 15:24:23 +02:00
UTIL_PrecacheOther( "crossbow_bolt" );
m_usCrossbow = PRECACHE_EVENT( 1, "events/crossbow1.sc" );
m_usCrossbow2 = PRECACHE_EVENT( 1, "events/crossbow2.sc" );
}
2016-07-31 15:48:50 +02:00
int CCrossbow::GetItemInfo( ItemInfo *p )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
p->pszName = STRING( pev->classname );
2016-06-04 15:24:23 +02:00
p->pszAmmo1 = "bolts";
p->iMaxAmmo1 = BOLT_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = CROSSBOW_MAX_CLIP;
p->iSlot = 2;
p->iPosition = 2;
p->iId = WEAPON_CROSSBOW;
p->iFlags = 0;
p->iWeight = CROSSBOW_WEIGHT;
return 1;
}
2016-07-31 15:48:50 +02:00
BOOL CCrossbow::Deploy()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_iClip )
2016-06-04 15:24:23 +02:00
return DefaultDeploy( "models/v_crossbow.mdl", "models/p_crossbow.mdl", CROSSBOW_DRAW1, "bow" );
return DefaultDeploy( "models/v_crossbow.mdl", "models/p_crossbow.mdl", CROSSBOW_DRAW2, "bow" );
}
void CCrossbow::Holster( int skiplocal /* = 0 */ )
{
m_fInReload = FALSE;// cancel any reload in progress.
2023-09-30 20:27:53 +02:00
if( m_pPlayer->pev->fov != 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SecondaryAttack();
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
2016-07-31 15:48:50 +02:00
if( m_iClip )
2016-06-04 15:24:23 +02:00
SendWeaponAnim( CROSSBOW_HOLSTER1 );
else
SendWeaponAnim( CROSSBOW_HOLSTER2 );
}
void CCrossbow::PrimaryAttack( void )
{
2021-06-07 02:05:58 +02:00
#if CLIENT_DLL
2016-07-31 15:48:50 +02:00
if( m_fInZoom && bIsMultiplayer() )
2016-06-04 15:24:23 +02:00
#else
2016-07-31 15:48:50 +02:00
if( m_fInZoom && g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
#endif
{
FireSniperBolt();
return;
}
FireBolt();
}
// this function only gets called in multiplayer
void CCrossbow::FireSniperBolt()
{
2019-10-13 13:49:25 +02:00
m_flNextPrimaryAttack = GetNextAttackDelay( 0.75f );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_iClip == 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PlayEmptySound();
2016-06-04 15:24:23 +02:00
return;
}
TraceResult tr;
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_iClip--;
int flags;
2021-06-07 16:17:22 +02:00
#if CLIENT_WEAPONS
2016-06-04 15:24:23 +02:00
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usCrossbow2, 0.0f, g_vecZero, g_vecZero, 0, 0, m_iClip, 0, 0, 0 );
2016-06-04 15:24:23 +02:00
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
Vector anglesAim = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
UTIL_MakeVectors( anglesAim );
2019-10-13 13:49:25 +02:00
Vector vecSrc = m_pPlayer->GetGunPosition() - gpGlobals->v_up * 2.0f;
2016-06-04 15:24:23 +02:00
Vector vecDir = gpGlobals->v_forward;
2016-07-31 15:48:50 +02:00
UTIL_TraceLine( vecSrc, vecSrc + vecDir * 8192, dont_ignore_monsters, m_pPlayer->edict(), &tr );
2016-06-04 15:24:23 +02:00
2021-06-07 02:05:58 +02:00
#if !CLIENT_DLL
2016-07-31 15:48:50 +02:00
if( tr.pHit->v.takedamage )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ClearMultiDamage();
CBaseEntity::Instance( tr.pHit )->TraceAttack( m_pPlayer->pev, 120, vecDir, &tr, DMG_BULLET | DMG_NEVERGIB );
2016-06-04 15:24:23 +02:00
ApplyMultiDamage( pev, m_pPlayer->pev );
}
#endif
}
void CCrossbow::FireBolt()
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
if( m_iClip == 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PlayEmptySound();
2016-06-04 15:24:23 +02:00
return;
}
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_iClip--;
int flags;
2021-06-07 16:17:22 +02:00
#if CLIENT_WEAPONS
2016-06-04 15:24:23 +02:00
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usCrossbow, 0.0f, g_vecZero, g_vecZero, 0, 0, m_iClip, 0, 0, 0 );
2016-06-04 15:24:23 +02:00
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
Vector anglesAim = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
UTIL_MakeVectors( anglesAim );
2016-07-31 15:48:50 +02:00
anglesAim.x = -anglesAim.x;
2017-06-29 15:56:03 +02:00
2021-06-07 02:05:58 +02:00
#if !CLIENT_DLL
2019-10-13 13:49:25 +02:00
Vector vecSrc = m_pPlayer->GetGunPosition() - gpGlobals->v_up * 2.0f;
2016-07-31 15:48:50 +02:00
Vector vecDir = gpGlobals->v_forward;
2016-06-04 15:24:23 +02:00
CCrossbowBolt *pBolt = CCrossbowBolt::BoltCreate();
pBolt->pev->origin = vecSrc;
pBolt->pev->angles = anglesAim;
pBolt->pev->owner = m_pPlayer->edict();
2016-07-31 15:48:50 +02:00
if( m_pPlayer->pev->waterlevel == 3 )
2016-06-04 15:24:23 +02:00
{
pBolt->pev->velocity = vecDir * BOLT_WATER_VELOCITY;
pBolt->pev->speed = BOLT_WATER_VELOCITY;
}
else
{
pBolt->pev->velocity = vecDir * BOLT_AIR_VELOCITY;
pBolt->pev->speed = BOLT_AIR_VELOCITY;
}
2019-10-13 13:49:25 +02:00
pBolt->pev->avelocity.z = 10.0f;
2016-06-04 15:24:23 +02:00
#endif
2016-07-31 15:48:50 +02:00
if( !m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
2016-06-04 15:24:23 +02:00
// HEV suit - indicate out of ammo condition
2016-07-31 15:48:50 +02:00
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
m_flNextPrimaryAttack = GetNextAttackDelay( 0.75f );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.75f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_iClip != 0 )
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 5.0f;
2016-06-04 15:24:23 +02:00
else
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.75f;
2016-06-04 15:24:23 +02:00
}
void CCrossbow::SecondaryAttack()
{
2016-07-31 15:48:50 +02:00
if( m_pPlayer->pev->fov != 0 )
2016-06-04 15:24:23 +02:00
{
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
m_fInZoom = 0;
}
2016-07-31 15:48:50 +02:00
else if( m_pPlayer->pev->fov != 20 )
2016-06-04 15:24:23 +02:00
{
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 20;
m_fInZoom = 1;
}
2016-07-31 15:48:50 +02:00
2019-10-13 13:49:25 +02:00
pev->nextthink = UTIL_WeaponTimeBase() + 0.1f;
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f;
2016-06-04 15:24:23 +02:00
}
void CCrossbow::Reload( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == CROSSBOW_MAX_CLIP )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( m_pPlayer->pev->fov != 0 )
2016-06-04 15:24:23 +02:00
{
SecondaryAttack();
}
2019-10-13 13:49:25 +02:00
if( DefaultReload( CROSSBOW_MAX_CLIP, CROSSBOW_RELOAD, 4.5f ) )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/xbow_reload1.wav", RANDOM_FLOAT( 0.95f, 1.0f ), ATTN_NORM, 0, 93 + RANDOM_LONG( 0, 0xF ) );
2016-06-04 15:24:23 +02:00
}
}
void CCrossbow::WeaponIdle( void )
{
m_pPlayer->GetAutoaimVector( AUTOAIM_2DEGREES ); // get the autoaim vector but ignore it; used for autoaim crosshair in DM
2016-07-31 15:48:50 +02:00
ResetEmptySound();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_flTimeWeaponIdle < UTIL_WeaponTimeBase() )
2016-06-04 15:24:23 +02:00
{
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
2019-10-13 13:49:25 +02:00
if( flRand <= 0.75f )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_iClip )
2016-06-04 15:24:23 +02:00
{
SendWeaponAnim( CROSSBOW_IDLE1 );
}
else
{
SendWeaponAnim( CROSSBOW_IDLE2 );
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
else
{
2016-07-31 15:48:50 +02:00
if( m_iClip )
2016-06-04 15:24:23 +02:00
{
SendWeaponAnim( CROSSBOW_FIDGET1 );
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 90.0f / 30.0f;
2016-06-04 15:24:23 +02:00
}
else
{
SendWeaponAnim( CROSSBOW_FIDGET2 );
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 80.0f / 30.0f;
2016-06-04 15:24:23 +02:00
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
}
}
class CCrossbowAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
2016-07-31 15:48:50 +02:00
Precache();
SET_MODEL( ENT( pev ), "models/w_crossbow_clip.mdl" );
CBasePlayerAmmo::Spawn();
2016-06-04 15:24:23 +02:00
}
void Precache( void )
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/w_crossbow_clip.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
BOOL AddAmmo( CBaseEntity *pOther )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pOther->GiveAmmo( AMMO_CROSSBOWCLIP_GIVE, "bolts", BOLT_MAX_CARRY ) != -1 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
return TRUE;
}
return FALSE;
}
};
2016-06-25 20:21:01 +02:00
LINK_ENTITY_TO_CLASS( ammo_crossbow, CCrossbowAmmo )
2016-04-17 22:30:05 +02:00
#endif