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.

570 lines
13 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 "player.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "effects.h"
#include "customentity.h"
#include "gamerules.h"
#define EGON_PRIMARY_VOLUME 450
#define EGON_BEAM_SPRITE "sprites/xbeam1.spr"
#define EGON_FLARE_SPRITE "sprites/XSpark1.spr"
#define EGON_SOUND_OFF "weapons/egon_off1.wav"
#define EGON_SOUND_RUN "weapons/egon_run3.wav"
#define EGON_SOUND_STARTUP "weapons/egon_windup2.wav"
#define EGON_SWITCH_NARROW_TIME 0.75f // Time it takes to switch fire modes
#define EGON_SWITCH_WIDE_TIME 1.5f
9 years ago
enum egon_e {
EGON_IDLE1 = 0,
EGON_FIDGET1,
EGON_ALTFIREON,
EGON_ALTFIRECYCLE,
EGON_ALTFIREOFF,
EGON_FIRE1,
EGON_FIRE2,
EGON_FIRE3,
EGON_FIRE4,
EGON_DRAW,
EGON_HOLSTER
};
LINK_ENTITY_TO_CLASS( weapon_egon, CEgon )
9 years ago
int CEgon::g_fireAnims1[] = { EGON_FIRE1, EGON_FIRE2, EGON_FIRE3, EGON_FIRE4 };
int CEgon::g_fireAnims2[] = { EGON_ALTFIRECYCLE };
8 years ago
void CEgon::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
m_iId = WEAPON_EGON;
8 years ago
SET_MODEL( ENT( pev ), "models/w_egon.mdl" );
9 years ago
m_iDefaultAmmo = EGON_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CEgon::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_egon.mdl" );
PRECACHE_MODEL( "models/v_egon.mdl" );
PRECACHE_MODEL( "models/p_egon.mdl" );
9 years ago
8 years ago
PRECACHE_MODEL( "models/w_9mmclip.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
PRECACHE_SOUND( EGON_SOUND_OFF );
PRECACHE_SOUND( EGON_SOUND_RUN );
PRECACHE_SOUND( EGON_SOUND_STARTUP );
PRECACHE_MODEL( EGON_BEAM_SPRITE );
PRECACHE_MODEL( EGON_FLARE_SPRITE );
8 years ago
PRECACHE_SOUND( "weapons/357_cock1.wav" );
9 years ago
}
BOOL CEgon::Deploy( void )
{
m_deployed = FALSE;
// m_fireState = FIRE_OFF;
9 years ago
return DefaultDeploy( "models/v_egon.mdl", "models/p_egon.mdl", EGON_DRAW, "egon" );
}
int CEgon::AddToPlayer( CBasePlayer *pPlayer )
{
8 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;
}
void CEgon::Holster( int skiplocal /* = 0 */ )
{
DefaultHolster( EGON_HOLSTER, 0.7f );
8 years ago
EndAttack();
9 years ago
}
8 years ago
int CEgon::GetItemInfo( ItemInfo *p )
9 years ago
{
8 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 = WEAPON_NOCLIP;
p->iSlot = 3;
p->iPosition = 2;
p->iId = m_iId = WEAPON_EGON;
p->iFlags = 0;
p->iWeight = EGON_WEIGHT;
return 1;
}
8 years ago
#define EGON_PULSE_INTERVAL 0.1
9 years ago
#define EGON_DISCHARGE_INTERVAL 0.1
float CEgon::GetPulseInterval( void )
{
return EGON_PULSE_INTERVAL;
}
float CEgon::GetDischargeInterval( void )
{
return EGON_DISCHARGE_INTERVAL;
}
BOOL CEgon::HasAmmo( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
9 years ago
return FALSE;
return TRUE;
}
void CEgon::UseAmmo( int count )
{
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= count )
9 years ago
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= count;
else
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] = 0;
}
void CEgon::Attack( void )
{
// don't fire underwater
8 years ago
if( m_pPlayer->pev->waterlevel == 3 )
9 years ago
{
if( m_pBeam )
9 years ago
{
EndAttack();
}
else
{
8 years ago
PlayEmptySound();
9 years ago
}
return;
}
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecAiming = gpGlobals->v_forward;
8 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
9 years ago
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
switch( m_fireState )
{
case FIRE_OFF:
{
8 years ago
if( !HasAmmo() )
9 years ago
{
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.25f;
9 years ago
PlayEmptySound( );
return;
}
m_flAmmoUseTime = gpGlobals->time;// start using ammo ASAP.
SendWeaponAnim( g_fireAnims1[ RANDOM_LONG( 0, ARRAYSIZE( g_fireAnims1 ) - 1 ) ] );
9 years ago
m_shakeTime = 0;
m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1f;
m_shootTime = gpGlobals->time + 2.0f;
if( m_fireMode == FIRE_WIDE )
{
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, EGON_SOUND_STARTUP, 0.98f, ATTN_NORM, 0, 125 );
}
else
{
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, EGON_SOUND_STARTUP, 0.9f, ATTN_NORM, 0, 100 );
}
9 years ago
pev->dmgtime = gpGlobals->time + GetPulseInterval();
m_fireState = FIRE_CHARGE;
8 years ago
break;
9 years ago
}
case FIRE_CHARGE:
{
Fire( vecSrc, vecAiming );
m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME;
8 years ago
if( m_shootTime != 0 && gpGlobals->time > m_shootTime )
9 years ago
{
if( m_fireMode == FIRE_WIDE )
{
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_STATIC, EGON_SOUND_RUN, 0.98f, ATTN_NORM, 0, 125 );
}
else
{
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_STATIC, EGON_SOUND_RUN, 0.9f, ATTN_NORM, 0, 100 );
}
m_shootTime = 0;
9 years ago
}
8 years ago
if( !HasAmmo() )
9 years ago
{
EndAttack();
m_fireState = FIRE_OFF;
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f;
9 years ago
}
8 years ago
break;
9 years ago
}
}
}
void CEgon::PrimaryAttack( void )
{
if( m_pPlayer->m_bIsHolster )
{
WeaponIdle();
return;
}
9 years ago
m_fireMode = FIRE_WIDE;
Attack();
}
void CEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
{
Vector vecDest = vecOrigSrc + vecDir * 2048.0f;
8 years ago
edict_t *pentIgnore;
9 years ago
TraceResult tr;
pentIgnore = m_pPlayer->edict();
Vector tmpSrc = vecOrigSrc + gpGlobals->v_up * -8.0f + gpGlobals->v_right * 3.0f;
9 years ago
// ALERT( at_console, "." );
UTIL_TraceLine( vecOrigSrc, vecDest, dont_ignore_monsters, pentIgnore, &tr );
8 years ago
if( tr.fAllSolid )
9 years ago
return;
#ifndef CLIENT_DLL
8 years ago
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
9 years ago
8 years ago
if( pEntity == NULL )
9 years ago
return;
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
8 years ago
if( m_pSprite && pEntity->pev->takedamage )
9 years ago
{
m_pSprite->pev->effects &= ~EF_NODRAW;
}
8 years ago
else if( m_pSprite )
9 years ago
{
m_pSprite->pev->effects |= EF_NODRAW;
}
}
#endif
float timedist = 0.0f;
9 years ago
8 years ago
switch( m_fireMode )
9 years ago
{
case FIRE_NARROW:
#ifndef CLIENT_DLL
8 years ago
if( pev->dmgtime < gpGlobals->time )
9 years ago
{
// Narrow mode only does damage to the entity it hits
ClearMultiDamage();
8 years ago
if( pEntity->pev->takedamage )
9 years ago
{
pEntity->TraceAttack( m_pPlayer->pev, gSkillData.plrDmgEgonNarrow, vecDir, &tr, DMG_ENERGYBEAM );
}
8 years ago
ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );
9 years ago
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
// multiplayer uses 1 ammo every 1/10th second
8 years ago
if( gpGlobals->time >= m_flAmmoUseTime )
9 years ago
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->time + 0.1f;
9 years ago
}
}
else
{
// single player, use 3 ammo/second
8 years ago
if( gpGlobals->time >= m_flAmmoUseTime )
9 years ago
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->time + 0.166f;
9 years ago
}
}
pev->dmgtime = gpGlobals->time + GetPulseInterval();
}
#endif
timedist = ( pev->dmgtime - gpGlobals->time ) / GetPulseInterval();
break;
case FIRE_WIDE:
#ifndef CLIENT_DLL
8 years ago
if( pev->dmgtime < gpGlobals->time )
9 years ago
{
// wide mode does damage to the ent, and radius damage
ClearMultiDamage();
8 years ago
if( pEntity->pev->takedamage )
9 years ago
{
8 years ago
pEntity->TraceAttack( m_pPlayer->pev, gSkillData.plrDmgEgonWide, vecDir, &tr, DMG_ENERGYBEAM | DMG_ALWAYSGIB );
9 years ago
}
8 years ago
ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );
9 years ago
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
// radius damage a little more potent in multiplayer.
::RadiusDamage( tr.vecEndPos, pev, m_pPlayer->pev, gSkillData.plrDmgEgonWide * 0.25f, 128, CLASS_NONE, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB );
9 years ago
}
8 years ago
if( !m_pPlayer->IsAlive() )
9 years ago
return;
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
//multiplayer uses 5 ammo/second
8 years ago
if( gpGlobals->time >= m_flAmmoUseTime )
9 years ago
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->time + 0.2f;
9 years ago
}
}
else
{
// Wide mode uses 10 charges per second in single player
8 years ago
if( gpGlobals->time >= m_flAmmoUseTime )
9 years ago
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->time + 0.1f;
9 years ago
}
}
pev->dmgtime = gpGlobals->time + GetDischargeInterval();
8 years ago
if( m_shakeTime < gpGlobals->time )
9 years ago
{
UTIL_ScreenShake( tr.vecEndPos, 5.0f, 150.0f, 0.75f, 250.0f );
m_shakeTime = gpGlobals->time + 1.5f;
9 years ago
}
}
#endif
timedist = ( pev->dmgtime - gpGlobals->time ) / GetDischargeInterval();
break;
}
8 years ago
if( timedist < 0 )
9 years ago
timedist = 0;
8 years ago
else if( timedist > 1 )
9 years ago
timedist = 1;
8 years ago
timedist = 1 - timedist;
9 years ago
UpdateEffect( tmpSrc, tr.vecEndPos, timedist );
}
void CEgon::UpdateEffect( const Vector &startPoint, const Vector &endPoint, float timeBlend )
{
#ifndef CLIENT_DLL
8 years ago
if( !m_pBeam )
9 years ago
{
CreateEffect();
}
m_pBeam->SetStartPos( endPoint );
m_pBeam->SetBrightness( (int)( 255 - ( timeBlend * 180 )) );
m_pBeam->SetWidth( (int)( 40 - ( timeBlend * 20 ) ) );
9 years ago
8 years ago
if( m_fireMode == FIRE_WIDE )
m_pBeam->SetColor( (int)( 30 + ( 25 * timeBlend ) ), (int)( 30 + ( 30 * timeBlend ) ), (int)( 64 + 80 * fabs( sin( gpGlobals->time * 10.0f ) ) ) );
9 years ago
else
m_pBeam->SetColor( (int)( 60 + ( 25 * timeBlend ) ), (int)( 120 + ( 30 * timeBlend ) ), (int)( 64 + 80 * fabs( sin( gpGlobals->time * 10.0f ) ) ) );
9 years ago
UTIL_SetOrigin( m_pSprite->pev, endPoint );
m_pSprite->pev->frame += 8.0f * gpGlobals->frametime;
8 years ago
if( m_pSprite->pev->frame > m_pSprite->Frames() )
9 years ago
m_pSprite->pev->frame = 0;
m_pNoise->SetStartPos( endPoint );
#endif
}
void CEgon::CreateEffect( void )
{
#ifndef CLIENT_DLL
DestroyEffect();
m_pBeam = CBeam::BeamCreate( EGON_BEAM_SPRITE, 40 );
m_pBeam->PointEntInit( pev->origin, m_pPlayer->entindex() );
m_pBeam->SetFlags( BEAM_FSINE );
m_pBeam->SetEndAttachment( 1 );
m_pBeam->pev->spawnflags |= SF_BEAM_TEMPORARY; // Flag these to be destroyed on save/restore or level transition
// m_pBeam->pev->flags |= FL_SKIPLOCALHOST;
// m_pBeam->pev->owner = m_pPlayer->edict();
9 years ago
m_pNoise = CBeam::BeamCreate( EGON_BEAM_SPRITE, 55 );
m_pNoise->PointEntInit( pev->origin, m_pPlayer->entindex() );
m_pNoise->SetScrollRate( 25 );
m_pNoise->SetBrightness( 100 );
m_pNoise->SetEndAttachment( 1 );
m_pNoise->pev->spawnflags |= SF_BEAM_TEMPORARY;
// m_pNoise->pev->flags |= FL_SKIPLOCALHOST;
// m_pNoise->pev->owner = m_pPlayer->edict();
9 years ago
m_pSprite = CSprite::SpriteCreate( EGON_FLARE_SPRITE, pev->origin, FALSE );
m_pSprite->pev->scale = 1.0;
m_pSprite->SetTransparency( kRenderGlow, 255, 255, 255, 255, kRenderFxNoDissipation );
m_pSprite->pev->spawnflags |= SF_SPRITE_TEMPORARY;
// m_pSprite->pev->flags |= FL_SKIPLOCALHOST;
// m_pSprite->pev->owner = m_pPlayer->edict();
9 years ago
8 years ago
if( m_fireMode == FIRE_WIDE )
9 years ago
{
m_pBeam->SetScrollRate( 50 );
m_pBeam->SetNoise( 20 );
m_pNoise->SetColor( 50, 50, 255 );
m_pNoise->SetNoise( 8 );
}
else
{
m_pBeam->SetScrollRate( 110 );
m_pBeam->SetNoise( 5 );
m_pNoise->SetColor( 80, 120, 255 );
m_pNoise->SetNoise( 2 );
}
#endif
}
void CEgon::DestroyEffect( void )
{
#ifndef CLIENT_DLL
8 years ago
if( m_pBeam )
9 years ago
{
UTIL_Remove( m_pBeam );
m_pBeam = NULL;
}
8 years ago
if( m_pNoise )
9 years ago
{
UTIL_Remove( m_pNoise );
m_pNoise = NULL;
}
8 years ago
if( m_pSprite )
9 years ago
{
8 years ago
if( m_fireMode == FIRE_WIDE )
9 years ago
m_pSprite->Expand( 10, 500 );
else
UTIL_Remove( m_pSprite );
m_pSprite = NULL;
}
#endif
}
void CEgon::WeaponIdle( void )
{
if( m_pPlayer->m_bIsHolster )
{
if( m_flTimeWeaponIdle <= UTIL_WeaponTimeBase() )
{
m_pPlayer->m_bIsHolster = FALSE;
Deploy();
}
return;
}
8 years ago
ResetEmptySound();
9 years ago
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
8 years ago
if( m_fireState != FIRE_OFF )
9 years ago
EndAttack();
8 years ago
9 years ago
int iAnim;
float flRand = RANDOM_FLOAT( 0.0f, 1.0f );
9 years ago
if( flRand <= 0.5f )
9 years ago
{
iAnim = EGON_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10.0f, 15.0f );
9 years ago
}
else
{
iAnim = EGON_FIDGET1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3.0f;
9 years ago
}
SendWeaponAnim( iAnim );
m_deployed = TRUE;
}
void CEgon::EndAttack( void )
{
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
STOP_SOUND( ENT( m_pPlayer->pev ), CHAN_STATIC, EGON_SOUND_RUN );
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, EGON_SOUND_OFF, 0.98, ATTN_NORM, 0, 100 );
9 years ago
m_fireState = FIRE_OFF;
DestroyEffect();
}
class CEgonAmmo : public CBasePlayerAmmo
{
void Spawn( void )
{
8 years ago
Precache();
SET_MODEL( ENT( pev ), "models/w_chainammo.mdl" );
CBasePlayerAmmo::Spawn();
9 years ago
}
8 years ago
9 years ago
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_chainammo.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
}
8 years ago
BOOL AddAmmo( CBaseEntity *pOther )
{
if( pOther->GiveAmmo( AMMO_URANIUMBOX_GIVE, "uranium", URANIUM_MAX_CARRY ) != -1 )
9 years ago
{
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
9 years ago
return TRUE;
}
return FALSE;
}
};
8 years ago
LINK_ENTITY_TO_CLASS( ammo_egonclip, CEgonAmmo )
#endif