halflife-thewastes-sdk/dlls/python.cpp

320 lines
7.1 KiB
C++
Raw Normal View History

1999-04-07 00:00:00 +00:00
/***
*
2001-11-08 00:00:00 +00:00
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
1999-04-07 00:00:00 +00:00
*
* 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"
enum python_e {
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 );
int CPython::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
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 )
{
if ( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
void CPython::Spawn( )
{
pev->classname = MAKE_STRING("weapon_357"); // hack to allow for old names
Precache( );
m_iId = WEAPON_PYTHON;
SET_MODEL(ENT(pev), "models/w_357.mdl");
m_iDefaultAmmo = PYTHON_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CPython::Precache( void )
{
PRECACHE_MODEL("models/v_357.mdl");
PRECACHE_MODEL("models/w_357.mdl");
PRECACHE_MODEL("models/p_357.mdl");
PRECACHE_MODEL("models/w_357ammobox.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND ("weapons/357_reload1.wav");
PRECACHE_SOUND ("weapons/357_cock1.wav");
PRECACHE_SOUND ("weapons/357_shot1.wav");
PRECACHE_SOUND ("weapons/357_shot2.wav");
2000-06-05 00:00:00 +00:00
m_usFirePython = PRECACHE_EVENT( 1, "events/python.sc" );
1999-04-07 00:00:00 +00:00
}
BOOL CPython::Deploy( )
{
2001-08-29 00:00:00 +00:00
#ifdef CLIENT_DLL
if ( bIsMultiplayer() )
#else
1999-04-07 00:00:00 +00:00
if ( g_pGameRules->IsMultiplayer() )
2001-08-29 00:00:00 +00:00
#endif
1999-04-07 00:00:00 +00:00
{
// enable laser sight geometry.
pev->body = 1;
}
else
{
pev->body = 0;
}
2001-11-08 00:00:00 +00:00
return DefaultDeploy( "models/v_357.mdl", "models/p_357.mdl", PYTHON_DRAW, "python", UseDecrement(), pev->body );
1999-04-07 00:00:00 +00:00
}
2000-06-05 00:00:00 +00:00
void CPython::Holster( int skiplocal /* = 0 */ )
1999-04-07 00:00:00 +00:00
{
m_fInReload = FALSE;// cancel any reload in progress.
if ( m_fInZoom )
{
SecondaryAttack();
}
2000-06-05 00:00:00 +00:00
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0;
2001-08-29 00:00:00 +00:00
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
1999-04-07 00:00:00 +00:00
SendWeaponAnim( PYTHON_HOLSTER );
}
void CPython::SecondaryAttack( void )
{
2001-08-29 00:00:00 +00:00
#ifdef CLIENT_DLL
if ( !bIsMultiplayer() )
#else
1999-04-07 00:00:00 +00:00
if ( !g_pGameRules->IsMultiplayer() )
2001-08-29 00:00:00 +00:00
#endif
1999-04-07 00:00:00 +00:00
{
return;
}
2001-08-29 00:00:00 +00:00
if ( m_pPlayer->pev->fov != 0 )
1999-04-07 00:00:00 +00:00
{
m_fInZoom = FALSE;
2001-08-29 00:00:00 +00:00
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
1999-04-07 00:00:00 +00:00
}
2001-08-29 00:00:00 +00:00
else if ( m_pPlayer->pev->fov != 40 )
1999-04-07 00:00:00 +00:00
{
m_fInZoom = TRUE;
2001-08-29 00:00:00 +00:00
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 40;
1999-04-07 00:00:00 +00:00
}
2001-08-29 00:00:00 +00:00
m_flNextSecondaryAttack = 0.5;
1999-04-07 00:00:00 +00:00
}
void CPython::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound( );
2001-08-29 00:00:00 +00:00
m_flNextPrimaryAttack = 0.15;
1999-04-07 00:00:00 +00:00
return;
}
if (m_iClip <= 0)
{
if (!m_fFireOnEmpty)
Reload( );
else
{
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/357_cock1.wav", 0.8, ATTN_NORM);
2001-08-29 00:00:00 +00:00
m_flNextPrimaryAttack = 0.15;
1999-04-07 00:00:00 +00:00
}
return;
}
2000-06-05 00:00:00 +00:00
1999-04-07 00:00:00 +00:00
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_iClip--;
2001-08-29 00:00:00 +00:00
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
2000-06-05 00:00:00 +00:00
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
1999-04-07 00:00:00 +00:00
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
2001-08-29 00:00:00 +00:00
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;
#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 );
1999-04-07 00:00:00 +00:00
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
// HEV suit - indicate out of ammo condition
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
2001-08-29 00:00:00 +00:00
m_flNextPrimaryAttack = 0.75;
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
1999-04-07 00:00:00 +00:00
}
void CPython::Reload( void )
{
2001-08-29 00:00:00 +00:00
if ( m_pPlayer->ammo_357 <= 0 )
return;
if ( m_pPlayer->pev->fov != 0 )
1999-04-07 00:00:00 +00:00
{
m_fInZoom = FALSE;
2001-08-29 00:00:00 +00:00
m_pPlayer->pev->fov = m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
1999-04-07 00:00:00 +00:00
}
2001-11-08 00:00:00 +00:00
int bUseScope = FALSE;
#ifdef CLIENT_DLL
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
if (DefaultReload( 6, PYTHON_RELOAD, 2.0, bUseScope ))
1999-04-07 00:00:00 +00:00
{
2001-08-29 00:00:00 +00:00
m_flSoundDelay = 1.5;
1999-04-07 00:00:00 +00:00
}
}
void CPython::WeaponIdle( void )
{
ResetEmptySound( );
m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
// ALERT( at_console, "%.2f\n", gpGlobals->time - m_flSoundDelay );
2001-08-29 00:00:00 +00:00
if (m_flSoundDelay != 0 && m_flSoundDelay <= UTIL_WeaponTimeBase() )
1999-04-07 00:00:00 +00:00
{
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/357_reload1.wav", RANDOM_FLOAT(0.8, 0.9), ATTN_NORM);
m_flSoundDelay = 0;
}
2001-08-29 00:00:00 +00:00
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
1999-04-07 00:00:00 +00:00
return;
int iAnim;
2001-08-29 00:00:00 +00:00
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
1999-04-07 00:00:00 +00:00
if (flRand <= 0.5)
{
iAnim = PYTHON_IDLE1;
2001-08-29 00:00:00 +00:00
m_flTimeWeaponIdle = (70.0/30.0);
1999-04-07 00:00:00 +00:00
}
else if (flRand <= 0.7)
{
iAnim = PYTHON_IDLE2;
2001-08-29 00:00:00 +00:00
m_flTimeWeaponIdle = (60.0/30.0);
1999-04-07 00:00:00 +00:00
}
else if (flRand <= 0.9)
{
iAnim = PYTHON_IDLE3;
2001-08-29 00:00:00 +00:00
m_flTimeWeaponIdle = (88.0/30.0);
1999-04-07 00:00:00 +00:00
}
else
{
iAnim = PYTHON_FIDGET;
2001-08-29 00:00:00 +00:00
m_flTimeWeaponIdle = (170.0/30.0);
1999-04-07 00:00:00 +00:00
}
2001-11-08 00:00:00 +00:00
int bUseScope = FALSE;
#ifdef CLIENT_DLL
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
SendWeaponAnim( iAnim, UseDecrement() ? 1 : 0, bUseScope );
1999-04-07 00:00:00 +00:00
}
class CPythonAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), "models/w_357ammobox.mdl");
CBasePlayerAmmo::Spawn( );
}
void Precache( void )
{
PRECACHE_MODEL ("models/w_357ammobox.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_357, CPythonAmmo );
#endif