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.
|
|
|
|
*
|
|
|
|
****/
|
2016-06-25 18:33:39 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
#include "extdll.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "monsters.h"
|
|
|
|
#include "customentity.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
#include "decals.h"
|
|
|
|
#include "func_break.h"
|
|
|
|
#include "shake.h"
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
#define SF_GIBSHOOTER_REPEATABLE 1 // allows a gibshooter to be refired
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
#define SF_FUNNEL_REVERSE 1 // funnel effect repels particles instead of attracting them.
|
|
|
|
|
|
|
|
// Lightning target, just alias landmark
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( info_target, CPointEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
class CBubbling : public CBaseEntity
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
|
|
|
|
|
|
|
void EXPORT FizzThink( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
|
|
|
|
virtual int Save( CSave &save );
|
|
|
|
virtual int Restore( CRestore &restore );
|
|
|
|
virtual int ObjectCaps( void ) { return CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
|
|
|
|
|
|
|
int m_density;
|
|
|
|
int m_frequency;
|
|
|
|
int m_bubbleModel;
|
|
|
|
int m_state;
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_bubbles, CBubbling )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
TYPEDESCRIPTION CBubbling::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
DEFINE_FIELD( CBubbling, m_density, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CBubbling, m_frequency, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CBubbling, m_state, FIELD_INTEGER ),
|
|
|
|
// Let spawn restore this!
|
2016-06-25 18:33:39 +02:00
|
|
|
//DEFINE_FIELD( CBubbling, m_bubbleModel, FIELD_INTEGER ),
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CBubbling, CBaseEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
#define SF_BUBBLES_STARTOFF 0x0001
|
|
|
|
|
|
|
|
void CBubbling::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
|
|
|
SET_MODEL( ENT( pev ), STRING( pev->model ) ); // Set size
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pev->solid = SOLID_NOT; // Remove model & collisions
|
|
|
|
pev->renderamt = 0; // The engine won't draw this model if this is set to 0 and blending is on
|
|
|
|
pev->rendermode = kRenderTransTexture;
|
2017-06-29 15:56:03 +02:00
|
|
|
int speed = fabs( pev->speed );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// HACKHACK!!! - Speed in rendercolor
|
|
|
|
pev->rendercolor.x = speed >> 8;
|
|
|
|
pev->rendercolor.y = speed & 255;
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->rendercolor.z = ( pev->speed < 0 ) ? 1 : 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !( pev->spawnflags & SF_BUBBLES_STARTOFF ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( &CBubbling::FizzThink );
|
|
|
|
pev->nextthink = gpGlobals->time + 2.0;
|
|
|
|
m_state = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBubbling::Precache( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_bubbleModel = PRECACHE_MODEL( "sprites/bubble.spr" ); // Precache bubble sprite
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBubbling::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ShouldToggle( useType, m_state ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_state = !m_state;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_state )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( &CBubbling::FizzThink );
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetThink( NULL );
|
|
|
|
pev->nextthink = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBubbling::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "density" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_density = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "frequency" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_frequency = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "current" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->speed = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CBaseEntity::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBubbling::FizzThink( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, VecBModelOrigin( pev ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( TE_FIZZ );
|
|
|
|
WRITE_SHORT( (short)ENTINDEX( edict() ) );
|
|
|
|
WRITE_SHORT( (short)m_bubbleModel );
|
|
|
|
WRITE_BYTE( m_density );
|
|
|
|
MESSAGE_END();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_frequency > 19 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.5;
|
|
|
|
else
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 2.5 - ( 0.1 * m_frequency );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
//
|
|
|
|
// Beams
|
|
|
|
//
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( beam, CBeam )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CBeam::Spawn( void )
|
|
|
|
{
|
|
|
|
pev->solid = SOLID_NOT; // Remove model & collisions
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::Precache( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->owner )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetStartEntity( ENTINDEX( pev->owner ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->aiment )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetEndEntity( ENTINDEX( pev->aiment ) );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBeam::SetStartEntity( int entityIndex )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->sequence = ( entityIndex & 0x0FFF ) | ( ( pev->sequence & 0xF000 ) << 12 );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->owner = g_engfuncs.pfnPEntityOfEntIndex( entityIndex );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBeam::SetEndEntity( int entityIndex )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->skin = ( entityIndex & 0x0FFF ) | ( ( pev->skin & 0xF000 ) << 12 );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->aiment = g_engfuncs.pfnPEntityOfEntIndex( entityIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
// These don't take attachments into account
|
|
|
|
const Vector &CBeam::GetStartPos( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( GetType() == BEAM_ENTS )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
edict_t *pent = g_engfuncs.pfnPEntityOfEntIndex( GetStartEntity() );
|
|
|
|
return pent->v.origin;
|
|
|
|
}
|
|
|
|
return pev->origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vector &CBeam::GetEndPos( void )
|
|
|
|
{
|
|
|
|
int type = GetType();
|
2016-07-31 15:48:50 +02:00
|
|
|
if( type == BEAM_POINTS || type == BEAM_HOSE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return pev->angles;
|
|
|
|
}
|
|
|
|
|
|
|
|
edict_t *pent = g_engfuncs.pfnPEntityOfEntIndex( GetEndEntity() );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pent )
|
2016-06-04 15:24:23 +02:00
|
|
|
return pent->v.origin;
|
|
|
|
return pev->angles;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBeam *CBeam::BeamCreate( const char *pSpriteName, int width )
|
|
|
|
{
|
|
|
|
// Create a new entity with CBeam private data
|
|
|
|
CBeam *pBeam = GetClassPtr( (CBeam *)NULL );
|
2016-07-31 15:48:50 +02:00
|
|
|
pBeam->pev->classname = MAKE_STRING( "beam" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pBeam->BeamInit( pSpriteName, width );
|
|
|
|
|
|
|
|
return pBeam;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::BeamInit( const char *pSpriteName, int width )
|
|
|
|
{
|
|
|
|
pev->flags |= FL_CUSTOMENTITY;
|
|
|
|
SetColor( 255, 255, 255 );
|
|
|
|
SetBrightness( 255 );
|
|
|
|
SetNoise( 0 );
|
|
|
|
SetFrame( 0 );
|
|
|
|
SetScrollRate( 0 );
|
|
|
|
pev->model = MAKE_STRING( pSpriteName );
|
2017-07-23 23:24:55 +02:00
|
|
|
SetTexture( PRECACHE_MODEL( pSpriteName ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
SetWidth( width );
|
|
|
|
pev->skin = 0;
|
|
|
|
pev->sequence = 0;
|
|
|
|
pev->rendermode = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::PointsInit( const Vector &start, const Vector &end )
|
|
|
|
{
|
|
|
|
SetType( BEAM_POINTS );
|
|
|
|
SetStartPos( start );
|
|
|
|
SetEndPos( end );
|
|
|
|
SetStartAttachment( 0 );
|
|
|
|
SetEndAttachment( 0 );
|
|
|
|
RelinkBeam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::HoseInit( const Vector &start, const Vector &direction )
|
|
|
|
{
|
|
|
|
SetType( BEAM_HOSE );
|
|
|
|
SetStartPos( start );
|
|
|
|
SetEndPos( direction );
|
|
|
|
SetStartAttachment( 0 );
|
|
|
|
SetEndAttachment( 0 );
|
|
|
|
RelinkBeam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::PointEntInit( const Vector &start, int endIndex )
|
|
|
|
{
|
|
|
|
SetType( BEAM_ENTPOINT );
|
|
|
|
SetStartPos( start );
|
|
|
|
SetEndEntity( endIndex );
|
|
|
|
SetStartAttachment( 0 );
|
|
|
|
SetEndAttachment( 0 );
|
|
|
|
RelinkBeam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::EntsInit( int startIndex, int endIndex )
|
|
|
|
{
|
|
|
|
SetType( BEAM_ENTS );
|
|
|
|
SetStartEntity( startIndex );
|
|
|
|
SetEndEntity( endIndex );
|
|
|
|
SetStartAttachment( 0 );
|
|
|
|
SetEndAttachment( 0 );
|
|
|
|
RelinkBeam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::RelinkBeam( void )
|
|
|
|
{
|
|
|
|
const Vector &startPos = GetStartPos(), &endPos = GetEndPos();
|
|
|
|
|
2017-10-14 21:57:55 +02:00
|
|
|
pev->mins.x = Q_min( startPos.x, endPos.x );
|
|
|
|
pev->mins.y = Q_min( startPos.y, endPos.y );
|
|
|
|
pev->mins.z = Q_min( startPos.z, endPos.z );
|
|
|
|
pev->maxs.x = Q_max( startPos.x, endPos.x );
|
|
|
|
pev->maxs.y = Q_max( startPos.y, endPos.y );
|
|
|
|
pev->maxs.z = Q_max( startPos.z, endPos.z );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->mins = pev->mins - pev->origin;
|
|
|
|
pev->maxs = pev->maxs - pev->origin;
|
|
|
|
|
|
|
|
UTIL_SetSize( pev, pev->mins, pev->maxs );
|
|
|
|
UTIL_SetOrigin( pev, pev->origin );
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void CBeam::SetObjectCollisionBox( void )
|
|
|
|
{
|
|
|
|
const Vector &startPos = GetStartPos(), &endPos = GetEndPos();
|
|
|
|
|
|
|
|
pev->absmin.x = min( startPos.x, endPos.x );
|
|
|
|
pev->absmin.y = min( startPos.y, endPos.y );
|
|
|
|
pev->absmin.z = min( startPos.z, endPos.z );
|
|
|
|
pev->absmax.x = max( startPos.x, endPos.x );
|
|
|
|
pev->absmax.y = max( startPos.y, endPos.y );
|
|
|
|
pev->absmax.z = max( startPos.z, endPos.z );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CBeam::TriggerTouch( CBaseEntity *pOther )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pOther->pev->flags & ( FL_CLIENT | FL_MONSTER ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->owner )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pOwner = CBaseEntity::Instance( pev->owner );
|
2016-06-04 15:24:23 +02:00
|
|
|
pOwner->Use( pOther, this, USE_TOGGLE, 0 );
|
|
|
|
}
|
|
|
|
ALERT( at_console, "Firing targets!!!\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBaseEntity *CBeam::RandomTargetname( const char *szName )
|
|
|
|
{
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
CBaseEntity *pEntity = NULL;
|
|
|
|
CBaseEntity *pNewEntity = NULL;
|
2016-07-31 15:48:50 +02:00
|
|
|
while( ( pNewEntity = UTIL_FindEntityByTargetname( pNewEntity, szName ) ) != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
total++;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( RANDOM_LONG( 0, total - 1 ) < 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pEntity = pNewEntity;
|
|
|
|
}
|
|
|
|
return pEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::DoSparks( const Vector &start, const Vector &end )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & ( SF_BEAM_SPARKSTART | SF_BEAM_SPARKEND ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_SPARKSTART )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
UTIL_Sparks( start );
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_SPARKEND )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
UTIL_Sparks( end );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CLightning : public CBeam
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
|
|
|
void Activate( void );
|
|
|
|
|
|
|
|
void EXPORT StrikeThink( void );
|
|
|
|
void EXPORT DamageThink( void );
|
|
|
|
void RandomArea( void );
|
|
|
|
void RandomPoint( Vector &vecSrc );
|
|
|
|
void Zap( const Vector &vecSrc, const Vector &vecDest );
|
|
|
|
void EXPORT StrikeUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
void EXPORT ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
inline BOOL ServerSide( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_life == 0 && !( pev->spawnflags & SF_BEAM_RING ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
virtual int Save( CSave &save );
|
|
|
|
virtual int Restore( CRestore &restore );
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void BeamUpdateVars( void );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_active;
|
|
|
|
int m_iszStartEntity;
|
|
|
|
int m_iszEndEntity;
|
2016-06-04 15:24:23 +02:00
|
|
|
float m_life;
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_boltWidth;
|
|
|
|
int m_noiseAmplitude;
|
|
|
|
int m_brightness;
|
|
|
|
int m_speed;
|
2016-06-04 15:24:23 +02:00
|
|
|
float m_restrike;
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_spriteTexture;
|
|
|
|
int m_iszSpriteName;
|
|
|
|
int m_frameStart;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
float m_radius;
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_lightning, CLightning )
|
|
|
|
LINK_ENTITY_TO_CLASS( env_beam, CLightning )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// UNDONE: Jay -- This is only a test
|
|
|
|
#if _DEBUG
|
|
|
|
class CTripBeam : public CLightning
|
|
|
|
{
|
|
|
|
void Spawn( void );
|
|
|
|
};
|
2016-06-25 18:33:39 +02:00
|
|
|
|
|
|
|
LINK_ENTITY_TO_CLASS( trip_beam, CTripBeam )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CTripBeam::Spawn( void )
|
|
|
|
{
|
|
|
|
CLightning::Spawn();
|
2017-01-10 10:09:44 +01:00
|
|
|
SetTouch( &CLightning::TriggerTouch );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->solid = SOLID_TRIGGER;
|
|
|
|
RelinkBeam();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
TYPEDESCRIPTION CLightning::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
DEFINE_FIELD( CLightning, m_active, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_iszStartEntity, FIELD_STRING ),
|
|
|
|
DEFINE_FIELD( CLightning, m_iszEndEntity, FIELD_STRING ),
|
|
|
|
DEFINE_FIELD( CLightning, m_life, FIELD_FLOAT ),
|
|
|
|
DEFINE_FIELD( CLightning, m_boltWidth, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_noiseAmplitude, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_brightness, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_speed, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_restrike, FIELD_FLOAT ),
|
|
|
|
DEFINE_FIELD( CLightning, m_spriteTexture, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_iszSpriteName, FIELD_STRING ),
|
|
|
|
DEFINE_FIELD( CLightning, m_frameStart, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CLightning, m_radius, FIELD_FLOAT ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CLightning, CBeam )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CLightning::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStringNull( m_iszSpriteName ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pev->solid = SOLID_NOT; // Remove model & collisions
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pev->dmgtime = gpGlobals->time;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ServerSide() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( NULL );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->dmg > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( &CLightning::DamageThink );
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->targetname )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !( pev->spawnflags & SF_BEAM_STARTON ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
m_active = 0;
|
|
|
|
pev->nextthink = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_active = 1;
|
|
|
|
|
|
|
|
SetUse( &CLightning::ToggleUse );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_active = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStringNull( pev->targetname ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetUse( &CLightning::StrikeUse );
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStringNull( pev->targetname ) || FBitSet( pev->spawnflags, SF_BEAM_STARTON ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( &CLightning::StrikeThink );
|
|
|
|
pev->nextthink = gpGlobals->time + 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::Precache( void )
|
|
|
|
{
|
2017-07-23 23:24:55 +02:00
|
|
|
m_spriteTexture = PRECACHE_MODEL( STRING( m_iszSpriteName ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
CBeam::Precache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::Activate( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ServerSide() )
|
2016-06-04 15:24:23 +02:00
|
|
|
BeamUpdateVars();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "LightningStart" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_iszStartEntity = ALLOC_STRING( pkvd->szValue );
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "LightningEnd" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_iszEndEntity = ALLOC_STRING( pkvd->szValue );
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "life" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_life = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "BoltWidth" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_boltWidth = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "NoiseAmplitude" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_noiseAmplitude = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "TextureScroll" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_speed = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "StrikeTime" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_restrike = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "texture" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iszSpriteName = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "framestart" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_frameStart = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "Radius" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_radius = atof( pkvd->szValue );
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "damage" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->dmg = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CBeam::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !ShouldToggle( useType, m_active ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_active )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_active = 0;
|
|
|
|
pev->effects |= EF_NODRAW;
|
|
|
|
pev->nextthink = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_active = 1;
|
|
|
|
pev->effects &= ~EF_NODRAW;
|
|
|
|
DoSparks( GetStartPos(), GetEndPos() );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->dmg > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
pev->dmgtime = gpGlobals->time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::StrikeUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !ShouldToggle( useType, m_active ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_active )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_active = 0;
|
|
|
|
SetThink( NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetThink( &CLightning::StrikeThink );
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FBitSet( pev->spawnflags, SF_BEAM_TOGGLE ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetUse( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
int IsPointEntity( CBaseEntity *pEnt )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pEnt->pev->modelindex )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FClassnameIs( pEnt->pev, "info_target" ) || FClassnameIs( pEnt->pev, "info_landmark" ) || FClassnameIs( pEnt->pev, "path_corner" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::StrikeThink( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_life != 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_RANDOM )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->nextthink = gpGlobals->time + m_life + RANDOM_FLOAT( 0, m_restrike );
|
|
|
|
else
|
|
|
|
pev->nextthink = gpGlobals->time + m_life + m_restrike;
|
|
|
|
}
|
|
|
|
m_active = 1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStringNull( m_iszEndEntity ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStringNull( m_iszStartEntity ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
RandomArea();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pStart = RandomTargetname( STRING( m_iszStartEntity ) );
|
|
|
|
if( pStart != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
RandomPoint( pStart->pev->origin );
|
|
|
|
else
|
2016-07-31 15:48:50 +02:00
|
|
|
ALERT( at_console, "env_beam: unknown entity \"%s\"\n", STRING( m_iszStartEntity ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pStart = RandomTargetname( STRING( m_iszStartEntity ) );
|
|
|
|
CBaseEntity *pEnd = RandomTargetname( STRING( m_iszEndEntity ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pStart != NULL && pEnd != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( IsPointEntity( pStart ) || IsPointEntity( pEnd ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_RING )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// don't work
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( IsPointEntity( pStart ) || IsPointEntity( pEnd ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !IsPointEntity( pEnd ) ) // One point entity must be in pEnd
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBaseEntity *pTemp;
|
|
|
|
pTemp = pStart;
|
|
|
|
pStart = pEnd;
|
|
|
|
pEnd = pTemp;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !IsPointEntity( pStart ) ) // One sided
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
WRITE_BYTE( TE_BEAMENTPOINT );
|
|
|
|
WRITE_SHORT( pStart->entindex() );
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_COORD( pEnd->pev->origin.x );
|
|
|
|
WRITE_COORD( pEnd->pev->origin.y );
|
|
|
|
WRITE_COORD( pEnd->pev->origin.z );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( TE_BEAMPOINTS );
|
|
|
|
WRITE_COORD( pStart->pev->origin.x );
|
|
|
|
WRITE_COORD( pStart->pev->origin.y );
|
|
|
|
WRITE_COORD( pStart->pev->origin.z );
|
|
|
|
WRITE_COORD( pEnd->pev->origin.x );
|
|
|
|
WRITE_COORD( pEnd->pev->origin.y );
|
|
|
|
WRITE_COORD( pEnd->pev->origin.z );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_RING )
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( TE_BEAMRING );
|
|
|
|
else
|
|
|
|
WRITE_BYTE( TE_BEAMENTS );
|
|
|
|
WRITE_SHORT( pStart->entindex() );
|
|
|
|
WRITE_SHORT( pEnd->entindex() );
|
|
|
|
}
|
|
|
|
|
|
|
|
WRITE_SHORT( m_spriteTexture );
|
|
|
|
WRITE_BYTE( m_frameStart ); // framestart
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( (int)pev->framerate ); // framerate
|
|
|
|
WRITE_BYTE( (int)( m_life * 10.0 ) ); // life
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( m_boltWidth ); // width
|
|
|
|
WRITE_BYTE( m_noiseAmplitude ); // noise
|
|
|
|
WRITE_BYTE( (int)pev->rendercolor.x ); // r, g, b
|
|
|
|
WRITE_BYTE( (int)pev->rendercolor.y ); // r, g, b
|
|
|
|
WRITE_BYTE( (int)pev->rendercolor.z ); // r, g, b
|
2017-06-29 15:56:03 +02:00
|
|
|
WRITE_BYTE( (int)pev->renderamt ); // brightness
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( m_speed ); // speed
|
|
|
|
MESSAGE_END();
|
|
|
|
DoSparks( pStart->pev->origin, pEnd->pev->origin );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->dmg > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
TraceResult tr;
|
|
|
|
UTIL_TraceLine( pStart->pev->origin, pEnd->pev->origin, dont_ignore_monsters, NULL, &tr );
|
|
|
|
BeamDamageInstant( &tr, pev->dmg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeam::BeamDamage( TraceResult *ptr )
|
|
|
|
{
|
|
|
|
RelinkBeam();
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ptr->flFraction != 1.0 && ptr->pHit != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pHit = CBaseEntity::Instance( ptr->pHit );
|
|
|
|
if( pHit )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
ClearMultiDamage();
|
2016-07-31 15:48:50 +02:00
|
|
|
pHit->TraceAttack( pev, pev->dmg * ( gpGlobals->time - pev->dmgtime ), ( ptr->vecEndPos - pev->origin ).Normalize(), ptr, DMG_ENERGYBEAM );
|
2016-06-04 15:24:23 +02:00
|
|
|
ApplyMultiDamage( pev, pev );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_DECALS )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pHit->IsBSPModel() )
|
|
|
|
UTIL_DecalTrace( ptr, DECAL_BIGSHOT1 + RANDOM_LONG( 0, 4 ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pev->dmgtime = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::DamageThink( void )
|
|
|
|
{
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
TraceResult tr;
|
|
|
|
UTIL_TraceLine( GetStartPos(), GetEndPos(), dont_ignore_monsters, NULL, &tr );
|
|
|
|
BeamDamage( &tr );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::Zap( const Vector &vecSrc, const Vector &vecDest )
|
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( TE_BEAMPOINTS );
|
|
|
|
WRITE_COORD( vecSrc.x );
|
|
|
|
WRITE_COORD( vecSrc.y );
|
|
|
|
WRITE_COORD( vecSrc.z );
|
|
|
|
WRITE_COORD( vecDest.x );
|
|
|
|
WRITE_COORD( vecDest.y );
|
|
|
|
WRITE_COORD( vecDest.z );
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_SHORT( m_spriteTexture );
|
|
|
|
WRITE_BYTE( m_frameStart ); // framestart
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( (int)pev->framerate ); // framerate
|
|
|
|
WRITE_BYTE( (int)( m_life * 10.0) ); // life
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( m_boltWidth ); // width
|
|
|
|
WRITE_BYTE( m_noiseAmplitude ); // noise
|
|
|
|
WRITE_BYTE( (int)pev->rendercolor.x ); // r, g, b
|
|
|
|
WRITE_BYTE( (int)pev->rendercolor.y ); // r, g, b
|
|
|
|
WRITE_BYTE( (int)pev->rendercolor.z ); // r, g, b
|
2017-06-29 15:56:03 +02:00
|
|
|
WRITE_BYTE( (int)pev->renderamt ); // brightness
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( m_speed ); // speed
|
|
|
|
MESSAGE_END();
|
|
|
|
#else
|
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( TE_LIGHTNING );
|
|
|
|
WRITE_COORD( vecSrc.x );
|
|
|
|
WRITE_COORD( vecSrc.y );
|
|
|
|
WRITE_COORD( vecSrc.z );
|
|
|
|
WRITE_COORD( vecDest.x );
|
|
|
|
WRITE_COORD( vecDest.y );
|
|
|
|
WRITE_COORD( vecDest.z );
|
|
|
|
WRITE_BYTE( 10 );
|
|
|
|
WRITE_BYTE( 50 );
|
|
|
|
WRITE_BYTE( 40 );
|
|
|
|
WRITE_SHORT( m_spriteTexture );
|
2016-06-04 15:24:23 +02:00
|
|
|
MESSAGE_END();
|
|
|
|
#endif
|
|
|
|
DoSparks( vecSrc, vecDest );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::RandomArea( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int iLoops;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( iLoops = 0; iLoops < 10; iLoops++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector vecSrc = pev->origin;
|
|
|
|
|
|
|
|
Vector vecDir1 = Vector( RANDOM_FLOAT( -1.0, 1.0 ), RANDOM_FLOAT( -1.0, 1.0 ),RANDOM_FLOAT( -1.0, 1.0 ) );
|
|
|
|
vecDir1 = vecDir1.Normalize();
|
2016-07-31 15:48:50 +02:00
|
|
|
TraceResult tr1;
|
|
|
|
UTIL_TraceLine( vecSrc, vecSrc + vecDir1 * m_radius, ignore_monsters, ENT( pev ), &tr1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr1.flFraction == 1.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Vector vecDir2;
|
2016-07-31 15:48:50 +02:00
|
|
|
do
|
|
|
|
{
|
2016-06-04 15:24:23 +02:00
|
|
|
vecDir2 = Vector( RANDOM_FLOAT( -1.0, 1.0 ), RANDOM_FLOAT( -1.0, 1.0 ),RANDOM_FLOAT( -1.0, 1.0 ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
} while( DotProduct( vecDir1, vecDir2 ) > 0 );
|
2016-06-04 15:24:23 +02:00
|
|
|
vecDir2 = vecDir2.Normalize();
|
2016-07-31 15:48:50 +02:00
|
|
|
TraceResult tr2;
|
|
|
|
UTIL_TraceLine( vecSrc, vecSrc + vecDir2 * m_radius, ignore_monsters, ENT( pev ), &tr2 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr2.flFraction == 1.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( tr1.vecEndPos - tr2.vecEndPos ).Length() < m_radius * 0.1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_TraceLine( tr1.vecEndPos, tr2.vecEndPos, ignore_monsters, ENT( pev ), &tr2 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr2.flFraction != 1.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Zap( tr1.vecEndPos, tr2.vecEndPos );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::RandomPoint( Vector &vecSrc )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int iLoops;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( iLoops = 0; iLoops < 10; iLoops++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector vecDir1 = Vector( RANDOM_FLOAT( -1.0, 1.0 ), RANDOM_FLOAT( -1.0, 1.0 ),RANDOM_FLOAT( -1.0, 1.0 ) );
|
|
|
|
vecDir1 = vecDir1.Normalize();
|
2016-07-31 15:48:50 +02:00
|
|
|
TraceResult tr1;
|
|
|
|
UTIL_TraceLine( vecSrc, vecSrc + vecDir1 * m_radius, ignore_monsters, ENT( pev ), &tr1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( tr1.vecEndPos - vecSrc ).Length() < m_radius * 0.1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr1.flFraction == 1.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Zap( vecSrc, tr1.vecEndPos );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLightning::BeamUpdateVars( void )
|
|
|
|
{
|
|
|
|
int beamType;
|
|
|
|
int pointStart, pointEnd;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
edict_t *pStart = FIND_ENTITY_BY_TARGETNAME( NULL, STRING( m_iszStartEntity ) );
|
|
|
|
edict_t *pEnd = FIND_ENTITY_BY_TARGETNAME ( NULL, STRING( m_iszEndEntity ) );
|
|
|
|
pointStart = IsPointEntity( CBaseEntity::Instance( pStart ) );
|
|
|
|
pointEnd = IsPointEntity( CBaseEntity::Instance( pEnd ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pev->skin = 0;
|
|
|
|
pev->sequence = 0;
|
|
|
|
pev->rendermode = 0;
|
|
|
|
pev->flags |= FL_CUSTOMENTITY;
|
|
|
|
pev->model = m_iszSpriteName;
|
|
|
|
SetTexture( m_spriteTexture );
|
|
|
|
|
|
|
|
beamType = BEAM_ENTS;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pointStart || pointEnd )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pointStart ) // One point entity must be in pStart
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
edict_t *pTemp;
|
|
|
|
// Swap start & end
|
|
|
|
pTemp = pStart;
|
|
|
|
pStart = pEnd;
|
|
|
|
pEnd = pTemp;
|
|
|
|
int swap = pointStart;
|
|
|
|
pointStart = pointEnd;
|
|
|
|
pointEnd = swap;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pointEnd )
|
2016-06-04 15:24:23 +02:00
|
|
|
beamType = BEAM_ENTPOINT;
|
|
|
|
else
|
|
|
|
beamType = BEAM_POINTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetType( beamType );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( beamType == BEAM_POINTS || beamType == BEAM_ENTPOINT || beamType == BEAM_HOSE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetStartPos( pStart->v.origin );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( beamType == BEAM_POINTS || beamType == BEAM_HOSE )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetEndPos( pEnd->v.origin );
|
|
|
|
else
|
2016-07-31 15:48:50 +02:00
|
|
|
SetEndEntity( ENTINDEX( pEnd ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetStartEntity( ENTINDEX( pStart ) );
|
|
|
|
SetEndEntity( ENTINDEX( pEnd ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RelinkBeam();
|
|
|
|
|
|
|
|
SetWidth( m_boltWidth );
|
|
|
|
SetNoise( m_noiseAmplitude );
|
|
|
|
SetFrame( m_frameStart );
|
|
|
|
SetScrollRate( m_speed );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BEAM_SHADEIN )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetFlags( BEAM_FSHADEIN );
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pev->spawnflags & SF_BEAM_SHADEOUT )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetFlags( BEAM_FSHADEOUT );
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_laser, CLaser )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
TYPEDESCRIPTION CLaser::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
DEFINE_FIELD( CLaser, m_pSprite, FIELD_CLASSPTR ),
|
|
|
|
DEFINE_FIELD( CLaser, m_iszSpriteName, FIELD_STRING ),
|
|
|
|
DEFINE_FIELD( CLaser, m_firePosition, FIELD_POSITION_VECTOR ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CLaser, CBeam )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CLaser::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStringNull( pev->model ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pev->solid = SOLID_NOT; // Remove model & collisions
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
SetThink( &CLaser::StrikeThink );
|
|
|
|
pev->flags |= FL_CUSTOMENTITY;
|
|
|
|
|
|
|
|
PointsInit( pev->origin, pev->origin );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !m_pSprite && m_iszSpriteName )
|
|
|
|
m_pSprite = CSprite::SpriteCreate( STRING( m_iszSpriteName ), pev->origin, TRUE );
|
2016-06-04 15:24:23 +02:00
|
|
|
else
|
|
|
|
m_pSprite = NULL;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pSprite )
|
2017-06-29 15:56:03 +02:00
|
|
|
m_pSprite->SetTransparency( kRenderGlow, (int)pev->rendercolor.x, (int)pev->rendercolor.y, (int)pev->rendercolor.z, (int)pev->renderamt, (int)pev->renderfx );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->targetname && !( pev->spawnflags & SF_BEAM_STARTON ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
TurnOff();
|
|
|
|
else
|
|
|
|
TurnOn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::Precache( void )
|
|
|
|
{
|
2017-07-23 23:24:55 +02:00
|
|
|
pev->modelindex = PRECACHE_MODEL( STRING( pev->model ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_iszSpriteName )
|
2017-07-23 23:24:55 +02:00
|
|
|
PRECACHE_MODEL( STRING( m_iszSpriteName ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "LaserTarget" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->message = ALLOC_STRING( pkvd->szValue );
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "width" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetWidth( (int)atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "NoiseAmplitude" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetNoise( atoi( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "TextureScroll" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetScrollRate( atoi( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "texture" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->model = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "EndSprite" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iszSpriteName = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "framestart" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->frame = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "damage" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->dmg = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CBeam::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLaser::IsOn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->effects & EF_NODRAW )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::TurnOff( void )
|
|
|
|
{
|
|
|
|
pev->effects |= EF_NODRAW;
|
|
|
|
pev->nextthink = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pSprite )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pSprite->TurnOff();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::TurnOn( void )
|
|
|
|
{
|
|
|
|
pev->effects &= ~EF_NODRAW;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pSprite )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pSprite->TurnOn();
|
|
|
|
pev->dmgtime = gpGlobals->time;
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
int active = IsOn();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !ShouldToggle( useType, active ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( active )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
TurnOff();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TurnOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::FireAtPoint( TraceResult &tr )
|
|
|
|
{
|
|
|
|
SetEndPos( tr.vecEndPos );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pSprite )
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_SetOrigin( m_pSprite->pev, tr.vecEndPos );
|
|
|
|
|
|
|
|
BeamDamage( &tr );
|
|
|
|
DoSparks( GetStartPos(), tr.vecEndPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLaser::StrikeThink( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEnd = RandomTargetname( STRING( pev->message ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEnd )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_firePosition = pEnd->pev->origin;
|
|
|
|
|
|
|
|
TraceResult tr;
|
|
|
|
|
|
|
|
UTIL_TraceLine( pev->origin, m_firePosition, dont_ignore_monsters, NULL, &tr );
|
|
|
|
FireAtPoint( tr );
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CGlow : public CPointEntity
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Spawn( void );
|
|
|
|
void Think( void );
|
|
|
|
void Animate( float frames );
|
2016-07-31 15:48:50 +02:00
|
|
|
virtual int Save( CSave &save );
|
|
|
|
virtual int Restore( CRestore &restore );
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
float m_lastTime;
|
|
|
|
float m_maxFrame;
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_glow, CGlow )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
TYPEDESCRIPTION CGlow::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
DEFINE_FIELD( CGlow, m_lastTime, FIELD_TIME ),
|
|
|
|
DEFINE_FIELD( CGlow, m_maxFrame, FIELD_FLOAT ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CGlow, CPointEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CGlow::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->effects = 0;
|
|
|
|
pev->frame = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2017-07-23 23:24:55 +02:00
|
|
|
PRECACHE_MODEL( STRING( pev->model ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), STRING( pev->model ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_maxFrame = (float) MODEL_FRAMES( pev->modelindex ) - 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_maxFrame > 1.0 && pev->framerate != 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
|
|
|
|
m_lastTime = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGlow::Think( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
Animate( pev->framerate * ( gpGlobals->time - m_lastTime ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
m_lastTime = gpGlobals->time;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGlow::Animate( float frames )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_maxFrame > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->frame = fmod( pev->frame + frames, m_maxFrame );
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_sprite, CSprite )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
TYPEDESCRIPTION CSprite::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
DEFINE_FIELD( CSprite, m_lastTime, FIELD_TIME ),
|
|
|
|
DEFINE_FIELD( CSprite, m_maxFrame, FIELD_FLOAT ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CSprite, CPointEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CSprite::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->effects = 0;
|
|
|
|
pev->frame = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
Precache();
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), STRING( pev->model ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_maxFrame = (float) MODEL_FRAMES( pev->modelindex ) - 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->targetname && !( pev->spawnflags & SF_SPRITE_STARTON ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
TurnOff();
|
|
|
|
else
|
|
|
|
TurnOn();
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Worldcraft only sets y rotation, copy to Z
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->angles.y != 0 && pev->angles.z == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->angles.z = pev->angles.y;
|
|
|
|
pev->angles.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::Precache( void )
|
|
|
|
{
|
2017-07-23 23:24:55 +02:00
|
|
|
PRECACHE_MODEL( STRING( pev->model ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Reset attachment after save/restore
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->aiment )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetAttachment( pev->aiment, pev->body );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Clear attachment
|
|
|
|
pev->skin = 0;
|
|
|
|
pev->body = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::SpriteInit( const char *pSpriteName, const Vector &origin )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->model = MAKE_STRING( pSpriteName );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->origin = origin;
|
|
|
|
Spawn();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSprite *CSprite::SpriteCreate( const char *pSpriteName, const Vector &origin, BOOL animate )
|
|
|
|
{
|
|
|
|
CSprite *pSprite = GetClassPtr( (CSprite *)NULL );
|
|
|
|
pSprite->SpriteInit( pSpriteName, origin );
|
2016-07-31 15:48:50 +02:00
|
|
|
pSprite->pev->classname = MAKE_STRING( "env_sprite" );
|
2016-06-04 15:24:23 +02:00
|
|
|
pSprite->pev->solid = SOLID_NOT;
|
|
|
|
pSprite->pev->movetype = MOVETYPE_NOCLIP;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( animate )
|
2016-06-04 15:24:23 +02:00
|
|
|
pSprite->TurnOn();
|
|
|
|
|
|
|
|
return pSprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::AnimateThink( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
Animate( pev->framerate * ( gpGlobals->time - m_lastTime ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
m_lastTime = gpGlobals->time;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::AnimateUntilDead( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( gpGlobals->time > pev->dmgtime )
|
|
|
|
UTIL_Remove( this );
|
2016-06-04 15:24:23 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
AnimateThink();
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::Expand( float scaleSpeed, float fadeSpeed )
|
|
|
|
{
|
|
|
|
pev->speed = scaleSpeed;
|
|
|
|
pev->health = fadeSpeed;
|
|
|
|
SetThink( &CSprite::ExpandThink );
|
|
|
|
|
|
|
|
pev->nextthink = gpGlobals->time;
|
2016-07-31 15:48:50 +02:00
|
|
|
m_lastTime = gpGlobals->time;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::ExpandThink( void )
|
|
|
|
{
|
|
|
|
float frametime = gpGlobals->time - m_lastTime;
|
|
|
|
pev->scale += pev->speed * frametime;
|
|
|
|
pev->renderamt -= pev->health * frametime;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->renderamt <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->renderamt = 0;
|
|
|
|
UTIL_Remove( this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
m_lastTime = gpGlobals->time;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::Animate( float frames )
|
|
|
|
{
|
|
|
|
pev->frame += frames;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->frame > m_maxFrame )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_SPRITE_ONCE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
TurnOff();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_maxFrame > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->frame = fmod( pev->frame, m_maxFrame );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::TurnOff( void )
|
|
|
|
{
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
pev->nextthink = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::TurnOn( void )
|
|
|
|
{
|
|
|
|
pev->effects = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pev->framerate && m_maxFrame > 1.0 ) || ( pev->spawnflags & SF_SPRITE_ONCE ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-01-10 10:09:44 +01:00
|
|
|
SetThink( &CSprite::AnimateThink );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
m_lastTime = gpGlobals->time;
|
|
|
|
}
|
|
|
|
pev->frame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSprite::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
int on = pev->effects != EF_NODRAW;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ShouldToggle( useType, on ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( on )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
TurnOff();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TurnOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CGibShooter : public CBaseDelay
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
2016-06-04 15:24:23 +02:00
|
|
|
void EXPORT ShootThink( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
|
|
|
|
virtual CGib *CreateGib( void );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
virtual int Save( CSave &save );
|
|
|
|
virtual int Restore( CRestore &restore );
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_iGibs;
|
2016-06-04 15:24:23 +02:00
|
|
|
int m_iGibCapacity;
|
|
|
|
int m_iGibMaterial;
|
|
|
|
int m_iGibModelIndex;
|
|
|
|
float m_flGibVelocity;
|
|
|
|
float m_flVariance;
|
|
|
|
float m_flGibLife;
|
|
|
|
};
|
|
|
|
|
|
|
|
TYPEDESCRIPTION CGibShooter::m_SaveData[] =
|
|
|
|
{
|
|
|
|
DEFINE_FIELD( CGibShooter, m_iGibs, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CGibShooter, m_iGibCapacity, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CGibShooter, m_iGibMaterial, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CGibShooter, m_iGibModelIndex, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CGibShooter, m_flGibVelocity, FIELD_FLOAT ),
|
|
|
|
DEFINE_FIELD( CGibShooter, m_flVariance, FIELD_FLOAT ),
|
|
|
|
DEFINE_FIELD( CGibShooter, m_flGibLife, FIELD_FLOAT ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CGibShooter, CBaseDelay )
|
|
|
|
LINK_ENTITY_TO_CLASS( gibshooter, CGibShooter )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CGibShooter::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( g_Language == LANGUAGE_GERMAN )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iGibModelIndex = PRECACHE_MODEL( "models/germanygibs.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iGibModelIndex = PRECACHE_MODEL( "models/hgibs.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGibShooter::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "m_iGibs" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iGibs = m_iGibCapacity = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_flVelocity" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_flGibVelocity = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_flVariance" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_flVariance = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_flGibLife" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_flGibLife = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CBaseDelay::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGibShooter::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
SetThink( &CGibShooter::ShootThink );
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGibShooter::Spawn( void )
|
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_flDelay == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_flDelay = 0.1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_flGibLife == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_flGibLife = 25;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
SetMovedir( pev );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->body = MODEL_FRAMES( m_iGibModelIndex );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CGib *CGibShooter::CreateGib( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( CVAR_GET_FLOAT( "violence_hgibs" ) == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CGib *pGib = GetClassPtr( (CGib *)NULL );
|
|
|
|
pGib->Spawn( "models/hgibs.mdl" );
|
|
|
|
pGib->m_bloodColor = BLOOD_COLOR_RED;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->body <= 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
ALERT( at_aiconsole, "GibShooter Body is <= 1!\n" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pGib->pev->body = RANDOM_LONG( 1, pev->body - 1 );// avoid throwing random amounts of the 0th gib. (skull).
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
return pGib;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CGibShooter::ShootThink( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->nextthink = gpGlobals->time + m_flDelay;
|
|
|
|
|
|
|
|
Vector vecShootDir;
|
|
|
|
|
|
|
|
vecShootDir = pev->movedir;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
vecShootDir = vecShootDir + gpGlobals->v_right * RANDOM_FLOAT( -1, 1 ) * m_flVariance;;
|
|
|
|
vecShootDir = vecShootDir + gpGlobals->v_forward * RANDOM_FLOAT( -1, 1 ) * m_flVariance;;
|
|
|
|
vecShootDir = vecShootDir + gpGlobals->v_up * RANDOM_FLOAT( -1, 1 ) * m_flVariance;;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
vecShootDir = vecShootDir.Normalize();
|
|
|
|
CGib *pGib = CreateGib();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pGib )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pGib->pev->origin = pev->origin;
|
|
|
|
pGib->pev->velocity = vecShootDir * m_flGibVelocity;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
pGib->pev->avelocity.x = RANDOM_FLOAT( 100, 200 );
|
|
|
|
pGib->pev->avelocity.y = RANDOM_FLOAT( 100, 300 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
float thinkTime = pGib->pev->nextthink - gpGlobals->time;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pGib->m_lifeTime = ( m_flGibLife * RANDOM_FLOAT( 0.95, 1.05 ) ); // +/- 5%
|
|
|
|
if( pGib->m_lifeTime < thinkTime )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pGib->pev->nextthink = gpGlobals->time + pGib->m_lifeTime;
|
|
|
|
pGib->m_lifeTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( --m_iGibs <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_GIBSHOOTER_REPEATABLE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_iGibs = m_iGibCapacity;
|
|
|
|
SetThink( NULL );
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CEnvShooter : public CGibShooter
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
void Precache( void );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CGib *CreateGib( void );
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_shooter, CEnvShooter )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CEnvShooter::KeyValue( KeyValueData *pkvd )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "shootmodel" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->model = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if ( FStrEq( pkvd->szKeyName, "shootsounds" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int iNoise = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
switch( iNoise )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
m_iGibMaterial = matGlass;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
m_iGibMaterial = matWood;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_iGibMaterial = matMetal;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_iGibMaterial = matFlesh;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
m_iGibMaterial = matRocks;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case -1:
|
|
|
|
m_iGibMaterial = matNone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CGibShooter::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CEnvShooter::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-07-23 23:24:55 +02:00
|
|
|
m_iGibModelIndex = PRECACHE_MODEL( STRING( pev->model ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
CBreakable::MaterialSoundPrecache( (Materials)m_iGibMaterial );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CGib *CEnvShooter::CreateGib( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CGib *pGib = GetClassPtr( (CGib *)NULL );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pGib->Spawn( STRING( pev->model ) );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
int bodyPart = 0;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->body > 1 )
|
|
|
|
bodyPart = RANDOM_LONG( 0, pev->body - 1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pGib->pev->body = bodyPart;
|
|
|
|
pGib->m_bloodColor = DONT_BLEED;
|
|
|
|
pGib->m_material = m_iGibMaterial;
|
|
|
|
|
|
|
|
pGib->pev->rendermode = pev->rendermode;
|
|
|
|
pGib->pev->renderamt = pev->renderamt;
|
|
|
|
pGib->pev->rendercolor = pev->rendercolor;
|
|
|
|
pGib->pev->renderfx = pev->renderfx;
|
|
|
|
pGib->pev->scale = pev->scale;
|
|
|
|
pGib->pev->skin = pev->skin;
|
|
|
|
|
|
|
|
return pGib;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CTestEffect : public CBaseDelay
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
2016-06-04 15:24:23 +02:00
|
|
|
// void KeyValue( KeyValueData *pkvd );
|
|
|
|
void EXPORT TestThink( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_iLoop;
|
|
|
|
int m_iBeam;
|
|
|
|
CBeam *m_pBeam[24];
|
|
|
|
float m_flBeamTime[24];
|
|
|
|
float m_flStartTime;
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( test_effect, CTestEffect )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CTestEffect::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTestEffect::Precache( void )
|
|
|
|
{
|
|
|
|
PRECACHE_MODEL( "sprites/lgtning.spr" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTestEffect::TestThink( void )
|
|
|
|
{
|
|
|
|
int i;
|
2016-07-31 15:48:50 +02:00
|
|
|
float t = gpGlobals->time - m_flStartTime;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_iBeam < 24 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBeam *pbeam = CBeam::BeamCreate( "sprites/lgtning.spr", 100 );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
TraceResult tr;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
Vector vecSrc = pev->origin;
|
|
|
|
Vector vecDir = Vector( RANDOM_FLOAT( -1.0, 1.0 ), RANDOM_FLOAT( -1.0, 1.0 ),RANDOM_FLOAT( -1.0, 1.0 ) );
|
|
|
|
vecDir = vecDir.Normalize();
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_TraceLine( vecSrc, vecSrc + vecDir * 128, ignore_monsters, ENT( pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pbeam->PointsInit( vecSrc, tr.vecEndPos );
|
|
|
|
// pbeam->SetColor( 80, 100, 255 );
|
|
|
|
pbeam->SetColor( 255, 180, 100 );
|
|
|
|
pbeam->SetWidth( 100 );
|
|
|
|
pbeam->SetScrollRate( 12 );
|
|
|
|
|
|
|
|
m_flBeamTime[m_iBeam] = gpGlobals->time;
|
|
|
|
m_pBeam[m_iBeam] = pbeam;
|
|
|
|
m_iBeam++;
|
|
|
|
#if 0
|
2016-07-31 15:48:50 +02:00
|
|
|
Vector vecMid = ( vecSrc + tr.vecEndPos ) * 0.5;
|
2016-06-04 15:24:23 +02:00
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( TE_DLIGHT );
|
|
|
|
WRITE_COORD( vecMid.x ); // X
|
|
|
|
WRITE_COORD( vecMid.y ); // Y
|
|
|
|
WRITE_COORD( vecMid.z ); // Z
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( 20 ); // radius * 0.1
|
|
|
|
WRITE_BYTE( 255 ); // r
|
|
|
|
WRITE_BYTE( 180 ); // g
|
|
|
|
WRITE_BYTE( 100 ); // b
|
|
|
|
WRITE_BYTE( 20 ); // time * 10
|
|
|
|
WRITE_BYTE( 0 ); // decay * 0.1
|
|
|
|
MESSAGE_END( );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( t < 3.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < m_iBeam; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
t = ( gpGlobals->time - m_flBeamTime[i] ) / ( 3 + m_flStartTime - m_flBeamTime[i] );
|
2017-06-29 15:56:03 +02:00
|
|
|
m_pBeam[i]->SetBrightness( (int)( 255 * t ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
// m_pBeam[i]->SetScrollRate( 20 * t );
|
|
|
|
}
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < m_iBeam; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
UTIL_Remove( m_pBeam[i] );
|
|
|
|
}
|
|
|
|
m_flStartTime = gpGlobals->time;
|
|
|
|
m_iBeam = 0;
|
|
|
|
// pev->nextthink = gpGlobals->time;
|
|
|
|
SetThink( NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTestEffect::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
SetThink( &CTestEffect::TestThink );
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
m_flStartTime = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blood effects
|
|
|
|
class CBlood : public CPointEntity
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
inline int Color( void )
|
|
|
|
{
|
|
|
|
return pev->impulse;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
inline float BloodAmount( void )
|
|
|
|
{
|
|
|
|
return pev->dmg;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
inline void SetColor( int color )
|
|
|
|
{
|
|
|
|
pev->impulse = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetBloodAmount( float amount )
|
|
|
|
{
|
|
|
|
pev->dmg = amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector Direction( void );
|
|
|
|
Vector BloodPosition( CBaseEntity *pActivator );
|
2016-06-04 15:24:23 +02:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_blood, CBlood )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
#define SF_BLOOD_RANDOM 0x0001
|
|
|
|
#define SF_BLOOD_STREAM 0x0002
|
|
|
|
#define SF_BLOOD_PLAYER 0x0004
|
|
|
|
#define SF_BLOOD_DECAL 0x0008
|
|
|
|
|
|
|
|
void CBlood::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->effects = 0;
|
|
|
|
pev->frame = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
SetMovedir( pev );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBlood::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "color" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int color = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
switch( color )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
SetColor( BLOOD_COLOR_YELLOW );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetColor( BLOOD_COLOR_RED );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "amount" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetBloodAmount( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CPointEntity::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector CBlood::Direction( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BLOOD_RANDOM )
|
2016-06-04 15:24:23 +02:00
|
|
|
return UTIL_RandomBloodVector();
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
return pev->movedir;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector CBlood::BloodPosition( CBaseEntity *pActivator )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BLOOD_PLAYER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
edict_t *pPlayer;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pActivator && pActivator->IsPlayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pPlayer = pActivator->edict();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pPlayer )
|
|
|
|
return( pPlayer->v.origin + pPlayer->v.view_ofs ) + Vector( RANDOM_FLOAT( -10, 10 ), RANDOM_FLOAT( -10, 10 ), RANDOM_FLOAT( -10, 10 ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pev->origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBlood::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BLOOD_STREAM )
|
2017-06-29 15:56:03 +02:00
|
|
|
UTIL_BloodStream( BloodPosition( pActivator ), Direction(), ( Color() == BLOOD_COLOR_RED ) ? 70 : Color(), (int)BloodAmount() );
|
2016-06-04 15:24:23 +02:00
|
|
|
else
|
2017-06-29 15:56:03 +02:00
|
|
|
UTIL_BloodDrips( BloodPosition( pActivator ), Direction(), Color(), (int)BloodAmount() );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_BLOOD_DECAL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector forward = Direction();
|
|
|
|
Vector start = BloodPosition( pActivator );
|
|
|
|
TraceResult tr;
|
|
|
|
|
|
|
|
UTIL_TraceLine( start, start + forward * BloodAmount() * 2, ignore_monsters, NULL, &tr );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr.flFraction != 1.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_BloodDecalTrace( &tr, Color() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Screen shake
|
|
|
|
class CShake : public CPointEntity
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
|
|
|
|
|
|
|
inline float Amplitude( void )
|
|
|
|
{
|
|
|
|
return pev->scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float Frequency( void )
|
|
|
|
{
|
|
|
|
return pev->dmg_save;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float Duration( void )
|
|
|
|
{
|
|
|
|
return pev->dmg_take;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float Radius( void )
|
|
|
|
{
|
|
|
|
return pev->dmg;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetAmplitude( float amplitude )
|
|
|
|
{
|
|
|
|
pev->scale = amplitude;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetFrequency( float frequency )
|
|
|
|
{
|
|
|
|
pev->dmg_save = frequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetDuration( float duration )
|
|
|
|
{
|
|
|
|
pev->dmg_take = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetRadius( float radius )
|
|
|
|
{
|
|
|
|
pev->dmg = radius;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_shake, CShake )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// pev->scale is amplitude
|
|
|
|
// pev->dmg_save is frequency
|
|
|
|
// pev->dmg_take is duration
|
|
|
|
// pev->dmg is radius
|
|
|
|
// radius of 0 means all players
|
|
|
|
// NOTE: UTIL_ScreenShake() will only shake players who are on the ground
|
|
|
|
|
|
|
|
#define SF_SHAKE_EVERYONE 0x0001 // Don't check radius
|
|
|
|
// UNDONE: These don't work yet
|
|
|
|
#define SF_SHAKE_DISRUPT 0x0002 // Disrupt controls
|
|
|
|
#define SF_SHAKE_INAIR 0x0004 // Shake players in air
|
|
|
|
|
|
|
|
void CShake::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->effects = 0;
|
|
|
|
pev->frame = 0;
|
|
|
|
|
|
|
|
if( pev->spawnflags & SF_SHAKE_EVERYONE )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->dmg = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CShake::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "amplitude" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetAmplitude( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "frequency" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetFrequency( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "duration" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetDuration( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "radius" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetRadius( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CPointEntity::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CShake::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
UTIL_ScreenShake( pev->origin, Amplitude(), Frequency(), Duration(), Radius() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CFade : public CPointEntity
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
|
|
|
|
|
|
|
inline float Duration( void )
|
|
|
|
{
|
|
|
|
return pev->dmg_take;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
inline float HoldTime( void )
|
|
|
|
{
|
|
|
|
return pev->dmg_save;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetDuration( float duration )
|
|
|
|
{
|
|
|
|
pev->dmg_take = duration;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
inline void SetHoldTime( float hold )
|
|
|
|
{
|
|
|
|
pev->dmg_save = hold;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_fade, CFade )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// pev->dmg_take is duration
|
|
|
|
// pev->dmg_save is hold duration
|
2016-07-31 15:48:50 +02:00
|
|
|
#define SF_FADE_IN 0x0001 // Fade in, not out
|
2016-06-04 15:24:23 +02:00
|
|
|
#define SF_FADE_MODULATE 0x0002 // Modulate, don't blend
|
|
|
|
#define SF_FADE_ONLYONE 0x0004
|
|
|
|
|
|
|
|
void CFade::Spawn( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->effects = 0;
|
|
|
|
pev->frame = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CFade::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "duration" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetDuration( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "holdtime" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
SetHoldTime( atof( pkvd->szValue ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CPointEntity::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFade::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
int fadeFlags = 0;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !( pev->spawnflags & SF_FADE_IN ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
fadeFlags |= FFADE_OUT;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_FADE_MODULATE )
|
2016-06-04 15:24:23 +02:00
|
|
|
fadeFlags |= FFADE_MODULATE;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_FADE_ONLYONE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pActivator->IsNetClient() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-06-29 15:56:03 +02:00
|
|
|
UTIL_ScreenFade( pActivator, pev->rendercolor, Duration(), HoldTime(), (int)pev->renderamt, fadeFlags );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-29 15:56:03 +02:00
|
|
|
UTIL_ScreenFadeAll( pev->rendercolor, Duration(), HoldTime(), (int)pev->renderamt, fadeFlags );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
SUB_UseTargets( this, USE_TOGGLE, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
class CMessage : public CPointEntity
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
2016-06-04 15:24:23 +02:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_message, CMessage )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CMessage::Spawn( void )
|
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
switch( pev->impulse )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
case 1:
|
|
|
|
// Medium radius
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->speed = ATTN_STATIC;
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
// Large radius
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->speed = ATTN_NORM;
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case 3:
|
|
|
|
//EVERYWHERE
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->speed = ATTN_NONE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0: // Small radius
|
|
|
|
pev->speed = ATTN_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pev->impulse = 0;
|
|
|
|
|
|
|
|
// No volume, use normal
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->scale <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->scale = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMessage::Precache( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->noise )
|
2017-07-23 23:24:55 +02:00
|
|
|
PRECACHE_SOUND( STRING( pev->noise ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMessage::KeyValue( KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "messagesound" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->noise = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq(pkvd->szKeyName, "messagevolume" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->scale = atof( pkvd->szValue ) * 0.1;
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "messageattenuation" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->impulse = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CPointEntity::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMessage::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
CBaseEntity *pPlayer = NULL;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_MESSAGE_ALL )
|
|
|
|
UTIL_ShowMessageAll( STRING( pev->message ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pActivator && pActivator->IsPlayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
pPlayer = pActivator;
|
|
|
|
else
|
|
|
|
pPlayer = CBaseEntity::Instance( g_engfuncs.pfnPEntityOfEntIndex( 1 ) );
|
2017-07-23 23:24:55 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pPlayer )
|
|
|
|
UTIL_ShowMessage( STRING( pev->message ), pPlayer );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2017-07-23 23:24:55 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->noise )
|
|
|
|
EMIT_SOUND( edict(), CHAN_BODY, STRING( pev->noise ), pev->scale, pev->speed );
|
2017-07-23 23:24:55 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_MESSAGE_ONCE )
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_Remove( this );
|
|
|
|
|
|
|
|
SUB_UseTargets( this, USE_TOGGLE, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// FunnelEffect
|
|
|
|
//=========================================================
|
|
|
|
class CEnvFunnel : public CBaseDelay
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_iSprite; // Don't save, precache
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CEnvFunnel::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-07-23 23:24:55 +02:00
|
|
|
m_iSprite = PRECACHE_MODEL( "sprites/flare6.spr" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_funnel, CEnvFunnel )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CEnvFunnel::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
|
|
|
WRITE_BYTE( TE_LARGEFUNNEL );
|
|
|
|
WRITE_COORD( pev->origin.x );
|
|
|
|
WRITE_COORD( pev->origin.y );
|
|
|
|
WRITE_COORD( pev->origin.z );
|
|
|
|
WRITE_SHORT( m_iSprite );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_FUNNEL_REVERSE )// funnel flows in reverse?
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
WRITE_SHORT( 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WRITE_SHORT( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
MESSAGE_END();
|
|
|
|
|
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEnvFunnel::Spawn( void )
|
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// Beverage Dispenser
|
|
|
|
// overloaded pev->frags, is now a flag for whether or not a can is stuck in the dispenser.
|
|
|
|
// overloaded pev->health, is now how many cans remain in the machine.
|
|
|
|
//=========================================================
|
|
|
|
class CEnvBeverage : public CBaseDelay
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CEnvBeverage::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PRECACHE_MODEL( "models/can.mdl" );
|
|
|
|
PRECACHE_SOUND( "weapons/g_bounce3.wav" );
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( env_beverage, CEnvBeverage )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CEnvBeverage::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->frags != 0 || pev->health <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// no more cans while one is waiting in the dispenser, or if I'm out of cans.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBaseEntity *pCan = CBaseEntity::Create( "item_sodacan", pev->origin, pev->angles, edict() );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->skin == 6 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// random
|
|
|
|
pCan->pev->skin = RANDOM_LONG( 0, 5 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCan->pev->skin = pev->skin;
|
|
|
|
}
|
|
|
|
|
|
|
|
pev->frags = 1;
|
|
|
|
pev->health--;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//SetThink( &SUB_Remove );
|
2016-06-04 15:24:23 +02:00
|
|
|
//pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEnvBeverage::Spawn( void )
|
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
pev->frags = 0;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->health == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->health = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// Soda can
|
|
|
|
//=========================================================
|
|
|
|
class CItemSoda : public CBaseEntity
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 15:48:50 +02:00
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void EXPORT CanThink( void );
|
|
|
|
void EXPORT CanTouch( CBaseEntity *pOther );
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CItemSoda::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( item_sodacan, CItemSoda )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CItemSoda::Spawn( void )
|
|
|
|
{
|
|
|
|
Precache();
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_TOSS;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), "models/can.mdl" );
|
|
|
|
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
SetThink( &CItemSoda::CanThink );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.5;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CItemSoda::CanThink( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "weapons/g_bounce3.wav", 1, ATTN_NORM );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pev->solid = SOLID_TRIGGER;
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_SetSize( pev, Vector( -8, -8, 0 ), Vector( 8, 8, 8 ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
SetThink( NULL );
|
|
|
|
SetTouch( &CItemSoda::CanTouch );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CItemSoda::CanTouch( CBaseEntity *pOther )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pOther->IsPlayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// spoit sound here
|
|
|
|
pOther->TakeHealth( 1, DMG_GENERIC );// a bit of health.
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FNullEnt( pev->owner ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// tell the machine the can was taken
|
|
|
|
pev->owner->v.frags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
SetTouch( NULL );
|
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
|
|
|
pev->nextthink = gpGlobals->time;
|
2016-04-17 22:30:05 +02:00
|
|
|
}
|