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.

522 lines
14 KiB

9 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 "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "soundent.h"
#include "shake.h"
#include "gamerules.h"
#include "game.h"
#include "xsbeam.h"
9 years ago
#define XS_PRIMARY_CHARGE_VOLUME 256// how loud xen squasher is while charging
#define XS_PRIMARY_FIRE_VOLUME 450// how loud xen squasher is when discharged
9 years ago
enum xs_e
9 years ago
{
XS_IDLE = 0,
XS_IDLE2,
XS_FIDGET,
XS_SPINUP,
XS_SPIN,
XS_FIRE,
XS_FIRE2,
XS_HOLSTER,
XS_DRAW,
XS_RELOAD
9 years ago
};
LINK_ENTITY_TO_CLASS( weapon_xs, CXS )
9 years ago
float CXS::GetFullChargeTime( void )
9 years ago
{
#ifdef CLIENT_DLL
9 years ago
if( bIsMultiplayer() )
9 years ago
#else
9 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
#endif
{
return 1.5f;
9 years ago
}
return 4.0f;
9 years ago
}
void CXS::Spawn()
9 years ago
{
9 years ago
Precache();
m_iId = WEAPON_XS;
SET_MODEL( ENT( pev ), "models/w_xs.mdl" );
9 years ago
m_iDefaultAmmo = XS_DEFAULT_GIVE;
9 years ago
FallInit();// get ready to fall down.
pev->sequence = 0;
pev->animtime = gpGlobals->time;
pev->framerate = 1;
9 years ago
}
void CXS::Precache( void )
9 years ago
{
PRECACHE_MODEL( "models/w_xs.mdl" );
PRECACHE_MODEL( "models/v_xs.mdl" );
9 years ago
PRECACHE_MODEL( "models/p_gauss.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
PRECACHE_SOUND( "weapons/xs_shot.wav" );
PRECACHE_SOUND( "weapons/xs_moan1.wav" );
PRECACHE_SOUND( "weapons/xs_moan2.wav" );
PRECACHE_SOUND( "weapons/xs_moan3.wav" );
PRECACHE_SOUND( "weapons/xs_windup.wav" );
PRECACHE_SOUND( "weapons/xs_reload.wav" );
9 years ago
m_usXSSpin = PRECACHE_EVENT( 1, "events/xsspin.sc" );
9 years ago
UTIL_PrecacheOther( "xs_beam" );
9 years ago
}
int CXS::AddToPlayer( CBasePlayer *pPlayer )
9 years ago
{
9 years ago
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
9 years ago
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
int CXS::GetItemInfo( ItemInfo *p )
9 years ago
{
9 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "uranium";
p->iMaxAmmo1 = URANIUM_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = XS_MAX_CLIP;
9 years ago
p->iSlot = 3;
p->iPosition = 0;
p->iId = m_iId = WEAPON_XS;
9 years ago
p->iFlags = 0;
p->iWeight = XS_WEIGHT;
9 years ago
return 1;
}
BOOL CXS::IsUseable()
{
// Currently charging, allow the player to fire it first. - Solokiller
8 years ago
return CBasePlayerWeapon::IsUseable() || m_fInAttack != 0;
}
BOOL CXS::Deploy()
9 years ago
{
return DefaultDeploy( "models/v_xs.mdl", "models/p_gauss.mdl", XS_DRAW, "gauss" );
9 years ago
}
void CXS::Holster( int skiplocal /* = 0 */ )
9 years ago
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
SendWeaponAnim( XS_HOLSTER );
9 years ago
m_fInAttack = 0;
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM );
9 years ago
}
void CXS::PrimaryAttack()
9 years ago
{
// don't fire underwater
9 years ago
if( m_pPlayer->pev->waterlevel == 3 )
9 years ago
{
9 years ago
PlayEmptySound();
m_flNextSecondaryAttack = m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15f;
9 years ago
return;
}
if( m_iClip <= 0 )
9 years ago
{
9 years ago
PlayEmptySound();
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
return;
}
m_pPlayer->m_iWeaponVolume = XS_PRIMARY_FIRE_VOLUME;
9 years ago
m_fPrimaryFire = TRUE;
--m_iClip;
9 years ago
StartFire();
m_fInAttack = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.2f;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.4f;
9 years ago
}
void CXS::SecondaryAttack()
9 years ago
{
// don't fire underwater
9 years ago
if( m_pPlayer->pev->waterlevel == 3 )
9 years ago
{
9 years ago
if( m_fInAttack != 0 )
9 years ago
{
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_moan1.wav", 1.0, ATTN_NORM, 0, 80 + RANDOM_LONG( 0, 0x3f ) );
SendWeaponAnim( XS_IDLE );
9 years ago
m_fInAttack = 0;
}
else
{
9 years ago
PlayEmptySound();
9 years ago
}
m_flNextSecondaryAttack = m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
return;
}
9 years ago
if( m_fInAttack == 0 )
9 years ago
{
if( m_iClip <= 0 )
9 years ago
{
9 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/357_cock1.wav", 0.8, ATTN_NORM );
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
return;
}
m_fPrimaryFire = FALSE;
--m_iClip;// take one ammo just to start the spin
9 years ago
m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase();
// spin up
m_pPlayer->m_iWeaponVolume = XS_PRIMARY_CHARGE_VOLUME;
9 years ago
SendWeaponAnim( XS_SPINUP );
9 years ago
m_fInAttack = 1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
m_pPlayer->m_flStartCharge = gpGlobals->time;
m_pPlayer->m_flAmmoStartCharge = UTIL_WeaponTimeBase() + GetFullChargeTime();
PLAYBACK_EVENT_FULL( 0, m_pPlayer->edict(), m_usXSSpin, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 110, 0, 0, 0 );
9 years ago
m_iSoundState = SND_CHANGE_PITCH;
}
9 years ago
else if( m_fInAttack == 1 )
9 years ago
{
9 years ago
if( m_flTimeWeaponIdle < UTIL_WeaponTimeBase() )
9 years ago
{
SendWeaponAnim( XS_SPIN );
9 years ago
m_fInAttack = 2;
}
}
else
{
// Moved to before the ammo burn.
// Because we drained 1 when m_InAttack == 0, then 1 again now before checking if we're out of ammo,
// this resuled in the player having -1 ammo, which in turn caused CanDeploy to think it could be deployed.
// This will need to be fixed further down the line by preventing negative ammo unless explicitly required (infinite ammo?),
// But this check will prevent the problem for now. - Solokiller
// TODO: investigate further.
if( m_iClip <= 0 )
{
// out of ammo! force the gun to fire
StartFire();
m_fInAttack = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.2f;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1;
return;
}
9 years ago
// during the charging process, eat one bit of ammo every once in a while
9 years ago
if( UTIL_WeaponTimeBase() >= m_pPlayer->m_flNextAmmoBurn && m_pPlayer->m_flNextAmmoBurn != 1000 )
9 years ago
{
#ifdef CLIENT_DLL
9 years ago
if( bIsMultiplayer() )
9 years ago
#else
9 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
#endif
{
--m_iClip;
m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.1f;
9 years ago
}
else
{
--m_iClip;
m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.3f;
9 years ago
}
}
9 years ago
if( UTIL_WeaponTimeBase() >= m_pPlayer->m_flAmmoStartCharge )
9 years ago
{
// don't eat any more ammo after gun is fully charged.
m_pPlayer->m_flNextAmmoBurn = 1000;
}
int pitch = (int)( ( gpGlobals->time - m_pPlayer->m_flStartCharge ) * ( 150 / GetFullChargeTime() ) + 100 );
9 years ago
if( pitch > 250 )
9 years ago
pitch = 250;
// ALERT( at_console, "%d %d %d\n", m_fInAttack, m_iSoundState, pitch );
const bool overcharge = m_pPlayer->m_flStartCharge < gpGlobals->time - 10.0f;
9 years ago
if( m_iSoundState == 0 )
9 years ago
ALERT( at_console, "sound state %d\n", m_iSoundState );
#ifdef GAUSS_OVERCHARGE_FIX
if (!overcharge)
#endif
PLAYBACK_EVENT_FULL( 0, m_pPlayer->edict(), m_usXSSpin, 0.0f, g_vecZero, g_vecZero, 0.0f, 0.0f, pitch, 0, ( m_iSoundState == SND_CHANGE_PITCH ) ? 1 : 0, 0 );
9 years ago
m_iSoundState = SND_CHANGE_PITCH; // hack for going through level transitions
m_pPlayer->m_iWeaponVolume = XS_PRIMARY_CHARGE_VOLUME;
9 years ago
// m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1f;
if( overcharge )
9 years ago
{
// Player charged up too long. Zap him.
#ifdef GAUSS_OVERCHARGE_FIX
PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usGaussSpin, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, pitch, 0, 0, 1 );
#endif
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_moan1.wav", 1.0f, ATTN_NORM, 0, 80 + RANDOM_LONG( 0, 0x3f ) );
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/xs_moan3.wav", 1.0f, ATTN_NORM, 0, 75 + RANDOM_LONG( 0, 0x3f ) );
9 years ago
9 years ago
m_fInAttack = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.2f;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
9 years ago
#ifndef CLIENT_DLL
m_pPlayer->TakeDamage( VARS( eoNullEntity ), VARS( eoNullEntity ), 50, DMG_POISON );
UTIL_ScreenFade( m_pPlayer, Vector( 192, 224, 0 ), 2, 0.5f, 128, FFADE_IN );
9 years ago
#endif
SendWeaponAnim( XS_IDLE );
9 years ago
9 years ago
// Player may have been killed and this weapon dropped, don't execute any more code after this!
return;
}
}
}
//=========================================================
// StartFire- since all of this code has to run and then
// call Fire(), it was easier at this point to rip it out
// of weaponidle() and make its own function then to try to
// merge this into Fire(), which has some identical variable names
//=========================================================
void CXS::StartFire( void )
9 years ago
{
float flDamage;
9 years ago
9 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecAiming = gpGlobals->v_forward;
Vector vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 20 + gpGlobals->v_up * -6 + gpGlobals->v_right * 3;
9 years ago
if( gpGlobals->time - m_pPlayer->m_flStartCharge > GetFullChargeTime() )
9 years ago
{
flDamage = 200.0f;
9 years ago
}
else
{
flDamage = 200.0f * ( ( gpGlobals->time - m_pPlayer->m_flStartCharge ) / GetFullChargeTime() );
9 years ago
}
9 years ago
if( m_fPrimaryFire )
9 years ago
{
// fixed damage on primary attack
#ifdef CLIENT_DLL
flDamage = 20.0f;
9 years ago
#else
flDamage = gSkillData.plrDmgGauss;
#endif
}
9 years ago
if( m_fInAttack != 3 )
9 years ago
{
9 years ago
//ALERT( at_console, "Time:%f Damage:%f\n", gpGlobals->time - m_pPlayer->m_flStartCharge, flDamage );
9 years ago
#ifndef CLIENT_DLL
float flZVel = m_pPlayer->pev->velocity.z;
9 years ago
if( !m_fPrimaryFire )
9 years ago
{
m_pPlayer->pev->velocity = m_pPlayer->pev->velocity - gpGlobals->v_forward * flDamage * 5.0f;
9 years ago
}
9 years ago
if( !g_pGameRules->IsMultiplayer() )
9 years ago
{
// in deathmatch, xen squasher can pop you up into the air. Not in single play.
9 years ago
m_pPlayer->pev->velocity.z = flZVel;
}
#endif
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
}
// time until aftershock 'static discharge' sound
m_pPlayer->m_flPlayAftershock = gpGlobals->time + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.3f, 0.8f );
9 years ago
Fire( vecSrc, vecAiming, flDamage );
}
void CXS::Fire( Vector vecOrigSrc, Vector vecDir, float flDamage )
9 years ago
{
m_pPlayer->m_iWeaponVolume = XS_PRIMARY_FIRE_VOLUME;
CXSBeam *pXSBeam = CXSBeam::CXSBeamCreate( flDamage );
pXSBeam->pev->origin = vecOrigSrc;
pXSBeam->m_vecOldOrigin = vecOrigSrc;
pXSBeam->pev->angles = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle;
pXSBeam->pev->velocity = vecDir * 1250.0f;
pXSBeam->pev->owner = m_pPlayer->edict();
pXSBeam->Init();
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_shot.wav", flDamage * 0.0025f + 0.5f, ATTN_NORM, 0, 85 + RANDOM_LONG( 0, 16 ) );
9 years ago
// This reliable event is used to stop the spinning sound
// It's delayed by a fraction of second to make sure it is delayed by 1 frame on the client
// It's sent reliably anyway, which could lead to other delays
PLAYBACK_EVENT_FULL( FEV_RELIABLE, m_pPlayer->edict(), m_usXSSpin, 0.01f, m_pPlayer->pev->origin, m_pPlayer->pev->angles, 0.0f, 0.0f, 0, 0, 0, 1 );
9 years ago
pev->effects |= EF_MUZZLEFLASH;
}
9 years ago
void CXS::Reload()
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == XS_MAX_CLIP )
return;
9 years ago
if( !m_fInAttack && DefaultReload( XS_MAX_CLIP, XS_RELOAD, 3.5f ) )
9 years ago
{
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_reload.wav", 0.8f, ATTN_NORM, 0, ATTN_NORM );
9 years ago
}
}
void CXS::WeaponIdle( void )
9 years ago
{
9 years ago
ResetEmptySound();
9 years ago
// play aftershock static discharge
9 years ago
if( m_pPlayer->m_flPlayAftershock && m_pPlayer->m_flPlayAftershock < gpGlobals->time )
9 years ago
{
9 years ago
switch( RANDOM_LONG( 0, 3 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_moan1.wav", RANDOM_FLOAT( 0.7, 0.8 ), ATTN_NORM );
9 years ago
break;
case 1:
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_moan2.wav", RANDOM_FLOAT( 0.7, 0.8 ), ATTN_NORM );
9 years ago
break;
case 2:
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/xs_moan3.wav", RANDOM_FLOAT( 0.7, 0.8 ), ATTN_NORM );
9 years ago
break;
case 3:
break; // no sound
9 years ago
}
m_pPlayer->m_flPlayAftershock = 0.0f;
9 years ago
}
9 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
9 years ago
if( m_fInAttack != 0 )
9 years ago
{
StartFire();
m_fInAttack = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.2f;
// Need to set m_flNextPrimaryAttack so the weapon gets a chance to complete its secondary fire animation. - Solokiller
if( m_iClip <= 0 )
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
}
else
{
int iAnim;
float flRand = RANDOM_FLOAT( 0.0f, 1.0f );
if( flRand <= 0.5f )
9 years ago
{
iAnim = XS_IDLE;
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
else if( flRand <= 0.75f )
9 years ago
{
iAnim = XS_IDLE2;
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
else
{
iAnim = XS_FIDGET;
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3;
}
SendWeaponAnim( iAnim );
}
}
class CXSAmmo : public CBasePlayerAmmo
9 years ago
{
void EXPORT FallThink()
{
pev->nextthink = gpGlobals->time + 0.1f;
if( pev->flags & FL_ONGROUND )
{
// clatter if we have an owner (i.e., dropped by someone)
// don't clatter if the gun is waiting to respawn (if it's waiting, it is invisible!)
if( !FNullEnt( pev->owner ) )
{
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "items/weapondrop1.wav", 1, ATTN_NORM, 0, 100 );
}
// lie flat
pev->angles.x = 0;
pev->angles.z = 0;
UTIL_SetOrigin( pev, pev->origin );// link into world.
SetThink( NULL );
}
}
9 years ago
void Spawn( void )
{
9 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_xencandy.mdl" );
9 years ago
CBasePlayerAmmo::Spawn();
SetThink( &CXSAmmo::FallThink );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
}
void Precache( void )
{
PRECACHE_MODEL( "models/w_xencandy.mdl" );
9 years ago
PRECACHE_SOUND( "items/9mmclip1.wav" );
PRECACHE_SOUND( "items/weapondrop1.wav" );
9 years ago
}
BOOL AddAmmo( CBaseEntity *pOther )
{
9 years ago
if( pOther->GiveAmmo( AMMO_URANIUMBOX_GIVE, "uranium", URANIUM_MAX_CARRY ) != -1 )
9 years ago
{
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
9 years ago
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( ammo_xencandy, CXSAmmo )
9 years ago
#endif