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.

452 lines
10 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.
*
****/
/*
===== h_cycler.cpp ========================================================
The Halflife Cycler Monsters
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "animation.h"
#include "weapons.h"
#include "player.h"
#define TEMP_FOR_SCREEN_SHOTS
4 years ago
#if TEMP_FOR_SCREEN_SHOTS //===================================================
9 years ago
class CCycler : public CBaseMonster
{
public:
void GenericCyclerSpawn( const char *szModel, Vector vecMin, Vector vecMax );
8 years ago
virtual int ObjectCaps( void ) { return ( CBaseEntity::ObjectCaps() | FCAP_IMPULSE_USE ); }
9 years ago
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
void Spawn( void );
void Think( void );
//void Pain( float flDamage );
void Use ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
// Don't treat as a live target
virtual BOOL IsAlive( void ) { return FALSE; }
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
8 years ago
int m_animate;
9 years ago
};
8 years ago
TYPEDESCRIPTION CCycler::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CCycler, m_animate, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CCycler, CBaseMonster )
9 years ago
//
// we should get rid of all the other cyclers and replace them with this.
//
class CGenericCycler : public CCycler
{
public:
8 years ago
void Spawn( void )
{
GenericCyclerSpawn( STRING( pev->model ), Vector( -16, -16, 0 ), Vector( 16, 16, 72 ) );
8 years ago
}
9 years ago
};
LINK_ENTITY_TO_CLASS( cycler, CGenericCycler )
9 years ago
// Probe droid imported for tech demo compatibility
//
// PROBE DROID
//
class CCyclerProbe : public CCycler
{
public:
void Spawn( void );
};
LINK_ENTITY_TO_CLASS( cycler_prdroid, CCyclerProbe )
8 years ago
void CCyclerProbe::Spawn( void )
9 years ago
{
8 years ago
pev->origin = pev->origin + Vector( 0, 0, 16 );
GenericCyclerSpawn( "models/prdroid.mdl", Vector( -16, -16, -16 ), Vector( 16, 16, 16 ) );
9 years ago
}
// Cycler member functions
void CCycler::GenericCyclerSpawn( const char *szModel, Vector vecMin, Vector vecMax )
9 years ago
{
8 years ago
if( !szModel || !*szModel )
9 years ago
{
ALERT( at_error, "cycler at %.0f %.0f %0.f missing modelname", (double)pev->origin.x, (double)pev->origin.y, (double)pev->origin.z );
8 years ago
REMOVE_ENTITY( ENT( pev ) );
9 years ago
return;
}
8 years ago
pev->classname = MAKE_STRING( "cycler" );
9 years ago
PRECACHE_MODEL( szModel );
8 years ago
SET_MODEL( ENT( pev ), szModel );
9 years ago
8 years ago
CCycler::Spawn();
9 years ago
8 years ago
UTIL_SetSize( pev, vecMin, vecMax );
9 years ago
}
8 years ago
void CCycler::Spawn()
9 years ago
{
InitBoneControllers();
8 years ago
pev->solid = SOLID_SLIDEBOX;
9 years ago
pev->movetype = MOVETYPE_NONE;
pev->takedamage = DAMAGE_YES;
pev->effects = 0;
8 years ago
pev->health = 80000;// no cycler should die
9 years ago
pev->yaw_speed = 5;
pev->ideal_yaw = pev->angles.y;
ChangeYaw( 360 );
8 years ago
9 years ago
m_flFrameRate = 75;
m_flGroundSpeed = 0;
pev->nextthink += 1.0f;
9 years ago
8 years ago
ResetSequenceInfo();
9 years ago
8 years ago
if( pev->sequence != 0 || pev->frame != 0 )
9 years ago
{
m_animate = 0;
pev->framerate = 0;
}
else
{
m_animate = 1;
}
}
//
// cycler think
//
8 years ago
void CCycler::Think( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
8 years ago
if( m_animate )
9 years ago
{
8 years ago
StudioFrameAdvance();
9 years ago
}
8 years ago
if( m_fSequenceFinished && !m_fSequenceLoops )
9 years ago
{
// ResetSequenceInfo();
// hack to avoid reloading model every frame
pev->animtime = gpGlobals->time;
pev->framerate = 1.0;
m_fSequenceFinished = FALSE;
m_flLastEventCheck = gpGlobals->time;
pev->frame = 0;
8 years ago
if( !m_animate )
pev->framerate = 0.0f; // FIX: don't reset framerate
9 years ago
}
}
//
// CyclerUse - starts a rotation trend
//
8 years ago
void CCycler::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
9 years ago
{
m_animate = !m_animate;
8 years ago
if( m_animate )
pev->framerate = 1.0f;
9 years ago
else
pev->framerate = 0.0f;
9 years ago
}
//
// CyclerPain , changes sequences when shot
//
8 years ago
//void CCycler::Pain( float flDamage )
int CCycler::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
8 years ago
if( m_animate )
9 years ago
{
pev->sequence++;
8 years ago
ResetSequenceInfo();
9 years ago
if( m_flFrameRate == 0.0f )
9 years ago
{
pev->sequence = 0;
8 years ago
ResetSequenceInfo();
9 years ago
}
pev->frame = 0;
}
else
{
pev->framerate = 1.0f;
StudioFrameAdvance( 0.1f );
9 years ago
pev->framerate = 0;
ALERT( at_console, "sequence: %d, frame %.0f\n", pev->sequence, (double)pev->frame );
9 years ago
}
return 0;
}
#endif
class CCyclerSprite : public CBaseEntity
{
public:
void Spawn( void );
void Think( void );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
8 years ago
virtual int ObjectCaps( void ) { return ( CBaseEntity :: ObjectCaps() | FCAP_DONT_SAVE | FCAP_IMPULSE_USE ); }
virtual int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
void Animate( float frames );
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
inline int ShouldAnimate( void )
{
return m_animate && m_maxFrame > 1.0f;
8 years ago
}
int m_animate;
float m_lastTime;
float m_maxFrame;
9 years ago
};
LINK_ENTITY_TO_CLASS( cycler_sprite, CCyclerSprite )
9 years ago
8 years ago
TYPEDESCRIPTION CCyclerSprite::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CCyclerSprite, m_animate, FIELD_INTEGER ),
DEFINE_FIELD( CCyclerSprite, m_lastTime, FIELD_TIME ),
DEFINE_FIELD( CCyclerSprite, m_maxFrame, FIELD_FLOAT ),
};
IMPLEMENT_SAVERESTORE( CCyclerSprite, CBaseEntity )
9 years ago
void CCyclerSprite::Spawn( void )
{
8 years ago
pev->solid = SOLID_SLIDEBOX;
9 years ago
pev->movetype = MOVETYPE_NONE;
pev->takedamage = DAMAGE_YES;
pev->effects = 0;
8 years ago
pev->frame = 0;
pev->nextthink = gpGlobals->time + 0.1f;
8 years ago
m_animate = 1;
m_lastTime = gpGlobals->time;
9 years ago
PRECACHE_MODEL( STRING( pev->model ) );
8 years ago
SET_MODEL( ENT( pev ), STRING( pev->model ) );
9 years ago
8 years ago
m_maxFrame = (float)MODEL_FRAMES( pev->modelindex ) - 1;
9 years ago
}
void CCyclerSprite::Think( void )
{
8 years ago
if( ShouldAnimate() )
Animate( pev->framerate * ( gpGlobals->time - m_lastTime ) );
9 years ago
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
m_lastTime = gpGlobals->time;
}
void CCyclerSprite::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
m_animate = !m_animate;
8 years ago
ALERT( at_console, "Sprite: %s\n", STRING( pev->model ) );
9 years ago
}
8 years ago
int CCyclerSprite::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
if( m_maxFrame > 1.0f )
9 years ago
{
Animate( 1.0f );
9 years ago
}
return 1;
}
void CCyclerSprite::Animate( float frames )
{
pev->frame += frames;
8 years ago
if( m_maxFrame > 0 )
9 years ago
pev->frame = fmod( pev->frame, m_maxFrame );
}
class CWeaponCycler : public CBasePlayerWeapon
{
public:
void Spawn( void );
int iItemSlot( void ) { return 1; }
int GetItemInfo(ItemInfo *p) {return 0; }
void PrimaryAttack( void );
void SecondaryAttack( void );
BOOL Deploy( void );
void Holster( int skiplocal = 0 );
int m_iszModel;
int m_iModel;
};
LINK_ENTITY_TO_CLASS( cycler_weapon, CWeaponCycler )
9 years ago
8 years ago
void CWeaponCycler::Spawn()
9 years ago
{
8 years ago
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_NONE;
9 years ago
PRECACHE_MODEL( STRING( pev->model ) );
8 years ago
SET_MODEL( ENT( pev ), STRING( pev->model ) );
9 years ago
m_iszModel = pev->model;
m_iModel = pev->modelindex;
UTIL_SetOrigin( pev, pev->origin );
8 years ago
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) );
9 years ago
SetTouch( &CBasePlayerItem::DefaultTouch );
}
8 years ago
BOOL CWeaponCycler::Deploy()
9 years ago
{
m_pPlayer->pev->viewmodel = m_iszModel;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
9 years ago
SendWeaponAnim( 0 );
m_iClip = 0;
return TRUE;
}
void CWeaponCycler::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
}
void CWeaponCycler::PrimaryAttack()
{
SendWeaponAnim( pev->sequence );
m_flNextPrimaryAttack = gpGlobals->time + 0.3f;
9 years ago
}
void CWeaponCycler::SecondaryAttack( void )
{
float flFrameRate, flGroundSpeed;
8 years ago
pev->sequence = ( pev->sequence + 1 ) % 8;
9 years ago
pev->modelindex = m_iModel;
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
9 years ago
GetSequenceInfo( pmodel, pev, &flFrameRate, &flGroundSpeed );
pev->modelindex = 0;
if( flFrameRate == 0.0f )
9 years ago
{
pev->sequence = 0;
}
SendWeaponAnim( pev->sequence );
m_flNextSecondaryAttack = gpGlobals->time + 0.3f;
9 years ago
}
// Flaming Wreakage
class CWreckage : public CBaseMonster
{
8 years ago
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
void Spawn( void );
void Precache( void );
void Think( void );
int m_flStartTime;
};
8 years ago
TYPEDESCRIPTION CWreckage::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CWreckage, m_flStartTime, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CWreckage, CBaseMonster )
9 years ago
LINK_ENTITY_TO_CLASS( cycler_wreckage, CWreckage )
9 years ago
void CWreckage::Spawn( void )
{
8 years ago
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_NONE;
pev->takedamage = 0;
pev->effects = 0;
9 years ago
8 years ago
pev->frame = 0;
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
8 years ago
if( pev->model )
9 years ago
{
PRECACHE_MODEL( STRING( pev->model ) );
8 years ago
SET_MODEL( ENT( pev ), STRING( pev->model ) );
9 years ago
}
// pev->scale = 5.0;
m_flStartTime = (int)gpGlobals->time;
9 years ago
}
8 years ago
void CWreckage::Precache()
9 years ago
{
8 years ago
if( pev->model )
PRECACHE_MODEL( STRING( pev->model ) );
9 years ago
}
void CWreckage::Think( void )
{
8 years ago
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.2f;
9 years ago
8 years ago
if( pev->dmgtime )
9 years ago
{
8 years ago
if( pev->dmgtime < gpGlobals->time )
9 years ago
{
UTIL_Remove( this );
return;
}
8 years ago
else if( RANDOM_FLOAT( 0, pev->dmgtime - m_flStartTime ) > pev->dmgtime - gpGlobals->time )
9 years ago
{
return;
}
}
8 years ago
9 years ago
Vector VecSrc;
8 years ago
9 years ago
VecSrc.x = RANDOM_FLOAT( pev->absmin.x, pev->absmax.x );
VecSrc.y = RANDOM_FLOAT( pev->absmin.y, pev->absmax.y );
VecSrc.z = RANDOM_FLOAT( pev->absmin.z, pev->absmax.z );
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, VecSrc );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( VecSrc.x );
WRITE_COORD( VecSrc.y );
WRITE_COORD( VecSrc.z );
WRITE_SHORT( g_sModelIndexSmoke );
8 years ago
WRITE_BYTE( RANDOM_LONG( 0,49 ) + 50 ); // scale * 10
WRITE_BYTE( RANDOM_LONG( 0, 3 ) + 8 ); // framerate
9 years ago
MESSAGE_END();
}