rendered paste body//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "npcevent.h"
#include "in_buttons.h"
#ifdef CLIENT_DLL
#include "c_hl2mp_player.h"
#include "beamdraw.h"
#else
#include "hl2mp_player.h"
#include "util.h"
#endif
#include "weapon_hl2mpbasehlmpcombatweapon.h"
#ifdef CLIENT_DLL
#define CWeaponHealthGun C_WeaponHealthGun
#endif
//-----------------------------------------------------------------------------
// CWeaponHealthGun
//-----------------------------------------------------------------------------
class CWeaponHealthGun : public CBaseHL2MPCombatWeapon
{
DECLARE_CLASS( CWeaponHealthGun, CBaseHL2MPCombatWeapon );
public:
CWeaponHealthGun( void );
void PrimaryAttack( void );
void SecondaryAttack( void );
void DrawBeam();
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
#ifndef CLIENT_DLL
DECLARE_ACTTABLE();
#endif
private:
CWeaponHealthGun( const CWeaponHealthGun & );
};
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponHealthGun, DT_WeaponHealthGun )
BEGIN_NETWORK_TABLE( CWeaponHealthGun, DT_WeaponHealthGun )
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponHealthGun )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( weapon_healthgun, CWeaponHealthGun );
PRECACHE_WEAPON_REGISTER( weapon_healthgun );
#ifndef CLIENT_DLL
acttable_t CWeaponHealthGun::m_acttable[] =
{
{ ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_PISTOL, false },
{ ACT_HL2MP_RUN, ACT_HL2MP_RUN_PISTOL, false },
{ ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_PISTOL, false },
{ ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_PISTOL, false },
{ ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_PISTOL, false },
{ ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_PISTOL, false },
{ ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_PISTOL, false },
{ ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_PISTOL, false },
};
IMPLEMENT_ACTTABLE( CWeaponHealthGun );
#endif
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CWeaponHealthGun::CWeaponHealthGun( void )
{
m_bReloadsSingly = false;
m_bFiresUnderwater = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponHealthGun::PrimaryAttack( void )
{
// Only the player fires this way so we can cast
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
if ( m_iClip1 <= 0 )
{
if ( !m_bFireOnEmpty )
{
WeaponSound( EMPTY );
m_flNextPrimaryAttack = 0.15;
}
return;
}
WeaponSound( SINGLE );
SendWeaponAnim( ACT_VM_PRIMARYATTACK );
pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flNextPrimaryAttack = gpGlobals->curtime + 0.75;
m_flNextSecondaryAttack = gpGlobals->curtime + 0.75;
Vector vecSrc = pPlayer->Weapon_ShootPosition();
Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector vecEnd = vecSrc + vecAiming * MAX_TRACE_LENGTH;
trace_t trace;
UTIL_TraceLine( vecSrc, vecEnd, MASK_ALL, pPlayer, COLLISION_GROUP_NPC, &trace );
if (trace.m_pEnt->IsPlayer())
{
CBaseEntity *pHealy = trace.m_pEnt;
pHealy->SetHealth(23);
}
if ( !m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 )
{
// HEV suit - indicate out of ammo condition
pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
}
}
//------------------------------------------------------------
//Purpose:secondary fire
//------------------------------------------------------------
void CWeaponHealthGun::SecondaryAttack(void)
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
//drop the healthkit
#ifndef CLIENT_DLL
CBaseEntity *pHealth = CBaseEntity::Create( "item_healthkit", pPlayer->Weapon_ShootPosition(), pPlayer->GetAbsAngles(), pPlayer );
if(pHealth)
{
Vector vForward;
pPlayer->EyeVectors( &vForward, NULL, NULL );
pHealth->SetAbsVelocity(vForward * 100);
}
#endif
SendWeaponAnim( ACT_VM_SECONDARYATTACK );
// player "shoot" animation
pPlayer->SetAnimation( PLAYER_ATTACK1 );
// Decrease ammo
pPlayer->RemoveAmmo( 1, m_iSecondaryAmmoType );
// Can shoot again immediately
m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f;
// Can blow up after a short delay (so have time to release mouse button)
m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f;
}