Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

357 lines
8.5 KiB

7 years ago
/***
*
* 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.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "weapons.h"
#include "monsters.h"
#include "player.h"
#include "gamerules.h"
8 years ago
enum python_e
{
7 years ago
PYTHON_IDLE1 = 0,
PYTHON_FIDGET,
PYTHON_FIRE1,
PYTHON_RELOAD,
PYTHON_HOLSTER,
PYTHON_DRAW,
PYTHON_IDLE2,
PYTHON_IDLE3
};
LINK_ENTITY_TO_CLASS( weapon_python, CPython )
LINK_ENTITY_TO_CLASS( weapon_357, CPython )
7 years ago
8 years ago
int CPython::GetItemInfo( ItemInfo *p )
7 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
7 years ago
p->pszAmmo1 = "357";
p->iMaxAmmo1 = _357_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = PYTHON_MAX_CLIP;
p->iFlags = 0;
p->iSlot = 1;
p->iPosition = 1;
p->iId = m_iId = WEAPON_PYTHON;
p->iWeight = PYTHON_WEIGHT;
p->weaponName = "357 Fullautomatic";
7 years ago
return 1;
}
int CPython::AddToPlayer( CBasePlayer *pPlayer )
{
8 years ago
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
7 years ago
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
8 years ago
void CPython::Spawn()
7 years ago
{
8 years ago
pev->classname = MAKE_STRING( "weapon_357" ); // hack to allow for old names
Precache();
7 years ago
m_iId = WEAPON_PYTHON;
8 years ago
SET_MODEL( ENT( pev ), "models/w_357.mdl" );
7 years ago
m_iDefaultAmmo = PYTHON_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CPython::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/v_357.mdl" );
PRECACHE_MODEL( "models/w_357.mdl" );
PRECACHE_MODEL( "models/p_357.mdl" );
7 years ago
8 years ago
PRECACHE_MODEL( "models/w_357ammobox.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
7 years ago
8 years ago
PRECACHE_SOUND( "weapons/357_reload1.wav" );
PRECACHE_SOUND( "weapons/357_cock1.wav" );
PRECACHE_SOUND( "weapons/357_shot1.wav" );
PRECACHE_SOUND( "weapons/357_shot2.wav" );
7 years ago
m_usFirePython = PRECACHE_EVENT( 1, "events/python.sc" );
}
8 years ago
BOOL CPython::Deploy()
7 years ago
{
#ifdef CLIENT_DLL
8 years ago
if( bIsMultiplayer() )
7 years ago
#else
8 years ago
if( g_pGameRules->IsMultiplayer() )
7 years ago
#endif
{
// enable laser sight geometry.
pev->body = 1;
}
else
{
pev->body = 0;
}
return DefaultDeploy( "models/v_357.mdl", "models/p_357.mdl", PYTHON_DRAW, "python", UseDecrement(), pev->body );
}
void CPython::Holster( int skiplocal /* = 0 */ )
{
m_fInReload = FALSE;// cancel any reload in progress.
8 years ago
if( m_fInZoom )
7 years ago
{
SecondaryAttack();
}
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0;
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
7 years ago
SendWeaponAnim( PYTHON_HOLSTER );
}
void CPython::SecondaryAttack( void )
{
// don't fire under water
if( ( m_iClip <= 0 ) || ( m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD ) )
7 years ago
{
PlayEmptySound();
m_flNextSecondaryAttack = 0.15;
7 years ago
return;
}
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_iClip--;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
7 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecSrc = m_pPlayer->GetGunPosition();
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_4DEGREES, 8192, BULLET_PLAYER_357, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usFirePython, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
if( !m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
// HEV suit - indicate out of ammo condition
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
m_flNextSecondaryAttack = 0.2;
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
7 years ago
}
void CPython::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD)
{
8 years ago
PlayEmptySound();
7 years ago
m_flNextPrimaryAttack = 0.15;
return;
}
8 years ago
if( m_iClip <= 0 )
7 years ago
{
8 years ago
if( !m_fFireOnEmpty )
Reload();
7 years ago
else
{
PlayEmptySound();
7 years ago
m_flNextPrimaryAttack = 0.15;
}
return;
}
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_iClip--;
8 years ago
m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH;
7 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
8 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
7 years ago
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_1DEGREES, 8192, BULLET_PLAYER_357, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
int flags;
7 years ago
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usFirePython, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
8 years ago
if( !m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
7 years ago
// HEV suit - indicate out of ammo condition
8 years ago
m_pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
7 years ago
m_flNextPrimaryAttack = 0.75;
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
7 years ago
}
void CPython::Reload( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == PYTHON_MAX_CLIP )
7 years ago
return;
8 years ago
if( m_pPlayer->pev->fov != 0 )
7 years ago
{
m_fInZoom = FALSE;
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
}
int bUseScope = FALSE;
#ifdef CLIENT_DLL
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
if( DefaultReload( PYTHON_MAX_CLIP, PYTHON_RELOAD, 2.0, bUseScope ) )
7 years ago
{
m_flSoundDelay = 1.5;
}
}
void CPython::WeaponIdle( void )
{
8 years ago
ResetEmptySound();
7 years ago
m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
// ALERT( at_console, "%.2f\n", gpGlobals->time - m_flSoundDelay );
8 years ago
if( m_flSoundDelay != 0 && m_flSoundDelay <= UTIL_WeaponTimeBase() )
7 years ago
{
8 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/357_reload1.wav", RANDOM_FLOAT( 0.8, 0.9 ), ATTN_NORM );
7 years ago
m_flSoundDelay = 0;
}
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
7 years ago
return;
int iAnim;
9 years ago
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0f, 1.0f );
8 years ago
if( flRand <= 0.5 )
7 years ago
{
iAnim = PYTHON_IDLE1;
8 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 70.0 / 30.0 );
7 years ago
}
8 years ago
else if( flRand <= 0.7 )
7 years ago
{
iAnim = PYTHON_IDLE2;
8 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 60.0 / 30.0 );
7 years ago
}
8 years ago
else if( flRand <= 0.9 )
7 years ago
{
iAnim = PYTHON_IDLE3;
8 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 88.0 / 30.0 );
7 years ago
}
else
{
iAnim = PYTHON_FIDGET;
8 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 170.0 / 30.0 );
7 years ago
}
int bUseScope = FALSE;
#ifdef CLIENT_DLL
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
SendWeaponAnim( iAnim, UseDecrement() ? 1 : 0, bUseScope );
}
class CPythonAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT(pev), "models/w_357ammobox.mdl" );
CBasePlayerAmmo::Spawn();
7 years ago
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_357ammobox.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
7 years ago
}
8 years ago
BOOL AddAmmo( CBaseEntity *pOther )
7 years ago
{
8 years ago
if( pOther->GiveAmmo( AMMO_357BOX_GIVE, "357", _357_MAX_CARRY ) != -1 )
7 years ago
{
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
7 years ago
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( ammo_357, CPythonAmmo )
class CPythonAmmo2 : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache();
SET_MODEL( ENT( pev ), "models/w_357ammo.mdl" );
CBasePlayerAmmo::Spawn();
}
void Precache( void )
{
PRECACHE_MODEL( "models/w_357ammo.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
}
BOOL AddAmmo( CBaseEntity *pOther )
{
if( pOther->GiveAmmo( AMMO_357BOX_GIVE, "357", _357_MAX_CARRY ) != -1 )
{
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( ammo_357speed, CPythonAmmo2 )
7 years ago
#endif