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

310 lines
7.0 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:17:22 +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 "weapons.h"
#include "monsters.h"
#include "player.h"
#include "gamerules.h"
2016-07-31 15:48:50 +02:00
enum python_e
{
2016-06-04 15:24:23 +02:00
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 )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
int CPython::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 = "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;
return 1;
}
int CPython::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;
}
2016-07-31 15:48:50 +02:00
void CPython::Spawn()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->classname = MAKE_STRING( "weapon_357" ); // hack to allow for old names
Precache();
2016-06-04 15:24:23 +02:00
m_iId = WEAPON_PYTHON;
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/w_357.mdl" );
2016-06-04 15:24:23 +02:00
m_iDefaultAmmo = PYTHON_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CPython::Precache( void )
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/v_357.mdl" );
PRECACHE_MODEL( "models/w_357.mdl" );
PRECACHE_MODEL( "models/p_357.mdl" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/w_357ammobox.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
PRECACHE_SOUND( "weapons/357_reload1.wav" );
PRECACHE_SOUND( "weapons/357_cock1.wav" );
PRECACHE_SOUND( "weapons/357_shot1.wav" );
PRECACHE_SOUND( "weapons/357_shot2.wav" );
2016-06-04 15:24:23 +02:00
m_usFirePython = PRECACHE_EVENT( 1, "events/python.sc" );
}
2016-07-31 15:48:50 +02:00
BOOL CPython::Deploy()
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( bIsMultiplayer() )
2016-06-04 15:24:23 +02:00
#else
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
#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.
2016-07-31 15:48:50 +02:00
if( m_fInZoom )
2016-06-04 15:24:23 +02:00
{
SecondaryAttack();
}
2019-10-13 13:49:25 +02:00
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10.0f, 15.0f );
2016-06-04 15:24:23 +02:00
SendWeaponAnim( PYTHON_HOLSTER );
}
void CPython::SecondaryAttack( void )
{
2021-06-07 02:05:58 +02:00
#if CLIENT_DLL
2016-07-31 15:48:50 +02:00
if( !bIsMultiplayer() )
2016-06-04 15:24:23 +02:00
#else
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
#endif
{
return;
}
2016-07-31 15:48:50 +02:00
if( m_pPlayer->pev->fov != 0 )
2016-06-04 15:24:23 +02:00
{
m_fInZoom = FALSE;
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
}
2016-07-31 15:48:50 +02:00
else if( m_pPlayer->pev->fov != 40 )
2016-06-04 15:24:23 +02:00
{
m_fInZoom = TRUE;
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 40;
}
2019-10-13 13:49:25 +02:00
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5f;
2016-06-04 15:24:23 +02:00
}
void CPython::PrimaryAttack()
{
// don't fire underwater
2016-07-31 15:48:50 +02:00
if( m_pPlayer->pev->waterlevel == 3 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PlayEmptySound();
2019-10-13 13:49:25 +02:00
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15f;
2016-06-04 15:24:23 +02:00
return;
}
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
if( !m_fFireOnEmpty )
Reload();
2016-06-04 15:24:23 +02:00
else
{
PlayEmptySound();
2019-10-13 13:49:25 +02:00
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15f;
2016-06-04 15:24:23 +02:00
}
return;
}
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_iClip--;
2016-07-31 15:48:50 +02:00
m_pPlayer->pev->effects = (int)( m_pPlayer->pev->effects ) | EF_MUZZLEFLASH;
2016-06-04 15:24:23 +02:00
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
2016-07-31 15:48:50 +02:00
Vector vecSrc = m_pPlayer->GetGunPosition();
2016-06-04 15:24:23 +02:00
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;
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_usFirePython, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
2016-06-04 15:24:23 +02:00
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 = 0.75f;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10.0f, 15.0f );
2016-06-04 15:24:23 +02:00
}
void CPython::Reload( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == PYTHON_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
{
m_fInZoom = FALSE;
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
}
int bUseScope = FALSE;
2021-06-07 02:05:58 +02:00
#if CLIENT_DLL
2016-06-04 15:24:23 +02:00
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
2019-10-13 13:49:25 +02:00
if( DefaultReload( PYTHON_MAX_CLIP, PYTHON_RELOAD, 2.0f, bUseScope ) )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
m_flSoundDelay = 1.5f;
2016-06-04 15:24:23 +02:00
}
}
void CPython::WeaponIdle( void )
{
2016-07-31 15:48:50 +02:00
ResetEmptySound();
2016-06-04 15:24:23 +02:00
m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
// ALERT( at_console, "%.2f\n", gpGlobals->time - m_flSoundDelay );
2016-07-31 15:48:50 +02:00
if( m_flSoundDelay != 0 && m_flSoundDelay <= UTIL_WeaponTimeBase() )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/357_reload1.wav", RANDOM_FLOAT( 0.8f, 0.9f ), ATTN_NORM );
m_flSoundDelay = 0.0f;
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
return;
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0f, 1.0f );
2019-10-13 13:49:25 +02:00
if( flRand <= 0.5f )
2016-06-04 15:24:23 +02:00
{
iAnim = PYTHON_IDLE1;
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 70.0f / 30.0f );
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
else if( flRand <= 0.7f )
2016-06-04 15:24:23 +02:00
{
iAnim = PYTHON_IDLE2;
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 60.0f / 30.0f );
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
else if( flRand <= 0.9f )
2016-06-04 15:24:23 +02:00
{
iAnim = PYTHON_IDLE3;
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 88.0f / 30.0f );
2016-06-04 15:24:23 +02:00
}
else
{
iAnim = PYTHON_FIDGET;
2019-10-13 13:49:25 +02:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + ( 170.0f / 30.0f );
2016-06-04 15:24:23 +02:00
}
int bUseScope = FALSE;
2021-06-07 02:05:58 +02:00
#if CLIENT_DLL
2016-06-04 15:24:23 +02:00
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
SendWeaponAnim( iAnim, UseDecrement() ? 1 : 0, bUseScope );
}
class CPythonAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
2016-07-31 15:48:50 +02:00
Precache();
SET_MODEL( ENT(pev), "models/w_357ammobox.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_357ammobox.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_357BOX_GIVE, "357", _357_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;
}
};
LINK_ENTITY_TO_CLASS( ammo_357, CPythonAmmo )
#endif